ExchangeHelpers: in setMaxAllowance, safeApprove shouldn't be used #50
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")
Handle
PierrickGT
Vulnerability details
Impact
In setMaxAllowance,
safeApprove
is used to increase allowance. As stated in the following Pull Request,safeApprove
has been deprecated in favor ofsafeIncreaseAllowance
andsafeDecreaseAllowance
.https://github.com/OpenZeppelin/openzeppelin-contracts/pull/2268/files
This is because
safeApprove
shouldn't check for allowance, as explained in the issue below:OpenZeppelin/openzeppelin-contracts#2219
approve
is actually vulnerable to a sandwich attack as explained in the following document and this check for allowance doesn't actually avoid it.https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/edit
Proof of Concept
safeIncreaseAllowance
should be used to increase allowance andsafeDecreaseAllowance
to decrease allowance to 0. We can also gain in code clarity by refactoring theif else
statement and calling_token.safeIncreaseAllowance(_spender, type(uint256).max);
only once.Recommended Mitigation Steps
The following changes are recommended.
The text was updated successfully, but these errors were encountered: