Platform: Code4rena
Start Date: 14/06/2022
Pot Size: $50,000 USDC
Total HM: 19
Participants: 99
Period: 5 days
Judge: HardlyDifficult
Total Solo HM: 4
Id: 136
League: ETH
Rank: 90/99
Findings: 1
Award: $33.03
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: IllIllI
Also found by: 0v3rf10w, 0x1f8b, 0x29A, 0xAsm0d3us, 0xDjango, 0xKitsune, 0xNazgul, 0xf15ers, 0xkatana, 0xkowloon, BowTiedWardens, Chom, ElKu, FSchmoede, Funen, GimelSec, Kaiziron, Kenshin, Lambda, MadWookie, MiloTruck, PPrieditis, Picodes, PwnedNoMore, StErMi, Tadashi, TerrierLover, TomJ, Tomio, Wayne, Waze, _Adam, antonttc, apostle0x01, asutorufos, c3phas, codexploder, defsec, delfin454000, fatherOfBlocks, hake, hansfriese, hyh, joestakey, k, kenta, oyc_109, peritoflores, reassor, rfa, robee, sach1r0, simon135, slywaters, zer0dot
33.0288 USDC - $33.03
Solidity does not recognize null as a value, so uint variables are initialized to zero. Setting a uint variable to zero is redundant and can waste gas.
Locations where this was found include https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L76 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L82 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L197 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L199 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L214 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L216 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L244 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L246 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L247 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L289 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L290 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L291 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L318 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L320 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L148 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L200 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L219 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L272 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L308 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L349 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L393 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1048 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1086 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1109 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1190 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1206
Remove the redundant zero initialization
uint256 i;
instead of uint256 i = 0;
Combining require statement conditions with && logic uses unnecessary gas. It is better to split up each part of the logical statement into a separate require statements
Locations where this was found include https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L264 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L949
Use separate require statements instead of concatenating with &&
abi.encodePacked()
not abi.encode()
Changing abi.encode
to abi.encodePacked
can save gas. abi.encode
pads extra null bytes at the end of the call data which is normally unnecessary. In general, abi.encodePacked
is more gas-efficient.
Locations where this was found include https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L107 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1173 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1191 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1207
Change abi.encode
to abi.encodePacked
Using > 0
uses slightly more gas than using != 0
. Use != 0
when comparing uint variables to zero, which cannot hold values below zero
Locations where this was found include https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L392
Replace > 0
with != 0
to save gas
Strings in solidity are handled in 32 byte chunks. A require string longer than 32 bytes uses more gas. Shortening these strings will save gas.
Locations where this was found include https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L395 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L96
Shorten all require strings to less than 32 characters
For loops that use i++ do not need to use safemath for this operation because the loop would run out of gas long before this point. Making this addition operation unsafe using unchecked saves gas.
Sample code to make the for loop increment unsafe
for (uint i = 0; i < length; i = unchecked_inc(i)) { // do something that doesn't change the value of i } function unchecked_inc(uint i) returns (uint) { unchecked { return i + 1; } }
Idea borrowed from https://gist.github.com/hrkrshnn/ee8fabd532058307229d65dcd5836ddc#the-increment-in-for-loop-post-condition-can-be-made-unchecked
Locations where this was found include https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L85 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L97 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L202 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L219 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L251 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L260 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L264 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L297 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L303 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L307 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L323 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L166 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L213 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L227 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L291 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L320 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L356 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L398 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1051 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1089 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1113 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1194 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1210
Make the increment in for loops unsafe to save gas
Comparing a value to zero can be done using the iszero
EVM opcode. This can save gas
Source from t11s https://twitter.com/transmissions11/status/1474465495243898885
Locations where this was found include https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L104 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L264 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L240 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L286 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L334 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1157
Use the assembly iszero
evm opcode to compare values to zero
Use unchecked math when there is no overflow risk to save gas. Before index is decreased in remove it is checked for zero condition. This means index will not underflow and can be unchecked.
Locations where this was found include https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L268 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L301 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L305 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L309
Add unchecked around math that can't overflow for gas savings. In Solidity before 0.8.0, use the normal math operators instead of safe math functions.
Identifying a function as payable saves gas. Functions that have a modifier like onlyOwner cannot be called by normal users and will not mistakenly receive ETH. These functions can be payable to save gas.
Locations where this was found include https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L345 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L351 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L368 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L375 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1224 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1229 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1235 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1240 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1245 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1250 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1255 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1260 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1266
Add payable to these functions for gas savings
Identifying a constructor as payable saves gas. Constructors should only be called by the admin or deployer and should not mistakenly receive ETH. Constructors can be payable to save gas.
Locations where this was found include https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L49 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/TimelockConfig.sol#L43 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/InfinityToken.sol#L37 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L104
Add payable to these functions for gas savings
An internal function can save gas vs. a modifier. A modifier inlines the code of the original function but an internal function does not.
Locations where this was found include https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/TimelockConfig.sol#L38
Use internal functions in place of modifiers to save gas.
Booleans are more expensive than uint256 or any type that takes up a full word because each write operation emits an extra SLOAD to first read the slot's contents, replace the bits taken up by the boolean, and then write back. This is the compiler's defense against contract upgrades and pointer aliasing, and it cannot be disabled.
Locations where this was found include https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L346 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/TimelockConfig.sol#L80 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/TimelockConfig.sol#L98 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L32 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L38 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L42 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L73 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L74 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L101 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L108 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L133 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L254 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L151 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L274 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L304 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L311 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L345 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L442 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L462 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L466 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L468 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L497 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L515 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L519 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L947 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L948 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L967 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L992 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1140 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1230 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/libs/OrderTypes.sol#L24 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/libs/OrderTypes.sol#L47
Replace bool variables with uints
From the solidity docs
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.
Locations where this was found include https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L33 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L34 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L35 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L36 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L40 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L41 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L42 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L351 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L365 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L366 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L367 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/TimelockConfig.sol#L39 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/TimelockConfig.sol#L44 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/InfinityToken.sol#L114 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L61 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L63 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L82 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L83 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L145 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L146 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L196 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L197 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L269 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L270 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L423 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L518 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L579 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L580 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L616 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L617 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L646 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L678 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L679 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L719 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L720 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L770 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L771 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L816 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L869 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L870 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1260 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L1266 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/libs/SignatureChecker.sol#L23 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/libs/SignatureChecker.sol#L56
Replace bool variables with uints
Solidity errors introduced in version 0.8.4 can save gas on revert conditions https://blog.soliditylang.org/2021/04/21/custom-errors/ https://twitter.com/PatrickAlphaC/status/1505197417884528640
Locations where this was found include https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L68 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L69 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L91 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L92 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L96 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L117 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L123 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L193 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L347 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/TimelockConfig.sol#L39 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/TimelockConfig.sol#L51 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/TimelockConfig.sol#L52 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/TimelockConfig.sol#L94 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/TimelockConfig.sol#L112 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/TimelockConfig.sol#L119 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/TimelockConfig.sol#L127 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/InfinityToken.sol#L61 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/InfinityToken.sol#L62 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/InfinityToken.sol#L63 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityOrderBookComplication.sol#L255 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L138 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L139 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L150 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L155
Replace require blocks with new solidity errors described in https://blog.soliditylang.org/2021/04/21/custom-errors/
The comparison operators >= and <= use more gas than >, <, or ==. Replacing the >= and ≤ operators with a comparison operator that has an opcode in the EVM saves gas
The existing code is https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/staking/InfinityStaker.sol#L270
return secondsSinceStake >= durationInSeconds ? amount : 0;
A simple comparison can be used for gas savings by reversing the logic
return secondsSinceStake < durationInSeconds ? 0 : amount;
Replace the comparison operator and reverse the logic to save gas using the suggestions above
The comparison operators >= and <= use more gas than >, <, or ==. Replacing the >= and ≤ operators with a comparison operator that has an opcode in the EVM saves gas
The existing code is https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L311-L312
bool isTimeValid = makerOrders[i].constraints[3] <= block.timestamp && makerOrders[i].constraints[4] >= block.timestamp;
A simple comparison can be used for gas savings by reversing the logic
bool isTimeValid = ! (makerOrders[i].constraints[3] > block.timestamp || makerOrders[i].constraints[4] < block.timestamp);
Replace the comparison operator and modify the logic to save gas using the suggestions above
Many constant variables are public, but changing the visibility of these variables to private or internal can save gas. The TimelockConfig constants especially can be private variables.
Locations where this was found include https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/TimelockConfig.sol#L9 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/TimelockConfig.sol#L10 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/InfinityToken.sol#L25 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/InfinityToken.sol#L26 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/InfinityToken.sol#L27 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/token/InfinityToken.sol#L28 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L55 https://github.com/code-423n4/2022-06-infinity/tree/main/contracts/core/InfinityExchange.sol#L57
Declare some public variables as private or internal to save gas
The contracts are all written entirely in solidity. Writing contracts with vyper instead of solidity can save gas.
Source https://twitter.com/eiber_david/status/1515737811881807876 doggo demonstrates https://twitter.com/fubuloubu/status/1528179581974417414?t=-hcq_26JFDaHdAQZ-wYxCA&s=19
Write some or all of the contracts in vyper to save gas
#0 - nneverlander
2022-06-23T11:59:43Z
Love the comment about vyper. We want to write this in vyper in our next iteration. If you are interested in helping out, please dm me on Twitter or Discord.