From 2970b5ddaed2e403a9c719bfe161a2f0db133f56 Mon Sep 17 00:00:00 2001 From: ImJeremyHe Date: Mon, 20 May 2024 16:43:56 +0800 Subject: [PATCH] Fix the light client genesis --- hotshot-state-prover/src/service.rs | 8 +++++++- sequencer/src/api.rs | 32 ++++------------------------- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/hotshot-state-prover/src/service.rs b/hotshot-state-prover/src/service.rs index 462859fe58..9f0c9b249f 100644 --- a/hotshot-state-prover/src/service.rs +++ b/hotshot-state-prover/src/service.rs @@ -159,11 +159,17 @@ pub async fn light_client_genesis( stake_table_capacity: usize, ) -> anyhow::Result { let st = init_stake_table_from_orchestrator(orchestrator_url, stake_table_capacity).await; + light_client_genesis_from_stake_table(st) +} + +#[inline] +pub fn light_client_genesis_from_stake_table( + st: StakeTable, +) -> anyhow::Result { let (bls_comm, schnorr_comm, stake_comm) = st .commitment(SnapshotVersion::LastEpochStart) .expect("Commitment computation shouldn't fail."); let threshold = one_honest_threshold(st.total_stake(SnapshotVersion::LastEpochStart)?); - let pi = vec![ u256_to_field(threshold), F::from(0_u64), // Arbitrary value for view number diff --git a/sequencer/src/api.rs b/sequencer/src/api.rs index 3a09b13b41..46322e8bd2 100644 --- a/sequencer/src/api.rs +++ b/sequencer/src/api.rs @@ -20,6 +20,7 @@ use futures::{ use hotshot::types::{Event, SystemContextHandle}; use hotshot_events_service::events_source::{BuilderEvent, EventsSource, EventsStreamer}; use hotshot_query_service::data_source::ExtensibleDataSource; +use hotshot_state_prover::service::light_client_genesis_from_stake_table; use hotshot_types::{data::ViewNumber, light_client::StateSignatureRequestBody}; use jf_merkle_tree::MerkleTreeScheme; use serde::{Deserialize, Serialize}; @@ -35,8 +36,6 @@ mod update; pub use options::Options; -type F = ark_ed_on_bn254::Fq; - #[derive(Clone, Debug, Serialize, Deserialize)] pub struct AccountQueryData { pub balance: U256, @@ -269,17 +268,10 @@ pub mod test_helpers { }; use hotshot::types::{Event, EventType}; - use hotshot_contract_adapter::{ - jellyfish::u256_to_field, light_client::ParsedLightClientState, - }; + use hotshot_contract_adapter::light_client::ParsedLightClientState; use hotshot_types::{ event::LeafInfo, - light_client::GenericPublicInput, - traits::{ - metrics::NoMetrics, - node_implementation::ConsensusTime, - stake_table::{SnapshotVersion, StakeTableScheme}, - }, + traits::{metrics::NoMetrics, node_implementation::ConsensusTime}, }; use itertools::izip; use jf_merkle_tree::{MerkleCommitment, MerkleTreeScheme}; @@ -389,23 +381,7 @@ pub mod test_helpers { pub fn light_client_genesis(&self) -> ParsedLightClientState { let st = self.cfg.stake_table(STAKE_TABLE_CAPACITY_FOR_TEST); - let (bls_comm, schnorr_comm, stake_comm) = st - .commitment(SnapshotVersion::LastEpochStart) - .expect("Commitment computation shouldn't fail."); - let threshold = st.total_stake(SnapshotVersion::LastEpochStart).unwrap() * 2 / 3; - - let pi = vec![ - u256_to_field(threshold), - F::from(0_u64), // Arbitrary value for view number - F::from(0_u64), // Arbitrary value for block height - F::from(0_u64), // Arbitrary value for state commitment - F::from(0_u64), // Arbitrary value for fee ledger commitment - bls_comm, - schnorr_comm, - stake_comm, - ]; - let pi: GenericPublicInput = pi.into(); - pi.into() + light_client_genesis_from_stake_table(st).unwrap() } pub async fn stop_consensus(&mut self) {