mirror of https://github.com/zcash/halo2.git
Benchmark batch trial decryption
This commit is contained in:
parent
c4fb1efb1c
commit
8c15cc25be
|
@ -80,5 +80,5 @@ debug = true
|
||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
halo2 = { git = "https://github.com/zcash/halo2.git", rev = "27c4187673a9c6ade13fbdbd4f20955530c22d7f" }
|
halo2 = { git = "https://github.com/zcash/halo2.git", rev = "27c4187673a9c6ade13fbdbd4f20955530c22d7f" }
|
||||||
zcash_note_encryption = { git = "https://github.com/zcash/librustzcash.git", rev = "cc533a9da4f6a7209a7be05f82b12a03969152c9" }
|
zcash_note_encryption = { git = "https://github.com/zcash/librustzcash.git", rev = "13b023387bafdc7b5712c933dc0e16ee94b96a6a" }
|
||||||
incrementalmerkletree = { git = "https://github.com/zcash/incrementalmerkletree.git", rev = "b7bd6246122a6e9ace8edb51553fbf5228906cbb" }
|
incrementalmerkletree = { git = "https://github.com/zcash/incrementalmerkletree.git", rev = "b7bd6246122a6e9ace8edb51553fbf5228906cbb" }
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
use criterion::{criterion_group, criterion_main, Criterion, Throughput};
|
use std::array;
|
||||||
|
|
||||||
|
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
|
||||||
use orchard::{
|
use orchard::{
|
||||||
builder::Builder,
|
builder::Builder,
|
||||||
bundle::Flags,
|
bundle::Flags,
|
||||||
|
@ -9,7 +11,7 @@ use orchard::{
|
||||||
Anchor, Bundle,
|
Anchor, Bundle,
|
||||||
};
|
};
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use zcash_note_encryption::{try_compact_note_decryption, try_note_decryption};
|
use zcash_note_encryption::{batch, try_compact_note_decryption, try_note_decryption};
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use pprof::criterion::{Output, PProfProfiler};
|
use pprof::criterion::{Output, PProfProfiler};
|
||||||
|
@ -63,6 +65,7 @@ fn bench_note_decryption(c: &mut Criterion) {
|
||||||
|
|
||||||
let compact = {
|
let compact = {
|
||||||
let mut group = c.benchmark_group("note-decryption");
|
let mut group = c.benchmark_group("note-decryption");
|
||||||
|
group.throughput(Throughput::Elements(1));
|
||||||
|
|
||||||
group.bench_function("valid", |b| {
|
group.bench_function("valid", |b| {
|
||||||
b.iter(|| try_note_decryption(&domain, &valid_ivk, action).unwrap())
|
b.iter(|| try_note_decryption(&domain, &valid_ivk, action).unwrap())
|
||||||
|
@ -93,6 +96,47 @@ fn bench_note_decryption(c: &mut Criterion) {
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Benchmark with 2 IVKs to emulate a wallet with two pools of funds.
|
||||||
|
let ivks = 2;
|
||||||
|
let valid_ivks = vec![valid_ivk; ivks];
|
||||||
|
let actions: Vec<_> = (0..100)
|
||||||
|
.map(|_| (OrchardDomain::for_action(action), action.clone()))
|
||||||
|
.collect();
|
||||||
|
let compact: Vec<_> = (0..100)
|
||||||
|
.map(|_| {
|
||||||
|
(
|
||||||
|
OrchardDomain::for_action(action),
|
||||||
|
CompactAction::from(action),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let mut group = c.benchmark_group("batch-note-decryption");
|
||||||
|
|
||||||
|
for size in array::IntoIter::new([10, 50, 100]) {
|
||||||
|
group.throughput(Throughput::Elements((ivks * size) as u64));
|
||||||
|
|
||||||
|
group.bench_function(BenchmarkId::new("valid", size), |b| {
|
||||||
|
b.iter(|| batch::try_note_decryption(&valid_ivks, &actions[..size]))
|
||||||
|
});
|
||||||
|
|
||||||
|
group.bench_function(BenchmarkId::new("invalid", size), |b| {
|
||||||
|
b.iter(|| batch::try_note_decryption(&invalid_ivks[..ivks], &actions[..size]))
|
||||||
|
});
|
||||||
|
|
||||||
|
group.bench_function(BenchmarkId::new("compact-valid", size), |b| {
|
||||||
|
b.iter(|| batch::try_compact_note_decryption(&valid_ivks, &compact[..size]))
|
||||||
|
});
|
||||||
|
|
||||||
|
group.bench_function(BenchmarkId::new("compact-invalid", size), |b| {
|
||||||
|
b.iter(|| {
|
||||||
|
batch::try_compact_note_decryption(&invalid_ivks[..ivks], &compact[..size])
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
|
|
@ -263,7 +263,7 @@ impl FullViewingKey {
|
||||||
/// Defined in [Zcash Protocol Spec § 4.2.3: Orchard Key Components][orchardkeycomponents].
|
/// Defined in [Zcash Protocol Spec § 4.2.3: Orchard Key Components][orchardkeycomponents].
|
||||||
///
|
///
|
||||||
/// [orchardkeycomponents]: https://zips.z.cash/protocol/nu5.pdf#orchardkeycomponents
|
/// [orchardkeycomponents]: https://zips.z.cash/protocol/nu5.pdf#orchardkeycomponents
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct DiversifierKey([u8; 32]);
|
pub struct DiversifierKey([u8; 32]);
|
||||||
|
|
||||||
impl From<&FullViewingKey> for DiversifierKey {
|
impl From<&FullViewingKey> for DiversifierKey {
|
||||||
|
@ -345,7 +345,7 @@ impl Diversifier {
|
||||||
/// decryption of notes). When we actually want to serialize ivk, we're guaranteed to get
|
/// decryption of notes). When we actually want to serialize ivk, we're guaranteed to get
|
||||||
/// a valid base field element encoding, because we always construct ivk from an integer
|
/// a valid base field element encoding, because we always construct ivk from an integer
|
||||||
/// in the correct range.
|
/// in the correct range.
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct KeyAgreementPrivateKey(NonZeroPallasScalar);
|
struct KeyAgreementPrivateKey(NonZeroPallasScalar);
|
||||||
|
|
||||||
impl From<&FullViewingKey> for KeyAgreementPrivateKey {
|
impl From<&FullViewingKey> for KeyAgreementPrivateKey {
|
||||||
|
@ -382,7 +382,7 @@ impl KeyAgreementPrivateKey {
|
||||||
/// Defined in [Zcash Protocol Spec § 5.6.4.3: Orchard Raw Incoming Viewing Keys][orchardinviewingkeyencoding].
|
/// Defined in [Zcash Protocol Spec § 5.6.4.3: Orchard Raw Incoming Viewing Keys][orchardinviewingkeyencoding].
|
||||||
///
|
///
|
||||||
/// [orchardinviewingkeyencoding]: https://zips.z.cash/protocol/nu5.pdf#orchardinviewingkeyencoding
|
/// [orchardinviewingkeyencoding]: https://zips.z.cash/protocol/nu5.pdf#orchardinviewingkeyencoding
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct IncomingViewingKey {
|
pub struct IncomingViewingKey {
|
||||||
dk: DiversifierKey,
|
dk: DiversifierKey,
|
||||||
ivk: KeyAgreementPrivateKey,
|
ivk: KeyAgreementPrivateKey,
|
||||||
|
|
Loading…
Reference in New Issue