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

💥 Explicit verifier versions #824

Open
wants to merge 2 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
11 changes: 11 additions & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion crates/hyle-verifiers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ risc0-zkvm = { version = "1.2.4", default-features = false, features = ["std"] }
tracing = "0.1"

sp1-sdk = { version = "4.1.1", default-features = false, optional = true }
bincode = {version = "1.3.3", optional = true}
bincode = { version = "1.3.3", optional = true }

[dev-dependencies]
test-log = { version = "0.2.17", features = [
"color",
"trace",
], default-features = false }

[build-dependencies]
cargo-toml-parser = "0.2.1"

[features]
default = []
sp1 = ["dep:sp1-sdk", "dep:bincode"]
34 changes: 34 additions & 0 deletions crates/hyle-verifiers/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::env;
use std::fs::File;
use std::io::{Read, Write};
use std::path::Path;

fn main() {
// Lire le fichier Cargo.toml
let mut cargo_toml_content = String::new();
File::open("Cargo.toml")
.unwrap()
.read_to_string(&mut cargo_toml_content)
.unwrap();

let cargo_toml = cargo_toml_parser::parse_cargo_toml(&cargo_toml_content).unwrap();

// Chemin vers le fichier généré
let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("dependency_versions.rs");

// Écrire les versions dans un fichier
let mut f = File::create(&dest_path).unwrap();
writeln!(
f,
"pub const RISC0_VERSION: &str = \"risc0-{}\";",
cargo_toml.get_dependency("risc0-zkvm").unwrap().version
)
.unwrap();
writeln!(
f,
"pub const SP1_VERSION: &str = \"sp1-{}\";",
cargo_toml.get_dependency("sp1-sdk").unwrap().version
)
.unwrap();
}
2 changes: 2 additions & 0 deletions crates/hyle-verifiers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use anyhow::{bail, Context, Error};
use hyle_model::{HyleOutput, ProgramId};
use rand::Rng;

include!(concat!(env!("OUT_DIR"), "/dependency_versions.rs"));

#[cfg(feature = "sp1")]
use sp1_sdk::{ProverClient, SP1ProofWithPublicValues, SP1VerifyingKey};

Expand Down
8 changes: 4 additions & 4 deletions src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ impl Genesis {
register_hyle_contract(
&mut register_tx,
"staking".into(),
"risc0".into(),
hyle_verifiers::RISC0_VERSION.into(),
staking_program_id.clone().into(),
ctx.staking.as_digest(),
)
Expand All @@ -436,7 +436,7 @@ impl Genesis {
register_hyle_contract(
&mut register_tx,
"hyllar".into(),
"risc0".into(),
hyle_verifiers::RISC0_VERSION.into(),
hyllar_program_id.clone().into(),
ctx.hyllar.as_digest(),
)
Expand All @@ -445,7 +445,7 @@ impl Genesis {
register_hyle_contract(
&mut register_tx,
"hydentity".into(),
"risc0".into(),
hyle_verifiers::RISC0_VERSION.into(),
hydentity_program_id.clone().into(),
ctx.hydentity.as_digest(),
)
Expand All @@ -454,7 +454,7 @@ impl Genesis {
register_hyle_contract(
&mut register_tx,
"risc0-recursion".into(),
"risc0".into(),
hyle_verifiers::RISC0_VERSION.into(),
hyle_contracts::RISC0_RECURSION_ID.to_vec().into(),
StateDigest::default(),
)
Expand Down
10 changes: 5 additions & 5 deletions src/mempool/verifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub fn verify_proof(
tracing::info!("Woke up from sleep");
Ok(serde_json::from_slice(&proof.0)?)
}
"risc0" => {
hyle_verifiers::RISC0_VERSION => {
let journal = risc0_proof_verifier(&proof.0, &program_id.0)?;
// First try to decode it as a single HyleOutput
Ok(match journal.decode::<HyleOutput>() {
Expand All @@ -47,7 +47,7 @@ pub fn verify_proof(
}
"noir" => noir_proof_verifier(&proof.0, &program_id.0),
#[cfg(feature = "sp1")]
"sp1" => hyle_verifiers::sp1_proof_verifier(&proof.0, &program_id.0),
hyle_verifiers::SP1_VERSION => hyle_verifiers::sp1_proof_verifier(&proof.0, &program_id.0),
_ => Err(anyhow::anyhow!("{} verifier not implemented yet", verifier)),
}?;
hyle_outputs.iter().for_each(|hyle_output| {
Expand All @@ -70,7 +70,7 @@ pub fn verify_recursive_proof(
use risc0_recursion::{Risc0Journal, Risc0ProgramId};

let outputs = match verifier.0.as_str() {
"risc0" => {
hyle_verifiers::RISC0_VERSION => {
let journal = risc0_proof_verifier(&proof.0, &program_id.0)?;
let mut output = journal
.decode::<Vec<(Risc0ProgramId, Risc0Journal)>>()
Expand Down Expand Up @@ -175,9 +175,9 @@ pub fn verify_native_impl(

pub fn validate_program_id(verifier: &Verifier, program_id: &ProgramId) -> Result<()> {
match verifier.0.as_str() {
"risc0" => validate_risc0_program_id(program_id),
hyle_verifiers::RISC0_VERSION => validate_risc0_program_id(program_id),
#[cfg(feature = "sp1")]
"sp1" => hyle_verifiers::validate_sp1_program_id(program_id),
hyle_verifiers::SP1_VERSION => hyle_verifiers::validate_sp1_program_id(program_id),
_ => Ok(()),
}
}
8 changes: 4 additions & 4 deletions tests/fixtures/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct ERC20TestContract {}

impl E2EContract for ERC20TestContract {
fn verifier() -> Verifier {
"risc0".into()
hyle_verifiers::RISC0_VERSION.into()
}

fn program_id() -> ProgramId {
Expand All @@ -30,7 +30,7 @@ pub struct HydentityTestContract {}

impl E2EContract for HydentityTestContract {
fn verifier() -> Verifier {
"risc0".into()
hyle_verifiers::RISC0_VERSION.into()
}

fn program_id() -> ProgramId {
Expand All @@ -46,7 +46,7 @@ pub struct HyllarTestContract {}

impl E2EContract for HyllarTestContract {
fn verifier() -> Verifier {
"risc0".into()
hyle_verifiers::RISC0_VERSION.into()
}

fn program_id() -> ProgramId {
Expand All @@ -62,7 +62,7 @@ pub struct AmmTestContract {}

impl E2EContract for AmmTestContract {
fn verifier() -> Verifier {
"risc0".into()
hyle_verifiers::RISC0_VERSION.into()
}

fn program_id() -> ProgramId {
Expand Down
4 changes: 2 additions & 2 deletions tests/uuid_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod fixtures;
struct UuidContract {}
impl E2EContract for UuidContract {
fn verifier() -> Verifier {
Verifier("risc0".into())
Verifier(hyle_verifiers::RISC0_VERSION.into())
}
fn program_id() -> ProgramId {
ProgramId(UUID_TLD_ID.to_vec())
Expand Down Expand Up @@ -102,7 +102,7 @@ async fn test_uuid_registration() {

let outputs = verify_proof(
&uuid_proof.proof,
&Verifier("risc0".into()),
&Verifier(hyle_verifiers::RISC0_VERSION.into()),
&ProgramId(UUID_TLD_ID.to_vec()),
)
.expect("Must validate proof");
Expand Down
Loading