Crates.io | sigop |
lib.rs | sigop |
version | 0.1.0 |
source | src |
created_at | 2022-09-23 04:22:40.868113 |
updated_at | 2022-09-23 04:22:40.868113 |
description | A A tool to optimize your Solidity function signatures. |
homepage | |
repository | https://github.com/quartz-technology/sigop |
max_upload_size | |
id | 672126 |
size | 40,898 |
A CLI tool to optimize your Solidity function signatures. I wanted to create this after seeing transmissions11's comment about this optimization.
Inspired by the great work of emn178.
The optimizer takes a function signature such as myFunction(address)
and tries to combine it with
a suffix generated from a dictionary.
For each combination, the 4-bytes function selector is computed and verified : if it contains a specified number of zeros at the beginning, the optimization has been found.
Installing from cargo:
cargo install sigop
Or building locally from source:
make build-release
./target/release/sigop -s "myFunction(address)"
Which should print:
[2022-09-23T04:06:03Z INFO sigop::optimizer] Found this optimization: myFunction_6mI(address)
Using cast
, we can see the optimized function selector:
$ cast sig "myFunction_6mI(address)"
0x00001926
You can specify custom parameters used by the optimizer:
length
: The maximum size of the suffix following the original function name.target
: The number of zero-bytes you want to have at the beginning of the optimized function
selector.Example:
$ sigop -s "myFunction(address)" --length=4 --target=3
[2022-09-23T04:06:26Z INFO sigop::optimizer] Found this optimization: myFunction_LYq3(address)
$ cast sig "myFunction_LYq3(address)"
0x0000006d
Using Remix, we can track the gas cost of calling these functions:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.14;
contract Test {
// Execution cost : 22132
function myFunction(address a) public pure returns (address) {
return a;
}
// Execution cost : 22074
function myFunction_LYq3(address a) public pure returns (address) {
return a;
}
}
Made with ❤️ by 🤖 Luca Georges François 🤖