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.
Submitted by cmichel, also found by rayn and catchup
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
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.