Submitted by chaduke, also found by minglei-wang-3570, Infect3d, zhaojohnson (1, 2), 0xINFINITY (1, 2), Spearmint, 0xbepresent, pks_, petarP1998, Anirruth, and pkqs90
SwapAction.transferAndSwap() will perform a _transferFrom to transfer the input tokens to the user proxy and then perform a swap via a router. When it uses an ERC20 permit transferFrom, an attacker can extract the v, r, s from the safePermit() call and frontruns it with a direct safePermit() with the same arguments. As a result, SwapAction.transferAndSwap() will fail due to the advancing of nonce. Effectively, this is a DOS attack.
First, SwapAction.transferAndSwap() will perform a _transferFrom to transfer the input tokens to the user proxy and then perform a swap via a router.
https://github.com/code-423n4/2024-07-loopfi/blob/57871f64bdea450c1f04c9a53dc1a78223719164/src/proxy/SwapAction.sol#L93C14-L103
Second, _transferFrom has three cases: permit2, permit or standard transferFrom:
https://github.com/code-423n4/2024-07-loopfi/blob/57871f64bdea450c1f04c9a53dc1a78223719164/src/proxy/TransferAction.sol#L46-L82
The vulnerability lies in the second case, there are two parts:
The first component will set the proper allowance when successful. The problem is that an attacker can observe the mempool and extract the v, r, s from the safePermit() call and frontruns it with a direct safePermit() with the same arguments. As a result, the _transferFrom and thus SwapAction.transferAndSwap() will fail due to the advancement of the nonce.
This permit DOS attack has been reported by Immunifi earlier.
The following POC confirms the finding:
Run forge test --match-test testSwapDOS -vv:
Foundry
Change the logic to either there is sufficient allowance or the safePermit succeeds using a try-catch clause:
DoS
amarcu (LoopFi) acknowledged and commented:
