A set of benchmarks to evaluate Solidity compiler optimizations.
Each benchmark is composed by one Solidity file containing one or many contracts and libraries with the code being executed. Additionally, each folder contains a JS test file to execute the tests using a development network (Hardhat).
This simple benchmark contains a single Solidity contracts with one function adding up the values of two storage array into another storage array.
This benchmark contains two Solidity contracts implementing a integer array management library (UintArray and IntArray). In addition to that, it contains the contract TestArray composed of one instance of each array contract and several funtions to test the libraries.
Libraries source: https://github.com/alianse777/solidity-standard-library
This benchmark contains Solidity libraries for matrix and vector management (VectorUtils and MatrixUtils). In addition to that, it contains the contract TestSortLib containing several funtions to test the library.
Library source: https://github.com/NTA-Capital/SolMATe
This benchmark contains a Solidity library implementing different array sorting methods. In addition to that, it contains the contract TestArray composed of one instance of each array contract and several funtions to test the libraries.
The benchmarks can be executed using the Hardhat development enviroment on Linux and MacOS computers. Folder hardhatEnvironment
includes a Hardhat project with the smart contracts cource code and tests needed to run the benchmark.
In order to execute the benchmark using the provided Hardhat project we must:
- Install Node.js on your computer.
- Install Hardhat on the computer using the Hardhat installation guide.
- Intall the Hardhat gas reporter tool using the command
npm install hardhat-gas-reporter --save-dev
.
In order to executeute the execute the benchmark tests we have to:
- Open the terminal on the
hardhatEnvironment
folder. - Compile the contracts with command
npx hardhat compile
. - Execute the command
npx hardhat test
. If we want to only execute one specific test suite you can use the commandnpx hardhat test test/<suite>.js
. In the case we wanted to execute the tests for the Sort library, we should executenpx hardhat test test/SortLibTests.js
.
This will execute the test over the smart contracts compiled using the version of the Solidity compiler set as default by Hardhat.
In order to execute the tests over smart contracts compiled using any compiler version of the Solidity compiler, including experimental versions, we provide the script contractArtifacts.sh
. This script will compile the specified source code and create the corresponding artifacts to exetute them in Hardhat.
In order to compile the smart contracts using a custom Solidity compiler we must:
- Open a tetminal,
- Execute
chmod +x contractArtifacts.sh
. - Execute
./contractArtifacts.sh <source_file> [<optimization_options>]
, where:
source_file
is the path to the Solidity source file containing the contracts and libraries being executed.- If we want to apply any optimization,
optimization_options
is the list of the compiler optimization options, as specified by the compiler documentation.
Doing this we will be compiling the source code usign the compiler version set as default on our computer (solc --version
). If we want to compile using a different version, especially if we want to use an experimental or customized verison, we have to specify the absolute path to the compiler executable (solc
):
./contractArtifacts.sh -c <path_solc> <source_file> [<optimization_options>]
.
Then, we have to copy the hardhat artifacts to the artifacts folder of the environment. To do so we must:
- Open the
artifacts/contracts
folder generated by thecontractArtifacts
script. - Copy the folder
<contract_name>.sol/
. - Paste the copied folder into
hardhatEnvironment/artifacts/contracts
.