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: 39/88
Findings: 2
Award: $65.42
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0x1f8b
Also found by: 0xSmartContract, 0xc0ffEE, Aymen0909, B2, Deivitto, Josiah, KingNFT, Rahoz, RaymondFam, RedOneN, ReyAdmirado, Trust, ajtra, aviggiano, brgltd, c7e7eff, cryptonue, ctf_sec, delfin454000, djxploit, lukris02, peanuts, rvierdiiev, shark, simon135, slowmoses, tnevler, trustindistrust
44.2869 USDC - $44.29
Issue | Risk | Instances | |
---|---|---|---|
1 | Auction can be created with zero totalBaseAmount | Low | 1 |
2 | Named return variables not used anywhere in the functions | NC | 2 |
3 | constant should be defined rather than using magic numbers | NC | 4 |
totalBaseAmount
:In the createAuction
function a user can start a new auction without transferring any baseToken
, this is possible because there are no checks on the values of auctionParams
, one of them being totalBaseAmount
which could be set to zero. This will create an auction with zero base tokens and bidders will still be able to bid on it but in the end no fund will be distributed.
Instances include:
File: src/SizeSealed.sol Line 98-100
SafeTransferLib.safeTransferFrom( ERC20(auctionParams.baseToken), msg.sender, address(this), auctionParams.totalBaseAmount );
Add a check in the createAuction
function to verify that the totalBaseAmount
of the auction is not equal to 0.
When Named return variable are declared they should be used inside the function instead of the return statement or if not they should be removed to avoid confusion.
Instances include:
File: src/SizeSealed.sol
returns (uint128 tokensAvailable)
File: src/util/ECCMath.sol
returns (bytes32 decryptedMessage)
Either use the named return variables inplace of the return statement or remove them.
constant
should be defined rather than using magic numbers :It is best practice to use constant variables rather than hex/numeric literal values to make the code easier to understand and maintain, but if they are used those numbers should be well docummented.
Instances include:
File: src/SizeSealed.sol
File: src/util/ECCMath.sol
Replace the hex/numeric literals aforementioned with constants
.
#0 - c4-judge
2022-11-10T02:53:25Z
0xean marked the issue as grade-b
🌟 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
Issue | Instances | |
---|---|---|
1 | Using storage pointer to a struct cost more gas tham memory when it's values are called multiple times | 3 |
2 | x += y/x -= y costs more gas than x = x + y/x = x - y for state variables | 1 |
3 | Use calldata instead of memory for function parameters type | 1 |
4 | ++i/i++ should be unchecked{++i} /unchecked{i++} when it is not possible for them to overflow, as in the case when used in for & while loops | 2 |
storage
pointer to a struct cost more gas tham memory
when it's values are called multiple times :In general using the storage keyword instead of memory for reading from struct/array/mapping cost less gas, but this is only true if you don't need to read all or many members multiple times.
There are 3 instances of this issue:
File: src/SizeSealed.sol Line 181
Auction storage a = idToAuction[auctionId];
File: src/SizeSealed.sol Line 359
Auction storage a = idToAuction[auctionId];
File: src/SizeSealed.sol Line 418
Auction storage a = idToAuction[auctionId];
x += y/x -= y
costs more gas than x = x + y/x = x - y
for state variables :Using the addition operator instead of plus-equals saves 113 gas as explained here
There is 1 instance of this issue:
File: src/SizeSealed.sol Line 373
b.baseWithdrawn += baseTokensAvailable;
calldata
instead of memory
for function parameters type :If a reference type function parameter is read-only, it is cheaper in gas to use calldata instead of memory. Calldata is a non-modifiable, non-persistent area where function arguments are stored, and behaves mostly like memory.
There is 1 instance of this issue:
File: src/SizeSealed.sol Line 217
function finalize(uint256 auctionId, uint256[] memory bidIndices, uint128 clearingBase, uint128 clearingQuote)
++i/i++
should be unchecked{++i}/unchecked{i++}
when it is not possible for them to overflow, as in the case when used in for & while loops :There are 2 instances of this issue:
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++)
#0 - c4-judge
2022-11-10T02:10:17Z
0xean marked the issue as grade-b