Using this search command: https://github.com/search?q=repo%3ACyfrin%2F2023-12-the-standard+safeApprove+NOT+language%3AMarkdown&type=code we can see that there is one instance of using safeApprove
whenever swaps are meant to occur. Note that this issue i believe is a tad different from the already publicly disclosed from here, as functionality still works well and protocol might not have decided to implement a fix.
Take a look at SmartVaultV3.sol#L196-L204
Now here is the implementation of safeApprove()
From attached code snippets, we can see that the swap uses safeApprove()
which requires the allowance to be 0 otherwise it reverts, this means that as long as the allowance has not been used up sometime before, then this method will not work properly anymore.
Allowance might not be used in different instances, to showcase a potential case of how approval would be left over, when UniswapV3Router
executes exactInput()
If the paid token is weth
, and the UniswapV3Router
has enough contract balance, it will use the contract balance directly, and will not execute transferFrom(),
i.e. it will not use the allowance.
UniswapV3Router
transfers the payment token via pay()
with the following code
https://github.com/Uniswap/v3-periphery/blob/6cce88e63e176af1ddb6cc56e029110289622317/contracts/base/PeripheryPayments.sol#L58-L62
This now allows a malicious user to frontrun owners attempt to swap, they might wait for the value of swap being relatively small so they don't spend too much then front run with a transfer of ETH to UniswapV3SwapRouter
.
resulting in the allowance not being used, and the next swap that requires an execution safeApprove()
will surely REVERT.
Subsequent calls can now no longer work properly.
If for whatever reason the router does not use up all the current allowances, for example after exactInput()
is executed, then there is a potential failure of all next attempts of ERC20 swaps.
If safeApprove()
is still going to be used, then always reset allowance to 0 before making current approval or instead just use safeIncreaseAllowance()
instead.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.