Skip to content

Commit

Permalink
Rename V2 name suffixes to Vanilla, and V3 - to ZSA
Browse files Browse the repository at this point in the history
  • Loading branch information
dmidem committed Jan 24, 2024
1 parent 4b9a30f commit 4f894a4
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 81 deletions.
4 changes: 2 additions & 2 deletions benches/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use orchard::{
bundle::Flags,
circuit::{ProvingKey, VerifyingKey},
keys::{FullViewingKey, Scope, SpendingKey},
note_encryption_v3::OrchardDomainV3,
note_encryption_zsa::OrchardDomainZSA,
value::NoteValue,
Anchor, Bundle,
};
Expand Down Expand Up @@ -43,7 +43,7 @@ fn criterion_benchmark(c: &mut Criterion) {
)
.unwrap();
}
let bundle: Bundle<_, i64, OrchardDomainV3> = builder.build(rng).unwrap();
let bundle: Bundle<_, i64, OrchardDomainZSA> = builder.build(rng).unwrap();

let instances: Vec<_> = bundle
.actions()
Expand Down
12 changes: 6 additions & 6 deletions benches/note_decryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use orchard::{
keys::{FullViewingKey, PreparedIncomingViewingKey, Scope, SpendingKey},
note::AssetBase,
note_encryption::{CompactAction, OrchardType},
note_encryption_v3::OrchardDomainV3,
note_encryption_zsa::OrchardDomainZSA,
value::NoteValue,
Anchor, Bundle,
};
Expand All @@ -16,7 +16,7 @@ use zcash_note_encryption_zsa::{batch, try_compact_note_decryption, try_note_dec
#[cfg(unix)]
use pprof::criterion::{Output, PProfProfiler};

type OrchardV3 = OrchardType<OrchardDomainV3>;
type OrchardZSA = OrchardType<OrchardDomainZSA>;

fn bench_note_decryption(c: &mut Criterion) {
let rng = OsRng;
Expand Down Expand Up @@ -73,7 +73,7 @@ fn bench_note_decryption(c: &mut Criterion) {
None,
)
.unwrap();
let bundle: Bundle<_, i64, OrchardDomainV3> = builder.build(rng).unwrap();
let bundle: Bundle<_, i64, OrchardDomainZSA> = builder.build(rng).unwrap();
bundle
.create_proof(&pk, rng)
.unwrap()
Expand All @@ -82,7 +82,7 @@ fn bench_note_decryption(c: &mut Criterion) {
};
let action = bundle.actions().first();

let domain = OrchardV3::for_action(action);
let domain = OrchardZSA::for_action(action);

let compact = {
let mut group = c.benchmark_group("note-decryption");
Expand Down Expand Up @@ -123,10 +123,10 @@ fn bench_note_decryption(c: &mut Criterion) {
let ivks = 2;
let valid_ivks = vec![valid_ivk; ivks];
let actions: Vec<_> = (0..100)
.map(|_| (OrchardV3::for_action(action), action.clone()))
.map(|_| (OrchardZSA::for_action(action), action.clone()))
.collect();
let compact: Vec<_> = (0..100)
.map(|_| (OrchardV3::for_action(action), CompactAction::from(action)))
.map(|_| (OrchardZSA::for_action(action), CompactAction::from(action)))
.collect();

let mut group = c.benchmark_group("batch-note-decryption");
Expand Down
10 changes: 5 additions & 5 deletions src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub(crate) mod testing {
commitment::ExtractedNoteCommitment, nullifier::testing::arb_nullifier,
testing::arb_note, TransmittedNoteCiphertext,
},
note_encryption_v3::{NoteCiphertextBytes, OrchardDomainV3},
note_encryption_zsa::{NoteCiphertextBytes, OrchardDomainZSA},
primitives::redpallas::{
self,
testing::{arb_spendauth_signing_key, arb_spendauth_verification_key},
Expand All @@ -150,15 +150,15 @@ pub(crate) mod testing {
rk in arb_spendauth_verification_key(),
note in arb_note(output_value),
asset in arb_asset_base()
) -> Action<(), OrchardDomainV3> {
) -> Action<(), OrchardDomainZSA> {
let cmx = ExtractedNoteCommitment::from(note.commitment());
let cv_net = ValueCommitment::derive(
spend_value - output_value,
ValueCommitTrapdoor::zero(),
asset
);
// FIXME: make a real one from the note.
let encrypted_note = TransmittedNoteCiphertext::<OrchardDomainV3> {
let encrypted_note = TransmittedNoteCiphertext::<OrchardDomainZSA> {
epk_bytes: [0u8; 32],
enc_ciphertext: NoteCiphertextBytes([0u8; 612]),
out_ciphertext: [0u8; 80]
Expand All @@ -183,7 +183,7 @@ pub(crate) mod testing {
rng_seed in prop::array::uniform32(prop::num::u8::ANY),
fake_sighash in prop::array::uniform32(prop::num::u8::ANY),
asset in arb_asset_base()
) -> Action<redpallas::Signature<SpendAuth>, OrchardDomainV3> {
) -> Action<redpallas::Signature<SpendAuth>, OrchardDomainZSA> {
let cmx = ExtractedNoteCommitment::from(note.commitment());
let cv_net = ValueCommitment::derive(
spend_value - output_value,
Expand All @@ -192,7 +192,7 @@ pub(crate) mod testing {
);

// FIXME: make a real one from the note.
let encrypted_note = TransmittedNoteCiphertext::<OrchardDomainV3> {
let encrypted_note = TransmittedNoteCiphertext::<OrchardDomainZSA> {
epk_bytes: [0u8; 32],
enc_ciphertext: NoteCiphertextBytes([0u8; 612]),
out_ciphertext: [0u8; 80]
Expand Down
16 changes: 8 additions & 8 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl Builder {
}

// FIXME: fix the doc, this line was removed from the doc:
// [`OrchardDomain`]: crate::note_encryption_v3::OrchardZSADomain
// [`OrchardDomain`]: crate::note_encryption_zsa::OrchardZSADomain

/// Adds a note to be spent in this transaction.
///
Expand Down Expand Up @@ -928,7 +928,7 @@ pub mod testing {
keys::{testing::arb_spending_key, FullViewingKey, SpendAuthorizingKey, SpendingKey},
note::testing::arb_note,
note_encryption::OrchardDomain,
note_encryption_v3::OrchardDomainV3,
note_encryption_zsa::OrchardDomainZSA,
tree::{Anchor, MerkleHashOrchard, MerklePath},
value::{testing::arb_positive_note_value, NoteValue, MAX_NOTE_VALUE},
Address, Note,
Expand Down Expand Up @@ -1041,17 +1041,17 @@ pub mod testing {

/// Produce an arbitrary valid Orchard bundle using a random spending key.
pub fn arb_bundle<V: TryFrom<i64> + Debug + Copy + Into<i64>>(
) -> impl Strategy<Value = Bundle<Authorized, V, OrchardDomainV3>> {
) -> impl Strategy<Value = Bundle<Authorized, V, OrchardDomainZSA>> {
arb_spending_key()
.prop_flat_map(arb_bundle_inputs)
.prop_map(|inputs| inputs.into_bundle::<V, OrchardDomainV3>())
.prop_map(|inputs| inputs.into_bundle::<V, OrchardDomainZSA>())
}

/// Produce an arbitrary valid Orchard bundle using a specified spending key.
pub fn arb_bundle_with_key<V: TryFrom<i64> + Debug + Copy + Into<i64>>(
k: SpendingKey,
) -> impl Strategy<Value = Bundle<Authorized, V, OrchardDomainV3>> {
arb_bundle_inputs(k).prop_map(|inputs| inputs.into_bundle::<V, OrchardDomainV3>())
) -> impl Strategy<Value = Bundle<Authorized, V, OrchardDomainZSA>> {
arb_bundle_inputs(k).prop_map(|inputs| inputs.into_bundle::<V, OrchardDomainZSA>())
}
}

Expand All @@ -1066,7 +1066,7 @@ mod tests {
circuit::ProvingKey,
constants::MERKLE_DEPTH_ORCHARD,
keys::{FullViewingKey, Scope, SpendingKey},
note_encryption_v3::OrchardDomainV3,
note_encryption_zsa::OrchardDomainZSA,
tree::EMPTY_ROOTS,
value::NoteValue,
};
Expand Down Expand Up @@ -1097,7 +1097,7 @@ mod tests {
let balance: i64 = builder.value_balance().unwrap();
assert_eq!(balance, -5000);

let bundle: Bundle<Authorized, i64, OrchardDomainV3> = builder
let bundle: Bundle<Authorized, i64, OrchardDomainZSA> = builder
.build(&mut rng)
.unwrap()
.create_proof(&pk, &mut rng)
Expand Down
10 changes: 5 additions & 5 deletions src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ pub mod testing {
pub use crate::action::testing::{arb_action, arb_unauthorized_action};
use crate::note::asset_base::testing::arb_zsa_asset_base;
use crate::note::AssetBase;
use crate::note_encryption_v3::OrchardDomainV3;
use crate::note_encryption_zsa::OrchardDomainZSA;
use crate::value::testing::arb_value_sum;

/// Marker for an unauthorized bundle with no proofs or signatures.
Expand All @@ -573,7 +573,7 @@ pub mod testing {
pub fn arb_unauthorized_action_n(
n_actions: usize,
flags: Flags,
) -> impl Strategy<Value = (ValueSum, Action<(), OrchardDomainV3>)> {
) -> impl Strategy<Value = (ValueSum, Action<(), OrchardDomainZSA>)> {
let spend_value_gen = if flags.spends_enabled {
Strategy::boxed(arb_note_value_bounded(MAX_NOTE_VALUE / n_actions as u64))
} else {
Expand Down Expand Up @@ -601,7 +601,7 @@ pub mod testing {
) -> impl Strategy<
Value = (
ValueSum,
Action<redpallas::Signature<SpendAuth>, OrchardDomainV3>,
Action<redpallas::Signature<SpendAuth>, OrchardDomainZSA>,
),
> {
let spend_value_gen = if flags.spends_enabled {
Expand Down Expand Up @@ -664,7 +664,7 @@ pub mod testing {
anchor in arb_base().prop_map(Anchor::from),
flags in Just(flags),
burn in vec(arb_asset_to_burn(), 1usize..10)
) -> Bundle<Unauthorized, ValueSum, OrchardDomainV3> {
) -> Bundle<Unauthorized, ValueSum, OrchardDomainZSA> {
let (balances, actions): (Vec<ValueSum>, Vec<Action<_, _>>) = acts.into_iter().unzip();

Bundle::from_parts(
Expand Down Expand Up @@ -695,7 +695,7 @@ pub mod testing {
fake_sighash in prop::array::uniform32(prop::num::u8::ANY),
flags in Just(flags),
burn in vec(arb_asset_to_burn(), 1usize..10)
) -> Bundle<Authorized, ValueSum, OrchardDomainV3> {
) -> Bundle<Authorized, ValueSum, OrchardDomainZSA> {
let (balances, actions): (Vec<ValueSum>, Vec<Action<_, _>, >) = acts.into_iter().unzip();
let rng = StdRng::from_seed(rng_seed);

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub mod note;
pub mod supply_info;

pub mod note_encryption;
pub mod note_encryption_v2;
pub mod note_encryption_v3;
pub mod note_encryption_vanilla;
pub mod note_encryption_zsa;

pub mod primitives;
mod spec;
Expand Down
14 changes: 7 additions & 7 deletions src/note_encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ const NOTE_DIVERSIFIER_OFFSET: usize = NOTE_VERSION_OFFSET + NOTE_VERSION_SIZE;
const NOTE_VALUE_OFFSET: usize = NOTE_DIVERSIFIER_OFFSET + NOTE_DIVERSIFIER_SIZE;
const NOTE_RSEED_OFFSET: usize = NOTE_VALUE_OFFSET + NOTE_VALUE_SIZE;

/// The size of a v2 compact note.
pub const COMPACT_NOTE_SIZE_V2: usize =
/// The size of a Vanilla compact note.
pub const COMPACT_NOTE_SIZE_VANILLA: usize =
NOTE_VERSION_SIZE + NOTE_DIVERSIFIER_SIZE + NOTE_VALUE_SIZE + NOTE_RSEED_SIZE;

/// The size of the encoding of a ZSA asset id.
const ZSA_ASSET_SIZE: usize = 32;

/// The size of a v3 compact note.
pub const COMPACT_NOTE_SIZE_V3: usize = COMPACT_NOTE_SIZE_V2 + ZSA_ASSET_SIZE;
/// The size of a ZSA compact note.
pub const COMPACT_NOTE_SIZE_ZSA: usize = COMPACT_NOTE_SIZE_VANILLA + ZSA_ASSET_SIZE;

pub(crate) type Memo = [u8; MEMO_SIZE];

Expand Down Expand Up @@ -189,7 +189,7 @@ pub(crate) fn build_base_note_plaintext_bytes<const NOTE_PLAINTEXT_SIZE: usize>(
np[NOTE_DIVERSIFIER_OFFSET..NOTE_VALUE_OFFSET]
.copy_from_slice(note.recipient().diversifier().as_array());
np[NOTE_VALUE_OFFSET..NOTE_RSEED_OFFSET].copy_from_slice(&note.value().to_bytes());
np[NOTE_RSEED_OFFSET..COMPACT_NOTE_SIZE_V2].copy_from_slice(note.rseed().as_bytes());
np[NOTE_RSEED_OFFSET..COMPACT_NOTE_SIZE_VANILLA].copy_from_slice(note.rseed().as_bytes());

np
}
Expand Down Expand Up @@ -244,7 +244,7 @@ impl<D: OrchardDomain> OrchardType<D> {
);

let rseed = Option::from(RandomSeed::from_bytes(
plaintext.as_ref()[NOTE_RSEED_OFFSET..COMPACT_NOTE_SIZE_V2]
plaintext.as_ref()[NOTE_RSEED_OFFSET..COMPACT_NOTE_SIZE_VANILLA]
.try_into()
.unwrap(),
&domain.rho,
Expand All @@ -256,7 +256,7 @@ impl<D: OrchardDomain> OrchardType<D> {
let asset = match note_version(plaintext.as_ref())? {
0x02 => AssetBase::native(),
0x03 => {
let bytes = plaintext.as_ref()[COMPACT_NOTE_SIZE_V2..COMPACT_NOTE_SIZE_V3]
let bytes = plaintext.as_ref()[COMPACT_NOTE_SIZE_VANILLA..COMPACT_NOTE_SIZE_ZSA]
.try_into()
.unwrap();
AssetBase::from_bytes(bytes).unwrap()
Expand Down
31 changes: 16 additions & 15 deletions src/note_encryption_v2.rs → src/note_encryption_vanilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ use zcash_note_encryption_zsa::{AEAD_TAG_SIZE, MEMO_SIZE};
use crate::{
note_encryption::{
build_base_note_plaintext_bytes, define_note_byte_types, Memo, OrchardDomain,
COMPACT_NOTE_SIZE_V2,
COMPACT_NOTE_SIZE_VANILLA,
},
Note,
};

define_note_byte_types!(COMPACT_NOTE_SIZE_V2);
define_note_byte_types!(COMPACT_NOTE_SIZE_VANILLA);

/// FIXME: add doc
#[derive(Debug, Clone)]
pub struct OrchardDomainV2;
pub struct OrchardDomainVanilla;

impl OrchardDomain for OrchardDomainV2 {
impl OrchardDomain for OrchardDomainVanilla {
const COMPACT_NOTE_SIZE: usize = COMPACT_NOTE_SIZE;

type NotePlaintextBytes = NotePlaintextBytes;
Expand All @@ -27,7 +27,7 @@ impl OrchardDomain for OrchardDomainV2 {
fn build_note_plaintext_bytes(note: &Note, memo: &Memo) -> Self::NotePlaintextBytes {
let mut np = build_base_note_plaintext_bytes(0x02, note);

np[COMPACT_NOTE_SIZE_V2..].copy_from_slice(memo);
np[COMPACT_NOTE_SIZE_VANILLA..].copy_from_slice(memo);

NotePlaintextBytes(np)
}
Expand All @@ -42,7 +42,7 @@ mod tests {
EphemeralKeyBytes,
};

use super::{NoteCiphertextBytes, OrchardDomainV2};
use super::{NoteCiphertextBytes, OrchardDomainVanilla};
use crate::{
action::Action,
keys::{
Expand All @@ -59,27 +59,28 @@ mod tests {
Address, Note,
};

type OrchardV2 = OrchardType<OrchardDomainV2>;
type OrchardVanilla = OrchardType<OrchardDomainVanilla>;

/// Implementation of in-band secret distribution for Orchard bundles.
pub type OrchardNoteEncryptionV2 = zcash_note_encryption_zsa::NoteEncryption<OrchardV2>;
pub type OrchardNoteEncryptionVanilla =
zcash_note_encryption_zsa::NoteEncryption<OrchardVanilla>;

proptest! {
#[test]
fn test_encoding_roundtrip(
note in arb_native_note(),
) {
let memo = &crate::test_vectors::note_encryption_v2::test_vectors()[0].memo;
let memo = &crate::test_vectors::note_encryption_vanilla::test_vectors()[0].memo;

// Encode.
let mut plaintext = OrchardV2::note_plaintext_bytes(&note, memo);
let mut plaintext = OrchardVanilla::note_plaintext_bytes(&note, memo);

// Decode.
let domain = OrchardV2::for_nullifier(note.rho());
let domain = OrchardVanilla::for_nullifier(note.rho());
let parsed_version = note_version(plaintext.as_mut()).unwrap();
let (compact,parsed_memo) = domain.extract_memo(&plaintext);

let (parsed_note, parsed_recipient) = OrchardV2::orchard_parse_note_plaintext_without_memo(&domain, &compact,
let (parsed_note, parsed_recipient) = OrchardVanilla::orchard_parse_note_plaintext_without_memo(&domain, &compact,
|diversifier| {
assert_eq!(diversifier, &note.recipient().diversifier());
Some(*note.recipient().pk_d())
Expand All @@ -96,7 +97,7 @@ mod tests {

#[test]
fn test_vectors() {
let test_vectors = crate::test_vectors::note_encryption_v2::test_vectors();
let test_vectors = crate::test_vectors::note_encryption_vanilla::test_vectors();

for tv in test_vectors {
//
Expand Down Expand Up @@ -163,7 +164,7 @@ mod tests {
// (Tested first because it only requires immutable references.)
//

let domain = OrchardV2::for_nullifier(rho);
let domain = OrchardVanilla::for_nullifier(rho);

match try_note_decryption(&domain, &ivk, &action) {
Some((decrypted_note, decrypted_to, decrypted_memo)) => {
Expand Down Expand Up @@ -195,7 +196,7 @@ mod tests {
// Test encryption
//

let ne = OrchardNoteEncryptionV2::new_with_esk(esk, Some(ovk), note, tv.memo);
let ne = OrchardNoteEncryptionVanilla::new_with_esk(esk, Some(ovk), note, tv.memo);

assert_eq!(ne.encrypt_note_plaintext().as_ref(), &tv.c_enc[..]);
assert_eq!(
Expand Down
Loading

0 comments on commit 4f894a4

Please sign in to comment.