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

[api] fix revert custom errors and returns the correct revert message in eth_call #3920

Closed
wants to merge 3 commits into from

Conversation

millken
Copy link
Contributor

@millken millken commented Aug 14, 2023

Description

Returns the correct json when the contract call contains a revert (custom) error

Fixes #3919 #3821

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • [] Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

@iotexproject iotexproject locked and limited conversation to collaborators Aug 14, 2023
@iotexproject iotexproject unlocked this conversation Aug 14, 2023
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@codecov
Copy link

codecov bot commented Aug 14, 2023

Codecov Report

Merging #3920 (5ca0a00) into master (e1f0636) will increase coverage by 0.61%.
Report is 77 commits behind head on master.
The diff coverage is 72.37%.

❗ Current head 5ca0a00 differs from pull request most recent head 00007ff. Consider uploading reports for the commit 00007ff to get more accurate results

@@            Coverage Diff             @@
##           master    #3920      +/-   ##
==========================================
+ Coverage   75.38%   75.99%   +0.61%     
==========================================
  Files         303      328      +25     
  Lines       25923    27847    +1924     
==========================================
+ Hits        19541    21163    +1622     
- Misses       5360     5592     +232     
- Partials     1022     1092      +70     
Files Changed Coverage Δ
action/protocol/execution/evm/evm.go 43.52% <0.00%> (-2.95%) ⬇️
action/protocol/execution/evm/evmstatedbadapter.go 66.77% <ø> (ø)
action/protocol/poll/consortium.go 0.00% <0.00%> (ø)
action/protocol/poll/staking_committee.go 43.85% <0.00%> (ø)
...tion/protocol/staking/contractstake_bucket_type.go 0.00% <0.00%> (ø)
action/receipt.go 82.17% <ø> (ø)
api/grpcserver.go 86.40% <0.00%> (ø)
api/loglistener.go 25.00% <0.00%> (ø)
api/web3server_marshal.go 93.68% <ø> (+0.47%) ⬆️
api/websocket.go 4.10% <0.00%> (-1.07%) ⬇️
... and 64 more

... and 8 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

if errUnpack != nil {
reason = "execution reverted"
}
receipt.SetExecutionRevertMsg(reason)
Copy link
Member

Choose a reason for hiding this comment

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

will cause HF

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
Contributor Author

Choose a reason for hiding this comment

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

  1. here is only to capture custom errors while keeping the logic unchanged as before.

  2. geth’s handling has been moved to the API layer, and making changes here would cause HF, necessitating significant code adjustments.
    https://github.com/iotexproject/iotex-core/pull/3920/files#diff-6dc4e8a6418cb4f7e5b7da626b745fb04ff21d7c37b77d883b8c8b9ab7aacfcbR403

Copy link
Member

Choose a reason for hiding this comment

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

geth code

typ, err := NewType("string", "", nil)
	if err != nil {
		return "", err
	}
	unpacked, err := (Arguments{{Type: typ}}).Unpack(data[4:])
	if err != nil {
		return "", err
	}
	return unpacked[0].(string), nil

I am not 100% sure, if that will be exactly same as our code

data := retval[4:]
msgLength := byteutil.BytesToUint64BigEndian(data[56:64])
revertMsg := string(data[64 : 64+msgLength])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

100% sure. if not, the check of ExecutionRevertMsg in tests will not passed

Copy link
Member

@dustinxie dustinxie Aug 16, 2023

Choose a reason for hiding this comment

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

inside L290:

if fCtx.CorrectCustomRevert { 
    your code in PR
} else if bytes.Equal(retval[:4], _revertSelector) {
    current code
}

@millken
Copy link
Contributor Author

millken commented Aug 16, 2023

this PR split into #3923 and #3922

@millken millken closed this Aug 16, 2023
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.

[ Web3 API ] Custom Errors are not correctly returned
3 participants