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

SingleJoin/SingleExit contracts use transfer() to send ether back to the caller #131

Closed
code423n4 opened this issue Dec 18, 2021 · 1 comment
Labels
1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working duplicate This issue or pull request already exists

Comments

@code423n4
Copy link
Contributor

Handle

Ruhum

Vulnerability details

Impact

The SingleJoin & SingleExit contracts use transfer() to send ether to the caller. If the caller is a smart contract the call might fail reverting the transaction if:

  • caller contract isn't able to receive ether (missing receive() or payable fallback() function)
  • caller contract uses more than the provided 2300 gas when receiving ether

Since gas costs might increase in the future, using transfer() might cause these contracts to potentially break since transfer() would always fail.

Here's a blogpost about using transfer(): https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/

I'd rate the issue as medium since a part of the protocol would potentially be unusable.

Proof of Concept

Usage of transfer():

https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/singleJoinExit/EthSingleTokenJoin.sol#L37

https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/singleJoinExit/EthSingleTokenJoinV2.sol#L37

https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/singleJoinExit/SingleNativeTokenExit.sol#L93

https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/singleJoinExit/SingleNativeTokenExitV2.sol#L121

Tools Used

none

Recommended Mitigation Steps

Instead, the contracts should use:

(bool success, ) = payable(msg.sender).call{value: intermediateTokenBalance}("");
require(success);

Note that this approach introduces a risk of reentrancy. But, that shouldn't be a problem for these specific contracts. Nevertheless, it might be worth adding reentrancy guards in case the contracts ever get extended.

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Dec 18, 2021
code423n4 added a commit that referenced this issue Dec 18, 2021
@loki-sama loki-sama added the duplicate This issue or pull request already exists label Dec 29, 2021
@loki-sama
Copy link
Collaborator

loki-sama commented Dec 29, 2021

duplicate #175

@ghost ghost closed this as completed Jan 10, 2022
@0xleastwood 0xleastwood added 1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Jan 22, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants