Skip to content

Conversation

@m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Jun 13, 2024

Closes: #302

Description

Also remove the temporary fix regarding the gas estimation failures for calls that had gas refunds from SSTORE opcode. This issue was fixed upstream, on EVM.dryRun.


For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • Refactor

    • Improved error handling in the EVM methods for more streamlined and efficient error generation.
    • Adjusted gas consumption calculation in the EstimateGas function.
  • Bug Fixes

    • Enhanced handling of specific execution errors to ensure accurate error reporting and gas calculation.

@m-Peter m-Peter added this to the Flow-EVM-M2 milestone Jun 13, 2024
@m-Peter m-Peter self-assigned this Jun 13, 2024
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 13, 2024

Walkthrough

The recent modifications to services/requester/requester.go enhance the error handling and gas estimation within the EVM struct. The changes involve refining the handling of ExecutionErrCodeExecutionReverted error, updating EstimateGas function to improve gas consumption calculations, and refactoring error handling by using evmTypes.ErrorFromCode directly. These adjustments align the implementation with Geth's behavior for eth_estimateGas.

Changes

File Change Summary
services/requester/requester.go - Adjusted handling for ExecutionErrCodeExecutionReverted in EstimateGas.
- Refined gas consumption calculations.
- Removed getErrorForCode function and updated error handling using evmTypes.ErrorFromCode directly.

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Update eth_estimateGas to correctly handle execution reverts (#302)

Poem

Amidst the code where errors reside,
Changes made with care and pride,
Gas estimation, precise and neat,
Handling reverts, a coder's feat.
EVM flows as smooth as stream,
Achieving goals, a coder's dream. 🚀


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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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/schema.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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
services/requester/requester.go (1)

Line range hint 667-667: Consider refactoring the getErrorForCode function to improve maintainability. Perhaps using a map or separate smaller functions could help reduce complexity.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4fd9489 and 6ccd2c6.

Files selected for processing (2)
  • services/requester/requester.go (2 hunks)
  • tests/web3js/eth_deploy_contract_and_interact_test.js (1 hunks)
Files not summarized due to errors (1)
  • tests/web3js/eth_deploy_contract_and_interact_test.js: Error: Server error. Please try again later.
Additional context used
golangci-lint
services/requester/requester.go

561-561: Function 'signAndSend' is too long (82 > 60) (funlen)


667-667: Function 'getErrorForCode' has too many statements (66 > 40) (funlen)

Additional comments not posted (3)
tests/web3js/eth_deploy_contract_and_interact_test.js (2)

176-192: LGTM! Consider adding comments explaining the specific custom error handling during gas estimation.


194-210: LGTM! Consider adding comments explaining the specific assertion error handling during gas estimation.

services/requester/requester.go (1)

375-383: LGTM! The changes to handle execution reverts in EstimateGas are aligned with the PR objectives. Consider adding unit tests to cover these new error handling scenarios.

)
}

// check that revert reason for custom error is correctly returned for gas estimation
Copy link
Contributor

Choose a reason for hiding this comment

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

lets create maybe gast estimation test separately, because it feels to me we will have multiple tests with weird cases

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right. It has become quite large, I must admit. I'll leave it for another PR though.

// Note that this is not actually consumed in the end.
// TODO: Consider moving this to `EVM.dryRun`, if we want the
// fix to also apply for the EVM API, on Cadence side.
gasConsumed := evmResult.GasConsumed + params.SstoreSentryGasEIP2200 + 1
Copy link
Contributor

Choose a reason for hiding this comment

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

so we removed this because we handle it in the EVM core now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, exactly, this is done by EVM.dryRun now.

if evmResult.ErrorCode == evmTypes.ExecutionErrCodeExecutionReverted {
return 0, errs.NewRevertError(evmResult.ReturnedData)
}
return 0, getErrorForCode(evmResult.ErrorCode)
Copy link
Contributor

Choose a reason for hiding this comment

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

don't have this function now inside evm core?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, good point, I forgot that it was added 😇

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated in 2192050

@devbugging devbugging self-requested a review June 13, 2024 13:51
Copy link
Contributor

@devbugging devbugging left a comment

Choose a reason for hiding this comment

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

Nice, left some minor comments. Good work.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
services/requester/requester.go (1)

Line range hint 559-559: Refactor signAndSend to reduce complexity and improve maintainability.

Consider breaking down the function into smaller, more manageable functions, each handling a specific part of the transaction process. This could improve readability and maintainability.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6ccd2c6 and 2192050.

Files selected for processing (1)
  • services/requester/requester.go (4 hunks)
Additional context used
golangci-lint
services/requester/requester.go

559-559: Function 'signAndSend' is too long (82 > 60) (funlen)

Additional comments not posted (2)
services/requester/requester.go (2)

373-378: Improved handling of execution reverts in EstimateGas aligns with PR objectives and enhances robustness.


381-381: Simplification of gas consumption calculation appears correct, assuming upstream handling of SstoreSentryGasEIP2200. Ensure this assumption is verified.

Verification successful

The results indicate that the SstoreSentryGasEIP2200 constant was removed as part of a commit that addressed gas estimation failures with SSTORE refunds. This change confirms that the handling of SstoreSentryGasEIP2200 has been intentionally removed and is no longer necessary.

  • Commit 6ccd2c6f3bf24edd0c9e776a459cdad293387bca explicitly removed the usage of params.SstoreSentryGasEIP2200 from services/requester/requester.go.

Thus, the simplification of the gas consumption calculation is valid and does not require the previously included constant.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the upstream changes correctly handle the `SstoreSentryGasEIP2200` case.

# Test: Search for handling of `SstoreSentryGasEIP2200` in upstream modules.
rg --type go $'SstoreSentryGasEIP2200'

Length of output: 37



Script:

#!/bin/bash
# Description: Verify if `SstoreSentryGasEIP2200` has been renamed or removed and check for its handling.

# Test 1: Search for any definitions or mentions of `SstoreSentryGasEIP2200`.
rg 'SstoreSentryGasEIP2200'

# Test 2: Search for any gas-related constants or variables that might have replaced `SstoreSentryGasEIP2200`.
rg --type go 'Sstore|Gas|EIP2200'

# Test 3: Check for any recent changes in the repository that might have affected `SstoreSentryGasEIP2200`.
git log -p -G'SstoreSentryGasEIP2200'

Length of output: 31320

@m-Peter m-Peter merged commit 1a81274 into onflow:main Jun 13, 2024
@m-Peter m-Peter deleted the eth-estimate-gas-handle-reverts branch June 13, 2024 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

Update eth_estimateGas to correctly handle execution reverts

2 participants