From ec3be9d585864d0651a3edbfe225d9bd33e5edd9 Mon Sep 17 00:00:00 2001 From: cabrador <84449820+cabrador@users.noreply.github.com> Date: Fri, 29 Nov 2024 12:14:22 +0100 Subject: [PATCH 1/3] Update Carmen to 34dad37b56481fcd1863d93cd501278420a1e265 (#358) --- go.mod | 2 +- go.sum | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index bac59d016..7a0384646 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22.0 toolchain go1.22.3 require ( - github.com/Fantom-foundation/Carmen/go v0.0.0-20241121102311-62fc85c89464 + github.com/Fantom-foundation/Carmen/go v0.0.0-20241128114701-34dad37b5648 github.com/Fantom-foundation/Tosca v0.0.0-20241028082205-7b33705a4675 github.com/Fantom-foundation/lachesis-base v0.0.0-20240116072301-a75735c4ef00 github.com/cespare/cp v1.1.1 diff --git a/go.sum b/go.sum index 973b4262a..dfa8f6462 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,7 @@ github.com/DataDog/zstd v1.5.6 h1:LbEglqepa/ipmmQJUDnSsfvA8e8IStVcGaFWDuxvGOY= github.com/DataDog/zstd v1.5.6/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= -github.com/Fantom-foundation/Carmen/go v0.0.0-20241021085109-e8dc12374917 h1:NisjazAL9OL1n51CRXpUtkrfz/zzkcEEnA39wO0pcXM= -github.com/Fantom-foundation/Carmen/go v0.0.0-20241021085109-e8dc12374917/go.mod h1:vNRGm/b21hDlF8kYyKHkXq1s+jLMKpV4jGwXHylXIIg= -github.com/Fantom-foundation/Carmen/go v0.0.0-20241023071438-8b3c25fd1ff8 h1:uDlLl/ZbGUM7FHxDjmzHxMnJkSvOt8mLV9+O41pROGA= -github.com/Fantom-foundation/Carmen/go v0.0.0-20241023071438-8b3c25fd1ff8/go.mod h1:vNRGm/b21hDlF8kYyKHkXq1s+jLMKpV4jGwXHylXIIg= -github.com/Fantom-foundation/Carmen/go v0.0.0-20241119172232-50adaaafeea4 h1:8FF/xZh6fBMHF3B19cMvPg909eDQJqatsVuUbtBQeHk= -github.com/Fantom-foundation/Carmen/go v0.0.0-20241119172232-50adaaafeea4/go.mod h1:vNRGm/b21hDlF8kYyKHkXq1s+jLMKpV4jGwXHylXIIg= -github.com/Fantom-foundation/Carmen/go v0.0.0-20241121102311-62fc85c89464 h1:xWayjc87Mk3ESu4xGtX6YYx7KrN+gJpCWZhqmZHDpxs= -github.com/Fantom-foundation/Carmen/go v0.0.0-20241121102311-62fc85c89464/go.mod h1:vNRGm/b21hDlF8kYyKHkXq1s+jLMKpV4jGwXHylXIIg= -github.com/Fantom-foundation/Tosca v0.0.0-20241009135726-aa99babe0a10 h1:D7askaARHcrcXDVZHweaxxz2wKvo/ipvjA/qooyEkNM= -github.com/Fantom-foundation/Tosca v0.0.0-20241009135726-aa99babe0a10/go.mod h1:DtJlv3NCjaFxBKGXR7HQfLhLSu+BY5OILQ/4s7MR6lA= +github.com/Fantom-foundation/Carmen/go v0.0.0-20241128114701-34dad37b5648 h1:gVmZHEjmw9/JAyaU28MOWkbDzLPZ+Qfu1WTHOuE26UU= +github.com/Fantom-foundation/Carmen/go v0.0.0-20241128114701-34dad37b5648/go.mod h1:vNRGm/b21hDlF8kYyKHkXq1s+jLMKpV4jGwXHylXIIg= github.com/Fantom-foundation/Tosca v0.0.0-20241028082205-7b33705a4675 h1:Meqtt0eM9UAw1ceQ1tGiD497V0IVfqj8c6UrFJhkFNE= github.com/Fantom-foundation/Tosca v0.0.0-20241028082205-7b33705a4675/go.mod h1:8i7r+dUOkXjEC61SaFoRet6JYjRaSoiM/PhviP6K4Y8= github.com/Fantom-foundation/go-ethereum-sonic v0.0.0-20241022121122-7063a6b506bd h1:WoAkgzLLlyh3Zpnd/3gW8Ym5sHtugLCA4rQdT5udVF8= From 0c8ffcf8c20eddde525b985e06cf0af0ea3fd844 Mon Sep 17 00:00:00 2001 From: Herbert Date: Sat, 30 Nov 2024 11:50:26 +0100 Subject: [PATCH 2/3] Update Carmen to get proof steps in correct order (#362) --- ethapi/api.go | 8 +++----- go.mod | 2 +- go.sum | 4 ++-- tests/block_header_test.go | 41 ++++++++++++++++++++++++++------------ 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/ethapi/api.go b/ethapi/api.go index b826cf734..22166561e 100644 --- a/ethapi/api.go +++ b/ethapi/api.go @@ -745,7 +745,7 @@ func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Addre storageProof := make([]StorageResult, len(keys)) for i, key := range keys { - elements, _, _ := proof.GetStorageElements(cc.Hash(header.Root), cc.Address(address), cc.Key(keys[i])) + elements, _ := proof.GetStorageElements(cc.Hash(header.Root), cc.Address(address), cc.Key(keys[i])) storageProof[i] = StorageResult{ Key: key.Hex(), Value: (*hexutil.Big)(state.GetState(address, key).Big()), @@ -753,14 +753,12 @@ func (s *PublicBlockChainAPI) GetProof(ctx context.Context, address common.Addre } } - _, storageHash, _ := proof.GetStorageElements(cc.Hash(header.Root), cc.Address(address)) + accountProof, storageHash, _ := proof.GetAccountElements(cc.Hash(header.Root), cc.Address(address)) codeHash := state.GetCodeHash(address) - accountProof, _ := proof.Extract(cc.Hash(header.Root), cc.Address(address)) - return &AccountResult{ Address: address, - AccountProof: toHexSlice(accountProof.GetElements()), + AccountProof: toHexSlice(accountProof), Balance: (*hexutil.U256)(state.GetBalance(address)), CodeHash: codeHash, Nonce: hexutil.Uint64(state.GetNonce(address)), diff --git a/go.mod b/go.mod index 7a0384646..2e0d2dd66 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22.0 toolchain go1.22.3 require ( - github.com/Fantom-foundation/Carmen/go v0.0.0-20241128114701-34dad37b5648 + github.com/Fantom-foundation/Carmen/go v0.0.0-20241129202153-690bc10fa624 github.com/Fantom-foundation/Tosca v0.0.0-20241028082205-7b33705a4675 github.com/Fantom-foundation/lachesis-base v0.0.0-20240116072301-a75735c4ef00 github.com/cespare/cp v1.1.1 diff --git a/go.sum b/go.sum index dfa8f6462..01e3251f8 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ github.com/DataDog/zstd v1.5.6 h1:LbEglqepa/ipmmQJUDnSsfvA8e8IStVcGaFWDuxvGOY= github.com/DataDog/zstd v1.5.6/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= -github.com/Fantom-foundation/Carmen/go v0.0.0-20241128114701-34dad37b5648 h1:gVmZHEjmw9/JAyaU28MOWkbDzLPZ+Qfu1WTHOuE26UU= -github.com/Fantom-foundation/Carmen/go v0.0.0-20241128114701-34dad37b5648/go.mod h1:vNRGm/b21hDlF8kYyKHkXq1s+jLMKpV4jGwXHylXIIg= +github.com/Fantom-foundation/Carmen/go v0.0.0-20241129202153-690bc10fa624 h1:9bFojtY5KoLFUtLYZGc1GNf0oIdBIOarlLr4+a/DA7U= +github.com/Fantom-foundation/Carmen/go v0.0.0-20241129202153-690bc10fa624/go.mod h1:vNRGm/b21hDlF8kYyKHkXq1s+jLMKpV4jGwXHylXIIg= github.com/Fantom-foundation/Tosca v0.0.0-20241028082205-7b33705a4675 h1:Meqtt0eM9UAw1ceQ1tGiD497V0IVfqj8c6UrFJhkFNE= github.com/Fantom-foundation/Tosca v0.0.0-20241028082205-7b33705a4675/go.mod h1:8i7r+dUOkXjEC61SaFoRet6JYjRaSoiM/PhviP6K4Y8= github.com/Fantom-foundation/go-ethereum-sonic v0.0.0-20241022121122-7063a6b506bd h1:WoAkgzLLlyh3Zpnd/3gW8Ym5sHtugLCA4rQdT5udVF8= diff --git a/tests/block_header_test.go b/tests/block_header_test.go index a59fa3f43..f44737410 100644 --- a/tests/block_header_test.go +++ b/tests/block_header_test.go @@ -481,14 +481,14 @@ func testHeaders_StateRootsMatchActualStateRoots(t *testing.T, headers []*types. // root we see in the database. To get access to the database, we request // a witness proof for an account at the given block. From this proof we // we have a list of state-root candidates which we can test for. - steps, err := getWitnessProofSteps(client, int(header.Number.Int64())) + want, err := getStateRoot(client, int(header.Number.Int64())) require.NoError(err, "failed to get witness proof for block %d", i) got := header.Root - require.Contains(steps, got, "state root mismatch for block %d", i) + require.Equal(want, got, "state root mismatch for block %d", i) } } -func getWitnessProofSteps(client *ethclient.Client, blockNumber int) ([]common.Hash, error) { +func getStateRoot(client *ethclient.Client, blockNumber int) (common.Hash, error) { var result struct { AccountProof []string } @@ -500,18 +500,19 @@ func getWitnessProofSteps(client *ethclient.Client, blockNumber int) ([]common.H fmt.Sprintf("0x%x", blockNumber), ) if err != nil { - return nil, fmt.Errorf("failed to get witness proof; %v", err) + return common.Hash{}, fmt.Errorf("failed to get witness proof; %v", err) } - res := []common.Hash{} - for _, proof := range result.AccountProof { - data, err := hexutil.Decode(proof) - if err != nil { - return nil, err - } - res = append(res, common.BytesToHash(crypto.Keccak256(data))) + // The hash of the first element of the account proof is the state root. + if len(result.AccountProof) == 0 { + return common.Hash{}, fmt.Errorf("no account proof found") } - return res, nil + + data, err := hexutil.Decode(result.AccountProof[0]) + if err != nil { + return common.Hash{}, err + } + return common.BytesToHash(crypto.Keccak256(data)), nil } func testHeaders_SystemContractsHaveNonZeroNonce(t *testing.T, headers []*types.Header, client *ethclient.Client) { @@ -708,6 +709,7 @@ func getVerifiedCounterState( require := require.New(t) var result struct { AccountProof []string + StorageHash common.Hash StorageProof []struct { Value string Proof []string @@ -722,6 +724,7 @@ func getVerifiedCounterState( ) require.NoError(err, "failed to get witness proof") require.Equal(1, len(result.StorageProof), "expected exactly one storage proof") + require.GreaterOrEqual(len(result.StorageProof[0].Proof), 1, "expected at least one proof element") // Verify the proof. elements := []carmen.Bytes{} @@ -733,13 +736,25 @@ func getVerifiedCounterState( } } proof := carmen.CreateWitnessProofFromNodes(elements...) - require.True(proof.IsValid(), "proof is invalid") + require.True(proof.IsValid()) // Extract the storage value from the proof. value, present, err := proof.GetState(carmen.Hash(stateRoot), carmen.Address(counterAddress), carmen.Key{}) require.NoError(err, "failed to get state from proof") require.True(present, "slot not found in proof") + // Check that the storage root hash is consistent. + _, storageRoot, complete := proof.GetAccountElements(carmen.Hash(stateRoot), carmen.Address(counterAddress)) + require.True(complete, "proof is not complete") + require.Equal(common.Hash(storageRoot), result.StorageHash, "storage root mismatch") + + // Check that the storage proof starts with an element that corresponds to + // the storage root. + hash := crypto.Keccak256(hexutil.MustDecode(result.StorageProof[0].Proof[0])) + firstElementHash := carmen.Hash{} + copy(firstElementHash[:], hash) + require.Equal(storageRoot, firstElementHash, "storage proof does not start with the storage root") + // Compare the proof value with the value in the RPC result. fromProof := int(new(big.Int).SetBytes(value[:]).Uint64()) fromResult, err := hexutil.DecodeUint64(result.StorageProof[0].Value) From 797a5ab8186b3579978f8e44b761826b89f3f412 Mon Sep 17 00:00:00 2001 From: JM Date: Sun, 1 Dec 2024 10:42:02 +0100 Subject: [PATCH 3/3] Add Sonic network bootstrap nodes --- config/params.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/config/params.go b/config/params.go index b7fdbdae0..3fcb57a9f 100644 --- a/config/params.go +++ b/config/params.go @@ -2,6 +2,20 @@ package config var ( Bootnodes = map[string][]string{ + "sonic": { + "enode://5facb14cfb4c5cb63f916f46e9689619f65040aa8efb7e9e9adb506db9fc006f042828ad7896467cf5eb1f3b74e53ad4fcd6bc4f15ae3acc3e8b7628e5446dad@boot-a.sonic.soniclabs.com:5050", + "enode://04d51b2e172ed3722267bf26a39b55645ea220df7d35be7581a96409567cab5807eadd4c0b94f2c0c7128adece5ae64dd808dd9aa4543aa05c789bca02099731@boot-b.sonic.soniclabs.com:5050", + "enode://ae3a88445aafb8cfff48bbcb1e7399c49d5d00d7c859f6dc0d3f8f2386019481f49cf1c32f2bce5a234de1311ebd8162858a4aa4c9dcc7f99b9b0c770044e7d5@boot-c.sonic.soniclabs.com:5050", + "enode://979d4ed2a093324cafb413bd890f9e61d5ed1838215fe1704994e88d74e6067c294e03efd17e1186d8cafb70ca1ab05709765b1eb373928d7736319216cb97d0@boot-d.sonic.soniclabs.com:5050", + "enode://22002ecd942431f5ba13c6873c32e5af5901eca9af170e263592a43e18dda774d7f986e6fd1e57c3f97d7566d7f713da30ed59746b4c52448e1e8c8fbcc7de5a@boot-e.sonic.soniclabs.com:5050", + "enode://d85734f1fa2415ceffe56ae55f3f446fd722e3a5189af5753e4db3947efea2d11637912c010ab67d884cc8859f76bfd1e9ea47b613fff61f746b3aa0e0237837@boot-f.sonic.soniclabs.com:5050", + "enode://9403ff58d782635f5a82974a774efdfa10ca15125c5c146426485dbe68305d52a39ae2af8739175b11cca7b3f42746ea9c51d1c19969cfd5ef96ec24b0fce093@boot-g.sonic.soniclabs.com:5050", + "enode://e03d93283100cec25105da49bdaf34e38d5ae9ddcbc54114c9095471f2e9b3f6f1d190ef4cc5acdb12da4131722f9948c9af43ab64c6f0d8b7d05694cfc3c5b4@boot-h.sonic.soniclabs.com:5050", + "enode://e6bb6a491256d67f6731a9b03af0426965449f205343605ad4ff075448a88624c30a0274aef29d9d44ce1bd94e2bec6fc158e076422545a20dbf6e272f1188c7@boot-i.sonic.soniclabs.com:5050", + "enode://ecf6bc22d0293db8a1323dc525b69b3a5648692da6d64c612cacbec47b6139e18acf49a7edfb8298b7e4df9182b0da271c63a7d53f293fa9d035f2242bf554e2@boot-j.sonic.soniclabs.com:5050", + "enode://06f542cb2377feb39d544cb7d6160ddcb682d4a93b8fbb15137b75558295cc31dfe8862b233d26c32a377a71d13539befeadb5164efca365de5743812031d467@boot-k.sonic.soniclabs.com:5050", + "enode://81616eadbe45cf147ddc87dabd44a326cc9c3c78ef446bceca42380bc5ac4260b8f52a1369a444d67c80896232916dbdab732cb9779c86d43af9142a5befcc85@boot-l.sonic.soniclabs.com:5050", + }, "blaze-testnet": { "enode://8afb7207ac6448871f9d165b59c8392fd1341b6cd89fc031e383b075326c31ca9399a058314ef3265a5000325b67b567502946496c4a94ae5354a0db646d3350@bootstrap-a.blaze.soniclabs.com:5050", "enode://6ed780d0f72e3e67c863cc26090040a56579bc989a3597fc88b045a65653633acddc77907635bc4128ad48e9c067ac0b4da406f3b32c92b2d61f79f99978cd40@bootstrap-b.blaze.soniclabs.com:5050",