Skip to content

feat: update SP1 to v4 #2168

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

Open
wants to merge 11 commits into
base: nightly
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
2,514 changes: 2,076 additions & 438 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ members = [
"crates/sequencer",
"crates/short-header-proof-provider",
"crates/l2-block-rule-enforcer",
# "crates/sp1",
"crates/sp1/guest",
"crates/sp1/host",
# Sovereign sdk
"crates/sovereign-sdk/rollup-interface",
"crates/sovereign-sdk/adapters/mock-da",
Expand Down Expand Up @@ -66,6 +67,7 @@ brotli = "7"
byteorder = { version = "1.5.0", default-features = false }
bytes = { version = "1.10.0", default-features = false }
chrono = { version = "0.4.39", default-features = false }
cfg-if = "1.0.0"
clap = { version = "4.5.23", features = ["derive", "env"] }
const-hex = "1.14"
constmuck = "1.1"
Expand Down Expand Up @@ -116,6 +118,11 @@ tokio = { version = "1.44.2", features = ["full"] }
tower-http = { version = "0.5.0", features = ["full"] }
tower = { version = "0.4.13", features = ["full"] }

# SP1 dependencies
sp1-build = "4.1.7"
sp1-sdk = "4.1.7"
sp1-zkvm = "4.1.7"

# Risc0 dependencies
bonsai-sdk = { version = "1.4" }
risc0-binfmt = "2.0.0"
Expand Down Expand Up @@ -169,6 +176,10 @@ citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "055e7b2
[patch.crates-io]
bitcoincore-rpc = { version = "0.18.0", git = "https://github.com/chainwayxyz/rust-bitcoincore-rpc.git", rev = "0fe8a8b" }

sp1-build ={ git = "https://github.com/succinctlabs/sp1", rev = "4602a5efbd17a7fd170079a9376f1962e551f9e6" }
sp1-zkvm ={ git = "https://github.com/succinctlabs/sp1", rev = "4602a5efbd17a7fd170079a9376f1962e551f9e6" }
sp1-sdk ={ git = "https://github.com/succinctlabs/sp1", rev = "4602a5efbd17a7fd170079a9376f1962e551f9e6" }

[profile.release]
opt-level = 3
lto = true
Expand Down
38 changes: 30 additions & 8 deletions bin/citrea/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ citrea-common = { path = "../../crates/common" }
citrea-fullnode = { path = "../../crates/fullnode" }
citrea-light-client-prover = { path = "../../crates/light-client-prover", features = ["native"] }
citrea-primitives = { path = "../../crates/primitives" }
citrea-risc0-adapter = { path = "../../crates/risc0", features = ["native"] }
citrea-risc0-batch-proof = { path = "../../guests/risc0/batch-proof" }
citrea-risc0-light-client = { path = "../../guests/risc0/light-client-proof" }
citrea-sequencer = { path = "../../crates/sequencer" }
# citrea-sp1 = { path = "../../crates/sp1", features = ["native"] }

citrea-stf = { path = "../../crates/citrea-stf", features = ["native"] }
citrea-storage-ops = { path = "../../crates/storage-ops" }
ethereum-rpc = { path = "../../crates/ethereum-rpc" }
Expand All @@ -43,12 +40,23 @@ sov-prover-storage-manager = { path = "../../crates/sovereign-sdk/full-node/sov-
sov-rollup-interface = { path = "../../crates/sovereign-sdk/rollup-interface", features = ["native"] }
sov-state = { path = "../../crates/sovereign-sdk/module-system/sov-state", features = ["native"] }

# Risc Zero
citrea-risc0-adapter = { path = "../../crates/risc0", features = ["native"], optional = true, default-features = false }
citrea-risc0-batch-proof = { path = "../../guests/risc0/batch-proof", optional = true }
citrea-risc0-light-client = { path = "../../guests/risc0/light-client-proof", optional = true }
risc0-binfmt = { workspace = true, optional = true}

# SP1
citrea-sp1-host = { path = "../../crates/sp1/host", optional = true }
sp1-sdk = { workspace = true, optional = true }

# 3rd-party deps
alloy-primitives = { workspace = true }
alloy-sol-types = { workspace = true }
anyhow = { workspace = true }
async-trait = { workspace = true }
borsh = { workspace = true, features = ["bytes"] }
cfg-if = { workspace = true }
clap = { workspace = true }
hex = { workspace = true }
jsonrpsee = { workspace = true, features = ["http-client", "server"] }
Expand All @@ -60,7 +68,6 @@ metrics-util = { workspace = true }
reth-primitives = { workspace = true }
reth-tasks = { workspace = true }
reth-transaction-pool = { workspace = true }
risc0-binfmt = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tokio = { workspace = true }
Expand All @@ -70,7 +77,6 @@ tracing-subscriber = { workspace = true }
[dev-dependencies]
citrea-evm = { path = "../../crates/evm", features = ["native"] }
citrea-primitives = { path = "../../crates/primitives", features = ["testing"] }
citrea-risc0-adapter = { path = "../../crates/risc0", features = ["native", "testing"] }
sov-mock-da = { path = "../../crates/sovereign-sdk/adapters/mock-da", default-features = false }
sov-prover-storage-manager = { path = "../../crates/sovereign-sdk/full-node/sov-prover-storage-manager", features = ["test-utils"] }
sov-rollup-interface = { path = "../../crates/sovereign-sdk/rollup-interface", features = ["testing"] }
Expand Down Expand Up @@ -107,17 +113,33 @@ bitcoincore-rpc.workspace = true
citrea-e2e = { workspace = true }

[build-dependencies]
sp1-helper = { version = "3.0.0", default-features = false }
sp1-build = { workspace = true, optional = true }

[features]
default = [] # Deviate from convention by making the "native" feature active by default. This aligns with how this package is meant to be used (as a binary first, library second).
default = ["r0"] # Deviate from convention by making the "native" feature active by default. This aligns with how this package is meant to be used (as a binary first, library second).
testing = [
"bitcoin-da/testing",
"citrea-primitives/testing",
"citrea-risc0-batch-proof/testing",
"citrea-risc0-light-client/testing",
"citrea-sp1-host/testing",
"sov-rollup-interface/testing",
]
r0 = [
"dep:citrea-risc0-adapter",
"dep:citrea-risc0-batch-proof",
"dep:citrea-risc0-light-client",
"dep:risc0-binfmt",
"citrea-risc0-adapter/r0",
"citrea-primitives/r0",
"citrea-light-client-prover/r0",
]
sp1 = [
"dep:citrea-sp1-host",
"dep:sp1-build",
"dep:sp1-sdk",
"citrea-light-client-prover/sp1",
]

[[bin]]
name = "citrea"
Expand Down
85 changes: 65 additions & 20 deletions bin/citrea/src/guests.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use std::collections::HashMap;

use citrea_risc0_adapter::Digest;
use citrea_primitives::types::Digest;
use lazy_static::lazy_static;
use risc0_binfmt::compute_image_id;
use sov_rollup_interface::spec::SpecId;

macro_rules! guest {
($a:expr) => {{
let code = include_bytes!($a).to_vec();
let id = compute_image_id(&code).unwrap();
let id = risc0_binfmt::compute_image_id(&code).unwrap();

(id, code)
(id.into(), code)
}};
}

#[cfg(feature = "r0")]
lazy_static! {
/// The following 2 are used as latest guest builds for tests that use mock DA.
pub(crate) static ref BATCH_PROOF_LATEST_MOCK_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
Expand All @@ -28,6 +28,7 @@ lazy_static! {
);
m
};

pub(crate) static ref LIGHT_CLIENT_LATEST_MOCK_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
let mut m = HashMap::new();

Expand All @@ -41,32 +42,66 @@ lazy_static! {
m
};

}

#[cfg(feature = "sp1")]
lazy_static! {
pub(crate) static ref BATCH_PROOF_LATEST_MOCK_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
let mut m = HashMap::new();
m
};
pub(crate) static ref LIGHT_CLIENT_LATEST_MOCK_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
let mut m = HashMap::new();
m
};
}

lazy_static! {
pub(crate) static ref BATCH_PROOF_REGTEST_BITCOIN_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
HashMap::from(
[
(SpecId::Tangerine,
(Digest::new(citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ID),
citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ELF.to_vec())
)
]
)
let mut m = HashMap::new();

#[cfg(feature = "r0")]
m.insert(
SpecId::Tangerine,
(citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ID.into(),
citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ELF.to_vec())
);

#[cfg(feature = "sp1")]
m.insert(
SpecId::Tangerine,
(Digest::new([0; 8]),
citrea_sp1_host::ELF.to_vec())
);

m
};

/// The following 2 are used as latest guest builds for tests that use Bitcoin DA.
pub(crate) static ref BATCH_PROOF_LATEST_BITCOIN_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
HashMap::from(
[
(SpecId::Tangerine,
(Digest::new(citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ID),
citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ELF.to_vec())
)
]
)
let mut m = HashMap::new();

#[cfg(feature = "r0")]
m.insert(
SpecId::Tangerine,
(Digest::new(citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ID),
citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ELF.to_vec())
);

#[cfg(feature = "sp1")]
m.insert(
SpecId::Tangerine,
(Digest::new([0; 8]),
citrea_sp1_host::ELF.to_vec())
);

m
};

pub(crate) static ref LIGHT_CLIENT_LATEST_BITCOIN_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
let mut m = HashMap::new();

#[cfg(feature = "r0")]
m.insert(
SpecId::Tangerine,
(
Expand All @@ -80,12 +115,14 @@ lazy_static! {
pub(crate) static ref BATCH_PROOF_MAINNET_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
let mut m = HashMap::new();

#[cfg(feature = "r0")]
m.insert(SpecId::Tangerine, guest!("../../../resources/guests/risc0/mainnet/batch-0.elf"));
m
};
pub(crate) static ref BATCH_PROOF_TESTNET_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
let mut m = HashMap::new();

#[cfg(feature = "r0")]
m.insert(SpecId::Tangerine, guest!("../../../resources/guests/risc0/testnet/batch-0.elf"));

m
Expand All @@ -94,22 +131,27 @@ lazy_static! {
let mut m = HashMap::new();

// won't be used but putting here just in case
#[cfg(feature = "r0")]
m.insert(SpecId::Genesis, guest!("../../../resources/guests/risc0/devnet/batch-proof-0.bin"));
// won't be used but putting here just in case
#[cfg(feature = "r0")]
m.insert(SpecId::Kumquat, guest!("../../../resources/guests/risc0/devnet/batch-proof-0.bin"));
#[cfg(feature = "r0")]
m.insert(SpecId::Tangerine, guest!("../../../resources/guests/risc0/devnet/batch-proof-0.bin"));

m
};
pub(crate) static ref LIGHT_CLIENT_MAINNET_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
let mut m = HashMap::new();

#[cfg(feature = "r0")]
m.insert(SpecId::Tangerine, guest!("../../../resources/guests/risc0/mainnet/light-0.elf"));
m
};
pub(crate) static ref LIGHT_CLIENT_TESTNET_GUESTS: HashMap<SpecId, (Digest, Vec<u8>)> = {
let mut m = HashMap::new();

#[cfg(feature = "r0")]
m.insert(SpecId::Tangerine, guest!("../../../resources/guests/risc0/testnet/light-0.elf"));

m
Expand All @@ -118,9 +160,12 @@ lazy_static! {
let mut m = HashMap::new();

// won't be used but putting here just in case
#[cfg(feature = "r0")]
m.insert(SpecId::Genesis, guest!("../../../resources/guests/risc0/devnet/light-client-proof-0.bin"));
// won't be used but putting here just in case
#[cfg(feature = "r0")]
m.insert(SpecId::Kumquat, guest!("../../../resources/guests/risc0/devnet/light-client-proof-0.bin"));
#[cfg(feature = "r0")]
m.insert(SpecId::Tangerine, guest!("../../../resources/guests/risc0/devnet/light-client-proof-0.bin"));
m
};
Expand Down
27 changes: 19 additions & 8 deletions bin/citrea/src/rollup/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use citrea_common::rpc::register_healthcheck_rpc;
use citrea_common::FullNodeConfig;
use citrea_primitives::forks::use_network_forks;
use citrea_primitives::REVEAL_TX_PREFIX;
use citrea_risc0_adapter::host::Risc0Host;
// use citrea_sp1::host::SP1Host;
use citrea_stf::genesis_config::StorageConfig;
use citrea_stf::runtime::CitreaRuntime;
use prover_services::{ParallelProverService, ProofGenMode};
Expand Down Expand Up @@ -50,7 +48,10 @@ impl RollupBlueprint for BitcoinRollup {
type DaSpec = BitcoinSpec;
type DaConfig = BitcoinServiceConfig;
type DaVerifier = BitcoinVerifier;
type Vm = Risc0Host;
#[cfg(feature = "r0")]
type Vm = citrea_risc0_adapter::host::Risc0Host;
#[cfg(feature = "sp1")]
type Vm = citrea_sp1_host::SP1Host;

fn new(network: Network) -> Self {
use_network_forks(network);
Expand Down Expand Up @@ -263,11 +264,21 @@ impl RollupBlueprint for BitcoinRollup {
proof_sampling_number: usize,
is_light_client_prover: bool,
) -> ParallelProverService<Self::DaService, Self::Vm> {
let vm = Risc0Host::new(ledger_db.clone(), self.network);
// let vm = SP1Host::new(
// include_bytes!("../guests/sp1/batch-prover-bitcoin/elf/zkvm-elf"),
// ledger_db.clone(),
// );
cfg_if::cfg_if! {
if #[cfg(feature = "sp1")] {
use citrea_sp1_host::SP1Host;

let vm = SP1Host::new(
citrea_sp1_host::ELF.to_vec(),
ledger_db.clone(),
self.network,
);
} else {
use citrea_risc0_adapter::host::Risc0Host;

let vm = Risc0Host::new(ledger_db.clone(), self.network);
}
}

let proof_mode = match proving_mode {
ProverGuestRunConfig::Skip => ProofGenMode::Skip,
Expand Down
Loading