Open code423n4 opened 2 years ago
This doesn't allow explicit stealing by an attacker, but does leak value. We would suggest a (2) severity on this.
This results in a user losing assets that they will never be able to recover. Per documentation
3 — High: Assets can be stolen/lost/compromised directly (or indirectly if there is a valid attack path that does not have hand-wavy hypotheticals).
Lost assets are a high sev.
Long after the fact, I've been able to reproduce the ethDelta
vuln but not the erc20Delta
issue... it appears there is a bug there, but it reverts rather than locking user funds.
Handle
WatchPug
Vulnerability details
https://github.com/code-423n4/2021-10-tally/blob/c585c214edb58486e0564cb53d87e4831959c08b/contracts/swap/Swap.sol#L200-L225
When a user tries to swap unwrapped ETH to ERC20, even if there is a certain amount of ETH refunded, at L215,
ethDelta
will always be0
.That's because
originalETHBalance
already includes themsg.value
sent by the caller.Let's say the ETH balance of the contract is
1 ETH
before the swap.10 ETH
to USDC;originalETHBalance
will be11 ETH
;1 ETH
of refund;ethDelta
will be0
as the new balance is2 ETH
andsubOrZero(2, 11)
is0
.Similarly,
erc20Delta
is also computed wrong.Consider a special case of a user trying to arbitrage from
WBTC
toWBTC
, theoriginalERC20Balance
already includes the input amount,erc20Delta
will always be much lower than the actual delta amount.For example, for an arb swap from
1 WBTC
to1.1 WBTC
, theethDelta
will be0.1 WBTC
while it should be1.1 WBTC
.Impact
Recommendation
Consider subtracting the input amount from the originalBalance.