mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-02 13:23:10 +00:00
use risc0 method for image_id computaiton
This commit is contained in:
parent
e8f660c2c7
commit
69b610269b
@ -4,16 +4,16 @@ curl -L https://risczero.com/install | bash
|
||||
/home/runner/.risc0/bin/rzup install
|
||||
source env.sh
|
||||
|
||||
RISC0_DEV_MODE=1 cargo test --release
|
||||
RISC0_DEV_MODE=1 cargo test --release --features no_docker
|
||||
|
||||
cd integration_tests
|
||||
export NSSA_WALLET_HOME_DIR=$(pwd)/configs/debug/wallet/
|
||||
export RUST_LOG=info
|
||||
cargo run $(pwd)/configs/debug all
|
||||
cargo run $(pwd)/configs/debug all --features no_docker
|
||||
echo "Try test valid proof at least once"
|
||||
cargo run $(pwd)/configs/debug test_success_private_transfer_to_another_owned_account
|
||||
cargo run $(pwd)/configs/debug test_success_private_transfer_to_another_owned_account --features no_docker
|
||||
echo "Continuing in dev mode"
|
||||
RISC0_DEV_MODE=1 cargo run $(pwd)/configs/debug all
|
||||
RISC0_DEV_MODE=1 cargo run $(pwd)/configs/debug all --features no_docker
|
||||
cd ..
|
||||
|
||||
cd nssa/program_methods/guest && cargo test --release
|
||||
cd nssa/program_methods/guest && cargo test --release --features no_docker
|
||||
|
||||
@ -7,7 +7,7 @@ edition = "2024"
|
||||
thiserror = "2.0.12"
|
||||
risc0-zkvm = { version = "3.0.3", features = ['std'] }
|
||||
nssa-core = { path = "core", features = ["host"] }
|
||||
program-methods = { path = "program_methods" }
|
||||
program-methods = { path = "program_methods", optional = true }
|
||||
serde = "1.0.219"
|
||||
sha2 = "0.10.9"
|
||||
secp256k1 = "0.31.1"
|
||||
@ -17,6 +17,7 @@ hex = "0.4.3"
|
||||
|
||||
[build-dependencies]
|
||||
risc0-build = "3.0.3"
|
||||
risc0-binfmt = "3.0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
test-program-methods = { path = "test_program_methods" }
|
||||
@ -24,3 +25,4 @@ hex-literal = "1.0.0"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
no_docker = ["program-methods"]
|
||||
|
||||
@ -1,66 +1,63 @@
|
||||
use std::{env, fs, path::Path, process::Command};
|
||||
use risc0_build::a;
|
||||
|
||||
fn main() {
|
||||
// 1️⃣ Crate root and OUT_DIR
|
||||
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
if cfg!(feature = "no_docker") {
|
||||
println!("cargo:warning=NO_DOCKER feature enabled – deterministic build skipped");
|
||||
return;
|
||||
}
|
||||
|
||||
// 2️⃣ Directory to write generated module
|
||||
let mod_dir = Path::new(&out_dir).join("nssa_programs");
|
||||
build_deterministic().expect("Deterministic build failed");
|
||||
}
|
||||
|
||||
fn build_deterministic() -> Result<(), Box<dyn std::error::Error>> {
|
||||
use std::{env, fs, path::PathBuf, process::Command};
|
||||
|
||||
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?);
|
||||
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
|
||||
let mod_dir = out_dir.join("program_methods");
|
||||
let mod_file = mod_dir.join("mod.rs");
|
||||
|
||||
println!("cargo:rerun-if-changed=program_methods/guest");
|
||||
println!("cargo:rerun-if-changed=program_methods/guest/src");
|
||||
println!("cargo:rerun-if-changed=program_methods/guest/Cargo.toml");
|
||||
|
||||
// 3️⃣ Build the Risc0 guest program
|
||||
let guest_manifest = Path::new(&manifest_dir)
|
||||
.join("program_methods/guest/Cargo.toml");
|
||||
let guest_manifest = manifest_dir.join("program_methods/guest/Cargo.toml");
|
||||
|
||||
let status = Command::new("cargo")
|
||||
.arg("risczero")
|
||||
.arg("build")
|
||||
.arg("--manifest-path")
|
||||
.args(["risczero", "build", "--manifest-path"])
|
||||
.arg(&guest_manifest)
|
||||
.status()
|
||||
.expect("failed to run risczero build");
|
||||
assert!(status.success(), "Risc0 deterministic build failed");
|
||||
.status()?;
|
||||
if !status.success() {
|
||||
return Err("Risc0 deterministic build failed".into());
|
||||
}
|
||||
|
||||
// 4️⃣ Target directory where the Risc0 build produces .bin files
|
||||
let target_dir = Path::new(&manifest_dir)
|
||||
.join("program_methods/guest/target/riscv32im-risc0-zkvm-elf/docker/");
|
||||
let target_dir =
|
||||
manifest_dir.join("program_methods/guest/target/riscv32im-risc0-zkvm-elf/docker/");
|
||||
|
||||
println!("cargo:warning=Looking for binaries in {}", target_dir.display());
|
||||
|
||||
// 5️⃣ Collect all .bin files
|
||||
let bins = fs::read_dir(&target_dir)
|
||||
.expect("failed to read external target dir")
|
||||
let bins = fs::read_dir(&target_dir)?
|
||||
.filter_map(Result::ok)
|
||||
.filter(|e| e.path().extension().map(|ext| ext == "bin").unwrap_or(false))
|
||||
.filter(|e| e.path().extension().is_some_and(|ext| ext == "bin"))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if bins.is_empty() {
|
||||
panic!("No .bin files found in {:?}", target_dir);
|
||||
return Err(format!("No .bin files found in {:?}", target_dir).into());
|
||||
}
|
||||
|
||||
println!("cargo:warning=Found {} binaries:", bins.len());
|
||||
for b in &bins {
|
||||
println!("cargo:warning= - {}", b.path().display());
|
||||
}
|
||||
|
||||
// 6️⃣ Generate Rust module
|
||||
fs::create_dir_all(&mod_dir).unwrap();
|
||||
fs::create_dir_all(&mod_dir)?;
|
||||
let mut src = String::new();
|
||||
for entry in bins {
|
||||
let path = entry.path();
|
||||
let name = path.file_stem().unwrap().to_string_lossy();
|
||||
let bytecode = fs::read(&path)?;
|
||||
let image_id: [u32; 8] = risc0_binfmt::compute_image_id(&bytecode)?.into();
|
||||
src.push_str(&format!(
|
||||
"pub const {}_ELF: &[u8] = include_bytes!(r#\"{}\"#);\n",
|
||||
"pub const {}_ELF: &[u8] = include_bytes!(r#\"{}\"#);\n\
|
||||
pub const {}_ID: [u32; 8] = {:?};\n",
|
||||
name.to_uppercase(),
|
||||
path.display()
|
||||
path.display(),
|
||||
name.to_uppercase(),
|
||||
image_id
|
||||
));
|
||||
}
|
||||
|
||||
fs::write(&mod_file, src).unwrap();
|
||||
fs::write(&mod_file, src)?;
|
||||
println!("cargo:warning=Generated module at {}", mod_file.display());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
pub mod programs {
|
||||
include!(concat!(env!("OUT_DIR"), "/nssa_programs/mod.rs"));
|
||||
#[cfg(not(feature = "no_docker"))]
|
||||
pub mod program_methods {
|
||||
include!(concat!(env!("OUT_DIR"), "/program_methods/mod.rs"));
|
||||
}
|
||||
|
||||
#[cfg(feature = "no_docker")]
|
||||
use program_methods;
|
||||
|
||||
pub mod encoding;
|
||||
pub mod error;
|
||||
mod merkle_tree;
|
||||
|
||||
@ -8,7 +8,7 @@ use risc0_zkvm::{ExecutorEnv, InnerReceipt, Receipt, default_prover};
|
||||
|
||||
use crate::{error::NssaError, program::Program};
|
||||
|
||||
use program_methods::{PRIVACY_PRESERVING_CIRCUIT_ELF, PRIVACY_PRESERVING_CIRCUIT_ID};
|
||||
use crate::program_methods::{PRIVACY_PRESERVING_CIRCUIT_ELF, PRIVACY_PRESERVING_CIRCUIT_ID};
|
||||
|
||||
/// Proof of the privacy preserving execution circuit
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
||||
@ -2,7 +2,7 @@ use nssa_core::{
|
||||
account::{Account, AccountWithMetadata},
|
||||
program::{InstructionData, ProgramId, ProgramOutput},
|
||||
};
|
||||
use crate::programs::{
|
||||
use crate::program_methods::{
|
||||
AUTHENTICATED_TRANSFER_ELF, AUTHENTICATED_TRANSFER_ID, PINATA_ELF, PINATA_ID, TOKEN_ELF,
|
||||
TOKEN_ID,
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user