From 9a0ddbb4ff5b38468af22a61ef7ebe82239cb6f4 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 27 Oct 2022 14:31:02 +0300 Subject: [PATCH] rename 2 note_type -> asset as per https://github.com/zcash/orchard/pull/356#discussion_r967636009 --- src/action.rs | 10 ++-- src/builder.rs | 36 +++++++------- src/constants/fixed_bases.rs | 2 +- src/issuance.rs | 66 +++++++++++++------------- src/note.rs | 8 ++-- src/note/{note_type.rs => asset_id.rs} | 0 src/note/commitment.rs | 8 ++-- src/note_encryption.rs | 8 ++-- src/test_vectors/note_encryption.rs | 42 ++++++++-------- src/value.rs | 10 ++-- tests/zsa.rs | 32 ++++++------- 11 files changed, 111 insertions(+), 111 deletions(-) rename src/note/{note_type.rs => asset_id.rs} (100%) diff --git a/src/action.rs b/src/action.rs index eed1e9cc5..94fe4f3f4 100644 --- a/src/action.rs +++ b/src/action.rs @@ -126,7 +126,7 @@ pub(crate) mod testing { use proptest::prelude::*; - use crate::note::note_type::testing::arb_asset_id; + use crate::note::asset_id::testing::arb_asset_id; use crate::{ note::{ commitment::ExtractedNoteCommitment, nullifier::testing::arb_nullifier, @@ -147,13 +147,13 @@ pub(crate) mod testing { nf in arb_nullifier(), rk in arb_spendauth_verification_key(), note in arb_note(output_value), - note_type in arb_asset_id() + asset in arb_asset_id() ) -> Action<()> { let cmx = ExtractedNoteCommitment::from(note.commitment()); let cv_net = ValueCommitment::derive( spend_value - output_value, ValueCommitTrapdoor::zero(), - note_type + asset ); // FIXME: make a real one from the note. let encrypted_note = TransmittedNoteCiphertext { @@ -180,13 +180,13 @@ pub(crate) mod testing { note in arb_note(output_value), rng_seed in prop::array::uniform32(prop::num::u8::ANY), fake_sighash in prop::array::uniform32(prop::num::u8::ANY), - note_type in arb_asset_id() + asset in arb_asset_id() ) -> Action> { let cmx = ExtractedNoteCommitment::from(note.commitment()); let cv_net = ValueCommitment::derive( spend_value - output_value, ValueCommitTrapdoor::zero(), - note_type + asset ); // FIXME: make a real one from the note. diff --git a/src/builder.rs b/src/builder.rs index 950e4b494..f932f3b97 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -74,8 +74,8 @@ impl SpendInfo { /// Defined in [Zcash Protocol Spec § 4.8.3: Dummy Notes (Orchard)][orcharddummynotes]. /// /// [orcharddummynotes]: https://zips.z.cash/protocol/nu5.pdf#orcharddummynotes - fn dummy(note_type: AssetId, rng: &mut impl RngCore) -> Self { - let (sk, fvk, note) = Note::dummy(rng, None, note_type); + fn dummy(asset: AssetId, rng: &mut impl RngCore) -> Self { + let (sk, fvk, note) = Note::dummy(rng, None, asset); let merkle_path = MerklePath::dummy(rng); SpendInfo { @@ -104,7 +104,7 @@ struct RecipientInfo { ovk: Option, recipient: Address, value: NoteValue, - note_type: AssetId, + asset: AssetId, memo: Option<[u8; 512]>, } @@ -112,7 +112,7 @@ impl RecipientInfo { /// Defined in [Zcash Protocol Spec § 4.8.3: Dummy Notes (Orchard)][orcharddummynotes]. /// /// [orcharddummynotes]: https://zips.z.cash/protocol/nu5.pdf#orcharddummynotes - fn dummy(rng: &mut impl RngCore, note_type: AssetId) -> Self { + fn dummy(rng: &mut impl RngCore, asset: AssetId) -> Self { let fvk: FullViewingKey = (&SpendingKey::random(rng)).into(); let recipient = fvk.address_at(0u32, Scope::External); @@ -120,7 +120,7 @@ impl RecipientInfo { ovk: None, recipient, value: NoteValue::zero(), - note_type, + asset, memo: None, } } @@ -167,13 +167,13 @@ impl ActionInfo { fn build(self, mut rng: impl RngCore) -> (Action, Circuit) { assert_eq!( self.spend.note.asset(), - self.output.note_type, + self.output.asset, "spend and recipient note types must be equal" ); let v_net = self.value_sum(); - let note_type = self.output.note_type; - let cv_net = ValueCommitment::derive(v_net, self.rcv, note_type); + let asset = self.output.asset; + let cv_net = ValueCommitment::derive(v_net, self.rcv, asset); let nf_old = self.spend.note.nullifier(&self.spend.fvk); let sender_address = self.spend.note.recipient(); @@ -187,7 +187,7 @@ impl ActionInfo { let note = Note::new( self.output.recipient, self.output.value, - self.output.note_type, + self.output.asset, nf_old, &mut rng, ); @@ -326,7 +326,7 @@ impl Builder { ovk: Option, recipient: Address, value: NoteValue, - note_type: AssetId, + asset: AssetId, memo: Option<[u8; 512]>, ) -> Result<(), &'static str> { if !self.flags.outputs_enabled() { @@ -337,7 +337,7 @@ impl Builder { ovk, recipient, value, - note_type, + asset, memo, }); @@ -355,7 +355,7 @@ impl Builder { let mut pre_actions: Vec<_> = Vec::new(); // Pair up the spends and recipients, extending with dummy values as necessary. - for (note_type, (mut spends, mut recipients)) in + for (asset, (mut spends, mut recipients)) in partition_by_asset(&self.spends, &self.recipients) { let num_spends = spends.len(); @@ -369,16 +369,16 @@ impl Builder { // TODO: uncomment once the circuit is ready. // use the first spend to create split spend(s) or create a dummy if empty. // let dummy_spend = spends.first().map_or_else( - // || SpendInfo::dummy(note_type, &mut rng), + // || SpendInfo::dummy(asset, &mut rng), // |s| s.create_split_spend(), // ); - let dummy_spend = SpendInfo::dummy(note_type, &mut rng); + let dummy_spend = SpendInfo::dummy(asset, &mut rng); // Extend the spends and recipients with dummy values. spends.extend(iter::repeat_with(|| dummy_spend.clone()).take(num_actions - num_spends)); recipients.extend( - iter::repeat_with(|| RecipientInfo::dummy(&mut rng, note_type)) + iter::repeat_with(|| RecipientInfo::dummy(&mut rng, asset)) .take(num_actions - num_recipients), ); @@ -461,7 +461,7 @@ fn partition_by_asset( } for r in recipients { - hm.entry(r.note_type) + hm.entry(r.asset) .or_insert((vec![], vec![])) .1 .push(r.clone()) @@ -776,12 +776,12 @@ pub mod testing { builder.add_spend(fvk.clone(), note, path).unwrap(); } - for (addr, value, note_type) in self.recipient_amounts.into_iter() { + for (addr, value, asset) in self.recipient_amounts.into_iter() { let scope = fvk.scope_for_address(&addr).unwrap(); let ovk = fvk.to_ovk(scope); builder - .add_recipient(Some(ovk.clone()), addr, value, note_type, None) + .add_recipient(Some(ovk.clone()), addr, value, asset, None) .unwrap(); } diff --git a/src/constants/fixed_bases.rs b/src/constants/fixed_bases.rs index d9c92edd3..4b5d1518e 100644 --- a/src/constants/fixed_bases.rs +++ b/src/constants/fixed_bases.rs @@ -22,7 +22,7 @@ pub const ORCHARD_PERSONALIZATION: &str = "z.cash:Orchard"; pub const VALUE_COMMITMENT_PERSONALIZATION: &str = "z.cash:Orchard-cv"; /// SWU hash-to-curve personalization for the note type generator -// pub const NOTE_TYPE_PERSONALIZATION: &str = "z.cash:Orchard-NoteType"; +// pub const ASSET_ID_PERSONALIZATION: &str = "z.cash:Orchard-NoteType"; /// SWU hash-to-curve value for the value commitment generator pub const VALUE_COMMITMENT_V_BYTES: [u8; 1] = *b"v"; diff --git a/src/issuance.rs b/src/issuance.rs index 50bf11f6e..ab93bf5b6 100644 --- a/src/issuance.rs +++ b/src/issuance.rs @@ -12,7 +12,7 @@ use crate::issuance::Error::{ IssueBundleInvalidSignature, WrongAssetDescSize, }; use crate::keys::{IssuanceAuthorizingKey, IssuanceValidatingKey}; -use crate::note::note_type::MAX_ASSET_DESCRIPTION_SIZE; +use crate::note::asset_id::MAX_ASSET_DESCRIPTION_SIZE; use crate::note::{AssetId, Nullifier}; use crate::value::NoteValue; use crate::{ @@ -81,24 +81,24 @@ impl IssueAction { self.finalize } - /// Return the `NoteType` if the provided `ik` is used to derive the `note_type` for **all** internal notes. - fn are_note_types_derived_correctly( + /// Return the `AssetId` if the provided `ik` is used to derive the `asset_id` for **all** internal notes. + fn are_note_asset_ids_derived_correctly( &self, ik: &IssuanceValidatingKey, ) -> Result { match self .notes .iter() - .try_fold(self.notes().head.asset(), |note_type, ¬e| { + .try_fold(self.notes().head.asset(), |asset, ¬e| { // Fail if not all note types are equal note.asset() - .eq(¬e_type) - .then(|| note_type) + .eq(&asset) + .then(|| asset) .ok_or(IssueActionIncorrectNoteType) }) { - Ok(note_type) => note_type // check that the note_type was properly derived. + Ok(asset) => asset // check that the asset was properly derived. .eq(&AssetId::derive(ik, &self.asset_desc)) - .then(|| note_type) + .then(|| asset) .ok_or(IssueBundleIkMismatchNoteType), Err(e) => Err(e), } @@ -162,12 +162,12 @@ impl IssueBundle { self.actions.iter().find(|a| a.asset_desc.eq(&asset_desc)) } - /// Find an action by `note_type` for a given `IssueBundle`. - pub fn get_action_by_type(&self, note_type: AssetId) -> Option<&IssueAction> { + /// Find an action by `asset` for a given `IssueBundle`. + pub fn get_action_by_type(&self, asset: AssetId) -> Option<&IssueAction> { let action = self .actions .iter() - .find(|a| AssetId::derive(&self.ik, &a.asset_desc).eq(¬e_type)); + .find(|a| AssetId::derive(&self.ik, &a.asset_desc).eq(&asset)); action } @@ -207,12 +207,12 @@ impl IssueBundle { return Err(WrongAssetDescSize); } - let note_type = AssetId::derive(&self.ik, &asset_desc); + let asset = AssetId::derive(&self.ik, &asset_desc); let note = Note::new( recipient, value, - note_type, + asset, Nullifier::dummy(&mut rng), &mut rng, ); @@ -238,7 +238,7 @@ impl IssueBundle { } } - Ok(note_type) + Ok(asset) } /// Finalizes a given `IssueAction` @@ -279,7 +279,7 @@ impl IssueBundle { impl IssueBundle { /// Sign the `IssueBundle`. - /// The call makes sure that the provided `isk` matches the `ik` and the driven `note_type` for each note in the bundle. + /// The call makes sure that the provided `isk` matches the `ik` and the driven `asset` for each note in the bundle. pub fn sign( self, mut rng: R, @@ -287,10 +287,10 @@ impl IssueBundle { ) -> Result, Error> { let expected_ik: IssuanceValidatingKey = (isk).into(); - // Make sure the `expected_ik` matches the note_type for all notes. + // Make sure the `expected_ik` matches the `asset` for all notes. self.actions.iter().try_for_each(|action| { action - .are_note_types_derived_correctly(&expected_ik) + .are_note_asset_ids_derived_correctly(&expected_ik) .map(|_| ()) // Transform Result into Result<(),Error)>. })?; @@ -370,19 +370,19 @@ pub fn verify_issue_bundle( } // Fail if any note in the IssueAction has incorrect note type. - let note_type = action.are_note_types_derived_correctly(bundle.ik())?; + let asset = action.are_note_asset_ids_derived_correctly(bundle.ik())?; - // Fail if the current note_type was previously finalized. - if finalized.contains(¬e_type) || acc.contains(¬e_type) { - return Err(IssueActionPreviouslyFinalizedNoteType(note_type)); + // Fail if the current asset was previously finalized. + if finalized.contains(&asset) || acc.contains(&asset) { + return Err(IssueActionPreviouslyFinalizedNoteType(asset)); } // Add to finalization set, if needed. if action.is_finalized() { - acc.insert(note_type); + acc.insert(asset); } - // Proceed with the new accumulated note_type finalization set. + // Proceed with the new asset finalization set. Ok(acc) })?; @@ -525,37 +525,37 @@ mod tests { WrongAssetDescSize ); - let note_type = bundle + let asset = bundle .add_recipient(str.clone(), recipient, NoteValue::from_raw(5), false, rng) .unwrap(); - let another_note_type = bundle + let another_asset = bundle .add_recipient(str, recipient, NoteValue::from_raw(10), false, rng) .unwrap(); - assert_eq!(note_type, another_note_type); + assert_eq!(asset, another_asset); - let third_note_type = bundle + let third_asset = bundle .add_recipient(str2.clone(), recipient, NoteValue::from_raw(15), false, rng) .unwrap(); - assert_ne!(note_type, third_note_type); + assert_ne!(asset, third_asset); let actions = bundle.actions(); assert_eq!(actions.len(), 2); - let action = bundle.get_action_by_type(note_type).unwrap(); + let action = bundle.get_action_by_type(asset).unwrap(); assert_eq!(action.notes.len(), 2); assert_eq!(action.notes.first().value().inner(), 5); - assert_eq!(action.notes.first().asset(), note_type); + assert_eq!(action.notes.first().asset(), asset); assert_eq!(action.notes.first().recipient(), recipient); assert_eq!(action.notes.tail().first().unwrap().value().inner(), 10); - assert_eq!(action.notes.tail().first().unwrap().asset(), note_type); + assert_eq!(action.notes.tail().first().unwrap().asset(), asset); assert_eq!(action.notes.tail().first().unwrap().recipient(), recipient); let action2 = bundle.get_action(str2).unwrap(); assert_eq!(action2.notes.len(), 1); assert_eq!(action2.notes().first().value().inner(), 15); - assert_eq!(action2.notes().first().asset(), third_note_type); + assert_eq!(action2.notes().first().asset(), third_asset); } #[test] @@ -703,7 +703,7 @@ mod tests { } #[test] - fn issue_bundle_incorrect_note_type_for_signature() { + fn issue_bundle_incorrect_asset_for_signature() { let (mut rng, isk, ik, recipient, _) = setup_params(); let mut bundle = IssueBundle::new(ik); diff --git a/src/note.rs b/src/note.rs index bc25917cc..9381a38f6 100644 --- a/src/note.rs +++ b/src/note.rs @@ -19,8 +19,8 @@ pub use self::commitment::{ExtractedNoteCommitment, NoteCommitment}; pub(crate) mod nullifier; pub use self::nullifier::Nullifier; -pub(crate) mod note_type; -pub use self::note_type::AssetId; +pub(crate) mod asset_id; +pub use self::asset_id::AssetId; /// The ZIP 212 seed randomness for a note. #[derive(Copy, Clone, Debug)] @@ -282,8 +282,8 @@ impl fmt::Debug for TransmittedNoteCiphertext { pub mod testing { use proptest::prelude::*; - use crate::note::note_type::testing::arb_asset_id; - use crate::note::note_type::testing::zsa_asset_id; + use crate::note::asset_id::testing::arb_asset_id; + use crate::note::asset_id::testing::zsa_asset_id; use crate::value::testing::arb_note_value; use crate::{ address::testing::arb_address, note::nullifier::testing::arb_nullifier, value::NoteValue, diff --git a/src/note/note_type.rs b/src/note/asset_id.rs similarity index 100% rename from src/note/note_type.rs rename to src/note/asset_id.rs diff --git a/src/note/commitment.rs b/src/note/commitment.rs index 267aed500..f4bc7247b 100644 --- a/src/note/commitment.rs +++ b/src/note/commitment.rs @@ -11,7 +11,7 @@ use crate::{ fixed_bases::{NOTE_COMMITMENT_PERSONALIZATION, NOTE_ZSA_COMMITMENT_PERSONALIZATION}, L_ORCHARD_BASE, }, - note::note_type::AssetId, + note::asset_id::AssetId, spec::extract_p, value::NoteValue, }; @@ -45,7 +45,7 @@ impl NoteCommitment { g_d: [u8; 32], pk_d: [u8; 32], v: NoteValue, - note_type: AssetId, + asset: AssetId, rho: pallas::Base, psi: pallas::Base, rcm: NoteCommitTrapdoor, @@ -64,13 +64,13 @@ impl NoteCommitment { .chain(psi_bits.iter().by_vals().take(L_ORCHARD_BASE)); // TODO: make this constant-time. - if note_type.is_native().into() { + if asset.is_native().into() { // Commit to ZEC notes as per the Orchard protocol. Self::commit(NOTE_COMMITMENT_PERSONALIZATION, zec_note_bits, rcm) } else { // Commit to non-ZEC notes as per the ZSA protocol. // Append the note type to the Orchard note encoding. - let type_bits = BitArray::<_, Lsb0>::new(note_type.to_bytes()); + let type_bits = BitArray::<_, Lsb0>::new(asset.to_bytes()); let zsa_note_bits = zec_note_bits.chain(type_bits.iter().by_vals()); // Commit in a different domain than Orchard notes. diff --git a/src/note_encryption.rs b/src/note_encryption.rs index 71db1f9bd..612b6d87f 100644 --- a/src/note_encryption.rs +++ b/src/note_encryption.rs @@ -183,7 +183,7 @@ impl Domain for OrchardDomain { np[0] = if is_native { 0x02 } else { 0x03 }; np[1..12].copy_from_slice(note.recipient().diversifier().as_array()); np[12..20].copy_from_slice(¬e.value().to_bytes()); - // todo: add note_type + // todo: add asset_id np[20..52].copy_from_slice(note.rseed().as_bytes()); if is_native { np[52..].copy_from_slice(memo); @@ -493,12 +493,12 @@ mod tests { let recipient = Address::from_parts(d, pk_d); - let note_type = match tv.note_type { + let asset = match tv.asset { None => AssetId::native(), Some(type_bytes) => AssetId::from_bytes(&type_bytes).unwrap(), }; - let note = Note::from_parts(recipient, value, note_type, rho, rseed); + let note = Note::from_parts(recipient, value, asset, rho, rseed); assert_eq!(ExtractedNoteCommitment::from(note.commitment()), cmx); let action = Action::from_parts( @@ -537,7 +537,7 @@ mod tests { assert_eq!(decrypted_note, note); assert_eq!(decrypted_to, recipient); } - None => assert!(tv.note_type.is_some(), "Compact note decryption failed"), + None => assert!(tv.asset.is_some(), "Compact note decryption failed"), // Ignore that ZSA notes are not detected in compact decryption. } diff --git a/src/test_vectors/note_encryption.rs b/src/test_vectors/note_encryption.rs index 7d2b7c960..9501a79b1 100644 --- a/src/test_vectors/note_encryption.rs +++ b/src/test_vectors/note_encryption.rs @@ -20,7 +20,7 @@ pub(crate) struct TestVector { pub(crate) ock: [u8; 32], pub(crate) op: [u8; 64], pub(crate) c_out: [u8; 80], - pub(crate) note_type: Option<[u8; 32]>, + pub(crate) asset: Option<[u8; 32]>, } pub(crate) fn test_vectors() -> Vec { @@ -233,7 +233,7 @@ pub(crate) fn test_vectors() -> Vec { 0x2d, 0xb5, 0x96, 0x9d, 0x8d, 0x2f, 0x32, 0x25, 0x91, 0x9c, 0xe3, 0x88, 0x26, 0x41, 0x5c, 0xc6, 0xb3, 0x38, 0x94, 0x4b, 0x48, 0x99, 0x54, 0x8b, ], - note_type: None, + asset: None, }, TestVector { incoming_viewing_key: [ @@ -443,7 +443,7 @@ pub(crate) fn test_vectors() -> Vec { 0x4d, 0xde, 0x70, 0x49, 0x48, 0x72, 0xb2, 0x20, 0x8a, 0x7c, 0x58, 0x02, 0xdf, 0xe9, 0xbd, 0x1c, 0xa1, 0x9b, 0xef, 0x4b, 0x37, 0xc6, 0x13, 0xb2, ], - note_type: None, + asset: None, }, TestVector { incoming_viewing_key: [ @@ -653,7 +653,7 @@ pub(crate) fn test_vectors() -> Vec { 0x0e, 0x01, 0x86, 0x45, 0x32, 0xa3, 0x57, 0x2c, 0x68, 0xaf, 0xe4, 0x0a, 0xc3, 0xc0, 0x95, 0x7b, 0x7a, 0xfc, 0x23, 0xfd, 0x5e, 0x05, 0x17, 0xaa, ], - note_type: None, + asset: None, }, TestVector { incoming_viewing_key: [ @@ -863,7 +863,7 @@ pub(crate) fn test_vectors() -> Vec { 0xd1, 0x4c, 0xf8, 0xe8, 0xe2, 0x8e, 0xa2, 0x5c, 0x18, 0x62, 0x7a, 0x84, 0xa2, 0xbe, 0x96, 0x1f, 0x44, 0x72, 0x67, 0x67, 0xe9, 0xf8, 0x43, 0x1b, ], - note_type: None, + asset: None, }, TestVector { incoming_viewing_key: [ @@ -1073,7 +1073,7 @@ pub(crate) fn test_vectors() -> Vec { 0x2e, 0xe8, 0x86, 0x8b, 0x2d, 0xa0, 0x7d, 0xa2, 0x99, 0x2c, 0x6d, 0x9f, 0xb8, 0xbd, 0x59, 0x0b, 0x8d, 0xa0, 0x28, 0x11, 0xb5, 0x09, 0xe8, 0xc6, ], - note_type: None, + asset: None, }, TestVector { incoming_viewing_key: [ @@ -1283,7 +1283,7 @@ pub(crate) fn test_vectors() -> Vec { 0x87, 0x01, 0x0c, 0x8d, 0x13, 0x5c, 0x32, 0xd5, 0x6e, 0xe2, 0x84, 0x68, 0x65, 0xa2, 0x61, 0xde, 0x14, 0x25, 0xd2, 0x3b, 0xcc, 0x51, 0xb8, 0xa0, ], - note_type: None, + asset: None, }, TestVector { incoming_viewing_key: [ @@ -1493,7 +1493,7 @@ pub(crate) fn test_vectors() -> Vec { 0x5d, 0x1b, 0x04, 0x3e, 0xb1, 0x2a, 0x0e, 0xfa, 0xb5, 0x16, 0x09, 0x34, 0xbc, 0x75, 0x9e, 0x02, 0x01, 0xd8, 0x66, 0xad, 0xa7, 0x44, 0x35, 0x71, ], - note_type: None, + asset: None, }, TestVector { incoming_viewing_key: [ @@ -1703,7 +1703,7 @@ pub(crate) fn test_vectors() -> Vec { 0x61, 0x33, 0x92, 0x59, 0x28, 0x3e, 0x3a, 0x95, 0x3c, 0x57, 0xdf, 0x3a, 0x48, 0xca, 0x82, 0x71, 0xfc, 0x5f, 0x26, 0x4d, 0x6f, 0x15, 0xb6, 0xb3, ], - note_type: None, + asset: None, }, TestVector { incoming_viewing_key: [ @@ -1913,7 +1913,7 @@ pub(crate) fn test_vectors() -> Vec { 0x97, 0x4c, 0x26, 0xb5, 0x1b, 0x85, 0x9f, 0xab, 0xe0, 0x2e, 0xab, 0xae, 0x96, 0x8a, 0xab, 0x2e, 0x5e, 0x61, 0xef, 0xc2, 0xd4, 0x46, 0x2c, 0x1e, ], - note_type: None, + asset: None, }, TestVector { incoming_viewing_key: [ @@ -2123,7 +2123,7 @@ pub(crate) fn test_vectors() -> Vec { 0xba, 0xfe, 0x80, 0x4d, 0x46, 0x6e, 0xd0, 0x79, 0x82, 0x7f, 0xc1, 0x41, 0x91, 0xeb, 0xb5, 0x99, 0x17, 0x87, 0x49, 0xe9, 0xc4, 0x06, 0xaf, 0x26, ], - note_type: None, + asset: None, }, TestVector { incoming_viewing_key: [ @@ -2333,7 +2333,7 @@ pub(crate) fn test_vectors() -> Vec { 0x13, 0x51, 0xe2, 0x4b, 0x47, 0x02, 0x87, 0xd5, 0x83, 0xba, 0x69, 0x71, 0x18, 0xec, 0x07, 0xf6, 0x59, 0x2c, 0x4c, 0xd7, 0xcd, 0x6a, 0xc7, 0x7e, ], - note_type: Some([ + asset: Some([ 0xa9, 0x71, 0x5e, 0x65, 0xaf, 0x82, 0x67, 0x37, 0x3d, 0x34, 0x51, 0x67, 0x4f, 0xf0, 0x84, 0xef, 0xd9, 0x2c, 0xcf, 0x3b, 0xcc, 0x7a, 0xca, 0x14, 0x67, 0xb6, 0x32, 0x7e, 0x4f, 0x95, 0x22, 0xb2, @@ -2547,7 +2547,7 @@ pub(crate) fn test_vectors() -> Vec { 0xe8, 0x27, 0xdd, 0x43, 0x89, 0xb8, 0x57, 0xd1, 0x6d, 0xb8, 0x24, 0xe7, 0x72, 0xba, 0x5a, 0xb5, 0xe2, 0x8d, 0xd6, 0xe9, 0x80, 0x82, 0x6b, 0xed, ], - note_type: Some([ + asset: Some([ 0xdf, 0xfd, 0x79, 0xa9, 0xde, 0xd0, 0x5e, 0x88, 0x89, 0x58, 0x19, 0x9e, 0xea, 0x45, 0x01, 0xe2, 0x99, 0x0a, 0x53, 0xa5, 0xcd, 0x2a, 0x46, 0xa4, 0x01, 0x57, 0x65, 0x88, 0xfd, 0x7d, 0x05, 0x8a, @@ -2761,7 +2761,7 @@ pub(crate) fn test_vectors() -> Vec { 0xe7, 0xb9, 0x41, 0x0d, 0x6b, 0xe7, 0x59, 0x2a, 0xed, 0xa9, 0xf5, 0x2d, 0x56, 0xd8, 0xc9, 0xf9, 0x3a, 0x0b, 0xe3, 0x8c, 0xfc, 0x8d, 0xc2, 0x94, ], - note_type: Some([ + asset: Some([ 0xa6, 0x33, 0x05, 0x44, 0xe5, 0x46, 0x39, 0xb5, 0x41, 0x87, 0x01, 0xff, 0x4c, 0xc4, 0x5a, 0x31, 0xf6, 0x2e, 0xdd, 0x84, 0x3d, 0xbb, 0xdc, 0x5a, 0xa7, 0x27, 0xab, 0x79, 0xb4, 0x42, 0x68, 0x3c, @@ -2975,7 +2975,7 @@ pub(crate) fn test_vectors() -> Vec { 0xb3, 0x76, 0xcf, 0x33, 0xc9, 0xff, 0x27, 0xa5, 0xaa, 0x01, 0x58, 0x24, 0xe6, 0x78, 0x6e, 0x16, 0xe3, 0x7b, 0x35, 0x5c, 0xf7, 0x54, 0x52, 0xdb, ], - note_type: Some([ + asset: Some([ 0x61, 0x16, 0xcf, 0xec, 0x26, 0x47, 0xcc, 0xaa, 0xe1, 0xc7, 0x4b, 0x41, 0x6f, 0x3e, 0x6a, 0xe8, 0xf7, 0xcc, 0x60, 0xea, 0xaf, 0x7b, 0x6a, 0x59, 0x0d, 0x51, 0x54, 0x41, 0x38, 0xe1, 0x73, 0x29, @@ -3189,7 +3189,7 @@ pub(crate) fn test_vectors() -> Vec { 0x9a, 0xb5, 0xa7, 0xce, 0x77, 0x2b, 0x52, 0x2c, 0x4b, 0xaa, 0x12, 0x95, 0xd8, 0x8f, 0x15, 0xdc, 0x75, 0x1d, 0xdf, 0x7d, 0x20, 0x8d, 0xd5, 0x17, ], - note_type: Some([ + asset: Some([ 0x29, 0x8a, 0xc0, 0xaf, 0xdc, 0x52, 0x87, 0xd7, 0xad, 0x12, 0x4c, 0xd9, 0x40, 0x5a, 0x62, 0xcd, 0x1c, 0xa0, 0x8b, 0x28, 0x2e, 0xfe, 0xf7, 0xf9, 0x28, 0xdf, 0x76, 0xe2, 0x82, 0x1a, 0x41, 0x84, @@ -3403,7 +3403,7 @@ pub(crate) fn test_vectors() -> Vec { 0x1e, 0x58, 0x7e, 0x43, 0xfd, 0xfc, 0x65, 0xfe, 0x52, 0xf1, 0xe0, 0xc6, 0xa0, 0x46, 0x46, 0x48, 0xcd, 0x1f, 0xc8, 0x9e, 0x80, 0xbd, 0x78, 0x0f, ], - note_type: Some([ + asset: Some([ 0xf9, 0x78, 0x1e, 0xbe, 0x31, 0x7a, 0x07, 0x10, 0xae, 0x54, 0x61, 0xe3, 0x4f, 0xe6, 0xf1, 0xb1, 0xaa, 0x9b, 0x4e, 0x67, 0xb1, 0x49, 0x10, 0x98, 0x48, 0x02, 0xc2, 0xa7, 0xe3, 0x81, 0x93, 0xbc, @@ -3617,7 +3617,7 @@ pub(crate) fn test_vectors() -> Vec { 0x51, 0xa5, 0x38, 0x28, 0x0d, 0xaa, 0x94, 0x20, 0x3a, 0xb5, 0x02, 0xa8, 0x15, 0x09, 0xe4, 0x3a, 0x61, 0xa6, 0x98, 0x56, 0x57, 0xd9, 0xe8, 0x4e, ], - note_type: Some([ + asset: Some([ 0x76, 0xba, 0x24, 0x3f, 0x28, 0x42, 0xb7, 0xb5, 0xfc, 0x74, 0x6a, 0xe5, 0x1b, 0x0b, 0xc4, 0xbd, 0x4f, 0xc9, 0xfd, 0x83, 0x35, 0x65, 0xea, 0x85, 0x2b, 0x92, 0xb2, 0x24, 0xf6, 0x99, 0x03, 0x18, @@ -3831,7 +3831,7 @@ pub(crate) fn test_vectors() -> Vec { 0xe2, 0x31, 0x31, 0xf4, 0xe7, 0x6b, 0xa7, 0x6b, 0x9d, 0x64, 0x66, 0x78, 0xd8, 0x53, 0xd1, 0xdc, 0xaf, 0x81, 0xb8, 0x0e, 0x2e, 0xfd, 0xf0, 0x60, ], - note_type: Some([ + asset: Some([ 0x64, 0xd0, 0x87, 0x40, 0x89, 0x86, 0xe7, 0x3d, 0x6e, 0x28, 0x4f, 0xea, 0x9a, 0x23, 0xc3, 0x93, 0x11, 0x78, 0x2f, 0x86, 0xca, 0xbf, 0xf9, 0x45, 0x5e, 0x4c, 0xf6, 0x99, 0xe5, 0xf5, 0xd4, 0xbc, @@ -4045,7 +4045,7 @@ pub(crate) fn test_vectors() -> Vec { 0xd8, 0x15, 0xf7, 0x29, 0x8c, 0x1d, 0x59, 0x09, 0x1f, 0x1b, 0x38, 0x7a, 0x26, 0x46, 0xe7, 0xfe, 0x36, 0x3a, 0xde, 0x83, 0x63, 0xa9, 0x2a, 0xde, ], - note_type: Some([ + asset: Some([ 0xc3, 0xcc, 0x4f, 0x43, 0xfa, 0x01, 0x88, 0x52, 0x1b, 0xc6, 0x1b, 0x21, 0xdd, 0x04, 0xe3, 0x7a, 0x83, 0xec, 0xe6, 0x8c, 0xa7, 0xa2, 0xfa, 0x6c, 0x8f, 0x9e, 0x34, 0xa6, 0x29, 0x03, 0x35, 0xaa, @@ -4259,7 +4259,7 @@ pub(crate) fn test_vectors() -> Vec { 0x62, 0x00, 0xfb, 0x18, 0x7d, 0x2c, 0x16, 0x90, 0x65, 0xaf, 0x84, 0xcc, 0x02, 0x3d, 0x6d, 0x63, 0xce, 0x05, 0x83, 0x28, 0xe2, 0x47, 0xb5, 0x98, ], - note_type: Some([ + asset: Some([ 0x96, 0x86, 0xaa, 0x36, 0x36, 0xbd, 0x37, 0x5b, 0xd3, 0x13, 0x6b, 0xee, 0x0b, 0xda, 0xab, 0xcf, 0xac, 0x88, 0x1b, 0xc7, 0x01, 0x81, 0x27, 0x21, 0xe6, 0xfb, 0x75, 0xaa, 0x07, 0x2d, 0x2d, 0x18, diff --git a/src/value.rs b/src/value.rs index b42d682b7..54736dcd9 100644 --- a/src/value.rs +++ b/src/value.rs @@ -309,7 +309,7 @@ impl ValueCommitment { /// /// [concretehomomorphiccommit]: https://zips.z.cash/protocol/nu5.pdf#concretehomomorphiccommit #[allow(non_snake_case)] - pub(crate) fn derive(value: ValueSum, rcv: ValueCommitTrapdoor, note_type: AssetId) -> Self { + pub(crate) fn derive(value: ValueSum, rcv: ValueCommitTrapdoor, asset: AssetId) -> Self { let hasher = pallas::Point::hash_to_curve(VALUE_COMMITMENT_PERSONALIZATION); let R = hasher(&VALUE_COMMITMENT_R_BYTES); let abs_value = u64::try_from(value.0.abs()).expect("value must be in valid range"); @@ -320,7 +320,7 @@ impl ValueCommitment { pallas::Scalar::from(abs_value) }; - let V_zsa = note_type.cv_base(); + let V_zsa = asset.cv_base(); ValueCommitment(V_zsa * value + R * rcv.0) } @@ -425,7 +425,7 @@ pub mod testing { #[cfg(test)] mod tests { - use crate::note::note_type::testing::{arb_asset_id, native_asset_id}; + use crate::note::asset_id::testing::{arb_asset_id, native_asset_id}; use crate::note::AssetId; use proptest::prelude::*; @@ -446,7 +446,7 @@ mod tests { .iter() .cloned() .zip(neg_trapdoors.iter().cloned()) - .map(|((value, _, note_type), rcv)| ((-value).unwrap(), rcv, note_type)) + .map(|((value, _, asset), rcv)| ((-value).unwrap(), rcv, asset)) .collect(); let native_value_balance = native_values @@ -465,7 +465,7 @@ mod tests { let bvk = (values .iter() - .map(|(value, rcv, note_type)| ValueCommitment::derive(*value, *rcv, *note_type)) + .map(|(value, rcv, asset)| ValueCommitment::derive(*value, *rcv, *asset)) .sum::() - ValueCommitment::derive( native_value_balance, diff --git a/tests/zsa.rs b/tests/zsa.rs index 169440b24..53be3c95c 100644 --- a/tests/zsa.rs +++ b/tests/zsa.rs @@ -225,7 +225,7 @@ impl TestSpendInfo { struct TestOutputInfo { value: NoteValue, - note_type: AssetId, + asset: AssetId, } fn build_and_verify_bundle( @@ -247,7 +247,7 @@ fn build_and_verify_bundle( }); outputs.iter().for_each(|output| { assert_eq!( - builder.add_recipient(None, keys.recipient, output.value, output.note_type, None), + builder.add_recipient(None, keys.recipient, output.value, output.asset, None), Ok(()) ) }); @@ -289,7 +289,7 @@ fn zsa_issue_and_transfer() { vec![&zsa_spend_1], vec![TestOutputInfo { value: zsa_spend_1.note.value(), - note_type: zsa_spend_1.note.asset(), + asset: zsa_spend_1.note.asset(), }], anchor, 2, @@ -303,11 +303,11 @@ fn zsa_issue_and_transfer() { vec![ TestOutputInfo { value: NoteValue::from_raw(zsa_spend_1.note.value().inner() - delta), - note_type: zsa_spend_1.note.asset(), + asset: zsa_spend_1.note.asset(), }, TestOutputInfo { value: NoteValue::from_raw(delta), - note_type: zsa_spend_1.note.asset(), + asset: zsa_spend_1.note.asset(), }, ], anchor, @@ -322,7 +322,7 @@ fn zsa_issue_and_transfer() { value: NoteValue::from_raw( zsa_spend_1.note.value().inner() + zsa_spend_2.note.value().inner(), ), - note_type: zsa_spend_1.note.asset(), + asset: zsa_spend_1.note.asset(), }], anchor, 2, @@ -335,11 +335,11 @@ fn zsa_issue_and_transfer() { vec![ TestOutputInfo { value: NoteValue::from_raw(zsa_spend_1.note.value().inner() - delta), - note_type: zsa_spend_1.note.asset(), + asset: zsa_spend_1.note.asset(), }, TestOutputInfo { value: NoteValue::from_raw(zsa_spend_2.note.value().inner() + delta), - note_type: zsa_spend_2.note.asset(), + asset: zsa_spend_2.note.asset(), }, ], anchor, @@ -353,11 +353,11 @@ fn zsa_issue_and_transfer() { vec![ TestOutputInfo { value: zsa_spend_1.note.value(), - note_type: zsa_spend_1.note.asset(), + asset: zsa_spend_1.note.asset(), }, TestOutputInfo { value: NoteValue::from_raw(100), - note_type: AssetId::native(), + asset: AssetId::native(), }, ], anchor, @@ -383,11 +383,11 @@ fn zsa_issue_and_transfer() { vec![ TestOutputInfo { value: zsa_spend_1.note.value(), - note_type: zsa_spend_1.note.asset(), + asset: zsa_spend_1.note.asset(), }, TestOutputInfo { value: native_spend.note.value(), - note_type: AssetId::native(), + asset: AssetId::native(), }, ], native_anchor, @@ -413,11 +413,11 @@ fn zsa_issue_and_transfer() { vec![ TestOutputInfo { value: zsa_spend_t7_1.note.value(), - note_type: zsa_spend_t7_1.note.asset(), + asset: zsa_spend_t7_1.note.asset(), }, TestOutputInfo { value: zsa_spend_t7_2.note.value(), - note_type: zsa_spend_t7_2.note.asset(), + asset: zsa_spend_t7_2.note.asset(), }, ], anchor_t7, @@ -432,11 +432,11 @@ fn zsa_issue_and_transfer() { vec![ TestOutputInfo { value: NoteValue::from_raw(zsa_spend_t7_1.note.value().inner() + delta), - note_type: zsa_spend_t7_1.note.asset(), + asset: zsa_spend_t7_1.note.asset(), }, TestOutputInfo { value: NoteValue::from_raw(zsa_spend_t7_2.note.value().inner() - delta), - note_type: zsa_spend_t7_2.note.asset(), + asset: zsa_spend_t7_2.note.asset(), }, ], anchor_t7,