diff --git a/goas/cl/cl/src/bundle.rs b/goas/cl/cl/src/bundle.rs index 137ff4d..226cb94 100644 --- a/goas/cl/cl/src/bundle.rs +++ b/goas/cl/cl/src/bundle.rs @@ -63,7 +63,9 @@ mod test { let bundle_witness = BundleWitness { balance: BalanceWitness::new( - crv_4840_out.balance.0 - nmo_10_in.balance.0 - eth_23_in.balance.0, + crv_4840_out.balance_blinding.0 + - nmo_10_in.balance_blinding.0 + - eth_23_in.balance_blinding.0, ), }; @@ -74,9 +76,16 @@ mod test { assert!(!bundle.is_balanced(bundle_witness.balance)); assert_eq!( bundle.balance(), - crate::balance::balance(4840, hash_to_curve(b"CRV"), crv_4840_out.balance.0) - - (crate::balance::balance(10, hash_to_curve(b"NMO"), nmo_10_in.balance.0) - + crate::balance::balance(23, hash_to_curve(b"ETH"), eth_23_in.balance.0)) + crate::balance::balance(4840, hash_to_curve(b"CRV"), crv_4840_out.balance_blinding.0) + - (crate::balance::balance( + 10, + hash_to_curve(b"NMO"), + nmo_10_in.balance_blinding.0 + ) + crate::balance::balance( + 23, + hash_to_curve(b"ETH"), + eth_23_in.balance_blinding.0 + )) ); let crv_4840_in = InputWitness::random(crv_4840_out, nf_c, &mut rng); @@ -100,10 +109,11 @@ mod test { let witness = BundleWitness { balance: BalanceWitness::new( - -nmo_10_in.balance.0 - eth_23_in.balance.0 + crv_4840_out.balance.0 - - crv_4840_in.balance.0 - + nmo_10_out.balance.0 - + eth_23_out.balance.0, + -nmo_10_in.balance_blinding.0 - eth_23_in.balance_blinding.0 + + crv_4840_out.balance_blinding.0 + - crv_4840_in.balance_blinding.0 + + nmo_10_out.balance_blinding.0 + + eth_23_out.balance_blinding.0, ), }; diff --git a/goas/cl/cl/src/input.rs b/goas/cl/cl/src/input.rs index c2d53ee..246952d 100644 --- a/goas/cl/cl/src/input.rs +++ b/goas/cl/cl/src/input.rs @@ -21,8 +21,8 @@ pub struct Input { #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub struct InputWitness { pub note: NoteWitness, - pub utxo_balance: BalanceWitness, - pub balance: BalanceWitness, + pub utxo_balance_blinding: BalanceWitness, + pub balance_blinding: BalanceWitness, pub nf_sk: NullifierSecret, pub nonce: NullifierNonce, } @@ -36,8 +36,8 @@ impl InputWitness { assert_eq!(nf_sk.commit(), output.nf_pk); Self { note: output.note, - utxo_balance: output.balance, - balance: BalanceWitness::random(&mut rng), + utxo_balance_blinding: output.balance_blinding, + balance_blinding: BalanceWitness::random(&mut rng), nf_sk, nonce: output.nonce, } @@ -50,7 +50,7 @@ impl InputWitness { pub fn commit(&self) -> Input { Input { nullifier: self.nullifier(), - balance: self.balance.commit(&self.note), + balance: self.balance_blinding.commit(&self.note), death_cm: self.note.death_commitment(), } } @@ -58,7 +58,7 @@ impl InputWitness { pub fn to_output(&self) -> crate::OutputWitness { crate::OutputWitness { note: self.note, - balance: self.utxo_balance, + balance_blinding: self.utxo_balance_blinding, nf_pk: self.nf_sk.commit(), nonce: self.nonce, } diff --git a/goas/cl/cl/src/output.rs b/goas/cl/cl/src/output.rs index 743f92d..ec71c6a 100644 --- a/goas/cl/cl/src/output.rs +++ b/goas/cl/cl/src/output.rs @@ -18,7 +18,7 @@ pub struct Output { #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub struct OutputWitness { pub note: NoteWitness, - pub balance: BalanceWitness, + pub balance_blinding: BalanceWitness, pub nf_pk: NullifierCommitment, pub nonce: NullifierNonce, } @@ -31,7 +31,7 @@ impl OutputWitness { ) -> Self { Self { note, - balance: BalanceWitness::random(&mut rng), + balance_blinding: BalanceWitness::random(&mut rng), nf_pk: owner, nonce: NullifierNonce::random(&mut rng), } @@ -42,7 +42,7 @@ impl OutputWitness { } pub fn commit_balance(&self) -> Balance { - self.balance.commit(&self.note) + self.balance_blinding.commit(&self.note) } pub fn commit(&self) -> Output { @@ -60,7 +60,7 @@ pub struct OutputProof(OutputWitness); impl Output { pub fn prove(&self, w: &OutputWitness) -> Result { if &w.commit() == self { - Ok(OutputProof(w.clone())) + Ok(OutputProof(*w)) } else { Err(Error::ProofFailed) } @@ -94,7 +94,7 @@ mod test { let witness = OutputWitness { note: NoteWitness::basic(10, "NMO"), - balance: BalanceWitness::random(&mut rng), + balance_blinding: BalanceWitness::random(&mut rng), nf_pk: NullifierSecret::random(&mut rng).commit(), nonce: NullifierNonce::random(&mut rng), }; @@ -114,7 +114,7 @@ mod test { ..witness.clone() }, OutputWitness { - balance: BalanceWitness::random(&mut rng), + balance_blinding: BalanceWitness::random(&mut rng), ..witness.clone() }, OutputWitness { diff --git a/goas/cl/cl/src/partial_tx.rs b/goas/cl/cl/src/partial_tx.rs index 85e11ab..6be8d77 100644 --- a/goas/cl/cl/src/partial_tx.rs +++ b/goas/cl/cl/src/partial_tx.rs @@ -138,9 +138,13 @@ mod test { assert_eq!( ptx.balance(), - crate::balance::balance(4840, hash_to_curve(b"CRV"), crv_4840.balance.0) - - (crate::balance::balance(10, hash_to_curve(b"NMO"), nmo_10.balance.0) - + crate::balance::balance(23, hash_to_curve(b"ETH"), eth_23.balance.0)) + crate::balance::balance(4840, hash_to_curve(b"CRV"), crv_4840.balance_blinding.0) + - (crate::balance::balance(10, hash_to_curve(b"NMO"), nmo_10.balance_blinding.0) + + crate::balance::balance( + 23, + hash_to_curve(b"ETH"), + eth_23.balance_blinding.0 + )) ); } } diff --git a/goas/cl/ledger/src/input.rs b/goas/cl/ledger/src/input.rs index 3e8cf66..ace8e0f 100644 --- a/goas/cl/ledger/src/input.rs +++ b/goas/cl/ledger/src/input.rs @@ -25,7 +25,7 @@ impl InputProof { } pub fn prove_input(input: cl::InputWitness, note_commitments: &[cl::NoteCommitment]) -> InputProof { - let output_cm = input.to_output_witness().commit_note(); + let output_cm = input.to_output().commit_note(); let cm_leaves = note_commitment_leaves(note_commitments); let cm_idx = note_commitments @@ -80,17 +80,16 @@ mod test { #[test] fn test_input_nullifier_prover() { let mut rng = thread_rng(); + let input = cl::InputWitness { - note: cl::NoteWitness { - balance: cl::BalanceWitness::random(32, "NMO", &mut rng), - death_constraint: [0u8; 32], - state: [0u8; 32], - }, + note: cl::NoteWitness::basic(32, "NMO"), + utxo_balance_blinding: cl::BalanceWitness::random(&mut rng), + balance_blinding: cl::BalanceWitness::random(&mut rng), nf_sk: cl::NullifierSecret::random(&mut rng), nonce: cl::NullifierNonce::random(&mut rng), }; - let notes = vec![input.to_output_witness().commit_note()]; + let notes = vec![input.to_output().commit_note()]; let proof = prove_input(input, ¬es); @@ -125,7 +124,8 @@ mod test { }, InputPublic { input: cl::Input { - balance: cl::BalanceWitness::random(32, "NMO", &mut rng).commit(), + balance: cl::BalanceWitness::random(&mut rng) + .commit(&cl::NoteWitness::basic(32, "NMO")), ..expected_public_inputs.input }, ..expected_public_inputs diff --git a/goas/cl/proof_statements/src/ptx.rs b/goas/cl/proof_statements/src/ptx.rs index 7c7f9d7..2428e09 100644 --- a/goas/cl/proof_statements/src/ptx.rs +++ b/goas/cl/proof_statements/src/ptx.rs @@ -15,7 +15,7 @@ impl PartialTxInputPrivate { } pub fn cm_root(&self) -> [u8; 32] { - let leaf = merkle::leaf(self.input.to_output_witness().commit_note().as_bytes()); + let leaf = merkle::leaf(self.input.to_output().commit_note().as_bytes()); merkle::path_root(leaf, &self.cm_path) } } diff --git a/goas/cl/risc0_proofs/input/src/main.rs b/goas/cl/risc0_proofs/input/src/main.rs index b84517f..fa63ab3 100644 --- a/goas/cl/risc0_proofs/input/src/main.rs +++ b/goas/cl/risc0_proofs/input/src/main.rs @@ -6,7 +6,7 @@ use risc0_zkvm::guest::env; fn main() { let secret: InputPrivate = env::read(); - let out_cm = secret.input.to_output_witness().commit_note(); + let out_cm = secret.input.to_output().commit_note(); let cm_leaf = merkle::leaf(out_cm.as_bytes()); let cm_root = merkle::path_root(cm_leaf, &secret.cm_path); diff --git a/goas/zone/risc0_proofs/spend_zone_funds/src/main.rs b/goas/zone/risc0_proofs/spend_zone_funds/src/main.rs index 18a00ea..97beecd 100644 --- a/goas/zone/risc0_proofs/spend_zone_funds/src/main.rs +++ b/goas/zone/risc0_proofs/spend_zone_funds/src/main.rs @@ -39,19 +39,18 @@ fn main() { let change = in_zone_funds .input .note - .balance .value .checked_sub(spend_event.amount) .unwrap(); - assert_eq!(out_zone_funds.output.note.balance.value, change); + assert_eq!(out_zone_funds.output.note.value, change); // zone funds output should have the same death constraints as the zone funds input assert_eq!( out_zone_funds.output.note.death_constraint, in_zone_funds.input.note.death_constraint ); assert_eq!( - out_zone_funds.output.note.balance.unit, - in_zone_funds.input.note.balance.unit + out_zone_funds.output.note.unit, + in_zone_funds.input.note.unit ); // zone funds nullifier, nonce and value blinding should be public so that everybody can spend it assert_eq!( @@ -59,8 +58,8 @@ fn main() { NullifierSecret::from_bytes([0; 16]).commit() ); assert_eq!( - out_zone_funds.output.note.balance.blinding, - in_zone_funds.input.note.balance.blinding + out_zone_funds.output.balance_blinding, + in_zone_funds.input.balance_blinding ); let mut evolved_nonce = [0; 16]; evolved_nonce[..16] @@ -73,11 +72,8 @@ fn main() { assert_eq!(ptx_root, spent_note.ptx_root()); // check the correct amount of funds is being spent - assert_eq!(spent_note.output.note.balance.value, spend_event.amount); - assert_eq!( - spent_note.output.note.balance.unit, - in_zone_funds.input.note.balance.unit - ); + assert_eq!(spent_note.output.note.value, spend_event.amount); + assert_eq!(spent_note.output.note.unit, in_zone_funds.input.note.unit); // check the correct recipient is being paid assert_eq!(spent_note.output.nf_pk, spend_event.to);