Skip to content

Commit 19607d1

Browse files
eth/tracers: Fix prestateTracer pre nonce on contract creation (#29099)
The prestateTracer was reporting an inaccurate nonce for the contract being created in post EIP-158 transactions. Correct nonce is 0, due to the issue nonce was being reported as 1.
1 parent ca473b8 commit 19607d1

File tree

3 files changed

+149
-0
lines changed

3 files changed

+149
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"genesis": {
3+
"baseFeePerGas": "7",
4+
"difficulty": "2",
5+
"extraData": "0xd983010d0e846765746888676f312e32312e318664617277696e0000000000001713699f05f79a59abec177c7a87b90ceda79b72ff5edc9197dd7627a447cde45b079bbc3765a236cdf680e2d4d2247135d0e6bb6fd92b50638b92504ddb274f00",
6+
"gasLimit": "30000000",
7+
"hash": "0x6ad5258175c66f4e883d238a92a08428d8ebcbeac631ab7b972634cc05effab3",
8+
"miner": "0x2445e8c26a2bf3d1e59f1bb9b1d442caf90768e0",
9+
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
10+
"nonce": "0x0000000000000000",
11+
"number": "39137",
12+
"stateRoot": "0x715f00df764dbadd4863247a215ac44b5420beafde3ec458b15db7aafa89be0c",
13+
"timestamp": "1709022192",
14+
"totalDifficulty": "78275",
15+
"alloc": {
16+
"0x2445e8c26a2bf3d1e59f1bb9b1d442caf90768e0": {
17+
"balance": "0x10f06447a8d44dba190",
18+
"nonce": "2"
19+
},
20+
"0x82211934c340b29561381392348d48413e15adc8": {
21+
"balance": "0x6abd7a808913ed2",
22+
"nonce": "64"
23+
}
24+
},
25+
"config": {
26+
"chainId": 12345,
27+
"homesteadBlock": 0,
28+
"eip150Block": 0,
29+
"eip155Block": 0,
30+
"eip158Block": 0,
31+
"byzantiumBlock": 0,
32+
"constantinopleBlock": 0,
33+
"petersburgBlock": 0,
34+
"istanbulBlock": 0,
35+
"muirGlacierBlock": 0,
36+
"berlinBlock": 0,
37+
"londonBlock": 0,
38+
"arrowGlacierBlock": 0,
39+
"grayGlacierBlock": 0,
40+
"clique": {
41+
"period": 5,
42+
"epoch": 30000
43+
}
44+
}
45+
},
46+
"context": {
47+
"number": "39138",
48+
"difficulty": "2",
49+
"timestamp": "1709022197",
50+
"gasLimit": "30000000",
51+
"miner": "0x2445e8c26a2bf3d1e59f1bb9b1d442caf90768e0"
52+
},
53+
"input": "0x02f902af823039408459682f008459682f088302b3538080b90254608060405234801561001057600080fd5b50610234806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806309ce9ccb1461003b5780633fb5c1cb14610059575b600080fd5b610043610075565b60405161005091906100e2565b60405180910390f35b610073600480360381019061006e919061012e565b61007b565b005b60005481565b80600081905550600a8111156100c6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100bd906101de565b60405180910390fd5b50565b6000819050919050565b6100dc816100c9565b82525050565b60006020820190506100f760008301846100d3565b92915050565b600080fd5b61010b816100c9565b811461011657600080fd5b50565b60008135905061012881610102565b92915050565b600060208284031215610144576101436100fd565b5b600061015284828501610119565b91505092915050565b600082825260208201905092915050565b7f4e756d6265722069732067726561746572207468616e2031302c207472616e7360008201527f616374696f6e2072657665727465642e00000000000000000000000000000000602082015250565b60006101c860308361015b565b91506101d38261016c565b604082019050919050565b600060208201905081810360008301526101f7816101bb565b905091905056fea264697066735822122069018995fecf03bda91a88b6eafe41641709dee8b4a706fe301c8a569fe8c1b364736f6c63430008130033c001a0a8cf4729b7e4664687abb3e2559853d7d489eb441519be2a17493061fb4c3a03a04b5a904ba8a6e59c6c40049c4d14a73233aeb8a45b38403199f304630dc0d453",
54+
"result": {
55+
"0x2445e8c26a2bf3d1e59f1bb9b1d442caf90768e0": {
56+
"balance": "0x10f06447a8d44dba190",
57+
"nonce": 2
58+
},
59+
"0x82211934c340b29561381392348d48413e15adc8": {
60+
"balance": "0x6abd7a808913ed2",
61+
"nonce": 64
62+
}
63+
}
64+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"genesis": {
3+
"baseFeePerGas": "7",
4+
"difficulty": "2",
5+
"extraData": "0xd983010d0e846765746888676f312e32312e318664617277696e0000000000001713699f05f79a59abec177c7a87b90ceda79b72ff5edc9197dd7627a447cde45b079bbc3765a236cdf680e2d4d2247135d0e6bb6fd92b50638b92504ddb274f00",
6+
"gasLimit": "30000000",
7+
"hash": "0x6ad5258175c66f4e883d238a92a08428d8ebcbeac631ab7b972634cc05effab3",
8+
"miner": "0x2445e8c26a2bf3d1e59f1bb9b1d442caf90768e0",
9+
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
10+
"nonce": "0x0000000000000000",
11+
"number": "39137",
12+
"stateRoot": "0x715f00df764dbadd4863247a215ac44b5420beafde3ec458b15db7aafa89be0c",
13+
"timestamp": "1709022192",
14+
"totalDifficulty": "78275",
15+
"alloc": {
16+
"0x2445e8c26a2bf3d1e59f1bb9b1d442caf90768e0": {
17+
"balance": "0x10f06447a8d44dba190",
18+
"nonce": "2"
19+
},
20+
"0x82211934c340b29561381392348d48413e15adc8": {
21+
"balance": "0x6abd7a808913ed2",
22+
"nonce": "64"
23+
}
24+
},
25+
"config": {
26+
"chainId": 12345,
27+
"homesteadBlock": 0,
28+
"eip150Block": 0,
29+
"eip155Block": 0,
30+
"eip158Block": 0,
31+
"byzantiumBlock": 0,
32+
"constantinopleBlock": 0,
33+
"petersburgBlock": 0,
34+
"istanbulBlock": 0,
35+
"muirGlacierBlock": 0,
36+
"berlinBlock": 0,
37+
"londonBlock": 0,
38+
"arrowGlacierBlock": 0,
39+
"grayGlacierBlock": 0,
40+
"clique": {
41+
"period": 5,
42+
"epoch": 30000
43+
}
44+
}
45+
},
46+
"context": {
47+
"number": "39138",
48+
"difficulty": "2",
49+
"timestamp": "1709022197",
50+
"gasLimit": "30000000",
51+
"miner": "0x2445e8c26a2bf3d1e59f1bb9b1d442caf90768e0"
52+
},
53+
"input": "0x02f902af823039408459682f008459682f088302b3538080b90254608060405234801561001057600080fd5b50610234806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806309ce9ccb1461003b5780633fb5c1cb14610059575b600080fd5b610043610075565b60405161005091906100e2565b60405180910390f35b610073600480360381019061006e919061012e565b61007b565b005b60005481565b80600081905550600a8111156100c6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100bd906101de565b60405180910390fd5b50565b6000819050919050565b6100dc816100c9565b82525050565b60006020820190506100f760008301846100d3565b92915050565b600080fd5b61010b816100c9565b811461011657600080fd5b50565b60008135905061012881610102565b92915050565b600060208284031215610144576101436100fd565b5b600061015284828501610119565b91505092915050565b600082825260208201905092915050565b7f4e756d6265722069732067726561746572207468616e2031302c207472616e7360008201527f616374696f6e2072657665727465642e00000000000000000000000000000000602082015250565b60006101c860308361015b565b91506101d38261016c565b604082019050919050565b600060208201905081810360008301526101f7816101bb565b905091905056fea264697066735822122069018995fecf03bda91a88b6eafe41641709dee8b4a706fe301c8a569fe8c1b364736f6c63430008130033c001a0a8cf4729b7e4664687abb3e2559853d7d489eb441519be2a17493061fb4c3a03a04b5a904ba8a6e59c6c40049c4d14a73233aeb8a45b38403199f304630dc0d453",
54+
"tracerConfig": {
55+
"diffMode": true
56+
},
57+
"result": {
58+
"post": {
59+
"0x1bda2f8e4735507930bd6cfe873bf0bf0f4ab1de": {
60+
"code": "0x608060405234801561001057600080fd5b50600436106100365760003560e01c806309ce9ccb1461003b5780633fb5c1cb14610059575b600080fd5b610043610075565b60405161005091906100e2565b60405180910390f35b610073600480360381019061006e919061012e565b61007b565b005b60005481565b80600081905550600a8111156100c6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100bd906101de565b60405180910390fd5b50565b6000819050919050565b6100dc816100c9565b82525050565b60006020820190506100f760008301846100d3565b92915050565b600080fd5b61010b816100c9565b811461011657600080fd5b50565b60008135905061012881610102565b92915050565b600060208284031215610144576101436100fd565b5b600061015284828501610119565b91505092915050565b600082825260208201905092915050565b7f4e756d6265722069732067726561746572207468616e2031302c207472616e7360008201527f616374696f6e2072657665727465642e00000000000000000000000000000000602082015250565b60006101c860308361015b565b91506101d38261016c565b604082019050919050565b600060208201905081810360008301526101f7816101bb565b905091905056fea264697066735822122069018995fecf03bda91a88b6eafe41641709dee8b4a706fe301c8a569fe8c1b364736f6c63430008130033",
61+
"nonce": 1
62+
},
63+
"0x2445e8c26a2bf3d1e59f1bb9b1d442caf90768e0": {
64+
"balance": "0x10f0645688331eb5690"
65+
},
66+
"0x82211934c340b29561381392348d48413e15adc8": {
67+
"balance": "0x6aae9b21b6ee855",
68+
"nonce": 65
69+
}
70+
},
71+
"pre": {
72+
"0x2445e8c26a2bf3d1e59f1bb9b1d442caf90768e0": {
73+
"balance": "0x10f06447a8d44dba190",
74+
"nonce": 2
75+
},
76+
"0x82211934c340b29561381392348d48413e15adc8": {
77+
"balance": "0x6abd7a808913ed2",
78+
"nonce": 64
79+
}
80+
}
81+
}
82+
}

eth/tracers/native/prestate.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ func (t *prestateTracer) CaptureStart(env *vm.EVM, from common.Address, to commo
102102
// The recipient balance includes the value transferred.
103103
toBal := new(big.Int).Sub(t.pre[to].Balance, value)
104104
t.pre[to].Balance = toBal
105+
if env.ChainConfig().Rules(env.Context.BlockNumber, env.Context.Random != nil, env.Context.Time).IsEIP158 && create {
106+
t.pre[to].Nonce--
107+
}
105108

106109
// The sender balance is after reducing: value and gasLimit.
107110
// We need to re-add them to get the pre-tx balance.

0 commit comments

Comments
 (0)