Submitted by bart1e, also found by bart1e, Udsen, shaka, deth, 0xDING99YA, peanuts, 0xAsen, 00xSEV, nmirchev8, ke1caM, Timenov, _eperezok, and fnanni
https://github.com/code-423n4/2023-12-revolutionprotocol/blob/d42cc62b873a1b2b44f57310f9d4bbfdd875e8d6/packages/revolution/src/AuctionHouse.sol#L378 
https://github.com/code-423n4/2023-12-revolutionprotocol/blob/d42cc62b873a1b2b44f57310f9d4bbfdd875e8d6/packages/revolution/src/AuctionHouse.sol#L394 
https://github.com/code-423n4/2023-12-revolutionprotocol/blob/d42cc62b873a1b2b44f57310f9d4bbfdd875e8d6/packages/revolution/src/AuctionHouse.sol#L400 
https://github.com/code-423n4/2023-12-revolutionprotocol/blob/d42cc62b873a1b2b44f57310f9d4bbfdd875e8d6/packages/revolution/src/ERC20TokenEmitter.sol#L212 
https://github.com/code-423n4/2023-12-revolutionprotocol/blob/d42cc62b873a1b2b44f57310f9d4bbfdd875e8d6/packages/revolution/src/ERC20TokenEmitter.sol#L109 
https://github.com/code-423n4/2023-12-revolutionprotocol/blob/d42cc62b873a1b2b44f57310f9d4bbfdd875e8d6/packages/revolution/src/NontransferableERC20Votes.sol#L131 
https://github.com/code-423n4/2023-12-revolutionprotocol/blob/d42cc62b873a1b2b44f57310f9d4bbfdd875e8d6/packages/revolution/src/base/erc20/ERC20Upgradeable.sol#L232 
https://github.com/code-423n4/2023-12-revolutionprotocol/blob/d42cc62b873a1b2b44f57310f9d4bbfdd875e8d6/packages/revolution/src/base/erc20/ERC20VotesUpgradeable.sol#L62 
https://github.com/code-423n4/2023-12-revolutionprotocol/blob/d42cc62b873a1b2b44f57310f9d4bbfdd875e8d6/packages/revolution/src/base/VotesUpgradeable.sol#L222 
https://github.com/code-423n4/2023-12-revolutionprotocol/blob/d42cc62b873a1b2b44f57310f9d4bbfdd875e8d6/packages/revolution/src/base/VotesUpgradeable.sol#L227 
https://github.com/code-423n4/2023-12-revolutionprotocol/blob/d42cc62b873a1b2b44f57310f9d4bbfdd875e8d6/packages/revolution/src/base/VotesUpgradeable.sol#L245-L249
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*.
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.
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:
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):
In order to make _settleAuction as costly as possible, attacker can do several things:
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.
If the attack is able to cause _settleAuction to reach block gas limit, AuctionHouse will be DoSed as it wont be possible to settle auctions.
While its not the case at the moment (attacker can now reach 20 000 000), I will now demonstrate why its problematic even right now:
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:
Hence, I believe that Medium severity is appropriate for this issue.
First of all, please modify the code in the AuctionHouse::_settleAuction in the following way:
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 wont be possible to calculate precisely the impact of the described attack).
Then, please put the following contract definition in AuctionSettling.t.sol:
Then, please put the following code in AuctionSettling.t.sol and run the test (import "forge-std/console.sol"; will be needed as well):
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.
VS Code
Consider limiting the number of creators that may be specified.
Alternatively, dont 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.
0xTheC0der (Judge) commented:
