GasBad is a project aimed at comparing the gas efficiency of various Solidity libraries. It focuses on analyzing and measuring the gas consumption of popular Solidity libraries to identify which ones offer the most efficient gas usage.

Why GasBad?#

Gas consumption is a critical factor in Ethereum smart contract development. Efficient gas usage not only helps optimize transaction costs but also contributes to scalability and overall contract performance. GasBad aims to provide developers with insights into the gas efficiency of different Solidity libraries, allowing them to make informed decisions when choosing libraries for their projects.

What did you test?#

Currently, GasBad focuses on testing (only) the gas usage of the following Solidity libraries:

  • OpenZeppelin: A widely-used library for secure and community-audited smart contract development.
  • Solady: A Solidity library known for its gas optimization techniques and efficiency enhancements.
  • Solmate: A library specifically designed to provide gas-efficient implementations of common Solidity operations.

How did you test?#

GasBad conducts gas efficiency tests using Forge 0.2.0 with via-IR optimizations and Solidity 0.8.20. The Forge framework allows for precise gas measurement and analysis of Solidity code.

What are the results?#

GasBad evaluates the gas efficiency of libraries across different contracts. This is a snapshot of what has been tested as of March 2024, in the Github repository you’ll always find the updated results.

ERC20#

Gas consumption evaluation of ERC20 token-related operations provided by the tested libraries. By comparing gas usage, developers can make informed decisions about the most efficient library for ERC20 functionality.

Function NameSolmateSoladyOpenZeppelinGas Efficiency
allowance808768788Solady
approve243102426824387Solady
decimals265257262Solady
name29015292823Solady
symbol30837382985Solady
totalSupply232123192324Solady
transfer295672954129666Solady
transferFrom202342002121828Solady

ERC721#

Gas consumption evaluation of ERC721 token-related operations provided by the tested libraries. By comparing gas usage, developers can make informed decisions about the most efficient library for ERC721 functionality.

Function NameSolmateSoladyOpenZeppelinGas Efficiency
approve226672244423030Solady
balanceOf266326182663Solady
burn423441814511Solady
getApproved412545699Solmate
isApprovedForAll291528072915Solady
mint468944667847149Solady
name2928549565Solady
setApprovalForAll246022447724626Solady
symbol3134747768Solady
tokenURI850835850Solady
transferFrom225152031923352Solady

ERC1155#

Gas consumption evaluation of ERC1155 token-related operations provided by the tested libraries. By comparing gas usage, developers can make informed decisions about the most efficient library for ERC1155 functionality.

Function NameOpenZeppelinSoladySolmateGas Efficiency
balanceOf254724072485Solady
balanceOfBatch161061256614317Solady
burn878480648156Solady
burnBatch366843363535648Solady
isApprovedForAll778681783Solady
mint281552771227871Solady
mintBatch124178121891124104Solady
safeBatchTransferFrom151145146637148209Solady
safeTransferFrom340273314133458Solady
setApprovalForAll245062436724487Solady
uri2945540566Solady

ERC4626#

Gas consumption evaluation of ERC4626 vault-related operations provided by the tested libraries. By comparing gas usage, developers can make informed decisions about the most efficient library for ERC4626 functionality.

Function NameOpenZeppelinSoladySolmateGas Efficiency
balanceOf756705707Solady
convertToAssets15441286361 - 1424Solmate if totalSupply is zero else Solady
deposit626996009359628Solmate
mint628026019959652Solmate
name288628402922Solady
previewDeposit211918751972Solady
previewWithdraw166613961497Solady
redeem248492390123944Solady
symbol322631953252Solady
totalAssets11399121133Solady
totalSupply383380380Solmate/Solady
withdraw259582479223922Solmate

Ownable#

Gas consumption evaluation of Ownable related operations provided by the tested libraries. By comparing gas usage, developers can make informed decisions about the most efficient library for this functionality.

Function NameOpenZeppelinSoladySolmateGas Efficiency
owner229823552279Solmate
renounceOwnership54865472-Solady
transferOwnership695570026785Solmate

RoleBasedAccess#

Gas consumption evaluation of RoleBasedAccess contracts related operations provided by the tested libraries. By comparing gas usage, developers can make informed decisions about the most efficient library for this functionality.

Note: In order to be specific, it uses the following contracts for comparisons:

  1. AccessControl.sol from Openzeppelin
  2. OwnableRoles from Solady
  3. RolesAuthority from Solmate
Function NameOpenZeppelinSoladySolmateGas Efficiency
owner236325462444OpenZeppelin
grantRole291782609618915Solmate
revokeRole7146632318915Solady

ECDSA#

Gas consumption evaluation of ECDSA related operations provided by the tested libraries. By comparing gas usage, developers can make informed decisions about the most efficient library for this functionalities.

Function NameOpenZeppelinSoladySolmateGas Efficiency
recover39353741-Solady
toEthSignedMessage252255-OpenZeppelin

MerkleProof#

Gas consumption evaluation of contracts related operations provided by the tested libraries. By comparing gas usage, developers can make informed decisions about the most efficient library for this functionality.

Note: As gas consumption of verify function depends on proof size there are several tests for each function with different amounts of elements in proof and corresponding amount of leaves (elements in tree)

  1. 5 elements in the proof = 32 leaves in tree
  2. 10 elements in the proof = 1024 leaves in tree
  3. 15 elements in the proof = 32668 leaves in tree
Function NameOpenZeppelinSoladySolmateGas Efficiency
verify_5_elements25541783-Solady
verify_10_elements44442863-Solady
verify_15_elements63403943-Solady
verifyCalldata_5_elements168512041095Solmate
verifyCalldata_10_elements291619291820Solmate
verifyCalldata_15_elements415926542545Solmate

Base64#

Gas consumption evaluation of Base64 related operations provided by the tested libraries. By comparing gas usage, developers can make informed decisions about the most efficient library for this functionality.

Function NameOpenZeppelinSoladySolmateGas Efficiency
encode25991925-Solady
decode-1786-Solady

Can I add other tests?#

Yes, of course! You can create an issue in the Github repository and explain what you’d like to see. I’ll be more than happy to add it to this collection and perform the necessary tests.

Alternatively, if you have already conducted gas efficiency tests and want to share your results, you can create a pull request (PR) on the repository. Once your PR is submitted, I will review and integrate it into the project, making it accessible to everyone.