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

Use SafeERC20 instead of IERC20 in contracts/mocks/DummyRouter.sol #41

Open
code423n4 opened this issue Nov 14, 2021 · 2 comments
Open
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 disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue

Comments

@code423n4
Copy link
Contributor

Handle

fatima_naz

Vulnerability details

Impact

In line - 20 , 29 and 30. ERC20 transfer and transferFrom are used. The race condition that happens the most on the network today is the race condition in the ERC20 token standard.
The ERC20 token standard includes a function called 'approve' which allows an address to approve another address to spend tokens on their behalf. Assume that Alice has approved Eve to spend n of her tokens, then Alice decides to change Eve's approval to m tokens. Alice submits a function call to approve with the value n for Eve. Eve runs a Ethereum node so knows that Alice is going to change her approval to m. Eve then submits a tranferFrom request sending n of Alice's tokens to herself, but gives it a much higher gas price than Alice's transaction. The transferFrom executes first so gives Eve n tokens and sets Eve's approval to zero. Then Alice's transaction executes and sets Eve's approval to m. Eve then sends those m tokens to herself as well. Thus Eve gets n + m tokens even thought she should have gotten at most max(n,m).

Proof of Concept

https://swcregistry.io/docs/SWC-114
https://medium.com/coinmonks/solidity-transaction-ordering-attacks-1193a014884e

Tools Used

Recommended Mitigation Steps

use SafeERC20 - Library that brings an abstract layer above the ERC20 standard interface providing a way to call its methods safely by checking pre and post-conditions.

Add these 2 lines-
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
using SafeERC20 for IERC20

Replace transferFrom with SafeTransferFrom
Replace transfer with SafeTransfer

@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 Nov 14, 2021
code423n4 added a commit that referenced this issue Nov 14, 2021
@adrien-supizet adrien-supizet added the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label Nov 18, 2021
@adrien-supizet
Copy link
Collaborator

This is a mock contract that will obviously not be used in production, and only for tests.

@alcueca
Copy link
Collaborator

alcueca commented Dec 3, 2021

Dispute rejected, scope wasn't set.

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 disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Projects
None yet
Development

No branches or pull requests

3 participants