Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade helios to 0.7.0 #11

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
706 changes: 235 additions & 471 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ sp1-helios-program = { path = "program" }
sp1-helios-primitives = { path = "primitives" }

# helios
helios = { git = "https://github.com/a16z/helios", version = "0.6.1" }
consensus-core = { git = "https://github.com/a16z/helios", version = "0.6.1" }
common = { git = "https://github.com/a16z/helios", version = "0.6.1" }
helios = { git = "https://github.com/a16z/helios", version = "0.7.0" }
helios-consensus-core = { git = "https://github.com/a16z/helios", version = "0.7.0" }
helios-ethereum = { git = "https://github.com/a16z/helios", version = "0.7.0" }

# general
dotenv = "0.15.0"
eyre = "0.6.12"
sp1-sdk = "2.0.0"
sp1-build = "2.0.0"
sp1-sdk = "3.0.0"
sp1-build = "3.0.0"
tokio = "1.38.0"
tracing = "0.1.37"
serde = "1.0.203"
Expand Down
Binary file modified elf/riscv32im-succinct-zkvm-elf
Binary file not shown.
2 changes: 1 addition & 1 deletion primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ authors.workspace = true
[dependencies]
ssz-rs = { workspace = true }
serde = { workspace = true }
consensus-core = { workspace = true }
helios-consensus-core = { workspace = true }
alloy-sol-types = { workspace = true }
alloy-primitives = { workspace = true }
11 changes: 6 additions & 5 deletions primitives/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use alloy_primitives::B256;
use alloy_sol_types::sol;
use consensus_core::types::Forks;
use consensus_core::types::{FinalityUpdate, LightClientStore, Update};
use helios_consensus_core::consensus_spec::MainnetConsensusSpec;
use helios_consensus_core::types::Forks;
use helios_consensus_core::types::{FinalityUpdate, LightClientStore, Update};
use serde::{Deserialize, Serialize};
use ssz_rs::prelude::*;
pub use ssz_rs::prelude::{Bitvector, Vector};

#[derive(Serialize, Deserialize, Debug)]
pub struct ProofInputs {
pub updates: Vec<Update>,
pub finality_update: FinalityUpdate,
pub updates: Vec<Update<MainnetConsensusSpec>>,
pub finality_update: FinalityUpdate<MainnetConsensusSpec>,
pub expected_current_slot: u64,
pub store: LightClientStore,
pub store: LightClientStore<MainnetConsensusSpec>,
pub genesis_root: B256,
pub forks: Forks,
pub execution_state_proof: ExecutionStateProof,
Expand Down
4 changes: 2 additions & 2 deletions program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ license.workspace = true
authors.workspace = true

[dependencies]
sp1-zkvm = "2.0.0"
consensus-core = { workspace = true }
sp1-zkvm = "3.0.0"
helios-consensus-core = { workspace = true }
serde_cbor = { workspace = true }
sp1-helios-primitives = { workspace = true }
alloy-sol-types = { workspace = true }
Expand Down
14 changes: 8 additions & 6 deletions program/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ sp1_zkvm::entrypoint!(main);

use alloy_primitives::{B256, U256};
use alloy_sol_types::SolValue;
use consensus_core::{apply_finality_update, apply_update, verify_finality_update, verify_update};
use helios_consensus_core::{
apply_finality_update, apply_update, verify_finality_update, verify_update,
};
use sp1_helios_primitives::types::{ProofInputs, ProofOutputs};
use ssz_rs::prelude::*;
use tree_hash::TreeHash;
Expand Down Expand Up @@ -31,8 +33,8 @@ pub fn main() {
execution_state_proof,
} = serde_cbor::from_slice(&encoded_inputs).unwrap();

let prev_header: B256 = store.finalized_header.beacon.tree_hash_root();
let prev_head = store.finalized_header.beacon.slot;
let prev_header: B256 = store.finalized_header.beacon().tree_hash_root();
let prev_head = store.finalized_header.beacon().slot;

// 1. Apply sync committee updates, if any
for (index, update) in updates.iter().enumerate() {
Expand Down Expand Up @@ -75,21 +77,21 @@ pub fn main() {
execution_state_branch_nodes.iter(),
MERKLE_BRANCH_DEPTH,
MERKLE_BRANCH_INDEX,
&Node::try_from(store.finalized_header.beacon.body_root.as_ref()).unwrap(),
&Node::try_from(store.finalized_header.beacon().body_root.as_ref()).unwrap(),
);
if !execution_state_proof_is_valid {
panic!("Execution state root proof is invalid!");
}
println!("Execution state root proof is valid.");

// 4. Commit new state root, header, and sync committee for usage in the on-chain contract
let header: B256 = store.finalized_header.beacon.tree_hash_root();
let header: B256 = store.finalized_header.beacon().tree_hash_root();
let sync_committee_hash: B256 = store.current_sync_committee.tree_hash_root();
let next_sync_committee_hash: B256 = match &mut store.next_sync_committee {
Some(next_sync_committee) => next_sync_committee.tree_hash_root(),
None => B256::ZERO,
};
let head = store.finalized_header.beacon.slot;
let head = store.finalized_header.beacon().slot;

let proof_outputs = ProofOutputs {
executionStateRoot: execution_state_proof.execution_state_root,
Expand Down
3 changes: 2 additions & 1 deletion script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ path = "./bin/test.rs"
dotenv = { workspace = true }
sp1-sdk = { workspace = true }
tokio = { workspace = true }
helios = { workspace = true }
helios-consensus-core = { workspace = true }
helios-ethereum = { workspace = true }
sp1-helios-primitives = { workspace = true }
serde = { workspace = true }
ssz-rs = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions script/bin/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ pub async fn main() -> Result<()> {
.store
.finalized_header
.clone()
.beacon
.beacon()
.tree_hash_root();
let head = helios_client.store.finalized_header.clone().beacon.slot;
let head = helios_client.store.finalized_header.clone().beacon().slot;
let sync_committee_hash = helios_client
.store
.current_sync_committee
Expand Down
12 changes: 7 additions & 5 deletions script/bin/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ use alloy::{
sol,
transports::http::{Client, Http},
};
use helios_ethereum::consensus::Inner;
use helios_ethereum::rpc::http_rpc::HttpRpc;
use helios_consensus_core::consensus_spec::MainnetConsensusSpec;
use helios_ethereum::rpc::ConsensusRpc;
use alloy_primitives::{B256, U256};
use anyhow::Result;
use helios::consensus::rpc::ConsensusRpc;
use helios::consensus::{rpc::nimbus_rpc::NimbusRpc, Inner};
use log::{error, info};
use sp1_helios_primitives::types::ProofInputs;
use sp1_helios_script::*;
Expand Down Expand Up @@ -124,7 +126,7 @@ impl SP1LightClientOperator {
/// Fetch values and generate an 'update' proof for the SP1 LightClient contract.
async fn request_update(
&self,
mut client: Inner<NimbusRpc>,
mut client: Inner<MainnetConsensusSpec, HttpRpc>,
) -> Result<Option<SP1ProofWithPublicValues>> {
// Fetch required values.
let contract = SP1LightClient::new(self.contract_address, self.wallet_filler.clone());
Expand Down Expand Up @@ -158,7 +160,7 @@ impl SP1LightClientOperator {
let finality_update = client.rpc.get_finality_update().await.unwrap();

// Check if contract is up to date
let latest_block = finality_update.finalized_header.beacon.slot;
let latest_block = finality_update.finalized_header.beacon().slot;
if latest_block <= head {
info!("Contract is up to date. Nothing to update.");
return Ok(None);
Expand Down Expand Up @@ -199,7 +201,7 @@ impl SP1LightClientOperator {
stdin.write_slice(&encoded_proof_inputs);

// Generate proof.
let proof = self.client.prove(&self.pk, stdin).plonk().run()?;
let proof = self.client.prove(&self.pk, stdin).groth16().run()?;

info!("Attempting to update to new head block: {:?}", latest_block);
Ok(Some(proof))
Expand Down
4 changes: 2 additions & 2 deletions script/bin/test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Result;
use clap::{command, Parser};
use helios::consensus::rpc::ConsensusRpc;
use helios_ethereum::rpc::ConsensusRpc;
use sp1_helios_primitives::types::ProofInputs;
use sp1_helios_script::{
get_checkpoint, get_client, get_execution_state_root_proof, get_latest_checkpoint, get_updates,
Expand Down Expand Up @@ -32,7 +32,7 @@ async fn main() -> Result<()> {
let helios_client = get_client(checkpoint).await;
let updates = get_updates(&helios_client).await;
let finality_update = helios_client.rpc.get_finality_update().await.unwrap();
let latest_block = finality_update.finalized_header.beacon.slot;
let latest_block = finality_update.finalized_header.beacon().slot;

let execution_state_root_proof = get_execution_state_root_proof(latest_block).await.unwrap();

Expand Down
58 changes: 39 additions & 19 deletions script/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
use alloy_primitives::B256;
use helios::{
config::networks::Network,
consensus::{
constants,
rpc::{nimbus_rpc::NimbusRpc, ConsensusRpc},
Inner,
},
consensus_core::calc_sync_period,
prelude::*,
types::Update,
use helios_consensus_core::{calc_sync_period, consensus_spec::MainnetConsensusSpec, types::{Update, BeaconBlock}};
use helios_ethereum::{
config::{checkpoints, networks::Network, Config},
consensus::Inner,
rpc::http_rpc::HttpRpc,
};
use helios_ethereum::rpc::ConsensusRpc;
use serde::Deserialize;
use sp1_helios_primitives::types::ExecutionStateProof;
use ssz_rs::prelude::*;
Expand All @@ -18,13 +14,16 @@ use tokio::sync::{mpsc::channel, watch};
use tree_hash::TreeHash;
pub mod relay;

/// TODO: Expose this from helios-ethereum
pub const MAX_REQUEST_LIGHT_CLIENT_UPDATES: u8 = 128;

/// Fetch updates for client
pub async fn get_updates(client: &Inner<NimbusRpc>) -> Vec<Update> {
let period = calc_sync_period(client.store.finalized_header.beacon.slot);
pub async fn get_updates(client: &Inner<MainnetConsensusSpec, HttpRpc>) -> Vec<Update<MainnetConsensusSpec>> {
let period = calc_sync_period::<MainnetConsensusSpec>(client.store.finalized_header.beacon().slot);

let updates = client
.rpc
.get_updates(period, constants::MAX_REQUEST_LIGHT_CLIENT_UPDATES)
.get_updates(period, MAX_REQUEST_LIGHT_CLIENT_UPDATES)
.await
.unwrap();

Expand All @@ -46,11 +45,32 @@ pub async fn get_latest_checkpoint() -> B256 {

/// Fetch checkpoint from a slot number.
pub async fn get_checkpoint(slot: u64) -> B256 {
let rpc_url =
std::env::var("SOURCE_CONSENSUS_RPC_URL").expect("SOURCE_CONSENSUS_RPC_URL not set");
let rpc: NimbusRpc = NimbusRpc::new(&rpc_url);
let consensus_rpc = std::env::var("SOURCE_CONSENSUS_RPC_URL").unwrap();
let chain_id = std::env::var("SOURCE_CHAIN_ID").unwrap();
let network = Network::from_chain_id(chain_id.parse().unwrap()).unwrap();
let base_config = network.to_base_config();

let config = Config {
consensus_rpc: consensus_rpc.to_string(),
execution_rpc: String::new(),
chain: base_config.chain,
forks: base_config.forks,
strict_checkpoint_age: false,
..Default::default()
};

let (block_send, _) = channel(256);
let (finalized_block_send, _) = watch::channel(None);
let (channel_send, _) = watch::channel(None);
let client = Inner::<MainnetConsensusSpec, HttpRpc>::new(
&consensus_rpc,
block_send,
finalized_block_send,
channel_send,
Arc::new(config),
);

let block = rpc.get_block(slot).await.unwrap();
let block: BeaconBlock<MainnetConsensusSpec> = client.rpc.get_block(slot).await.unwrap();

B256::from_slice(block.tree_hash_root().as_ref())
}
Expand Down Expand Up @@ -90,7 +110,7 @@ pub async fn get_execution_state_root_proof(
}

/// Setup a client from a checkpoint.
pub async fn get_client(checkpoint: B256) -> Inner<NimbusRpc> {
pub async fn get_client(checkpoint: B256) -> Inner<MainnetConsensusSpec, HttpRpc> {
let consensus_rpc = std::env::var("SOURCE_CONSENSUS_RPC_URL").unwrap();
let chain_id = std::env::var("SOURCE_CHAIN_ID").unwrap();
let network = Network::from_chain_id(chain_id.parse().unwrap()).unwrap();
Expand All @@ -109,7 +129,7 @@ pub async fn get_client(checkpoint: B256) -> Inner<NimbusRpc> {
let (finalized_block_send, _) = watch::channel(None);
let (channel_send, _) = watch::channel(None);

let mut client = Inner::<NimbusRpc>::new(
let mut client = Inner::new(
&consensus_rpc,
block_send,
finalized_block_send,
Expand Down
Loading