Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Feature request: Optimism support #273

Closed
andrewshvv opened this issue Jan 19, 2022 · 10 comments
Closed

Feature request: Optimism support #273

andrewshvv opened this issue Jan 19, 2022 · 10 comments

Comments

@andrewshvv
Copy link

andrewshvv commented Jan 19, 2022

@cgewecke

Hey, pretty new in web3 space, I am wondering - can the eth-gas-reporter support Optimism?

I am not familiar with eth-gas-reporter internals and thought that maybe you can give me initial guidance on what kind of changes are necessary to make it work and the place where to start looking?

Depending on the work required I may try to implement it.

From an initial naive glance it seems we need:

  • Separate gasPrice on gasPriceL1, and gasPriceL2.
  • Separate gasUsed on gasUsedL1, and gasUsedL2.
  • Calculate the calldata size, and derive cost based on gasPriceL1 and gasUsedL1.
  • Leave the rest of the cost to be based on gasPriceL2 and gasUsedL2.

About Optimism fees: https://community.optimism.io/docs/developers/l2/new-fees.html#frontmatter-title

@cgewecke
Copy link
Owner

cgewecke commented Jan 19, 2022

Yes, that looks right to me.

As a practical matter this tool is usually run with HardhatEVM or ganache-cli (both ethereumjs-vm based) It would nice to know if gasUsedL2 on an optimism vm is reasonably similar to what is used on an L1 ethereum vm.

Do you know if that's the case?

@cgewecke
Copy link
Owner

cgewecke commented Jan 19, 2022

Cross-linking relevant issue at hardhat-gas-reporter

cgewecke/hardhat-gas-reporter#78

Will think a little bit about how this should be done....if we take the simplest approach and don't worry about representing the different layer costs in the table, most of the code changes would be in this file where the utilities to fetch and calculate gasPrices are:

https://github.com/cgewecke/eth-gas-reporter/blob/master/lib/utils.js

@andrewshvv
Copy link
Author

andrewshvv commented Jan 20, 2022

Cool, glad to hear that!

It would nice to know if gasUsedL2 on an optimism vm is reasonably similar to what is used on an L1 ethereum VM.
Do you know if that's the case?

By reading this it seems so https://research.paradigm.xyz/optimism
But I will take a deeper dive in a couple of days.

Cross-linking relevant issue at hardhat-gas-reporter

Yeah, hardhat-gas-reporter is what I am actually using.

https://github.com/cgewecke/eth-gas-reporter/blob/master/lib/utils.js

Alright, I will take a look in utils.js, optimism rpc node documentation, ethereumjs-vm docs.

@andrewshvv
Copy link
Author

andrewshvv commented Jan 20, 2022

(in progress, will update with time)

Optimism research:

eth-gas-reporter research:

Open questions:

  • Is estimation is sufficient or do we need to get the actual gas cost?
  • What is required to get the actual L1 gas cost on Optimism?
  • How exactly injectL2Context function works in Optimism? Do we need to replicate it in sync rpc?

@smartcontracts
Copy link

FYI, we just updated the Optimism docs to give more information about how to accurately estimate the current L1 data cost for a given transaction: https://community.optimism.io/docs/developers/build/transaction-fees/#estimating-the-l1-data-fee

@smartcontracts
Copy link

smartcontracts commented Jan 22, 2022

When computing the total cost for a transaction on Optimism you need to account for two things, the L2 "execution" fee and the L1 "data" fee.

The L2 execution fee can be computed with the standard formula of provider.estimateGas(tx) * provider.getGasPrice().

The L1 data fee can be most easily estimated by making a query to OVM_GasPriceOracle.getL1Fee(serialize(tx)).

@andrewshvv
Copy link
Author

First calculation:
Screen Shot 2022-01-24 at 6 29 43 AM

@math77
Copy link

math77 commented May 13, 2023

this was implemented?

@andrewshvv
Copy link
Author

andrewshvv commented May 14, 2023

@math77 nah, sorry, never got it working properly
I ended up rewriting too much, and got stuck introducing new bugs
It is open for anyone to take

@cgewecke
Copy link
Owner

Hi! eth-gas-reporter is being deprecated in favor of hardhat-gas-reporter.

In the latest version at Hardhat, Optimism Ecotone l1GasUsed and total cost are available by setting the L2 option to "optimism". The reporter synthesizes these costs locally so there's no performance hit for collecting this data while running your tests.

https://github.com/cgewecke/hardhat-gas-reporter/releases/tag/v2.0.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants