Skip to content

Commit d7b3ae0

Browse files
lupin012claude
andauthored
rpc: fix prestateTracer diff mode missing deleted accounts (#20807)
Replaces repeated t.pre[addr] map lookups with the range variable `state` Re-enable test_33/test_34 of debug_traceBlockByNumber() --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1124c7d commit d7b3ae0

5 files changed

Lines changed: 18 additions & 23 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
RPC_VERSION=v2.8.1
1+
RPC_VERSION=v2.8.2

.github/workflows/scripts/run_rpc_tests_ethereum.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ DISABLED_TEST_LIST=(
1919
net_listening/test_1.json
2020
# Temporary disable required block 24298763
2121
debug_traceBlockByNumber/test_51.json
22-
# Temporary disable after merge #20830, waiting for new rpc-tests tag after merge PR #552
23-
debug_traceBlockByNumber/test_33.tar
24-
debug_traceBlockByNumber/test_34.tar
2522
# to investigate
2623
engine_exchangeCapabilities/test_1.json
2724
engine_exchangeTransitionConfigurationV1/test_01.json

.github/workflows/scripts/run_rpc_tests_remote_ethereum.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ DISABLED_TEST_LIST=(
2020
# these tests/apis are disabled because some methods are not implmented on grpc
2121
eth_getProof
2222
eth_simulateV1
23-
# Temporary disable after merge #20830, waiting for new rpc-tests tag after merge PR #552
24-
debug_traceBlockByNumber/test_33.tar
25-
debug_traceBlockByNumber/test_34.tar
2623
# Temporary disable required block 24298763
2724
debug_traceBlockByNumber/test_51.json
2825
# Temporary disable required block 23917742

execution/tracing/tracers/native/prestate.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -283,24 +283,24 @@ func (t *prestateTracer) processDiffState() {
283283

284284
newBalance, _ := t.env.IntraBlockState.GetBalance(addr)
285285
newNonce, _ := t.env.IntraBlockState.GetNonce(addr)
286-
// GetCodeHash returns common.Hash{} for deleted accounts; GetCode cannot make
287-
// that distinction (empty bytes for both deleted and codeless accounts).
286+
// GetCode returns empty bytes for both deleted and codeless accounts;
287+
// GetCodeHash distinguishes them (deleted → zero hash).
288288
codeHash, _ := t.env.IntraBlockState.GetCodeHash(addr)
289289
newCodeHash := codeHash.Value()
290290

291291
newBalanceBig := newBalance.ToBig()
292-
if newBalanceBig.Cmp(t.pre[addr].Balance) != 0 {
292+
if newBalanceBig.Cmp(state.Balance) != 0 {
293293
modified = true
294294
postAccount.Balance = newBalanceBig
295295
}
296-
if newNonce != t.pre[addr].Nonce {
296+
if newNonce != state.Nonce {
297297
modified = true
298298
postAccount.Nonce = newNonce
299299
}
300300

301301
prevCodeHash := empty.CodeHash
302-
if t.pre[addr].CodeHash != nil {
303-
prevCodeHash = *t.pre[addr].CodeHash
302+
if state.CodeHash != nil {
303+
prevCodeHash = *state.CodeHash
304304
}
305305

306306
if newCodeHash != prevCodeHash {
@@ -311,8 +311,8 @@ func (t *prestateTracer) processDiffState() {
311311
if !t.config.DisableCode {
312312
newCode, _ := t.env.IntraBlockState.GetCode(addr)
313313
var prevCode []byte
314-
if t.pre[addr].Code != nil {
315-
prevCode = *t.pre[addr].Code
314+
if state.Code != nil {
315+
prevCode = *state.Code
316316
}
317317
if !bytes.Equal(newCode, prevCode) {
318318
modified = true
@@ -324,13 +324,13 @@ func (t *prestateTracer) processDiffState() {
324324
for key, val := range state.Storage {
325325
// don't include the empty slot
326326
if val == (common.Hash{}) {
327-
delete(t.pre[addr].Storage, key)
327+
delete(state.Storage, key)
328328
}
329329

330330
newVal, _ := t.env.IntraBlockState.GetState(addr, accounts.InternKey(key))
331331
if new(uint256.Int).SetBytes(val[:]).Eq(&newVal) {
332332
// Omit unchanged slots
333-
delete(t.pre[addr].Storage, key)
333+
delete(state.Storage, key)
334334
} else {
335335
modified = true
336336
if !newVal.IsZero() {

execution/tracing/tracers/native/prestate_deleted_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
"github.com/erigontech/erigon/execution/types/accounts"
3030
)
3131

32+
var _ tracing.IntraBlockState = (*postTxIBS)(nil)
33+
3234
// postTxIBS simulates the IntraBlockState *after* a transaction where deletedAddr
3335
// no longer exists (GetCodeHash returns NilCodeHash) and all other accounts are
3436
// codeless-but-existent (EmptyCodeHash).
@@ -39,17 +41,17 @@ type postTxIBS struct {
3941
func (m *postTxIBS) GetBalance(accounts.Address) (uint256.Int, error) { return uint256.Int{}, nil }
4042
func (m *postTxIBS) GetNonce(accounts.Address) (uint64, error) { return 0, nil }
4143
func (m *postTxIBS) GetCode(accounts.Address) ([]byte, error) { return nil, nil }
42-
func (m *postTxIBS) GetState(accounts.Address, accounts.StorageKey) (uint256.Int, error) {
43-
return uint256.Int{}, nil
44-
}
45-
func (m *postTxIBS) Exist(accounts.Address) (bool, error) { return false, nil }
46-
func (m *postTxIBS) GetRefund() mdgas.MdGas { return mdgas.MdGas{} }
4744
func (m *postTxIBS) GetCodeHash(addr accounts.Address) (accounts.CodeHash, error) {
4845
if addr == m.deletedAddr {
4946
return accounts.NilCodeHash, nil
5047
}
5148
return accounts.EmptyCodeHash, nil
5249
}
50+
func (m *postTxIBS) GetState(accounts.Address, accounts.StorageKey) (uint256.Int, error) {
51+
return uint256.Int{}, nil
52+
}
53+
func (m *postTxIBS) Exist(accounts.Address) (bool, error) { return false, nil }
54+
func (m *postTxIBS) GetRefund() mdgas.MdGas { return mdgas.MdGas{} }
5355

5456
// TestPrestateTracerDiffModeDeletedAccount verifies that an account deleted during
5557
// a tx appears in the diff-mode post state with codeHash == 0x000...000.
@@ -64,7 +66,6 @@ func TestPrestateTracerDiffModeDeletedAccount(t *testing.T) {
6466
deleted: make(map[accounts.Address]bool),
6567
}
6668

67-
// Pre-tx: codeless account — no CodeHash set, balance = 0.
6869
tr.pre[deletedAddr] = &account{Balance: big.NewInt(0)}
6970

7071
tr.env = &tracing.VMContext{

0 commit comments

Comments
 (0)