move to reproducible builds vis cargo risczero build

This commit is contained in:
David Rusu 2025-03-05 23:22:26 +04:00
parent 40961e0e4c
commit 138f6cfb1c
26 changed files with 111 additions and 46 deletions

View File

@ -4,12 +4,9 @@ members = [
"cl",
"ledger",
"ledger_proof_statements",
"risc0_proofs",
"bundle_risc0_proof",
"tx_risc0_proof",
"ledger_validity_proof",
"risc0_images",
"risc0_images_police",
# "risc0_images_police",
]
# Always optimize; building and running the risc0_proofs takes much longer without optimization.

View File

@ -7,10 +7,9 @@ edition = "2021"
[dependencies]
risc0-zkvm = { version = "1.0", default-features = false, features = ['std'] }
serde = { version = "1.0", features = ["derive"] }
cl = { path = "../../cl" }
ledger_proof_statements = { path = "../../ledger_proof_statements" }
risc0_images = { path = "../../risc0_images" }
risc0_images = { path = "../../risc0_images", features=["nomos_mantle_tx_risc0_proof"] }
hex = "0.4"
[patch.crates-io]

View File

@ -1,4 +1,5 @@
use cl::crust::BundleWitness;
use hex::FromHex;
use risc0_zkvm::{guest::env, serde};
fn main() {
@ -6,7 +7,7 @@ fn main() {
for tx in &bundle_private.txs {
env::verify(
risc0_images::nomos_mantle_tx_risc0_proof::TX_ID,
<[u8; 32]>::from_hex(risc0_images::BUNDLE_ID).unwrap(),
&serde::to_vec(&tx).unwrap(),
)
.unwrap();

View File

@ -3,22 +3,14 @@ name = "cl"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde = {version="1.0", features = ["derive"]}
group = "0.13.0"
rand = "0.8.5"
rand_core = "0.6.0"
hex = "0.4.3"
curve25519-dalek = {version = "4.1", features = ["serde", "digest", "rand_core"]}
sha2 = "0.10"
lazy_static = "1.5.0"
risc0-zkvm = "1.2"
itertools = "0.14"
digest = "0.10"
[dev-dependencies]
rand = "0.8.5"
proptest = "1.2.0"
proptest-macro = "0.1"

View File

@ -6,7 +6,7 @@ use crate::{
mantle::ZoneId,
Digest, Hash,
};
use rand::RngCore;
use rand_core::RngCore;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]

View File

@ -1,7 +1,6 @@
use crate::crust::{balance::Unit, nullifier::NullifierCommitment};
use crate::mantle::ZoneId;
use crate::{Digest, Hash};
use rand::RngCore;
use serde::{Deserialize, Serialize};
#[cfg(test)]

View File

@ -2,8 +2,9 @@ pub mod crust;
pub mod ds;
pub mod mantle;
pub type Hash = risc0_zkvm::sha::rust_crypto::Sha256;
pub use digest::Digest;
pub use risc0_zkvm::sha::rust_crypto::{Digest, Sha256};
pub type Hash = Sha256;
pub fn hash(data: &[u8]) -> [u8; 32] {
let mut hasher = Hash::new();

View File

@ -5,13 +5,48 @@ set -e
# proof's id changes, then the parent proof will also change, but we don't see the
# parent's id change until the next run.
cargo run --bin gen_risc0_images > risc0_images/src/lib.rs.new
proofs=$(cat <<EOF
tx_risc0_proof/tx
risc0_proofs/stf_nop
ledger_validity_proof/ledger
bundle_risc0_proof/bundle
EOF
)
for proof in $proofs; do
echo "Building $proof"
# Run the cargo risczero build command and process output line by line
cargo risczero build --manifest-path "$proof/Cargo.toml" | while read -r line; do
# Parse out the
if [[ $line =~ ImageID:\ ([0-9a-f]+)\ -\ \"(.+)\" ]]; then
image_id="${BASH_REMATCH[1]}"
image_elf="${BASH_REMATCH[2]}"
image_name=$(basename $image_elf | tr '[:lower:]' '[:upper:]')
echo "ID: $image_id"
echo "ELF: $image_elf"
cp $image_elf "risc0_images/src/${image_name}_ELF"
echo $image_id > "risc0_images/src/${image_name}_ID"
fi
done
done
exit
cargo run --release --bin gen_risc0_images > risc0_images/src/lib.rs.new
while ! cmp -s risc0_images/src/lib.rs.new risc0_images/src/lib.rs
do
mv risc0_images/src/lib.rs.new risc0_images/src/lib.rs
cargo run --bin gen_risc0_images > risc0_images/src/lib.rs.new
echo "-------- FINISHED UPDATE ITERATION --------"
echo "FOLLOWING PROOF IDS HAVE CHANGED:"
diff risc0_images/src/lib.rs.new risc0_images/src/lib.rs | rg '_ID' | grep "^<" | while read line; do id=$(echo "$line" | grep -o "[A-Z_]*_ID"); if [ -n "$id" ]; then hash=$(echo -n "$line" | sha256sum | cut -d" " -f1); echo " - $id ${hash:0:5}"; fi; done
echo "FOLLOWING PROOF ELFS HAVE CHANGED:"
diff risc0_images/src/lib.rs.new risc0_images/src/lib.rs | rg '_ELF' | grep "^<" | while read line; do elf=$(echo "$line" | grep -o "[A-Z_]*_ELF"); if [ -n "$elf" ]; then hash=$(echo -n "$line" | sha256sum | cut -d" " -f1); echo " - $elf ${hash:0:5}"; fi; done
mv risc0_images/src/lib.rs.new risc0_images/src/lib.rs
cargo run --release --bin gen_risc0_images > risc0_images/src/lib.rs.new
echo "-------- FINISHED UPDATE ITERATION --------"
done
rm risc0_images/src/lib.rs.new

View File

@ -6,9 +6,10 @@ edition = "2021"
[dependencies]
cl = { path = "../cl" }
ledger_proof_statements = { path = "../ledger_proof_statements" }
risc0_images = { path = "../risc0_images" }
risc0_images = { path = "../risc0_images", features = ["all"]}
risc0-zkvm = { version = "1.0", features = ["prove", "metal"] }
risc0-groth16 = { version = "1.0" }
rand = "0.8.5"
rand_core = "0.6.0"
thiserror = "1.0.62"
thiserror = "1.0.62"
hex = "0.4"

View File

@ -1,6 +1,8 @@
use crate::tx::ProvedTx;
use cl::crust::{Bundle, BundleWitness};
use hex::FromHex;
#[derive(Debug, Clone)]
pub struct ProvedBundle {
pub risc0_receipt: risc0_zkvm::Receipt,
@ -50,7 +52,10 @@ impl ProvedBundle {
pub fn verify(&self) -> bool {
self.risc0_receipt
.verify(risc0_images::nomos_mantle_bundle_risc0_proof::BUNDLE_ID)
.verify(
<[u8; 32]>::from_hex(risc0_images::nomos_mantle_bundle_risc0_proof::BUNDLE_ID)
.unwrap(),
)
.is_ok()
}
}

View File

@ -5,6 +5,8 @@ use ledger_proof_statements::ledger::{LedgerBundleWitness, LedgerProofPrivate, L
use crate::bundle::ProvedBundle;
use cl::mantle::{ledger::LedgerState, zone::ZoneId};
use hex::FromHex;
#[derive(Debug, Clone)]
pub struct ProvedLedgerTransition {
pub risc0_receipt: risc0_zkvm::Receipt,
@ -99,7 +101,7 @@ impl ProvedLedgerTransition {
pub fn verify(&self) -> bool {
self.risc0_receipt
.verify(risc0_images::ledger_validity_proof::LEDGER_ID)
.verify(<[u8; 32]>::from_hex(risc0_images::ledger_validity_proof::LEDGER_ID).unwrap())
.is_ok()
}
}

View File

@ -1,9 +1,11 @@
use cl::mantle::zone::Stf;
use ledger_proof_statements::stf::StfPublic;
use hex::FromHex;
#[derive(Debug, Clone)]
pub struct StfProof {
pub risc0_id: [u32; 8],
pub risc0_id: [u8; 32],
pub public: StfPublic,
pub risc0_receipt: risc0_zkvm::Receipt,
}
@ -15,7 +17,7 @@ pub fn risc0_stf(risc0_id: [u32; 8]) -> Stf {
}
impl StfProof {
pub fn from_risc0(risc0_id: [u32; 8], risc0_receipt: risc0_zkvm::Receipt) -> Self {
pub fn from_risc0(risc0_id: [u8; 32], risc0_receipt: risc0_zkvm::Receipt) -> Self {
Self {
risc0_id,
public: risc0_receipt.journal.decode().unwrap(),
@ -24,14 +26,14 @@ impl StfProof {
}
pub fn stf(&self) -> Stf {
risc0_stf(self.risc0_id)
self.risc0_id
}
pub fn verify(&self) -> bool {
self.risc0_receipt.verify(self.risc0_id).is_ok()
}
pub fn nop_stf() -> [u8; 32] {
risc0_stf(risc0_images::nomos_mantle_risc0_proofs::STF_NOP_ID)
FromHex::from_hex(risc0_images::nomos_mantle_risc0_proofs::STF_NOP_ID).unwrap()
}
pub fn prove_nop(public: StfPublic) -> Self {
@ -64,7 +66,8 @@ impl StfProof {
let receipt = prove_info.receipt;
Self {
risc0_id: risc0_images::nomos_mantle_risc0_proofs::STF_NOP_ID,
risc0_id: FromHex::from_hex(risc0_images::nomos_mantle_risc0_proofs::STF_NOP_ID)
.unwrap(),
public,
risc0_receipt: receipt,
}

View File

@ -3,6 +3,7 @@ use crate::{
error::{Error, Result},
};
use cl::crust::{Tx, TxWitness};
use hex::FromHex;
#[derive(Debug, Clone)]
pub struct ProvedTx {
@ -61,7 +62,7 @@ impl ProvedTx {
pub fn verify(&self) -> bool {
self.risc0_receipt
.verify(risc0_images::nomos_mantle_tx_risc0_proof::TX_ID)
.verify(<[u8; 32]>::from_hex(risc0_images::nomos_mantle_tx_risc0_proof::TX_ID).unwrap())
.is_ok()
}
}

View File

@ -10,7 +10,8 @@ risc0-zkvm = { version = "1.0", default-features = false, features = ['std'] }
serde = { version = "1.0", features = ["derive"] }
cl = { path = "../../cl" }
ledger_proof_statements = { path = "../../ledger_proof_statements" }
risc0_images = { path = "../../risc0_images" }
risc0_images = { path = "../../risc0_images", features = ["nomos_mantle_bundle_risc0_proof"] }
hex = "0.4"
[patch.crates-io]
# add RISC Zero accelerator support for all downstream usages of the following crates.

View File

@ -1,4 +1,5 @@
use cl::ds::merkle;
use hex::FromHex;
use ledger_proof_statements::ledger::{
LedgerBundleWitness, LedgerProofPrivate, LedgerProofPublic, SyncLog,
};
@ -23,7 +24,7 @@ fn main() {
} in bundles
{
env::verify(
risc0_images::nomos_mantle_bundle_risc0_proof::BUNDLE_ID,
<[u8; 32]>::from_hex(risc0_images::nomos_mantle_bundle_risc0_proof::BUNDLE_ID).unwrap(),
&serde::to_vec(&bundle).unwrap(),
)
.unwrap();

View File

@ -4,4 +4,14 @@ version = "0.1.0"
edition = "2021"
[dependencies]
binary_macros = "1.0.0"
binary_macros = "1.0.0"
hex = "0.4"
lazy_static = "1.5.0"
[features]
default = []
all = ["nomos_mantle_tx_risc0_proof", "nomos_mantle_risc0_proofs", "nomos_mantle_bundle_risc0_proof", "ledger_validity_proof", "elf"]
nomos_mantle_tx_risc0_proof = []
nomos_mantle_risc0_proofs = []
nomos_mantle_bundle_risc0_proof = []
ledger_validity_proof = []
elf = []

Binary file not shown.

View File

@ -0,0 +1 @@
63819c8c6c20d8077b2fb739d30a3914e4a193c35e76d7f867d6ca5dccdb076f

Binary file not shown.

View File

@ -0,0 +1 @@
3d73a931233123f842d3fc10e2b44d770c1bd3c6d1ebd64601d0e11cb60e74cb

Binary file not shown.

View File

@ -0,0 +1 @@
fe255112cc925c6e507222cbdae2030eb271b1e384e0fa8ab25cfe10109fb10f

Binary file not shown.

View File

@ -0,0 +1 @@
de9c0427462cd7fbaff5f640547278a6e41a98dc79445442db2dfe8d0978fc25

File diff suppressed because one or more lines are too long

View File

@ -2,12 +2,15 @@ use base64::prelude::*;
macro_rules! gen_risc0_image {
($module:ident, $id:ident, $elf:ident) => {
println!("#[cfg(feature=\"{}\")]", stringify!($module));
println!("pub mod {} {{", stringify!($module));
println!(
" pub const {}: [u32; 8] = {:?};",
stringify!($id),
$module::$id
);
println!("#[cfg(feature=\"elf\")]");
println!(
" pub static {}: &[u8] = binary_macros::base64!({:?});",
stringify!($elf),