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: 43/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
indexed
fieldsEach event should use three indexed fields if there are three or more fields.
event AuctionCreated( uint256 auctionId, address seller, AuctionParameters params, Timings timings, bytes encryptedPrivKey
File: src/interfaces/ISizeSealed.sol (line 97-98)
event Bid( address sender, uint256 auctionId, uint256 bidIndex, uint128 quoteAmount, bytes32 commitment, ECCMath.Point pubKey, bytes32 encryptedMessage, bytes encryptedPrivateKey
File: src/interfaces/ISizeSealed.sol (line 103-111)
Other instances of this issue are:
block.timestamp
Block timestamps have historically been used for a variety of applications, such as entropy for random numbers, locking funds for periods of time, and various state-changing conditional statements that are time-dependent. Miners have the ability to adjust timestamps slightly, which can prove to be dangerous if block timestamps are used incorrectly in smart contracts.
if (block.timestamp < a.timings.startTimestamp) {
File: src/SizeSealed.sol (line 29)
} else if (block.timestamp < a.timings.endTimestamp) {
File: src/SizeSealed.sol (line 31)
Other instances of this issue are:
///@audit: @`runnning` /// @notice Bid on a runnning auction
File: src/SizeSealed.sol (line 112)
///@audit: @`futher` // Prevent any futher access to this EncryptedBid
File: src/SizeSealed.sol (line 431)
revert()
should have descriptive reason strings30 if (_state != States.Created) revert InvalidState(); 32 if (_state != States.AcceptingBids) revert InvalidState(); 34 if (_state != States.Finalized) revert InvalidState(); 36 if (_state != States.RevealPeriod) revert InvalidState(); 38 if (_state != States.Voided) revert InvalidState(); 40 revert();
File: src/SizeSealed.sol (https://github.com/code-423n4/2022-11-size/blob/main/src/SizeSealed.sol)
All revert()
in the file src/SizeSealed.sol
lacks descriptive reason strings .
uints/ints
smaller than 32 bytes (256 bits) incurs overheadWhen using elements that are smaller than 32 bytes, your contract’s gas usage may be higher. This is because the EVM operates on 32 bytes at a time. Therefore, if the element is smaller than that, the EVM must use more operations in order to reduce the size of the element from 32 bytes to the desired size.
uint128 quoteAmount,
File: src/SizeSealed.sol (line 124)
uint32 startTimestamp; uint32 endTimestamp; uint32 vestingStartTimestamp; uint32 vestingEndTimestamp;
File: src/interfaces/ISizeSealed.sol(line 56-59)
Other instances of this issue are:
NatSpec
is incomplete/// @audit Missing: '@param:auctionId` /// @notice Reveals the private key of the seller /// @dev All valid bids are decrypted after this /// finalizeData should be empty if seller does not wish to finalize in this tx /// @param privateKey Private key corresponding to the auctions public key /// @param finalizeData Calldata that will be sent to finalize() function reveal(uint256 auctionId, uint256 privateKey, bytes calldata finalizeData)
/// @audit Missing: '@return` /// @notice calculates point^scalar /// @dev returns (1,1) if the ecMul failed or invalid parameters /// @return corresponding point function ecMul(Point memory point, uint256 scalar) internal view returns (Point memory) {
Other instances of this issue are:
@retun
@retun
@retun
&@param
@retun
&@param
#0 - c4-judge
2022-11-10T02:52:56Z
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
calldata
instead of memory
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.
Try to use calldata as a data location because it will avoid copies and also makes sure that the data cannot be modified.
function encryptMessage(Point memory encryptToPub, uint256 encryptWithPriv, bytes32 message)
File: src/util/ECCMath.sol (line 37)
function decryptMessage(Point memory sharedPoint, bytes32 encryptedMessage)
File: src/util/ECCMath.sol (line 51)
Other instances of this issue are:
unchecked
to save gasbaseAmount - cliffAmount, currentTime - vestingStart, vestingEnd - vestingStart
File: src/util/CommonTokenMath.sol (line 65)
return
Using both named returns and a return statement isn’t necessary. Removing one of those can improve code clarity:
return encryptedMessage ^ hashPoint(sharedPoint);
File: src/util/ECCMath.sol (line 56)
return CommonTokenMath.tokensAvailableAtTime(
File: src/SizeSealed.sol (line 56)
internal
functions only called once can be inlined
to save gasNot inlining costs 20 to 40 gas because of two extra JUMP instructions and additional stack operations needed for function calls.
function encryptMessage(Point memory encryptToPub, uint256 encryptWithPriv, bytes32 message) internal
File: src/util/ECCMath.sol (line 37-38)
a.timings
to save gasa.timings
is used multiple times cache it in a memory variable to save gas.
///@audit: `a.timings` is used more than one time if (block.timestamp < a.timings.startTimestamp) { if (_state != States.Created) revert InvalidState(); } else if (block.timestamp < a.timings.endTimestamp) { if (_state != States.AcceptingBids) revert InvalidState(); } else if (a.data.lowestQuote != type(uint128).max) { if (_state != States.Finalized) revert InvalidState(); } else if (block.timestamp <= a.timings.endTimestamp + 24 hours) { if (_state != States.RevealPeriod) revert InvalidState(); } else if (block.timestamp > a.timings.endTimestamp + 24 hours) {
File: src/SizeSealed.sol (line 29-37)
internal
functions not called by the contract should be removed to save deployment gasfunction decryptMessage(Point memory sharedPoint, bytes32 encryptedMessage) internal
File: src/util/ECCMath.sol (line 51-52)
abi.encode()
is less efficient than abi.encodePacked()
return keccak256(abi.encode(message));
File: src/SizeSealed.sol (line 467)
#0 - c4-judge
2022-11-10T02:08:29Z
0xean marked the issue as grade-b