Skip to content

Commit

Permalink
Take sequencer pub keys as arg to batch proof circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
yaziciahmet committed Dec 18, 2024
1 parent aec4378 commit 1fb4c64
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 12 deletions.
5 changes: 4 additions & 1 deletion bin/citrea/src/rollup/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bitcoin_da::spec::{BitcoinSpec, RollupParams};
use bitcoin_da::verifier::BitcoinVerifier;
use citrea_common::rpc::register_healthcheck_rpc;
use citrea_common::tasks::manager::TaskManager;
use citrea_common::FullNodeConfig;
use citrea_common::{FullNodeConfig, RollupPublicKeys};
use citrea_primitives::{TO_BATCH_PROOF_PREFIX, TO_LIGHT_CLIENT_PREFIX};
use citrea_risc0_adapter::host::Risc0BonsaiHost;
// use citrea_sp1::host::SP1Host;
Expand Down Expand Up @@ -261,6 +261,7 @@ impl RollupBlueprint for BitcoinRollup {
da_service: &Arc<Self::DaService>,
da_verifier: Self::DaVerifier,
ledger_db: LedgerDB,
keys: RollupPublicKeys,
) -> Self::ProverService {
let vm = Risc0BonsaiHost::new(ledger_db.clone());
// let vm = SP1Host::new(
Expand All @@ -287,6 +288,8 @@ impl RollupBlueprint for BitcoinRollup {
proof_mode,
zk_storage,
ledger_db,
keys.sequencer_public_key.clone(),
keys.sequencer_da_pub_key,
)
.expect("Should be able to instantiate prover service")
}
Expand Down
16 changes: 13 additions & 3 deletions bin/citrea/src/rollup/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::sync::Arc;
use async_trait::async_trait;
use citrea_common::rpc::register_healthcheck_rpc;
use citrea_common::tasks::manager::TaskManager;
use citrea_common::FullNodeConfig;
use citrea_common::{FullNodeConfig, RollupPublicKeys};
// use citrea_sp1::host::SP1Host;
use citrea_risc0_adapter::host::Risc0BonsaiHost;
use citrea_stf::genesis_config::StorageConfig;
Expand Down Expand Up @@ -138,6 +138,7 @@ impl RollupBlueprint for MockDemoRollup {
da_service: &Arc<Self::DaService>,
da_verifier: Self::DaVerifier,
ledger_db: LedgerDB,
keys: RollupPublicKeys,
) -> Self::ProverService {
let vm = Risc0BonsaiHost::new(ledger_db.clone());

Expand All @@ -154,8 +155,17 @@ impl RollupBlueprint for MockDemoRollup {
ProverGuestRunConfig::Prove => ProofGenMode::Prove,
};

ParallelProverService::new(da_service.clone(), vm, proof_mode, zk_storage, 1, ledger_db)
.expect("Should be able to instantiate prover service")
ParallelProverService::new(
da_service.clone(),
vm,
proof_mode,
zk_storage,
1,
ledger_db,
keys.sequencer_public_key.clone(),
keys.sequencer_da_pub_key,
)
.expect("Should be able to instantiate prover service")
}

fn create_storage_manager(
Expand Down
2 changes: 2 additions & 0 deletions bin/citrea/src/rollup/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {
&da_service,
da_verifier,
ledger_db.clone(),
rollup_config.public_keys.clone(),
)
.await;

Expand Down Expand Up @@ -472,6 +473,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint {
&da_service,
da_verifier,
ledger_db.clone(),
rollup_config.public_keys.clone(),
)
.await;

Expand Down
2 changes: 2 additions & 0 deletions crates/batch-prover/tests/prover_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ fn make_new_prover(thread_pool_size: usize, da_service: Arc<MockDaService>) -> T
(),
thread_pool_size,
ledger_db,
vec![],
vec![],
)
.expect("Should be able to instantiate Prover service"),
),
Expand Down
6 changes: 4 additions & 2 deletions crates/citrea-stf/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ where
&mut self,
data: BatchProofCircuitInput<Stf::StateRoot, Stf::Witness, Da::Spec, Stf::Transaction>,
pre_state: Stf::PreState,
sequencer_public_key: &[u8],
sequencer_da_public_key: &[u8],
forks: &[Fork],
) -> Result<BatchProofCircuitOutput<Da::Spec, Stf::StateRoot>, Da::Error> {
println!("Running sequencer commitments in DA slot");
Expand Down Expand Up @@ -65,8 +67,8 @@ where
} = self
.app
.apply_soft_confirmations_from_sequencer_commitments(
data.sequencer_public_key.as_ref(),
data.sequencer_da_public_key.as_ref(),
sequencer_public_key,
sequencer_da_public_key,
&data.initial_state_root,
pre_state,
data.da_data,
Expand Down
33 changes: 30 additions & 3 deletions crates/prover-services/src/parallel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ where
_ledger_db: LedgerDB,

proof_queue: Arc<Mutex<Vec<ProofData>>>,
sequencer_public_key: Vec<u8>,
sequencer_da_public_key: Vec<u8>,
}

impl<Da, Vm, Stf> ParallelProverService<Da, Vm, Stf>
Expand All @@ -54,6 +56,8 @@ where
zk_storage: Stf::PreState,
thread_pool_size: usize,
_ledger_db: LedgerDB,
sequencer_public_key: Vec<u8>,
sequencer_da_public_key: Vec<u8>,
) -> anyhow::Result<Self> {
assert!(
thread_pool_size > 0,
Expand Down Expand Up @@ -88,6 +92,8 @@ where
zk_storage,
_ledger_db,
proof_queue: Arc::new(Mutex::new(vec![])),
sequencer_public_key,
sequencer_da_public_key,
})
}

Expand All @@ -99,6 +105,8 @@ where
proof_mode: ProofGenMode<Da, Stf>,
zk_storage: Stf::PreState,
_ledger_db: LedgerDB,
sequencer_public_key: Vec<u8>,
sequencer_da_public_key: Vec<u8>,
) -> anyhow::Result<Self> {
let thread_pool_size = std::env::var("PARALLEL_PROOF_LIMIT")
.expect("PARALLEL_PROOF_LIMIT must be set")
Expand All @@ -112,6 +120,8 @@ where
zk_storage,
thread_pool_size,
_ledger_db,
sequencer_public_key,
sequencer_da_public_key,
)
}

Expand Down Expand Up @@ -162,6 +172,8 @@ where
let mut vm = self.vm.clone();
let zk_storage = self.zk_storage.clone();
let proof_mode = self.proof_mode.clone();
let sequencer_public_key = self.sequencer_public_key.clone();
let sequencer_da_public_key = self.sequencer_da_public_key.clone();

vm.add_hint(input);
for assumption in assumptions {
Expand All @@ -170,8 +182,15 @@ where

let (tx, rx) = oneshot::channel();
self.thread_pool.spawn(move || {
let proof =
make_proof(vm, elf, zk_storage, proof_mode).expect("Proof creation must not fail");
let proof = make_proof(
vm,
elf,
zk_storage,
proof_mode,
&sequencer_public_key,
&sequencer_da_public_key,
)
.expect("Proof creation must not fail");
let _ = tx.send(proof);
});

Expand Down Expand Up @@ -249,6 +268,8 @@ fn make_proof<Da, Vm, Stf>(
elf: Vec<u8>,
zk_storage: Stf::PreState,
proof_mode: Arc<Mutex<ProofGenMode<Da, Stf>>>,
sequencer_public_key: &[u8],
sequencer_da_public_key: &[u8],
) -> Result<Proof, anyhow::Error>
where
Da: DaService,
Expand All @@ -263,7 +284,13 @@ where
let guest = vm.simulate_with_hints();
let data = guest.read_from_host();
verifier
.run_sequencer_commitments_in_da_slot(data, zk_storage, get_forks().inner())
.run_sequencer_commitments_in_da_slot(
data,
zk_storage,
sequencer_public_key,
sequencer_da_public_key,
get_forks().inner(),
)
.map(|_| Vec::default())
.map_err(|e| {
anyhow::anyhow!("Guest execution must succeed but failed with {:?}", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::sync::Arc;

use async_trait::async_trait;
use citrea_common::tasks::manager::TaskManager;
use citrea_common::FullNodeConfig;
use citrea_common::{FullNodeConfig, RollupPublicKeys};
use derive_more::Display;
use sov_db::ledger_db::LedgerDB;
use sov_db::rocks_db_config::RocksdbConfig;
Expand Down Expand Up @@ -141,6 +141,7 @@ pub trait RollupBlueprint: Sized + Send + Sync {
da_service: &Arc<Self::DaService>,
da_verifier: Self::DaVerifier,
ledger_db: LedgerDB,
keys: RollupPublicKeys,
) -> Self::ProverService;

/// Creates instance of [`Self::StorageManager`].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn main() {
let data = guest.read_from_host();

let out = stf_verifier
.run_sequencer_commitments_in_da_slot(data, storage, FORKS)
.run_sequencer_commitments_in_da_slot(data, storage, &SEQUENCER_PUBLIC_KEY, &SEQUENCER_DA_PUBLIC_KEY, FORKS)
.expect("Prover must be honest");

guest.commit(&out);
Expand Down
2 changes: 1 addition & 1 deletion guests/risc0/batch-proof-mock/src/bin/batch_proof_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn main() {
let data = guest.read_from_host();

let out = stf_verifier
.run_sequencer_commitments_in_da_slot(data, storage, FORKS)
.run_sequencer_commitments_in_da_slot(data, storage, &SEQUENCER_PUBLIC_KEY, &SEQUENCER_DA_PUBLIC_KEY, FORKS)
.expect("Prover must be honest");

guest.commit(&out);
Expand Down

0 comments on commit 1fb4c64

Please sign in to comment.