An automated CLI tool that optimizes gas usage in Solidity smart contracts, focusing on storage and function call efficiency.

Overview

Solidity-Gas-Optimizoor

An high performance automated CLI tool that optimizes gas usage in Solidity smart contracts, focusing on storage and function call efficiency.

For more information on architecture and implementation, see the docs

Disclaimer:

This code is a work in progress and can contain bugs. Use it at your own risk. Feature request and bug reports are welcome.

Problem Statement:

Solidity developers need tools to help them write gas-efficient code to minimize the execution cost of smart contracts on the blockchain. While there are some linters and optimizers available, there's a lack of tools specifically designed to analyze and suggest optimizations at both the source code and intermediate representation levels.

Project Objective:

The goal of this project is to design and implement a Rust-based tool that analyzes Solidity smart contracts, identifies patterns that lead to high gas usage, and suggests or automatically applies optimizations to improve gas efficiency.

How does our tool optimize the gas of your smart contracts?

Structured Data Packing

  • Concept: Aligning struct members under 32 bytes together optimizes storage usage on the EVM.
  • Advantages: This technique minimizes the number of SLOAD or SSTORE operations, slashing storage interaction costs by 50% or more when dealing with multiple struct values within a single slot.
  • Tooling: A Rust CLI application scrutinizes Solidity struct layouts, reorganizing fields to use fewer storage slots. It respects existing comments and assumes bytes32 for unrecognized types.
  • Documentation: Structured Data Packing Guidance

Caching Storage Variables

  • Approach: Utilize local variables to cache frequently accessed storage variables, reducing the number of expensive storage reads and writes.
  • Details: Create a temporary local variable to store the value of a storage variable if it's accessed multiple times.
  • Source: Caching Storage Variables

Calldata Efficiency

  • Gas Savings: Leveraging calldata for unaltered external function inputs is more cost-effective than utilizing memory.
  • Implementation: Analyze functions to ensure that inputs declared as memory are not modified. If unmodified, convert to calldata.
  • Reference: Calldata Efficiency Tips

Delivables of the project

Core Deliverables:

  • A Rust-based CLI tool that can be run on various operating systems.
  • Source code analysis and optimization algorithms that:
    • Apply tight variable packing and efficient data type usage.
    • Struct packing optimization feature that reorders struct fields to use storage slots efficiently.
    • Function selector optimization that reorders function definitions based on call frequency to save gas.
  • Automated code rewriting capabilities that apply the suggested optimizations directly to the Solidity source code.
  • Documentation on how to install, configure, and use the tool.
  • Test suite that covers various Solidity contracts and ensures the reliability of the optimization process.
  • Benchmarking reports that demonstrate the gas savings achieved by the tool on sample contracts.

Roadmap

Week 8:

  • Start on lexer and parser
    • look at the optimisations u need to do and look at the tokens we neeed
      • struct packing
        • struct, parathesis, variable name, type identifier
      • storage cache
        • identifying read and write
          • what can trigger a read / write
        • function
        • limit it to value types only
          • start with integer
            • we can start with value types (pass by value)
You might also like...
Rust client to Opensea's APIs and Ethereum smart contracts

opensea.rs Rust bindings & CLI to the Opensea API and Contracts CLI Usage Run cargo r -- --help to get the top level help menu: opensea-cli 0.1.0 Choo

A framework for creating PoC's for Solana Smart Contracts in a painless and intuitive way

Solana PoC Framework DISCLAIMER: any illegal usage of this framework is heavily discouraged. Most projects on Solana offer a more than generous bug bo

Helpful functions and macros for developing smart contracts on NEAR Protocol.

near-contract-tools Helpful functions and macros for developing smart contracts on NEAR Protocol. This package is a collection of common tools and pat

Helpful functions and macros for developing smart contracts on NEAR Protocol.

near-contract-tools Helpful functions and macros for developing smart contracts on NEAR Protocol. This package is a collection of common tools and pat

Rust client to Seaport's APIs and Ethereum smart contracts(WIP)

Seaport-rs WIP - WORK IN PROGRESS. REFER TO https://github.com/Alcibiades-Capital/quay FOR PRODUCTION READY CODE I'm new to Rust and seek to be legend

Rust project for working with ETH - Ethereum transactions with Rust on Ganache and also deploy smart contracts :)

Just a test project to work with Ethereum but using Rust. I'm using plain Rust here, not Foundry. In future we will use Foundry. Hope you're already f

RGB smart contracts: client-facing library & command-line for desktop and mobile

RGB smart contracts RGB is confidential & scalable client-validated smart contracts for Bitcoin & Lightning. It embraces the concepts of private & mut

A framework for publishing, deploying, invoking, and upgrading soroban smart contracts

SmartDeploy A framework for publishing, deploying, and upgrading Soroban smart contracts. Uses Loam-SDK Publishing Currently smart contracts are insta

zink! is a library for developing ink! smart contracts with useful Rust macros that extend functionality and reduce boilerplate code.
zink! is a library for developing ink! smart contracts with useful Rust macros that extend functionality and reduce boilerplate code.

zink! Smart Contract Macros This is a helper library for developing ink! smart contracts. It contains useful Rust macros that extend functionality and

Owner
Chia Yong Kang
Final year CS student | Fun with distributed systems, smart contracts, and building a better internet 🌐
Chia Yong Kang
evm2near compiles Solidity contracts into NEAR WebAssembly contracts.

EVM → NEAR evm2near is a project for compiling EVM bytecode into wasm bytecode, with the particular goal of having that wasm artifact be executable on

Aurora 125 Dec 3, 2022
A tool to optimize your Solidity function signatures.

sigop A CLI tool to optimize your Solidity function signatures. I wanted to create this after seeing transmissions11's comment about this optimization

Quartz Technology 11 Nov 24, 2022
Minimal Substrate node configured for smart contracts via pallet-contracts.

substrate-contracts-node This repository contains Substrate's node-template configured to include Substrate's pallet-contracts ‒ a smart contract modu

Parity Technologies 73 Dec 30, 2022
A tool to help with estimating NEAR gas spent by transactions on Aurora.

Aurora Gas Estimator A tool to help with estimating NEAR gas spent by transactions on Aurora. Building from source Prerequisites Rust GNU Make (3.81+)

Michael Birch 4 Aug 23, 2022
This is a solana lite rpc which optimizes sending transactions and confirming transactions strategies.

Solana Lite RPC This project aims to create a lite rpc server which is responsible only for sending and confirming the transactions. The lite-rpc serv

Blockworks Foundation 7 Dec 24, 2022
CLI for Stellar Smart Contracts.

stellar-contract-cli CLI for running Stellar contracts locally in a test VM. Executes WASM files built using the rs-stellar-contract-sdk. Install carg

Stellar 22 Dec 20, 2022
Vanitygen-bip39 - Generate vanity / gas efficient Ethereum addresses for your hdwallet (bip39 12 or 24 words)

vanitygen-bip39 Generate Ethereum gas efficient addresses with leading zeros https://medium.com/coinmonks/on-efficient-ethereum-addresses-3fef0596e263

iam4x 9 Jul 2, 2022
A blazingly fast compiling & optimization tool for CosmWasm smart contracts.

cw-optimizoor A blazingly fast alternative to CosmWasm/rust-optimizer for compiling & optimizing CW smart contracts. It's primarily meant to speed up

Sebastian Mandrean 37 Apr 15, 2023
A vertically scalable stream processing framework focusing on low latency, helping you scale and consume financial data feeds.

DragonflyBot A vertically scalable stream processing framework focusing on low latency, helping you scale and consume financial data feeds. Design The

null 17 Jul 12, 2023
Ticketed Discreet Log Contracts (DLCs) to enable instant buy-in for wager-like contracts on Bitcoin.

dlctix Ticketed Discreet Log Contracts (DLCs) to enable instant buy-in for wager-like contracts on Bitcoin. This project is part of the Backdrop Build

null 7 Feb 29, 2024