Skip to content

gethclient call fails if the Code property is not present in the state overrides #25615

@simonovic86

Description

@simonovic86

System information

go-ethereum version: v1.10.23
OS & Version: OSX

Expected behaviour

While using the gethclient/gethclient.go client to override the state with the gethclient/OverrideAccount properties, if the Code property is not present it should be omitted or set to null on marshal.

[
  {
    "data": "0xaa00000000000000000000000000000000000000",
    "from": "0xbb00000000000000000000000000000000000000",
    "to": "0xcc00000000000000000000000000000000000000"
  },
  "latest",
  {
    "0xdd00000000000000000000000000000000000000": {
      "nonce": "0x0",
      "code": null,
      "balance": null,
      "state": null,
      "stateDiff": null
    }
  }
]

Actual behaviour

If the Code property is not present in the overrides, it would still be marshalled into 0x because of the type hexutil.Bytes.

// Bytes marshals/unmarshals as a JSON string with 0x prefix.
// The empty slice marshals as "0x".
type Bytes []byte

The marshalled json:

[
  {
    "data": "0xaa00000000000000000000000000000000000000",
    "from": "0xbb00000000000000000000000000000000000000",
    "to": "0xcc00000000000000000000000000000000000000"
  },
  "latest",
  {
    "0xdd00000000000000000000000000000000000000": {
      "nonce": "0x0",
      "code": "0x",
      "balance": null,
      "state": null,
      "stateDiff": null
    }
  }
]

Because of this behaviour, the request fails with the execution reverted error.

Steps to reproduce the behaviour

// CallContract with override
override := gethclient.OverrideAccount{}

mapAcc := make(map[common.Address]gethclient.OverrideAccount)
mapAcc[address] = override

var err error
var result []byte

if result, err = client.CallContract(context.Background(), msg, nil, &mapAcc); err != nil {
	log.Fatalf("unexpected error: %v", err)
}

Backtrace

[backtrace]

When submitting logs: please submit them as text and not screenshots.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions