Skip to content

Commit

Permalink
Use the same data type as go-ethereum in the stateDiff override for e…
Browse files Browse the repository at this point in the history
…th_call (#10531)

Change the datatype used for the "stateDiff" override to eth_call to a
hash instead of a uint256.

https://github.com/ethereum/go-ethereum/blob/171430c3f5d474327bc1721c7c36ad83ad21b4b2/internal/ethapi/api.go#L975-L976
  • Loading branch information
boyuan-chen authored and AskAlexSharov committed Jul 27, 2024
1 parent ea49def commit 2e9aa02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 5 additions & 5 deletions turbo/adapter/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ func (args *CallArgs) ToMessage(globalGasCap uint64, baseFee *uint256.Int) (type
// if statDiff is set, all diff will be applied first and then execute the call
// message.
type Account struct {
Nonce *hexutil.Uint64 `json:"nonce"`
Code *hexutility.Bytes `json:"code"`
Balance **hexutil.Big `json:"balance"`
State *map[libcommon.Hash]uint256.Int `json:"state"`
StateDiff *map[libcommon.Hash]uint256.Int `json:"stateDiff"`
Nonce *hexutil.Uint64 `json:"nonce"`
Code *hexutility.Bytes `json:"code"`
Balance **hexutil.Big `json:"balance"`
State *map[libcommon.Hash]libcommon.Hash `json:"state"`
StateDiff *map[libcommon.Hash]libcommon.Hash `json:"stateDiff"`
}

func NewRevertError(result *core.ExecutionResult) *RevertError {
Expand Down
10 changes: 8 additions & 2 deletions turbo/adapter/ethapi/state_overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ func (overrides *StateOverrides) Override(state *state.IntraBlockState) error {
}
// Replace entire state if caller requires.
if account.State != nil {
state.SetStorage(addr, *account.State)
intState := map[libcommon.Hash]uint256.Int{}
for key, value := range *account.State {
intValue := new(uint256.Int).SetBytes32(value.Bytes())
intState[key] = *intValue
}
state.SetStorage(addr, intState)
}
// Apply state diff into specified accounts.
if account.StateDiff != nil {
for key, value := range *account.StateDiff {
key := key
state.SetState(addr, &key, value)
intValue := new(uint256.Int).SetBytes32(value.Bytes())
state.SetState(addr, &key, *intValue)
}
}
}
Expand Down

0 comments on commit 2e9aa02

Please sign in to comment.