This code repository aims to benchmark the gas costs between EVM and Stylus contracts for ERC20 tokens.
ERC20 Functions
Function | Stylus (WASM) | Solidity (Shanghai EVM) |
---|---|---|
fund/mint | 36345 | 34123 |
transfer | 37417 | 35000 |
approve | 31573 | 27005 |
transferFrom | 44683 | 41212 |
ED25519
Stylus (WASM) | Solidity (Shanghai EVM) | |
---|---|---|
verify | 184188 (-81%) | 975582 |
Note: https://github.com/chengwenxi/Ed25519/tree/main was used for the EVM implementation of ED25519 verification
- ERC20 and other contracts whose gas costs come predominantly from storage operations will not benefit greatly from Stylus contracts
- Purely computational contracts (e.g. ED25519 verification) would significantly benefit from Stylus as it would drastically lower the gas costs compared to an EVM implementation
- We are observing a ~81% reduction in gas costs in the case of a naive (non-optimised) WASM implementation of ED25519 verification compared to an EVM implementation
Important
-
The code shown in this repository is for demonstration purposes only and is not production-ready. It is meant to showcase the gas cost differences between the Stylus VM and the EVM.
-
The code used in the Stylus VM is a naive implementation and is not optimized. It is important to consider this when interpreting the benchmark results.
-
Benchmark was run based on the following gas schedule for Stylus which as of this writing is not yet on testnet!
- Compile the Stylus contracts
cargo build --package stylus-benchmark --release
- Clone Arbitrum Nova development node
git clone -b stylus --recurse-submodules https://github.com/OffchainLabs/nitro-testnode.git && cd nitro-testnode
- Run Local development node with Stylus support
./test-node.bash --init
- Fund the users addresses
./test-node.bash script send-l2 --to address_0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 --ethamount 100
./test-node.bash script send-l2 --to address_0x70997970c51812dc3a010c7d01b50e0d17dc79c8 --ethamount 100
-
Uncomment the
erc20
file in thelib.rs
, comment theed25519
file -
Deploy the erc20 contract
cargo stylus deploy -e http://localhost:8547 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
- Run the benches script - change the addresses of the ERC20 prior to launching the script
bash ./stylus-bench-erc20.sh
- Uncomment the
ed25519
file inlib.rs
, comment theerc20
file - Deploy the
ed25519
verifier contract
cargo stylus deploy -e http://localhost:8547 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
- Execute the following cast
cast send --rpc-url http://localhost:8547 --gas-limit 1000000 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 {CONTRACT_ADDRESS} "verify(bytes,bytes,bytes32)" 0xb0d8bdfd9f4d1023dae836b2e41da5019d20c60965dc40943e2c10f2ad4ee49ab0d8bdfd9f4d1023dae836b2e41da5019d20c60965dc 0xa6161c95fd4e3237b7dd12cc3052aaa69382510ecb5b89c2fbeb8b6efb78266b81160af2842235a0257fc1d3e968c2c1c9f56f117da3186effcaeda256c38a0d 0x06cf14cfae0ff9fe7fdf773202029a3e8976465c8919f4840d1c3c77c8162435