Skip to content

Commit

Permalink
rename 2 note_type -> asset as per zcash#356 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulLaux committed Oct 27, 2022
1 parent ce1443c commit 9a0ddbb
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 111 deletions.
10 changes: 5 additions & 5 deletions src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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<redpallas::Signature<SpendAuth>> {
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.
Expand Down
36 changes: 18 additions & 18 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -104,23 +104,23 @@ struct RecipientInfo {
ovk: Option<OutgoingViewingKey>,
recipient: Address,
value: NoteValue,
note_type: AssetId,
asset: AssetId,
memo: Option<[u8; 512]>,
}

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

RecipientInfo {
ovk: None,
recipient,
value: NoteValue::zero(),
note_type,
asset,
memo: None,
}
}
Expand Down Expand Up @@ -167,13 +167,13 @@ impl ActionInfo {
fn build(self, mut rng: impl RngCore) -> (Action<SigningMetadata>, 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();
Expand All @@ -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,
);
Expand Down Expand Up @@ -326,7 +326,7 @@ impl Builder {
ovk: Option<OutgoingViewingKey>,
recipient: Address,
value: NoteValue,
note_type: AssetId,
asset: AssetId,
memo: Option<[u8; 512]>,
) -> Result<(), &'static str> {
if !self.flags.outputs_enabled() {
Expand All @@ -337,7 +337,7 @@ impl Builder {
ovk,
recipient,
value,
note_type,
asset,
memo,
});

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

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/constants/fixed_bases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
66 changes: 33 additions & 33 deletions src/issuance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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<AssetId, Error> {
match self
.notes
.iter()
.try_fold(self.notes().head.asset(), |note_type, &note| {
.try_fold(self.notes().head.asset(), |asset, &note| {
// Fail if not all note types are equal
note.asset()
.eq(&note_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),
}
Expand Down Expand Up @@ -162,12 +162,12 @@ impl<T: IssueAuth> IssueBundle<T> {
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(&note_type));
.find(|a| AssetId::derive(&self.ik, &a.asset_desc).eq(&asset));
action
}

Expand Down Expand Up @@ -207,12 +207,12 @@ impl IssueBundle<Unauthorized> {
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,
);
Expand All @@ -238,7 +238,7 @@ impl IssueBundle<Unauthorized> {
}
}

Ok(note_type)
Ok(asset)
}

/// Finalizes a given `IssueAction`
Expand Down Expand Up @@ -279,18 +279,18 @@ impl IssueBundle<Unauthorized> {

impl IssueBundle<Prepared> {
/// 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<R: RngCore + CryptoRng>(
self,
mut rng: R,
isk: &IssuanceAuthorizingKey,
) -> Result<IssueBundle<Signed>, 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<NoteType,Error> into Result<(),Error)>.
})?;

Expand Down Expand Up @@ -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(&note_type) || acc.contains(&note_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)
})?;

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
Expand Down
File renamed without changes.
Loading

0 comments on commit 9a0ddbb

Please sign in to comment.