Skip to content

Comments

fix(sdk) depositETH gas estimation bug#9949

Closed
tsite wants to merge 7 commits intoethereum-optimism:developfrom
tsite:develop
Closed

fix(sdk) depositETH gas estimation bug#9949
tsite wants to merge 7 commits intoethereum-optimism:developfrom
tsite:develop

Conversation

@tsite
Copy link

@tsite tsite commented Mar 22, 2024

Description

Fix a bug in the sdk where gas estimation uses the zero address as the source instead of propagating the source address for the transaction.

Tests

Depositing eth via the CrossChainMessenger now works properly and estimateGas no longer reverts due to a lack of funds available at the zero address.

Metadata

propagate the deposit address instead of using the zero address
as the source for eth_estimateGas
@tsite tsite requested a review from a team as a code owner March 22, 2024 04:13
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 22, 2024

Walkthrough

Walkthrough

The recent changes involve enhancements to the CrossChainMessenger class and its test suite, focusing on improving gas estimation and simplifying the handling of overrides in token deposit methods. These adjustments aim to enhance reliability and efficiency in cross-chain transactions between Ethereum layers.

Changes

File Path Change Summary
.../sdk/src/cross-chain-messenger.ts - Improved gas estimation in depositETH
- Simplified overrides handling in depositERC20
.../sdk/test/cross-chain-messenger.spec.ts - Updated gas estimation logic and balance checks
- Modified sender addresses to account 13

Assessment against linked issues

Objective Addressed Explanation
Include "from" address in eth_estimateGas for depositETH (#6723)
Update transaction cost estimation process for accuracy and efficiency (github/ethereum-optimism/docs#595) The changes seem relevant to transaction cost estimation but without explicit mention, it's unclear if all aspects of the issue are addressed.
Ensure compatibility with the latest version of the SDK (github/ethereum-optimism/docs#595) The changes align with SDK updates, but without details on the SDK version, full compatibility cannot be confirmed.
Improve documentation related to transaction cost estimation (github/ethereum-optimism/docs#595) No changes to documentation are mentioned.

Possibly related issues

  • github/[TUTORIAL] update estimating transaction costs (with the sdk) to viem docs#595: The improvements in gas estimation and handling of overrides in the SDK could contribute to the objectives of updating the transaction cost estimation process for better accuracy and efficiency. This issue might benefit from linking to the PR for visibility on practical code adjustments that support its goals.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Mar 22, 2024

Codecov Report

Attention: Patch coverage is 18.18182% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 19.01%. Comparing base (b57a263) to head (289701d).
Report is 217 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9949      +/-   ##
===========================================
- Coverage    28.34%   19.01%   -9.33%     
===========================================
  Files          165      155      -10     
  Lines         7271     6194    -1077     
  Branches      1330     1327       -3     
===========================================
- Hits          2061     1178     -883     
+ Misses        5104     4941     -163     
+ Partials       106       75      -31     
Flag Coverage Δ
cannon-go-tests ?
chain-mon-tests 27.14% <ø> (ø)
common-ts-tests 26.72% <ø> (ø)
contracts-bedrock-tests 0.60% <ø> (ø)
contracts-ts-tests 12.25% <ø> (ø)
core-utils-tests 44.03% <ø> (ø)
sdk-next-tests 41.13% <18.18%> (+0.10%) ⬆️
sdk-tests 41.13% <18.18%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
packages/sdk/src/cross-chain-messenger.ts 48.05% <18.18%> (+0.32%) ⬆️

... and 10 files with indirect coverage changes

Copy link
Contributor

@roninjin10 roninjin10 left a comment

Choose a reason for hiding this comment

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

I believe this code has tests and I'm not 100% clear on why gasEstimation would fail here. Can you please write test that fails before your change demonstrating the issue?

Comment on lines 2264 to 2268
const from =
opts?.overrides?.from ??
(ethers.Signer.isSigner(this.l1SignerOrProvider)
? (this.l1SignerOrProvider as Signer).getAddress()
: undefined)
Copy link
Contributor

@roninjin10 roninjin10 Mar 22, 2024

Choose a reason for hiding this comment

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

Does ethers not already default to the signer address?

Copy link
Author

Choose a reason for hiding this comment

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

it was using the provider instead of signer for gas estimation - I updated the fix to use l1SignerOrProvider instead of l1Provider and cleaned up depositERC20 as well.

Copy link
Author

Choose a reason for hiding this comment

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

@roninjin10 if you could take another look at the pr, that would be awesome

Copy link
Contributor

Choose a reason for hiding this comment

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

See my comment here #9949 (review)

Copy link
Author

Choose a reason for hiding this comment

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

ok I updated the depositETH test to catch regressions @roninjin10 - the tests now fail without the changes made in this pr

we need to use the signer instead of provider to estimate the gas properly
Copy link
Contributor

@roninjin10 roninjin10 left a comment

Choose a reason for hiding this comment

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

Thanks for adding the tests and apologies if getting this pr merged has been fustrating. My general inclination is to not accept this change but I'm borderline.

@smartcontracts any thoughts? I will defer to you if you think this change is worth merging. As far as I can tell it doesn't hurt anything

// include a balance check as part of the estimateGas() call.
for (const signer of [l1Signer, l2Signer]) {
const estimateGas = signer.provider.estimateGas
signer.provider.estimateGas = async function (tx) {
Copy link
Contributor

Choose a reason for hiding this comment

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

So if I'm understanding this correctly, the issue here is geth reverts on balance checks. What I'm failing to understand though is we already have these tests running against geth via our devnet tests and against anvil via our anvil/vitest tests

Copy link
Author

@tsite tsite Apr 2, 2024

Choose a reason for hiding this comment

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

I think new versions of geth do fail the gas estimate if the balance is lower than the call value. I'll update the test to check for strict inequality since a zero balance is permitted for non-payable functions.

Copy link
Author

Choose a reason for hiding this comment

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

for example, cast rpc eth_estimateGas '{"to":"0x00a149B262EA8ACA092Af1c43a899e7B18C5A4De", "from":"0x00a149B262EA8ACA092Af1c43a899e7B18C5A4De","value":"0x1"}' fails on most networks due to insufficient balance while cast rpc eth_estimateGas '{"to":"0x00a149B262EA8ACA092Af1c43a899e7B18C5A4De", "from":"0x00a149B262EA8ACA092Af1c43a899e7B18C5A4De","value":"0x0"}' succeeds.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmmm definitely confusing to me because I'm pretty sure we are using a new version of geth for our devnet tests. I think you are right though and I just don't know enough to be able to approve this pr. @smartcontracts will check it out within a day or 2. Thank you for patience.

The sender is allowed to have no balance when calling estimateGas on
nonpayable functions.

Also revert some unnecessary test changes
@tsite
Copy link
Author

tsite commented Apr 2, 2024

I updated the test - would appreciate another review. We currently have patched code running in production to fix this bug and it would be nice to merge the fix upstream as well

@tsite tsite requested a review from roninjin10 April 12, 2024 19:01
@github-actions
Copy link
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with depositETH

2 participants