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

full node verify risc0 1.0.5 proofs #1693

Merged
merged 2 commits into from
Jan 11, 2025
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/risc0/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bincode = { workspace = true }
borsh = { workspace = true }
hex = { workspace = true }
metrics = { workspace = true, optional = true }
risc0-zkp = { workspace = true, optional = true }
risc0-zkvm = { workspace = true, default-features = false, features = ["std"] }
serde = { workspace = true }
sov-db = { path = "../sovereign-sdk/full-node/db/sov-db", optional = true }
Expand All @@ -31,6 +32,7 @@ native = [
"dep:metrics",
"risc0-zkvm/bonsai",
"risc0-zkvm/client",
"risc0-zkp",
"sov-rollup-interface/native",
]
bench = ["native"]
91 changes: 88 additions & 3 deletions crates/risc0/src/host.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! This module implements the [`ZkvmHost`] trait for the RISC0 VM.
use borsh::{BorshDeserialize, BorshSerialize};
use metrics::histogram;
use risc0_zkp::verify::VerificationError;
use risc0_zkvm::sha::Digest;
use risc0_zkvm::{
compute_image_id, default_prover, AssumptionReceipt, ExecutorEnvBuilder, ProveInfo, ProverOpts,
Receipt,
Receipt, VerifierContext,
};
use sov_db::ledger_db::LedgerDB;
use sov_rollup_interface::zk::{Proof, Zkvm, ZkvmHost};
Expand Down Expand Up @@ -221,8 +222,19 @@ impl Zkvm for Risc0BonsaiHost {
) -> Result<(), Self::Error> {
let receipt: Receipt = bincode::deserialize(serialized_proof)?;

#[allow(clippy::clone_on_copy)]
receipt.verify(code_commitment.clone())?;
let res = receipt.verify(*code_commitment);

if let Err(VerificationError::InvalidProof) = res {
tracing::warn!("Proof verification failed, trying risc0 1.0.5 verification...");

receipt.verify_with_context(&verifier_context_pre_1_1_0(), *code_commitment)?;

tracing::info!("Proof verification succeeded with risc0 1.0.5 context");

return Ok(());
}

res?;

Ok(())
}
Expand Down Expand Up @@ -257,3 +269,76 @@ impl Zkvm for Risc0BonsaiHost {
)
}
}

fn verifier_context_pre_1_1_0() -> VerifierContext {
use std::collections::BTreeSet;

use risc0_zkp::digest;
use risc0_zkvm::{
Groth16ReceiptVerifierParameters, SegmentReceiptVerifierParameters,
SuccinctReceiptVerifierParameters,
};

let mut ctx = VerifierContext::default();

ctx.segment_verifier_parameters = Some(SegmentReceiptVerifierParameters {
control_ids: BTreeSet::from_iter(
[
digest!("55ba2d763ec3c016c0f97c298507115c77e0a25215e5771ba501d016edca522c"), //
digest!("c265954c4dcb2155e041286a246bfe400ba9d042d919aa3cb1a299651f84c13e"), //
digest!("467cd61da86f37347b45e64b5d4665308871bc301c67ba6c6d13c9470c3e4840"), //
digest!("57b2031d3881e92b85d73d2d0800a223fdaccd5e7bdd0a569c10556ec138f551"), //
digest!("c1f19103f8376c00fe20f62aa4370f628efe3a4a5eb1a5739466c944cf7dfe31"), //
digest!("548ec1774c6c833b18db2e2a1464cb1923c6c721df87b437509ba87292d20529"), //
digest!("ce535b3b10e4cc212842b90a918553633c4f5375dee51d4788798765df5a8750"), //
digest!("7dea3854a91c906f92f23a291340066ecbd5375669fe752a5047c926e4d56747"), //
digest!("dca31f53c5bf4c67ecdc9f1035cf5934072afc29573a1845100d6140befab657"), //
digest!("12da4520930b1740810a69428c02fb2fcb586763a0e3794c45196608b594dd69"), //
digest!("5c2dce7226ff9073b8e38919583c01375f11395111e9ae3bfd519b57f84a5e00"), //
]
.into_iter()
.chain([
digest!("6d0ed860e3effc3cc00114075cb29630b583d227b5654adaf0e9a4e4926144a4"), //
digest!("8f4880393dbb0dccf06e78081ca4f81b56e57ca5a0d056d927d41d1f19d0eb78"), //
digest!("5461f6a04636ec3e513511de5b324e92ec027de3c3c2d5b56edcf28f21a2797e"), //
digest!("aa0fe87d397a845d6c63b7896a031e2fd9d221e02625741ce631cf060542842d"), //
digest!("fd2551902a296fcdc2d49ecbd7b2140b5b8adfb86023e4e2c1ad433e9d4e5487"), //
digest!("204f8e50713cd5da7a41c128d1dd27b722ea0d6c21c785a9a608df13dcadc108"), //
digest!("90d0d9c5bbb5ad02dd004a83e29a6ede8ed35d33a762bbf14f8fd323a8053fbf"), //
digest!("3b652874501bcbb2d3283f4a6640fbc292f9db0c3353b1b5d058c79ab9e684ed"), //
digest!("23ef25c5d5e356bab81c4905e499de9161596435839366c2b0e8fb3c6d8f2232"), //
digest!("bb795263e615f72c0fb6b8d07c8dba82d1a8b5a53870b106ffe738a4f8943dc0"), //
digest!("55330f0d062c6972bf3f65c4e5055544e20c9f776f6797f4428f7b3a6fbf0573"), //
])
.chain([
digest!("1f682e2ecfc82580667b8549ce548310f79f7055195d1f3a70d11565dd7c8311"), //
digest!("66c3c1e1293ec0deea97cd1531a4fb202f7c57c3fa9908598519b12776272f37"), //
digest!("e8a718749c38e77f1a52856568669d38591e5ee3deed15e251b4cd45994e56f7"), //
digest!("3010f3679241489056004ab35e7b0c5feae8a6b45fe46f2c17e65e681e43ef25"), //
digest!("a01d6a57f7aec62ffec3edcc5347c2acb88abdb0460e516d1b7d984f487dfce4"), //
digest!("ba388a957a36a9a514fe5efe738f497fec585e267bcb6fb0a9d79b22f5cb34b1"), //
digest!("e2fba32638e85de83c7ce06c41d48bb159efa0ec58de2e3ed4c172c7fc82b6e5"), //
digest!("d9edf22d1c828087fec2fce4cf46261e8b6e8072b29f4beffbfc36309ae0e9d9"), //
digest!("f04cfc7c358eaa225ee249e88b804a92679b43adf51b5cef1d0fef40c3afbc06"), //
digest!("98b1e437c659b0435b5829a5d2fe697d08fc4b02641747d0f7d6b171b9c83415"), //
digest!("68ada0a6c57d353b2a3645d42854365acd1aa453faebda9988b75c5802f4a1be"), //
]),
),
..Default::default()
});

ctx.succinct_verifier_parameters = Some(SuccinctReceiptVerifierParameters {
control_root: digest!("a516a057c9fbf5629106300934d48e0e775d4230e41e503347cad96fcbde7e2e"),
..Default::default()
});

ctx.groth16_verifier_parameters = Some(Groth16ReceiptVerifierParameters {
control_root: digest!("a516a057c9fbf5629106300934d48e0e775d4230e41e503347cad96fcbde7e2e"),
bn254_control_id: digest!(
"51b54a62f2aa599aef768744c95de8c7d89bf716e11b1179f05d6cf0bcfeb60e"
),
..Default::default()
});

ctx
}
Loading