diff --git a/cl/src/bundle.rs b/cl/src/bundle.rs index 6d39867..78fb9b1 100644 --- a/cl/src/bundle.rs +++ b/cl/src/bundle.rs @@ -87,7 +87,7 @@ impl Bundle { #[cfg(test)] mod test { use crate::{ - input::InputWitness, note::Note, nullifier::NullifierSecret, output::OutputWitness, + input::InputWitness, note::NoteWitness, nullifier::NullifierSecret, output::OutputWitness, test_util::seed_rng, }; @@ -97,10 +97,10 @@ mod test { fn test_bundle_balance() { let mut rng = seed_rng(0); - let nmo_10_in = InputWitness::random(Note::random(10, "NMO", &mut rng), &mut rng); - let eth_23_in = InputWitness::random(Note::random(23, "ETH", &mut rng), &mut rng); + let nmo_10_in = InputWitness::random(NoteWitness::random(10, "NMO", &mut rng), &mut rng); + let eth_23_in = InputWitness::random(NoteWitness::random(23, "ETH", &mut rng), &mut rng); let crv_4840_out = OutputWitness::random( - Note::random(4840, "CRV", &mut rng), + NoteWitness::random(4840, "CRV", &mut rng), NullifierSecret::random(&mut rng).commit(), // transferring to a random owner &mut rng, ); @@ -125,14 +125,15 @@ mod test { + crate::balance::balance(23, "ETH", eth_23_in.note.balance.blinding)) ); - let crv_4840_in = InputWitness::random(Note::random(4840, "CRV", &mut rng), &mut rng); + let crv_4840_in = + InputWitness::random(NoteWitness::random(4840, "CRV", &mut rng), &mut rng); let nmo_10_out = OutputWitness::random( - Note::random(10, "NMO", &mut rng), + NoteWitness::random(10, "NMO", &mut rng), NullifierSecret::random(&mut rng).commit(), // transferring to a random owner &mut rng, ); let eth_23_out = OutputWitness::random( - Note::random(23, "ETH", &mut rng), + NoteWitness::random(23, "ETH", &mut rng), NullifierSecret::random(&mut rng).commit(), // transferring to a random owner &mut rng, ); diff --git a/cl/src/input.rs b/cl/src/input.rs index 5e155dc..eb13aec 100644 --- a/cl/src/input.rs +++ b/cl/src/input.rs @@ -5,7 +5,7 @@ use crate::{ balance::Balance, error::Error, - note::{Note, NoteCommitment}, + note::{NoteCommitment, NoteWitness}, nullifier::{Nullifier, NullifierNonce, NullifierSecret}, partial_tx::PtxCommitment, }; @@ -22,13 +22,13 @@ pub struct Input { #[derive(Debug, Clone)] pub struct InputWitness { - pub note: Note, + pub note: NoteWitness, pub nf_sk: NullifierSecret, pub nonce: NullifierNonce, } impl InputWitness { - pub fn random(note: Note, mut rng: impl RngCore) -> Self { + pub fn random(note: NoteWitness, mut rng: impl RngCore) -> Self { Self { note, nf_sk: NullifierSecret::random(&mut rng), @@ -133,7 +133,7 @@ mod test { let ptx_comm = PtxCommitment::default(); - let note = Note::random(10, "NMO", &mut rng); + let note = NoteWitness::random(10, "NMO", &mut rng); let nf_sk = NullifierSecret::random(&mut rng); let nonce = NullifierNonce::random(&mut rng); @@ -146,11 +146,11 @@ mod test { let wrong_witnesses = [ InputWitness { - note: Note::random(11, "NMO", &mut rng), + note: NoteWitness::random(11, "NMO", &mut rng), ..witness.clone() }, InputWitness { - note: Note::random(10, "ETH", &mut rng), + note: NoteWitness::random(10, "ETH", &mut rng), ..witness.clone() }, InputWitness { @@ -176,7 +176,7 @@ mod test { fn test_input_ptx_coupling() { let mut rng = seed_rng(0); - let note = Note::random(10, "NMO", &mut rng); + let note = NoteWitness::random(10, "NMO", &mut rng); let nf_sk = NullifierSecret::random(&mut rng); let nonce = NullifierNonce::random(&mut rng); diff --git a/cl/src/note.rs b/cl/src/note.rs index 969bbd3..443d604 100644 --- a/cl/src/note.rs +++ b/cl/src/note.rs @@ -21,12 +21,12 @@ impl NoteCommitment { // TODO: Rename Note to NoteWitness and NoteCommitment to Note #[derive(Debug, Clone)] -pub struct Note { +pub struct NoteWitness { pub balance: BalanceWitness, pub death_constraint: Vec, // serialized death_constraint } -impl Note { +impl NoteWitness { pub fn random( value: u64, unit: impl Into, @@ -73,8 +73,8 @@ mod test { #[test] fn test_note_commitments_dont_commit_to_balance_blinding() { let mut rng = seed_rng(0); - let n1 = Note::random(12, "NMO", &mut rng); - let n2 = Note::random(12, "NMO", &mut rng); + let n1 = NoteWitness::random(12, "NMO", &mut rng); + let n2 = NoteWitness::random(12, "NMO", &mut rng); let nf_pk = NullifierSecret::random(&mut rng).commit(); let nonce = NullifierNonce::random(&mut rng); diff --git a/cl/src/output.rs b/cl/src/output.rs index f6f18fb..ea6a553 100644 --- a/cl/src/output.rs +++ b/cl/src/output.rs @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize}; use crate::{ balance::Balance, error::Error, - note::{Note, NoteCommitment}, + note::{NoteCommitment, NoteWitness}, nullifier::{NullifierCommitment, NullifierNonce}, }; @@ -16,13 +16,13 @@ pub struct Output { #[derive(Debug, Clone)] pub struct OutputWitness { - pub note: Note, + pub note: NoteWitness, pub nf_pk: NullifierCommitment, pub nonce: NullifierNonce, } impl OutputWitness { - pub fn random(note: Note, owner: NullifierCommitment, mut rng: impl RngCore) -> Self { + pub fn random(note: NoteWitness, owner: NullifierCommitment, mut rng: impl RngCore) -> Self { Self { note, nf_pk: owner, @@ -78,7 +78,7 @@ mod test { fn test_output_proof() { let mut rng = seed_rng(0); - let note = Note::random(10, "NMO", &mut rng); + let note = NoteWitness::random(10, "NMO", &mut rng); let nf_pk = NullifierSecret::random(&mut rng).commit(); let nonce = NullifierNonce::random(&mut rng); @@ -91,11 +91,11 @@ mod test { let wrong_witnesses = [ OutputWitness { - note: Note::random(11, "NMO", &mut rng), + note: NoteWitness::random(11, "NMO", &mut rng), ..witness.clone() }, OutputWitness { - note: Note::random(10, "ETH", &mut rng), + note: NoteWitness::random(10, "ETH", &mut rng), ..witness.clone() }, OutputWitness { diff --git a/cl/src/partial_tx.rs b/cl/src/partial_tx.rs index a302172..e1d037c 100644 --- a/cl/src/partial_tx.rs +++ b/cl/src/partial_tx.rs @@ -138,7 +138,7 @@ impl PartialTx { #[cfg(test)] mod test { - use crate::{note::Note, nullifier::NullifierSecret, test_util::seed_rng}; + use crate::{note::NoteWitness, nullifier::NullifierSecret, test_util::seed_rng}; use super::*; @@ -146,10 +146,10 @@ mod test { fn test_partial_tx_proof() { let mut rng = seed_rng(0); - let nmo_10 = InputWitness::random(Note::random(10, "NMO", &mut rng), &mut rng); - let eth_23 = InputWitness::random(Note::random(23, "ETH", &mut rng), &mut rng); + let nmo_10 = InputWitness::random(NoteWitness::random(10, "NMO", &mut rng), &mut rng); + let eth_23 = InputWitness::random(NoteWitness::random(23, "ETH", &mut rng), &mut rng); let crv_4840 = OutputWitness::random( - Note::random(4840, "CRV", &mut rng), + NoteWitness::random(4840, "CRV", &mut rng), NullifierSecret::random(&mut rng).commit(), // transferring to a random owner &mut rng, ); @@ -170,10 +170,10 @@ mod test { fn test_partial_tx_balance() { let mut rng = seed_rng(0); - let nmo_10 = InputWitness::random(Note::random(10, "NMO", &mut rng), &mut rng); - let eth_23 = InputWitness::random(Note::random(23, "ETH", &mut rng), &mut rng); + let nmo_10 = InputWitness::random(NoteWitness::random(10, "NMO", &mut rng), &mut rng); + let eth_23 = InputWitness::random(NoteWitness::random(23, "ETH", &mut rng), &mut rng); let crv_4840 = OutputWitness::random( - Note::random(4840, "CRV", &mut rng), + NoteWitness::random(4840, "CRV", &mut rng), NullifierSecret::random(&mut rng).commit(), // transferring to a random owner &mut rng, );