From e7ba44b42b51da7a48589d17721aa05928626ae6 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 16 Dec 2024 15:19:38 +0100 Subject: [PATCH] core/state: check for code/codehash mismatch in fuzzer --- core/state/journal_set.go | 1 + core/state/journal_test.go | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/state/journal_set.go b/core/state/journal_set.go index 9ab64cc874..aa5e73b672 100644 --- a/core/state/journal_set.go +++ b/core/state/journal_set.go @@ -217,6 +217,7 @@ func (j *scopedJournal) revert(s *StateDB) { } } else { if !bytes.Equal(obj.CodeHash(), journalHash) { + // TODO @holiman set the code back! obj.setCode(common.BytesToHash(data.codeHash), nil) } } diff --git a/core/state/journal_test.go b/core/state/journal_test.go index d76a2c856e..d0aaf6b801 100644 --- a/core/state/journal_test.go +++ b/core/state/journal_test.go @@ -28,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" "github.com/holiman/uint256" ) @@ -233,7 +234,7 @@ func fuzzJournals(t *testing.T, data []byte) { return } } - if s.GetNonce(addr) == 0 && emptyStorage { + if emptyStorage { s.CreateContract(addr) // We also set some code here, to prevent the // CreateContract action from being performed twice in a row, @@ -345,6 +346,19 @@ func fuzzJournals(t *testing.T, data []byte) { if !slices.Equal(accs1, accs2) { t.Fatalf("mismatched dirty-sets:\n%v\n%v", accs1, accs2) } + + for _, addr := range accs1 { + if cHash := stateDbs[0].GetCodeHash(addr); cHash != types.EmptyCodeHash && cHash != (common.Hash{}) { + have := crypto.Keccak256Hash(stateDbs[0].GetCode(addr)) + if have != cHash { + t.Fatalf("0: mismatched codehash <-> code.\ncodehash: %x\nhash(code): %x\n", cHash, have) + } + have = crypto.Keccak256Hash(stateDbs[1].GetCode(addr)) + if have != cHash { + t.Fatalf("1: mismatched codehash <-> code.\ncodehash: %x\nhash(code): %x\n", cHash, have) + } + } + } } h1, err1 := stateDbs[0].Commit(0, false) h2, err2 := stateDbs[1].Commit(0, false)