quartz-technology / sigop

๐Ÿ–‹๏ธ A fun tool to optimize your Solidity function signatures ๐Ÿ–‹๏ธ

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sigop

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.

๐Ÿงช How does it work ?

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.

๐Ÿš€ Getting started !

โš™๏ธ Installation

Installing from cargo:

cargo install sigop

Or building locally from source:

make build-release

๐Ÿ Quickstart

./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

โœ๏ธ Custom parameters

You can specify custom parameters used by the optimizer:

  1. length: The maximum size of the suffix following the original function name.
  2. 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

Results

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;
    }
}

๐Ÿค– Author

Made with โค๏ธ by ๐Ÿค– Luca Georges Franรงois ๐Ÿค–

About

๐Ÿ–‹๏ธ A fun tool to optimize your Solidity function signatures ๐Ÿ–‹๏ธ

License:MIT License


Languages

Language:Rust 97.0%Language:Makefile 3.0%