cl: use BundleWitness in bundle proof
This commit is contained in:
parent
61388121fb
commit
6463d9c65b
|
@ -11,7 +11,7 @@ pub struct Bundle {
|
||||||
pub partials: Vec<PartialTx>,
|
pub partials: Vec<PartialTx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct BundleWitness {
|
pub struct BundleWitness {
|
||||||
pub balance_blinding: BalanceWitness,
|
pub balance_blinding: BalanceWitness,
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,7 @@ mod test {
|
||||||
let nf_pk = NullifierSecret::random(&mut rng).commit();
|
let nf_pk = NullifierSecret::random(&mut rng).commit();
|
||||||
let nf_nonce = NullifierNonce::random(&mut rng);
|
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
|
// different notes under same nullifier produce different commitments
|
||||||
let mutation_tests = [
|
let mutation_tests = [
|
||||||
|
|
|
@ -6,12 +6,12 @@ pub struct ProvedBundle {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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.
|
// need to show that bundle is balanced.
|
||||||
// i.e. the sum of ptx balances is 0
|
// i.e. the sum of ptx balances is 0
|
||||||
|
|
||||||
let env = risc0_zkvm::ExecutorEnv::builder()
|
let env = risc0_zkvm::ExecutorEnv::builder()
|
||||||
.write(&balance_witness)
|
.write(&bundle_witness)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -62,6 +62,10 @@ fn test_simple_transfer() {
|
||||||
partials: vec![ptx_witness.commit()],
|
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.
|
assert!(proved_bundle.verify()); // The bundle is balanced.
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
use risc0_zkvm::guest::env;
|
use risc0_zkvm::guest::env;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let zero_witness: cl::BalanceWitness = env::read();
|
let bundle_witness: cl::BundleWitness = env::read();
|
||||||
let zero_balance = cl::Balance::zero(zero_witness);
|
let zero_balance = cl::Balance::zero(bundle_witness.balance_blinding);
|
||||||
env::commit(&zero_balance);
|
env::commit(&zero_balance);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue