Skip to content
Business logic Audit finding Intermediate

Setting new buffer does not reduce current buffer to cap

The setBufferCap function updates the buffer before changing the cap, so the buffer can remain above the new cap. An attacker could then perform actions that consume more than the intended buffer cap.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel, also found by rayn and catchup

RateLimited.sol#L142

The RateLimited.setBufferCap function first updates the buffer and then sets the new cap, but does not apply the new cap to the updated buffer. Meaning, the updated buffer value can be larger than the new buffer cap which should never be the case. Actions consuming more than the new buffer cap can be performed.

function _setBufferCap(uint256 newBufferCap) internal {
    // @audit still uses old buffer cap, should set buffer first
    _updateBufferStored();

    uint256 oldBufferCap = bufferCap;
    bufferCap = newBufferCap;

    emit BufferCapUpdate(oldBufferCap, newBufferCap);
}

Recommended Mitigation Steps

Update the buffer after setting the new cap:

function _setBufferCap(uint256 newBufferCap) internal {
-   _updateBufferStored();
    uint256 oldBufferCap = bufferCap;
    bufferCap = newBufferCap;

+   _updateBufferStored();

    emit BufferCapUpdate(oldBufferCap, newBufferCap);
}

ElliotFriedman (Volt) confirmed


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

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 order of operations is wrong: the buffer is updated using the old cap before the new cap is set, so the new cap is not enforced on the updated buffer.

Impact

Actions consuming more than the new buffer cap could be performed.

What the attacker needed

None

The fix

The buffer should be updated after setting the new cap, as shown in the recommended mitigation.

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 buffer cap is a limit on how much can be used in a period. The code changes the limit but forgets to check the current usage against the new limit, so usage can stay above the new limit. This lets someone use more than the new limit allows.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by cmichel

View all

196 more disclosed reports, best first.

More from Volt Protocol contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.