Skip to content
DoS Audit finding Intermediate

IncentiveBits.setOrThrow() will revert, leading to a DoS

The setOrThrow() function in IncentiveBits incorrectly checks whether an incentive has already been used, causing it to revert when incentives are not claimed in increasing order. An attacker or normal user could trigger this to prevent other users from claiming incentives for a given hash.

eLSeR17 Follow with ge6a and oxelmiguel

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-06-boost-aa-wallet-judging/issues/263

Found by

eLSeR17, ge6a, oxelmiguel

Summary

IncentiveBits.setOrThrow() will revert, leading to a DoS.

Vulnerability Detail

setOrThrow() expects each incentive from 0 to 7 to be used once per hash, reverting in case that for a given hash, an already used incentive is used again. However the mechanism that checks already used incentives does not work as expected: alreadySet := xor(1, shr(incentive, updatedStorageValue)), reverting if incentiveIds are not used in increasing order.

The external call will come from BoostCore.claimIncentiveFor(), which calls SignedValidator.validate() and therefore setOrThrow(). The value of the incentiveId parameter used is arbitrary and valid as long as uint256(validatorData.incentiveQuantity) <= incentiveId is not fulfilled, which does not guarantee that calls will necessarily be in increasing order.

Example: Imagine setOrThrow() function is used with incentiveId = 5, in that case updatedStorageValue will be set to XOR (00000000, 00100000) = 00100000. Therefore, the resulting value for alreadySet is: alreadySet = XOR (1, shr(5, 00100000)) = XOR (00000001, 00000001) = 0 => Does NOT revert.

Now setOrThrow() function is called again for incentiveId = 2, so that updatedStorageValue will be: XOR (00100000, 00000100) = 00100100. Therefore, the new resulting value for alreadySet is: alreadySet = XOR (1, shr(2, 00100100)) = XOR (00000001, 00001001) = 00001000 => Reverts as alreadySet != 0

Impact

Claiming incentive for a given hash will be no longer possible, or fewer claims will be allowed depending on the last incentiveId used. This could be performed by accident by a normal user or on purpose by a malicious attacker to DoS and prevent other users from claiming from this hash.

Code Snippet

https://github.com/sherlock-audit/2024-06-boost-aa-wallet/blob/main/boost-protocol/packages/evm/contracts/validators/SignerValidator.sol#L126-L154

Tool used

Manual Review

Recommendation

For correctly comparing if the incentiveId index has been used, that bit must be totally isolated and XOR it with 1. For this, first shift left until we get 10000000 and then shift 7 times to right to get 1.

Solidity
function setOrThrow(IncentiveMap storage bitmap, bytes32 hash, uint256 incentive) internal {
        bytes4 invalidSelector = BoostError.IncentiveToBig.selector;
        bytes4 claimedSelector = BoostError.IncentiveClaimed.selector;
        /// @solidity memory-safe-assembly
        assembly {
            if gt(incentive, 7) {
                // if the incentive is larger the 7 (the highest bit index)
                // we revert
                mstore(0, invalidSelector)
                mstore(4, incentive)
                revert(0x00, 0x24)
            }
            mstore(0x20, bitmap.slot)
            mstore(0x00, hash)
            let storageSlot := keccak256(0x00, 0x40)
            // toggle the value that was stored inline on stack with xor
            let updatedStorageValue := xor(sload(storageSlot), shl(incentive, 1))
            // isolate the toggled bit and see if it's been unset back to zero
-           let alreadySet := xor(1, shr(incentive, updatedStorageValue))
+          let alreadySet := xor(1, shr(7, shl(incentive - 1, updatedStorageValue)))
.
.
.

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/rabbitholegg/boost-protocol/pull/138

The original report as published on Sherlock, by eLSeR17. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the bit isolation logic in setOrThrow() is incorrect: it shifts the updated storage value by the incentive index without first isolating the target bit, so the XOR check can produce a non-zero result even when the bit was not previously set.

Impact

Claiming incentives for a given hash could be blocked, or fewer claims allowed, depending on the last incentiveId used; this could be done accidentally or on purpose to deny service.

What the attacker needed

Ability to call claimIncentiveFor with arbitrary incentiveId

The fix

The bit isolation logic should be corrected by shifting left to isolate the target bit and then shifting right by 7, as shown in the recommendation.

How it was found

  1. Call setOrThrow() with incentiveId = 5, which does not revert.
  2. Call setOrThrow() again with incentiveId = 2, which reverts because alreadySet != 0.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A smart contract uses a bitmap to track which incentives have been claimed. The check for whether a bit is already set is flawed: it can wrongly think a bit is set when it is not, causing the contract to reject valid claims. This means someone can block others from claiming rewards by claiming incentives in a non-sequential order.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More from Boost Core Incentive Protocol

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.