From 4456af3eb777c556260d4c73e5bf32915b0e2f47 Mon Sep 17 00:00:00 2001 From: timofey Date: Mon, 25 Sep 2023 19:53:16 +0200 Subject: [PATCH] Fix attested state root source (#15) * fix: swap finalized and attested header stateroot * fix attested state source --------- Co-authored-by: ec2 --- lightclient-circuits/src/sync_step_circuit.rs | 18 +++++++++--------- lightclient-circuits/src/witness/sync.rs | 5 ----- preprocessor/src/sync.rs | 8 ++++++-- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lightclient-circuits/src/sync_step_circuit.rs b/lightclient-circuits/src/sync_step_circuit.rs index 587c8c58..97f74eab 100644 --- a/lightclient-circuits/src/sync_step_circuit.rs +++ b/lightclient-circuits/src/sync_step_circuit.rs @@ -130,6 +130,13 @@ impl SyncStepCircuit { // Verify attestted header let attested_slot: HashInputChunk<_> = args.attested_header.slot.into_witness(); + let attested_header_state_root = args + .attested_header + .state_root + .as_ref() + .iter() + .map(|v| thread_pool.main().load_witness(F::from(*v as u64))) + .collect_vec(); let attested_header = ssz_merkleize_chunks( thread_pool, &sha256_chip, @@ -137,7 +144,7 @@ impl SyncStepCircuit { attested_slot.clone(), args.attested_header.proposer_index.into_witness(), args.attested_header.parent_root.as_ref().into_witness(), - args.attested_header.state_root.as_ref().into_witness(), + attested_header_state_root.clone().into(), args.attested_header.body_root.as_ref().into_witness(), ], )?; @@ -155,13 +162,6 @@ impl SyncStepCircuit { .collect_vec(); let finalized_slot: HashInputChunk<_> = args.finalized_header.slot.into_witness(); - let attested_header_state_root = args - .attested_header - .state_root - .as_ref() - .iter() - .map(|v| thread_pool.main().load_witness(F::from(*v as u64))) - .collect_vec(); let finalized_header_root = ssz_merkleize_chunks( thread_pool, @@ -170,7 +170,7 @@ impl SyncStepCircuit { finalized_slot.clone(), args.finalized_header.proposer_index.into_witness(), args.finalized_header.parent_root.as_ref().into_witness(), - attested_header_state_root.clone().into(), + args.finalized_header.state_root.as_ref().into_witness(), finalized_block_body_root.clone().into(), ], )?; diff --git a/lightclient-circuits/src/witness/sync.rs b/lightclient-circuits/src/witness/sync.rs index e855daa4..918adc01 100644 --- a/lightclient-circuits/src/witness/sync.rs +++ b/lightclient-circuits/src/witness/sync.rs @@ -29,8 +29,6 @@ pub struct SyncStepArgs { pub finality_branch: Vec>, - pub beacon_state_root: Vec, - #[serde(skip)] pub _spec: PhantomData, } @@ -66,8 +64,6 @@ impl Default for SyncStepArgs { let finality_merkle_branch = vec![vec![0; 32]; S::FINALIZED_HEADER_DEPTH]; - let beacon_state_root = compute_root(finalized_header, &state_merkle_branch); - Self { signature_compressed: hex::decode("462c5acb68722355eaa568a166e6da4c46702a496586aa94c681e0b03a200394b8f4adc98d6b5a68e3caf9dae31ff7035a402aad93bdd4752e521b3b536b47dee55d129b6374177f2be8c99b6ea6618abae84b389affc5a50ad8d991f763beaa").unwrap(), pubkeys_uncompressed: iter::repeat(dummy_pk_bytes) @@ -81,7 +77,6 @@ impl Default for SyncStepArgs { attested_header: BeaconBlockHeader::default(), finalized_header: finalized_block, finality_branch: finality_merkle_branch, - beacon_state_root, execution_payload_branch: execution_merkle_branch, execution_payload_root: execution_state_root, _spec: PhantomData, diff --git a/preprocessor/src/sync.rs b/preprocessor/src/sync.rs index aea3f3d6..1c98c36f 100644 --- a/preprocessor/src/sync.rs +++ b/preprocessor/src/sync.rs @@ -15,7 +15,7 @@ use tokio::fs; pub async fn fetch_step_args(node_url: String) -> eyre::Result> { let client = SyncCommitteeProver::new(node_url); let state_id = "head"; - let mut state = client + let state = client .fetch_beacon_state(state_id) .await .map_err(|e| eyre::eyre!("Error fetching state from node. Error: {}", e))?; @@ -47,6 +47,11 @@ pub async fn fetch_step_args(node_url: String) -> eyre::Result(node_url: String) -> eyre::Result