Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Jeiwan - Griefing attack may cause indefinite DoS on refunding #526

Closed
github-actions bot opened this issue Feb 22, 2023 · 0 comments
Closed

Jeiwan - Griefing attack may cause indefinite DoS on refunding #526

github-actions bot opened this issue Feb 22, 2023 · 0 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A valid High severity issue Reward A payout will be made for this issue

Comments

@github-actions
Copy link

github-actions bot commented Feb 22, 2023

Jeiwan

high

Griefing attack may cause indefinite DoS on refunding

Summary

Refunding can be blocked indefinitely if iterating all deposits consumes the entire gas limit of a block. Creating a huge number of deposits can be a cheap attack for two reasons: 1) transaction fees are low on Polygon; 2) fake ERC20 tokens, which cost nothing, can be deposited. As a result, deposited amounts may be locked indefinitely in the bounty contracts.

Vulnerability Detail

Every deposit into a bounty contract is saved into the deposits array. The array is iterated when calculating the amount of locked funds, i.e. the sum of all deposits that haven't expired yet. As you can see, the loop is not bounded:

bytes32[] memory depList = this.getDeposits();
for (uint256 i = 0; i < depList.length; i++) {
    if (
        block.timestamp <
        depositTime[depList[i]] + expiration[depList[i]] &&
        tokenAddress[depList[i]] == _depositId
    ) {
        lockedFunds += volume[depList[i]];
    }
}

Also, in each iteration, multiple storage slots are read: depositTime, expiration, tokenAddress, and volume, which increases the gas consumption, especially when there are many deposits to check.

Knowing the amount of locked funds is required to obtain the amount of available, i.e. unlocked, funds during refunding:

uint256 availableFunds = bounty.getTokenBalance(depToken) -
    bounty.getLockedFunds(depToken);

This opens up the following vulnerability:

  1. A malicious actor creates a fake ERC20 token and makes a huge amount of small deposits with infinite expiration (type(uint256)-1) into a bounty contract.
  2. When a depositor tries to refund their deposits, the getLockedFunds function is called to compute locked funds.
  3. Since the number of deposits in the contract is huge, the loop in the getLockedFunds function consumes the entire gas limit of a block and causes the refund transaction to revert.
  4. The depositor is not able to withdraw their funds since refunding is blocked.

Impact

Deposited funds may be locked indefinitely in the bounty contracts due to an artificially increased gas consumption of a refunding transaction.

Code Snippet

BountyCore.sol#L341-L349

Tool used

Manual Review

Recommendation

Consider setting a limit on the number of deposits so that the limit is high enough for all valid use cases and low enough to not allow the griefing attack.

Duplicate of #77

@github-actions github-actions bot added Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A valid High severity issue labels Feb 22, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label Mar 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A valid High severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

1 participant