diff --git a/crates/consensus/src/fork.rs b/crates/consensus/src/fork.rs index 68a4486..85529a7 100644 --- a/crates/consensus/src/fork.rs +++ b/crates/consensus/src/fork.rs @@ -2,6 +2,7 @@ pub mod altair; pub mod bellatrix; pub mod capella; pub mod deneb; +pub mod electra; use crate::beacon::{Epoch, Slot, Version}; use crate::errors::Error; diff --git a/crates/consensus/src/fork/electra.rs b/crates/consensus/src/fork/electra.rs new file mode 100644 index 0000000..bb29830 --- /dev/null +++ b/crates/consensus/src/fork/electra.rs @@ -0,0 +1,9 @@ +use super::{deneb, ForkSpec}; + +/// https://github.com/ethereum/consensus-specs/blob/a09d0c321550c5411557674a981e2b444a1178c0/specs/electra/light-client/sync-protocol.md#new-constants +pub const ELECTRA_FORK_SPEC: ForkSpec = ForkSpec { + finalized_root_gindex: 169, + current_sync_committee_gindex: 86, + next_sync_committee_gindex: 87, + ..deneb::DENEB_FORK_SPEC +}; diff --git a/crates/light-client-verifier/src/consensus.rs b/crates/light-client-verifier/src/consensus.rs index 6e1c342..786b603 100644 --- a/crates/light-client-verifier/src/consensus.rs +++ b/crates/light-client-verifier/src/consensus.rs @@ -1638,4 +1638,416 @@ mod tests { } } } + + mod electra { + use crate::{ + consensus::SyncProtocolVerifier, + context::{Fraction, LightClientContext}, + mock::MockStore, + updates::ConsensusUpdateInfo, + }; + use ethereum_consensus::{ + beacon::{Slot, Version}, + compute::hash_tree_root, + config::Config, + fork::{ + altair::ALTAIR_FORK_SPEC, + bellatrix::{LightClientUpdate, BELLATRIX_FORK_SPEC}, + capella::CAPELLA_FORK_SPEC, + deneb::{LightClientHeader, DENEB_FORK_SPEC}, + electra::ELECTRA_FORK_SPEC, + ForkParameter, ForkParameters, + }, + preset, + sync_protocol::{SyncAggregate, SyncCommittee}, + types::{H256, U64}, + }; + use hex_literal::hex; + use serde_json::json; + use std::time::SystemTime; + + #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] + pub struct LightClientUpdatesResponse< + const SYNC_COMMITTEE_SIZE: usize, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + >( + pub Vec< + LightClientUpdateResponse< + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + >, + >, + ); + + #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] + pub struct LightClientUpdateResponse< + const SYNC_COMMITTEE_SIZE: usize, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + > { + pub version: String, + pub data: LightClientUpdateData< + SYNC_COMMITTEE_SIZE, + BYTES_PER_LOGS_BLOOM, + MAX_EXTRA_DATA_BYTES, + >, + } + + #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] + pub struct LightClientUpdateData< + const SYNC_COMMITTEE_SIZE: usize, + const BYTES_PER_LOGS_BLOOM: usize, + const MAX_EXTRA_DATA_BYTES: usize, + > { + pub attested_header: LightClientHeader, + pub next_sync_committee: SyncCommittee, + pub next_sync_committee_branch: Vec, + pub finalized_header: LightClientHeader, + pub finality_branch: Vec, + pub sync_aggregate: SyncAggregate, + pub signature_slot: Slot, + } + + #[test] + fn test_electra_update_validation() { + let data = json!( + [ + { + "data": { + "attested_header": { + "beacon": { + "slot": "80", + "proposer_index": "2", + "parent_root": "0xc478ce4223c3345116c47e627379b4c18a24679481612727f54224b60f0924ba", + "state_root": "0x37ac7935d29e970710b9e777b7e5d91b3e4eb45d080adfe3678f88df87bd27e7", + "body_root": "0x8f8c8d6abfd6d0e72718e5cc8c34ed99fa407d4a3e2e126f4f373dba08138b27" + }, + "execution": { + "parent_hash": "0xb7452c7f7f73a3aeabd11ea46b6c7e2ebb3fb1a7321f13c7311666dd55852cc2", + "fee_recipient": "0xa89F47C6b463f74d87572b058427dA0A13ec5425", + "state_root": "0xde116fb056732e28005b7f2f6362a375150e3da8a871f6eaca39a0ec060075dc", + "receipts_root": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logs_bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "prev_randao": "0x644e51edcd3e5206109ac3f50f4816c96b785624761733394cce34c72ce97474", + "block_number": "80", + "gas_limit": "73985196", + "gas_used": "0", + "timestamp": "1731420784", + "extra_data": "0xd883010e0c846765746888676f312e32332e32856c696e7578", + "base_fee_per_gas": "27370", + "block_hash": "0x204042fa52acd657819696450daaaafeaa6238b81fc049b4333146d43434f814", + "transactions_root": "0x7ffe241ea60187fdb0187bfa22de35d1f9bed7ab061d9401fd47e34a54fbede1", + "withdrawals_root": "0x28ba1834a3a7b657460ce79fa3a1d909ab8828fd557659d4d0554a9bdbc0ec30", + "blob_gas_used": "0", + "excess_blob_gas": "0" + }, + "execution_branch": [ + "0x9f6d5e9a1cdddac70868a7f82ce79d3f07911dde6a7441a85a5cab2a7ac50085", + "0x6c6dd63656639d153a2e86a9cab291e7a26e957ad635fec872d2836e92340c23", + "0x60826dbec0252c937b31eee64acdb1e334aa120f8c860f3de894b6d9be9d1737", + "0x1ce581e460685c761fc37bad2e852d6c5708a0cb894335d6cd75c7e2cdabdd88" + ] + }, + "next_sync_committee": { + "pubkeys": [ + "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", + "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", + "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", + "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c" + ], + "aggregate_pubkey": "0x881d222b887a0188eab3a4829f4ba1b947afbb14a37f23bc1b09216268a8c60854cae8a9a7b9a447a7ce7e88a44646ad" + }, + "next_sync_committee_branch": [ + "0xeab4a7a54f4594e7172ccb2086a5b2d916ed2474773d48fa819e71ff7fd36498", + "0x4046f7db4be4754f0909477f8b4811a2cb18d0cb0b88cc1dacad10b760cf1814", + "0x572fffcc0741b3c95323ffa0217bbe6bcc6edfe6b832943b0f601b63fa5cb6ae", + "0xef911751d41e2cb9f4d7e4bee966947685fd329e7115efeeaf672ccd054b446b", + "0x6711cbb84a80bf4b8fbdd8cebe2dd3a2a813b9170c162c4d87cefcb79bb2bad4", + "0x953024c6ded67e542650258c58347cef640ac2bb254c6df6bc3af9bf3c1a1f7a" + ], + "finalized_header": { + "beacon": { + "slot": "64", + "proposer_index": "2", + "parent_root": "0x2ef4a5b4ae533517995b68e35ae31775ba9ac221b50ab762e5661326e998c6fb", + "state_root": "0xd718d5f0480998c282c88dc275f916dd56ea4e80c0b2358c1b1f0019896cbbb5", + "body_root": "0x5f86881d358e275004969e63ce088a5a1f6bd7f8d8d35c8996e89e72cee78d44" + }, + "execution": { + "parent_hash": "0xc0f67837cea15531bb28104dedefa25765134f674186e62c81657e4ce7b7fb71", + "fee_recipient": "0xa89F47C6b463f74d87572b058427dA0A13ec5425", + "state_root": "0xde116fb056732e28005b7f2f6362a375150e3da8a871f6eaca39a0ec060075dc", + "receipts_root": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logs_bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "prev_randao": "0x5d1642b26bd5368eb73530a862cf7a12426e718ac7c5dc8ca6832cc76a806b9a", + "block_number": "64", + "gas_limit": "75150842", + "gas_used": "0", + "timestamp": "1731420688", + "extra_data": "0xd883010e0c846765746888676f312e32332e32856c696e7578", + "base_fee_per_gas": "231790", + "block_hash": "0xf13c9a2cf0089115ab9699860be616f96e46c0549e4d2bcdcbd0d7a33c05df5b", + "transactions_root": "0x7ffe241ea60187fdb0187bfa22de35d1f9bed7ab061d9401fd47e34a54fbede1", + "withdrawals_root": "0x28ba1834a3a7b657460ce79fa3a1d909ab8828fd557659d4d0554a9bdbc0ec30", + "blob_gas_used": "0", + "excess_blob_gas": "0" + }, + "execution_branch": [ + "0x46711de535a492319b7c19a252e8152aa8302591fcc9550c60e3b8484c9c854c", + "0x6c6dd63656639d153a2e86a9cab291e7a26e957ad635fec872d2836e92340c23", + "0x60826dbec0252c937b31eee64acdb1e334aa120f8c860f3de894b6d9be9d1737", + "0x9da22bc8298cc09b761020d6f31be8d1aa592d983630d9a1b5bf66fd1c234335" + ] + }, + "finality_branch": [ + "0x0800000000000000000000000000000000000000000000000000000000000000", + "0x86220a2d72000ffb901cf75bf2918181ffea3c6567a573566d8c826e9e567493", + "0x1a1d518ef5295452ec357d6f063f089b1d2b371b940c20c8f0f8424894d8a6d0", + "0x572fffcc0741b3c95323ffa0217bbe6bcc6edfe6b832943b0f601b63fa5cb6ae", + "0xef911751d41e2cb9f4d7e4bee966947685fd329e7115efeeaf672ccd054b446b", + "0x6711cbb84a80bf4b8fbdd8cebe2dd3a2a813b9170c162c4d87cefcb79bb2bad4", + "0x953024c6ded67e542650258c58347cef640ac2bb254c6df6bc3af9bf3c1a1f7a" + ], + "sync_aggregate": { + "sync_committee_bits": "0xffffffff", + "sync_committee_signature": "0xac848cd9412ee24f5cbcc541361f9d127ac9ebc905f0ec67e726485ff895d509a3ab9f06c666e35e130c4b1391830f5c1533a6e1c1f2bbea7bae64ce21a2c69166a0edd8bb34afce676989626e8bc2cdc8bba896b10fb30e73554f6052155d4f" + }, + "signature_slot": "81" + }, + "version": "electra" + }, + { + "data": { + "attested_header": { + "beacon": { + "slot": "144", + "proposer_index": "0", + "parent_root": "0x9e296701b9891cdef2b0c65210bca3d365a53a8d36665edda1bc8899d77d1dcb", + "state_root": "0xcae6a42025aecf48b70abcb87f2b89c0fc961c311a6d382dd99e2fbfb9d08df8", + "body_root": "0xd3a2beb23a2e0631ab497a5b70a9a5e197056f3445dd77f26082059f9535116e" + }, + "execution": { + "parent_hash": "0xa539cbaef57f4c86ab523d8ab3f72e06f76f7fe01e565891945a215074e6a0e3", + "fee_recipient": "0xa89F47C6b463f74d87572b058427dA0A13ec5425", + "state_root": "0xde116fb056732e28005b7f2f6362a375150e3da8a871f6eaca39a0ec060075dc", + "receipts_root": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logs_bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "prev_randao": "0xc0e1e00889967b494afe8d44e59967c41945884228f9dcbff75cbdad9d06df02", + "block_number": "144", + "gas_limit": "69500628", + "gas_used": "0", + "timestamp": "1731421168", + "extra_data": "0xd883010e0c846765746888676f312e32332e32856c696e7578", + "base_fee_per_gas": "9", + "block_hash": "0xddf2e7681e437f01180f6e8cec70921bae38decb8682e2e68153cf8439789db3", + "transactions_root": "0x7ffe241ea60187fdb0187bfa22de35d1f9bed7ab061d9401fd47e34a54fbede1", + "withdrawals_root": "0x28ba1834a3a7b657460ce79fa3a1d909ab8828fd557659d4d0554a9bdbc0ec30", + "blob_gas_used": "0", + "excess_blob_gas": "0" + }, + "execution_branch": [ + "0x42b6087e510f2f392b75faf0b6344f35856b6f637cfd3e2f8f3ef6ec50f4da15", + "0x6c6dd63656639d153a2e86a9cab291e7a26e957ad635fec872d2836e92340c23", + "0x60826dbec0252c937b31eee64acdb1e334aa120f8c860f3de894b6d9be9d1737", + "0xcc5a70db4f0fe72b187cd010cbd8d0f29e1fbc6b9072b062cd1d7a240a2920f7" + ] + }, + "next_sync_committee": { + "pubkeys": [ + "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", + "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", + "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0xa3a32b0f8b4ddb83f1a0a853d81dd725dfe577d4f4c3db8ece52ce2b026eca84815c1a7e8e92a4de3d755733bf7e4a9b", + "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", + "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0xa99a76ed7796f7be22d5b7e85deeb7c5677e88e511e0b337618f8c4eb61349b4bf2d153f649f7b53359fe8b94a38e44c", + "0x88c141df77cd9d8d7a71a75c826c41a9c9f03c6ee1b180f3e7852f6a280099ded351b58d66e653af8e42816a4d8f532e", + "0xb89bebc699769726a318c8e9971bd3171297c61aea4a6578a7a4f94b547dcba5bac16a89108b6b6a1fe3695d1a874a0b" + ], + "aggregate_pubkey": "0xad140cfada110829569b1c1102c74c84fe2ce097fa7cce128b3174c12a9255b247dee99491fbd52d6591743a0fafed4e" + }, + "next_sync_committee_branch": [ + "0x2ed66fe705188bb88425bcf10879e9e58fdc894ab5324aea228e2fd6667dc898", + "0x0e521c1407a761f63eeea88ee607ac82af00b3562bd5aaa09b64263cb5b512f0", + "0x423733fd0ef9e89921cad0e8c4b8dd8fe0afd290a7c7389f49f9d1b1864fc450", + "0xddf9b0801e380ede4f51843267d3e11c084801ddd303fe6b65e5a5979269a0c6", + "0x1112067594716c340a1c50737a5916654ecf573daf435f6efd8521d3711ce2bb", + "0x953024c6ded67e542650258c58347cef640ac2bb254c6df6bc3af9bf3c1a1f7a" + ], + "finalized_header": { + "beacon": { + "slot": "128", + "proposer_index": "1", + "parent_root": "0x5d22192d8a204f30bfb4b9834b33c8bbbc6fda8e4f65dbb443755a8f59643d58", + "state_root": "0x8d2f20c8e71308d9c00a84b19b89b6796a8823990f3ed01898a077e23eb0bb27", + "body_root": "0x947690090787f644cad858c09724841283739fece1c4a78414bc10f614ce9e23" + }, + "execution": { + "parent_hash": "0x59aae856c9c526f4723a5c298756d8934ab7a2245ccf1770be5c977450635ba0", + "fee_recipient": "0xa89F47C6b463f74d87572b058427dA0A13ec5425", + "state_root": "0xde116fb056732e28005b7f2f6362a375150e3da8a871f6eaca39a0ec060075dc", + "receipts_root": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "logs_bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", + "prev_randao": "0x7a94d1a0a36f2322daea0310f90c909855f93085916218df84208c15da4b6be2", + "block_number": "128", + "gas_limit": "70595621", + "gas_used": "0", + "timestamp": "1731421072", + "extra_data": "0xd883010e0c846765746888676f312e32332e32856c696e7578", + "base_fee_per_gas": "49", + "block_hash": "0x73744f33faec476c04fd9a2ee832fd3ae4fc50fc2a6c2feb14e5f1083040c4c8", + "transactions_root": "0x7ffe241ea60187fdb0187bfa22de35d1f9bed7ab061d9401fd47e34a54fbede1", + "withdrawals_root": "0x28ba1834a3a7b657460ce79fa3a1d909ab8828fd557659d4d0554a9bdbc0ec30", + "blob_gas_used": "0", + "excess_blob_gas": "0" + }, + "execution_branch": [ + "0x8e85ebb032667a0fd5a434b3aa17cccf0e32e45b045970a2200d647133e5a8cd", + "0x6c6dd63656639d153a2e86a9cab291e7a26e957ad635fec872d2836e92340c23", + "0x60826dbec0252c937b31eee64acdb1e334aa120f8c860f3de894b6d9be9d1737", + "0x5060e8a414c24398c3dbf8327fd3cd6ac7669743596e0917b225d3c0fd4cfd1e" + ] + }, + "finality_branch": [ + "0x1000000000000000000000000000000000000000000000000000000000000000", + "0x86220a2d72000ffb901cf75bf2918181ffea3c6567a573566d8c826e9e567493", + "0x61046ece5bc124eaca970582081a9c317376948ac04f6826a54f3fd9bd5a2e64", + "0x423733fd0ef9e89921cad0e8c4b8dd8fe0afd290a7c7389f49f9d1b1864fc450", + "0xddf9b0801e380ede4f51843267d3e11c084801ddd303fe6b65e5a5979269a0c6", + "0x1112067594716c340a1c50737a5916654ecf573daf435f6efd8521d3711ce2bb", + "0x953024c6ded67e542650258c58347cef640ac2bb254c6df6bc3af9bf3c1a1f7a" + ], + "sync_aggregate": { + "sync_committee_bits": "0xffffffff", + "sync_committee_signature": "0xae5ac4800796fa0cd0b808826433c40f35251cea233657f2a9c4e8d38703cd4b7647e00646ec0a550b9bdde517c8f02a0abfc97a997a8a019e39aa93b6bf50fdd78fe9fd89a5598d2ed08957519d37bcb12eeaf930dfdb13756435a736539767" + }, + "signature_slot": "145" + }, + "version": "electra" + } + ] + ); + let res: LightClientUpdatesResponse<32, 256, 32> = + serde_json::from_value(data).unwrap(); + let period_1_update = res.0[0].data.clone(); + let period_2_update = res.0[1].data.clone(); + + let store = MockStore::new( + period_2_update.finalized_header.beacon.clone(), + period_1_update.next_sync_committee, + Default::default(), + ); + let ctx = LightClientContext::new_with_config( + get_config(), + H256::from_slice( + hex!("acac7566fdf384a1ada45c01dcf9030d7eb0e1e5f5302659101d0b2a5bb59092") + .as_ref(), + ), + 1731420304.into(), + Fraction::new(2, 3), + SystemTime::now() + .duration_since(SystemTime::UNIX_EPOCH) + .unwrap() + .as_secs() + .into(), + ); + let consensus_update = ConsensusUpdateInfo { + light_client_update: LightClientUpdate { + attested_header: period_2_update.attested_header.beacon, + next_sync_committee: Some(( + period_2_update.next_sync_committee.clone(), + period_2_update.next_sync_committee_branch.clone(), + )), + finalized_header: ( + period_2_update.finalized_header.beacon, + period_2_update.finality_branch.clone(), + ), + sync_aggregate: period_2_update.sync_aggregate, + signature_slot: period_2_update.signature_slot, + }, + finalized_execution_root: hash_tree_root( + period_2_update.finalized_header.execution, + ) + .unwrap(), + finalized_execution_branch: period_2_update.finalized_header.execution_branch, + }; + let res = SyncProtocolVerifier::default().validate_consensus_update( + &ctx, + &store, + &consensus_update, + ); + assert!(res.is_ok(), "{:?}", res); + } + + fn get_config() -> Config { + Config { + preset: preset::minimal::PRESET, + fork_parameters: ForkParameters::new( + Version([0, 0, 0, 1]), + vec![ + ForkParameter::new(Version([1, 0, 0, 1]), U64(0), ALTAIR_FORK_SPEC), + ForkParameter::new(Version([2, 0, 0, 1]), U64(0), BELLATRIX_FORK_SPEC), + ForkParameter::new(Version([3, 0, 0, 1]), U64(0), CAPELLA_FORK_SPEC), + ForkParameter::new(Version([4, 0, 0, 1]), U64(0), DENEB_FORK_SPEC), + ForkParameter::new(Version([5, 0, 0, 1]), U64(0), ELECTRA_FORK_SPEC), + ], + ) + .unwrap(), + min_genesis_time: U64(1578009600), + } + } + } }