Skip to content

feat: support state overrides in eth_call #337

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

mmsqe
Copy link
Contributor

@mmsqe mmsqe commented Jul 23, 2025

Description

upstream feature from crypto-org-chain/ethermint#369, for test info

Closes: #336


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • tackled an existing issue or discussed with a team member
  • left instructions on how to review the changes
  • targeted the main branch

Reviewers Checklist

All items are required.
Please add a note if the item is not applicable
and please add your handle next to the items reviewed
if you only reviewed selected items.

I have...

  • added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • confirmed all author checklist items have been addressed
  • confirmed that this PR does not change production code
  • reviewed content
  • tested instructions (if applicable)
  • confirmed all CI checks have passed

@mmsqe mmsqe requested review from a team as code owners July 23, 2025 01:48
@aljo242 aljo242 self-assigned this Jul 28, 2025
Comment on lines 329 to 331
func (b *Backend) DoCall(
args evmtypes.TransactionArgs, blockNr rpctypes.BlockNumber,
args evmtypes.TransactionArgs, blockNr rpctypes.BlockNumber, overrides *json.RawMessage,
) (*evmtypes.MsgEthereumTxResponse, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: formatting of the arguments - can we make them vertical?

Copy link
Contributor

@aljo242 aljo242 left a comment

Choose a reason for hiding this comment

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

Left some comments - I'd like for us to have unit tests as well as tests for the e2e grpc_query flow of applying the overrides

Comment on lines +91 to +93
for key, value := range *account.StateDiff {
db.SetState(addr, key, value)
}

Check warning

Code scanning / CodeQL

Iteration over map Warning

Iteration over map may be a possible source of non-determinism
@mmsqe mmsqe requested a review from aljo242 July 29, 2025 01:19
Copy link
Contributor

@cloudgray cloudgray 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 great work!
I left some comments for test and go-ethereum v1.15.x compatibility.

@@ -474,7 +474,7 @@ func (s *TestSuite) TestDoCall() {
s.SetupTest() // reset test and queries
tc.registerMock()

msgEthTx, err := s.backend.DoCall(tc.callArgs, tc.blockNum)
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be good to add a simple test case to check whether the expected result is returned when the state overrides input is set.

@@ -788,6 +788,7 @@ func (s *KeeperTestSuite) TestApplyMessageWithConfig() {
true,
config,
txConfig,
nil,
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the case in test_call_tx.go, it would be good to add a test case for when the state overrides input is set.

@@ -55,6 +60,42 @@ type RPCTransaction struct {
// StateOverride is the collection of overridden accounts.
type StateOverride map[common.Address]OverrideAccount

// Apply overrides the fields of specified accounts into the given state.
func (diff *StateOverride) Apply(db *statedb.StateDB) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

As of go-ethereum v1.15.10, the StateOverride.Apply method includes logic for handling precompile addresses.

From a compatibility standpoint, it may be best to either align the logic to match exactly, or alternatively, directly import the override package from Geth and use its Apply method. In the latter case, the StateDB.Finalise method would likely need to be implemented as a noop function.

@@ -477,6 +477,22 @@ func (s *StateDB) SetState(addr common.Address, key, value common.Hash) common.H
return common.Hash{}
}

// SetBalance sets the balance of account associated with addr to amount.
func (s *StateDB) SetBalance(addr common.Address, amount *uint256.Int) {
Copy link
Contributor

@cloudgray cloudgray Jul 30, 2025

Choose a reason for hiding this comment

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

I think this interface is aligned to go-ethereum v1.11.x.

Currently, cosmos/evm is compatibiile to go-ethereum v1.15.x.

You can check added arg, reason tracing.BalanceChangeReason. (ref)

@@ -263,6 +273,12 @@ func (s *stateObject) SetState(key common.Hash, value common.Hash) common.Hash {
return prev
}

func (s *stateObject) SetStorage(storage Storage) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Comment is needed because it can be confusing considering stateObject.SetStorage does not exist in go-ethereum (v1.15.10)

I suspect the reason this method was added is, it is difficult to use stateObject.StateState as it is. Because SetState sets value to dirtyStorage, and GetCommitedState method cannot get overrided state. So it seems that you alse added stateObject.overrideStorage and let GetCommittedState get state from overrideStorage.

I'm not sure my suspection is correct but anyway, it will helpful for devs to manange code if background explanation of this method is added.

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.

[Feature]: support state overrides in eth_call
3 participants