Skip to content

Commit e2007e5

Browse files
jsigns1na
andauthored
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 <[email protected]> Co-authored-by: Sina Mahmoodi <[email protected]>
1 parent 8b86ff7 commit e2007e5

File tree

8 files changed

+13
-28
lines changed

8 files changed

+13
-28
lines changed

eth/tracers/internal/tracetest/calltrace_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ func TestInternals(t *testing.T) {
321321
byte(vm.LOG0),
322322
},
323323
tracer: mkTracer("prestateTracer", nil),
324-
want: fmt.Sprintf(`{"0x0000000000000000000000000000000000000000":{"balance":"0x0"},"0x00000000000000000000000000000000deadbeef":{"balance":"0x0","code":"0x6001600052600164ffffffffff60016000f560ff6000a0"},"%s":{"balance":"0x1c6bf52634000"}}`, originHex),
324+
want: fmt.Sprintf(`{"0x00000000000000000000000000000000deadbeef":{"balance":"0x0","code":"0x6001600052600164ffffffffff60016000f560ff6000a0"},"%s":{"balance":"0x1c6bf52634000"}}`, originHex),
325325
},
326326
{
327327
// CREATE2 which requires padding memory by prestate tracer
@@ -340,7 +340,7 @@ func TestInternals(t *testing.T) {
340340
byte(vm.LOG0),
341341
},
342342
tracer: mkTracer("prestateTracer", nil),
343-
want: fmt.Sprintf(`{"0x0000000000000000000000000000000000000000":{"balance":"0x0"},"0x00000000000000000000000000000000deadbeef":{"balance":"0x0","code":"0x6001600052600160ff60016000f560ff6000a0"},"%s":{"balance":"0x1c6bf52634000"}}`, originHex),
343+
want: fmt.Sprintf(`{"0x00000000000000000000000000000000deadbeef":{"balance":"0x0","code":"0x6001600052600160ff60016000f560ff6000a0"},"%s":{"balance":"0x1c6bf52634000"}}`, originHex),
344344
},
345345
} {
346346
t.Run(tc.name, func(t *testing.T) {

eth/tracers/internal/tracetest/testdata/prestate_tracer/disable_code.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
},
6060
"result": {
6161
"0x0024f658a46fbb89d8ac105e98d7ac7cbbaf27c5": {
62-
"balance": "0x0",
63-
"nonce": 22
62+
"balance":"0x0",
63+
"nonce":22
6464
},
6565
"0x3b873a919aa0512d5a0f09e6dcceaa4a6727fafe": {
6666
"balance": "0x4d87094125a369d9bd5",
@@ -75,9 +75,6 @@
7575
"0xb436ba50d378d4bbc8660d312a13df6af6e89dfb": {
7676
"balance": "0x1780d77678137ac1b775",
7777
"nonce": 29072
78-
},
79-
"0x1585936b53834b021f68cc13eeefdec2efc8e724": {
80-
"balance": "0x0"
8178
}
8279
}
8380
}

eth/tracers/internal/tracetest/testdata/prestate_tracer/disable_code_and_storage.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@
7070
"0xb436ba50d378d4bbc8660d312a13df6af6e89dfb": {
7171
"balance": "0x1780d77678137ac1b775",
7272
"nonce": 29072
73-
},
74-
"0x1585936b53834b021f68cc13eeefdec2efc8e724": {
75-
"balance": "0x0"
7673
}
7774
}
7875
}

eth/tracers/internal/tracetest/testdata/prestate_tracer/disable_storage.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@
7070
"0xb436ba50d378d4bbc8660d312a13df6af6e89dfb": {
7171
"balance": "0x1780d77678137ac1b775",
7272
"nonce": 29072
73-
},
74-
"0x1585936b53834b021f68cc13eeefdec2efc8e724": {
75-
"balance": "0x0"
7673
}
7774
}
7875
}

eth/tracers/internal/tracetest/testdata/prestate_tracer/simple.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"0xb436ba50d378d4bbc8660d312a13df6af6e89dfb": {
2929
"balance": "0x1780d77678137ac1b775",
3030
"code": "0x",
31-
"nonce": "29072",
31+
"nonce": 29072,
3232
"storage": {}
3333
}
3434
},
@@ -74,9 +74,6 @@
7474
"0xb436ba50d378d4bbc8660d312a13df6af6e89dfb": {
7575
"balance": "0x1780d77678137ac1b775",
7676
"nonce": 29072
77-
},
78-
"0x1585936b53834b021f68cc13eeefdec2efc8e724": {
79-
"balance": "0x0"
8077
}
8178
}
8279
}

eth/tracers/internal/tracetest/testdata/prestate_tracer_with_diff_mode/simple.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@
6464
"balance": "0x0",
6565
"nonce": 22
6666
},
67-
"0x1585936b53834b021f68cc13eeefdec2efc8e724": {
68-
"balance": "0x0"
69-
},
7067
"0x3b873a919aa0512d5a0f09e6dcceaa4a6727fafe": {
7168
"balance": "0x4d87094125a369d9bd5",
7269
"nonce": 1,

eth/tracers/internal/tracetest/testdata/prestate_tracer_with_diff_mode/simple_disable_code_and_storage.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@
6363
"balance": "0x0",
6464
"nonce": 22
6565
},
66-
"0x1585936b53834b021f68cc13eeefdec2efc8e724": {
67-
"balance": "0x0"
68-
},
6966
"0x3b873a919aa0512d5a0f09e6dcceaa4a6727fafe": {
7067
"balance": "0x4d87094125a369d9bd5",
7168
"nonce": 1,

eth/tracers/native/prestate.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,14 @@ func (t *prestateTracer) OnTxEnd(receipt *types.Receipt, err error) {
184184
if t.config.DiffMode {
185185
t.processDiffState()
186186
}
187-
// the new created contracts' prestate were empty, so delete them
188-
for a := range t.created {
189-
// the created contract maybe exists in statedb before the creating tx
190-
if s := t.pre[a]; s != nil && s.empty && !t.config.IncludeEmpty {
191-
delete(t.pre, a)
187+
// Remove accounts that were empty prior to execution. Unless
188+
// user requested to include empty accounts.
189+
if t.config.IncludeEmpty {
190+
return
191+
}
192+
for addr, s := range t.pre {
193+
if s.empty {
194+
delete(t.pre, addr)
192195
}
193196
}
194197
}

0 commit comments

Comments
 (0)