Skip to content

Commit a404195

Browse files
jsvisas1na
andauthored
eth/tracers: fix the issue prestate missing existing contract state (#25996)
The prestate tracer did not report accounts that existed at a given address prior to a contract being created at that address. Signed-off-by: Delweng <[email protected]> Co-authored-by: Sina Mahmoodi <[email protected]>
1 parent 9b9a1b6 commit a404195

File tree

2 files changed

+101
-7
lines changed

2 files changed

+101
-7
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"genesis": {
3+
"difficulty": "6217248151198",
4+
"extraData": "0xd783010103844765746887676f312e342e32856c696e7578",
5+
"gasLimit": "3141592",
6+
"hash": "0xe8bff55fe3e61936ef321cf3afaeb1ba2f7234e1e89535fa8ae39963caebe9c3",
7+
"miner": "0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5",
8+
"mixHash": "0x03da00d5a15a064e5ebddf53cd0aaeb9a8aff0f40c0fb031a74f463d11ec83b8",
9+
"nonce": "0x6575fe08c4167044",
10+
"number": "243825",
11+
"stateRoot": "0x47182fe2e6e740b8a76f82fe5c527d6ad548f805274f21792cf4047235b24fbf",
12+
"timestamp": "1442424328",
13+
"totalDifficulty": "1035061827427752845",
14+
"alloc": {
15+
"0x082d4cdf07f386ffa9258f52a5c49db4ac321ec6": {
16+
"balance": "0xc820f93200f4000",
17+
"nonce": "0x5E",
18+
"code": "0x"
19+
},
20+
"0x332b656504f4eabb44c8617a42af37461a34e9dc": {
21+
"balance": "0x11faea4f35e5af80000",
22+
"code": "0x"
23+
},
24+
"0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5": {
25+
"balance": "0xbf681825be002ac452",
26+
"nonce": "0x70FA",
27+
"code": "0x"
28+
},
29+
"0x82effbaaaf28614e55b2ba440fb198e0e5789b0f": {
30+
"balance": "0xb3d0ac5cb94df6f6b0",
31+
"nonce": "0x1",
32+
"code": "0x"
33+
}
34+
},
35+
"config": {
36+
"chainId": 1,
37+
"homesteadBlock": 1150000,
38+
"daoForkBlock": 1920000,
39+
"daoForkSupport": true,
40+
"eip150Block": 2463000,
41+
"eip150Hash": "0x2086799aeebeae135c246c65021c82b4e15a2c451340993aacfd2751886514f0",
42+
"eip155Block": 2675000,
43+
"eip158Block": 2675000,
44+
"byzantiumBlock": 4370000,
45+
"constantinopleBlock": 7280000,
46+
"petersburgBlock": 7280000,
47+
"istanbulBlock": 9069000,
48+
"muirGlacierBlock": 9200000,
49+
"berlinBlock": 12244000,
50+
"londonBlock": 12965000,
51+
"arrowGlacierBlock": 13773000,
52+
"grayGlacierBlock": 15050000,
53+
"terminalTotalDifficultyPassed": true,
54+
"ethash": {}
55+
}
56+
},
57+
"context": {
58+
"number": "243826",
59+
"difficulty": "6214212385501",
60+
"timestamp": "1442424353",
61+
"gasLimit": "3141592",
62+
"miner": "0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5"
63+
},
64+
"input": "0xf8e85e850ba43b7400830f42408080b89660606040527382effbaaaf28614e55b2ba440fb198e0e5789b0f600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b600a80608c6000396000f30060606040526008565b001ca0340b21661e5bb85a46319a15f33a362e5c0f02faa7cdbf9c5808b2134da968eaa0226e6788f8c20e211d436ab7f6298ef32fa4c23a509eeeaac0880d115c17bc3f",
65+
"result": {
66+
"0x082d4cdf07f386ffa9258f52a5c49db4ac321ec6": {
67+
"balance": "0xc820f93200f4000",
68+
"nonce": 94
69+
},
70+
"0x332b656504f4eabb44c8617a42af37461a34e9dc": {
71+
"balance": "0x11faea4f35e5af80000",
72+
"storage": {
73+
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x0000000000000000000000000000000000000000000000000000000000000000"
74+
}
75+
},
76+
"0x52bc44d5378309ee2abf1539bf71de1b7d7be3b5": {
77+
"balance": "0xbf681825be002ac452",
78+
"nonce": 28922
79+
},
80+
"0x82effbaaaf28614e55b2ba440fb198e0e5789b0f": {
81+
"balance": "0xb3d0ac5cb94df6f6b0",
82+
"nonce": 1
83+
}
84+
}
85+
}

eth/tracers/native/prestate.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ type account struct {
4545
Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
4646
}
4747

48+
func (a *account) exists() bool {
49+
return a.Balance.Sign() != 0 || a.Nonce > 0 || len(a.Code) > 0 || len(a.Storage) > 0
50+
}
51+
4852
type accountMarshaling struct {
4953
Balance *hexutil.Big
5054
Code hexutil.Bytes
@@ -116,9 +120,16 @@ func (t *prestateTracer) CaptureStart(env *vm.EVM, from common.Address, to commo
116120

117121
// CaptureEnd is called after the call finishes to finalize the tracing.
118122
func (t *prestateTracer) CaptureEnd(output []byte, gasUsed uint64, _ time.Duration, err error) {
119-
if t.create && !t.config.DiffMode {
120-
// Exclude created contract.
121-
delete(t.pre, t.to)
123+
if t.config.DiffMode {
124+
return
125+
}
126+
127+
if t.create {
128+
// Keep existing account prior to contract creation at that address
129+
if s := t.pre[t.to]; s != nil && !s.exists() {
130+
// Exclude newly created contract.
131+
delete(t.pre, t.to)
132+
}
122133
}
123134
}
124135

@@ -229,10 +240,8 @@ func (t *prestateTracer) CaptureTxEnd(restGas uint64) {
229240
// the new created contracts' prestate were empty, so delete them
230241
for a := range t.created {
231242
// the created contract maybe exists in statedb before the creating tx
232-
if s := t.pre[a]; s != nil {
233-
if s.Balance.Sign() == 0 && len(s.Storage) == 0 && len(s.Code) == 0 {
234-
delete(t.pre, a)
235-
}
243+
if s := t.pre[a]; s != nil && !s.exists() {
244+
delete(t.pre, a)
236245
}
237246
}
238247
}

0 commit comments

Comments
 (0)