From bba55382456fee1ae1f56c8537f5d8fec6ddd7ed Mon Sep 17 00:00:00 2001 From: Bertrand Darbon Date: Mon, 24 Feb 2025 17:13:54 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=92=A5=20Explicit=20verifier=20versio?= =?UTF-8?q?ns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now the "verifier" value is like "risc0-1.2.3" you can use hyle-verifiers::RISC0_VERSION to get the value --- Cargo.lock | 9 +++++++++ crates/hyle-verifiers/Cargo.toml | 5 ++++- crates/hyle-verifiers/build.rs | 34 ++++++++++++++++++++++++++++++++ crates/hyle-verifiers/src/lib.rs | 2 ++ src/genesis.rs | 8 ++++---- src/mempool/verifiers.rs | 10 +++++----- tests/fixtures/contracts.rs | 8 ++++---- tests/uuid_test.rs | 4 ++-- 8 files changed, 64 insertions(+), 16 deletions(-) create mode 100644 crates/hyle-verifiers/build.rs diff --git a/Cargo.lock b/Cargo.lock index e5a77d2f..428fead8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -960,6 +960,14 @@ dependencies = [ "serde", ] +[[package]] +name = "cargo-toml-parser" +version = "0.2.0" +dependencies = [ + "serde", + "toml", +] + [[package]] name = "cargo_metadata" version = "0.18.1" @@ -2664,6 +2672,7 @@ dependencies = [ "anyhow", "bincode", "borsh", + "cargo-toml-parser", "hyle-model", "rand 0.9.0", "risc0-zkvm", diff --git a/crates/hyle-verifiers/Cargo.toml b/crates/hyle-verifiers/Cargo.toml index abf1ac05..20cbed0b 100644 --- a/crates/hyle-verifiers/Cargo.toml +++ b/crates/hyle-verifiers/Cargo.toml @@ -18,7 +18,7 @@ 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 = [ @@ -26,6 +26,9 @@ test-log = { version = "0.2.17", features = [ "trace", ], default-features = false } +[build-dependencies] +cargo-toml-parser = { path = "/home/bertrand/workspace/cargo-toml-parser" } + [features] default = [] sp1 = ["dep:sp1-sdk", "dep:bincode"] diff --git a/crates/hyle-verifiers/build.rs b/crates/hyle-verifiers/build.rs new file mode 100644 index 00000000..9f8502ac --- /dev/null +++ b/crates/hyle-verifiers/build.rs @@ -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(); +} diff --git a/crates/hyle-verifiers/src/lib.rs b/crates/hyle-verifiers/src/lib.rs index f6bdd7fb..9bb0c530 100644 --- a/crates/hyle-verifiers/src/lib.rs +++ b/crates/hyle-verifiers/src/lib.rs @@ -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}; diff --git a/src/genesis.rs b/src/genesis.rs index d0dbb937..68686721 100644 --- a/src/genesis.rs +++ b/src/genesis.rs @@ -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(), ) @@ -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(), ) @@ -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(), ) @@ -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(), ) diff --git a/src/mempool/verifiers.rs b/src/mempool/verifiers.rs index db54de2b..0f398ce3 100644 --- a/src/mempool/verifiers.rs +++ b/src/mempool/verifiers.rs @@ -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::() { @@ -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| { @@ -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::>() @@ -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(()), } } diff --git a/tests/fixtures/contracts.rs b/tests/fixtures/contracts.rs index 8b54f36c..24c35c76 100644 --- a/tests/fixtures/contracts.rs +++ b/tests/fixtures/contracts.rs @@ -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 { @@ -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 { @@ -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 { @@ -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 { diff --git a/tests/uuid_test.rs b/tests/uuid_test.rs index e4cb4f8d..e4a603aa 100644 --- a/tests/uuid_test.rs +++ b/tests/uuid_test.rs @@ -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()) @@ -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"); From 696677df70e2f76360e71519b281f0d2ebc19dcd Mon Sep 17 00:00:00 2001 From: Bertrand Darbon Date: Mon, 24 Feb 2025 17:22:10 +0100 Subject: [PATCH 2/2] fix cargo --- Cargo.lock | 4 +++- crates/hyle-verifiers/Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 428fead8..352074f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -962,7 +962,9 @@ dependencies = [ [[package]] name = "cargo-toml-parser" -version = "0.2.0" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14656017de701d73f0af4787d9ec0f942ffa6eb6e428c5389c39b5e4f863c80" dependencies = [ "serde", "toml", diff --git a/crates/hyle-verifiers/Cargo.toml b/crates/hyle-verifiers/Cargo.toml index 20cbed0b..04afd3f6 100644 --- a/crates/hyle-verifiers/Cargo.toml +++ b/crates/hyle-verifiers/Cargo.toml @@ -27,7 +27,7 @@ test-log = { version = "0.2.17", features = [ ], default-features = false } [build-dependencies] -cargo-toml-parser = { path = "/home/bertrand/workspace/cargo-toml-parser" } +cargo-toml-parser = "0.2.1" [features] default = []