diff --git a/core/packages/test/scripts/configure-beacon.sh b/core/packages/test/scripts/configure-beacon.sh index d6c0794e73d2d..f63c9bb355ef0 100755 --- a/core/packages/test/scripts/configure-beacon.sh +++ b/core/packages/test/scripts/configure-beacon.sh @@ -6,23 +6,12 @@ source scripts/xcm-helper.sh config_beacon_checkpoint() { + pushd $root_dir check_point_call=$($relay_bin generate-beacon-checkpoint --spec $active_spec --url $beacon_endpoint_http) + popd send_governance_transact_from_relaychain $bridgehub_para_id "$check_point_call" 180000000000 900000 } -config_beacon_relayer() -{ - # Configure beacon relay - jq \ - --arg beacon_endpoint_http $beacon_endpoint_http \ - --arg active_spec $active_spec \ - ' - .source.beacon.endpoint = $beacon_endpoint_http - | .source.beacon.activeSpec = $active_spec - ' \ - config/beacon-relay.json > $output_dir/beacon-relay.json -} - wait_beacon_chain_ready() { initial_beacon_block="" @@ -38,14 +27,11 @@ wait_beacon_chain_ready() function configure_beacon() { wait_beacon_chain_ready - config_beacon_relayer config_beacon_checkpoint } if [ -z "${from_start_services:-}" ]; then echo "config beacon checkpoint only!" - wait_beacon_chain_ready - config_beacon_relayer - config_beacon_checkpoint + configure_beacon wait fi diff --git a/cumulus b/cumulus index e1f936aa2c36b..226779afc932e 160000 --- a/cumulus +++ b/cumulus @@ -1 +1 @@ -Subproject commit e1f936aa2c36be16a88c1fac770a25515988404b +Subproject commit 226779afc932edd5508f2eb9df53e332eaa6102e diff --git a/parachain/pallets/ethereum-beacon-client/src/benchmarking/data_mainnet.rs b/parachain/pallets/ethereum-beacon-client/src/benchmarking/data_mainnet.rs index 4edd80e7481ab..81e5fffb6a271 100644 --- a/parachain/pallets/ethereum-beacon-client/src/benchmarking/data_mainnet.rs +++ b/parachain/pallets/ethereum-beacon-client/src/benchmarking/data_mainnet.rs @@ -1099,7 +1099,6 @@ pub fn sync_committee_update() -> SyncCommitteeUpdate { sync_committee_bits: hex!("ff7ffffdbffffff7edffd5f4fffffd79ffce7ff7dff6ffcdefb9fffdffff3bffdedbffbf7fff9fdfe7bf5dfebfbffeffffe7e1fffbfeefeb77bfdfa7ffddffbb"), sync_committee_signature: hex!("a58417f897521dc58fa339c9465b1346a7005251ad582fafae984918606005b23627eface374912c70e4ed28c4358eca03783419e3625ab1159b9562837581c6647fc960a6a7d54b0a811b1d5af853ee8274d9023a195f14530d46b8f6af07c2").into(), }, - sync_committee_period: 636, signature_slot: 5217992, block_roots_root: hex!("f46cd66ac816b7b890d37832c0a2fa8b56984edd7266926be26dbecf6bd93f62").into(), block_roots_branch: vec![ @@ -1154,7 +1153,7 @@ pub fn finalized_header_update() -> FinalizedHeaderUpdate { pub fn header_update() -> ExecutionHeaderUpdate { return ExecutionHeaderUpdate { - beacon_header: BeaconHeader{ + header: BeaconHeader{ slot: 5217982, proposer_index: 320636, parent_root: hex!("a4571a17210f45c48e1cf7732817d5a38c18f5d4c5642845978ed47ea7129ce9").into(), @@ -1184,12 +1183,8 @@ pub fn header_update() -> ExecutionHeaderUpdate { hex!("db56114e00fdd4c1f85c892bf35ac9a89289aaecb1ebd0a96cde606a748b5d71").into(), hex!("6fcc83169ef7b54eb9af29f63890644ac3fd1bffeb6edee8945bb13d9df802e9").into(), ].try_into().expect("too many branch proof items"), - sync_aggregate: SyncAggregate{ - sync_committee_bits: hex!("ff7ffefdbfffbff7edffd5b4fffffd39ff4c7f77dff6dfcdefa17ffdffff3bffded9fdbd7fff9ddfe7bf5dfeafb7feff7fe3e1fffbffefef77bfdfa7f7ddffb3"), - sync_committee_signature: hex!("9642b8a94e17eff18c50b1e0603e062fd7637e121d34a4a91e5ad48a9b8076497909de6c9c8e61980a5b33fa6f412d9519bb6f710f0144dfddd01eb36b18e9109ff7cdabc40752d15da22371214189320bc7588090ce4bfafeaee84972f4c7cf").into(), - }, - signature_slot: 5217983, - block_root_branch: vec![ + block_roots_root: hex!("52c9f5ef64da062dee00a30ebe16710a3ffe59cf91eedf96a69ae5d198d7d982").into(), + block_roots_branch: vec![ hex!("8406114752f4b0df307983b3d233e56b81822dcfcf37a04d31c03062582047a4").into(), hex!("7d1e19255fd12ccb31eff0832762c57cc6fcfe635191cb4afa9f1640b592e64f").into(), hex!("8de2db9fecd1827ab497b96968e1a880667aba9b55f73a76e5b16810fdbfd392").into(), @@ -1204,6 +1199,5 @@ pub fn header_update() -> ExecutionHeaderUpdate { hex!("f3b04813e6897bb1642c1c42f1edfdaf8b00b2b1b57d567e512dc1c5d51660db").into(), hex!("8795c1259089af496aa6339978f58f2fe25f89225dc97dd82dd0c3739fe94d10").into(), ], - block_root_branch_header_root: hex!("52c9f5ef64da062dee00a30ebe16710a3ffe59cf91eedf96a69ae5d198d7d982").into(), }; } diff --git a/parachain/pallets/ethereum-beacon-client/src/benchmarking/data_minimal.rs b/parachain/pallets/ethereum-beacon-client/src/benchmarking/data_minimal.rs deleted file mode 100644 index 8ea42907cf6a6..0000000000000 --- a/parachain/pallets/ethereum-beacon-client/src/benchmarking/data_minimal.rs +++ /dev/null @@ -1,267 +0,0 @@ -// Generated, do not edit! -// See README.md for instructions to generate -use frame_support::traits::Get; -use hex_literal::hex; -use snowbridge_beacon_primitives::{ - BeaconHeader, ExecutionPayloadHeader, FinalizedHeaderUpdate, HeaderUpdate, InitialUpdate, - PublicKey, SyncAggregate, SyncCommittee, SyncCommitteeUpdate, -}; -use sp_core::U256; -use sp_std::vec; - -pub fn initial_sync, ProofSize: Get>( -) -> InitialUpdate { - let time_now = 1675679352; //2023.2.6 - - return InitialUpdate{ - header: BeaconHeader{ - slot: 152, - proposer_index: 2, - parent_root: hex!("c6e5d2ad0e10309dc895c9f3a37b0dcadf95648f036b42d0ef5084252c69f1ed").into(), - state_root: hex!("b0f73342ab9c265eae11cc98cee2f82e5974158a6cb6772f5e57991b2f2a3f3a").into(), - body_root: hex!("d0ae6720fd5cd20d994292f4efa540811f2011b4b8aa466fe1a3c6aa8b1418ad").into(), - }, - current_sync_committee: SyncCommittee{ - pubkeys: [ - hex!("b89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b").into(), - hex!("88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e").into(), - hex!("81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e").into(), - hex!("a99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c").into(), - hex!("a3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b").into(), - hex!("ab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34").into(), - hex!("9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373").into(), - hex!("a8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac").into(), - hex!("b89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b").into(), - hex!("88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e").into(), - hex!("81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e").into(), - hex!("a99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c").into(), - hex!("a3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b").into(), - hex!("ab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34").into(), - hex!("9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373").into(), - hex!("a8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac").into(), - hex!("b89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b").into(), - hex!("88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e").into(), - hex!("81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e").into(), - hex!("a99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c").into(), - hex!("a3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b").into(), - hex!("ab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34").into(), - hex!("9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373").into(), - hex!("a8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac").into(), - hex!("b89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b").into(), - hex!("88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e").into(), - hex!("81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e").into(), - hex!("a99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c").into(), - hex!("a3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b").into(), - hex!("ab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34").into(), - hex!("9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373").into(), - hex!("a8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac").into(), - ], - aggregate_pubkey: hex!("8fe11476a05750c52618deb79918e2e674f56dfbf12dbce55ae4386d108e8a1e83c6326f5957e2ef19137582ce270dc6").into(), - }, - current_sync_committee_branch: vec![ - hex!("ae55686c9aa0cfc3a6a3edf5fcc27f3eafbe2772444f4fae6f1f00e1cee7d0ac").into(), - hex!("e6d21c47c11698b8acf43778e6e7bdb804f14318bd37460b2274814f1f6cc554").into(), - hex!("24851e4e01f264323b3bf1373dc8c99c71afa12ec04329df98e6dc1c45555365").into(), - hex!("f5097ceea15bf7a5f7eabcaacba29af64ba0653e2077287e1d17f98d1a5778ad").into(), - hex!("ebd5dd152ab8fc8acd6ee0d7e43537c3caedc12a9e283e9079ac17a92f2eb931").into(), - ], - validators_root: hex!("270d43e74ce340de4bca2b1936beca0f4f5408d9e78aec4850920baf659d5b69").into(), - import_time: time_now + 97200, // now + 27 hour sync committee period - }; -} - -pub fn sync_committee_update< - SignatureSize: Get, - ProofSize: Get, - SyncCommitteeSize: Get, ->() -> SyncCommitteeUpdate { - return SyncCommitteeUpdate { - attested_header: BeaconHeader { - slot: 144, - proposer_index: 2, - parent_root: hex!("d606dedd06b3e00b5c04a80d4d7f4c07c08c6bc1cd6ada47a141f0d7cc4a8032").into(), - state_root: hex!("1720054de28109ee155947a31ed88649c514e590440e959b071d981d70e57e76").into(), - body_root: hex!("8624a57d021cf59e367432769b53e4da63f9a613db778e2e89db701f0b068bea").into(), - }, - next_sync_committee: SyncCommittee { - pubkeys: [ - hex!("a99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c").into(), - hex!("a8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac").into(), - hex!("ab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34").into(), - hex!("88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e").into(), - hex!("a3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b").into(), - hex!("81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e").into(), - hex!("9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373").into(), - hex!("b89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b").into(), - hex!("a99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c").into(), - hex!("a8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac").into(), - hex!("ab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34").into(), - hex!("88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e").into(), - hex!("a3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b").into(), - hex!("81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e").into(), - hex!("9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373").into(), - hex!("b89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b").into(), - hex!("a99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c").into(), - hex!("a8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac").into(), - hex!("ab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34").into(), - hex!("88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e").into(), - hex!("a3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b").into(), - hex!("81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e").into(), - hex!("9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373").into(), - hex!("b89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b").into(), - hex!("a99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c").into(), - hex!("a8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac").into(), - hex!("ab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34").into(), - hex!("88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e").into(), - hex!("a3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b").into(), - hex!("81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e").into(), - hex!("9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373").into(), - hex!("b89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b").into(), - ], - aggregate_pubkey: hex!("8fe11476a05750c52618deb79918e2e674f56dfbf12dbce55ae4386d108e8a1e83c6326f5957e2ef19137582ce270dc6").into() - }, - next_sync_committee_branch: vec![ - hex!("9aaac2741ce2878a681113933945f318219d798b6d487cc93e8754a2a5a3a965").into(), - hex!("c31424ccfc25a7c31fdf86b6f96e8fd9968e79fb11b39f8a05c28a91d468705f").into(), - hex!("f782ef12694554b3080ea1479ae045ffa944b6619ca49f2ab75fc20b43c8980c").into(), - hex!("360a6db1bac303ac552dc634c7539af9c781e3fc20a7b68ddd95635c6e4cdee5").into(), - hex!("1e4cad215834a2821fd8cddb69258c0f49506cbd32a2165b774a1860e7e346e1").into(), - ].try_into().expect("too many branch proof items"), - finalized_header: BeaconHeader{ - slot: 128, - proposer_index: 3, - parent_root: hex!("85c48e098074d4e149c05065af9500cecc802f6ae860be69e33dbd52c5c11299").into(), - state_root: hex!("5229bec41f0b20ff789212c00466fa41d003ccec477948f1a2aa5acc875dff7a").into(), - body_root: hex!("abc39f53ae99d6a88afe978320365a6a08ab74167f752b1ca9ec1018e339c7bc").into(), - }, - finality_branch: vec![ - hex!("1000000000000000000000000000000000000000000000000000000000000000").into(), - hex!("10c726fac935bf9657cc7476d3cfa7bedec5983dcfb59e8a7df6d0a619e108d7").into(), - hex!("24477da323967ef1397fb25cde5aa28ed5d7f5a5b437ba4343c9be88041bc119").into(), - hex!("f782ef12694554b3080ea1479ae045ffa944b6619ca49f2ab75fc20b43c8980c").into(), - hex!("360a6db1bac303ac552dc634c7539af9c781e3fc20a7b68ddd95635c6e4cdee5").into(), - hex!("1e4cad215834a2821fd8cddb69258c0f49506cbd32a2165b774a1860e7e346e1").into(), - ].try_into().expect("too many branch proof items"), - sync_aggregate: SyncAggregate{ - sync_committee_bits: hex!("ffffffff").to_vec().try_into().expect("too many sync committee bits"), - sync_committee_signature: hex!("a6e5309e0439042fe2d98342faf63452f3aed9a0d4f0086a42588e96a4c619d90964575aff9d7c5aa80e6846efcae3ec1825e2b750314fb715692e38c8a74f2fa86ebf2d3343294c87eb7933794e3c82398168cf3fbf9732c4df51bba3e44989").to_vec().try_into().expect("signature too long"), - }, - sync_committee_period: 2, - signature_slot: 145, - block_roots_root: hex!("0367a032243a6c3660e9fe6d1a66c8347767908bff0feef436440e89b35947f5").into(), - block_roots_branch: vec![ - hex!("bae2da1b2ef7c3d5d08f251a52f28efb26baa02e37c068b9c7c714055eec0985").into(), - hex!("c046d211fd6f111e77a764a02e4c87ffb2495e23cec971793d2c3b141c23ad19").into(), - hex!("fffc075fe465a906ba230573b6087e6d582d051c6aa5a6983fee1284818818e8").into(), - hex!("ce896755e5dd78b5f1d8cff2cfff79745f3a53f3be1cab1faa86c2e4c727af59").into(), - hex!("06b03718b08a83210a0c3a0ba687e246a701e60c7d5d02cca2fc76d054a78918").into(), - ].try_into().expect("too many branch proof items"), - }; -} - -pub fn finalized_header_update< - SignatureSize: Get, - ProofSize: Get, - SyncCommitteeSize: Get, ->() -> FinalizedHeaderUpdate { - return FinalizedHeaderUpdate{ - attested_header: BeaconHeader { - slot: 168, - proposer_index: 5, - parent_root: hex!("d567978cf2992cc290f223df75d58369a9893d798c23ed3722ab7a0690bda687").into(), - state_root: hex!("3e30d9357c88dc78c3bc8ed19685e3f21e90072f809d0d30a4658634e4f5ab41").into(), - body_root: hex!("581383568a951904285564c960260d21a662919d0f18fb76e001515c7f1496f6").into(), - }, - finalized_header: BeaconHeader{ - slot: 152, - proposer_index: 2, - parent_root: hex!("c6e5d2ad0e10309dc895c9f3a37b0dcadf95648f036b42d0ef5084252c69f1ed").into(), - state_root: hex!("b0f73342ab9c265eae11cc98cee2f82e5974158a6cb6772f5e57991b2f2a3f3a").into(), - body_root: hex!("d0ae6720fd5cd20d994292f4efa540811f2011b4b8aa466fe1a3c6aa8b1418ad").into(), - }, - finality_branch: vec![ - hex!("1300000000000000000000000000000000000000000000000000000000000000").into(), - hex!("10c726fac935bf9657cc7476d3cfa7bedec5983dcfb59e8a7df6d0a619e108d7").into(), - hex!("24477da323967ef1397fb25cde5aa28ed5d7f5a5b437ba4343c9be88041bc119").into(), - hex!("dabc4d1850acd0551d8d30f9d35b3471f88477f56e617cbd48b52a38f0682fd9").into(), - hex!("58c6354b6ac69908c6306aa6a16ef3fd9d1fcfc9a1ba46732e65635b93d48788").into(), - hex!("e814c498f7b604b0ee9168053bb905fca91d004c1cb5cd5e8647ce7ceb4328c1").into(), - ].try_into().expect("too many branch proof items"), - sync_aggregate: SyncAggregate{ - sync_committee_bits: hex!("ffffffff"), - sync_committee_signature: hex!("b7a1aa69fd2b57308f871dc877215b3521ad336b5af88bc286c5b42f8ecf36cad076c67465fc5c02c72132ee000eeb300e60362fbd5548a6c27e5b0b8d0d3d6b32adfc08673605572b630b005ac07af5cb7617176100ae843fbb86cee4e7c683").into(), - }, - signature_slot: 169, - block_roots_root: hex!("0ca0cf2867bc9c8361f2c66a926218d0a5817301667e0a974983cd1d87dd6e55").into(), - block_roots_branch: vec![ - hex!("7265769c5443608ec0ca000bd6d92b98bd74a6ed1d91bdb9745b173bd4bd30b2").into(), - hex!("63da1a7293f7a8ba9e555312e91aac391847813390b76a51c6b6842a63509151").into(), - hex!("314eb3af46fb3cd5b6e78ad4e91467a4149c056d1e8d8e76dd2382177d2be464").into(), - hex!("bc5b324e321445e9ee98c670c563a5c7793b12ecdd79b25be0abee5288d9b410").into(), - hex!("c1e6c27607e2ec00b123b5e98426100fe38c14e35030505e9cd5c713f194c71d").into(), - ] - }; -} - -pub fn header_update< - FeeRecipientSize: Get, - LogsBloomSize: Get, - ExtraDataSize: Get, - SignatureSize: Get, - ProofSize: Get, - SyncCommitteeSize: Get, ->() -> HeaderUpdate< - FeeRecipientSize, - LogsBloomSize, - ExtraDataSize, - SignatureSize, - ProofSize, - SyncCommitteeSize, -> { - return HeaderUpdate{ - beacon_header: BeaconHeader{ - slot: 150, - proposer_index: 5, - parent_root: hex!("8bdd8b8f9e6887ff2b05b322339fea4ec78a7e6159ec4e54b591a44699662b5b").into(), - state_root: hex!("0db33febe0d69ec00eeab7961cb3d3e9a16ccc59f1314a5b67d2887be37e624d").into(), - body_root: hex!("cbfb4d27fd2e98f38921914e5e79b357684769b3adfaa17861b423f7f63f37b1").into(), - }, - execution_header: ExecutionPayloadHeader { - parent_hash: hex!("3fe1542912d40d01821fbee41809db8e53a8cbae0d854cb0e5a9d94247fbc031").into(), - fee_recipient: hex!("0000000000000000000000000000000000000000").to_vec().try_into().expect("fee recipient too long"), - state_root: hex!("251f215b8f0bb2caceac8cf469f0bf4daf1d0a8e319b506a02ab4a0362e31083").into(), - receipts_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(), - logs_bloom: hex!("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000").to_vec().try_into().expect("logs bloom too long"), - prev_randao: hex!("821b4a7000256c9927032630785533f5fa4f1a40b6ae95eedf86d5910e18549c").into(), - block_number: 150, - gas_limit: 69094400, - gas_used: 0, - timestamp: 1679133094, - extra_data: hex!("d983010b02846765746888676f312e31392e358664617277696e").into(), - base_fee_per_gas: U256::from(7 as u64), - block_hash: hex!("d84d6e83a9b4783fe4a290edc0d57e218a42aeb4f4c97dc7c83dacf82a1ec5eb").into(), - transactions_root: hex!("7ffe241ea60187fdb0187bfa22de35d1f9bed7ab061d9401fd47e34a54fbede1").into(), - withdrawals_root: hex!("28ba1834a3a7b657460ce79fa3a1d909ab8828fd557659d4d0554a9bdbc0ec30").into(), - }, - execution_branch: vec![ - hex!("577ef1f2f9b33764e9a0d56225a4df5890f3b5ac3dc6fec05db54b65f20a8984").into(), - hex!("336488033fe5f3ef4ccc12af07b9370b92e553e35ecb4a337a1b1c0e4afe1e0e").into(), - hex!("db56114e00fdd4c1f85c892bf35ac9a89289aaecb1ebd0a96cde606a748b5d71").into(), - hex!("1b1451ad43516084cc488a22800d39d3368f0220cbc844957321fdf4dfe8154d").into(), - ], - sync_aggregate: SyncAggregate{ - sync_committee_bits: hex!("ffffffff"), - sync_committee_signature: hex!("b203cba9326023622caad739fe44a50392d85a8bc1cb3f0c64d89319a865dc1dc1d1ff318d939ac24e4866068d8ca442116d4e7badec88015fd2865f97d5d5ab321c6c9a6994a9afee31f03cd015131320324bffc5d18746d232578c321ea61b").into(), - }, - signature_slot: 151, - block_root_branch: vec![ - hex!("c6e5d2ad0e10309dc895c9f3a37b0dcadf95648f036b42d0ef5084252c69f1ed").into(), - hex!("86d3344e6df5f9e3b930fe849e4ef99eca85cf455698db3acff0ab5449f0c383").into(), - hex!("476a0e95a7b8cdef9aa2b8456ad44c46e7d828fd1821dec3dd3f456c21dbd679").into(), - hex!("0fff87fb108fae09e61eafef5bcf22f4a5267699d5624fab371f661cc5e0c938").into(), - hex!("76dd343907582c21ec28320c1d6a10349d338ac8ae4bb6e890063ad7d4ce4a6a").into(), - hex!("7eebb150fd62159c1adf5dbe3e677b9574ea304d752f06de0a9f03f8f0ed6597").into(), - ], - block_root_branch_header_root: hex!("105976df5861b95fa4184564978eac0bcbe872acdd77a0ead552a8b283dabc4f").into(), - }; -} diff --git a/parachain/pallets/ethereum-beacon-client/src/benchmarking/mod.rs b/parachain/pallets/ethereum-beacon-client/src/benchmarking/mod.rs index f66bed959a5ae..59cfe0ef3db45 100644 --- a/parachain/pallets/ethereum-beacon-client/src/benchmarking/mod.rs +++ b/parachain/pallets/ethereum-beacon-client/src/benchmarking/mod.rs @@ -11,7 +11,7 @@ use data_mainnet::*; mod util; use primitives::{ fast_aggregate_verify, fast_aggregate_verify_legacy, prepare_aggregate_pubkey, - prepare_aggregate_signature, Mode, + prepare_aggregate_signature, verify_merkle_branch, Mode, }; use util::*; @@ -19,11 +19,21 @@ benchmarks! { sync_committee_period_update { let caller: T::AccountId = whitelisted_caller(); + let initial_sync_data = initial_sync(); let sync_committee_update = initialize_sync_committee::()?; + let period = EthereumBeaconClient::::compute_current_sync_period(sync_committee_update.attested_header.slot); + + // initialize LatestFinalizedHeaderState with parent slot of finalized_header_update + LatestFinalizedHeader::::set(FinalizedHeaderState { + beacon_block_root: Default::default(), + import_time: initial_sync_data.import_time, + beacon_slot: sync_committee_update.finalized_header.slot - 1, + }); + }: sync_committee_period_update(RawOrigin::Signed(caller.clone()), sync_committee_update.clone()) verify { - EthereumBeaconClient::::sync_committee_for_period(sync_committee_update.sync_committee_period+1).unwrap(); + EthereumBeaconClient::::sync_committee_for_period(period+1).unwrap(); } import_finalized_header { @@ -41,8 +51,8 @@ benchmarks! { EthereumBeaconClient::::store_sync_committee(current_period, &initial_sync_data.current_sync_committee)?; - //initialize LatestFinalizedHeaderState with parent slot of finalized_header_update - LatestFinalizedHeaderState::::set(FinalizedHeaderState { + // initialize LatestFinalizedHeaderState with parent slot of finalized_header_update + LatestFinalizedHeader::::set(FinalizedHeaderState { beacon_block_root: Default::default(), import_time: initial_sync_data.import_time + 51200, beacon_slot: finalized_header_update.finalized_header.slot - 1, @@ -65,7 +75,7 @@ benchmarks! { let header_update = header_update(); let current_period = EthereumBeaconClient::::compute_current_sync_period( - header_update.beacon_header.slot, + header_update.header.slot, ); EthereumBeaconClient::::store_sync_committee(current_period, &initial_sync_data.current_sync_committee)?; @@ -76,7 +86,7 @@ benchmarks! { let finalized_block_root = finalized_update.finalized_header.hash_tree_root() .unwrap(); - LatestFinalizedHeaderState::::set(FinalizedHeaderState{ + LatestFinalizedHeader::::set(FinalizedHeaderState{ beacon_block_root: finalized_block_root, beacon_slot: finalized_slot, import_time: 0, @@ -122,6 +132,14 @@ benchmarks! { }:{ fast_aggregate_verify(¤t_sync_committee.aggregate_pubkey, &absent_pubkeys, signing_root, &update.sync_aggregate.sync_committee_signature).unwrap(); } + + merkle_branch_verify { + let update = initialize_sync_committee::()?; + let block_root: H256 = update.finalized_header.hash_tree_root().unwrap(); + }:{ + verify_merkle_branch(block_root,&update.finality_branch,config::FINALIZED_ROOT_SUBTREE_INDEX, + config::FINALIZED_ROOT_DEPTH,update.attested_header.state_root); + } } impl_benchmark_test_suite!( diff --git a/parachain/pallets/ethereum-beacon-client/src/benchmarking/util.rs b/parachain/pallets/ethereum-beacon-client/src/benchmarking/util.rs index 963c362c523cc..1e0a519f39671 100644 --- a/parachain/pallets/ethereum-beacon-client/src/benchmarking/util.rs +++ b/parachain/pallets/ethereum-beacon-client/src/benchmarking/util.rs @@ -15,7 +15,7 @@ pub fn initialize_sync_committee() -> Result::set(EthereumBeaconClient::::compute_current_sync_period( sync_committee_update.attested_header.slot, )); @@ -69,7 +69,7 @@ pub fn absent_pubkeys( pub fn signing_root(update: &SyncCommitteeUpdate) -> Result { let validators_root = >::get(); let signing_root = EthereumBeaconClient::::signing_root( - update.attested_header, + &update.attested_header, validators_root, update.signature_slot, )?; diff --git a/parachain/pallets/ethereum-beacon-client/src/config/mainnet.rs b/parachain/pallets/ethereum-beacon-client/src/config/mainnet.rs index 9c8f888b7c248..f7b4e60776d0e 100644 --- a/parachain/pallets/ethereum-beacon-client/src/config/mainnet.rs +++ b/parachain/pallets/ethereum-beacon-client/src/config/mainnet.rs @@ -5,4 +5,4 @@ pub const SYNC_COMMITTEE_SIZE: usize = 512; pub const SYNC_COMMITTEE_BITS_SIZE: usize = SYNC_COMMITTEE_SIZE / 8; pub const SLOTS_PER_HISTORICAL_ROOT: usize = 8192; pub const IS_MINIMAL: bool = false; -pub const BLOCK_ROOT_AT_INDEX_PROOF_DEPTH: usize = 13; +pub const BLOCK_ROOT_AT_INDEX_DEPTH: usize = 13; diff --git a/parachain/pallets/ethereum-beacon-client/src/config/minimal.rs b/parachain/pallets/ethereum-beacon-client/src/config/minimal.rs index c2d0819760908..67ff3c44183f3 100644 --- a/parachain/pallets/ethereum-beacon-client/src/config/minimal.rs +++ b/parachain/pallets/ethereum-beacon-client/src/config/minimal.rs @@ -5,4 +5,4 @@ pub const SYNC_COMMITTEE_SIZE: usize = 32; pub const SYNC_COMMITTEE_BITS_SIZE: usize = SYNC_COMMITTEE_SIZE / 8; pub const SLOTS_PER_HISTORICAL_ROOT: usize = 64; pub const IS_MINIMAL: bool = true; -pub const BLOCK_ROOT_AT_INDEX_PROOF_DEPTH: usize = 6; +pub const BLOCK_ROOT_AT_INDEX_DEPTH: usize = 6; diff --git a/parachain/pallets/ethereum-beacon-client/src/config/mod.rs b/parachain/pallets/ethereum-beacon-client/src/config/mod.rs index 281fe14cc6678..a5ec6a20511bf 100644 --- a/parachain/pallets/ethereum-beacon-client/src/config/mod.rs +++ b/parachain/pallets/ethereum-beacon-client/src/config/mod.rs @@ -1,3 +1,4 @@ +use primitives::merkle_proof::{generalized_index_length, subtree_index}; use static_assertions::const_assert; pub mod mainnet; @@ -9,18 +10,33 @@ pub use minimal::*; #[cfg(not(feature = "minimal"))] pub use mainnet::*; -pub const CURRENT_SYNC_COMMITTEE_INDEX: usize = 22; -pub const NEXT_SYNC_COMMITTEE_INDEX: usize = 23; -pub const SYNC_COMMITTEE_DEPTH: usize = 5; - -pub const FINALIZED_ROOT_DEPTH: usize = 6; -pub const FINALIZED_ROOT_INDEX: usize = 41; - -pub const BLOCK_ROOTS_DEPTH: usize = 5; -pub const BLOCK_ROOTS_INDEX: usize = 5; - -pub const EXECUTION_HEADER_DEPTH: usize = 4; -pub const EXECUTION_HEADER_INDEX: usize = 9; +// Generalized Indices + +// get_generalized_index(BeaconState, 'block_roots') +pub const BLOCK_ROOTS_INDEX: usize = 37; +pub const BLOCK_ROOTS_SUBTREE_INDEX: usize = subtree_index(BLOCK_ROOTS_INDEX); +pub const BLOCK_ROOTS_DEPTH: usize = generalized_index_length(BLOCK_ROOTS_INDEX); + +// get_generalized_index(BeaconState, 'finalized_checkpoint', 'root') +pub const FINALIZED_ROOT_INDEX: usize = 105; +pub const FINALIZED_ROOT_SUBTREE_INDEX: usize = subtree_index(FINALIZED_ROOT_INDEX); +pub const FINALIZED_ROOT_DEPTH: usize = generalized_index_length(FINALIZED_ROOT_INDEX); + +// get_generalized_index(BeaconState, 'current_sync_committee') +pub const CURRENT_SYNC_COMMITTEE_INDEX: usize = 54; +pub const CURRENT_SYNC_COMMITTEE_SUBTREE_INDEX: usize = subtree_index(CURRENT_SYNC_COMMITTEE_INDEX); +pub const CURRENT_SYNC_COMMITTEE_DEPTH: usize = + generalized_index_length(CURRENT_SYNC_COMMITTEE_INDEX); + +// get_generalized_index(BeaconState, 'next_sync_committee') +pub const NEXT_SYNC_COMMITTEE_INDEX: usize = 55; +pub const NEXT_SYNC_COMMITTEE_SUBTREE_INDEX: usize = subtree_index(NEXT_SYNC_COMMITTEE_INDEX); +pub const NEXT_SYNC_COMMITTEE_DEPTH: usize = generalized_index_length(NEXT_SYNC_COMMITTEE_INDEX); + +// get_generalized_index(BeaconBlockBody, 'execution_payload') +pub const EXECUTION_HEADER_INDEX: usize = 25; +pub const EXECUTION_HEADER_SUBTREE_INDEX: usize = subtree_index(EXECUTION_HEADER_INDEX); +pub const EXECUTION_HEADER_DEPTH: usize = generalized_index_length(EXECUTION_HEADER_INDEX); pub const MAX_EXTRA_DATA_BYTES: usize = 32; pub const MAX_LOGS_BLOOM_SIZE: usize = 256; diff --git a/parachain/pallets/ethereum-beacon-client/src/lib.rs b/parachain/pallets/ethereum-beacon-client/src/lib.rs index 2809f2a1f0523..3c3daf5b3c449 100644 --- a/parachain/pallets/ethereum-beacon-client/src/lib.rs +++ b/parachain/pallets/ethereum-beacon-client/src/lib.rs @@ -28,9 +28,9 @@ use frame_support::{ }; use frame_system::ensure_signed; use primitives::{ - fast_aggregate_verify, verify_merkle_proof, verify_receipt_proof, BeaconHeader, BlsError, + fast_aggregate_verify, verify_merkle_branch, verify_receipt_proof, BeaconHeader, BlsError, CompactExecutionHeader, ExecutionHeaderState, FinalizedHeaderState, ForkData, ForkVersion, - ForkVersions, Mode, PublicKeyPrepared, Signature, SigningData, + ForkVersions, Mode, PublicKeyPrepared, SigningData, }; use snowbridge_core::{Message, RingBufferMap, RingBufferMapImpl, Verifier}; use sp_core::H256; @@ -46,14 +46,14 @@ pub use pallet::*; pub use config::{SLOTS_PER_HISTORICAL_ROOT, SYNC_COMMITTEE_BITS_SIZE, SYNC_COMMITTEE_SIZE}; pub type CheckpointUpdate = primitives::CheckpointUpdate; -pub type ExecutionHeaderUpdate = - primitives::ExecutionHeaderUpdate; +pub type ExecutionHeaderUpdate = primitives::ExecutionHeaderUpdate; pub type SyncCommitteeUpdate = primitives::SyncCommitteeUpdate; pub type FinalizedHeaderUpdate = primitives::FinalizedHeaderUpdate; pub type SyncCommittee = primitives::SyncCommittee; pub type SyncCommitteePrepared = primitives::SyncCommitteePrepared; +pub type SyncAggregate = primitives::SyncAggregate; fn decompress_sync_committee_bits( input: [u8; SYNC_COMMITTEE_BITS_SIZE], @@ -139,6 +139,7 @@ pub mod pallet { NoBranchExpected, HeaderNotFinalized, MissingHeader, + MissingFinalityHeader, InvalidProof, InvalidBlockRootAtSlot, DecodeFailed, @@ -152,7 +153,6 @@ pub mod pallet { UnexpectedHeaderSlotPosition, ExpectedFinalizedHeaderNotStored, BridgeBlocked, - InvalidSyncCommitteeHeaderUpdate, InvalidSyncCommitteeUpdateWithGap, InvalidSyncCommitteeUpdateWithDuplication, InvalidSignatureSlot, @@ -183,14 +183,17 @@ pub mod pallet { StorageMap<_, Identity, H256, CompactExecutionHeader, OptionQuery>; #[pallet::storage] + #[pallet::getter(fn validators_root)] pub(super) type ValidatorsRoot = StorageValue<_, H256, ValueQuery>; #[pallet::storage] - pub(super) type LatestFinalizedHeaderState = + #[pallet::getter(fn latest_finalized_header)] + pub(super) type LatestFinalizedHeader = StorageValue<_, FinalizedHeaderState, ValueQuery>; #[pallet::storage] - pub(super) type LatestExecutionHeaderState = + #[pallet::getter(fn latest_execution_header)] + pub(super) type LatestExecutionHeader = StorageValue<_, ExecutionHeaderState, ValueQuery>; #[pallet::storage] @@ -224,6 +227,46 @@ pub mod pallet { #[pallet::call] impl Pallet { #[pallet::call_index(0)] + #[pallet::weight(T::WeightInfo::force_mode())] + #[transactional] + pub fn force_mode(origin: OriginFor, mode: Mode) -> DispatchResult { + ensure_root(origin)?; + + match mode { + Mode::Blocked => >::set(true), + Mode::Active => >::set(false), + } + + log::info!(target: "ethereum-beacon-client","💫 syncing bridge from governance provided checkpoint."); + + Ok(()) + } + + #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::force_checkpoint())] + #[transactional] + pub fn force_checkpoint(origin: OriginFor, update: CheckpointUpdate) -> DispatchResult { + ensure_root(origin)?; + + if let Err(err) = Self::process_checkpoint_update(&update) { + log::error!( + target: "ethereum-beacon-client", + "💫 Sync committee period update failed with error {:?}", + err + ); + return Err(err) + } + + log::info!( + target: "ethereum-beacon-client", + "💫 Sync committee period update for slot {} succeeded.", + update.header.slot + ); + + Ok(()) + } + + #[pallet::call_index(2)] #[pallet::weight(T::WeightInfo::sync_committee_period_update())] #[transactional] pub fn sync_committee_period_update( @@ -234,7 +277,8 @@ pub mod pallet { Self::check_bridge_blocked_state()?; - let sync_committee_period = update.sync_committee_period; + let sync_committee_period = + Self::compute_current_sync_period(update.attested_header.slot); log::info!( target: "ethereum-beacon-client", "💫 Received sync committee update for period {}. Applying update", @@ -259,7 +303,7 @@ pub mod pallet { Ok(()) } - #[pallet::call_index(1)] + #[pallet::call_index(3)] #[pallet::weight(T::WeightInfo::import_finalized_header())] #[transactional] pub fn import_finalized_header( @@ -278,7 +322,7 @@ pub mod pallet { slot ); - if let Err(err) = Self::process_finalized_header(finalized_header_update) { + if let Err(err) = Self::process_finalized_header_update(&finalized_header_update) { log::error!( target: "ethereum-beacon-client", "💫 Finalized header update failed with error {:?}", @@ -296,7 +340,7 @@ pub mod pallet { Ok(()) } - #[pallet::call_index(2)] + #[pallet::call_index(4)] #[pallet::weight(T::WeightInfo::import_execution_header())] #[transactional] pub fn import_execution_header( @@ -307,7 +351,7 @@ pub mod pallet { Self::check_bridge_blocked_state()?; - let slot = update.beacon_header.slot; + let slot = update.header.slot; let block_hash = update.execution_header.block_hash; log::info!( @@ -316,7 +360,7 @@ pub mod pallet { slot ); - if let Err(err) = Self::process_header(update) { + if let Err(err) = Self::process_execution_header_update(&update) { log::error!( target: "ethereum-beacon-client", "💫 Header update failed with error {:?}", @@ -334,46 +378,6 @@ pub mod pallet { Ok(()) } - - #[pallet::call_index(3)] - #[pallet::weight(T::WeightInfo::force_mode())] - #[transactional] - pub fn force_mode(origin: OriginFor, mode: Mode) -> DispatchResult { - ensure_root(origin)?; - - match mode { - Mode::Blocked => >::set(true), - Mode::Active => >::set(false), - } - - log::info!(target: "ethereum-beacon-client","💫 syncing bridge from governance provided checkpoint."); - - Ok(()) - } - - #[pallet::call_index(5)] - #[pallet::weight(T::WeightInfo::force_checkpoint())] - #[transactional] - pub fn force_checkpoint(origin: OriginFor, update: CheckpointUpdate) -> DispatchResult { - ensure_root(origin)?; - - if let Err(err) = Self::process_checkpoint_update(&update) { - log::error!( - target: "ethereum-beacon-client", - "💫 Sync committee period update failed with error {:?}", - err - ); - return Err(err) - } - - log::info!( - target: "ethereum-beacon-client", - "💫 Sync committee period update for slot {} succeeded.", - update.header.slot - ); - - Ok(()) - } } impl Pallet { @@ -382,7 +386,8 @@ pub mod pallet { &update.current_sync_committee, &update.current_sync_committee_branch, update.header.state_root, - config::CURRENT_SYNC_COMMITTEE_INDEX, + config::CURRENT_SYNC_COMMITTEE_SUBTREE_INDEX, + config::CURRENT_SYNC_COMMITTEE_DEPTH, )?; let period = Self::compute_current_sync_period(update.header.slot); @@ -400,31 +405,24 @@ pub mod pallet { } fn process_sync_committee_period_update(update: &SyncCommitteeUpdate) -> DispatchResult { - ensure!( - update.signature_slot > update.attested_header.slot && - update.attested_header.slot >= update.finalized_header.slot, - Error::::InvalidSyncCommitteeHeaderUpdate - ); - let participation = - decompress_sync_committee_bits(update.sync_aggregate.sync_committee_bits); - Self::sync_committee_participation_is_supermajority(&participation)?; + Self::verify_weak_subjectivity()?; + Self::verify_attested_header( + &update.attested_header, + &update.sync_aggregate, + update.signature_slot, + )?; + let finalized_block_root = Self::verify_finalized_header( + &update.attested_header, + &update.finalized_header, + &update.finality_branch, + )?; + Self::verify_sync_committee( &update.next_sync_committee, &update.next_sync_committee_branch, update.attested_header.state_root, - config::NEXT_SYNC_COMMITTEE_INDEX, - )?; - - let block_root: H256 = update - .finalized_header - .hash_tree_root() - .map_err(|_| Error::::HeaderHashTreeRootFailed)?; - - Self::verify_header( - block_root, - &update.finality_branch, - update.attested_header.state_root, - config::FINALIZED_ROOT_INDEX, + config::NEXT_SYNC_COMMITTEE_SUBTREE_INDEX, + config::NEXT_SYNC_COMMITTEE_DEPTH, )?; let current_period = Self::compute_current_sync_period(update.attested_header.slot); @@ -446,85 +444,44 @@ pub mod pallet { Error::::InvalidSyncCommitteeUpdateWithGap ); - let validators_root = >::get(); - let sync_committee = Self::sync_committee_for_period(current_period)?; - Self::verify_signed_header( - &participation, - &update.sync_aggregate.sync_committee_signature, - &sync_committee, - update.attested_header, - validators_root, - update.signature_slot, - )?; ensure!( - update.block_roots_branch.len() == config::BLOCK_ROOTS_DEPTH && - verify_merkle_proof( - update.block_roots_root, - &update.block_roots_branch, - config::BLOCK_ROOTS_INDEX, - update.finalized_header.state_root - ), + verify_merkle_branch( + update.block_roots_root, + &update.block_roots_branch, + config::BLOCK_ROOTS_SUBTREE_INDEX, + config::BLOCK_ROOTS_DEPTH, + update.finalized_header.state_root + ) + .is_some_and(|x| x), Error::::InvalidAncestryMerkleProof ); - Self::store_block_root(update.block_roots_root, block_root); + Self::store_block_root(update.block_roots_root, finalized_block_root); Self::store_sync_committee(next_period, &update.next_sync_committee)?; - Self::store_finalized_header(block_root, update.finalized_header, None)?; + Self::store_finalized_header(finalized_block_root, update.finalized_header, None)?; Ok(()) } - fn process_finalized_header(update: FinalizedHeaderUpdate) -> DispatchResult { - let last_finalized_header = >::get(); - ensure!( - update.signature_slot > update.attested_header.slot, - Error::::InvalidSignatureSlot - ); - ensure!( - update.attested_header.slot >= update.finalized_header.slot, - Error::::InvalidAttestedHeaderSlot - ); + fn process_finalized_header_update(update: &FinalizedHeaderUpdate) -> DispatchResult { + Self::verify_weak_subjectivity()?; + Self::verify_attested_header( + &update.attested_header, + &update.sync_aggregate, + update.signature_slot, + )?; ensure!( - update.finalized_header.slot > last_finalized_header.beacon_slot, + update.finalized_header.slot > Self::latest_finalized_header().beacon_slot, Error::::DuplicateFinalizedHeaderUpdate ); - - let import_time = last_finalized_header.import_time; - let weak_subjectivity_period_check = - import_time + T::WeakSubjectivityPeriodSeconds::get(); - let time: u64 = T::TimeProvider::now().as_secs(); - - log::info!( - target: "ethereum-beacon-client", - "💫 Checking weak subjectivity period. Current time is :{:?} Weak subjectivity period check: {:?}.", - time, - weak_subjectivity_period_check - ); - - if time > weak_subjectivity_period_check { - log::info!(target: "ethereum-beacon-client","💫 Weak subjectivity period exceeded, blocking bridge.",); - >::set(true); - return Err(Error::::BridgeBlocked.into()) - } - - let participation = - decompress_sync_committee_bits(update.sync_aggregate.sync_committee_bits); - Self::sync_committee_participation_is_supermajority(&participation)?; - - let block_root: H256 = update - .finalized_header - .hash_tree_root() - .map_err(|_| Error::::HeaderHashTreeRootFailed)?; - - Self::verify_header( - block_root, + let finalized_block_root = Self::verify_finalized_header( + &update.attested_header, + &update.finalized_header, &update.finality_branch, - update.attested_header.state_root, - config::FINALIZED_ROOT_INDEX, )?; let last_finalized_period = - Self::compute_current_sync_period(last_finalized_header.beacon_slot); + Self::compute_current_sync_period(Self::latest_finalized_header().beacon_slot); let current_period = Self::compute_current_sync_period(update.attested_header.slot); ensure!( (current_period == last_finalized_period || @@ -532,31 +489,20 @@ pub mod pallet { Error::::InvalidFinalizedPeriodUpdate ); - let validators_root = >::get(); - let sync_committee = Self::sync_committee_for_period(current_period)?; - Self::verify_signed_header( - &participation, - &update.sync_aggregate.sync_committee_signature, - &sync_committee, - update.attested_header, - validators_root, - update.signature_slot, - )?; - ensure!( - update.block_roots_branch.len() == config::BLOCK_ROOTS_DEPTH && - verify_merkle_proof( - update.block_roots_root, - &update.block_roots_branch, - config::BLOCK_ROOTS_INDEX, - update.finalized_header.state_root - ), + verify_merkle_branch( + update.block_roots_root, + &update.block_roots_branch, + config::BLOCK_ROOTS_SUBTREE_INDEX, + config::BLOCK_ROOTS_DEPTH, + update.finalized_header.state_root + ) + .is_some_and(|x| x), Error::::InvalidAncestryMerkleProof ); - Self::store_block_root(update.block_roots_root, block_root); - - Self::store_finalized_header(block_root, update.finalized_header, None)?; + Self::store_block_root(update.block_roots_root, finalized_block_root); + Self::store_finalized_header(finalized_block_root, update.finalized_header, None)?; Ok(()) } @@ -568,74 +514,58 @@ pub mod pallet { ); } - fn process_header(update: ExecutionHeaderUpdate) -> DispatchResult { - let last_finalized_header = >::get(); - let latest_finalized_header_slot = last_finalized_header.beacon_slot; - let block_slot = update.beacon_header.slot; - ensure!(block_slot <= latest_finalized_header_slot, Error::::HeaderNotFinalized); + fn process_execution_header_update(update: &ExecutionHeaderUpdate) -> DispatchResult { + ensure!( + update.header.slot <= Self::latest_finalized_header().beacon_slot, + Error::::HeaderNotFinalized + ); - let execution_header_state = >::get(); ensure!( - update.execution_header.block_number > execution_header_state.block_number, + update.execution_header.block_number > Self::latest_execution_header().block_number, Error::::InvalidExecutionHeaderUpdate ); - let execution_root: H256 = update + let execution_header_root: H256 = update .execution_header .hash_tree_root() .map_err(|_| Error::::BlockBodyHashTreeRootFailed)?; ensure!( - update.execution_branch.len() == config::EXECUTION_HEADER_DEPTH && - verify_merkle_proof( - execution_root, - &update.execution_branch, - config::EXECUTION_HEADER_INDEX, - update.beacon_header.body_root - ), + verify_merkle_branch( + execution_header_root, + &update.execution_branch, + config::EXECUTION_HEADER_SUBTREE_INDEX, + config::EXECUTION_HEADER_DEPTH, + update.header.body_root + ) + .is_some_and(|x| x), Error::::InvalidExecutionHeaderProof ); - let beacon_block_root: H256 = update - .beacon_header + let header_root: H256 = update + .header .hash_tree_root() .map_err(|_| Error::::HeaderHashTreeRootFailed)?; Self::ancestry_proof( - update.block_root_branch, - block_slot, - beacon_block_root, - update.block_root_branch_header_root, - )?; - - let current_period = Self::compute_current_sync_period(update.beacon_header.slot); - let sync_committee = Self::sync_committee_for_period(current_period)?; - - let validators_root = >::get(); - let participation = - decompress_sync_committee_bits(update.sync_aggregate.sync_committee_bits); - - Self::verify_signed_header( - &participation, - &update.sync_aggregate.sync_committee_signature, - &sync_committee, - update.beacon_header, - validators_root, - update.signature_slot, + &update.block_roots_branch, + update.header.slot, + header_root, + update.block_roots_root, )?; Self::store_execution_header( update.execution_header.block_hash, - update.execution_header.into(), - block_slot, - beacon_block_root, + update.execution_header.clone().into(), + update.header.slot, + header_root, ); Ok(()) } fn ancestry_proof( - block_root_proof: Vec, + block_root_proof: &[H256], block_slot: u64, beacon_block_root: H256, finalized_header_root: H256, @@ -681,17 +611,18 @@ pub mod pallet { log::info!( target: "ethereum-beacon-client", - "💫 Depth: {} leaf_index: {}", config::BLOCK_ROOT_AT_INDEX_PROOF_DEPTH, leaf_index + "💫 Depth: {} leaf_index: {}", config::BLOCK_ROOT_AT_INDEX_DEPTH, leaf_index ); ensure!( - block_root_proof.len() == config::BLOCK_ROOT_AT_INDEX_PROOF_DEPTH && - verify_merkle_proof( - beacon_block_root, - &block_root_proof, - leaf_index, - finalized_block_root_hash - ), + verify_merkle_branch( + beacon_block_root, + &block_root_proof, + leaf_index, + config::BLOCK_ROOT_AT_INDEX_DEPTH, + finalized_block_root_hash + ) + .is_some_and(|x| x), Error::::InvalidAncestryMerkleProof ); @@ -706,39 +637,93 @@ pub mod pallet { Ok(()) } - pub(super) fn verify_signed_header( - sync_committee_bits: &[u8], - sync_committee_signature: &Signature, - sync_committee: &SyncCommitteePrepared, - header: BeaconHeader, - validators_root: H256, + // Weak subjectivity check + pub(super) fn verify_weak_subjectivity() -> DispatchResult { + let import_time = Self::latest_finalized_header().import_time; + let weak_subjectivity_period_check = + import_time + T::WeakSubjectivityPeriodSeconds::get(); + let time: u64 = T::TimeProvider::now().as_secs(); + log::info!( + target: "ethereum-beacon-client", + "💫 Checking weak subjectivity period. Current time is :{:?} Weak subjectivity period check: {:?}.", + time, + weak_subjectivity_period_check + ); + if time > weak_subjectivity_period_check { + log::info!(target: "ethereum-beacon-client","💫 Weak subjectivity period exceeded, blocking bridge.",); + >::set(true); + // FIXME: reverting the transaction will revert the state change! + return Err(Error::::BridgeBlocked.into()) + } + + Ok(()) + } + + /// Verify that a supermajority of the sync committee signed the attested beacon header + pub(super) fn verify_attested_header( + attested_header: &BeaconHeader, + sync_aggregate: &SyncAggregate, signature_slot: u64, ) -> DispatchResult { - // Gathers milagro pubkeys absent to participate - let absent_pubkeys = - Self::find_pubkeys(sync_committee_bits, &sync_committee.pubkeys, false); + // Verify sync committee has sufficient participants + let participation = decompress_sync_committee_bits(sync_aggregate.sync_committee_bits); + Self::sync_committee_participation_is_supermajority(&participation)?; - // Get signing root for BeaconHeader - let signing_root = Self::signing_root(header, validators_root, signature_slot)?; + // Verify update does not skip a sync committee period + ensure!(signature_slot > attested_header.slot, Error::::InvalidSignatureSlot); - // Verify sync committee aggregate signature. + // Verify sync committee aggregate signature + let current_period = Self::compute_current_sync_period(attested_header.slot); + let sync_committee = Self::sync_committee_for_period(current_period)?; + let absent_pubkeys = Self::find_pubkeys(&participation, &sync_committee.pubkeys, false); + let signing_root = + Self::signing_root(attested_header, Self::validators_root(), signature_slot)?; fast_aggregate_verify( &sync_committee.aggregate_pubkey, &absent_pubkeys, signing_root, - sync_committee_signature, + &sync_aggregate.sync_committee_signature, ) .map_err(|e| Error::::BLSVerificationFailed(e))?; Ok(()) } + pub(super) fn verify_finalized_header( + attested_header: &BeaconHeader, + finalized_header: &BeaconHeader, + finality_branch: &[H256], + ) -> Result { + ensure!( + attested_header.slot >= finalized_header.slot, + Error::::InvalidAttestedHeaderSlot + ); + + let finalized_block_root: H256 = finalized_header + .hash_tree_root() + .map_err(|_| Error::::HeaderHashTreeRootFailed)?; + + ensure!( + verify_merkle_branch( + finalized_block_root, + finality_branch, + config::FINALIZED_ROOT_SUBTREE_INDEX, + config::FINALIZED_ROOT_DEPTH, + attested_header.state_root + ) + .is_some_and(|x| x), + Error::::InvalidHeaderMerkleProof + ); + + Ok(finalized_block_root) + } + pub(super) fn compute_epoch_at_slot(signature_slot: u64, slots_per_epoch: u64) -> u64 { signature_slot / slots_per_epoch } pub(super) fn compute_signing_root( - beacon_header: BeaconHeader, + beacon_header: &BeaconHeader, domain: H256, ) -> Result { let beacon_header_root = beacon_header @@ -757,44 +742,27 @@ pub mod pallet { sync_committee_branch: &[H256], header_state_root: H256, index: usize, + depth: usize, ) -> DispatchResult { let sync_committee_root = sync_committee .hash_tree_root() .map_err(|_| Error::::SyncCommitteeHashTreeRootFailed)?; ensure!( - sync_committee_branch.len() == config::SYNC_COMMITTEE_DEPTH && - verify_merkle_proof( - sync_committee_root, - sync_committee_branch, - index, - header_state_root - ), + verify_merkle_branch( + sync_committee_root, + sync_committee_branch, + index, + depth, + header_state_root + ) + .is_some_and(|x| x), Error::::InvalidSyncCommitteeMerkleProof ); Ok(()) } - fn verify_header( - block_root: H256, - proof_branch: &[H256], - attested_header_state_root: H256, - index: usize, - ) -> DispatchResult { - ensure!( - proof_branch.len() == config::FINALIZED_ROOT_DEPTH && - verify_merkle_proof( - block_root, - proof_branch, - index, - attested_header_state_root - ), - Error::::InvalidHeaderMerkleProof - ); - Ok(()) - } - pub(crate) fn store_sync_committee( period: u64, sync_committee: &SyncCommittee, @@ -830,7 +798,7 @@ pub mod pallet { }; >::insert(block_root, header); - LatestFinalizedHeaderState::::set(finalized_header); + LatestFinalizedHeader::::set(finalized_header); Self::add_finalized_header_state(finalized_header)?; log::info!( @@ -880,7 +848,7 @@ pub mod pallet { block_number ); - LatestExecutionHeaderState::::mutate(|s| { + LatestExecutionHeader::::mutate(|s| { s.beacon_block_root = beacon_block_root; s.beacon_slot = beacon_slot; s.block_hash = block_hash; @@ -1012,7 +980,7 @@ pub mod pallet { // Calculate signing root for BeaconHeader pub fn signing_root( - header: BeaconHeader, + header: &BeaconHeader, validators_root: H256, signature_slot: u64, ) -> Result { diff --git a/parachain/pallets/ethereum-beacon-client/src/mock.rs b/parachain/pallets/ethereum-beacon-client/src/mock.rs index 50841bff3b9bf..61213718c081a 100644 --- a/parachain/pallets/ethereum-beacon-client/src/mock.rs +++ b/parachain/pallets/ethereum-beacon-client/src/mock.rs @@ -263,12 +263,7 @@ fn finalized_header_update_from_file< serde_json::from_reader(File::open(&filepath).unwrap()).unwrap() } -fn header_update_from_file< - const SYNC_COMMITTEE_SIZE: usize, - const SYNC_COMMITTEE_BITS_SIZE: usize, ->( - name: &str, -) -> primitives::ExecutionHeaderUpdate { +fn header_update_from_file(name: &str) -> primitives::ExecutionHeaderUpdate { let filepath = fixture_path(name); serde_json::from_reader(File::open(&filepath).unwrap()).unwrap() } @@ -311,13 +306,8 @@ pub fn get_committee_sync_ssz_test_data( sync_committee_from_file::(filename.as_str()) } -pub fn get_header_update< - const SYNC_COMMITTEE_SIZE: usize, - const SYNC_COMMITTEE_BITS_SIZE: usize, ->() -> primitives::ExecutionHeaderUpdate { - header_update_from_file::(&add_file_prefix( - "header_update.json", - )) +pub fn get_header_update() -> primitives::ExecutionHeaderUpdate { + header_update_from_file(&add_file_prefix("header_update.json")) } pub fn get_finalized_header_update< diff --git a/parachain/pallets/ethereum-beacon-client/src/tests.rs b/parachain/pallets/ethereum-beacon-client/src/tests.rs index b1725ef934976..bfe8d70d54d56 100644 --- a/parachain/pallets/ethereum-beacon-client/src/tests.rs +++ b/parachain/pallets/ethereum-beacon-client/src/tests.rs @@ -4,7 +4,7 @@ use crate::{ ExecutionHeaders, FinalizedBeaconHeaderStates, FinalizedBeaconHeaders, FinalizedBeaconHeadersBlockRoot, SyncCommittees, }, - verify_merkle_proof, BeaconHeader, Error, H256, SYNC_COMMITTEE_SIZE, + verify_merkle_branch, BeaconHeader, Error, H256, SYNC_COMMITTEE_SIZE, }; use frame_support::{assert_err, assert_ok}; use hex_literal::hex; @@ -75,7 +75,7 @@ pub fn test_compute_domain_kiln() { pub fn test_compute_signing_root_bls() { new_tester::().execute_with(|| { let signing_root = mock_minimal::EthereumBeaconClient::compute_signing_root( - BeaconHeader { + &BeaconHeader { slot: 3529537, proposer_index: 192549, parent_root: hex!( @@ -104,7 +104,7 @@ pub fn test_compute_signing_root_bls() { pub fn test_compute_signing_root_kiln() { new_tester::().execute_with(|| { let signing_root = mock_minimal::EthereumBeaconClient::compute_signing_root( - BeaconHeader { + &BeaconHeader { slot: 221316, proposer_index: 79088, parent_root: hex!( @@ -133,7 +133,7 @@ pub fn test_compute_signing_root_kiln() { pub fn test_compute_signing_root_kiln_head_update() { new_tester::().execute_with(|| { let signing_root = mock_minimal::EthereumBeaconClient::compute_signing_root( - BeaconHeader { + &BeaconHeader { slot: 222472, proposer_index: 10726, parent_root: hex!( @@ -179,7 +179,7 @@ pub fn test_compute_domain_bls() { pub fn test_is_valid_merkle_proof() { new_tester::().execute_with(|| { assert_eq!( - verify_merkle_proof( + verify_merkle_branch( hex!("0000000000000000000000000000000000000000000000000000000000000000").into(), &[ hex!("0000000000000000000000000000000000000000000000000000000000000000").into(), @@ -189,9 +189,11 @@ pub fn test_is_valid_merkle_proof() { hex!("d2dc4ba9fd4edff6716984136831e70a6b2e74fca27b8097a820cbbaa5a6e3c3").into(), hex!("91f77a19d8afa4a08e81164bb2e570ecd10477b3b65c305566a6d2be88510584").into(), ], - 41, + crate::config::FINALIZED_ROOT_INDEX, + crate::config::FINALIZED_ROOT_DEPTH, hex!("e46559327592741956f6beaa0f52e49625eb85dce037a0bd2eff333c743b287f").into() - ), + ) + .is_some_and(|x| x), true ); }); @@ -201,16 +203,18 @@ pub fn test_is_valid_merkle_proof() { pub fn test_merkle_proof_fails_if_depth_and_branch_dont_match() { new_tester::().execute_with(|| { assert_eq!( - verify_merkle_proof( + verify_merkle_branch( hex!("0000000000000000000000000000000000000000000000000000000000000000").into(), &[ hex!("0000000000000000000000000000000000000000000000000000000000000000").into(), hex!("5f6f02af29218292d21a69b64a794a7c0873b3e0f54611972863706e8cbdf371").into(), hex!("e7125ff9ab5a840c44bedb4731f440a405b44e15f2d1a89e27341b432fabe13d").into(), ], - 41, + crate::config::FINALIZED_ROOT_INDEX, + crate::config::FINALIZED_ROOT_DEPTH, hex!("e46559327592741956f6beaa0f52e49625eb85dce037a0bd2eff333c743b287f").into() - ), + ) + .is_some_and(|x| x), false ); }); diff --git a/parachain/pallets/ethereum-beacon-client/src/tests_mainnet.rs b/parachain/pallets/ethereum-beacon-client/src/tests_mainnet.rs index 5fb845e2a75e6..0ac9c592d9c5a 100644 --- a/parachain/pallets/ethereum-beacon-client/src/tests_mainnet.rs +++ b/parachain/pallets/ethereum-beacon-client/src/tests_mainnet.rs @@ -4,7 +4,7 @@ use crate::{ config::{SYNC_COMMITTEE_BITS_SIZE, SYNC_COMMITTEE_SIZE}, mock::*, Error, ExecutionHeaders, FinalizedBeaconHeaders, FinalizedBeaconHeadersBlockRoot, - FinalizedHeaderState, LatestFinalizedHeaderState, LatestSyncCommitteePeriod, ValidatorsRoot, + FinalizedHeaderState, LatestFinalizedHeader, LatestSyncCommitteePeriod, ValidatorsRoot, }; use frame_support::{assert_err, assert_ok}; use hex_literal::hex; @@ -74,7 +74,7 @@ fn it_processes_a_finalized_header_update() { current_period, ¤t_sync_committee, )); - LatestFinalizedHeaderState::::set(FinalizedHeaderState { + LatestFinalizedHeader::::set(FinalizedHeaderState { beacon_block_root: Default::default(), import_time, beacon_slot: slot - 1, @@ -111,7 +111,7 @@ fn it_errors_when_weak_subjectivity_period_exceeded_for_a_finalized_header_updat current_period, ¤t_sync_committee, )); - LatestFinalizedHeaderState::::set(FinalizedHeaderState { + LatestFinalizedHeader::::set(FinalizedHeaderState { beacon_block_root: Default::default(), import_time, beacon_slot: slot - 1, @@ -130,11 +130,11 @@ fn it_errors_when_weak_subjectivity_period_exceeded_for_a_finalized_header_updat #[test] fn it_processes_a_header_update() { - let update = get_header_update::(); + let update = get_header_update(); let current_sync_committee = get_initial_sync::<{ config::SYNC_COMMITTEE_SIZE }>().current_sync_committee; let current_period = - mock_mainnet::EthereumBeaconClient::compute_current_sync_period(update.beacon_header.slot); + mock_mainnet::EthereumBeaconClient::compute_current_sync_period(update.header.slot); let finalized_update = get_finalized_header_update::(); @@ -147,7 +147,7 @@ fn it_processes_a_header_update() { ¤t_sync_committee, )); ValidatorsRoot::::set(get_validators_root::()); - LatestFinalizedHeaderState::::set(FinalizedHeaderState { + LatestFinalizedHeader::::set(FinalizedHeaderState { beacon_block_root: finalized_block_root, beacon_slot: finalized_slot, import_time: 0, @@ -197,7 +197,7 @@ pub fn test_bls_fast_aggregate_verify() { mock_mainnet::EthereumBeaconClient::find_pubkeys(&participant_bits, &milagro_pubkeys, true); let signing_root = mock_mainnet::EthereumBeaconClient::signing_root( - test_data.header, + &test_data.header, test_data.validators_root, test_data.signature_slot, ) diff --git a/parachain/pallets/ethereum-beacon-client/src/tests_minimal.rs b/parachain/pallets/ethereum-beacon-client/src/tests_minimal.rs index 5c64af440f69d..8ea54a9939683 100644 --- a/parachain/pallets/ethereum-beacon-client/src/tests_minimal.rs +++ b/parachain/pallets/ethereum-beacon-client/src/tests_minimal.rs @@ -4,7 +4,7 @@ use crate::{ mock::*, pallet::FinalizedBeaconHeadersBlockRoot, Error, ExecutionHeaderState, ExecutionHeaders, FinalizedBeaconHeaders, FinalizedHeaderState, - LatestExecutionHeaderState, LatestFinalizedHeaderState, ValidatorsRoot, + LatestExecutionHeader, LatestFinalizedHeader, ValidatorsRoot, }; use frame_support::{assert_err, assert_ok}; use hex_literal::hex; @@ -58,7 +58,7 @@ fn it_updates_a_committee_period_sync_update() { } #[test] -fn it_updates_a_committee_period_sync_update_with_invalid_header() { +fn it_updates_a_committee_period_sync_update_with_invalid_signature_slot() { let initial_sync = get_initial_sync::(); let mut update = @@ -75,7 +75,7 @@ fn it_updates_a_committee_period_sync_update_with_invalid_header() { mock_minimal::RuntimeOrigin::signed(1), update.clone(), ), - Error::::InvalidSyncCommitteeHeaderUpdate + Error::::InvalidSignatureSlot ); }); } @@ -164,7 +164,7 @@ fn it_processes_a_finalized_header_update() { new_tester::().execute_with(|| { mock_minimal::Timestamp::set_timestamp(mock_pallet_time * 1000); // needs to be in milliseconds - LatestFinalizedHeaderState::::set(FinalizedHeaderState { + LatestFinalizedHeader::::set(FinalizedHeaderState { beacon_block_root: Default::default(), import_time, // set the last imported finalized header to an older finalized header. Necessary @@ -191,10 +191,13 @@ fn it_processes_a_finalized_header_update() { #[test] fn it_processes_a_invalid_finalized_header_update() { + let initial_sync = get_initial_sync::(); let update = get_finalized_header_update::(); new_tester::().execute_with(|| { - LatestFinalizedHeaderState::::set(FinalizedHeaderState { + assert_ok!(mock_minimal::EthereumBeaconClient::process_checkpoint_update(&initial_sync)); + + LatestFinalizedHeader::::set(FinalizedHeaderState { beacon_block_root: Default::default(), import_time: 0, // initialize with the same slot as the next updating @@ -207,7 +210,7 @@ fn it_processes_a_invalid_finalized_header_update() { mock_minimal::RuntimeOrigin::signed(1), update.clone() ), - Error::::DuplicateFinalizedHeaderUpdate + Error::::SyncCommitteeMissing ); }); } @@ -241,7 +244,7 @@ fn it_processes_a_invalid_finalized_header_update_with_period_gap() { #[test] fn it_processes_a_header_update() { - let update = get_header_update::(); + let update = get_header_update(); let current_sync_committee = get_initial_sync::().current_sync_committee; @@ -251,11 +254,11 @@ fn it_processes_a_header_update() { let finalized_block_root: H256 = finalized_update.finalized_header.hash_tree_root().unwrap(); let current_period = - mock_minimal::EthereumBeaconClient::compute_current_sync_period(update.beacon_header.slot); + mock_minimal::EthereumBeaconClient::compute_current_sync_period(update.header.slot); new_tester::().execute_with(|| { ValidatorsRoot::::set(get_validators_root::()); - LatestFinalizedHeaderState::::set(FinalizedHeaderState { + LatestFinalizedHeader::::set(FinalizedHeaderState { beacon_block_root: finalized_block_root, beacon_slot: finalized_slot, import_time: 0, @@ -282,16 +285,26 @@ fn it_processes_a_header_update() { #[test] fn it_processes_a_invalid_header_update_not_finalized() { - let update = get_header_update::(); + let initial_sync = get_initial_sync::(); + let update = get_header_update(); + let current_period = + mock_minimal::EthereumBeaconClient::compute_current_sync_period(update.header.slot); new_tester::().execute_with(|| { - LatestFinalizedHeaderState::::set(FinalizedHeaderState { + assert_ok!(mock_minimal::EthereumBeaconClient::process_checkpoint_update(&initial_sync)); + + LatestFinalizedHeader::::set(FinalizedHeaderState { beacon_block_root: H256::default(), // initialize finalized state with parent slot of the next update - beacon_slot: update.beacon_header.slot - 1, + beacon_slot: update.header.slot - 1, import_time: 0, }); + assert_ok!(mock_minimal::EthereumBeaconClient::store_sync_committee( + current_period, + &initial_sync.current_sync_committee, + )); + assert_err!( mock_minimal::EthereumBeaconClient::import_execution_header( mock_minimal::RuntimeOrigin::signed(1), @@ -304,16 +317,26 @@ fn it_processes_a_invalid_header_update_not_finalized() { #[test] fn it_processes_a_invalid_header_update_with_duplicate_entry() { - let update = get_header_update::(); + let initial_sync = get_initial_sync::(); + let update = get_header_update(); + let current_period = + mock_minimal::EthereumBeaconClient::compute_current_sync_period(update.header.slot); new_tester::().execute_with(|| { - LatestFinalizedHeaderState::::set(FinalizedHeaderState { + assert_ok!(mock_minimal::EthereumBeaconClient::process_checkpoint_update(&initial_sync)); + + LatestFinalizedHeader::::set(FinalizedHeaderState { beacon_block_root: H256::default(), - beacon_slot: update.beacon_header.slot, + beacon_slot: update.header.slot, import_time: 0, }); - LatestExecutionHeaderState::::set(ExecutionHeaderState { + assert_ok!(mock_minimal::EthereumBeaconClient::store_sync_committee( + current_period, + &initial_sync.current_sync_committee, + )); + + LatestExecutionHeader::::set(ExecutionHeaderState { beacon_block_root: Default::default(), beacon_slot: 0, block_hash: Default::default(), @@ -340,7 +363,7 @@ fn it_errors_when_importing_a_header_with_no_sync_committee_for_period() { hex!("99b09fcd43e5905236c370f184056bec6e6638cfc31a323b304fc4aa789cb4ad").into(), ); - LatestFinalizedHeaderState::::set(FinalizedHeaderState { + LatestFinalizedHeader::::set(FinalizedHeaderState { beacon_block_root: H256::default(), beacon_slot: update.finalized_header.slot - 1, import_time: 0, @@ -385,7 +408,7 @@ pub fn test_bls_fast_aggregate_verify() { mock_minimal::EthereumBeaconClient::find_pubkeys(&participant_bits, &milagro_pubkeys, true); let signing_root = mock_minimal::EthereumBeaconClient::signing_root( - test_data.header, + &test_data.header, test_data.validators_root, test_data.signature_slot, ) diff --git a/parachain/pallets/ethereum-beacon-client/src/weights.rs b/parachain/pallets/ethereum-beacon-client/src/weights.rs index 36683ef3d9621..b3cab16f498aa 100644 --- a/parachain/pallets/ethereum-beacon-client/src/weights.rs +++ b/parachain/pallets/ethereum-beacon-client/src/weights.rs @@ -41,6 +41,7 @@ pub trait WeightInfo { fn bls_fast_aggregate_verify_pre_aggregated() -> Weight; fn bls_fast_aggregate_verify() -> Weight; fn bls_fast_aggregate_verify_legacy() -> Weight; + fn merkle_branch_verify() -> Weight; } // For backwards compatibility and tests @@ -81,4 +82,9 @@ impl WeightInfo for () { Weight::from_parts(123_459_134_000, 0) .saturating_add(Weight::from_parts(0, 0)) } + + fn merkle_branch_verify() -> Weight { + Weight::from_parts(12_368_043_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } } diff --git a/parachain/pallets/ethereum-beacon-client/tests/fixtures/mainnet_header_update.json b/parachain/pallets/ethereum-beacon-client/tests/fixtures/mainnet_header_update.json index 8194a69fb4f44..a7d4668f75c6a 100755 --- a/parachain/pallets/ethereum-beacon-client/tests/fixtures/mainnet_header_update.json +++ b/parachain/pallets/ethereum-beacon-client/tests/fixtures/mainnet_header_update.json @@ -1,5 +1,5 @@ { - "beacon_header": { + "header": { "slot": 5217982, "proposer_index": 320636, "parent_root": "0xa4571a17210f45c48e1cf7732817d5a38c18f5d4c5642845978ed47ea7129ce9", @@ -29,12 +29,7 @@ "0xdb56114e00fdd4c1f85c892bf35ac9a89289aaecb1ebd0a96cde606a748b5d71", "0x6fcc83169ef7b54eb9af29f63890644ac3fd1bffeb6edee8945bb13d9df802e9" ], - "sync_aggregate": { - "sync_committee_bits": "0xff7ffefdbfffbff7edffd5b4fffffd39ff4c7f77dff6dfcdefa17ffdffff3bffded9fdbd7fff9ddfe7bf5dfeafb7feff7fe3e1fffbffefef77bfdfa7f7ddffb3", - "sync_committee_signature": "0x9642b8a94e17eff18c50b1e0603e062fd7637e121d34a4a91e5ad48a9b8076497909de6c9c8e61980a5b33fa6f412d9519bb6f710f0144dfddd01eb36b18e9109ff7cdabc40752d15da22371214189320bc7588090ce4bfafeaee84972f4c7cf" - }, - "signature_slot": 5217983, - "block_root_branch": [ + "block_roots_branch": [ "0x8406114752f4b0df307983b3d233e56b81822dcfcf37a04d31c03062582047a4", "0x7d1e19255fd12ccb31eff0832762c57cc6fcfe635191cb4afa9f1640b592e64f", "0x8de2db9fecd1827ab497b96968e1a880667aba9b55f73a76e5b16810fdbfd392", @@ -49,5 +44,5 @@ "0xf3b04813e6897bb1642c1c42f1edfdaf8b00b2b1b57d567e512dc1c5d51660db", "0x8795c1259089af496aa6339978f58f2fe25f89225dc97dd82dd0c3739fe94d10" ], - "block_root_branch_header_root": "0x52c9f5ef64da062dee00a30ebe16710a3ffe59cf91eedf96a69ae5d198d7d982" + "block_roots_root": "0x52c9f5ef64da062dee00a30ebe16710a3ffe59cf91eedf96a69ae5d198d7d982" } diff --git a/parachain/pallets/ethereum-beacon-client/tests/fixtures/mainnet_sync_committee_update.json b/parachain/pallets/ethereum-beacon-client/tests/fixtures/mainnet_sync_committee_update.json index 865a370c22973..aa7c67cd61f03 100755 --- a/parachain/pallets/ethereum-beacon-client/tests/fixtures/mainnet_sync_committee_update.json +++ b/parachain/pallets/ethereum-beacon-client/tests/fixtures/mainnet_sync_committee_update.json @@ -549,7 +549,6 @@ "sync_committee_bits": "0xff7ffffdbffffff7edffd5f4fffffd79ffce7ff7dff6ffcdefb9fffdffff3bffdedbffbf7fff9fdfe7bf5dfebfbffeffffe7e1fffbfeefeb77bfdfa7ffddffbb", "sync_committee_signature": "0xa58417f897521dc58fa339c9465b1346a7005251ad582fafae984918606005b23627eface374912c70e4ed28c4358eca03783419e3625ab1159b9562837581c6647fc960a6a7d54b0a811b1d5af853ee8274d9023a195f14530d46b8f6af07c2" }, - "sync_committee_period": 636, "signature_slot": 5217992, "block_roots_root": "0xf46cd66ac816b7b890d37832c0a2fa8b56984edd7266926be26dbecf6bd93f62", "block_roots_branch": [ diff --git a/parachain/pallets/ethereum-beacon-client/tests/fixtures/minimal_finalized_header_update.json b/parachain/pallets/ethereum-beacon-client/tests/fixtures/minimal_finalized_header_update.json index 451cbce8dfbb5..1b182eb8138e0 100644 --- a/parachain/pallets/ethereum-beacon-client/tests/fixtures/minimal_finalized_header_update.json +++ b/parachain/pallets/ethereum-beacon-client/tests/fixtures/minimal_finalized_header_update.json @@ -1,37 +1,37 @@ { "attested_header": { - "slot": 168, - "proposer_index": 5, - "parent_root": "0xd567978cf2992cc290f223df75d58369a9893d798c23ed3722ab7a0690bda687", - "state_root": "0x3e30d9357c88dc78c3bc8ed19685e3f21e90072f809d0d30a4658634e4f5ab41", - "body_root": "0x581383568a951904285564c960260d21a662919d0f18fb76e001515c7f1496f6" + "slot": 88, + "proposer_index": 4, + "parent_root": "0x3c5d78ac911dffd15db68532fb2636e0bdbc3ae2949019c00b6393270518c241", + "state_root": "0x2da21762825d7dda284dcf5abd4775a73f862b19ba5f242485ece9c13022d85d", + "body_root": "0xc23de36f009769dc4a7286f4d4bf3cba9ecd81451bbff95f8eb41dd6184be1e7" }, "finalized_header": { - "slot": 152, + "slot": 72, "proposer_index": 2, - "parent_root": "0xc6e5d2ad0e10309dc895c9f3a37b0dcadf95648f036b42d0ef5084252c69f1ed", - "state_root": "0xb0f73342ab9c265eae11cc98cee2f82e5974158a6cb6772f5e57991b2f2a3f3a", - "body_root": "0xd0ae6720fd5cd20d994292f4efa540811f2011b4b8aa466fe1a3c6aa8b1418ad" + "parent_root": "0x5629f3117ab668ceaa7a73850a0963737a9ade6b4dc933f33f89cca29d4afe18", + "state_root": "0x135ad596ce3d49f2e77f983e3974d57203dc73a072bd6b39df0f8597379538fb", + "body_root": "0x3f5981bf6bda829a629d1b363a1eefdba35ffdfb11b52a86e4e3bfb7e587d402" }, "finality_branch": [ - "0x1300000000000000000000000000000000000000000000000000000000000000", + "0x0900000000000000000000000000000000000000000000000000000000000000", "0x10c726fac935bf9657cc7476d3cfa7bedec5983dcfb59e8a7df6d0a619e108d7", - "0x24477da323967ef1397fb25cde5aa28ed5d7f5a5b437ba4343c9be88041bc119", - "0xdabc4d1850acd0551d8d30f9d35b3471f88477f56e617cbd48b52a38f0682fd9", - "0x58c6354b6ac69908c6306aa6a16ef3fd9d1fcfc9a1ba46732e65635b93d48788", - "0xe814c498f7b604b0ee9168053bb905fca91d004c1cb5cd5e8647ce7ceb4328c1" + "0x82948c086478d3cd9d4440c395e7c919fa33ce91abceeba81437478dc289acdf", + "0x51f5d2fdf77f840922a620300a9331378f6ee2359b4b531594edd05940cf2ca3", + "0xdd9fdd6452906fe49bacc0289348af8378e4696059bc96f8101f51dc2978ccdc", + "0x12a5e4daa84e527a9d385a353b3ce39466b0c5fab3d64900bdba82b3a596b68b" ], "sync_aggregate": { "sync_committee_bits": "0xffffffff", - "sync_committee_signature": "0xb7a1aa69fd2b57308f871dc877215b3521ad336b5af88bc286c5b42f8ecf36cad076c67465fc5c02c72132ee000eeb300e60362fbd5548a6c27e5b0b8d0d3d6b32adfc08673605572b630b005ac07af5cb7617176100ae843fbb86cee4e7c683" + "sync_committee_signature": "0x95a4470526294e5361ec25fa7d4614e9c7ab7d8fbbcc581f1e857559f53355013a4fb1c957c160735816d4cab737f39501b49c9c41641604175a2cc4fd39544da8ed6361fe3a2377cf072adfb91aeb3dd0d9063cd2f58dc9816089e59f569fad" }, - "signature_slot": 169, - "block_roots_root": "0x0ca0cf2867bc9c8361f2c66a926218d0a5817301667e0a974983cd1d87dd6e55", + "signature_slot": 89, + "block_roots_root": "0x3c24cf1eab10af300fb99827ccdf210738e44200c20d8740416534a775218f97", "block_roots_branch": [ - "0x7265769c5443608ec0ca000bd6d92b98bd74a6ed1d91bdb9745b173bd4bd30b2", - "0x63da1a7293f7a8ba9e555312e91aac391847813390b76a51c6b6842a63509151", - "0x314eb3af46fb3cd5b6e78ad4e91467a4149c056d1e8d8e76dd2382177d2be464", - "0xbc5b324e321445e9ee98c670c563a5c7793b12ecdd79b25be0abee5288d9b410", - "0xc1e6c27607e2ec00b123b5e98426100fe38c14e35030505e9cd5c713f194c71d" + "0xb6c272185a6ac2b7312fe852e9ae9788ddfb3a6c2277ee4c6d523d0da4770b74", + "0x7be44999084960dddb5224beb5d170deecf56fd837cc467d1f19ab5e9db835f2", + "0x80f2585a32b329c05067ab6eea4f70549020188abfa926b5c6a4bcade3734a36", + "0x7117ac2c53d67ecd44dfe218c6c3e2f204a1584a83bb1d1f3750bd8ec635dbdc", + "0xa13f0e75fe185d630a7f3e6fd1ab0887da47e542bd274d3834e22f030b830819" ] } \ No newline at end of file diff --git a/parachain/pallets/ethereum-beacon-client/tests/fixtures/minimal_header_update.json b/parachain/pallets/ethereum-beacon-client/tests/fixtures/minimal_header_update.json index 41e8060d8a0c4..65a233120b054 100644 --- a/parachain/pallets/ethereum-beacon-client/tests/fixtures/minimal_header_update.json +++ b/parachain/pallets/ethereum-beacon-client/tests/fixtures/minimal_header_update.json @@ -1,46 +1,41 @@ { - "beacon_header": { - "slot": 150, - "proposer_index": 5, - "parent_root": "0x8bdd8b8f9e6887ff2b05b322339fea4ec78a7e6159ec4e54b591a44699662b5b", - "state_root": "0x0db33febe0d69ec00eeab7961cb3d3e9a16ccc59f1314a5b67d2887be37e624d", - "body_root": "0xcbfb4d27fd2e98f38921914e5e79b357684769b3adfaa17861b423f7f63f37b1" - }, - "execution_header": { - "parent_hash": "0x3fe1542912d40d01821fbee41809db8e53a8cbae0d854cb0e5a9d94247fbc031", - "fee_recipient": "0x0000000000000000000000000000000000000000", - "state_root": "0x251f215b8f0bb2caceac8cf469f0bf4daf1d0a8e319b506a02ab4a0362e31083", - "receipts_root": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "logs_bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", - "prev_randao": "0x821b4a7000256c9927032630785533f5fa4f1a40b6ae95eedf86d5910e18549c", - "block_number": 150, - "gas_limit": 69094400, - "gas_used": 0, - "timestamp": 1679133094, - "extra_data": "0xd983010b02846765746888676f312e31392e358664617277696e", - "base_fee_per_gas": 7, - "block_hash": "0xd84d6e83a9b4783fe4a290edc0d57e218a42aeb4f4c97dc7c83dacf82a1ec5eb", - "transactions_root": "0x7ffe241ea60187fdb0187bfa22de35d1f9bed7ab061d9401fd47e34a54fbede1", - "withdrawals_root": "0x28ba1834a3a7b657460ce79fa3a1d909ab8828fd557659d4d0554a9bdbc0ec30" - }, - "execution_branch": [ - "0x577ef1f2f9b33764e9a0d56225a4df5890f3b5ac3dc6fec05db54b65f20a8984", - "0x336488033fe5f3ef4ccc12af07b9370b92e553e35ecb4a337a1b1c0e4afe1e0e", - "0xdb56114e00fdd4c1f85c892bf35ac9a89289aaecb1ebd0a96cde606a748b5d71", - "0x1b1451ad43516084cc488a22800d39d3368f0220cbc844957321fdf4dfe8154d" - ], - "sync_aggregate": { - "sync_committee_bits": "0xffffffff", - "sync_committee_signature": "0xb203cba9326023622caad739fe44a50392d85a8bc1cb3f0c64d89319a865dc1dc1d1ff318d939ac24e4866068d8ca442116d4e7badec88015fd2865f97d5d5ab321c6c9a6994a9afee31f03cd015131320324bffc5d18746d232578c321ea61b" - }, - "signature_slot": 151, - "block_root_branch": [ - "0xc6e5d2ad0e10309dc895c9f3a37b0dcadf95648f036b42d0ef5084252c69f1ed", - "0x86d3344e6df5f9e3b930fe849e4ef99eca85cf455698db3acff0ab5449f0c383", - "0x476a0e95a7b8cdef9aa2b8456ad44c46e7d828fd1821dec3dd3f456c21dbd679", - "0x0fff87fb108fae09e61eafef5bcf22f4a5267699d5624fab371f661cc5e0c938", - "0x76dd343907582c21ec28320c1d6a10349d338ac8ae4bb6e890063ad7d4ce4a6a", - "0x7eebb150fd62159c1adf5dbe3e677b9574ea304d752f06de0a9f03f8f0ed6597" - ], - "block_root_branch_header_root": "0x105976df5861b95fa4184564978eac0bcbe872acdd77a0ead552a8b283dabc4f" -} + "header": { + "slot": 70, + "proposer_index": 0, + "parent_root": "0x8d5bd407701a7c2a7783060aa32523947e8dee84587596dc865bfaaea7b88cb4", + "state_root": "0x76a774cdb872ae29238bea2b38283cfc9bf0724521042f48b47bad2ed7c13d1c", + "body_root": "0xc4c24fe96afde6e2bbe39ffb82b1385a1eb0805424197bc049251b8c5af6abb6" + }, + "execution_header": { + "parent_hash": "0x5d8301c97b80be6f94e4c3000124158c2cbe92ca8db38c6c6a09d81fb38f5715", + "fee_recipient": "0x0000000000000000000000000000000000000000", + "state_root": "0x04b361e1bb8763058a934ec9ef62224a63d8e5fef915926261026aa2ced4bf88", + "receipts_root": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logs_bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "prev_randao": "0x5c15907f0f9ba5c08bdda0ee009e8f6515400767bb79e85286262b3d532f26a1", + "block_number": 70, + "gas_limit": 74711588, + "gas_used": 0, + "timestamp": 1684385716, + "extra_data": "0xd983010b02846765746888676f312e31392e358664617277696e", + "base_fee_per_gas": 91685, + "block_hash": "0xcc3f686dcb2bdc8cafb810d936b0c7a68058430100baf0d8064d4446b4793b8d", + "transactions_root": "0x7ffe241ea60187fdb0187bfa22de35d1f9bed7ab061d9401fd47e34a54fbede1", + "withdrawals_root": "0x28ba1834a3a7b657460ce79fa3a1d909ab8828fd557659d4d0554a9bdbc0ec30" + }, + "execution_branch": [ + "0x211255a4f25e60c027f834a7b5c1f330d5fe8ceae2e70c0de2708ea1021439d8", + "0x336488033fe5f3ef4ccc12af07b9370b92e553e35ecb4a337a1b1c0e4afe1e0e", + "0xdb56114e00fdd4c1f85c892bf35ac9a89289aaecb1ebd0a96cde606a748b5d71", + "0x9c9b69df6b8cbbf1b220de8fbb767d0ce8bdd0d95db0ddd48b0533fa1c448e00" + ], + "block_roots_branch": [ + "0x5629f3117ab668ceaa7a73850a0963737a9ade6b4dc933f33f89cca29d4afe18", + "0xd0acaef3827b61abf9f7e84c6c00ef967da85acc535ba73e5fea4bf08e9b77ac", + "0xe63fa5d13b626269ea6d1712d92ae6366e0db878c8166f5b20c803e48b0bc262", + "0xaaddd43ec51ceae099faac448be992e2ec918f429d7f988b41c416d1ff95ecbd", + "0xbb8ecb6570c51c9c0e085cb49f091876ec25a5bd502e0d39e5f6d3e20256cb3f", + "0xfd0d41d7851435aed0bcf546897b846d0f87c9b430730ef00399a4d614092268" + ], + "block_roots_root": "0x40f276b469988631d66dad68840582af223ef5311fed38b82e6877ff4ea3ef11" +} \ No newline at end of file diff --git a/parachain/pallets/ethereum-beacon-client/tests/fixtures/minimal_initial_sync.json b/parachain/pallets/ethereum-beacon-client/tests/fixtures/minimal_initial_sync.json index a581546fd13ea..4fa1ea3548ca4 100644 --- a/parachain/pallets/ethereum-beacon-client/tests/fixtures/minimal_initial_sync.json +++ b/parachain/pallets/ethereum-beacon-client/tests/fixtures/minimal_initial_sync.json @@ -1,55 +1,55 @@ { "header": { - "slot": 152, - "proposer_index": 2, - "parent_root": "0xc6e5d2ad0e10309dc895c9f3a37b0dcadf95648f036b42d0ef5084252c69f1ed", - "state_root": "0xb0f73342ab9c265eae11cc98cee2f82e5974158a6cb6772f5e57991b2f2a3f3a", - "body_root": "0xd0ae6720fd5cd20d994292f4efa540811f2011b4b8aa466fe1a3c6aa8b1418ad" + "slot": 24, + "proposer_index": 3, + "parent_root": "0x1d16135f4c62d6bf36b64e6b9037ae9fcfc83be5aaebbef9284547b75d899dd2", + "state_root": "0xd8ab353955ddecc233f5a89b479e21e56a2293c57d3a8b1a1ca9709db18d0bb8", + "body_root": "0xb1250269238530a347a03bbf30357e9d1a20efba55dc98198dc5712edc7c4a20" }, "current_sync_committee": { "pubkeys": [ "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", - "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", - "0x81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e", + "0xab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34", "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0xa8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac", + "0x81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e", "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", - "0xab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", "0x9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373", - "0xa8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac", "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", - "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", - "0x81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e", + "0xab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34", "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0xa8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac", + "0x81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e", "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", - "0xab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", "0x9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373", - "0xa8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac", "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", - "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", - "0x81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e", + "0xab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34", "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0xa8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac", + "0x81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e", "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", - "0xab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", "0x9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373", - "0xa8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac", "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", - "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", - "0x81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e", + "0xab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34", "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0xa8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac", + "0x81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e", "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", - "0xab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34", - "0x9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373", - "0xa8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac" + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0x9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373" ], "aggregate_pubkey": "0x8fe11476a05750c52618deb79918e2e674f56dfbf12dbce55ae4386d108e8a1e83c6326f5957e2ef19137582ce270dc6" }, "current_sync_committee_branch": [ - "0xae55686c9aa0cfc3a6a3edf5fcc27f3eafbe2772444f4fae6f1f00e1cee7d0ac", - "0xe6d21c47c11698b8acf43778e6e7bdb804f14318bd37460b2274814f1f6cc554", - "0x24851e4e01f264323b3bf1373dc8c99c71afa12ec04329df98e6dc1c45555365", - "0xf5097ceea15bf7a5f7eabcaacba29af64ba0653e2077287e1d17f98d1a5778ad", - "0xebd5dd152ab8fc8acd6ee0d7e43537c3caedc12a9e283e9079ac17a92f2eb931" + "0xc83ff57424470a11c94cdd1ddd9acf552852c8f6f378bb58e9eb00b13f92f7ea", + "0x058baa5628d6156e55ab99da54244be4a071978528f2eb3b19a4f4d7ab36f870", + "0x03b5e2cb4493e1d163753fb3878648c5d36f230b0394c3109377332be7d7b144", + "0x8d75119782cfc16dda282bdf8ba885f3a93180821f6bb8e29a7bcfdb46f92420", + "0x06b3491486d61e4138350b536cf3d07f83bf398923cfb1f4f93cb5bf872247c0" ], "validators_root": "0x270d43e74ce340de4bca2b1936beca0f4f5408d9e78aec4850920baf659d5b69", - "import_time": 1679132194 + "import_time": 1684385440 } \ No newline at end of file diff --git a/parachain/pallets/ethereum-beacon-client/tests/fixtures/minimal_sync_committee_update.json b/parachain/pallets/ethereum-beacon-client/tests/fixtures/minimal_sync_committee_update.json index ebde1f1a68327..a97d35ebd0807 100644 --- a/parachain/pallets/ethereum-beacon-client/tests/fixtures/minimal_sync_committee_update.json +++ b/parachain/pallets/ethereum-beacon-client/tests/fixtures/minimal_sync_committee_update.json @@ -1,82 +1,81 @@ { "attested_header": { - "slot": 144, + "slot": 80, "proposer_index": 2, - "parent_root": "0xd606dedd06b3e00b5c04a80d4d7f4c07c08c6bc1cd6ada47a141f0d7cc4a8032", - "state_root": "0x1720054de28109ee155947a31ed88649c514e590440e959b071d981d70e57e76", - "body_root": "0x8624a57d021cf59e367432769b53e4da63f9a613db778e2e89db701f0b068bea" + "parent_root": "0x8c772b8cae6fcf05326d0baf2aa35f62721407764a4c40ebc6496f236f2996b6", + "state_root": "0xb8e9fb79fa9e5bf6f16f799a8db2d44f9c174f2938c8cc34168f95e1e597c955", + "body_root": "0x042581f5e4b50a56f5258e8f58358e4cb36819c76157fedde33fff7ab71e968a" }, "next_sync_committee": { "pubkeys": [ - "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", - "0xa8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac", - "0xab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34", + "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", - "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", "0x81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e", - "0x9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373", - "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", - "0xa8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac", - "0xab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34", - "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", - "0x81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e", + "0xab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34", "0x9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373", - "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", - "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", "0xa8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac", - "0xab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34", + "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", - "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", "0x81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", + "0xab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34", "0x9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373", + "0xa8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac", "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0x81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e", "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", - "0xa8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac", + "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", "0xab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34", + "0x9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373", + "0xa8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac", + "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", - "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", "0x81283b7a20e1ca460ebd9bbd77005d557370cabb1f9a44f530c4c4c66230f675f8df8b4c2818851aa7d77a80ca5a4a5e", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", + "0xab0bdda0f85f842f431beaccf1250bf1fd7ba51b4100fd64364b6401fda85bb0069b3e715b58819684e7fc0b10a72a34", "0x9977f1c8b731a8d5558146bfb86caea26434f3c5878b589bf280a42c9159e700e9df0e4086296c20b011d2e78c27d373", - "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b" + "0xa8d4c7c27795a725961317ef5953a7032ed6d83739db8b0e8a72353d1b8b4439427f7efa2c89caa03cc9f28f8cbab8ac" ], "aggregate_pubkey": "0x8fe11476a05750c52618deb79918e2e674f56dfbf12dbce55ae4386d108e8a1e83c6326f5957e2ef19137582ce270dc6" }, "next_sync_committee_branch": [ - "0x9aaac2741ce2878a681113933945f318219d798b6d487cc93e8754a2a5a3a965", - "0xc31424ccfc25a7c31fdf86b6f96e8fd9968e79fb11b39f8a05c28a91d468705f", - "0xf782ef12694554b3080ea1479ae045ffa944b6619ca49f2ab75fc20b43c8980c", - "0x360a6db1bac303ac552dc634c7539af9c781e3fc20a7b68ddd95635c6e4cdee5", - "0x1e4cad215834a2821fd8cddb69258c0f49506cbd32a2165b774a1860e7e346e1" + "0xc83ff57424470a11c94cdd1ddd9acf552852c8f6f378bb58e9eb00b13f92f7ea", + "0x952f981c1b064e7f348f085ed0b9a7adb6dae3c91a83436c9c7bb3033d9ac5b9", + "0x6aecda95663b9e2e1e63dfca55fe0372ba982040541bd0f46f8188bb977a923d", + "0xb569d651a3035ccf987b096c0a709f3675c1d51b4887930cc17dbde7b5622ec1", + "0xfc1d7df4f17e5d20edae1433e8268b0974287df80a91d8431829b626ade1f89a" ], "finalized_header": { - "slot": 128, - "proposer_index": 3, - "parent_root": "0x85c48e098074d4e149c05065af9500cecc802f6ae860be69e33dbd52c5c11299", - "state_root": "0x5229bec41f0b20ff789212c00466fa41d003ccec477948f1a2aa5acc875dff7a", - "body_root": "0xabc39f53ae99d6a88afe978320365a6a08ab74167f752b1ca9ec1018e339c7bc" + "slot": 64, + "proposer_index": 6, + "parent_root": "0x081a74140bfb2dfa9bfbfd9dfb4cf16273c7af830342a09a33a024e3ab61cfc2", + "state_root": "0x12530419828feb4acb6792916be98dbb2511bf1db0d1dd53af4b92b88ecf2de0", + "body_root": "0xfef2914c7b983f033f143ffe5a997b5c28f87f9737fee7a84554fdd7011ca643" }, "finality_branch": [ - "0x1000000000000000000000000000000000000000000000000000000000000000", + "0x0800000000000000000000000000000000000000000000000000000000000000", "0x10c726fac935bf9657cc7476d3cfa7bedec5983dcfb59e8a7df6d0a619e108d7", - "0x24477da323967ef1397fb25cde5aa28ed5d7f5a5b437ba4343c9be88041bc119", - "0xf782ef12694554b3080ea1479ae045ffa944b6619ca49f2ab75fc20b43c8980c", - "0x360a6db1bac303ac552dc634c7539af9c781e3fc20a7b68ddd95635c6e4cdee5", - "0x1e4cad215834a2821fd8cddb69258c0f49506cbd32a2165b774a1860e7e346e1" + "0x82948c086478d3cd9d4440c395e7c919fa33ce91abceeba81437478dc289acdf", + "0x6aecda95663b9e2e1e63dfca55fe0372ba982040541bd0f46f8188bb977a923d", + "0xb569d651a3035ccf987b096c0a709f3675c1d51b4887930cc17dbde7b5622ec1", + "0xfc1d7df4f17e5d20edae1433e8268b0974287df80a91d8431829b626ade1f89a" ], "sync_aggregate": { "sync_committee_bits": "0xffffffff", - "sync_committee_signature": "0xa6e5309e0439042fe2d98342faf63452f3aed9a0d4f0086a42588e96a4c619d90964575aff9d7c5aa80e6846efcae3ec1825e2b750314fb715692e38c8a74f2fa86ebf2d3343294c87eb7933794e3c82398168cf3fbf9732c4df51bba3e44989" + "sync_committee_signature": "0xa5a7e1f249b6de746e154cce33656ce1e02cec33e54c883a4fc80af657da26b2e2f79c817cf7d17b558a90012c984bcf03043988bbf086392eb24ed417f1d1f9c4dd09bfa61fec9419b292676cbffd124afd89a775f49c9716f5bb4586485554" }, - "sync_committee_period": 2, - "signature_slot": 145, - "block_roots_root": "0x0367a032243a6c3660e9fe6d1a66c8347767908bff0feef436440e89b35947f5", + "signature_slot": 81, + "block_roots_root": "0xfb8e30a463796805bf1d26d4343c1f44bf2ef40990c6899910adfb0620acb4b3", "block_roots_branch": [ - "0xbae2da1b2ef7c3d5d08f251a52f28efb26baa02e37c068b9c7c714055eec0985", - "0xc046d211fd6f111e77a764a02e4c87ffb2495e23cec971793d2c3b141c23ad19", - "0xfffc075fe465a906ba230573b6087e6d582d051c6aa5a6983fee1284818818e8", - "0xce896755e5dd78b5f1d8cff2cfff79745f3a53f3be1cab1faa86c2e4c727af59", - "0x06b03718b08a83210a0c3a0ba687e246a701e60c7d5d02cca2fc76d054a78918" + "0x4db88d411c4c4a74161590c0d74a90b1ef90c00c11357c6785fb370b48180c3a", + "0xaa68a5ab2d4b7b602b8248f672066adef102e3b1a30199fdbe49a1256aaa07d9", + "0xaa325bab0688c4876ff936d5ad9be143f5b221e317d67d6c20ff8c698043bb59", + "0x7eeee99ba2d0ee2979898849e0b71bec91c3e5652e20dc08fbe71f3256bd7fed", + "0x58eaba2309bd9ec1b77d9589b0e5caac686a9928434862feb1fa51d4dae3a0bc" ] } \ No newline at end of file diff --git a/parachain/primitives/beacon/src/lib.rs b/parachain/primitives/beacon/src/lib.rs index b06be0cefa870..f05b262a2db0e 100644 --- a/parachain/primitives/beacon/src/lib.rs +++ b/parachain/primitives/beacon/src/lib.rs @@ -27,5 +27,5 @@ pub use bls::{ prepare_aggregate_pubkey_from_absent, prepare_aggregate_signature, prepare_g1_pubkeys, AggregatePublicKey, AggregateSignature, BlsError, PublicKeyPrepared, SignaturePrepared, }; -pub use merkle_proof::verify_merkle_proof; +pub use merkle_proof::verify_merkle_branch; pub use receipt::verify_receipt_proof; diff --git a/parachain/primitives/beacon/src/merkle_proof.rs b/parachain/primitives/beacon/src/merkle_proof.rs index 0eebb57848ce9..db927f7f1d336 100644 --- a/parachain/primitives/beacon/src/merkle_proof.rs +++ b/parachain/primitives/beacon/src/merkle_proof.rs @@ -1,23 +1,56 @@ use sp_core::H256; use sp_io::hashing::sha2_256; -// Reference https://github.com/ethereum/consensus-specs/blob/dev/ssz/merkle-proofs.md -// p.s. index here is actually [subtree_index](https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#get_subtree_index) -pub fn verify_merkle_proof(leaf: H256, branch: &[H256], index: usize, root: H256) -> bool { +// Specified by https://github.com/ethereum/consensus-specs/blob/fe9c1a8cbf0c2da8a4f349efdcd77dd7ac8445c4/specs/phase0/beacon-chain.md?plain=1#L742 +// with improvements from https://github.com/ethereum/consensus-specs/blob/dev/ssz/merkle-proofs.md +pub fn verify_merkle_branch( + leaf: H256, + branch: &[H256], + index: usize, + depth: usize, + root: H256, +) -> Option { + // verify the proof length + if branch.len() != depth { + return None + } + // verify the computed merkle root + Some(root == compute_merkle_root(leaf, branch, index)) +} + +fn compute_merkle_root(leaf: H256, proof: &[H256], index: usize) -> H256 { let mut value: [u8; 32] = leaf.into(); - for (i, node) in branch.iter().enumerate() { + for (i, node) in proof.iter().enumerate() { let mut data = [0u8; 64]; - if (index / (2_u32.pow(i as u32) as usize) % 2) == 0 { + if generalized_index_bit(index, i) { // left node data[0..32].copy_from_slice(&value); - data[32..64].copy_from_slice(&node.0); + data[32..64].copy_from_slice(node.as_bytes()); value = sha2_256(&data); } else { // right node - data[0..32].copy_from_slice(&node.0); + data[0..32].copy_from_slice(node.as_bytes()); data[32..64].copy_from_slice(&value); value = sha2_256(&data); } } - value == root.0 + value.into() +} + +// Spec: https://github.com/ethereum/consensus-specs/blob/fe9c1a8cbf0c2da8a4f349efdcd77dd7ac8445c4/ssz/merkle-proofs.md#get_generalized_index_bit +fn generalized_index_bit(generalized_index: usize, position: usize) -> bool { + generalized_index & (1 << position) == 0 +} + +// Spec: https://github.com/ethereum/consensus-specs/blob/fe9c1a8cbf0c2da8a4f349efdcd77dd7ac8445c4/specs/altair/light-client/sync-protocol.md#get_subtree_index +pub const fn subtree_index(generalized_index: usize) -> usize { + generalized_index % (1 << generalized_index_length(generalized_index)) +} + +// Spec: https://github.com/ethereum/consensus-specs/blob/fe9c1a8cbf0c2da8a4f349efdcd77dd7ac8445c4/ssz/merkle-proofs.md#get_generalized_index_length +pub const fn generalized_index_length(generalized_index: usize) -> usize { + match generalized_index.checked_ilog2() { + Some(v) => v as usize, + None => panic!("checked statically; qed"), + } } diff --git a/parachain/primitives/beacon/src/updates.rs b/parachain/primitives/beacon/src/updates.rs index 6468f5b2b21aa..a677b3d2d83e2 100644 --- a/parachain/primitives/beacon/src/updates.rs +++ b/parachain/primitives/beacon/src/updates.rs @@ -4,9 +4,6 @@ use scale_info::TypeInfo; use sp_core::H256; use sp_std::prelude::*; -#[cfg(feature = "std")] -use serde::Deserialize; - use crate::types::{BeaconHeader, ExecutionPayloadHeader, SyncAggregate, SyncCommittee}; #[derive(Encode, Decode, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo)] @@ -15,8 +12,6 @@ use crate::types::{BeaconHeader, ExecutionPayloadHeader, SyncAggregate, SyncComm derive(serde::Serialize, serde::Deserialize), serde(deny_unknown_fields, bound(serialize = ""), bound(deserialize = "")) )] -#[scale_info(skip_type_params(SyncCommitteeSize))] -#[codec(mel_bound())] pub struct CheckpointUpdate { pub header: BeaconHeader, pub current_sync_committee: SyncCommittee, @@ -45,8 +40,6 @@ impl Default for CheckpointUpdate { derive(serde::Deserialize), serde(deny_unknown_fields, bound(serialize = ""), bound(deserialize = "")) )] -#[scale_info(skip_type_params(SyncCommitteeSize))] -#[codec(mel_bound())] pub struct SyncCommitteeUpdate { pub attested_header: BeaconHeader, pub next_sync_committee: SyncCommittee, @@ -54,7 +47,6 @@ pub struct SyncCommitteeUpdate, pub sync_aggregate: SyncAggregate, - pub sync_committee_period: u64, pub signature_slot: u64, pub block_roots_root: H256, pub block_roots_branch: Vec, @@ -68,8 +60,6 @@ pub struct SyncCommitteeUpdate { pub attested_header: BeaconHeader, pub finalized_header: BeaconHeader, @@ -83,17 +73,13 @@ pub struct FinalizedHeaderUpdate { - pub beacon_header: BeaconHeader, +pub struct ExecutionHeaderUpdate { + pub header: BeaconHeader, pub execution_header: ExecutionPayloadHeader, pub execution_branch: Vec, - pub sync_aggregate: SyncAggregate, - pub signature_slot: u64, - pub block_root_branch: Vec, - pub block_root_branch_header_root: H256, + pub block_roots_root: H256, + pub block_roots_branch: Vec, } diff --git a/parachain/templates/beacon_benchmarking_data.rs.mustache b/parachain/templates/beacon_benchmarking_data.rs.mustache index 5f32608910b1b..aa3875c47323a 100644 --- a/parachain/templates/beacon_benchmarking_data.rs.mustache +++ b/parachain/templates/beacon_benchmarking_data.rs.mustache @@ -9,8 +9,7 @@ use snowbridge_beacon_primitives::{ use sp_core::U256; use sp_std::vec; -pub fn initial_sync, ProofSize: Get>( - ) -> InitialUpdate { +pub fn initial_sync() -> InitialUpdate { let time_now = 1675679352; //2023.2.6 return InitialUpdate{ @@ -39,11 +38,7 @@ pub fn initial_sync, ProofSize: Get>( }; } -pub fn sync_committee_update< - SignatureSize: Get, - ProofSize: Get, - SyncCommitteeSize: Get, ->() -> SyncCommitteePeriodUpdate { +pub fn sync_committee_update() -> SyncCommitteePeriodUpdate { return SyncCommitteePeriodUpdate { attested_header: BeaconHeader { slot: {{SyncCommitteeUpdate.AttestedHeader.Slot}}, @@ -81,7 +76,6 @@ pub fn sync_committee_update< sync_committee_bits: hex!("{{SyncCommitteeUpdate.SyncAggregate.SyncCommitteeBits}}"), sync_committee_signature: hex!("{{SyncCommitteeUpdate.SyncAggregate.SyncCommitteeSignature}}").into(), }, - sync_committee_period: {{SyncCommitteeUpdate.SyncCommitteePeriod}}, signature_slot: {{SyncCommitteeUpdate.SignatureSlot}}, block_roots_root: hex!("{{SyncCommitteeUpdate.BlockRootsRoot}}").into(), block_roots_branch: vec![ @@ -92,11 +86,7 @@ pub fn sync_committee_update< }; } -pub fn finalized_header_update< - SignatureSize: Get, - ProofSize: Get, - SyncCommitteeSize: Get, ->() -> FinalizedHeaderUpdate { +pub fn finalized_header_update() -> FinalizedHeaderUpdate { return FinalizedHeaderUpdate{ attested_header: BeaconHeader { slot: {{FinalizedHeaderUpdate.AttestedHeader.Slot}}, @@ -131,23 +121,9 @@ pub fn finalized_header_update< }; } -pub fn header_update< - FeeRecipientSize: Get, - LogsBloomSize: Get, - ExtraDataSize: Get, - SignatureSize: Get, - ProofSize: Get, - SyncCommitteeSize: Get, ->() -> HeaderUpdate< - FeeRecipientSize, - LogsBloomSize, - ExtraDataSize, - SignatureSize, - ProofSize, - SyncCommitteeSize, -> { +pub fn header_update() -> HeaderUpdate { return HeaderUpdate{ - beacon_header: BeaconHeader{ + header: BeaconHeader{ slot: {{HeaderUpdate.BeaconHeader.Slot}}, proposer_index: {{HeaderUpdate.BeaconHeader.ProposerIndex}}, parent_root: hex!("{{HeaderUpdate.BeaconHeader.ParentRoot}}").into(), @@ -175,17 +151,12 @@ pub fn header_update< {{#HeaderUpdate.ExecutionBranch}} hex!("{{.}}").into(), {{/HeaderUpdate.ExecutionBranch}} - ].try_into().expect("too many branch proof items"), - sync_aggregate: SyncAggregate{ - sync_committee_bits: hex!("{{HeaderUpdate.SyncAggregate.SyncCommitteeBits}}"), - sync_committee_signature: hex!("{{HeaderUpdate.SyncAggregate.SyncCommitteeSignature}}").into(), - }, - signature_slot: {{HeaderUpdate.SignatureSlot}}, - block_root_branch: vec![ - {{#HeaderUpdate.BlockRootBranch}} + ], + block_roots_branch: vec![ + {{#HeaderUpdate.BlockRootsBranch}} hex!("{{.}}").into(), - {{/HeaderUpdate.BlockRootBranch}} + {{/HeaderUpdate.BlockRootsBranch}} ], - block_root_branch_header_root: hex!("{{HeaderUpdate.BlockRootBranchHeaderRoot}}").into(), + block_roots_root: hex!("{{HeaderUpdate.BlockRootsRoot}}").into(), }; } diff --git a/relayer/chain/parachain/writer.go b/relayer/chain/parachain/writer.go index ee12984b1a2b6..01b7554f970b3 100644 --- a/relayer/chain/parachain/writer.go +++ b/relayer/chain/parachain/writer.go @@ -252,7 +252,7 @@ func (wr *ParachainWriter) GetFinalizedSlots() ([]uint64, error) { } func (wr *ParachainWriter) GetLastExecutionHeaderState() (state.ExecutionHeader, error) { - key, err := types.CreateStorageKey(wr.conn.Metadata(), "EthereumBeaconClient", "LatestExecutionHeaderState", nil, nil) + key, err := types.CreateStorageKey(wr.conn.Metadata(), "EthereumBeaconClient", "LatestExecutionHeader", nil, nil) if err != nil { return state.ExecutionHeader{}, fmt.Errorf("create storage key for LatestExecutionHeaderState: %w", err) } @@ -277,7 +277,7 @@ func (wr *ParachainWriter) GetLastExecutionHeaderState() (state.ExecutionHeader, } func (wr *ParachainWriter) GetLastFinalizedHeaderState() (state.FinalizedHeader, error) { - key, err := types.CreateStorageKey(wr.conn.Metadata(), "EthereumBeaconClient", "LatestFinalizedHeaderState", nil, nil) + key, err := types.CreateStorageKey(wr.conn.Metadata(), "EthereumBeaconClient", "LatestFinalizedHeader", nil, nil) if err != nil { return state.FinalizedHeader{}, fmt.Errorf("create storage key for GetLastFinalizedHeaderState: %w", err) } diff --git a/relayer/cmd/generate_beacon_data.go b/relayer/cmd/generate_beacon_data.go index 6a76df8c7feb3..4062ad2a22fc0 100644 --- a/relayer/cmd/generate_beacon_data.go +++ b/relayer/cmd/generate_beacon_data.go @@ -4,10 +4,11 @@ import ( "encoding/hex" "encoding/json" "fmt" - "github.com/snowfork/go-substrate-rpc-client/v4/types" "os" "github.com/cbroglie/mustache" + "github.com/snowfork/go-substrate-rpc-client/v4/types" + log "github.com/sirupsen/logrus" "github.com/snowfork/snowbridge/relayer/relays/beacon/cache" "github.com/snowfork/snowbridge/relayer/relays/beacon/config" @@ -88,9 +89,10 @@ func generateBeaconCheckpoint(cmd *cobra.Command, _ []string) error { endpoint, err := cmd.Flags().GetString("url") - configFile := os.Getenv("output_dir") + "/beacon-relay.json" + exportJson, err := cmd.Flags().GetBool("export_json") + + viper.SetConfigFile("core/packages/test/config/beacon-relay.json") - viper.SetConfigFile(configFile) if err := viper.ReadInConfig(); err != nil { return err } @@ -109,9 +111,16 @@ func generateBeaconCheckpoint(cmd *cobra.Command, _ []string) error { if err != nil { return fmt.Errorf("get initial sync: %w", err) } + if exportJson { + initialSync := checkPointScale.ToJSON() + err = writeJSONToFile(initialSync, activeSpec.ToString()+"_initial_sync") + if err != nil { + return fmt.Errorf("write initial sync to file: %w", err) + } + } checkPointBytes, _ := types.EncodeToBytes(checkPointScale) // Call index for EthereumBeaconClient.force_checkpoint - checkPointCallIndex := "0x3205" + checkPointCallIndex := "0x3201" checkPointUpdateCall := checkPointCallIndex + hex.EncodeToString(checkPointBytes) fmt.Println(checkPointUpdateCall) return nil @@ -160,10 +169,6 @@ func generateBeaconData(cmd *cobra.Command, _ []string) error { } initialSync := initialSyncScale.ToJSON() initialSyncHeaderSlot := initialSync.Header.Slot - err = writeJSONToFile(initialSync, activeSpec.ToString()+"_initial_sync") - if err != nil { - return fmt.Errorf("write initial sync to file: %w", err) - } log.Info("created initial sync file") log.Info("downloading beacon state, this can take a few minutes...") @@ -201,12 +206,9 @@ func generateBeaconData(cmd *cobra.Command, _ []string) error { if err != nil { return fmt.Errorf("get header update: %w", err) } - nextHeaderUpdateScale, err := s.GetNextHeaderUpdateBySlot(blockUpdateSlot + 1) if err != nil { return fmt.Errorf("get next header update to get sync aggregate: %w", err) } - headerUpdateScale.Payload.SyncAggregate = nextHeaderUpdateScale.NextSyncAggregate - headerUpdateScale.Payload.SignatureSlot = nextHeaderUpdateScale.Payload.BeaconHeader.Slot headerUpdate := headerUpdateScale.ToJSON() err = writeJSONToFile(headerUpdate, activeSpec.ToString()+"_header_update") if err != nil { @@ -215,37 +217,39 @@ func generateBeaconData(cmd *cobra.Command, _ []string) error { log.Info("created header update file") - log.Info("now updating benchmarking data files") - - // Rust file hexes require the 0x of hashes to be removed - initialSync.RemoveLeadingZeroHashes() - syncCommitteeUpdate.RemoveLeadingZeroHashes() - finalizedUpdate.RemoveLeadingZeroHashes() - headerUpdate.RemoveLeadingZeroHashes() - - data := Data{ - InitialSync: initialSync, - SyncCommitteeUpdate: syncCommitteeUpdate, - FinalizedHeaderUpdate: finalizedUpdate, - HeaderUpdate: headerUpdate, - } - - log.WithFields(log.Fields{ - "location": pathToBeaconTestFixtureFiles, - "spec": activeSpec, - }).Info("rendering file using mustache") - - rendered, err := mustache.RenderFile(pathToBenchmarkDataTemplate, data) - filename := fmt.Sprintf("data_%s.rs", activeSpec) - - log.WithFields(log.Fields{ - "location": pathToBeaconBenchmarkData, - "filename": filename, - }).Info("writing result file") - - err = writeBenchmarkDataFile(filename, rendered) - if err != nil { - return err + if activeSpec.IsMainnet() { + log.Info("now updating benchmarking data files") + + // Rust file hexes require the 0x of hashes to be removed + initialSync.RemoveLeadingZeroHashes() + syncCommitteeUpdate.RemoveLeadingZeroHashes() + finalizedUpdate.RemoveLeadingZeroHashes() + headerUpdate.RemoveLeadingZeroHashes() + + data := Data{ + InitialSync: initialSync, + SyncCommitteeUpdate: syncCommitteeUpdate, + FinalizedHeaderUpdate: finalizedUpdate, + HeaderUpdate: headerUpdate, + } + + log.WithFields(log.Fields{ + "location": pathToBeaconTestFixtureFiles, + "spec": activeSpec, + }).Info("rendering file using mustache") + + rendered, err := mustache.RenderFile(pathToBenchmarkDataTemplate, data) + filename := fmt.Sprintf("data_%s.rs", activeSpec) + + log.WithFields(log.Fields{ + "location": pathToBeaconBenchmarkData, + "filename": filename, + }).Info("writing result file") + + err = writeBenchmarkDataFile(filename, rendered) + if err != nil { + return err + } } log.WithField("spec", activeSpec).Info("done") diff --git a/relayer/cmd/import_execution_header.go b/relayer/cmd/import_execution_header.go index 9152c60a2d72c..5c556cc98fccb 100644 --- a/relayer/cmd/import_execution_header.go +++ b/relayer/cmd/import_execution_header.go @@ -2,11 +2,12 @@ package cmd import ( "fmt" - "github.com/snowfork/snowbridge/relayer/relays/beacon/cache" - "github.com/snowfork/snowbridge/relayer/relays/beacon/config" "io/ioutil" "strings" + "github.com/snowfork/snowbridge/relayer/relays/beacon/cache" + "github.com/snowfork/snowbridge/relayer/relays/beacon/config" + "github.com/ethereum/go-ethereum/common" log "github.com/sirupsen/logrus" "github.com/snowfork/snowbridge/relayer/chain/parachain" @@ -117,16 +118,7 @@ func importExecutionHeaderFn(cmd *cobra.Command, _ []string) error { if err != nil { return fmt.Errorf("get header update: %w", err) } - log.WithField("slot", update.Payload.BeaconHeader.Slot).Info("found block at slot") - - syncAggregate, signatureSlot, err := syncer.GetSyncAggregateForSlot(uint64(update.Payload.BeaconHeader.Slot) + 1) - if err != nil { - return fmt.Errorf("get sync aggregate: %w", err) - } - log.Info("found sync aggregate") - - update.Payload.SyncAggregate = syncAggregate - update.Payload.SignatureSlot = signatureSlot + log.WithField("slot", update.Payload.Header.Slot).Info("found block at slot") err = writer.WriteToParachainAndWatch(ctx, "EthereumBeaconClient.import_execution_header", update.Payload) if err != nil { diff --git a/relayer/relays/beacon/header/header.go b/relayer/relays/beacon/header/header.go index 590ba16860442..f4ff10448280a 100644 --- a/relayer/relays/beacon/header/header.go +++ b/relayer/relays/beacon/header/header.go @@ -234,7 +234,7 @@ func (h *Header) SyncHeader(ctx context.Context, headerUpdate scale.HeaderUpdate blockNumber := uint64(headerUpdate.Payload.ExecutionHeader.BlockNumber) log.WithFields(log.Fields{ - "slot": headerUpdate.Payload.BeaconHeader.Slot, + "slot": headerUpdate.Payload.Header.Slot, "slotsLeftToSync": slotsLeft, "executionBlockRoot": blockHash, "executionBlockNumber": blockNumber, @@ -330,7 +330,7 @@ func (h *Header) SyncHeaders(ctx context.Context, fromHeaderBlockRoot, toHeaderB "epoch": epoch - 1, }).Debug("syncing header in epoch") for _, header := range headersToSync { - err := h.SyncHeader(ctx, header, toSlot-uint64(header.Payload.BeaconHeader.Slot)) + err := h.SyncHeader(ctx, header, toSlot-uint64(header.Payload.Header.Slot)) if err != nil { return fmt.Errorf("sync execution header: %w", err) } @@ -370,22 +370,19 @@ func (h *Header) SyncHeaders(ctx context.Context, fromHeaderBlockRoot, toHeaderB } } - headerUpdate.Payload.SyncAggregate = nextHeaderUpdate.NextSyncAggregate - headerUpdate.Payload.SignatureSlot = nextHeaderUpdate.Payload.BeaconHeader.Slot - headersToSync = append(headersToSync, headerUpdate) headerUpdate = nextHeaderUpdate // last slot to be synced, sync headers if currentSlot >= toSlot { for _, header := range headersToSync { - err := h.SyncHeader(ctx, header, toSlot-uint64(header.Payload.BeaconHeader.Slot)) + err := h.SyncHeader(ctx, header, toSlot-uint64(header.Payload.Header.Slot)) if err != nil { return err } } } - currentSlot = uint64(nextHeaderUpdate.Payload.BeaconHeader.Slot) + currentSlot = uint64(nextHeaderUpdate.Payload.Header.Slot) } return nil diff --git a/relayer/relays/beacon/header/syncer/json/beacon_json.go b/relayer/relays/beacon/header/syncer/json/beacon_json.go index af6a71acc1ad5..243882d9921e1 100644 --- a/relayer/relays/beacon/header/syncer/json/beacon_json.go +++ b/relayer/relays/beacon/header/syncer/json/beacon_json.go @@ -133,13 +133,11 @@ type BlockBody struct { } type HeaderUpdate struct { - BeaconHeader BeaconHeader `json:"beacon_header"` - ExecutionHeader ExecutionPayloadHeaderCapella `json:"execution_header"` - ExecutionBranch []string `json:"execution_branch"` - SyncAggregate SyncAggregate `json:"sync_aggregate"` - SignatureSlot uint64 `json:"signature_slot"` - BlockRootBranch []string `json:"block_root_branch"` - BlockRootBranchHeaderRoot string `json:"block_root_branch_header_root"` + Header BeaconHeader `json:"header"` + ExecutionHeader ExecutionPayloadHeaderCapella `json:"execution_header"` + ExecutionBranch []string `json:"execution_branch"` + BlockRootsRoot string `json:"block_roots_root"` + BlockRootsBranch []string `json:"block_roots_branch"` } type Attestation struct { @@ -299,12 +297,11 @@ func (f *FinalizedHeaderUpdate) RemoveLeadingZeroHashes() { } func (h *HeaderUpdate) RemoveLeadingZeroHashes() { - h.BeaconHeader.RemoveLeadingZeroHashes() + h.Header.RemoveLeadingZeroHashes() h.ExecutionHeader.RemoveLeadingZeroHashes() h.ExecutionBranch = removeLeadingZeroHashForSlice(h.ExecutionBranch) - h.SyncAggregate.RemoveLeadingZeroHashes() - h.BlockRootBranch = removeLeadingZeroHashForSlice(h.BlockRootBranch) - h.BlockRootBranchHeaderRoot = removeLeadingZeroHash(h.BlockRootBranchHeaderRoot) + h.BlockRootsBranch = removeLeadingZeroHashForSlice(h.BlockRootsBranch) + h.BlockRootsRoot = removeLeadingZeroHash(h.BlockRootsRoot) } func removeLeadingZeroHashForSlice(s []string) []string { diff --git a/relayer/relays/beacon/header/syncer/scale/beacon_scale.go b/relayer/relays/beacon/header/syncer/scale/beacon_scale.go index b7e3913b52b85..5f62ff2646143 100644 --- a/relayer/relays/beacon/header/syncer/scale/beacon_scale.go +++ b/relayer/relays/beacon/header/syncer/scale/beacon_scale.go @@ -37,7 +37,6 @@ type SyncCommitteePeriodPayload struct { FinalizedHeader BeaconHeader FinalityBranch []types.H256 SyncAggregate SyncAggregate - SyncCommitteePeriod types.U64 SignatureSlot types.U64 BlockRootsHash types.H256 BlockRootProof []types.H256 @@ -60,13 +59,11 @@ type FinalizedHeaderUpdate struct { } type HeaderUpdatePayload struct { - BeaconHeader BeaconHeader - ExecutionHeader ExecutionPayloadHeaderCapella - ExecutionBranch []types.H256 - SyncAggregate SyncAggregate - SignatureSlot types.U64 - BlockRootBranch []types.H256 - BlockRootBranchHeaderRoot types.H256 + Header BeaconHeader + ExecutionHeader ExecutionPayloadHeaderCapella + ExecutionBranch []types.H256 + BlockRootsRoot types.H256 + BlockRootsBranch []types.H256 } type HeaderUpdate struct { diff --git a/relayer/relays/beacon/header/syncer/scale/json_conversion.go b/relayer/relays/beacon/header/syncer/scale/json_conversion.go index 15822bb6a0062..294739f39e494 100644 --- a/relayer/relays/beacon/header/syncer/scale/json_conversion.go +++ b/relayer/relays/beacon/header/syncer/scale/json_conversion.go @@ -23,7 +23,6 @@ func (p SyncCommitteePeriodPayload) ToJSON() json.SyncCommitteeUpdate { FinalizedHeader: p.FinalizedHeader.ToJSON(), FinalityBranch: util.ScaleBranchToString(p.FinalityBranch), SyncAggregate: p.SyncAggregate.ToJSON(), - SyncCommitteePeriod: uint64(p.SyncCommitteePeriod), SignatureSlot: uint64(p.SignatureSlot), BlockRootsRoot: p.BlockRootsHash.Hex(), BlockRootBranch: util.ScaleBranchToString(p.BlockRootProof), @@ -44,13 +43,11 @@ func (p FinalizedHeaderPayload) ToJSON() json.FinalizedHeaderUpdate { func (h HeaderUpdate) ToJSON() json.HeaderUpdate { return json.HeaderUpdate{ - BeaconHeader: h.Payload.BeaconHeader.ToJSON(), - ExecutionHeader: h.Payload.ExecutionHeader.ToJSON(), - ExecutionBranch: util.ScaleBranchToString(h.Payload.ExecutionBranch), - SyncAggregate: h.Payload.SyncAggregate.ToJSON(), - SignatureSlot: uint64(h.Payload.SignatureSlot), - BlockRootBranch: util.ScaleBranchToString(h.Payload.BlockRootBranch), - BlockRootBranchHeaderRoot: h.Payload.BlockRootBranchHeaderRoot.Hex(), + Header: h.Payload.Header.ToJSON(), + ExecutionHeader: h.Payload.ExecutionHeader.ToJSON(), + ExecutionBranch: util.ScaleBranchToString(h.Payload.ExecutionBranch), + BlockRootsBranch: util.ScaleBranchToString(h.Payload.BlockRootsBranch), + BlockRootsRoot: h.Payload.BlockRootsRoot.Hex(), } } diff --git a/relayer/relays/beacon/header/syncer/syncer.go b/relayer/relays/beacon/header/syncer/syncer.go index 9057f6a3b844b..fe590ff6a96fe 100644 --- a/relayer/relays/beacon/header/syncer/syncer.go +++ b/relayer/relays/beacon/header/syncer/syncer.go @@ -177,7 +177,6 @@ func (s *Syncer) GetSyncCommitteePeriodUpdate(from uint64) (scale.SyncCommitteeP SignatureSlot: types.U64(signatureSlot), BlockRootsHash: blockRootsProof.Leaf, BlockRootProof: blockRootsProof.Proof, - SyncCommitteePeriod: types.U64(from), }, FinalizedHeaderBlockRoot: finalizedHeaderBlockRoot, BlockRootsTree: blockRootsProof.Tree, @@ -474,7 +473,7 @@ func (s *Syncer) GetNextHeaderUpdateBySlot(slot uint64) (scale.HeaderUpdate, err headerUpdate := scale.HeaderUpdate{ Payload: scale.HeaderUpdatePayload{ - BeaconHeader: beaconHeader, + Header: beaconHeader, ExecutionHeader: executionPayloadScale, ExecutionBranch: executionHeaderBranch, }, @@ -517,10 +516,10 @@ func (s *Syncer) GetHeaderUpdateWithAncestryProof(blockRoot common.Hash, checkpo if block.GetBeaconSlot() == checkpoint.Slot { return scale.HeaderUpdate{ Payload: scale.HeaderUpdatePayload{ - BeaconHeader: beaconHeader, - ExecutionHeader: executionPayloadScale, - ExecutionBranch: executionHeaderBranch, - BlockRootBranch: []types.H256{}, + Header: beaconHeader, + ExecutionHeader: executionPayloadScale, + ExecutionBranch: executionHeaderBranch, + BlockRootsBranch: []types.H256{}, }, NextSyncAggregate: nextSyncCommittee, }, nil @@ -538,11 +537,11 @@ func (s *Syncer) GetHeaderUpdateWithAncestryProof(blockRoot common.Hash, checkpo headerUpdate := scale.HeaderUpdate{ Payload: scale.HeaderUpdatePayload{ - BeaconHeader: beaconHeader, - ExecutionHeader: executionPayloadScale, - ExecutionBranch: executionHeaderBranch, - BlockRootBranch: proofScale, - BlockRootBranchHeaderRoot: types.NewH256(checkpoint.FinalizedBlockRoot.Bytes()), + Header: beaconHeader, + ExecutionHeader: executionPayloadScale, + ExecutionBranch: executionHeaderBranch, + BlockRootsBranch: proofScale, + BlockRootsRoot: types.NewH256(checkpoint.FinalizedBlockRoot.Bytes()), }, NextSyncAggregate: nextSyncCommittee, }