Skip to content

Commit

Permalink
Fix attested state root source (#15)
Browse files Browse the repository at this point in the history
* fix: swap finalized and attested header stateroot

* fix attested state source

---------

Co-authored-by: ec2 <[email protected]>
  • Loading branch information
nulltea and ec2 authored Sep 25, 2023
1 parent 72684b7 commit 4456af3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
18 changes: 9 additions & 9 deletions lightclient-circuits/src/sync_step_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,21 @@ impl<S: Spec, F: Field> SyncStepCircuit<S, F> {

// 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,
[
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(),
],
)?;
Expand All @@ -155,13 +162,6 @@ impl<S: Spec, F: Field> SyncStepCircuit<S, F> {
.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,
Expand All @@ -170,7 +170,7 @@ impl<S: Spec, F: Field> SyncStepCircuit<S, F> {
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(),
],
)?;
Expand Down
5 changes: 0 additions & 5 deletions lightclient-circuits/src/witness/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ pub struct SyncStepArgs<S: Spec> {

pub finality_branch: Vec<Vec<u8>>,

pub beacon_state_root: Vec<u8>,

#[serde(skip)]
pub _spec: PhantomData<S>,
}
Expand Down Expand Up @@ -66,8 +64,6 @@ impl<S: Spec> Default for SyncStepArgs<S> {

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)
Expand All @@ -81,7 +77,6 @@ impl<S: Spec> Default for SyncStepArgs<S> {
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,
Expand Down
8 changes: 6 additions & 2 deletions preprocessor/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use tokio::fs;
pub async fn fetch_step_args<S: Spec>(node_url: String) -> eyre::Result<SyncStepArgs<S>> {
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))?;
Expand Down Expand Up @@ -47,6 +47,11 @@ pub async fn fetch_step_args<S: Spec>(node_url: String) -> eyre::Result<SyncStep
.map_err(|e| eyre::eyre!("Error fetching light client update. Error: {}", e))?
.expect("Light client update should be present");

let mut state = client
.fetch_beacon_state(&light_client_update.attested_header.slot.to_string())
.await
.map_err(|e| eyre::eyre!("Error fetching state from node. Error: {}", e))?;

let pubkeys_uncompressed = client_state
.current_sync_committee
.public_keys
Expand Down Expand Up @@ -157,7 +162,6 @@ pub async fn fetch_step_args<S: Spec>(node_url: String) -> eyre::Result<SyncStep
.iter()
.map(|n| n.as_bytes().to_vec())
.collect_vec(),
beacon_state_root: state_root.as_bytes().to_vec(),
_spec: PhantomData,
};

Expand Down

0 comments on commit 4456af3

Please sign in to comment.