unbounded loop length dos
The setPeriodSize function loops over every entry in the allPairs array, and anyone can grow that array by calling createPair. By spamming createPair, an attacker could make the loop exceed the block gas limit so that setPeriodSize always reverts, stalling that admin function.
Submitted by 0xhunter, also found by BipinSah, fatherOfBlocks, m_Rassska, oyc_109, prasantgupta52, Rohan16, rokinot, Sm4rty, and Tomo
Loops that do not have a fixed number of iterations, for example, loops that depend on storage values, have to be used carefully: Due to the block gas limit, transactions can only consume a certain amount of gas. Either explicitly or just due to normal operation, the number of iterations in a loop can grow beyond the block gas limit which can cause the complete contract to be stalled at a certain point.
By calling createPair function a pair will be pushed to allPairs array , an admin can call setPeriodSize function and set newPeriod for every pairs in allpair array , however by spamming createPair function the loop in setPeriodSize function may revert in case of hitting gas limit of the network . since there is no way to remove allPairs or decrease their length in setPeriodSize function , its possible to totally make it impossible to call the setPeriodSize function.
In order to fix the issue setPeriodSize function has to be able to become executed in multiple times in case of facing gas limit.
nivasan1 (Canto) disagreed wtih severity and commented:
Given that it is not expected for admin to change the period size in the router often, we do not consider this a high-risk vulnerability. This would also cost an infinite amount of Canto if orchestrated by a single user.
0xean (judge) decreased severity to Medium and commented:
I am not sure the frequency that this is set to be used matter, it does lead to the functionality being lost. However, I do not see it leading to a loss of user funds, so will downgrade to a medium severity.
This would also cost an infinite amt of Canto if orchestrated by a single user<- I am also not sure I understand this point. Can you explain further? What are the transaction gas limits set on this network?
@0xean, the method mentioned requires admin privileges to call it. As such, in order for an address that isn’t timelock to access this method a malicious governance proposal must be passed to call the method from timelock, or to pass governance privileges to the malicious address. Secondly, the malicious user would have to spend a significant amount of Canto in deploying and adding sufficient liquidity to the contracts desired. As such, the risk-rewards for this action makes it unclear why any user would attempt to do this.
I don’t think this is necessarily an attack vector, simply a way that the intended logic of the contracts could fail. If Canto is wildly successful there could be sufficient pairs that this would fail, I think Medium is a reasonable severity.
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 an unbounded loop over a user-growable array, so the iteration count can exceed the block gas limit and make the function always revert.
Impact
The setPeriodSize function could become permanently uncallable, though the judge noted this does not lead to loss of user funds and the sponsor argued it would cost a large amount of Canto to carry out.
What the attacker needed
Ability to call createPair; enough funds to pay gas for many calls
The fix
The setPeriodSize function should be changed so it can be executed in multiple calls when it hits the gas limit.
How it was found
- Call createPair repeatedly to push many pairs into the allPairs array.
- The admin then calls setPeriodSize, which loops over every pair in allPairs.
- Once the array is large enough, the loop exceeds the block gas limit and the call reverts.
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 is a program on a blockchain, and every action it takes costs 'gas', with a cap per transaction. This contract has a function that goes through a list of trading pairs one by one, and the list can be made longer by anyone. If the list gets long enough, the function runs out of gas and can never finish, so it stops working.
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.