From 5c3e0d6437e276b25fedd675deedc20a2934e740 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Fri, 8 May 2020 16:41:11 -0500 Subject: [PATCH] complete tests for early mainnet blocks --- statediff/builder_test.go | 174 ++++--- statediff/test_data/builder_test.go | 630 +++++++++++++++++++++--- statediff/testhelpers/mocks/api_test.go | 76 ++- statediff/testhelpers/test_data.go | 10 +- 4 files changed, 709 insertions(+), 181 deletions(-) diff --git a/statediff/builder_test.go b/statediff/builder_test.go index 082300055..abe34828f 100644 --- a/statediff/builder_test.go +++ b/statediff/builder_test.go @@ -34,7 +34,8 @@ import ( // TODO: add test that filters on address var ( contractLeafKey []byte - emptyAccountMap = make([]statediff.AccountDiff, 0) + emptyAccounts = make([]statediff.AccountDiff, 0) + emptyStorage = make([]statediff.StorageDiff, 0) block0, block1, block2, block3 *types.Block builder statediff.Builder miningReward = int64(2000000000000000000) @@ -46,11 +47,6 @@ var ( block1BankBalance = int64(99990000) block1Account1Balance = int64(10000) block2Account2Balance = int64(1000) - nonce0 = uint64(0) - nonce1 = uint64(1) - nonce2 = uint64(2) - nonce3 = uint64(3) - originalContractRoot = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" contractContractRoot = "0x821e2556a290c86405f8160a2d662042a431ba456b9db265c79bb837c04be5f0" newContractRoot = "0x71e0d14b2b93e5c7f9748e69e1fe5f17498a1c3ac3cec29f96af13d7f8a4e070" originalStorageLocation = common.HexToHash("0") @@ -72,57 +68,57 @@ var ( newStorageValue, }) bankAccountAtBlock0, _ = rlp.EncodeToBytes(state.Account{ - Nonce: nonce0, + Nonce: testhelpers.Nonce0, Balance: big.NewInt(testhelpers.TestBankFunds.Int64()), - CodeHash: common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes(), - Root: common.HexToHash(originalContractRoot), + CodeHash: testhelpers.NullCodeHash.Bytes(), + Root: testhelpers.EmptyContractRoot, }) bankAccountAtBlock0LeafNode, _ = rlp.EncodeToBytes([]interface{}{ common.Hex2Bytes("2000bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"), bankAccountAtBlock0, }) account1AtBlock1, _ = rlp.EncodeToBytes(state.Account{ - Nonce: nonce0, + Nonce: testhelpers.Nonce0, Balance: big.NewInt(balanceChange10000), - CodeHash: common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes(), - Root: common.HexToHash(originalContractRoot), + CodeHash: testhelpers.NullCodeHash.Bytes(), + Root: testhelpers.EmptyContractRoot, }) account1AtBlock1LeafNode, _ = rlp.EncodeToBytes([]interface{}{ common.Hex2Bytes("3926db69aaced518e9b9f0f434a473e7174109c943548bb8f23be41ca76d9ad2"), account1AtBlock1, }) minerAccountAtBlock1, _ = rlp.EncodeToBytes(state.Account{ - Nonce: nonce0, + Nonce: testhelpers.Nonce0, Balance: big.NewInt(miningReward), - CodeHash: common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes(), - Root: common.HexToHash(originalContractRoot), + CodeHash: testhelpers.NullCodeHash.Bytes(), + Root: testhelpers.EmptyContractRoot, }) minerAccountAtBlock1LeafNode, _ = rlp.EncodeToBytes([]interface{}{ common.Hex2Bytes("3380c7b7ae81a58eb98d9c78de4a1fd7fd9535fc953ed2be602daaa41767312a"), minerAccountAtBlock1, }) bankAccountAtBlock1, _ = rlp.EncodeToBytes(state.Account{ - Nonce: nonce1, + Nonce: testhelpers.Nonce1, Balance: big.NewInt(testhelpers.TestBankFunds.Int64() - balanceChange10000), - CodeHash: common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes(), - Root: common.HexToHash(originalContractRoot), + CodeHash: testhelpers.NullCodeHash.Bytes(), + Root: testhelpers.EmptyContractRoot, }) bankAccountAtBlock1LeafNode, _ = rlp.EncodeToBytes([]interface{}{ common.Hex2Bytes("30bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"), bankAccountAtBlock1, }) account2AtBlock2, _ = rlp.EncodeToBytes(state.Account{ - Nonce: nonce0, + Nonce: testhelpers.Nonce0, Balance: big.NewInt(balanceChange1000), - CodeHash: common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes(), - Root: common.HexToHash(originalContractRoot), + CodeHash: testhelpers.NullCodeHash.Bytes(), + Root: testhelpers.EmptyContractRoot, }) account2AtBlock2LeafNode, _ = rlp.EncodeToBytes([]interface{}{ common.Hex2Bytes("3957f3e2f04a0764c3a0491b175f69926da61efbcc8f61fa1455fd2d2b4cdd45"), account2AtBlock2, }) contractAccountAtBlock2, _ = rlp.EncodeToBytes(state.Account{ - Nonce: nonce1, + Nonce: testhelpers.Nonce1, Balance: big.NewInt(0), CodeHash: common.HexToHash("0x753f98a8d4328b15636e46f66f2cb4bc860100aa17967cc145fcd17d1d4710ea").Bytes(), Root: common.HexToHash(contractContractRoot), @@ -132,47 +128,47 @@ var ( contractAccountAtBlock2, }) bankAccountAtBlock2, _ = rlp.EncodeToBytes(state.Account{ - Nonce: nonce2, + Nonce: testhelpers.Nonce2, Balance: big.NewInt(block1BankBalance - balanceChange1000), - CodeHash: common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes(), - Root: common.HexToHash(originalContractRoot), + CodeHash: testhelpers.NullCodeHash.Bytes(), + Root: testhelpers.EmptyContractRoot, }) bankAccountAtBlock2LeafNode, _ = rlp.EncodeToBytes([]interface{}{ common.Hex2Bytes("30bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"), bankAccountAtBlock2, }) account1AtBlock2, _ = rlp.EncodeToBytes(state.Account{ - Nonce: nonce2, + Nonce: testhelpers.Nonce2, Balance: big.NewInt(block1Account1Balance - balanceChange1000 + balanceChange1000), - CodeHash: common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes(), - Root: common.HexToHash(originalContractRoot), + CodeHash: testhelpers.NullCodeHash.Bytes(), + Root: testhelpers.EmptyContractRoot, }) account1AtBlock2LeafNode, _ = rlp.EncodeToBytes([]interface{}{ common.Hex2Bytes("3926db69aaced518e9b9f0f434a473e7174109c943548bb8f23be41ca76d9ad2"), account1AtBlock2, }) minerAccountAtBlock2, _ = rlp.EncodeToBytes(state.Account{ - Nonce: nonce0, + Nonce: testhelpers.Nonce0, Balance: big.NewInt(miningReward + miningReward), - CodeHash: common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes(), - Root: common.HexToHash(originalContractRoot), + CodeHash: testhelpers.NullCodeHash.Bytes(), + Root: testhelpers.EmptyContractRoot, }) minerAccountAtBlock2LeafNode, _ = rlp.EncodeToBytes([]interface{}{ common.Hex2Bytes("3380c7b7ae81a58eb98d9c78de4a1fd7fd9535fc953ed2be602daaa41767312a"), minerAccountAtBlock2, }) account2AtBlock3, _ = rlp.EncodeToBytes(state.Account{ - Nonce: nonce0, + Nonce: testhelpers.Nonce0, Balance: big.NewInt(block2Account2Balance + miningReward), - CodeHash: common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes(), - Root: common.HexToHash(originalContractRoot), + CodeHash: testhelpers.NullCodeHash.Bytes(), + Root: testhelpers.EmptyContractRoot, }) account2AtBlock3LeafNode, _ = rlp.EncodeToBytes([]interface{}{ common.Hex2Bytes("3957f3e2f04a0764c3a0491b175f69926da61efbcc8f61fa1455fd2d2b4cdd45"), account2AtBlock3, }) contractAccountAtBlock3, _ = rlp.EncodeToBytes(state.Account{ - Nonce: nonce1, + Nonce: testhelpers.Nonce1, Balance: big.NewInt(0), CodeHash: common.HexToHash("0x753f98a8d4328b15636e46f66f2cb4bc860100aa17967cc145fcd17d1d4710ea").Bytes(), Root: common.HexToHash(newContractRoot), @@ -182,10 +178,10 @@ var ( contractAccountAtBlock3, }) bankAccountAtBlock3, _ = rlp.EncodeToBytes(state.Account{ - Nonce: nonce3, + Nonce: testhelpers.Nonce3, Balance: big.NewInt(99989000), - CodeHash: common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes(), - Root: common.HexToHash(originalContractRoot), + CodeHash: testhelpers.NullCodeHash.Bytes(), + Root: testhelpers.EmptyContractRoot, }) bankAccountAtBlock3LeafNode, _ = rlp.EncodeToBytes([]interface{}{ common.Hex2Bytes("30bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"), @@ -306,9 +302,9 @@ func TestBuilder(t *testing.T) { &statediff.StateDiff{ BlockNumber: block0.Number(), BlockHash: block0.Hash(), - CreatedAccounts: emptyAccountMap, - DeletedAccounts: emptyAccountMap, - UpdatedAccounts: emptyAccountMap, + CreatedAccounts: emptyAccounts, + DeletedAccounts: emptyAccounts, + UpdatedAccounts: emptyAccounts, }, }, { @@ -329,11 +325,11 @@ func TestBuilder(t *testing.T) { NodeType: statediff.Leaf, LeafKey: testhelpers.BankLeafKey, NodeValue: bankAccountAtBlock0LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, }, - DeletedAccounts: emptyAccountMap, - UpdatedAccounts: emptyAccountMap, + DeletedAccounts: emptyAccounts, + UpdatedAccounts: emptyAccounts, }, }, { @@ -354,21 +350,21 @@ func TestBuilder(t *testing.T) { NodeType: statediff.Leaf, LeafKey: testhelpers.BankLeafKey, NodeValue: bankAccountAtBlock1LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, { Path: []byte{'\x05'}, NodeType: statediff.Leaf, LeafKey: minerLeafKey, NodeValue: minerAccountAtBlock1LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, { Path: []byte{'\x0e'}, NodeType: statediff.Leaf, LeafKey: testhelpers.Account1LeafKey, NodeValue: account1AtBlock1LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, }, DeletedAccounts: []statediff.AccountDiff{ // This leaf appears to be deleted since it is turned into a branch node @@ -377,10 +373,10 @@ func TestBuilder(t *testing.T) { NodeType: statediff.Leaf, LeafKey: testhelpers.BankLeafKey, NodeValue: bankAccountAtBlock0LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, }, - UpdatedAccounts: emptyAccountMap, + UpdatedAccounts: emptyAccounts, }, }, { @@ -417,31 +413,31 @@ func TestBuilder(t *testing.T) { NodeType: statediff.Leaf, LeafKey: testhelpers.Account2LeafKey, NodeValue: account2AtBlock2LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, }, - DeletedAccounts: emptyAccountMap, + DeletedAccounts: emptyAccounts, UpdatedAccounts: []statediff.AccountDiff{ { Path: []byte{'\x00'}, NodeType: statediff.Leaf, LeafKey: testhelpers.BankLeafKey, NodeValue: bankAccountAtBlock2LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, { Path: []byte{'\x05'}, NodeType: statediff.Leaf, LeafKey: minerLeafKey, NodeValue: minerAccountAtBlock2LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, { Path: []byte{'\x0e'}, NodeType: statediff.Leaf, LeafKey: testhelpers.Account1LeafKey, NodeValue: account1AtBlock2LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, }, }, @@ -460,14 +456,14 @@ func TestBuilder(t *testing.T) { BlockNumber: block3.Number(), BlockHash: block3.Hash(), CreatedAccounts: []statediff.AccountDiff{}, - DeletedAccounts: emptyAccountMap, + DeletedAccounts: emptyAccounts, UpdatedAccounts: []statediff.AccountDiff{ { Path: []byte{'\x00'}, NodeType: statediff.Leaf, LeafKey: testhelpers.BankLeafKey, NodeValue: bankAccountAtBlock3LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, { Path: []byte{'\x06'}, @@ -494,7 +490,7 @@ func TestBuilder(t *testing.T) { NodeType: statediff.Leaf, LeafKey: testhelpers.Account2LeafKey, NodeValue: account2AtBlock3LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, }, }, @@ -553,9 +549,9 @@ func TestBuilderWithIntermediateNodes(t *testing.T) { &statediff.StateDiff{ BlockNumber: block0.Number(), BlockHash: block0.Hash(), - CreatedAccounts: emptyAccountMap, - DeletedAccounts: emptyAccountMap, - UpdatedAccounts: emptyAccountMap, + CreatedAccounts: emptyAccounts, + DeletedAccounts: emptyAccounts, + UpdatedAccounts: emptyAccounts, }, }, { @@ -576,11 +572,11 @@ func TestBuilderWithIntermediateNodes(t *testing.T) { NodeType: statediff.Leaf, LeafKey: testhelpers.BankLeafKey, NodeValue: bankAccountAtBlock0LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, }, - DeletedAccounts: emptyAccountMap, - UpdatedAccounts: emptyAccountMap, + DeletedAccounts: emptyAccounts, + UpdatedAccounts: emptyAccounts, }, }, { @@ -601,30 +597,30 @@ func TestBuilderWithIntermediateNodes(t *testing.T) { NodeType: statediff.Leaf, LeafKey: testhelpers.BankLeafKey, NodeValue: bankAccountAtBlock1LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, { Path: []byte{'\x05'}, NodeType: statediff.Leaf, LeafKey: minerLeafKey, NodeValue: minerAccountAtBlock1LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, { Path: []byte{'\x0e'}, NodeType: statediff.Leaf, LeafKey: testhelpers.Account1LeafKey, NodeValue: account1AtBlock1LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, }, - DeletedAccounts: emptyAccountMap, + DeletedAccounts: emptyAccounts, UpdatedAccounts: []statediff.AccountDiff{ { Path: []byte{}, NodeType: statediff.Branch, NodeValue: block1BranchNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, }, }, @@ -663,37 +659,37 @@ func TestBuilderWithIntermediateNodes(t *testing.T) { NodeType: statediff.Leaf, LeafKey: testhelpers.Account2LeafKey, NodeValue: account2AtBlock2LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, }, - DeletedAccounts: emptyAccountMap, + DeletedAccounts: emptyAccounts, UpdatedAccounts: []statediff.AccountDiff{ { Path: []byte{}, NodeType: statediff.Branch, NodeValue: block2BranchNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, { Path: []byte{'\x00'}, NodeType: statediff.Leaf, LeafKey: testhelpers.BankLeafKey, NodeValue: bankAccountAtBlock2LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, { Path: []byte{'\x05'}, NodeType: statediff.Leaf, LeafKey: minerLeafKey, NodeValue: minerAccountAtBlock2LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, { Path: []byte{'\x0e'}, NodeType: statediff.Leaf, LeafKey: testhelpers.Account1LeafKey, NodeValue: account1AtBlock2LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, }, }, @@ -712,20 +708,20 @@ func TestBuilderWithIntermediateNodes(t *testing.T) { BlockNumber: block3.Number(), BlockHash: block3.Hash(), CreatedAccounts: []statediff.AccountDiff{}, - DeletedAccounts: emptyAccountMap, + DeletedAccounts: emptyAccounts, UpdatedAccounts: []statediff.AccountDiff{ { Path: []byte{}, NodeType: statediff.Branch, NodeValue: block3BranchNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, { Path: []byte{'\x00'}, NodeType: statediff.Leaf, LeafKey: testhelpers.BankLeafKey, NodeValue: bankAccountAtBlock3LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, { Path: []byte{'\x06'}, @@ -757,7 +753,7 @@ func TestBuilderWithIntermediateNodes(t *testing.T) { NodeType: statediff.Leaf, LeafKey: testhelpers.Account2LeafKey, NodeValue: account2AtBlock3LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, }, }, @@ -817,9 +813,9 @@ func TestBuilderWithWatchedAddressList(t *testing.T) { &statediff.StateDiff{ BlockNumber: block0.Number(), BlockHash: block0.Hash(), - CreatedAccounts: emptyAccountMap, - DeletedAccounts: emptyAccountMap, - UpdatedAccounts: emptyAccountMap, + CreatedAccounts: emptyAccounts, + DeletedAccounts: emptyAccounts, + UpdatedAccounts: emptyAccounts, }, }, { @@ -834,9 +830,9 @@ func TestBuilderWithWatchedAddressList(t *testing.T) { &statediff.StateDiff{ BlockNumber: block0.Number(), BlockHash: block0.Hash(), - CreatedAccounts: emptyAccountMap, - DeletedAccounts: emptyAccountMap, - UpdatedAccounts: emptyAccountMap, + CreatedAccounts: emptyAccounts, + DeletedAccounts: emptyAccounts, + UpdatedAccounts: emptyAccounts, }, }, { @@ -857,10 +853,10 @@ func TestBuilderWithWatchedAddressList(t *testing.T) { NodeType: statediff.Leaf, LeafKey: testhelpers.Account1LeafKey, NodeValue: account1AtBlock1LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, }, - DeletedAccounts: emptyAccountMap, + DeletedAccounts: emptyAccounts, UpdatedAccounts: []statediff.AccountDiff{}, }, }, @@ -893,14 +889,14 @@ func TestBuilderWithWatchedAddressList(t *testing.T) { }, }, }, - DeletedAccounts: emptyAccountMap, + DeletedAccounts: emptyAccounts, UpdatedAccounts: []statediff.AccountDiff{ { Path: []byte{'\x0e'}, NodeType: statediff.Leaf, LeafKey: testhelpers.Account1LeafKey, NodeValue: account1AtBlock2LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, }, }, @@ -919,7 +915,7 @@ func TestBuilderWithWatchedAddressList(t *testing.T) { BlockNumber: block3.Number(), BlockHash: block3.Hash(), CreatedAccounts: []statediff.AccountDiff{}, - DeletedAccounts: emptyAccountMap, + DeletedAccounts: emptyAccounts, UpdatedAccounts: []statediff.AccountDiff{ { Path: []byte{'\x06'}, diff --git a/statediff/test_data/builder_test.go b/statediff/test_data/builder_test.go index 0d664c6e4..7143b4df7 100644 --- a/statediff/test_data/builder_test.go +++ b/statediff/test_data/builder_test.go @@ -19,27 +19,399 @@ package statediff_test import ( "bytes" "io/ioutil" + "log" "math/big" "os" "sort" "testing" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/rawdb" - "github.com/ethereum/go-ethereum/core/vm" - "github.com/ethereum/go-ethereum/params" - - "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/core/vm" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/statediff" "github.com/ethereum/go-ethereum/statediff/testhelpers" ) var ( - builder statediff.Builder - emptyAccountMap = make([]statediff.AccountDiff, 0) + err error + db ethdb.Database + genesisBlock, block0, block1, block2, block3 *types.Block + block1CoinbaseAddr, block2CoinbaseAddr, block3CoinbaseAddr common.Address + block1CoinbaseHash, block2CoinbaseHash, block3CoinbaseHash common.Hash + builder statediff.Builder + emptyAccounts = make([]statediff.AccountDiff, 0) + emptyStorage = make([]statediff.StorageDiff, 0) + + // block 1 data + block1CoinbaseAccount, _ = rlp.EncodeToBytes(state.Account{ + Nonce: testhelpers.Nonce0, + Balance: big.NewInt(5000000000000000000), + CodeHash: testhelpers.NullCodeHash.Bytes(), + Root: testhelpers.EmptyContractRoot, + }) + block1CoinbaseLeafNode, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("38251692195afc818c92b485fcb8a4691af89cbe5a2ab557b83a4261be2a9a"), + block1CoinbaseAccount, + }) + block1CoinbaseLeafNodeHash = crypto.Keccak256(block1CoinbaseLeafNode) + block1x040bBranchNode, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("cc947d5ebb80600bad471f12c6ad5e4981e3525ecf8a2d982cc032536ae8b66d"), + common.Hex2Bytes("e80e52462e635a834e90e86ccf7673a6430384aac17004d626f4db831f0624bc"), + common.Hex2Bytes("59a8f11f60cb0a8488831f242da02944a26fd269d0608a44b8b873ded9e59e1b"), + common.Hex2Bytes("1ffb51e987e3cbd2e1dc1a64508d2e2b265477e21698b0d10fdf137f35027f40"), + []byte{}, + common.Hex2Bytes("ce5077f49a13ff8199d0e77715fdd7bfd6364774effcd5499bd93cba54b3c644"), + common.Hex2Bytes("f5146783c048e66ce1a776ae990b4255e5fba458ece77fcb83ff6e91d6637a88"), + common.Hex2Bytes("6a0558b6c38852e985cf01c2156517c1c6a1e64c787a953c347825f050b236c6"), + common.Hex2Bytes("56b6e93958b99aaae158cc2329e71a1865ba6f39c67b096922c5cf3ed86b0ae5"), + []byte{}, + common.Hex2Bytes("50d317a89a3405367d66668902f2c9f273a8d0d7d5d790dc516bca142f4a84af"), + common.Hex2Bytes("c72ca72750fdc1af3e6da5c7c5d82c54e4582f15b488a8aa1674058a99825dae"), + common.Hex2Bytes("e1a489df7b18cde818da6d38e235b026c2e61bcd3d34880b3ed0d67e0e4f0159"), + common.Hex2Bytes("b58d5062f2609fd2d68f00d14ab33fef2b373853877cf40bf64729e85b8fdc54"), + block1CoinbaseLeafNodeHash, + []byte{}, + []byte{}, + }) + block1x040bBranchNodeHash = crypto.Keccak256(block1x040bBranchNode) + block1x04BranchNode, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("a9317a59365ca09cefcd384018696590afffc432e35a97e8f85aa48907bf3247"), + common.Hex2Bytes("e0bc229254ce7a6a736c3953e570ab18b4a7f5f2a9aa3c3057b5f17d250a1cad"), + common.Hex2Bytes("a2484ec8884dbe0cf24ece99d67df0d1fe78992d67cc777636a817cb2ef205aa"), + common.Hex2Bytes("12b78d4078c607747f06bb88bd08f839eaae0e3ac6854e5f65867d4f78abb84e"), + common.Hex2Bytes("359a51862df5462e4cd302f69cb338512f21eb37ce0791b9a562e72ec48b7dbf"), + common.Hex2Bytes("13f8d617b6a734da9235b6ac80bdd7aeaff6120c39aa223638d88f22d4ba4007"), + common.Hex2Bytes("02055c6400e0ec3440a8bb8fdfd7d6b6c57b7bf83e37d7e4e983d416fdd8314e"), + common.Hex2Bytes("4b1cca9eb3e47e805e7f4c80671a9fcd589fd6ddbe1790c3f3e177e8ede01b9e"), + common.Hex2Bytes("70c3815efb23b986018089e009a38e6238b8850b3efd33831913ca6fa9240249"), + common.Hex2Bytes("7084699d2e72a193fd75bb6108ae797b4661696eba2d631d521fc94acc7b3247"), + common.Hex2Bytes("b2b3cd9f1e46eb583a6185d9a96b4e80125e3d75e6191fdcf684892ef52935cb"), + block1x040bBranchNodeHash, + common.Hex2Bytes("34d9ff0fee6c929424e52268dedbc596d10786e909c5a68d6466c2aba17387ce"), + common.Hex2Bytes("7484d5e44b6ee6b10000708c37e035b42b818475620f9316beffc46531d1eebf"), + common.Hex2Bytes("30c8a283adccf2742272563cd3d6710c89ba21eac0118bf5310cfb231bcca77f"), + common.Hex2Bytes("4bae8558d2385b8d3bc6e6ede20bdbc5dbb0b5384c316ba8985682f88d2e506d"), + []byte{}, + }) + block1x04BranchNodeHash = crypto.Keccak256(block1x04BranchNode) + block1RootBranchNode, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("90dcaf88c40c7bbc95a912cbdde67c175767b31173df9ee4b0d733bfdd511c43"), + common.Hex2Bytes("babe369f6b12092f49181ae04ca173fb68d1a5456f18d20fa32cba73954052bd"), + common.Hex2Bytes("473ecf8a7e36a829e75039a3b055e51b8332cbf03324ab4af2066bbd6fbf0021"), + common.Hex2Bytes("bbda34753d7aa6c38e603f360244e8f59611921d9e1f128372fec0d586d4f9e0"), + block1x04BranchNodeHash, + common.Hex2Bytes("a5f3f2f7542148c973977c8a1e154c4300fec92f755f7846f1b734d3ab1d90e7"), + common.Hex2Bytes("e823850f50bf72baae9d1733a36a444ab65d0a6faaba404f0583ce0ca4dad92d"), + common.Hex2Bytes("f7a00cbe7d4b30b11faea3ae61b7f1f2b315b61d9f6bd68bfe587ad0eeceb721"), + common.Hex2Bytes("7117ef9fc932f1a88e908eaead8565c19b5645dc9e5b1b6e841c5edbdfd71681"), + common.Hex2Bytes("69eb2de283f32c11f859d7bcf93da23990d3e662935ed4d6b39ce3673ec84472"), + common.Hex2Bytes("203d26456312bbc4da5cd293b75b840fc5045e493d6f904d180823ec22bfed8e"), + common.Hex2Bytes("9287b5c21f2254af4e64fca76acc5cd87399c7f1ede818db4326c98ce2dc2208"), + common.Hex2Bytes("6fc2d754e304c48ce6a517753c62b1a9c1d5925b89707486d7fc08919e0a94ec"), + common.Hex2Bytes("7b1c54f15e299bd58bdfef9741538c7828b5d7d11a489f9c20d052b3471df475"), + common.Hex2Bytes("51f9dd3739a927c89e357580a4c97b40234aa01ed3d5e0390dc982a7975880a0"), + common.Hex2Bytes("89d613f26159af43616fd9455bb461f4869bfede26f2130835ed067a8b967bfb"), + []byte{}, + }) + + // block 2 data + block2CoinbaseAccount, _ = rlp.EncodeToBytes(state.Account{ + Nonce: testhelpers.Nonce0, + Balance: big.NewInt(5000000000000000000), + CodeHash: testhelpers.NullCodeHash.Bytes(), + Root: testhelpers.EmptyContractRoot, + }) + block2CoinbaseLeafNode, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("20679cbcf198c1741a6f4e4473845659a30caa8b26f8d37a0be2e2bc0d8892"), + block2CoinbaseAccount, + }) + block2CoinbaseLeafNodeHash = crypto.Keccak256(block2CoinbaseLeafNode) + block2MovedPremineBalance, _ = new(big.Int).SetString("4000000000000000000000", 10) + block2MovedPremineAccount, _ = rlp.EncodeToBytes(state.Account{ + Nonce: testhelpers.Nonce0, + Balance: block2MovedPremineBalance, + CodeHash: testhelpers.NullCodeHash.Bytes(), + Root: testhelpers.EmptyContractRoot, + }) + block2MovedPremineLeafNode, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("20f2e24db7943eab4415f99e109698863b0fecca1cf9ffc500f38cefbbe29e"), + block2MovedPremineAccount, + }) + block2MovedPremineLeafNodeHash = crypto.Keccak256(block2MovedPremineLeafNode) + block2x00080dBranchNode, _ = rlp.EncodeToBytes([]interface{}{ + block2MovedPremineLeafNodeHash, + []byte{}, + []byte{}, + []byte{}, + block2CoinbaseLeafNodeHash, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + }) + block2x00080dBranchNodeHash = crypto.Keccak256(block2x00080dBranchNode) + block2x0008BranchNode, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("def97a26f824fc3911cf7f8c41dfc9bc93cc36ae2248de22ecae01d6950b2dc9"), + common.Hex2Bytes("234a575e2c5badab8de0f6515b6723195323a0562fbe1316255888637043f1c1"), + common.Hex2Bytes("29659740af1c23306ee8f8294c71a5632ace8c80b1eb61cfdf7022f47ff52305"), + common.Hex2Bytes("cf2681d23bb666d89dec8123bce9e626240a7e2ce7a1e8316b1ee88181c9471c"), + common.Hex2Bytes("18d8de6967fe34b9fd411c74fecc45f8a737961791e70d8ece967bb07cf4d4dc"), + common.Hex2Bytes("7cad60c7cbca8c79c2db5a8fc1baa9381484d43d6c37dfb97718c3a109d47dfc"), + common.Hex2Bytes("2138f5a9062b750b6320e5fac5b134da90a9edbda06ef3e1ae64fb1366ca998c"), + common.Hex2Bytes("532826502a9661fcae7c0f5d2a4c8cb287dfc521e828349543c5a461a9d591ed"), + common.Hex2Bytes("30543537413dd086d4b1560f46b90e8da0f43de5584a138ab036d74e84657523"), + common.Hex2Bytes("c98042928af640bfa1142aca895cd76e146332dce94ddad3426e74ed519ca1e0"), + common.Hex2Bytes("43de3e62cc3148193899d018dff813c04c5b636ce95bd7e828416204292d9ff9"), + []byte{}, + common.Hex2Bytes("78d533b9182bb42f6c16e9ebd5734f0d280179ba1c9b6316c2c1df73f7dd8a54"), + block2x00080dBranchNodeHash, + common.Hex2Bytes("934b736b57a892aaa15a03c7e37746bb096313727135f9841cb64c263785cf81"), + common.Hex2Bytes("38ce97150e90dfd7258901a0ddee72d8e30760a3d0419dbb80135c66588739a2"), + []byte{}, + }) + block2x0008BranchNodeHash = crypto.Keccak256(block2x0008BranchNode) + block2x00BranchNode, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("e45a9e85cab1b6eb18b30df2c6acc448bbac6a30d81646823b31223e16e5063e"), + common.Hex2Bytes("33bd7171d556b981f6849064eb09412b24fedc0812127db936067043f53db1b9"), + common.Hex2Bytes("ca56945f074da4f15587404593faf3a50d17ea0e21a418ad6ec99bdf4bf3f914"), + common.Hex2Bytes("da23e9004f782df128eea1adff77952dc85f91b7f7ca4893aac5f21d24c3a1c9"), + common.Hex2Bytes("ba5ec61fa780ee02af19db99677c37560fc4f0df5c278d9dfa2837f30f72bc6b"), + common.Hex2Bytes("8310ad91625c2e3429a74066b7e2e0c958325e4e7fa3ec486b73b7c8300cfef7"), + common.Hex2Bytes("732e5c103bf4d5adfef83773026809d9405539b67e93293a02342e83ad2fb766"), + common.Hex2Bytes("30d14ff0c2aab57d1fbaf498ab14519b4e9d94f149a3dc15f0eec5adf8df25e1"), + block2x0008BranchNodeHash, + common.Hex2Bytes("5a43bd92e55aa78df60e70b6b53b6366c4080fd6a5bdd7b533b46aff4a75f6f2"), + common.Hex2Bytes("a0c410aa59efe416b1213166fab680ce330bd46c3ebf877ff14609ee6a383600"), + common.Hex2Bytes("2f41e918786e557293068b1eda9b3f9f86ed4e65a6a5363ee3262109f6e08b17"), + common.Hex2Bytes("01f42a40f02f6f24bb97b09c4d3934e8b03be7cfbb902acc1c8fd67a7a5abace"), + common.Hex2Bytes("0acbdce2787a6ea177209bd13bfc9d0779d7e2b5249e0211a2974164e14312f5"), + common.Hex2Bytes("dadbe113e4132e0c0c3cd4867e0a2044d0e5a3d44b350677ed42fc9244d004d4"), + common.Hex2Bytes("aa7441fefc17d76aedfcaf692fe71014b94c1547b6d129562b34fc5995ca0d1a"), + []byte{}, + }) + block2x00BranchNodeHash = crypto.Keccak256(block2x00BranchNode) + block2RootBranchNode, _ = rlp.EncodeToBytes([]interface{}{ + block2x00BranchNodeHash, + common.Hex2Bytes("babe369f6b12092f49181ae04ca173fb68d1a5456f18d20fa32cba73954052bd"), + common.Hex2Bytes("473ecf8a7e36a829e75039a3b055e51b8332cbf03324ab4af2066bbd6fbf0021"), + common.Hex2Bytes("bbda34753d7aa6c38e603f360244e8f59611921d9e1f128372fec0d586d4f9e0"), + block1x04BranchNodeHash, + common.Hex2Bytes("a5f3f2f7542148c973977c8a1e154c4300fec92f755f7846f1b734d3ab1d90e7"), + common.Hex2Bytes("e823850f50bf72baae9d1733a36a444ab65d0a6faaba404f0583ce0ca4dad92d"), + common.Hex2Bytes("f7a00cbe7d4b30b11faea3ae61b7f1f2b315b61d9f6bd68bfe587ad0eeceb721"), + common.Hex2Bytes("7117ef9fc932f1a88e908eaead8565c19b5645dc9e5b1b6e841c5edbdfd71681"), + common.Hex2Bytes("69eb2de283f32c11f859d7bcf93da23990d3e662935ed4d6b39ce3673ec84472"), + common.Hex2Bytes("203d26456312bbc4da5cd293b75b840fc5045e493d6f904d180823ec22bfed8e"), + common.Hex2Bytes("9287b5c21f2254af4e64fca76acc5cd87399c7f1ede818db4326c98ce2dc2208"), + common.Hex2Bytes("6fc2d754e304c48ce6a517753c62b1a9c1d5925b89707486d7fc08919e0a94ec"), + common.Hex2Bytes("7b1c54f15e299bd58bdfef9741538c7828b5d7d11a489f9c20d052b3471df475"), + common.Hex2Bytes("51f9dd3739a927c89e357580a4c97b40234aa01ed3d5e0390dc982a7975880a0"), + common.Hex2Bytes("89d613f26159af43616fd9455bb461f4869bfede26f2130835ed067a8b967bfb"), + []byte{}, + }) + + // block3 data + // path 060e0f + blcok3CoinbaseBalance, _ = new(big.Int).SetString("5156250000000000000", 10) + block3CoinbaseAccount, _ = rlp.EncodeToBytes(state.Account{ + Nonce: testhelpers.Nonce0, + Balance: blcok3CoinbaseBalance, + CodeHash: testhelpers.NullCodeHash.Bytes(), + Root: testhelpers.EmptyContractRoot, + }) + block3CoinbaseLeafNode, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("3a174f00e64521a535f35e67c1aa241951c791639b2f3d060f49c5d9fa8b9e"), + block3CoinbaseAccount, + }) + block3CoinbaseLeafNodeHash = crypto.Keccak256(block3CoinbaseLeafNode) + // path 0c0e050703 + block3MovedPremineBalance1, _ = new(big.Int).SetString("3750000000000000000", 10) + block3MovedPremineAccount1, _ = rlp.EncodeToBytes(state.Account{ + Nonce: testhelpers.Nonce0, + Balance: block3MovedPremineBalance1, + CodeHash: testhelpers.NullCodeHash.Bytes(), + Root: testhelpers.EmptyContractRoot, + }) + block3MovedPremineLeafNode1, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("3ced93917e658d10e2d9009470dad72b63c898d173721194a12f2ae5e190"), // ce573ced93917e658d10e2d9009470dad72b63c898d173721194a12f2ae5e190 + block3MovedPremineAccount1, + }) + block3MovedPremineLeafNodeHash1 = crypto.Keccak256(block3MovedPremineLeafNode1) + // path 0c0e050708 + block3MovedPremineBalance2, _ = new(big.Int).SetString("1999944000000000000000", 10) + block3MovedPremineAccount2, _ = rlp.EncodeToBytes(state.Account{ + Nonce: testhelpers.Nonce0, + Balance: block3MovedPremineBalance2, + CodeHash: testhelpers.NullCodeHash.Bytes(), + Root: testhelpers.EmptyContractRoot, + }) + block3MovedPremineLeafNode2, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("33bc1e69eedf90f402e11f6862da14ed8e50156635a04d6393bbae154012"), // ce5783bc1e69eedf90f402e11f6862da14ed8e50156635a04d6393bbae154012 + block3MovedPremineAccount2, + }) + block3MovedPremineLeafNodeHash2 = crypto.Keccak256(block3MovedPremineLeafNode2) + + block3x0c0e0507BranchNode, _ = rlp.EncodeToBytes([]interface{}{ + []byte{}, + []byte{}, + []byte{}, + block3MovedPremineLeafNodeHash1, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + block3MovedPremineLeafNodeHash2, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + }) + block3x0c0e0507BranchNodeHash = crypto.Keccak256(block3x0c0e0507BranchNode) + + block3x0c0e05BranchNode, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("452e3beb503b1d87ae7c672b98a8e3fd043a671405502562ae1043dc97151a50"), + []byte{}, + common.Hex2Bytes("2f5bb16f77086f67ce8c4258cb9061cb299e597b2ad4ad6d7ccc474d6d88e85e"), + []byte{}, + []byte{}, + []byte{}, + []byte{}, + block3x0c0e0507BranchNodeHash, + []byte{}, + common.Hex2Bytes("44623e5a9319f83870db0ea4611a25fca1e1da3eeea2be4a091dfc15ab45689e"), + common.Hex2Bytes("b41e047a97f44fa4cb8146467b88c8f4705811029d9e170abb0aba7d0af9f0da"), + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + []byte{}, + }) + block3x0c0e05BranchNodeHash = crypto.Keccak256(block3x0c0e05BranchNode) + + block3x060eBranchNode, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("94d77c7c30b88829c9989948b206cda5e532b38b49534261c517aebf4a3e6fdb"), + common.Hex2Bytes("a5cf57a50da8204964e834a12a53f9bed7afc9b700a4a81b440122d60c7603a7"), + []byte{}, + common.Hex2Bytes("3730ec0571f34b6c3b178dc26ccb31a3f50c29da9b1921e41b9477ddab41b0fe"), + []byte{}, + common.Hex2Bytes("543952bb9566c2018cf8d7b90d6a7903cdfff3d79ac36189be5322de42fc3fc0"), + []byte{}, + common.Hex2Bytes("c4a49b66f0bcc08531e50cdea5577a281d111fa542eaefd9a9aead8febb0735e"), + common.Hex2Bytes("362ad58916c71463b98c079649fc486c5f082c4f548bd4ab501515f0c5641cb4"), + common.Hex2Bytes("36aae109f6f55f0bd05eb05bb365af2332dfe5f06d3d17903e88534c319eb709"), + common.Hex2Bytes("430dcfc5cc49a6b490dd54138920e8f94e427239c2bccc14705cfd4ff6cc4383"), + common.Hex2Bytes("73ed77563dfed2fdb38900b474db88b2270f449167e0d877fda9e2229f119fe8"), + common.Hex2Bytes("5dfe06013f2a41f1779194ceb07769d019f518b2a694a82fa1661e60fd973eaa"), + common.Hex2Bytes("80bdfd85fbb6b45850bad6e34136aaa1b04711e47469fa2f0d19eca52089efb5"), + []byte{}, + block3CoinbaseLeafNodeHash, + []byte{}, + }) + block3x060eBranchNodeHash = crypto.Keccak256(block3x060eBranchNode) + + block3x0c0eBranchNode, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("70647f11b2b995d718f9e8aceb44c8839e0055641930d216fa6090280a9d63d5"), + common.Hex2Bytes("fdfb17cd2fba2a14219981cb7886a1977cd85dbef5c767c562f4a5f547febff0"), + common.Hex2Bytes("ff87313253ec6f860142b7bf62efb4cb07ea668c57aa90cbe9ef22b72fee15c7"), + common.Hex2Bytes("3a77b3c26a54ad37bdf4e19c1bce93493ec0f79d9ad90190b70bc840b54918e1"), + common.Hex2Bytes("af1b3b14324561b68f2e24dbcc28673ab35ce3fd0230fe2bc86b3d1931745195"), + block3x0c0e05BranchNodeHash, + common.Hex2Bytes("647dcbfe6aabcd9d219ff40422af4326bfc1ec66703195a78eb48618ddef248d"), + common.Hex2Bytes("2d2bf06159cc8928283c3419a03f08ea34c493a9d002a0ec76d5c429508ccaf4"), + common.Hex2Bytes("d7147251b3f48f25e1e4c6d8f83a00b1eca66e99a4ea0d238942ce72d0ba6414"), + common.Hex2Bytes("cb859370869967594fb29f4e2904413310146733d7fcbd11407f3e47626e0e34"), + common.Hex2Bytes("b93ab9b0bd83963860fbe0b7d543879cfde756ea1618d2a40d85483058cc5a26"), + common.Hex2Bytes("45aee096499d209931457ce251c5c7e5543f22524f67785ff8f0f3f02588b0ed"), + []byte{}, + common.Hex2Bytes("aa2ae9379797c5066bba646108074ae8677e82c923d584b6d1c1268ca3708c5c"), + common.Hex2Bytes("e6eb055f0d8e194c083471479a3de87fa0f90c0f4aaa518416ec1e469ec32e3a"), + common.Hex2Bytes("0cc9c50fc7eba162fb17f2e04e3599c13abbf210d9781864d0edec401ecaebba"), + []byte{}, + }) + block3x0c0eBranchNodeHash = crypto.Keccak256(block3x0c0eBranchNode) + + block3x06BranchNode, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("68f7ff8c074d6e4cccd55b5b1c2116a6dd7047d4332090e6db8839362991b0ae"), + common.Hex2Bytes("c446eb4377c750701374c56e50759e6ba68b7adf4d543e718c8b28a99ae3b6ad"), + common.Hex2Bytes("ef2c49ec64cb65eae0d99684e74c8af2bd0206c9a0214d9d3eddf0881dd8412a"), + common.Hex2Bytes("7096c4cc7e8125f0b142d8644ad681f8a8142e210c806f33f3f7004f0e9d6002"), + common.Hex2Bytes("bc9a8ae647b234cd6607b6b0245e3b3d5ec4f7ea006e7eda1f92d02f0ea91116"), + common.Hex2Bytes("a87720deb92ff2f899e809befab9970a61c86148c4fa09d04b77505ee4a5bda5"), + common.Hex2Bytes("2460e5b6ded7c0001de29c15db124614432fef6486370cc9970f63b0d95fd5e2"), + common.Hex2Bytes("ed1c447d4a32bc31e9e32259dc63da10df91231e786332e3df122b301b1f8fc3"), + common.Hex2Bytes("0d27dfc201d995c2323b792860dbca087da7cc56d1698c39b7c4b9277729c5ca"), + common.Hex2Bytes("f6d2be168d9c17643c9ea80c29322b364604cdfd36eef40123d83fad364e43fa"), + common.Hex2Bytes("004bf1c30a5730f464de1a0ba4ac5b5618df66d6106073d08742166e33a7eeb5"), + common.Hex2Bytes("7298d019a57a1b04ac31ed874d654ba0d3c249704c5d9efa1d08959fc89e0779"), + common.Hex2Bytes("fb3d50b7af6f839e371ff8ebd0322e94e6b6fb7888416737f88cf55bcf5859ec"), + common.Hex2Bytes("4e7a2618fa1fc560a73c24839657adf7e48d600ecfb12333678115936597a913"), + block3x060eBranchNodeHash, + common.Hex2Bytes("1909706c5db040f54c19f4050659ad484982145b02474653917de379f15ebb36"), + []byte{}, + }) + block3x06BranchNodeHash = crypto.Keccak256(block3x06BranchNode) + + block3x0cBranchNode, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("dae48f5b47930c28bb116fbd55e52cd47242c71bf55373b55eb2805ee2e4a929"), + common.Hex2Bytes("0f1f37f337ec800e2e5974e2e7355f10f1a4832b39b846d916c3597a460e0676"), + common.Hex2Bytes("da8f627bb8fbeead17b318e0a8e4f528db310f591bb6ab2deda4a9f7ca902ab5"), + common.Hex2Bytes("971c662648d58295d0d0aa4b8055588da0037619951217c22052802549d94a2f"), + common.Hex2Bytes("ccc701efe4b3413fd6a61a6c9f40e955af774649a8d9fd212d046a5a39ddbb67"), + common.Hex2Bytes("d607cdb32e2bd635ee7f2f9e07bc94ddbd09b10ec0901b66628e15667aec570b"), + common.Hex2Bytes("5b89203dc940e6fa70ec19ad4e01d01849d3a5baa0a8f9c0525256ed490b159f"), + common.Hex2Bytes("b84227d48df68aecc772939a59afa9e1a4ab578f7b698bdb1289e29b6044668e"), + common.Hex2Bytes("fd1c992070b94ace57e48cbf6511a16aa770c645f9f5efba87bbe59d0a042913"), + common.Hex2Bytes("e16a7ccea6748ae90de92f8aef3b3dc248a557b9ac4e296934313f24f7fced5f"), + common.Hex2Bytes("42373cf4a00630d94de90d0a23b8f38ced6b0f7cb818b8925fee8f0c2a28a25a"), + common.Hex2Bytes("5f89d2161c1741ff428864f7889866484cef622de5023a46e795dfdec336319f"), + common.Hex2Bytes("7597a017664526c8c795ce1da27b8b72455c49657113e0455552dbc068c5ba31"), + common.Hex2Bytes("d5be9089012fda2c585a1b961e988ea5efcd3a06988e150a8682091f694b37c5"), + block3x0c0eBranchNodeHash, + common.Hex2Bytes("49bf6e8df0acafd0eff86defeeb305568e44d52d2235cf340ae15c6034e2b241"), + []byte{}, + }) + block3x0cBranchNodeHash = crypto.Keccak256(block3x0cBranchNode) + + block3RootBranchNode, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("f646da473c426e79f1c796b00d4873f47de1dbe1c9d19d63993a05eeb8b4041d"), + common.Hex2Bytes("babe369f6b12092f49181ae04ca173fb68d1a5456f18d20fa32cba73954052bd"), + common.Hex2Bytes("473ecf8a7e36a829e75039a3b055e51b8332cbf03324ab4af2066bbd6fbf0021"), + common.Hex2Bytes("bbda34753d7aa6c38e603f360244e8f59611921d9e1f128372fec0d586d4f9e0"), + common.Hex2Bytes("d9cff5d5f2418afd16a4da5c221fdc8bd47520c5927922f69a68177b64da6ac0"), + common.Hex2Bytes("a5f3f2f7542148c973977c8a1e154c4300fec92f755f7846f1b734d3ab1d90e7"), + block3x06BranchNodeHash, + common.Hex2Bytes("f7a00cbe7d4b30b11faea3ae61b7f1f2b315b61d9f6bd68bfe587ad0eeceb721"), + common.Hex2Bytes("7117ef9fc932f1a88e908eaead8565c19b5645dc9e5b1b6e841c5edbdfd71681"), + common.Hex2Bytes("69eb2de283f32c11f859d7bcf93da23990d3e662935ed4d6b39ce3673ec84472"), + common.Hex2Bytes("203d26456312bbc4da5cd293b75b840fc5045e493d6f904d180823ec22bfed8e"), + common.Hex2Bytes("9287b5c21f2254af4e64fca76acc5cd87399c7f1ede818db4326c98ce2dc2208"), + block3x0cBranchNodeHash, + common.Hex2Bytes("7b1c54f15e299bd58bdfef9741538c7828b5d7d11a489f9c20d052b3471df475"), + common.Hex2Bytes("51f9dd3739a927c89e357580a4c97b40234aa01ed3d5e0390dc982a7975880a0"), + common.Hex2Bytes("89d613f26159af43616fd9455bb461f4869bfede26f2130835ed067a8b967bfb"), + []byte{}, + }) ) type arguments struct { @@ -49,6 +421,41 @@ type arguments struct { blockHash common.Hash } +func init() { + db = rawdb.NewMemoryDatabase() + genesisBlock = core.DefaultGenesisBlock().MustCommit(db) + genBy, err := rlp.EncodeToBytes(genesisBlock) + if err != nil { + log.Fatal(err) + } + var block0RLP []byte + block0, block0RLP, err = loadBlockFromRLPFile("./block0_rlp") + if err != nil { + log.Fatal(err) + } + if !bytes.Equal(genBy, block0RLP) { + log.Fatal("mainnet genesis blocks do not match") + } + block1, _, err = loadBlockFromRLPFile("./block1_rlp") + if err != nil { + log.Fatal(err) + } + block1CoinbaseAddr = block1.Coinbase() + block1CoinbaseHash = crypto.Keccak256Hash(block1CoinbaseAddr.Bytes()) + block2, _, err = loadBlockFromRLPFile("./block2_rlp") + if err != nil { + log.Fatal(err) + } + block2CoinbaseAddr = block2.Coinbase() + block2CoinbaseHash = crypto.Keccak256Hash(block2CoinbaseAddr.Bytes()) + block3, _, err = loadBlockFromRLPFile("./block3_rlp") + if err != nil { + log.Fatal(err) + } + block3CoinbaseAddr = block3.Coinbase() + block3CoinbaseHash = crypto.Keccak256Hash(block3CoinbaseAddr.Bytes()) +} + func loadBlockFromRLPFile(filename string) (*types.Block, []byte, error) { f, err := os.Open(filename) if err != nil { @@ -64,35 +471,8 @@ func loadBlockFromRLPFile(filename string) (*types.Block, []byte, error) { } func TestBuilderOnMainnetBlocks(t *testing.T) { - db := rawdb.NewMemoryDatabase() - gen := core.DefaultGenesisBlock().MustCommit(db) - genBy, err := rlp.EncodeToBytes(gen) - if err != nil { - t.Error(err) - } - block0, block0RLP, err := loadBlockFromRLPFile("./block0_rlp") - if err != nil { - t.Error(err) - } - if !bytes.Equal(genBy, block0RLP) { - t.Error("mainnet genesis blocks do not match") - } - - block1, _, err := loadBlockFromRLPFile("./block1_rlp") - if err != nil { - t.Error(err) - } - block2, _, err := loadBlockFromRLPFile("./block2_rlp") - if err != nil { - t.Error(err) - } - block3, _, err := loadBlockFromRLPFile("./block3_rlp") - if err != nil { - t.Error(err) - } - chain, _ := core.NewBlockChain(db, nil, params.MainnetChainConfig, ethash.NewFaker(), vm.Config{}, nil) - _, err = chain.InsertChain([]*types.Block{block1, block2, block3}) + _, err := chain.InsertChain([]*types.Block{block1, block2, block3}) if err != nil { t.Error(err) } @@ -106,23 +486,6 @@ func TestBuilderOnMainnetBlocks(t *testing.T) { startingArguments arguments expected *statediff.StateDiff }{ - { - "testBlock0", - //10000 transferred from testBankAddress to account1Addr - arguments{ - oldStateRoot: testhelpers.NullHash, - newStateRoot: block0.Root(), - blockNumber: block0.Number(), - blockHash: block0.Hash(), - }, - &statediff.StateDiff{ - BlockNumber: block0.Number(), - BlockHash: block0.Hash(), - CreatedAccounts: emptyAccountMap, - DeletedAccounts: emptyAccountMap, - UpdatedAccounts: emptyAccountMap, - }, - }, { "testBlock1", //10000 transferred from testBankAddress to account1Addr @@ -133,11 +496,38 @@ func TestBuilderOnMainnetBlocks(t *testing.T) { blockHash: block1.Hash(), }, &statediff.StateDiff{ - BlockNumber: block1.Number(), - BlockHash: block1.Hash(), - CreatedAccounts: emptyAccountMap, - DeletedAccounts: emptyAccountMap, - UpdatedAccounts: emptyAccountMap, + BlockNumber: block1.Number(), + BlockHash: block1.Hash(), + CreatedAccounts: []statediff.AccountDiff{ + { + Path: []byte{'\x04', '\x0b', '\x0e'}, + NodeType: statediff.Leaf, + LeafKey: block1CoinbaseHash.Bytes(), + NodeValue: block1CoinbaseLeafNode, + Storage: emptyStorage, + }, + }, + DeletedAccounts: emptyAccounts, + UpdatedAccounts: []statediff.AccountDiff{ + { + Path: []byte{}, + NodeType: statediff.Branch, + Storage: emptyStorage, + NodeValue: block1RootBranchNode, + }, + { + Path: []byte{'\x04'}, + NodeType: statediff.Branch, + Storage: emptyStorage, + NodeValue: block1x04BranchNode, + }, + { + Path: []byte{'\x04', '\x0b'}, + NodeType: statediff.Branch, + Storage: emptyStorage, + NodeValue: block1x040bBranchNode, + }, + }, }, }, { @@ -152,11 +542,54 @@ func TestBuilderOnMainnetBlocks(t *testing.T) { blockHash: block2.Hash(), }, &statediff.StateDiff{ - BlockNumber: block2.Number(), - BlockHash: block2.Hash(), - CreatedAccounts: emptyAccountMap, - DeletedAccounts: emptyAccountMap, - UpdatedAccounts: emptyAccountMap, + BlockNumber: block2.Number(), + BlockHash: block2.Hash(), + CreatedAccounts: []statediff.AccountDiff{ + // this new leaf at x00 x08 x0d x00 was created when a premine account (leaf) was moved from path x00 x08 x0d + // this occurred because of the creation of the new coinbase receiving account (leaf) at x00 x08 x0d x04 + // which necessitates we create a branch at x00 x08 x0d (as shown in the below UpdateAccounts) + { + Path: []byte{'\x00', '\x08', '\x0d', '\x00'}, + NodeType: statediff.Leaf, + Storage: emptyStorage, + LeafKey: common.HexToHash("08d0f2e24db7943eab4415f99e109698863b0fecca1cf9ffc500f38cefbbe29e").Bytes(), + NodeValue: block2MovedPremineLeafNode, + }, + { + Path: []byte{'\x00', '\x08', '\x0d', '\x04'}, + NodeType: statediff.Leaf, + Storage: emptyStorage, + LeafKey: block2CoinbaseHash.Bytes(), + NodeValue: block2CoinbaseLeafNode, + }, + }, + DeletedAccounts: emptyAccounts, + UpdatedAccounts: []statediff.AccountDiff{ + { + Path: []byte{}, + NodeType: statediff.Branch, + Storage: emptyStorage, + NodeValue: block2RootBranchNode, + }, + { + Path: []byte{'\x00'}, + NodeType: statediff.Branch, + Storage: emptyStorage, + NodeValue: block2x00BranchNode, + }, + { + Path: []byte{'\x00', '\x08'}, + NodeType: statediff.Branch, + Storage: emptyStorage, + NodeValue: block2x0008BranchNode, + }, + { + Path: []byte{'\x00', '\x08', '\x0d'}, + NodeType: statediff.Branch, + Storage: emptyStorage, + NodeValue: block2x00080dBranchNode, + }, + }, }, }, { @@ -170,11 +603,76 @@ func TestBuilderOnMainnetBlocks(t *testing.T) { blockHash: block3.Hash(), }, &statediff.StateDiff{ - BlockNumber: block3.Number(), - BlockHash: block3.Hash(), - CreatedAccounts: emptyAccountMap, - DeletedAccounts: emptyAccountMap, - UpdatedAccounts: emptyAccountMap, + BlockNumber: block3.Number(), + BlockHash: block3.Hash(), + CreatedAccounts: []statediff.AccountDiff{ + { // How was this account created??? + Path: []byte{'\x0c', '\x0e', '\x05', '\x07', '\x03'}, + NodeType: statediff.Leaf, + Storage: emptyStorage, + LeafKey: common.HexToHash("ce573ced93917e658d10e2d9009470dad72b63c898d173721194a12f2ae5e190").Bytes(), + NodeValue: block3MovedPremineLeafNode1, + }, + { // This account (leaf) used to be at 0c 0e 05 07, not sure why it moves... + Path: []byte{'\x0c', '\x0e', '\x05', '\x07', '\x08'}, + NodeType: statediff.Leaf, + Storage: emptyStorage, + LeafKey: common.HexToHash("ce5783bc1e69eedf90f402e11f6862da14ed8e50156635a04d6393bbae154012").Bytes(), + NodeValue: block3MovedPremineLeafNode2, + }, + { // this is the new account created due to the coinbase mining a block, it's creation shouldn't affect 0x 0e 05 07 + Path: []byte{'\x06', '\x0e', '\x0f'}, + NodeType: statediff.Leaf, + Storage: emptyStorage, + LeafKey: block3CoinbaseHash.Bytes(), + NodeValue: block3CoinbaseLeafNode, + }, + }, + DeletedAccounts: emptyAccounts, + UpdatedAccounts: []statediff.AccountDiff{ + { + Path: []byte{}, + NodeType: statediff.Branch, + Storage: emptyStorage, + NodeValue: block3RootBranchNode, + }, + { + Path: []byte{'\x06'}, + NodeType: statediff.Branch, + Storage: emptyStorage, + NodeValue: block3x06BranchNode, + }, + { + Path: []byte{'\x06', '\x0e'}, + NodeType: statediff.Branch, + Storage: emptyStorage, + NodeValue: block3x060eBranchNode, + }, + { + Path: []byte{'\x0c'}, + NodeType: statediff.Branch, + Storage: emptyStorage, + NodeValue: block3x0cBranchNode, + }, + { + Path: []byte{'\x0c', '\x0e'}, + NodeType: statediff.Branch, + Storage: emptyStorage, + NodeValue: block3x0c0eBranchNode, + }, + { + Path: []byte{'\x0c', '\x0e', '\x05'}, + NodeType: statediff.Branch, + Storage: emptyStorage, + NodeValue: block3x0c0e05BranchNode, + }, + { + Path: []byte{'\x0c', '\x0e', '\x05', '\x07'}, + NodeType: statediff.Branch, + Storage: emptyStorage, + NodeValue: block3x0c0e0507BranchNode, + }, + }, }, }, } diff --git a/statediff/testhelpers/mocks/api_test.go b/statediff/testhelpers/mocks/api_test.go index eb069436d..a826b1b6f 100644 --- a/statediff/testhelpers/mocks/api_test.go +++ b/statediff/testhelpers/mocks/api_test.go @@ -33,8 +33,10 @@ import ( ) var ( + emptyStorage = make([]statediff.StorageDiff, 0) + emptyAccounts = make([]statediff.AccountDiff, 0) block0, block1 *types.Block - burnLeafKey = testhelpers.AddressToLeafKey(common.HexToAddress("0x0")) + minerLeafKey = testhelpers.AddressToLeafKey(common.HexToAddress("0x0")) emptyAccountDiffEventualMap = make([]statediff.AccountDiff, 0) account1, _ = rlp.EncodeToBytes(state.Account{ Nonce: uint64(0), @@ -46,25 +48,35 @@ var ( common.Hex2Bytes("3926db69aaced518e9b9f0f434a473e7174109c943548bb8f23be41ca76d9ad2"), account1, }) - burnAccount1, _ = rlp.EncodeToBytes(state.Account{ + bankAccountAtBlock0, _ = rlp.EncodeToBytes(state.Account{ + Nonce: testhelpers.Nonce0, + Balance: big.NewInt(testhelpers.TestBankFunds.Int64()), + CodeHash: testhelpers.NullCodeHash.Bytes(), + Root: testhelpers.EmptyContractRoot, + }) + bankAccountAtBlock0LeafNode, _ = rlp.EncodeToBytes([]interface{}{ + common.Hex2Bytes("2000bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"), + bankAccountAtBlock0, + }) + minerAccount, _ = rlp.EncodeToBytes(state.Account{ Nonce: uint64(0), Balance: big.NewInt(2000000000000000000), CodeHash: common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes(), Root: common.HexToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"), }) - burnAccount1LeafNode, _ = rlp.EncodeToBytes([]interface{}{ + minerAccountLeafNode, _ = rlp.EncodeToBytes([]interface{}{ common.Hex2Bytes("3380c7b7ae81a58eb98d9c78de4a1fd7fd9535fc953ed2be602daaa41767312a"), - burnAccount1, + minerAccount, }) - bankAccount1, _ = rlp.EncodeToBytes(state.Account{ + bankAccount, _ = rlp.EncodeToBytes(state.Account{ Nonce: uint64(1), Balance: big.NewInt(testhelpers.TestBankFunds.Int64() - 10000), CodeHash: common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes(), Root: common.HexToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"), }) - bankAccount1LeafNode, _ = rlp.EncodeToBytes([]interface{}{ + bankAccountLeafNode, _ = rlp.EncodeToBytes([]interface{}{ common.Hex2Bytes("30bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"), - bankAccount1, + bankAccount, }) mockTotalDifficulty = big.NewInt(1337) ) @@ -94,28 +106,35 @@ func testSubscriptionAPI(t *testing.T) { { Path: []byte{'\x05'}, NodeType: statediff.Leaf, - LeafKey: burnLeafKey, - NodeValue: burnAccount1LeafNode, - Storage: []statediff.StorageDiff{}, + LeafKey: minerLeafKey, + NodeValue: minerAccountLeafNode, + Storage: emptyStorage, }, { Path: []byte{'\x0e'}, NodeType: statediff.Leaf, LeafKey: testhelpers.Account1LeafKey, NodeValue: account1LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, - }, - DeletedAccounts: emptyAccountDiffEventualMap, - UpdatedAccounts: []statediff.AccountDiff{ { Path: []byte{'\x00'}, NodeType: statediff.Leaf, LeafKey: testhelpers.BankLeafKey, - NodeValue: bankAccount1LeafNode, - Storage: []statediff.StorageDiff{}, + NodeValue: bankAccountLeafNode, + Storage: emptyStorage, }, }, + DeletedAccounts: []statediff.AccountDiff{ // This leaf appears to be deleted since it is turned into a branch node + { // It would instead show up in the UpdateAccounts as new branch node IF intermediate node diffing was turned on (as it is in the test below) + Path: []byte{}, + NodeType: statediff.Leaf, + LeafKey: testhelpers.BankLeafKey, + NodeValue: bankAccountAtBlock0LeafNode, + Storage: emptyStorage, + }, + }, + UpdatedAccounts: emptyAccounts, } expectedStateDiffBytes, _ := rlp.EncodeToBytes(expectedStateDiff) blockChan := make(chan *types.Block) @@ -186,28 +205,35 @@ func testHTTPAPI(t *testing.T) { { Path: []byte{'\x05'}, NodeType: statediff.Leaf, - LeafKey: burnLeafKey, - NodeValue: burnAccount1LeafNode, - Storage: []statediff.StorageDiff{}, + LeafKey: minerLeafKey, + NodeValue: minerAccountLeafNode, + Storage: emptyStorage, }, { Path: []byte{'\x0e'}, NodeType: statediff.Leaf, LeafKey: testhelpers.Account1LeafKey, NodeValue: account1LeafNode, - Storage: []statediff.StorageDiff{}, + Storage: emptyStorage, }, - }, - DeletedAccounts: emptyAccountDiffEventualMap, - UpdatedAccounts: []statediff.AccountDiff{ { Path: []byte{'\x00'}, NodeType: statediff.Leaf, LeafKey: testhelpers.BankLeafKey, - NodeValue: bankAccount1LeafNode, - Storage: []statediff.StorageDiff{}, + NodeValue: bankAccountLeafNode, + Storage: emptyStorage, }, }, + DeletedAccounts: []statediff.AccountDiff{ // This leaf appears to be deleted since it is turned into a branch node + { // It would instead show up in the UpdateAccounts as new branch node IF intermediate node diffing was turned on (as it is in the test below) + Path: []byte{}, + NodeType: statediff.Leaf, + LeafKey: testhelpers.BankLeafKey, + NodeValue: bankAccountAtBlock0LeafNode, + Storage: emptyStorage, + }, + }, + UpdatedAccounts: emptyAccounts, } expectedStateDiffBytes, _ := rlp.EncodeToBytes(expectedStateDiff) config := statediff.Config{ diff --git a/statediff/testhelpers/test_data.go b/statediff/testhelpers/test_data.go index 800dd7855..e144797c9 100644 --- a/statediff/testhelpers/test_data.go +++ b/statediff/testhelpers/test_data.go @@ -24,6 +24,7 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/rlp" ) // AddressToLeafKey hashes an returns an address @@ -43,7 +44,7 @@ var ( EvenLeafFlag = []byte{byte(2) << 4} BlockNumber = big.NewInt(rand.Int63()) BlockHash = "0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73" - CodeHash = common.Hex2Bytes("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470") + NullCodeHash = crypto.Keccak256Hash([]byte{}) StoragePath = common.HexToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470").Bytes() StorageKey = common.HexToHash("0000000000000000000000000000000000000000000000000000000000000001").Bytes() StorageValue = common.Hex2Bytes("0x03") @@ -64,4 +65,11 @@ var ( Account2LeafKey = AddressToLeafKey(Account2Addr) ContractCode = common.Hex2Bytes("608060405234801561001057600080fd5b50602060405190810160405280600160ff16815250600090600161003592919061003b565b506100a5565b826064810192821561006f579160200282015b8281111561006e578251829060ff1690559160200191906001019061004e565b5b50905061007c9190610080565b5090565b6100a291905b8082111561009e576000816000905550600101610086565b5090565b90565b610124806100b46000396000f3fe6080604052348015600f57600080fd5b5060043610604f576000357c01000000000000000000000000000000000000000000000000000000009004806360cd2685146054578063c16431b9146093575b600080fd5b607d60048036036020811015606857600080fd5b810190808035906020019092919050505060c8565b6040518082815260200191505060405180910390f35b60c66004803603604081101560a757600080fd5b81019080803590602001909291908035906020019092919050505060e0565b005b6000808260648110151560d757fe5b01549050919050565b8060008360648110151560ef57fe5b0181905550505056fea165627a7a7230582064e918c3140a117bf3aa65865a9b9e83fae21ad1720506e7933b2a9f54bb40260029") ContractAddr common.Address + + EmptyRootNode, _ = rlp.EncodeToBytes([]byte{}) + EmptyContractRoot = crypto.Keccak256Hash(EmptyRootNode) + Nonce0 = uint64(0) + Nonce1 = uint64(1) + Nonce2 = uint64(2) + Nonce3 = uint64(3) )