Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing payable keyword in function receiveFromBridge() in DecentBridgeAdapter #620

Closed
c4-bot-3 opened this issue Jan 23, 2024 · 9 comments
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue grade-c insufficient quality report This report is not of sufficient quality primary issue Highest quality submission among a set of duplicates QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@c4-bot-3
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2024-01-decent/blob/07ef78215e3d246d47a410651906287c6acec3ef/src/bridge_adapters/DecentBridgeAdapter.sol#L127

Vulnerability details

Impact

Currently, the DecentBridgeExecutor has two functions, namely, _executeWeth() and _executeEth(). The contract approves the WETH correctly to the adapter but it is not able to send the ETH since the receiveFromBridge() function is not marked payable. Due to this, the user would lose funds since the call to the payload (i.e. receiveFromBridge) always reverts.

Proof of Concept

  1. The function execute() is called from the decentEthRouter contract. If the user originates the call from the bridge() function in the router and sets deliverEth to true, we enter the else block on Line 80. Note: This requires gasCurrencyIsEth to be true as well i.e. the chain should have it's native token to be ether.
File: DecentBridgeExecutor.sol
68:     function execute(
69:         address from,
70:         address target,
71:         bool deliverEth,
72:         uint256 amount,
73:         bytes memory callPayload
74:     ) public onlyOwner {
75:         weth.transferFrom(msg.sender, address(this), amount);
76: 
77:         if (!gasCurrencyIsEth || !deliverEth) {
78:             _executeWeth(from, target, amount, callPayload);
79:         } else {
80:             _executeEth(from, target, amount, callPayload);
81:         }
82:     }
  1. The call on Line 80 above, leads us to the _executeEth() function. This function transfers msg.value = amount to the adapter contract and calls the payload. The payload is set to the receiveFromBridge() function in the adapter as seen here. But since the function is not payable, the call would revert. The call would never succeed which causes the user funds to be permanently locked on the destination chain.
File: DecentBridgeExecutor.sol
54:     function _executeEth(
55:         address from,
56:         address target,
57:         uint256 amount,
58:         bytes memory callPayload
59:     ) private {
60:         weth.withdraw(amount);
61:         (bool success, ) = target.call{value: amount}(callPayload);
62:         if (!success) {
63:             payable(from).transfer(amount);
64:         }
65:     }

Tools Used

Manual Review

Recommended Mitigation Steps

Add the payable keyword to the function receiveFromBridge() to allow accepting ETH when sent from executor.

Assessed type

Error

@c4-bot-3 c4-bot-3 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Jan 23, 2024
c4-bot-4 added a commit that referenced this issue Jan 23, 2024
@c4-pre-sort c4-pre-sort added the insufficient quality report This report is not of sufficient quality label Jan 25, 2024
@c4-pre-sort
Copy link

raymondfam marked the issue as insufficient quality report

@raymondfam
Copy link

Intended design as IUTB(utb).receiveFromBridge() isn't payable either.

@c4-pre-sort
Copy link

raymondfam marked the issue as primary issue

@c4-pre-sort c4-pre-sort added the primary issue Highest quality submission among a set of duplicates label Jan 25, 2024
@alex-ppg
Copy link

alex-ppg commented Feb 1, 2024

The confusion in this submission and the code's structure arises from the lack of access control in DecentEthRouter.

Specifically, the cross-chain transfers between DecentBridgeAdapter implementations will correctly execute when handled by a UTB top-level call as the DecentBridgeAdapter::bridge function hard-codes the deliverEth value to false.

As the DecentEthRouter lacks access control, direct usage of the router to transfer funds along with a misconfiguration of the call will cause funds to be permanently lost as the DecentBridgeAdapter cannot handle native funds, causing the non-blocking transaction to fail forever even if retried.

As the vulnerability will solely arise from misuse of the DecentEthRouter by the user, I consider it to be capped at QA per the relevant SC verdict and thus QA (L).

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Feb 1, 2024
@c4-judge
Copy link

c4-judge commented Feb 1, 2024

alex-ppg changed the severity to QA (Quality Assurance)

@c4-judge c4-judge added the QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax label Feb 1, 2024
@alex-ppg
Copy link

alex-ppg commented Feb 4, 2024

Based on other QA reports submitted in the contest I am inclined to award this a C grade.

@c4-judge c4-judge closed this as completed Feb 4, 2024
@c4-judge c4-judge added grade-c unsatisfactory does not satisfy C4 submission criteria; not eligible for awards labels Feb 4, 2024
@c4-judge
Copy link

c4-judge commented Feb 4, 2024

alex-ppg marked the issue as grade-c

@mcgrathcoutinho
Copy link

Hi @alex-ppg, thank you for the detailed response. I believe issue this is valid since:

Based on the comment I've provided on #647, keeping the bridge() and bridgeWithPayload() function publicly accessible in the DecentEthRouter is intentional since decent bridge charges no bridge fees.

Additionally, there is no misconfiguration of the call happening here since the issue is talking about delivering ETH on a chain where ETH is the gas currency, which is why this condition if (!gasCurrencyIsEth || !deliverEth) in function execute() would have both gasCurrencyIsEth and deliverEth set to true, meaning we will enter the else block to call function _executeEth(). This is where the error occurs, which I have pointed out in the report.

Please consider re-evaluating this issue.

Thank you.

@alex-ppg
Copy link

alex-ppg commented Feb 9, 2024

Hey @mcgrathcoutinho, thanks for following up on your original concerns in #647. You can consult #647 again to confirm that these functions should not be publicly accessible. Based on the above, my original ruling stands and can be considered final.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue grade-c insufficient quality report This report is not of sufficient quality primary issue Highest quality submission among a set of duplicates QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

6 participants