From f27dc71b9b8ef5550fb8bb084f222c43dc2df778 Mon Sep 17 00:00:00 2001 From: Sergio Chouhy Date: Mon, 11 Aug 2025 14:22:51 -0300 Subject: [PATCH] restructure project --- Cargo.toml | 5 - chacha20-demo/Cargo.toml | 10 +- chacha20-demo/build.log | 256 ------------------------- chacha20-demo/build.rs | 4 - chacha20-demo/methods/Cargo.toml | 2 +- chacha20-demo/methods/guest/src/lib.rs | 22 --- chacha20-demo/src/lib.rs | 37 ---- chacha20-demo/src/main.rs | 27 +-- chacha20-demo/tests/bad_guest.rs | 21 +- chacha20-demo/tests/proof_works.rs | 36 ++-- chacha20-demo/tests/wrong_image_id.rs | 16 +- 11 files changed, 44 insertions(+), 392 deletions(-) delete mode 100644 Cargo.toml delete mode 100644 chacha20-demo/build.log delete mode 100644 chacha20-demo/build.rs delete mode 100644 chacha20-demo/methods/guest/src/lib.rs delete mode 100644 chacha20-demo/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index f41b7e2..0000000 --- a/Cargo.toml +++ /dev/null @@ -1,5 +0,0 @@ -[workspace] -resolver = "2" -members = [ - "chacha20-demo", -] diff --git a/chacha20-demo/Cargo.toml b/chacha20-demo/Cargo.toml index ccb9bb1..06379fd 100644 --- a/chacha20-demo/Cargo.toml +++ b/chacha20-demo/Cargo.toml @@ -2,23 +2,15 @@ name = "encryption-demo" version = "0.1.0" edition = "2021" -build = "build.rs" [dependencies] risc0-zkvm = { version = "2.3.1", features = ["std", "prove"] } anyhow = "1.0" hex = "0.4" +methods = {path = "methods"} [dev-dependencies] chacha20 = "0.9" cipher = { version = "0.4", features = ["std"] } -[build-dependencies] -risc0-build = "2.3.1" - -[package.metadata.risc0] -methods = ["methods/guest"] - -[lints.rust] -unexpected_cfgs = { level = "allow", check-cfg = ['cfg(rust_analyzer)'] } diff --git a/chacha20-demo/build.log b/chacha20-demo/build.log deleted file mode 100644 index 54c533e..0000000 --- a/chacha20-demo/build.log +++ /dev/null @@ -1,256 +0,0 @@ - Compiling proc-macro2 v1.0.95 - Compiling unicode-ident v1.0.18 - Compiling libc v0.2.174 - Compiling version_check v0.9.5 - Compiling serde v1.0.219 - Compiling typenum v1.18.0 - Compiling zerocopy v0.8.26 - Compiling cfg-if v1.0.1 - Compiling once_cell v1.21.3 - Compiling paste v1.0.15 - Compiling subtle v2.6.1 - Compiling pin-project-lite v0.2.16 - Compiling autocfg v1.5.0 - Compiling rand_core v0.6.4 - Compiling thiserror v2.0.12 - Compiling generic-array v0.14.7 - Compiling ahash v0.8.12 - Compiling hashbrown v0.15.4 - Compiling equivalent v1.0.2 - Compiling const-oid v0.9.6 - Compiling winnow v0.7.12 - Compiling toml_write v0.1.2 - Compiling anyhow v1.0.98 - Compiling indexmap v2.10.0 - Compiling tracing-core v0.1.34 - Compiling log v0.4.27 - Compiling cfg_aliases v0.2.1 - Compiling semver v1.0.26 - Compiling borsh v1.5.7 - Compiling num-traits v0.2.19 - Compiling stable_deref_trait v1.2.0 - Compiling memchr v2.7.5 - Compiling quote v1.0.40 - Compiling bitflags v2.9.1 - Compiling syn v2.0.104 - Compiling itoa v1.0.15 - Compiling cpufeatures v0.2.17 - Compiling getrandom v0.3.3 - Compiling allocator-api2 v0.2.21 - Compiling futures-core v0.3.31 - Compiling unicode-xid v0.2.6 - Compiling rustix v1.0.8 - Compiling serde_json v1.0.142 - Compiling shlex v1.3.0 - Compiling ident_case v1.0.1 - Compiling rustversion v1.0.21 - Compiling fnv v1.0.7 - Compiling strsim v0.11.1 - Compiling cc v1.2.31 - Compiling mio v1.0.4 - Compiling socket2 v0.6.0 - Compiling either v1.15.0 - Compiling core-foundation-sys v0.8.7 - Compiling num-integer v0.1.46 - Compiling camino v1.1.10 - Compiling futures-sink v0.3.31 - Compiling crypto-common v0.1.6 - Compiling block-buffer v0.10.4 - Compiling arrayvec v0.7.6 - Compiling core-foundation v0.9.4 - Compiling digest v0.10.7 - Compiling itertools v0.13.0 - Compiling ppv-lite86 v0.2.21 - Compiling num-bigint v0.4.6 - Compiling sha2 v0.10.9 - Compiling blake2 v0.10.6 - Compiling malloc_buf v0.0.6 - Compiling rand_chacha v0.3.1 - Compiling heck v0.5.0 - Compiling bitflags v1.3.2 - Compiling smallvec v1.15.1 - Compiling rand v0.8.5 - Compiling ring v0.17.14 - Compiling syn v1.0.109 - Compiling litemap v0.8.0 - Compiling hex v0.4.3 - Compiling writeable v0.6.1 - Compiling foreign-types-shared v0.3.1 - Compiling core-graphics-types v0.1.3 - Compiling ark-std v0.5.0 - Compiling objc v0.2.7 - Compiling risc0-zkp v2.0.2 - Compiling block v0.1.6 - Compiling icu_normalizer_data v2.0.0 - Compiling futures-io v0.3.31 - Compiling icu_properties_data v2.0.1 - Compiling futures-task v0.3.31 - Compiling pin-utils v0.1.0 - Compiling synstructure v0.13.2 - Compiling darling_core v0.20.11 - Compiling slab v0.4.10 - Compiling futures-util v0.3.31 - Compiling getrandom v0.2.16 - Compiling percent-encoding v2.3.1 - Compiling hex-literal v0.4.1 - Compiling untrusted v0.9.0 - Compiling httparse v1.10.1 - Compiling rustls v0.23.31 - Compiling try-lock v0.2.5 - Compiling spin v0.9.8 - Compiling ryu v1.0.20 - Compiling tower-service v0.3.3 - Compiling lazy_static v1.5.0 - Compiling want v0.3.1 - Compiling serde_derive v1.0.219 - Compiling tracing-attributes v0.1.30 - Compiling zeroize_derive v1.4.2 - Compiling thiserror-impl v2.0.12 - Compiling bytemuck_derive v1.8.1 - Compiling foreign-types-macros v0.2.3 - Compiling zerofrom-derive v0.1.6 - Compiling zeroize v1.8.1 - Compiling yoke-derive v0.8.0 - Compiling stability v0.2.1 - Compiling zerovec-derive v0.11.1 - Compiling displaydoc v0.2.5 - Compiling enum-ordinalize-derive v4.3.1 - Compiling tracing v0.1.41 - Compiling derive_more-impl v2.0.1 - Compiling ark-serialize-derive v0.5.0 - Compiling darling_macro v0.20.11 - Compiling ark-ff-macros v0.5.0 - Compiling enum-ordinalize v4.3.0 - Compiling ark-ff-asm v0.5.0 - Compiling darling v0.20.11 - Compiling zerofrom v0.1.6 - Compiling ark-serialize v0.5.0 - Compiling bytemuck v1.23.1 - Compiling foreign-types v0.5.0 - Compiling strum_macros v0.26.4 - Compiling educe v0.6.0 - Compiling risc0-zkvm-platform v2.0.3 - Compiling rustls-pki-types v1.12.0 - Compiling derive_builder_core v0.20.2 - Compiling cobs v0.3.0 - Compiling yoke v0.8.0 - Compiling derive_builder_macro v0.20.2 - Compiling derive_more v2.0.1 - Compiling risc0-core v2.0.0 - Compiling metal v0.29.0 - Compiling futures-channel v0.3.31 - Compiling tracing-subscriber v0.2.25 - Compiling proc-macro-error-attr v1.0.4 - Compiling ark-ff v0.5.0 - Compiling zerovec v0.11.4 - Compiling zerotrie v0.2.2 - Compiling rustls-webpki v0.103.4 - Compiling elf v0.7.4 - Compiling hashbrown v0.14.5 - Compiling form_urlencoded v1.2.1 - Compiling aho-corasick v1.1.3 - Compiling toml_datetime v0.6.11 - Compiling serde_spanned v0.6.9 - Compiling toml_edit v0.22.27 - Compiling bytes v1.10.1 - Compiling tinystr v0.8.1 - Compiling potential_utf v0.1.2 - Compiling postcard v1.1.3 - Compiling icu_locale_core v2.0.0 - Compiling icu_collections v2.0.0 - Compiling tokio v1.47.1 - Compiling http v1.3.1 - Compiling icu_provider v2.0.0 - Compiling sync_wrapper v1.0.2 - Compiling keccak v0.1.5 - Compiling errno v0.3.13 - Compiling icu_properties v2.0.1 - Compiling icu_normalizer v2.0.0 - Compiling proc-macro-error v1.0.4 - Compiling http-body v1.0.1 - Compiling proc-macro-crate v3.3.0 - Compiling regex-syntax v0.8.5 - Compiling base64 v0.22.1 - Compiling idna_adapter v1.2.1 - Compiling tower-layer v0.3.3 - Compiling ipnet v2.11.0 - Compiling borsh-derive v1.5.7 - Compiling utf8_iter v1.0.4 - Compiling byteorder v1.5.0 - Compiling merlin v3.0.0 - Compiling idna v1.0.3 - Compiling regex-automata v0.4.9 - Compiling ark-poly v0.5.0 - Compiling ark-relations v0.5.1 - Compiling hyper v1.6.0 - Compiling tower v0.5.2 - Compiling ark-snark v0.5.1 - Compiling tokio-rustls v0.26.2 - Compiling hyper-util v0.1.16 - Compiling hashlink v0.9.1 - Compiling ark-ec v0.5.0 - Compiling risc0-binfmt v2.0.2 - Compiling webpki-roots v1.0.2 - Compiling derivative v2.2.0 - Compiling ark-crypto-primitives-macros v0.5.0 - Compiling risc0-circuit-recursion v3.0.0 - Compiling encoding_rs v0.8.35 - Compiling option-ext v0.2.0 - Compiling arraydeque v0.5.1 - Compiling iri-string v0.7.8 - Compiling thiserror v1.0.69 - Compiling fastrand v2.3.0 - Compiling itertools v0.14.0 - Compiling tempfile v3.20.0 - Compiling dirs-sys v0.4.1 - Compiling yaml-rust2 v0.9.0 - Compiling ark-crypto-primitives v0.5.0 - Compiling tower-http v0.6.6 - Compiling hyper-rustls v0.27.7 - Compiling toml v0.8.23 - Compiling regex v1.11.1 - Compiling tokio-util v0.7.16 - Compiling url v2.5.4 - Compiling http-body-util v0.1.3 - Compiling serde_urlencoded v0.7.1 - Compiling cargo-platform v0.1.9 - Compiling strum v0.26.3 - Compiling thiserror-impl v1.0.69 - Compiling include_bytes_aligned v0.1.4 - Compiling heck v0.4.1 - Compiling no_std_strings v0.1.3 - Compiling duplicate v1.0.0 - Compiling risc0-zkos-v1compat v2.0.1 - Compiling rzup v0.4.1 - Compiling cargo_metadata v0.19.2 - Compiling reqwest v0.12.22 - Compiling lazy-regex-proc_macros v3.4.1 - Compiling ark-groth16 v0.5.0 - Compiling dirs v5.0.1 - Compiling prost-derive v0.13.5 - Compiling ark-bn254 v0.5.0 - Compiling derive_builder v0.20.2 - Compiling maybe-async v0.2.10 - Compiling docker-generate v0.1.3 - Compiling bit-vec v0.8.0 - Compiling downcast-rs v1.2.1 - Compiling rrs-lib v0.1.0 - Compiling risc0-circuit-rv32im v3.0.0 - Compiling risc0-build v2.3.1 - Compiling bonsai-sdk v1.4.0 - Compiling risc0-groth16 v2.0.2 - Compiling prost v0.13.5 - Compiling risc0-circuit-keccak v3.0.0 - Compiling lazy-regex v3.4.1 - Compiling bincode v1.3.3 - Compiling inout v0.1.4 - Compiling host v0.1.0 (/Users/mellaz/Documents/nssa-zkvms/nescience-zkvm-testing/encryption-demo/host) - Compiling cipher v0.4.4 - Compiling chacha20 v0.9.1 -error: failed to run custom build command for `host v0.1.0 (/Users/mellaz/Documents/nssa-zkvms/nescience-zkvm-testing/encryption-demo/host)` - -Caused by: - process didn't exit successfully: `/Users/mellaz/Documents/nssa-zkvms/nescience-zkvm-testing/encryption-demo/target/release/build/host-26fa01eaea54642e/build-script-build` (exit status: 255) - --- stderr - ERROR: No package found in "/Users/mellaz/Documents/nssa-zkvms/nescience-zkvm-testing/encryption-demo/host/../guest" -warning: build failed, waiting for other jobs to finish... diff --git a/chacha20-demo/build.rs b/chacha20-demo/build.rs deleted file mode 100644 index aa600df..0000000 --- a/chacha20-demo/build.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - risc0_build::embed_methods(); -} - diff --git a/chacha20-demo/methods/Cargo.toml b/chacha20-demo/methods/Cargo.toml index 9ab59da..f5da0df 100644 --- a/chacha20-demo/methods/Cargo.toml +++ b/chacha20-demo/methods/Cargo.toml @@ -7,4 +7,4 @@ edition = "2021" risc0-build = { version = "2.3.1" } [package.metadata.risc0] -methods = ["methods/guest"] +methods = ["guest"] diff --git a/chacha20-demo/methods/guest/src/lib.rs b/chacha20-demo/methods/guest/src/lib.rs deleted file mode 100644 index cf0f528..0000000 --- a/chacha20-demo/methods/guest/src/lib.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![no_std] -#![no_main] - -extern crate alloc; -use alloc::vec::Vec; - -use risc0_zkvm::guest::env; -risc0_zkvm::entry!(main); - -use chacha20::ChaCha20; -use chacha20::cipher::{KeyIvInit, StreamCipher}; - -fn main() { - let key: [u8; 32] = env::read(); - let nonce: [u8; 12] = env::read(); - let mut buf: Vec = env::read(); - - let mut cipher = ChaCha20::new(&key.into(), &nonce.into()); - cipher.apply_keystream(&mut buf); - - env::commit_slice(&buf); -} diff --git a/chacha20-demo/src/lib.rs b/chacha20-demo/src/lib.rs deleted file mode 100644 index d2461e1..0000000 --- a/chacha20-demo/src/lib.rs +++ /dev/null @@ -1,37 +0,0 @@ -#[cfg(not(rust_analyzer))] -mod generated { - include!(concat!(env!("OUT_DIR"), "/methods.rs")); -} -#[cfg(not(rust_analyzer))] -pub use generated::{GUEST_ELF, GUEST_ID}; - - -#[cfg(rust_analyzer)] -pub const GUEST_ELF: &[u8] = &[]; -#[cfg(rust_analyzer)] -pub const GUEST_ID: [u32; 8] = [0; 8]; - -use anyhow::Result; -use risc0_zkvm::{default_prover, ExecutorEnv, Receipt}; - - -pub fn prove_encrypt( - key: [u8; 32], - nonce: [u8; 12], - plaintext: &[u8], -) -> Result<(Receipt, Vec)> { - let env = ExecutorEnv::builder() - .write(&key)? - .write(&nonce)? - .write(&plaintext.to_vec())? - .build()?; - - let prover = default_prover(); - let prove_info = prover.prove(env, GUEST_ELF)?; - let receipt = prove_info.receipt; - receipt.verify(GUEST_ID)?; - - let ciphertext: Vec = receipt.journal.bytes.clone(); // if this errors, use .to_vec() - - Ok((receipt, ciphertext)) -} diff --git a/chacha20-demo/src/main.rs b/chacha20-demo/src/main.rs index 61db16b..e799089 100644 --- a/chacha20-demo/src/main.rs +++ b/chacha20-demo/src/main.rs @@ -1,23 +1,13 @@ -#[cfg(not(rust_analyzer))] -include!(concat!(env!("OUT_DIR"), "/methods.rs")); - -#[cfg(rust_analyzer)] -mod methods { - pub const GUEST_ELF: &[u8] = &[]; - pub const GUEST_ID: [u32; 8] = [0; 8]; -} -#[cfg(rust_analyzer)] use methods::*; - -use anyhow::Result; +use anyhow::Result; use hex::encode; use risc0_zkvm::{default_prover, ExecutorEnv}; fn main() -> Result<()> { // Example inputs - let key = [0x42u8; 32]; - let nonce = [0x24u8; 12]; + let key = [0x42u8; 32]; + let nonce = [0x24u8; 12]; let plaintext = b"Hello, RISC Zero ChaCha20 demo!"; let env = ExecutorEnv::builder() @@ -25,12 +15,11 @@ fn main() -> Result<()> { .write(&nonce)? .write(&plaintext.to_vec())? .build()?; - - - let prover = default_prover(); + + let prover = default_prover(); let prove_info = prover.prove(env, GUEST_ELF)?; - let receipt = prove_info.receipt; - + let receipt = prove_info.receipt; + // (Optionally) verify the proof receipt.verify(GUEST_ID)?; @@ -40,5 +29,3 @@ fn main() -> Result<()> { Ok(()) } - - diff --git a/chacha20-demo/tests/bad_guest.rs b/chacha20-demo/tests/bad_guest.rs index 264c226..61a1e4e 100644 --- a/chacha20-demo/tests/bad_guest.rs +++ b/chacha20-demo/tests/bad_guest.rs @@ -1,12 +1,3 @@ -#[cfg(not(rust_analyzer))] -include!(concat!(env!("OUT_DIR"), "/methods.rs")); - -#[cfg(rust_analyzer)] -mod methods { - pub const GUEST_ELF: &[u8] = &[]; - pub const GUEST_ID: [u32; 8] = [0; 8]; -} -#[cfg(rust_analyzer)] use methods::*; use risc0_zkvm::{default_prover, ExecutorEnv}; @@ -19,10 +10,14 @@ fn guest_panics_on_bad_key() { let plaintext = b"panic please".to_vec(); let env = ExecutorEnv::builder() - .write(&key).unwrap() - .write(&nonce).unwrap() - .write(&plaintext).unwrap() - .build().unwrap(); + .write(&key) + .unwrap() + .write(&nonce) + .unwrap() + .write(&plaintext) + .unwrap() + .build() + .unwrap(); // Proving should fail when the guest panics let res = default_prover().prove(env, GUEST_ELF); diff --git a/chacha20-demo/tests/proof_works.rs b/chacha20-demo/tests/proof_works.rs index 74722c6..b7a7ec4 100644 --- a/chacha20-demo/tests/proof_works.rs +++ b/chacha20-demo/tests/proof_works.rs @@ -1,12 +1,3 @@ -#[cfg(not(rust_analyzer))] -include!{concat!(env!("OUT_DIR"), "/methods.rs")} - -#[cfg(rust_analyzer)] -mod methods { - pub const GUEST_ELF: &[u8] = &[]; - pub const GUEST_ID: [u32; 8] = [0; 8]; -} -#[cfg(rust_analyzer)] use methods::*; use risc0_zkvm::{default_prover, ExecutorEnv}; @@ -18,21 +9,26 @@ use cipher::{KeyIvInit, StreamCipher}; #[test] fn proof_works_and_matches_host_chacha() { // Inputs (must match what your guest expects) - let key = [0x42u8; 32]; - let nonce = [0x24u8; 12]; + let key = [0x42u8; 32]; + let nonce = [0x24u8; 12]; let plaintext = b"Hello, RISC Zero ChaCha20 demo!"; // Prove with the R0 guest let env = ExecutorEnv::builder() - .write(&key).unwrap() - .write(&nonce).unwrap() - .write(&plaintext.to_vec()).unwrap() - .build().unwrap(); + .write(&key) + .unwrap() + .write(&nonce) + .unwrap() + .write(&plaintext.to_vec()) + .unwrap() + .build() + .unwrap(); - let prove_info = default_prover().prove(env, GUEST_ELF).expect("prove failed"); + let prove_info = default_prover() + .prove(env, GUEST_ELF) + .expect("prove failed"); prove_info.receipt.verify(GUEST_ID).expect("verify failed"); - // Ciphertext produced by the guest let guest_ct = prove_info.receipt.journal.bytes.clone(); @@ -44,6 +40,8 @@ fn proof_works_and_matches_host_chacha() { cipher.apply_keystream(&mut host_ct); // Compare - assert_eq!(guest_ct, host_ct, "guest ciphertext != host ChaCha20 ciphertext"); - + assert_eq!( + guest_ct, host_ct, + "guest ciphertext != host ChaCha20 ciphertext" + ); } diff --git a/chacha20-demo/tests/wrong_image_id.rs b/chacha20-demo/tests/wrong_image_id.rs index 8097c62..b904b1f 100644 --- a/chacha20-demo/tests/wrong_image_id.rs +++ b/chacha20-demo/tests/wrong_image_id.rs @@ -1,8 +1,6 @@ use anyhow::Result; -use risc0_zkvm::{default_prover, ExecutorEnv, Digest}; - -#[cfg(not(rust_analyzer))] -include!(concat!(env!("OUT_DIR"), "/methods.rs")); +use methods::*; +use risc0_zkvm::{default_prover, Digest, ExecutorEnv}; #[test] fn verify_rejects_wrong_image() -> Result<()> { @@ -11,12 +9,18 @@ fn verify_rejects_wrong_image() -> Result<()> { let plaintext = b"bad id test".to_vec(); let env = ExecutorEnv::builder() - .write(&key)?.write(&nonce)?.write(&plaintext)?.build()?; + .write(&key)? + .write(&nonce)? + .write(&plaintext)? + .build()?; let info = default_prover().prove(env, GUEST_ELF)?; // Intentionally bogus image id let bogus = Digest::from([0u32; 8]); - assert!(info.receipt.verify(bogus).is_err(), "verification should fail"); + assert!( + info.receipt.verify(bogus).is_err(), + "verification should fail" + ); Ok(()) }