Skip to content

Commit

Permalink
Rename OrchardDomain to OrchardNoteEnc, OrchardDomainBase to OrchardD…
Browse files Browse the repository at this point in the history
…omain, intruduce and use OrchardFlavor
  • Loading branch information
dmidem committed Jun 24, 2024
1 parent 1be9604 commit 1dd1a82
Show file tree
Hide file tree
Showing 18 changed files with 125 additions and 118 deletions.
8 changes: 3 additions & 5 deletions benches/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ use pprof::criterion::{Output, PProfProfiler};

use orchard::{
builder::{Builder, BundleType},
bundle::OrchardHash,
circuit::{OrchardCircuit, ProvingKey, VerifyingKey},
circuit::{ProvingKey, VerifyingKey},
keys::{FullViewingKey, Scope, SpendingKey},
note::AssetBase,
note_encryption::OrchardDomain,
orchard_flavors::{OrchardVanilla, OrchardZSA},
orchard_flavors::{OrchardFlavor, OrchardVanilla, OrchardZSA},
value::NoteValue,
Anchor, Bundle,
};
use rand::rngs::OsRng;

fn criterion_benchmark<D: OrchardDomain + OrchardCircuit + OrchardHash>(c: &mut Criterion) {
fn criterion_benchmark<D: OrchardFlavor>(c: &mut Criterion) {
let rng = OsRng;

let sk = SpendingKey::from_bytes([7; 32]).unwrap();
Expand Down
15 changes: 7 additions & 8 deletions benches/note_decryption.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use orchard::{
builder::{Builder, BundleType},
bundle::OrchardHash,
circuit::{OrchardCircuit, ProvingKey},
circuit::ProvingKey,
keys::{FullViewingKey, PreparedIncomingViewingKey, Scope, SpendingKey},
note::AssetBase,
note_encryption::{CompactAction, OrchardDomain, OrchardDomainBase},
orchard_flavors::{OrchardVanilla, OrchardZSA},
note_encryption::{CompactAction, OrchardDomain},
orchard_flavors::{OrchardFlavor, OrchardVanilla, OrchardZSA},
value::NoteValue,
Anchor, Bundle,
};
Expand All @@ -16,7 +15,7 @@ use zcash_note_encryption_zsa::{batch, try_compact_note_decryption, try_note_dec
#[cfg(unix)]
use pprof::criterion::{Output, PProfProfiler};

fn bench_note_decryption<D: OrchardDomain + OrchardCircuit + OrchardHash>(c: &mut Criterion) {
fn bench_note_decryption<D: OrchardFlavor>(c: &mut Criterion) {
let rng = OsRng;
let pk = ProvingKey::build::<D>();

Expand Down Expand Up @@ -80,7 +79,7 @@ fn bench_note_decryption<D: OrchardDomain + OrchardCircuit + OrchardHash>(c: &mu
};
let action = bundle.actions().first();

let domain = OrchardDomainBase::for_action(action);
let domain = OrchardDomain::for_action(action);

let compact = {
let mut group = c.benchmark_group("note-decryption");
Expand Down Expand Up @@ -121,12 +120,12 @@ fn bench_note_decryption<D: OrchardDomain + OrchardCircuit + OrchardHash>(c: &mu
let ivks = 2;
let valid_ivks = vec![valid_ivk; ivks];
let actions: Vec<_> = (0..100)
.map(|_| (OrchardDomainBase::for_action(action), action.clone()))
.map(|_| (OrchardDomain::for_action(action), action.clone()))
.collect();
let compact: Vec<_> = (0..100)
.map(|_| {
(
OrchardDomainBase::for_action(action),
OrchardDomain::for_action(action),
CompactAction::from(action),
)
})
Expand Down
20 changes: 10 additions & 10 deletions src/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use memuse::DynamicUsage;

use crate::{
note::{ExtractedNoteCommitment, Nullifier, Rho, TransmittedNoteCiphertext},
note_encryption::OrchardDomain,
note_encryption::OrchardNoteEnc,
primitives::redpallas::{self, SpendAuth},
value::ValueCommitment,
};
Expand All @@ -12,7 +12,7 @@ use crate::{
/// This both creates a note (adding a commitment to the global ledger), and consumes
/// some note created prior to this action (adding a nullifier to the global ledger).
#[derive(Debug, Clone)]
pub struct Action<A, D: OrchardDomain> {
pub struct Action<A, D: OrchardNoteEnc> {
/// The nullifier of the note being spent.
nf: Nullifier,
/// The randomized verification key for the note being spent.
Expand All @@ -27,7 +27,7 @@ pub struct Action<A, D: OrchardDomain> {
authorization: A,
}

impl<A, D: OrchardDomain> Action<A, D> {
impl<A, D: OrchardNoteEnc> Action<A, D> {
/// Constructs an `Action` from its constituent parts.
pub fn from_parts(
nf: Nullifier,
Expand Down Expand Up @@ -107,7 +107,7 @@ impl<A, D: OrchardDomain> Action<A, D> {
}
}

impl<D: OrchardDomain> DynamicUsage for Action<redpallas::Signature<SpendAuth>, D> {
impl<D: OrchardNoteEnc> DynamicUsage for Action<redpallas::Signature<SpendAuth>, D> {
#[inline(always)]
fn dynamic_usage(&self) -> usize {
0
Expand Down Expand Up @@ -135,7 +135,7 @@ pub(crate) mod testing {
asset_base::testing::arb_asset_base, commitment::ExtractedNoteCommitment,
nullifier::testing::arb_nullifier, testing::arb_note, TransmittedNoteCiphertext,
},
note_encryption::{OrchardDomain, OrchardDomainBase},
note_encryption::{OrchardDomain, OrchardNoteEnc},
primitives::redpallas::{
self,
testing::{arb_spendauth_signing_key, arb_spendauth_verification_key},
Expand All @@ -148,13 +148,13 @@ pub(crate) mod testing {
/// `ActionArb` adapts `arb_...` functions for both Vanilla and ZSA Orchard protocol variations
/// in property-based testing, addressing proptest crate limitations.
#[derive(Debug)]
pub struct ActionArb<D: OrchardDomain> {
pub struct ActionArb<D: OrchardNoteEnc> {
phantom: std::marker::PhantomData<D>,
}

impl<D: OrchardDomain> ActionArb<D> {
impl<D: OrchardNoteEnc> ActionArb<D> {
fn encrypt_note<R: RngCore>(
encryptor: NoteEncryption<OrchardDomainBase<D>>,
encryptor: NoteEncryption<OrchardDomain<D>>,
cmx: &ExtractedNoteCommitment,
cv_net: &ValueCommitment,
rng: &mut R,
Expand Down Expand Up @@ -184,7 +184,7 @@ pub(crate) mod testing {
);

let mut rng = StdRng::from_seed(rng_seed);
let encryptor = NoteEncryption::<OrchardDomainBase<D>>::new(None, note, memo.try_into().unwrap());
let encryptor = NoteEncryption::<OrchardDomain<D>>::new(None, note, memo.try_into().unwrap());
let encrypted_note = Self::encrypt_note(encryptor, &cmx, &cv_net, &mut rng);

Action {
Expand Down Expand Up @@ -218,7 +218,7 @@ pub(crate) mod testing {

let mut rng = StdRng::from_seed(rng_seed);

let encryptor = NoteEncryption::<OrchardDomainBase<D>>::new(None, note, memo.try_into().unwrap());
let encryptor = NoteEncryption::<OrchardDomain<D>>::new(None, note, memo.try_into().unwrap());
let encrypted_note = Self::encrypt_note(encryptor, &cmx, &cv_net, &mut rng);

Action {
Expand Down
34 changes: 17 additions & 17 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::{
SpendingKey,
},
note::{AssetBase, Note, Rho, TransmittedNoteCiphertext},
note_encryption::{OrchardDomain, OrchardDomainBase},
note_encryption::{OrchardDomain, OrchardNoteEnc},
primitives::redpallas::{self, Binding, SpendAuth},
tree::{Anchor, MerklePath},
value::{self, NoteValue, OverflowError, ValueCommitTrapdoor, ValueCommitment, ValueSum},
Expand Down Expand Up @@ -387,7 +387,7 @@ impl ActionInfo {
/// # Panics
///
/// Panics if the asset types of the spent and output notes do not match.
fn build<D: OrchardDomain>(
fn build<D: OrchardNoteEnc>(
self,
mut rng: impl RngCore,
) -> (Action<SigningMetadata, D>, Circuit<D>) {
Expand Down Expand Up @@ -418,7 +418,7 @@ impl ActionInfo {
let cmx = cm_new.into();

let encryptor =
NoteEncryption::<OrchardDomainBase<D>>::new(self.output.ovk, note, self.output.memo);
NoteEncryption::<OrchardDomain<D>>::new(self.output.ovk, note, self.output.memo);

let encrypted_note = TransmittedNoteCiphertext {
epk_bytes: encryptor.epk().to_bytes().0,
Expand Down Expand Up @@ -635,7 +635,7 @@ impl Builder {
/// [`Bundle::create_proof`] and [`Bundle::apply_signatures`] respectively.
// FIXME: Consider factoring parts of the return type into `type` definitions
#[allow(clippy::type_complexity)]
pub fn build<V: TryFrom<i64>, D: OrchardDomain + OrchardCircuit + OrchardHash>(
pub fn build<V: TryFrom<i64>, D: OrchardNoteEnc + OrchardCircuit + OrchardHash>(
self,
rng: impl RngCore,
) -> Result<Option<(UnauthorizedBundle<V, D>, BundleMetadata)>, BuildError> {
Expand Down Expand Up @@ -716,7 +716,7 @@ fn pad_spend(spend: Option<&SpendInfo>, asset: AssetBase, mut rng: impl RngCore)
/// The returned bundle will have no proof or signatures; these can be applied with
/// [`Bundle::create_proof`] and [`Bundle::apply_signatures`] respectively.
#[allow(clippy::type_complexity)]
pub fn bundle<V: TryFrom<i64>, D: OrchardDomain + OrchardCircuit + OrchardHash>(
pub fn bundle<V: TryFrom<i64>, D: OrchardNoteEnc + OrchardCircuit + OrchardHash>(
mut rng: impl RngCore,
anchor: Anchor,
bundle_type: BundleType,
Expand Down Expand Up @@ -907,11 +907,11 @@ impl<P: fmt::Debug, S: InProgressSignatures> Authorization for InProgress<P, S>
///
/// This struct contains the private data needed to create a [`Proof`] for a [`Bundle`].
#[derive(Clone, Debug)]
pub struct Unproven<D: OrchardCircuit> {
circuits: Vec<Circuit<D>>,
pub struct Unproven<C: OrchardCircuit> {
circuits: Vec<Circuit<C>>,
}

impl<S: InProgressSignatures, D: OrchardCircuit> InProgress<Unproven<D>, S> {
impl<S: InProgressSignatures, C: OrchardCircuit> InProgress<Unproven<C>, S> {
/// Creates the proof for this bundle.
pub fn create_proof(
&self,
Expand All @@ -923,7 +923,7 @@ impl<S: InProgressSignatures, D: OrchardCircuit> InProgress<Unproven<D>, S> {
}
}

impl<S: InProgressSignatures, V, D: OrchardDomain + OrchardCircuit>
impl<S: InProgressSignatures, V, D: OrchardNoteEnc + OrchardCircuit>
Bundle<InProgress<Unproven<D>, S>, V, D>
{
/// Creates the proof for this bundle.
Expand Down Expand Up @@ -1014,7 +1014,7 @@ impl MaybeSigned {
}
}

impl<P: fmt::Debug, V, D: OrchardDomain> Bundle<InProgress<P, Unauthorized>, V, D> {
impl<P: fmt::Debug, V, D: OrchardNoteEnc> Bundle<InProgress<P, Unauthorized>, V, D> {
/// Loads the sighash into this bundle, preparing it for signing.
///
/// This API ensures that all signatures are created over the same sighash.
Expand Down Expand Up @@ -1043,7 +1043,7 @@ impl<P: fmt::Debug, V, D: OrchardDomain> Bundle<InProgress<P, Unauthorized>, V,
}
}

impl<V, D: OrchardDomain> Bundle<InProgress<Proof, Unauthorized>, V, D> {
impl<V, D: OrchardNoteEnc> Bundle<InProgress<Proof, Unauthorized>, V, D> {
/// Applies signatures to this bundle, in order to authorize it.
///
/// This is a helper method that wraps [`Bundle::prepare`], [`Bundle::sign`], and
Expand All @@ -1063,7 +1063,7 @@ impl<V, D: OrchardDomain> Bundle<InProgress<Proof, Unauthorized>, V, D> {
}
}

impl<P: fmt::Debug, V, D: OrchardDomain> Bundle<InProgress<P, PartiallyAuthorized>, V, D> {
impl<P: fmt::Debug, V, D: OrchardNoteEnc> Bundle<InProgress<P, PartiallyAuthorized>, V, D> {
/// Signs this bundle with the given [`SpendAuthorizingKey`].
///
/// This will apply signatures for all notes controlled by this spending key.
Expand Down Expand Up @@ -1126,7 +1126,7 @@ impl<P: fmt::Debug, V, D: OrchardDomain> Bundle<InProgress<P, PartiallyAuthorize
}
}

impl<V, D: OrchardDomain> Bundle<InProgress<Proof, PartiallyAuthorized>, V, D> {
impl<V, D: OrchardNoteEnc> Bundle<InProgress<Proof, PartiallyAuthorized>, V, D> {
/// Finalizes this bundle, enabling it to be included in a transaction.
///
/// Returns an error if any signatures are missing.
Expand Down Expand Up @@ -1195,7 +1195,7 @@ pub mod testing {
circuit::{OrchardCircuit, ProvingKey},
keys::{testing::arb_spending_key, FullViewingKey, SpendAuthorizingKey, SpendingKey},
note::testing::arb_note,
note_encryption::OrchardDomain,
note_encryption::OrchardNoteEnc,
tree::{Anchor, MerkleHashOrchard, MerklePath},
value::{testing::arb_positive_note_value, NoteValue, MAX_NOTE_VALUE},
Address, Note,
Expand Down Expand Up @@ -1224,7 +1224,7 @@ pub mod testing {
/// Create a bundle from the set of arbitrary bundle inputs.
fn into_bundle<
V: TryFrom<i64> + Copy + Into<i64>,
D: OrchardDomain + OrchardCircuit + OrchardHash,
D: OrchardNoteEnc + OrchardCircuit + OrchardHash,
>(
mut self,
) -> Bundle<Authorized, V, D> {
Expand Down Expand Up @@ -1262,11 +1262,11 @@ pub mod testing {
/// `BuilderArb` adapts `arb_...` functions for both Vanilla and ZSA Orchard protocol variations
/// in property-based testing, addressing proptest crate limitations.
#[derive(Debug)]
pub struct BuilderArb<D: OrchardDomain> {
pub struct BuilderArb<D: OrchardNoteEnc> {
phantom: std::marker::PhantomData<D>,
}

impl<D: OrchardDomain + OrchardCircuit + OrchardHash> BuilderArb<D> {
impl<D: OrchardNoteEnc + OrchardCircuit + OrchardHash> BuilderArb<D> {
prop_compose! {
/// Produce a random valid Orchard bundle.
fn arb_bundle_inputs(sk: SpendingKey)
Expand Down
Loading

0 comments on commit 1dd1a82

Please sign in to comment.