cl: use BundleWitness in bundle proof

This commit is contained in:
David Rusu 2024-07-22 18:08:54 +04:00
parent 61388121fb
commit 6463d9c65b
5 changed files with 11 additions and 7 deletions

View File

@ -11,7 +11,7 @@ pub struct Bundle {
pub partials: Vec<PartialTx>,
}
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct BundleWitness {
pub balance_blinding: BalanceWitness,
}

View File

@ -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 = [

View File

@ -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();

View File

@ -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.
}

View File

@ -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);
}