This code repository aims to benchmark the gas costs between EVM and Stylus contracts for ERC20 tokens and Ed25519 signature recovery.
# Required to run the examples
git submodule update --init --recursive
Each contract project directory ({erc20,ed25519}-{stylus,solidity}
) contains a Justfile
which reads a local .env
(use the provided .env.local
templates). Read the Justfile
s to read more on what targets they provide.
Note
For the TLDR, jump to the conclusion
Important
The provided numbers below are L2_GAS gas costs, because that's what's most important, since it represents the actual computational cost of the transactions, and not the L1
calldata fees that are always fluctuating.
Feel free to check the transactions on arbiscan
(the gas numbers are links that take you directly there) to check the gas costs for yourself.
Function | Stylus L2 Gas | Solidity L2 Gas | Difference (L2) | % Difference |
---|---|---|---|---|
deploy | 2'868'817 + 2'941'842 | 530'643 | +2'338'174 | 995.0% more |
mint | 87'649 | 68'455 | +19'194 | 28.0% more |
transfer | 70'949 | 51'332 | +19'617 | 38.2% more |
Function | Stylus L2 Gas | Solidity L2 Gas | Difference (L2) | % Difference |
---|---|---|---|---|
deploy | 3'934'896 + 3'123'366 | 2'814'629 | +1'120'267 | 39.8% more |
verify | 225'427 | 904'435 | -679'008 | 75% less |
- For ERC-20 contracts:
- Stylus deploy costs ~11 times more gas than Solidity (can be optimised through Cache Manager)
- while mint and transfer are also ~28% and ~38% more expensive, respectively
This is somewhat expected, since ERC-20 contracts aren't computationally heavy (no taking advantage of Stylus).
- For Ed25519 contracts:
- Stylus deploy costs ~40% more gas than Solidity (can be optimised through Cache Manager)
- but for signature verification, Stylus is ~75% cheaper
This is also expected and is the main takeaway from this benchmark - that Stylus is lot faster when doing heavy computational tasks.
- Our Solidity Ed25519 verification costs 904k gas, but some have optimized it to ~500k gas.
- Using zk-SNARKs, it can go down to 300k gas (and still require off-chain proving).
- And still, it costs more than Stylus's 225k gas.