code-423n4 / 2022-04-pooltogether-findings

0 stars 0 forks source link

Griefing attack by transferring aTokens to the contract #99

Closed gititGoro closed 2 years ago

gititGoro commented 2 years ago

Originally part of a QA report by Tadashi https://github.com/code-423n4/2022-04-pooltogether-findings/issues/69

Griefing attack by transferring aTokens to the contract

Summary:

_tokenToShares uses the following formula for computing the total shares of an user:

return _supply == 0 ? _tokens : _tokens.mul(_supply).div(aToken.balanceOf(address(this)));

An attacker wishing to harm users could perform the following attack:

  1. The attacker listens for transactions on mempool that are calling supplyTokenTo.
  2. When he listen the victim (or victims), the attacker sends X aTokens to the contract and cause a re-order (e.g. by bribing a miner) to guarantee that the transfer of aToken is the first transaction in the block.

Then one of the following damaging situations can occur:

Impact: The attacker can target just a subset of users, but with enough capital can degrade the experience of all users that are trying to supply tokens to Pool Together.

Some tokens require the approval to be zero before calling approve with a non-zero value

Summary: Some ERC20 tokens require approving to 0 first before approving a new value.

Details: Some tokens (such as USDT) do not work when changing the allowance from an existing non-zero allowance value.

Mitigation: Change L182 to

IERC20(_tokenAddress()).safeApprove(address(_pool()), 0);
IERC20(_tokenAddress()).safeApprove(address(_pool()), type(uint256).max);

Impact: It can break the contract composability if _tokenAddress() correspond to address of such tokens (e.g. USDT). Otherwise, it won’t cause any issue.

gititGoro commented 2 years ago

Duplicate of https://github.com/code-423n4/2022-04-pooltogether-findings/issues/44