Skip to content
DoS Audit finding Intermediate

Resizing the payout schedule with less items might revert

The setPayoutScheduleFixed function in a smart contract iterates over the old arrays' lengths when resizing metadata arrays, causing a revert if the new schedule has fewer items. An attacker could not exploit this directly, but it prevents legitimate resizing of the payout schedule.

GimelSec Follow with caventa, StErMi and 13 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-openq-judging/issues/244

Found by

GimelSec, caventa, StErMi, clems4ever, XKET, ck, Jeiwan, 0x52, HonorLt, unforgiven, ArcAnya, rvierdiiev, ak1, bin2chen, usmannk, TrungOre

Summary

According to some comments in setPayoutScheduleFixed, reducing the number of items in the schedule is a supported use case. However in that case, the function will revert because we are iterating over as many items as there was in the previous version of the three arrays making the function revert since the new arrays have less items.

Vulnerability Detail

Let say they were 4 items in the arrays tierWinners, invoiceComplete and supportingDocumentsComplete and we are resizing the schedule to 3 items. Then the following function would revert because we use the length of the previous arrays instead of the new ones in the for loops.

Solidity
function setPayoutScheduleFixed(
        uint256[] calldata _payoutSchedule,
        address _payoutTokenAddress
    ) external onlyOpenQ {
        require(
            bountyType == OpenQDefinitions.TIERED_FIXED,
            Errors.NOT_A_FIXED_TIERED_BOUNTY
        );
        payoutSchedule = _payoutSchedule;
        payoutTokenAddress = _payoutTokenAddress;

        // Resize metadata arrays and copy current members to new array
        // NOTE: If resizing to fewer tiers than previously, the final indexes will be removed
        string[] memory newTierWinners = new string[](payoutSchedule.length);
        bool[] memory newInvoiceComplete = new bool[](payoutSchedule.length);
        bool[] memory newSupportingDocumentsCompleted = new bool[](
            payoutSchedule.length
        );

        for (uint256 i = 0; i < tierWinners.length; i++) { <=====================================================
            newTierWinners[i] = tierWinners[i];
        }
        tierWinners = newTierWinners;

        for (uint256 i = 0; i < invoiceComplete.length; i++) { <=====================================================
            newInvoiceComplete[i] = invoiceComplete[i];
        }
        invoiceComplete = newInvoiceComplete;

        for (uint256 i = 0; i < supportingDocumentsComplete.length; i++) { <=====================================================
            newSupportingDocumentsCompleted[i] = supportingDocumentsComplete[i];
        }
        supportingDocumentsComplete = newSupportingDocumentsCompleted;
    }

The same issue exists on TieredPercentageBounty too.

Impact

Unable to resize the payout schedule to less items than the previous state.

Code Snippet

https://github.com/sherlock-audit/2023-02-openq/blob/main/contracts/Bounty/Implementations/TieredFixedBountyV1.sol#L157

Tool used

Manual Review

Recommendation

Solidity
        for (uint256 i = 0; i < newTierWinners.length; i++) {
            newTierWinners[i] = tierWinners[i];
        }
        tierWinners = newTierWinners;

        for (uint256 i = 0; i < newInvoiceComplete.length; i++) {
            newInvoiceComplete[i] = invoiceComplete[i];
        }
        invoiceComplete = newInvoiceComplete;

        for (uint256 i = 0; i < newSupportingDocumentsCompleted.length; i++) {
            newSupportingDocumentsCompleted[i] = supportingDocumentsComplete[i];
        }
        supportingDocumentsComplete = newSupportingDocumentsCompleted;

Note this won't work if increasing the number of items compared to previous state must also be supported. In that case you must use the length of the smallest of the two arrays in each for loop.

Discussion

FlacoJones

A valid issue but an invalid approach. Because if one is INCREASING the size of the array, you will still get an array out of bounds exception.

This suggestion, combined with adding a i >= previousArray.length will do the trick

https://github.com/OpenQDev/OpenQ-Contracts/pull/126

jacksanford1

Lead Senior Watson comment on PR #126:

Fixes look good. Payout schedule can now correctly be downsized

The original report as published on Sherlock, by GimelSec. 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

The for loops use the length of the previous arrays instead of the new arrays when copying elements, leading to out-of-bounds access when the new array is smaller.

Impact

The payout schedule cannot be resized to fewer items than the previous state, causing the function to revert.

What the attacker needed

Bounty type is tiered fixed or percentage

The fix

The fix was to iterate up to the length of the new arrays and also handle increasing size by using the minimum of the two lengths.

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.

This is a bug in a smart contract that manages bounty payouts. When someone tries to reduce the number of payout tiers, the code mistakenly uses the old number of tiers to copy data into new smaller lists, which causes an error and stops the transaction. So the intended feature of shrinking the schedule simply doesn't work.

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 by GimelSec

View all

18 more disclosed reports, best first.

More from OpenQ

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.