The Fees.sol contract will send Eth to the Staking.sol contract when _sellProfits is called. The attacker can call deposit() with a large amount of TKN followed by sellProfits() followed by withdraw() in a single atomic transaction to gain a large portion of the ETH rewards.
The Fees.sol contract will send Eth to the Staking.sol contract when _sellProfits is called. The accounting of the Staking.sol contract is such that it immediately allocates rewards proportionally to the amount of token staked at that exact point in time regardless of how long the stake position is kept before or after the transfer. An attacker can:
Deposit a large amount of funds into Staking contract
Call sellProfits() to initiate transfer of WETH from Fees contract to Staking contract
Withdraw liquidity from the pool
All in one block.
Note that even though the attack example refers to Fees.sol, the attack does not require integration with that contract to be complete to work. This works with any transfer of WETH to the Staking.sol contract.
Here is a Proof of Concept for this attack. This foundry test/POC can be run in the test folder of the 2023-07-BEEDLE audit directory. Skip to function test_POC_take_rewards() public to read the important part of the POC:
We defined this Attack-POC to be successful when we asserted that:
- The TKN cost for the attacker was zero/free. assertEq(tkn_before_attack, tkn_after_attack);
- the attacker to have more WETH after the attack than they started with assertGt(balance_after, balance_before);
We can see the profit of the entire attack by running forge test -vvv and seeing the console logs:
Attacker can gain unfair share of WETH rewards for free (aside from gas costs), leading to fee loss for other participants
Foundry testing
Add a time component to fee accounting or a time-delay for depositing and withdrawing TKN for WETH reward share.
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.