ardislu / code4rena-gas-test

A simple smart contract to test the effectiveness of common code4rena gas optimizations.

Home Page:https://ardislu.dev/checking-code4rena-gas-optimizations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

code4rena-gas-test

Update October 2023: starting in Solidity 0.8.22, the G011 ("Unnecessary checked arithmetic in for loop") gas optimization is performed automatically by the solc compiler! So the unchecked block can be dropped:

+ for (uint256 i; i < len; ++i) {
- for (uint256 i; i < len; ) {
-   unchecked { ++i; }
}

Other gas optimizations remain the same however.


A simple smart contract to test the effectiveness of common code4rena gas optimizations.

Specifically:

  • G001 - Don't Initialize Variables with Default Value
  • G002 - Cache Array Length Outside of Loop
  • G011 - Unnecessary checked arithmetic in for loop
  • G012 - Use Prefix Increment instead of Postfix Increment if possible

Use Echidna to run the test:

echidna GasTest.sol --config echidna.yaml

About

A simple smart contract to test the effectiveness of common code4rena gas optimizations.

https://ardislu.dev/checking-code4rena-gas-optimizations


Languages

Language:Solidity 100.0%