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

token.approve() doesn’t check return value #294

Open
code423n4 opened this issue Dec 19, 2021 · 1 comment
Open

token.approve() doesn’t check return value #294

code423n4 opened this issue Dec 19, 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 sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

Handle

sirhashalot

Vulnerability details

Impact

Multiple files within the contracts/basket/contracts/singleJoinExit/ directory call token.approve() for an ERC20 token, but these calls do not verify whether the approve() call failed. Some ERC20 tokens do not revert if an approval fails, and because the return value is not checked, the contract would not be aware of this failure, potentially causing malfunctions in later operations. Using a function from SafeERC20 that checks the return value would mitigate this edge case.

Proof of Concept

token.approve() is found in several locations:

  • singleJoinExit/SingleTokenJoin.sol line 43
  • singleJoinExit/SingleNativeTokenExitV2.sol line 55
  • singleJoinExit/SingleNativeTokenExit.sol line 44
  • singleJoinExit/SingleTokenJoinV2.sol line 53

Tools Used

Manual analysis

Recommended Mitigation Steps

While the OpenZeppelin SafeERC20 safeApprove() function could be used to revert on approve failures unlike the standard approve(), the safeApprove() function is deprecated and instead OpenZeppelin recommends either safeIncreaseAllowance() or safeDecreaseAllowance(). Because uint256(-1) should be an increase, replace each instance of token.approve(spender, uint256(-1)) with token.safeIncreaseAllowance(spender, uint256(-1)).

@code423n4 code423n4 added 1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working labels Dec 19, 2021
code423n4 added a commit that referenced this issue Dec 19, 2021
@loki-sama loki-sama added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Dec 30, 2021
@loki-sama
Copy link
Collaborator

In our case safeApprove() would be better as we don't care about front running the approval and safeIncreaseAllowance() would fail when allowance is bigger then 0.

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 sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

2 participants