Skip to content

Commit 1e01774

Browse files
committed
fix preprocessor asserts
1 parent abaab08 commit 1e01774

File tree

2 files changed

+52
-66
lines changed

2 files changed

+52
-66
lines changed

preprocessor/src/rotation.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ use std::marker::PhantomData;
66

77
use eth_types::Spec;
88
use itertools::Itertools;
9-
use log::debug;
109

1110
use crate::get_light_client_update_at_period;
1211
use eth2::{types::BlockId, BeaconNodeHttpClient};
1312
use ethereum_types::{EthSpec, LightClientUpdate};
1413
use lightclient_circuits::witness::CommitteeUpdateArgs;
15-
use tree_hash::{Hash256, TreeHash};
14+
use tree_hash::TreeHash;
1615

1716
/// Fetches LightClientUpdate from the beacon client and converts it to a [`CommitteeUpdateArgs`] witness
1817
pub async fn fetch_rotation_args<S: Spec, T: EthSpec>(
@@ -38,7 +37,7 @@ where
3837

3938
let slot = block.slot.as_u64();
4039
let period = slot / (32 * 256);
41-
debug!(
40+
println!(
4241
"Fetching light client update at current Slot: {} at Period: {}",
4342
slot, period
4443
);
@@ -129,7 +128,7 @@ mod tests {
129128
#[tokio::test]
130129
async fn test_rotation_circuit_sepolia() {
131130
const CONFIG_PATH: &str = "../lightclient-circuits/config/committee_update_testnet.json";
132-
const K: u32 = 21;
131+
const K: u32 = 20;
133132
const URL: &str = "https://lodestar-sepolia.chainsafe.io";
134133
let client = BeaconNodeHttpClient::new(
135134
SensitiveUrl::parse(URL).unwrap(),

preprocessor/src/step.rs

+49-62
Original file line numberDiff line numberDiff line change
@@ -97,70 +97,33 @@ pub async fn step_args_from_finality_update<S: Spec, T: EthSpec>(
9797
})
9898
.collect_vec();
9999

100-
let (execution_payload_root, execution_payload_branch, finalized_beacon_body_root) =
101-
match finality_update {
102-
LightClientFinalityUpdate::Altair(_) => unimplemented!(),
103-
LightClientFinalityUpdate::Capella(ref header) => {
104-
let finalized_header = &header.finalized_header;
105-
106-
(
107-
finalized_header.execution.tree_hash_root().0.to_vec(),
108-
finalized_header
109-
.execution_branch
110-
.iter()
111-
.map(|n| n.0.to_vec())
112-
.collect_vec(),
113-
finalized_header.beacon.body_root,
114-
)
115-
}
116-
LightClientFinalityUpdate::Deneb(ref header) => {
117-
let finalized_header = &header.finalized_header;
100+
let (execution_payload_root, execution_payload_branch) = match finality_update {
101+
LightClientFinalityUpdate::Altair(_) => unimplemented!(),
102+
LightClientFinalityUpdate::Capella(ref header) => {
103+
let finalized_header = &header.finalized_header;
118104

119-
(
120-
finalized_header.execution.tree_hash_root().0.to_vec(),
121-
finalized_header
122-
.execution_branch
123-
.iter()
124-
.map(|n| n.0.to_vec())
125-
.collect_vec(),
126-
finalized_header.beacon.body_root,
127-
)
128-
}
129-
};
105+
(
106+
finalized_header.execution.tree_hash_root().0.to_vec(),
107+
finalized_header
108+
.execution_branch
109+
.iter()
110+
.map(|n| n.0.to_vec())
111+
.collect_vec(),
112+
)
113+
}
114+
LightClientFinalityUpdate::Deneb(ref header) => {
115+
let finalized_header = &header.finalized_header;
130116

131-
assert!(
132-
merkle_proof::verify_merkle_proof(
133-
Hash256::from_slice(&execution_payload_root),
134-
&execution_payload_branch
135-
.iter()
136-
.map(|n| Hash256::from_slice(n))
137-
.collect_vec(),
138-
S::EXECUTION_STATE_ROOT_DEPTH,
139-
S::EXECUTION_STATE_ROOT_INDEX,
140-
finalized_beacon_body_root,
141-
),
142-
"Execution payload merkle proof verification failed"
143-
);
144-
// assert!(
145-
// merkle_proof::verify_merkle_proof(
146-
// finality_update
147-
// .finalized_header
148-
// .beacon
149-
// .clone()
150-
// .hash_tree_root()
151-
// .unwrap(),
152-
// &finality_update
153-
// .finality_branch
154-
// .iter()
155-
// .map(|n| n.as_ref())
156-
// .collect_vec(),
157-
// S::FINALIZED_HEADER_DEPTH,
158-
// S::FINALIZED_HEADER_INDEX,
159-
// finality_update.attested_header.beacon.state_root,
160-
// )
161-
// .is_ok(),
162-
// "Finality merkle proof verification failed"
163-
// );
117+
(
118+
finalized_header.execution.tree_hash_root().0.to_vec(),
119+
finalized_header
120+
.execution_branch
121+
.iter()
122+
.map(|n| n.0.to_vec())
123+
.collect_vec(),
124+
)
125+
}
126+
};
164127

165128
let attested_header_beacon = match &finality_update {
166129
LightClientFinalityUpdate::Altair(_) => unimplemented!(),
@@ -176,6 +139,30 @@ pub async fn step_args_from_finality_update<S: Spec, T: EthSpec>(
176139
LightClientFinalityUpdate::Deneb(update) => update.finalized_header.beacon.clone(),
177140
};
178141

142+
assert!(
143+
merkle_proof::verify_merkle_proof(
144+
Hash256::from_slice(&execution_payload_root),
145+
&execution_payload_branch
146+
.iter()
147+
.map(|n| Hash256::from_slice(n))
148+
.collect_vec(),
149+
S::EXECUTION_STATE_ROOT_DEPTH,
150+
S::EXECUTION_STATE_ROOT_INDEX,
151+
finalized_header_beacon.body_root,
152+
),
153+
"Execution payload merkle proof verification failed"
154+
);
155+
assert!(
156+
merkle_proof::verify_merkle_proof(
157+
finalized_header_beacon.tree_hash_root(),
158+
&finality_update.finality_branch(),
159+
S::FINALIZED_HEADER_DEPTH,
160+
S::FINALIZED_HEADER_INDEX,
161+
attested_header_beacon.state_root,
162+
),
163+
"Finality merkle proof verification failed"
164+
);
165+
179166
Ok(SyncStepArgs {
180167
signature_compressed: finality_update
181168
.sync_aggregate()

0 commit comments

Comments
 (0)