Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add history contract to TestProcessorVerkle #503

Open
wants to merge 1 commit into
base: kaustinen-with-shapella
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,12 @@ func GenerateVerkleChain(config *params.ChainConfig, parent *types.Block, engine
keyvals = append(keyvals, block.ExecutionWitness().StateDiff)
proots = append(proots, parent.Root())

// quick check that we are self-consistent
err = trie.DeserializeAndVerifyVerkleProof(block.ExecutionWitness().VerkleProof, block.ExecutionWitness().ParentStateRoot[:], block.Root().Bytes(), block.ExecutionWitness().StateDiff)
if err != nil {
panic(err)
}

return block, b.receipts
}
return nil, nil
Expand Down
48 changes: 46 additions & 2 deletions core/state_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
//"os"
"testing"

"github.com/davecgh/go-spew/spew"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/consensus"
Expand Down Expand Up @@ -475,6 +476,10 @@ func TestProcessVerkle(t *testing.T) {
Balance: big.NewInt(1000000000000000000), // 1 ether
Nonce: 0,
},
params.HistoryStorageAddress: GenesisAccount{
Balance: big.NewInt(0),
Nonce: 1,
},
},
}
loggerCfg = &logger.Config{}
Expand Down Expand Up @@ -601,6 +606,13 @@ func TestProcessVerkle(t *testing.T) {
//rlp.Encode(&buf, chain[1])
//f.Write(buf.Bytes())
//fmt.Printf("root= %x\n", chain[0].Root())

// check the proof for the 1st block
err = trie.DeserializeAndVerifyVerkleProof(proofs[0], genesis.Root().Bytes(), chain[0].Root().Bytes(), keyvals[0])
if err != nil {
spew.Dump(genesis.Root().Bytes(), proofs[0])
t.Fatal(err)
}
// check the proof for the last block
err = trie.DeserializeAndVerifyVerkleProof(proofs[1], chain[0].Root().Bytes(), chain[1].Root().Bytes(), keyvals[1])
if err != nil {
Expand Down Expand Up @@ -669,6 +681,10 @@ func TestProcessVerkleInvalidContractCreation(t *testing.T) {
Balance: big.NewInt(1000000000000000000), // 1 ether
Nonce: 1,
},
params.HistoryStorageAddress: GenesisAccount{
Copy link
Collaborator

@jsign jsign Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we should add it with the right code, correct?
Maybe irrelevant for these tests, but we can pull the code from the GenesisAlloc in execution-spec-tests if useful.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc, we decided to use the code for mainnet, but in the spec it's fine as long as the account exists (which it will with nonce 1).

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and I'd prefer waiting for the contract to have been reviewed before adding it

Balance: big.NewInt(0),
Nonce: 1,
},
},
}
)
Expand Down Expand Up @@ -775,8 +791,8 @@ func TestProcessVerkleInvalidContractCreation(t *testing.T) {
if stemStateDiff.SuffixDiffs[0].NewValue == nil {
t.Fatalf("missing post state value for BLOCKHASH contract at block #2")
}
if *stemStateDiff.SuffixDiffs[0].NewValue != common.HexToHash("ac9ab8a7d88cfee11ebcda5f47232c07fcb393c8916e37fa67eb5e315b1f8ef6") {
t.Fatalf("invalid post state value for BLOCKHASH contract at block #2: ac9ab8a7d88cfee11ebcda5f47232c07fcb393c8916e37fa67eb5e315b1f8ef6 != %x", (*stemStateDiff.SuffixDiffs[0].NewValue)[:])
if *stemStateDiff.SuffixDiffs[0].NewValue != common.HexToHash("0788c2c0f23aa07eb8bf76fe6c1ca9064a4821c1fd0af803913da488a58dba54") {
t.Fatalf("invalid post state value for BLOCKHASH contract at block #2: 0788c2c0f23aa07eb8bf76fe6c1ca9064a4821c1fd0af803913da488a58dba54 != %x", (*stemStateDiff.SuffixDiffs[0].NewValue)[:])
}
} else if suffixDiff.Suffix > 4 {
t.Fatalf("invalid suffix diff found for %x in block #2: %d\n", stemStateDiff.Stem, suffixDiff.Suffix)
Expand Down Expand Up @@ -827,6 +843,10 @@ func TestProcessVerkleContractWithEmptyCode(t *testing.T) {
Balance: big.NewInt(1000000000000000000), // 1 ether
Nonce: 3,
},
params.HistoryStorageAddress: GenesisAccount{
Balance: big.NewInt(0),
Nonce: 1,
},
},
}
)
Expand Down Expand Up @@ -922,6 +942,10 @@ func TestProcessVerklExtCodeHashOpcode(t *testing.T) {
Balance: big.NewInt(1000000000000000000), // 1 ether
Nonce: 3,
},
params.HistoryStorageAddress: GenesisAccount{
Balance: big.NewInt(0),
Nonce: 1,
},
},
}
)
Expand Down Expand Up @@ -1053,6 +1077,10 @@ func TestProcessVerkleBalanceOpcode(t *testing.T) {
Balance: big.NewInt(1000000000000000000), // 1 ether
Nonce: 3,
},
params.HistoryStorageAddress: GenesisAccount{
Balance: big.NewInt(0),
Nonce: 1,
},
},
}
)
Expand Down Expand Up @@ -1148,6 +1176,10 @@ func TestProcessVerkleSelfDestructInSeparateTx(t *testing.T) {
Balance: big.NewInt(1000000000000000000), // 1 ether
Nonce: 3,
},
params.HistoryStorageAddress: GenesisAccount{
Balance: big.NewInt(0),
Nonce: 1,
},
},
}
)
Expand Down Expand Up @@ -1295,6 +1327,10 @@ func TestProcessVerkleSelfDestructInSameTx(t *testing.T) {
Balance: big.NewInt(1000000000000000000), // 1 ether
Nonce: 3,
},
params.HistoryStorageAddress: GenesisAccount{
Balance: big.NewInt(0),
Nonce: 1,
},
},
}
)
Expand Down Expand Up @@ -1419,6 +1455,10 @@ func TestProcessVerkleSelfDestructInSeparateTxWithSelfBeneficiary(t *testing.T)
Balance: big.NewInt(1000000000000000000), // 1 ether
Nonce: 3,
},
params.HistoryStorageAddress: GenesisAccount{
Balance: big.NewInt(0),
Nonce: 1,
},
},
}
)
Expand Down Expand Up @@ -1540,6 +1580,10 @@ func TestProcessVerkleSelfDestructInSameTxWithSelfBeneficiary(t *testing.T) {
Balance: big.NewInt(1000000000000000000), // 1 ether
Nonce: 3,
},
params.HistoryStorageAddress: GenesisAccount{
Balance: big.NewInt(0),
Nonce: 1,
},
},
}
)
Expand Down
Loading