Skip to content

Commit

Permalink
Fix the light client genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
ImJeremyHe committed May 20, 2024
1 parent ca0bb09 commit 8a5cd08
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
8 changes: 7 additions & 1 deletion hotshot-state-prover/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,17 @@ pub async fn light_client_genesis(
stake_table_capacity: usize,
) -> anyhow::Result<ParsedLightClientState> {
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<BLSPubKey, StateVerKey, CircuitField>,
) -> anyhow::Result<ParsedLightClientState> {
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
Expand Down
32 changes: 4 additions & 28 deletions sequencer/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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,
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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<F> = pi.into();
pi.into()
light_client_genesis_from_stake_table(st).unwrap()
}

pub async fn stop_consensus(&mut self) {
Expand Down
1 change: 1 addition & 0 deletions utils/src/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ pub async fn deploy(
.with_chain_id(chain_id);
let owner = wallet.address();
let l1 = Arc::new(SignerMiddleware::new(provider, wallet));

// As a sanity check, check that the deployer address has some balance of ETH it can use to pay
// gas.
let balance = l1.get_balance(owner, None).await?;
Expand Down

0 comments on commit 8a5cd08

Please sign in to comment.