Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gas-oracle): handle Optimism Ecotone blob fees #352

Conversation

sylvaincormier
Copy link
Contributor

Overview

Fixes gas price overestimation issue in the Optimism gas oracle following the Ecotone upgrade which introduced blob fees.

Changes

  • Add OptimismGasComponents struct to track L1/L2 fees
  • Implement proper L1 data posting cost calculation
  • Consider both base fee and blob fee with scalars
  • Fix gas price overestimation issue

Testing

  • Added unit tests covering:
    • Total gas calculation including L2 execution and L1 data fees
    • L2 data cost calculation with mock data
    • Both tests pass and verify correct fee calculations

Impact

This fix ensures accurate gas estimations for Optimism transactions by properly accounting for:

  • Base fee with scalar
  • Blob fee with scalar (new in Ecotone)
  • L2 execution costs

Fixes #336

@Wizdave97
Copy link
Member

Thanks for this. In the code comments where the gas price calculations are implemented, please add relevant links to the OpStack repo.

}

#[tokio::test]
async fn test_optimism_total_gas_calculation() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be much better to test this using OpSepolia directly

Copy link
Contributor Author

@sylvaincormier sylvaincormier Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Wizdave97,

I've added the requested comments and references in the code, including links to the OpStack repository for additional context. Thanks again for the feedback—it's much appreciated!

Regarding testing against OpSepolia, I've currently limited the tests to unit-level logic simulations. Due to time constraints and other pending PRs I need to address, I haven't yet integrated direct end-to-end testing on OpSepolia. However, I definitely see value in adding those tests and will plan to revisit this when I have more bandwidth. It would be great to ensure full coverage and validate the changes in a live environment as well.
Will try to do this asap

Copy link
Contributor Author

@sylvaincormier sylvaincormier Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Wizdave97, I've now integrated direct testing against OpSepolia as requested. The tests run successfully against the OpSepolia endpoint, verifying both the L2 data cost calculations and the gas estimation logic in a live environment. Additionally, I've refined the code comments and references to the OpStack/Ecotone specifications for clarity. Let me know if there's anything else you'd like addressed!
Screenshot 2024-12-17 at 5 31 53 PM

@sylvaincormier sylvaincormier force-pushed the fix/optimism-gas-oracle branch from f4ad1d1 to f6827d0 Compare December 16, 2024 15:18
- Add OptimismGasComponents struct to track L1/L2 fees
- Implement proper L1 data posting cost calculation
- Consider both base fee and blob fee with scalars
- Fix gas price overestimation issue

Also:
- Added inline code comments and OpStack references as requested by maintainers
- Implemented direct testing against OpSepolia network
@sylvaincormier sylvaincormier force-pushed the fix/optimism-gas-oracle branch from f6827d0 to dbbc135 Compare December 18, 2024 02:51
id if is_op_stack(id) => {
let ovm_gas_price_oracle = OVM_gasPriceOracle::new(H160(OP_GAS_ORACLE), client.clone());

// Get L1 gas used first
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is already encapsulated by the get_l1_fee method, so we should just keep that
https://github.com/ethereum-optimism/optimism/blob/3db0492cb4ad37441192f3bc94259cc9df9bb4fc/packages/contracts-bedrock/src/L2/GasPriceOracle.sol#L57

I would suggest investigating if we are using the resulting values correctly, look into the optimism javascript sdk to see how the gas cost is estimated and replicate that here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the implementations are identical you can report back.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Wizdave97, thanks for pointing this out! I've removed the manual l1_gas_used calculation and now rely directly on get_l1_fee as per the contract implementation. Additionally, I've compared the updated logic with the Optimism SDK, and it aligns with their approach. Let me know if there's anything else you'd like adjusted.

- Dynamically calculate L1 fee based on transaction size
- Fix incorrect handling of L1 gas used scaling
- Add detailed logging for debug purposes
@Wizdave97
Copy link
Member

Closing because the current implementation of the gas estimate is identical to what's available in the optimism-sdk

Tesseract estimates are approximately correct as shown from the samples in the doc
https://docs.google.com/document/d/1-1Eo-5viezojO3EjPlYMVpgTx3zMVFxDWitG9aZnoDc/edit?tab=t.0

The issue was fixed by this PR #337

@Wizdave97 Wizdave97 closed this Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix bug in optimism gas oracle
2 participants