BondAggregator.liveMarketsBy eventually will revert because of block gas limit
The BondAggregator contract's view functions, such as liveMarketsBy, iterate over all markets without pagination, causing gas costs to grow with each new market. Eventually, the gas required exceeds the block gas limit, making these functions always revert and preventing users from retrieving market information.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-11-bond-judging/issues/10
Found by
rvierdiiev
Summary
BondAggregator.liveMarketsBy eventually will revert because of block gas limit
Vulnerability Detail
https://github.com/sherlock-audit/2022-11-bond/blob/main/src/BondAggregator.sol#L259-L280
function liveMarketsBy(address owner_) external view returns (uint256[] memory) {
uint256 count;
IBondAuctioneer auctioneer;
for (uint256 i; i < marketCounter; ++i) {
auctioneer = marketsToAuctioneers[i];
if (auctioneer.isLive(i) && auctioneer.ownerOf(i) == owner_) {
++count;
}
}
uint256[] memory ids = new uint256[](count);
count = 0;
for (uint256 i; i < marketCounter; ++i) {
auctioneer = marketsToAuctioneers[i];
if (auctioneer.isLive(i) && auctioneer.ownerOf(i) == owner_) {
ids[count] = i;
++count;
}
}
return ids;
}
BondAggregator.liveMarketsBy function is looping through all markets and does at least marketCounter amount of external calls(when all markets are not live) and at most 4 * marketCounter external calls(when all markets are live and owner matches. This all consumes a lot of gas, even that is called from view function. And each new market increases loop size.
That means that after some time marketsToAuctioneers mapping will be big enough that the gas amount sent for view/pure function will be not enough to retrieve all data(50 million gas according to this). So the function will revert.
Also similar problem is with findMarketFor, marketsFor and liveMarketsFor functions.
Impact
Functions will always revert and whoever depends on it will not be able to get information.
Code Snippet
Provided above
Tool used
Manual Review
Recommendation
Remove not active markets or some start and end indices to functions.
Discussion
Evert0x
Message from sponsor
Agree. We added start and stop indices to the BondAggregator.liveMarketsBy function to allow pagination through the bond markets and avoid the block gas limit.
xiaoming9090
Fixed in https://github.com/Bond-Protocol/bonds/commit/5a2a9a982f3bdfc31d22f72d270bf2d556096281
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 view functions loop over all markets without any pagination, so gas usage grows linearly with the number of markets and eventually exceeds the block gas limit.
Impact
The affected functions will always revert, so any user or contract relying on them cannot retrieve market information.
What the attacker needed
Many markets created over time
The fix
The functions were fixed by adding start and stop indices to allow pagination through the markets, avoiding the block gas limit.
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 has functions that read data, like listing all markets owned by someone. These functions loop through every market ever created, so as more markets are added, the loop gets longer and uses more gas. Eventually, the gas needed is more than the network allows in a single call, so the function fails and no one can get the data.
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.