-
Notifications
You must be signed in to change notification settings - Fork 13
Update eth_estimateGas to correctly handle execution reverts
#303
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,6 @@ import ( | |
| gethCore "github.com/onflow/go-ethereum/core" | ||
| "github.com/onflow/go-ethereum/core/types" | ||
| gethVM "github.com/onflow/go-ethereum/core/vm" | ||
| "github.com/onflow/go-ethereum/params" | ||
| "github.com/rs/zerolog" | ||
| "golang.org/x/sync/errgroup" | ||
|
|
||
|
|
@@ -373,16 +372,15 @@ func (e *EVM) EstimateGas( | |
| if err != nil { | ||
| return 0, fmt.Errorf("failed to decode EVM result from gas estimation: %w", err) | ||
| } | ||
|
|
||
| if evmResult.ErrorCode != 0 { | ||
| if evmResult.ErrorCode == evmTypes.ExecutionErrCodeExecutionReverted { | ||
| return 0, errs.NewRevertError(evmResult.ReturnedData) | ||
| } | ||
| return 0, getErrorForCode(evmResult.ErrorCode) | ||
| } | ||
|
|
||
| // This minimum gas availability is needed for: | ||
| // https://github.com/onflow/go-ethereum/blob/master/core/vm/operations_acl.go#L29-L32 | ||
| // 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, exactly, this is done by |
||
| gasConsumed := evmResult.GasConsumed | ||
|
|
||
| e.logger.Debug(). | ||
| Uint64("gas", gasConsumed). | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -173,4 +173,40 @@ it('deploy contract and interact', async() => { | |
| ) | ||
| } | ||
|
|
||
| // check that revert reason for custom error is correctly returned for gas estimation | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| try { | ||
| let callCustomError = deployed.contract.methods.customError().encodeABI() | ||
| result = await web3.eth.estimateGas({ | ||
| from: conf.eoa.address, | ||
| to: contractAddress, | ||
| data: callCustomError, | ||
| gas: 1_000_000, | ||
| gasPrice: 0 | ||
| }) | ||
| } catch (error) { | ||
| assert.equal(error.innerError.message, 'execution reverted') | ||
| assert.equal( | ||
| error.innerError.data, | ||
| '0x9195785a00000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001056616c756520697320746f6f206c6f7700000000000000000000000000000000' | ||
| ) | ||
| } | ||
|
|
||
| // check that assertion error is correctly returned for gas estimation | ||
| try { | ||
| let callAssertError = deployed.contract.methods.assertError().encodeABI() | ||
| result = await web3.eth.estimateGas({ | ||
| from: conf.eoa.address, | ||
| to: contractAddress, | ||
| data: callAssertError, | ||
| gas: 1_000_000, | ||
| gasPrice: 0 | ||
| }) | ||
| } catch (error) { | ||
| assert.equal(error.innerError.message, 'execution reverted: Assert Error Message') | ||
| assert.equal( | ||
| error.innerError.data, | ||
| '0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000014417373657274204572726f72204d657373616765000000000000000000000000' | ||
| ) | ||
| } | ||
|
|
||
| }).timeout(10*1000) | ||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 😇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 2192050