only include code hash for contracts

This commit is contained in:
Sina Mahmoodi 2025-08-12 16:38:55 +02:00
parent 40968d8b13
commit 651229775e
2 changed files with 22 additions and 9 deletions

View file

@ -17,7 +17,7 @@ func (a account) MarshalJSON() ([]byte, error) {
type account struct {
Balance *hexutil.Big `json:"balance,omitempty"`
Code hexutil.Bytes `json:"code,omitempty"`
CodeHash common.Hash `json:"codeHash,omitempty"`
CodeHash *common.Hash `json:"codeHash,omitempty"`
Nonce uint64 `json:"nonce,omitempty"`
Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
}
@ -50,7 +50,7 @@ func (a *account) UnmarshalJSON(input []byte) error {
a.Code = *dec.Code
}
if dec.CodeHash != nil {
a.CodeHash = *dec.CodeHash
a.CodeHash = dec.CodeHash
}
if dec.Nonce != nil {
a.Nonce = *dec.Nonce

View file

@ -46,7 +46,7 @@ type stateMap = map[common.Address]*account
type account struct {
Balance *big.Int `json:"balance,omitempty"`
Code []byte `json:"code,omitempty"`
CodeHash common.Hash `json:"codeHash,omitempty"`
CodeHash *common.Hash `json:"codeHash,omitempty"`
Nonce uint64 `json:"nonce,omitempty"`
Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
empty bool
@ -258,9 +258,18 @@ func (t *prestateTracer) processDiffState() {
modified = true
postAccount.Nonce = newNonce
}
if newCodeHash != t.pre[addr].CodeHash {
prevCodeHash := common.Hash{}
if t.pre[addr].CodeHash != nil {
prevCodeHash = *t.pre[addr].CodeHash
}
// Empty code hashes are excluded from the prestate. Normalize
// the empty code hash to a zero hash to make it comparable.
if newCodeHash == types.EmptyCodeHash {
newCodeHash = common.Hash{}
}
if newCodeHash != prevCodeHash {
modified = true
postAccount.CodeHash = newCodeHash
postAccount.CodeHash = &newCodeHash
}
if !t.config.DisableCode {
newCode := t.env.StateDB.GetCode(addr)
@ -307,10 +316,14 @@ func (t *prestateTracer) lookupAccount(addr common.Address) {
}
acc := &account{
Balance: t.env.StateDB.GetBalance(addr).ToBig(),
Nonce: t.env.StateDB.GetNonce(addr),
Code: t.env.StateDB.GetCode(addr),
CodeHash: t.env.StateDB.GetCodeHash(addr),
Balance: t.env.StateDB.GetBalance(addr).ToBig(),
Nonce: t.env.StateDB.GetNonce(addr),
Code: t.env.StateDB.GetCode(addr),
}
codeHash := t.env.StateDB.GetCodeHash(addr)
// If the code is empty, we don't need to store it in the prestate.
if codeHash != (common.Hash{}) && codeHash != types.EmptyCodeHash {
acc.CodeHash = &codeHash
}
if !acc.exists() {
acc.empty = true