From 6463d9c65b8b6411683104196ca977830991a34a Mon Sep 17 00:00:00 2001 From: David Rusu Date: Mon, 22 Jul 2024 18:08:54 +0400 Subject: [PATCH] cl: use BundleWitness in bundle proof --- goas/cl/cl/src/bundle.rs | 2 +- goas/cl/cl/src/note.rs | 2 +- goas/cl/ledger/src/bundle.rs | 4 ++-- goas/cl/ledger/tests/simple_transfer.rs | 6 +++++- goas/cl/risc0_proofs/bundle/src/main.rs | 4 ++-- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/goas/cl/cl/src/bundle.rs b/goas/cl/cl/src/bundle.rs index f38585f..e215f92 100644 --- a/goas/cl/cl/src/bundle.rs +++ b/goas/cl/cl/src/bundle.rs @@ -11,7 +11,7 @@ pub struct Bundle { pub partials: Vec, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub struct BundleWitness { pub balance_blinding: BalanceWitness, } diff --git a/goas/cl/cl/src/note.rs b/goas/cl/cl/src/note.rs index f853476..10a773e 100644 --- a/goas/cl/cl/src/note.rs +++ b/goas/cl/cl/src/note.rs @@ -103,7 +103,7 @@ mod test { let nf_pk = NullifierSecret::random(&mut rng).commit(); let nf_nonce = NullifierNonce::random(&mut rng); - let reference_note = NoteWitness::new(32, "NMO", [0u8; 32]); + let reference_note = NoteWitness::basic(32, "NMO"); // different notes under same nullifier produce different commitments let mutation_tests = [ diff --git a/goas/cl/ledger/src/bundle.rs b/goas/cl/ledger/src/bundle.rs index 096a8aa..7517be3 100644 --- a/goas/cl/ledger/src/bundle.rs +++ b/goas/cl/ledger/src/bundle.rs @@ -6,12 +6,12 @@ pub struct ProvedBundle { } impl ProvedBundle { - pub fn prove(bundle: &cl::Bundle, balance_witness: &cl::BalanceWitness) -> Self { + pub fn prove(bundle: &cl::Bundle, bundle_witness: &cl::BundleWitness) -> Self { // need to show that bundle is balanced. // i.e. the sum of ptx balances is 0 let env = risc0_zkvm::ExecutorEnv::builder() - .write(&balance_witness) + .write(&bundle_witness) .unwrap() .build() .unwrap(); diff --git a/goas/cl/ledger/tests/simple_transfer.rs b/goas/cl/ledger/tests/simple_transfer.rs index 66fad90..ecccc91 100644 --- a/goas/cl/ledger/tests/simple_transfer.rs +++ b/goas/cl/ledger/tests/simple_transfer.rs @@ -62,6 +62,10 @@ fn test_simple_transfer() { partials: vec![ptx_witness.commit()], }; - let proved_bundle = ProvedBundle::prove(&bundle, &ptx_witness.balance_blinding()); + let bundle_witness = cl::BundleWitness { + balance_blinding: ptx_witness.balance_blinding(), + }; + + let proved_bundle = ProvedBundle::prove(&bundle, &bundle_witness); assert!(proved_bundle.verify()); // The bundle is balanced. } diff --git a/goas/cl/risc0_proofs/bundle/src/main.rs b/goas/cl/risc0_proofs/bundle/src/main.rs index ac84364..d55efec 100644 --- a/goas/cl/risc0_proofs/bundle/src/main.rs +++ b/goas/cl/risc0_proofs/bundle/src/main.rs @@ -11,7 +11,7 @@ use risc0_zkvm::guest::env; fn main() { - let zero_witness: cl::BalanceWitness = env::read(); - let zero_balance = cl::Balance::zero(zero_witness); + let bundle_witness: cl::BundleWitness = env::read(); + let zero_balance = cl::Balance::zero(bundle_witness.balance_blinding); env::commit(&zero_balance); }