Gas Killer is an AVS that uses BLS signature verification to securely simulate a transaction off chain and write back the storage slot updates to save gas associated with read and compute operations.
Our intentionally "dumb" voting contract loops through a large array of voters to calculate voting power to show gas savings.
Gas Killer does not enforce any changes to existing solidity functions, nor externalizes the contract storage. Existing contracts can be integrated with continued support to existing flows and infra.
- Traditional Approach: All computation happens on-chain, requiring gas for every operation.
- Optimized Approach:
- Computation happens off-chain (simulated by the operator)
- Only storage updates are applied on-chain
- BLS signatures verify the integrity of the updates
This pattern can be applied to any computation-heavy smart contract to significantly reduce gas costs.
- BLS Signature Verification: Uses BLS signature aggregation for efficient multi-party consensus
- Slashing Mechanism: Implements objective on chain slashing
- State Transition Management: Tracks state transitions for consistent voting power calculation. Reverting if another write operation occurs first within same block before operator updates storage
The optimized approach of running complex calculations off-chain and only applying storage updates on-chain demonstrates substantial gas savings:
- With 3000 voters: ~99% gas reduction
- With 1000 voters: ~97% gas reduction
- With 100 voters: ~81% gas reduction
- With 40 voters: ~63% gas reduction
- With 15 voters: ~38% gas reduction
As the number of voters increases, the gas savings become more pronounced, making this approach highly scalable for applications with large data sets.
- Autogenerate functions based on the target function (for gas savings) that implement slashing, AVS access control, and contract storage tracking.
- Deploy an upgraded version of the original contract (all previous functions are still supported)
- Redirect existing transactions to the AVS instead of the contract
Verify the contract functionality with standard tests:
# Run all tests
forge test
# Run a specific test
forge test --match-test testAddVoter -vvvCompare gas usage between traditional and optimized approaches:
# Run the gas benchmark test
forge test --match-test testGasComparison -vvv
# Increase the gas limit if needed for large voter tests
forge test --match-test testGasComparison --gas-limit 1000000000 -vvvFor a real-world comparison, deploy and run benchmarks on a testnet:
# Set up environment (replace with your values)
export PRIVATE_KEY=your_private_key
export RPC_URL=your_rpc_url
# Deploy and run benchmark
forge script script/BenchmarkComparison.s.sol --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast -vvvVerify that both the on chain and off chain approaches produce identical results:
forge test --match-test testComputationalEquivalence -vvvFoundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
Foundry consists of:
- Forge: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- Cast: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- Anvil: Local Ethereum node, akin to Ganache, Hardhat Network.
- Chisel: Fast, utilitarian, and verbose solidity REPL.
$ forge build$ forge test$ forge fmt$ forge snapshot$ anvil$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>$ cast <subcommand>$ forge --help
$ anvil --help
$ cast --help