Platform: Code4rena
Start Date: 04/11/2022
Pot Size: $42,500 USDC
Total HM: 9
Participants: 88
Period: 4 days
Judge: 0xean
Total Solo HM: 2
Id: 180
League: ETH
Rank: 66/88
Findings: 1
Award: $21.13
π Selected for report: 0
π Solo Findings: 0
π Selected for report: 0x1f8b
Also found by: 0xSmartContract, 0xdeadbeef, Aymen0909, B2, Bnke0x0, Deivitto, Diana, Dinesh11G, JC, RaymondFam, ReyAdmirado, Rolezn, Sathish9098, TomJ, ajtra, aviggiano, chaduke, cryptostellar5, djxploit, gianganhnguyen, gogo, halden, karanctf, leosathya, lukris02, mcwildy, oyc_109, ret2basic, skyle, slowmoses
21.132 USDC - $21.13
Solidity version 0.8+ comes with implicit overflow and underflow checks on unsigned integers. When an overflow or an underflow isnβt possible (as an example, when a comparison is made before the arithmetic operation), some gas can be saved by using an unchecked block
File src/SizeSealed.sol, line 244: for (uint256 i; i < bidIndices.length; i++) { File src/SizeSealed.sol, line 302: for (uint256 i; i < seenBidMap.length - 1; i++) {
The code would go from:
for (uint256 i; i < numIterations; i++) { ... }
to:
for (uint256 i; i < numIterations;) { ... unchecked { ++i; } }
File src/SizeSealed.sol, line 337, 359, 418, 456: Auction storage a = idToAuction[auctionId]; // I suggest code replace: Auction memory a = idToAuction[auctionId];
calldata
because calldata
is more gas efficient than memory
.I suggest using calldata
instead of memory
here:
File src/SizeSealed.sol, line 217: function finalize(uint256 auctionId, uint256[] memory bidIndices, uint128 clearingBase, uint128 clearingQuote) File src/util/ECCMath.sol, line 25: function ecMul(Point memory point, uint256 scalar) File src/util/ECCMath.sol, line 37: function encryptMessage(Point memory encryptToPub, uint256 encryptWithPriv, bytes32 message) File src/util/ECCMath.sol, line 51: function decryptMessage(Point memory sharedPoint, bytes32 encryptedMessage) File src/util/ECCMath.sol, line 60: function hashPoint(Point memory point)
Solidity version 0.8+ comes with implicit overflow and underflow checks on unsigned integers. When an overflow or an underflow isn't possible, some gas can be saved by using an unchecked
block.
I suggest wrapping with an unchecked
block here:
File src/SizeSealed.sol, line 84: uint256 auctionId = ++currentAuctionId; File src/SizeSealed.sol, line 249: uint256 bitmapIndex = bidIndex / 256; File src/SizeSealed.sol, line 251: uint256 indexBit = 1 << (bidIndex % 256); File src/SizeSealed.sol, line 378: uint256 refundedQuote = b.quoteAmount - quoteBought;
#0 - c4-judge
2022-11-10T02:19:08Z
0xean marked the issue as grade-b