Platform: Code4rena
Start Date: 11/11/2022
Pot Size: $36,500 USDC
Total HM: 5
Participants: 62
Period: 3 days
Judge: berndartmueller
Id: 181
League: ETH
Rank: 54/62
Findings: 1
Award: $22.22
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: ReyAdmirado
Also found by: 0x4non, 0xRoxas, 0xab00, Awesome, Aymen0909, Bnke0x0, Deivitto, Diana, IllIllI, Rahoz, RaymondFam, Rolezn, Sathish9098, ajtra, aphak5010, aviggiano, c3phas, carlitox477, ch0bu, cryptostellar5, erictee, lukris02, martin, rotcivegaf, saian, shark, trustindistrust, zaskoh
22.2155 USDC - $22.22
Number of Instances Identified: 3
The unchecked
keyword is new in solidity version 0.8.0, so this only applies to that version or higher, which these instances are.
https://github.com/code-423n4/2022-11-non-fungible/blob/main/contracts/Exchange.sol
184: for (uint8 i = 0; i < executionsLength; i++) { 307: for (uint8 i = 0; i < orders.length; i++) { 598: for (uint8 i = 0; i < fees.length; i++) {
Number of Instances Identified: 6
Not inlining costs 20 to 40 gas because of two extra JUMP
instructions and additional stack operations needed for function calls.
https://github.com/code-423n4/2022-11-non-fungible/blob/main/contracts/Exchange.sol
440: function _validateUserAuthorization 471: function _validateOracleAuthorization 537: function _canMatchOrders(Order calldata sell, Order calldata buy) 565: function _executeFundsTransfer 591: function _transferFees 653: function _executeTokenTransfer
Number of Instances Identified: 7
https://github.com/code-423n4/2022-11-non-fungible/blob/main/contracts/Exchange.sol
316: nonces[msg.sender] += 1; 574: remainingETH -= price; 601: totalFee += fee;
https://github.com/code-423n4/2022-11-non-fungible/blob/main/contracts/Pool.sol
36: _balances[msg.sender] += msg.value; 46: _balances[msg.sender] -= amount; 73: _balances[from] -= amount; 74: _balances[to] += amount;
Number of Instances Identified: 1
modifier internalCall()
is only used once for function _execute
, hence it can be inlined to save gas
https://github.com/code-423n4/2022-11-non-fungible/blob/main/contracts/Exchange.sol
48: modifier internalCall()
Number of Instances Identified: 4
Each extra chunk of bytes past the original 32 incurs an MSTORE which costs 3 gas.
https://github.com/code-423n4/2022-11-non-fungible/blob/main/contracts/Exchange.sol
49: require(isInternal, "This function should not be called directly"); 295: require(!cancelledOrFilled[hash], "Order already cancelled or filled"); 604: require(totalFee <= price, "Total amount of fees are more than the price");
https://github.com/code-423n4/2022-11-non-fungible/blob/main/contracts/Pool.sol
63: revert('Caller is not authorized to transfer');
Number of Instances Identified: 1
Removing unused named returns variables can reduce gas usage (MSTOREs/MLOADs) and improve code clarity. To save gas and improve code quality: consider using only one of those.
https://github.com/code-423n4/2022-11-non-fungible/blob/main/contracts/Exchange.sol
540: returns (uint256 price, uint256 tokenId, uint256 amount, AssetType assetType)
Number of Instances Identified: 3
When 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.
https://docs.soliditylang.org/en/v0.8.11/internals/layout_in_storage.html Use a larger size then downcast where needed
https://github.com/code-423n4/2022-11-non-fungible/blob/main/contracts/Exchange.sol
184: for (uint8 i = 0; i < executionsLength; i++) { 307: for (uint8 i = 0; i < orders.length; i++) { 598: for (uint8 i = 0; i < fees.length; i++) {
#0 - c4-judge
2022-11-17T14:14:47Z
berndartmueller marked the issue as grade-b