{"id":26848223,"url":"https://github.com/0xpolarzero/gas-metering-comparison","last_synced_at":"2025-05-01T02:23:22.299Z","repository":{"id":222985725,"uuid":"758897787","full_name":"0xpolarzero/gas-metering-comparison","owner":"0xpolarzero","description":"Comparing gas measurements from Forge, Hardhat, Tevm and forge-gas-metering against testnet transactions.","archived":false,"fork":false,"pushed_at":"2024-02-28T10:40:20.000Z","size":212,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-15T05:02:26.492Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0xpolarzero.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-17T12:03:26.000Z","updated_at":"2024-03-20T12:30:08.000Z","dependencies_parsed_at":"2024-02-28T11:28:01.160Z","dependency_job_id":"e1f2581d-5f12-4599-bdf5-82e8304c7987","html_url":"https://github.com/0xpolarzero/gas-metering-comparison","commit_stats":null,"previous_names":["0xpolarzero/gas-metering-comparison"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xpolarzero%2Fgas-metering-comparison","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xpolarzero%2Fgas-metering-comparison/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xpolarzero%2Fgas-metering-comparison/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xpolarzero%2Fgas-metering-comparison/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0xpolarzero","download_url":"https://codeload.github.com/0xpolarzero/gas-metering-comparison/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251811419,"owners_count":21647703,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-30T20:53:35.808Z","updated_at":"2025-05-01T02:23:22.280Z","avatar_url":"https://github.com/0xpolarzero.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gas measurements comparison\n\nComparing the way Forge, Tevm, Hardhat and forge-gas-metering will report gas usage against Sepolia testnet transactions.\n\nThere are two subsequent mint transactions on a newly deployed mock ERC20 contract, for each of the two scenarios. There are 50 `0` bytes from the transaction's data in the first scenario that are turned into `1` bytes in the second one, which explains the expected 600 gas overhead (`600 = 50 * (16 - 4)`).\n\nThe idea is to figure out which of these tools will report different gas usage based on the amount of zero and non-zero bytes that need to be read/written.\n\n## Results\n\n\u003e The process is the following:\n\u003e\n\u003e 1. deploy the contract;\n\u003e 2. mint the same amount of tokens to the same address twice.\n\u003e\n\u003e `recipient = 0x0000000000000000000000000000000000000001 | 0x1111111111111111111111111111111111111111`\n\u003e\n\u003e `amount = 0x0000000000000000000000000000000000000000000000000000000000000001 | 0x1111111111111111111111111111111111111111111111111111111111111111`\n\n| Medium                 | Zero bytes (1st) | Non-zero bytes (1st) | Zero bytes (2nd) | Non-zero bytes (2nd) | Bytes cost diff included | Exact match |\n| ---------------------- | ---------------- | -------------------- | ---------------- | -------------------- | ------------------------ | ----------- |\n| Reference (Sepolia tx) | 67,839           | 68,439               | 33,639           | 34,239               | ✅                       | ✅          |\n| Forge (isolated)       | 67,839           | 68,439               | 33,639           | 34,239               | ✅                       | ✅          |\n| Hardhat                | 67,839           | 68,439               | 33,639           | 34,239               | ✅                       | ✅          |\n| forge-gas-metering     | 63,879           | 64,479               | 21,579           | 22,179               | ✅                       | ❌          |\n| Forge                  | 46,495           | 46,495               | 2,695            | 2,695                | ❌                       | ❌          |\n| Tevm                   | 46,495           | 46,495               | 2,695            | 2,695                | ❌                       | ❌          |\n\n## How to reproduce\n\n### Clone and install\n\n```bash\ngit clone git@github.com:0xpolarzero/gas-metering-comparison.git\ncd gas-metering-comparison\n\n# From the root:\n# Foundry\ncd foundry\nforge install\n\n# Hardhat\ncd hardhat\npnpm install\n\n# Tevm\ncd tevm\npnpm install\n```\n\n### Sepolia\n\nThis will deploy the contract and mint the tokens twice. Which will provide both the reference Sepolia txs and the measurements from the script.\n\n**In `/foundry`**:\n\n1. Create `.env` and fill it with the content in `.env.example`;\n\n2. run `source .env`;\n\n3. deploy the contract and mint the tokens:\n\n```bash\n  forge script script/DeployAndCall.s.sol:DeployAndCall --rpc-url $RPC_URL_SEPOLIA --broadcast -vvvv --sig \"run(address, uint256)\" 0x0000000000000000000000000000000000000001 0x0000000000000000000000000000000000000000000000000000000000000001\n  # or\n  forge script script/DeployAndCall.s.sol:DeployAndCall --rpc-url $RPC_URL_SEPOLIA --broadcast -vvvv --sig \"run(address, uint256)\" 0x1111111111111111111111111111111111111111 0x1111111111111111111111111111111111111111111111111111111111111111\n```\n\n### Foundry (Forge)\n\n**In `/foundry`**: run `forge test --mc MockERC20Foundry -vvvv --isolate`.\n\n### Hardhat\n\n**In `/hardhat`**: run `pnpm hardhat test`.\n\n### forge-gas-metering\n\n**In `/foundry`**: run `forge test --mc MockERC20ForgeGasMetering -vv`.\n\n### Tevm\n\n**In `/tevm`**: run `pnpm ts-node index.ts`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xpolarzero%2Fgas-metering-comparison","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0xpolarzero%2Fgas-metering-comparison","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xpolarzero%2Fgas-metering-comparison/lists"}