tracers/prestate: always remove empty accounts from pre-state (#31427)

The prestateTracer had the intention of excluding accounts that were
empty prior to execution from the prestate. This was being done only for
created contracts. This PR makes it so all such empty accounts are
excluded. This behavior is configurable using the `includeEmpty: true`
flag introduced in #31855.

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
This commit is contained in:
Ignacio Hagopian 2025-06-16 15:34:48 +02:00 committed by GitHub
parent 8b86ff7979
commit e2007e513c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 13 additions and 28 deletions

View file

@ -321,7 +321,7 @@ func TestInternals(t *testing.T) {
byte(vm.LOG0),
},
tracer: mkTracer("prestateTracer", nil),
want: fmt.Sprintf(`{"0x0000000000000000000000000000000000000000":{"balance":"0x0"},"0x00000000000000000000000000000000deadbeef":{"balance":"0x0","code":"0x6001600052600164ffffffffff60016000f560ff6000a0"},"%s":{"balance":"0x1c6bf52634000"}}`, originHex),
want: fmt.Sprintf(`{"0x00000000000000000000000000000000deadbeef":{"balance":"0x0","code":"0x6001600052600164ffffffffff60016000f560ff6000a0"},"%s":{"balance":"0x1c6bf52634000"}}`, originHex),
},
{
// CREATE2 which requires padding memory by prestate tracer
@ -340,7 +340,7 @@ func TestInternals(t *testing.T) {
byte(vm.LOG0),
},
tracer: mkTracer("prestateTracer", nil),
want: fmt.Sprintf(`{"0x0000000000000000000000000000000000000000":{"balance":"0x0"},"0x00000000000000000000000000000000deadbeef":{"balance":"0x0","code":"0x6001600052600160ff60016000f560ff6000a0"},"%s":{"balance":"0x1c6bf52634000"}}`, originHex),
want: fmt.Sprintf(`{"0x00000000000000000000000000000000deadbeef":{"balance":"0x0","code":"0x6001600052600160ff60016000f560ff6000a0"},"%s":{"balance":"0x1c6bf52634000"}}`, originHex),
},
} {
t.Run(tc.name, func(t *testing.T) {

View file

@ -59,8 +59,8 @@
},
"result": {
"0x0024f658a46fbb89d8ac105e98d7ac7cbbaf27c5": {
"balance": "0x0",
"nonce": 22
"balance":"0x0",
"nonce":22
},
"0x3b873a919aa0512d5a0f09e6dcceaa4a6727fafe": {
"balance": "0x4d87094125a369d9bd5",
@ -75,9 +75,6 @@
"0xb436ba50d378d4bbc8660d312a13df6af6e89dfb": {
"balance": "0x1780d77678137ac1b775",
"nonce": 29072
},
"0x1585936b53834b021f68cc13eeefdec2efc8e724": {
"balance": "0x0"
}
}
}

View file

@ -70,9 +70,6 @@
"0xb436ba50d378d4bbc8660d312a13df6af6e89dfb": {
"balance": "0x1780d77678137ac1b775",
"nonce": 29072
},
"0x1585936b53834b021f68cc13eeefdec2efc8e724": {
"balance": "0x0"
}
}
}

View file

@ -70,9 +70,6 @@
"0xb436ba50d378d4bbc8660d312a13df6af6e89dfb": {
"balance": "0x1780d77678137ac1b775",
"nonce": 29072
},
"0x1585936b53834b021f68cc13eeefdec2efc8e724": {
"balance": "0x0"
}
}
}

View file

@ -28,7 +28,7 @@
"0xb436ba50d378d4bbc8660d312a13df6af6e89dfb": {
"balance": "0x1780d77678137ac1b775",
"code": "0x",
"nonce": "29072",
"nonce": 29072,
"storage": {}
}
},
@ -74,9 +74,6 @@
"0xb436ba50d378d4bbc8660d312a13df6af6e89dfb": {
"balance": "0x1780d77678137ac1b775",
"nonce": 29072
},
"0x1585936b53834b021f68cc13eeefdec2efc8e724": {
"balance": "0x0"
}
}
}

View file

@ -64,9 +64,6 @@
"balance": "0x0",
"nonce": 22
},
"0x1585936b53834b021f68cc13eeefdec2efc8e724": {
"balance": "0x0"
},
"0x3b873a919aa0512d5a0f09e6dcceaa4a6727fafe": {
"balance": "0x4d87094125a369d9bd5",
"nonce": 1,

View file

@ -63,9 +63,6 @@
"balance": "0x0",
"nonce": 22
},
"0x1585936b53834b021f68cc13eeefdec2efc8e724": {
"balance": "0x0"
},
"0x3b873a919aa0512d5a0f09e6dcceaa4a6727fafe": {
"balance": "0x4d87094125a369d9bd5",
"nonce": 1,

View file

@ -184,11 +184,14 @@ func (t *prestateTracer) OnTxEnd(receipt *types.Receipt, err error) {
if t.config.DiffMode {
t.processDiffState()
}
// the new created contracts' prestate were empty, so delete them
for a := range t.created {
// the created contract maybe exists in statedb before the creating tx
if s := t.pre[a]; s != nil && s.empty && !t.config.IncludeEmpty {
delete(t.pre, a)
// Remove accounts that were empty prior to execution. Unless
// user requested to include empty accounts.
if t.config.IncludeEmpty {
return
}
for addr, s := range t.pre {
if s.empty {
delete(t.pre, addr)
}
}
}