DoS: claimForAllWindows() May Be Made Unusable By An Attacker
The claimForAllWindows function loops over all windows up to currentWindow, which can grow indefinitely. An attacker can repeatedly call incrementWindow by impersonating a royalty vault, causing the loop to exceed the block gas limit and making claimForAllWindows unusable.
Originally disclosed on Code4rena
Submitted by kirk-baird, also found by hyh and Ruhum
When the value of currentWindow is raised sufficiently high Splitter.claimForAllWindows() will not be able to be called due to the block gas limit.
currentWindow can only ever be incremented and thus will always increase. This value will naturally increase as royalties are paid into the contract.
Furthermore, an attacker can continually increment currentWindow by calling incrementWindow(). An attacker can impersonate a IRoyaltyVault and send 1 WEI worth of WETH to pass the required checks.
Proof of Concept
Excerpt from Splitter.claimForAllWindows() demonstrating the for loop over currentWindow that will grow indefinitely.
for (uint256 i = 0; i < currentWindow; i++) {
if (!isClaimed(msg.sender, i)) {
setClaimed(msg.sender, i);
amount += scaleAmountByPercentage(
balanceForWindow[i],
percentageAllocation
);
}
}
Splitter.incrementWindow() may be called by an attacker increasing currentWindow.
function incrementWindow(uint256 royaltyAmount) public returns (bool) {
uint256 wethBalance;
require(
IRoyaltyVault(msg.sender).supportsInterface(IID_IROYALTY),
"Royalty Vault not supported"
);
require(
IRoyaltyVault(msg.sender).getSplitter() == address(this),
"Unauthorised to increment window"
);
wethBalance = IERC20(splitAsset).balanceOf(address(this));
require(wethBalance >= royaltyAmount, "Insufficient funds");
require(royaltyAmount > 0, "No additional funds for window");
balanceForWindow.push(royaltyAmount);
currentWindow += 1;
emit WindowIncremented(currentWindow, royaltyAmount);
return true;
}
Recommended Mitigation Steps
Consider modifying the function claimForAllWindows() to instead claim for range of windows. Pass the function a startWindow and endWindow and only iterate through windows in that range. Ensure that endWindow < currentWindow.
sofianeOuafir (Joyn) confirmed, disagreed with severity and commented:
In my opinion, the severity level should be 3 (High Risk) instead of 2 (Med Risk) duplicate of #3
deluca-mike (judge) increased severity to High and commented:
While similar, I believe these issues are separate.
Issue 3 indicates that the check that
msg.senderis an authorizedRoyaltyVaultis faulty, since any contract can implement the interface and return theSplitterfromgetSplitter. While this should be fixed, as the warden suggested in the Recommended Mitigation Steps in #3, the issue raised in this issue can still occur when enough authorizedRoyaltyVaultcontracts callincrementWindow.
claimForAllWindowscan remain, but as this warden suggests, aclaimForWindows(uint256 startWindow, uint256 endWindow, uint256 percentageAllocation, bytes32[] calldata merkleProof)should exist, in caseclaimForAllWindowsbecomes prohibitively expensive, even organically (i.e.currentWindowis made very high due to sufficient authorizedincrementWindowcalls).
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 claimForAllWindows function iterates over an unbounded array (currentWindow) without a limit, and the incrementWindow function lacks proper access control, allowing an attacker to increase the array length arbitrarily.
Impact
An attacker can make claimForAllWindows permanently unusable, preventing users from claiming their royalties through that function.
What the attacker needed
Attacker can deploy a contract; Splitter has some WETH balance
The fix
The function should be modified to allow claiming for a specific range of windows (startWindow and endWindow) instead of all windows, and ensure endWindow is less than currentWindow.
How it was found
- An attacker deploys a contract that implements the IRoyaltyVault interface and returns the Splitter's address from getSplitter.
- The attacker calls incrementWindow with a small royaltyAmount (e.g., 1 WEI) after ensuring the Splitter has enough WETH balance.
- The attacker repeats this many times to increase currentWindow significantly.
- Eventually, claimForAllWindows exceeds the block gas limit and cannot be called.
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 smart contract where users claim royalties from different time windows. The function that claims all windows at once uses a loop that goes through every window ever created. An attacker can keep adding new windows, making the loop so long that it runs out of gas and the function can never be called again.
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.