-
Notifications
You must be signed in to change notification settings - Fork 0
Upstream PR 471 (OrchardZSA) – internal review and fixes #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7f8a848
1328c62
e6b7762
088abc6
1420f84
0b2988a
9b43497
985d0d2
f3ebe7a
355b569
9405f80
d8f3563
5a50fb8
efbfc19
babf1da
4681cc2
cec48d7
4e47677
cbf0a3a
43d5e77
527e29a
f0b7948
563b4e5
7d3b6df
ea0fd59
9a35108
4e1c616
c77d96c
aeb9934
b4f6281
95fcf88
8e71fff
bedc732
32eee6e
02fa582
9965a6d
7ad2bac
950b806
8bc18f7
5b003f8
f49be89
aa1d895
daf6269
477f949
d4ff716
21d7273
62d4ae7
1a00c4a
ff2ac96
081513b
139ecca
7937e5b
8b0560d
2810365
a680f41
7b943e1
f38d6b9
0ee75f5
344b647
1a1f3e7
c9a8f49
f3d9459
0f56f52
149827d
c8c84aa
ac371f0
7969b9e
47f7aae
bb9e03b
dd956b8
123b609
ee89541
73218b0
50c6310
78c8efc
39b479e
6e6112c
07b3697
3ba9e5b
e2fb49d
dd69425
410037d
a7c02d2
25020f8
8a2a8de
adc6995
97cf5a3
8b89888
fe15076
9eb97f0
3d2515b
0d2f439
69f92a3
3dbdbc5
70daf8b
40e7e10
01e85a5
a95364c
b62f72a
b8d4543
e88e261
aeec27d
123a2f4
190a50c
831ca10
75c55b2
6d557af
5c09d33
c7d57b1
37101f4
57f39bf
d56c5d5
cb539d4
5f080b4
8388060
572ba6b
502c410
8509081
cf31792
0a61d36
f2411a0
9a25bd1
7e4f28c
6616893
cbcdb71
fdd69e2
1746a4b
9f44f55
f7bcf01
c1f3dcc
806878c
fab774d
58b710b
0982ff6
826dc03
76d9b7e
8784d39
cc68804
0e496fe
532b0d2
b4517e3
d18f0d5
962564b
78b6f76
cf6d3b6
abd6ecc
fc73b8e
a7de16f
2083efe
a02fdf1
c59a2a5
ca1e342
6836da8
0de4303
36b53cb
a0012b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| /target | ||
| **/*.rs.bk | ||
| .vscode | ||
| .idea | ||
| action-circuit-layout.png |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,28 +10,43 @@ use orchard::{ | |
| builder::{Builder, BundleType}, | ||
| circuit::{ProvingKey, VerifyingKey}, | ||
| keys::{FullViewingKey, Scope, SpendingKey}, | ||
| note::AssetBase, | ||
| orchard_flavor::{OrchardVanilla, OrchardZSA}, | ||
| value::NoteValue, | ||
| Anchor, Bundle, | ||
| }; | ||
| use rand::rngs::OsRng; | ||
|
|
||
| fn criterion_benchmark(c: &mut Criterion) { | ||
| mod utils; | ||
|
|
||
| use utils::OrchardFlavorBench; | ||
|
|
||
| fn criterion_benchmark<FL: OrchardFlavorBench>(c: &mut Criterion) { | ||
| let rng = OsRng; | ||
|
|
||
| let sk = SpendingKey::from_bytes([7; 32]).unwrap(); | ||
| let recipient = FullViewingKey::from(&sk).address_at(0u32, Scope::External); | ||
|
|
||
| let vk = VerifyingKey::build(); | ||
| let pk = ProvingKey::build(); | ||
| let vk = VerifyingKey::build::<FL>(); | ||
| let pk = ProvingKey::build::<FL>(); | ||
|
|
||
| let create_bundle = |num_recipients| { | ||
| let mut builder = Builder::new(BundleType::DEFAULT, Anchor::from_bytes([0; 32]).unwrap()); | ||
| let mut builder = Builder::new( | ||
| BundleType::DEFAULT_VANILLA, | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. str4d (Link): Bug: you are using |
||
| Anchor::from_bytes([0; 32]).unwrap(), | ||
| ); | ||
| for _ in 0..num_recipients { | ||
| builder | ||
| .add_output(None, recipient, NoteValue::from_raw(10), [0; 512]) | ||
| .add_output( | ||
| None, | ||
| recipient, | ||
| NoteValue::from_raw(10), | ||
| AssetBase::native(), | ||
| [0; 512], | ||
| ) | ||
| .unwrap(); | ||
| } | ||
| let bundle: Bundle<_, i64> = builder.build(rng).unwrap().unwrap().0; | ||
| let bundle: Bundle<_, i64, FL> = builder.build(rng).unwrap().0; | ||
|
|
||
| let instances: Vec<_> = bundle | ||
| .actions() | ||
|
|
@@ -45,23 +60,23 @@ fn criterion_benchmark(c: &mut Criterion) { | |
| let recipients_range = 1..=4; | ||
|
|
||
| { | ||
| let mut group = c.benchmark_group("proving"); | ||
| let mut group = FL::benchmark_group(c, "proving"); | ||
| group.sample_size(10); | ||
| for num_recipients in recipients_range.clone() { | ||
| let (bundle, instances) = create_bundle(num_recipients); | ||
| group.bench_function(BenchmarkId::new("bundle", num_recipients), |b| { | ||
| b.iter(|| { | ||
| bundle | ||
| .authorization() | ||
| .create_proof(&pk, &instances, rng) | ||
| .create_proof::<FL>(&pk, &instances, rng) | ||
| .unwrap() | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| { | ||
| let mut group = c.benchmark_group("verifying"); | ||
| let mut group = FL::benchmark_group(c, "verifying"); | ||
| for num_recipients in recipients_range { | ||
| let (bundle, instances) = create_bundle(num_recipients); | ||
| let bundle = bundle | ||
|
|
@@ -78,15 +93,25 @@ fn criterion_benchmark(c: &mut Criterion) { | |
| } | ||
|
|
||
| #[cfg(unix)] | ||
| criterion_group! { | ||
| name = benches; | ||
| config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); | ||
| targets = criterion_benchmark | ||
| fn create_config() -> Criterion { | ||
| Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))) | ||
| } | ||
|
|
||
| #[cfg(windows)] | ||
| fn create_config() -> Criterion { | ||
| Criterion::default() | ||
| } | ||
|
|
||
| criterion_group! { | ||
| name = benches; | ||
| config = Criterion::default(); | ||
| targets = criterion_benchmark | ||
| name = benches_vanilla; | ||
| config = create_config(); | ||
| targets = criterion_benchmark::<OrchardVanilla> | ||
| } | ||
| criterion_main!(benches); | ||
|
|
||
| criterion_group! { | ||
| name = benches_zsa; | ||
| config = create_config(); | ||
| targets = criterion_benchmark::<OrchardZSA> | ||
| } | ||
|
|
||
| criterion_main!(benches_vanilla, benches_zsa); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,9 @@ use orchard::{ | |
| builder::{Builder, BundleType}, | ||
| circuit::ProvingKey, | ||
| keys::{FullViewingKey, PreparedIncomingViewingKey, Scope, SpendingKey}, | ||
| note_encryption::{CompactAction, OrchardDomain}, | ||
| note::AssetBase, | ||
| orchard_flavor::{OrchardVanilla, OrchardZSA}, | ||
| primitives::{CompactAction, OrchardDomain}, | ||
| value::NoteValue, | ||
| Anchor, Bundle, | ||
| }; | ||
|
|
@@ -13,9 +15,13 @@ use zcash_note_encryption::{batch, try_compact_note_decryption, try_note_decrypt | |
| #[cfg(unix)] | ||
| use pprof::criterion::{Output, PProfProfiler}; | ||
|
|
||
| fn bench_note_decryption(c: &mut Criterion) { | ||
| mod utils; | ||
|
|
||
| use utils::OrchardFlavorBench; | ||
|
|
||
| fn bench_note_decryption<FL: OrchardFlavorBench>(c: &mut Criterion) { | ||
| let rng = OsRng; | ||
| let pk = ProvingKey::build(); | ||
| let pk = ProvingKey::build::<FL>(); | ||
|
|
||
| let fvk = FullViewingKey::from(&SpendingKey::from_bytes([7; 32]).unwrap()); | ||
| let valid_ivk = fvk.to_ivk(Scope::External); | ||
|
|
@@ -44,16 +50,31 @@ fn bench_note_decryption(c: &mut Criterion) { | |
| .collect(); | ||
|
|
||
| let bundle = { | ||
| let mut builder = Builder::new(BundleType::DEFAULT, Anchor::from_bytes([0; 32]).unwrap()); | ||
| let mut builder = Builder::new( | ||
| BundleType::DEFAULT_VANILLA, | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. str4d (Link): Bug: same issue here. |
||
| Anchor::from_bytes([0; 32]).unwrap(), | ||
| ); | ||
| // The builder pads to two actions, and shuffles their order. Add two recipients | ||
| // so the first action is always decryptable. | ||
| builder | ||
| .add_output(None, recipient, NoteValue::from_raw(10), [0; 512]) | ||
| .add_output( | ||
| None, | ||
| recipient, | ||
| NoteValue::from_raw(10), | ||
| AssetBase::native(), | ||
| [0; 512], | ||
| ) | ||
| .unwrap(); | ||
| builder | ||
| .add_output(None, recipient, NoteValue::from_raw(10), [0; 512]) | ||
| .add_output( | ||
| None, | ||
| recipient, | ||
| NoteValue::from_raw(10), | ||
| AssetBase::native(), | ||
| [0; 512], | ||
| ) | ||
| .unwrap(); | ||
| let bundle: Bundle<_, i64> = builder.build(rng).unwrap().unwrap().0; | ||
| let bundle: Bundle<_, i64, FL> = builder.build(rng).unwrap().0; | ||
| bundle | ||
| .create_proof(&pk, rng) | ||
| .unwrap() | ||
|
|
@@ -65,7 +86,7 @@ fn bench_note_decryption(c: &mut Criterion) { | |
| let domain = OrchardDomain::for_action(action); | ||
|
|
||
| let compact = { | ||
| let mut group = c.benchmark_group("note-decryption"); | ||
| let mut group = FL::benchmark_group(c, "note-decryption"); | ||
| group.throughput(Throughput::Elements(1)); | ||
|
|
||
| group.bench_function("valid", |b| { | ||
|
|
@@ -87,7 +108,7 @@ fn bench_note_decryption(c: &mut Criterion) { | |
| }; | ||
|
|
||
| { | ||
| let mut group = c.benchmark_group("compact-note-decryption"); | ||
| let mut group = FL::benchmark_group(c, "compact-note-decryption"); | ||
| group.throughput(Throughput::Elements(invalid_ivks.len() as u64)); | ||
| group.bench_function("invalid", |b| { | ||
| b.iter(|| { | ||
|
|
@@ -114,7 +135,7 @@ fn bench_note_decryption(c: &mut Criterion) { | |
| }) | ||
| .collect(); | ||
|
|
||
| let mut group = c.benchmark_group("batch-note-decryption"); | ||
| let mut group = FL::benchmark_group(c, "batch-note-decryption"); | ||
|
|
||
| for size in [10, 50, 100] { | ||
| group.throughput(Throughput::Elements((ivks * size) as u64)); | ||
|
|
@@ -141,11 +162,25 @@ fn bench_note_decryption(c: &mut Criterion) { | |
| } | ||
|
|
||
| #[cfg(unix)] | ||
| fn create_config() -> Criterion { | ||
| Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))) | ||
| } | ||
|
|
||
| #[cfg(windows)] | ||
| fn create_config() -> Criterion { | ||
| Criterion::default() | ||
| } | ||
|
|
||
| criterion_group! { | ||
| name = benches; | ||
| config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); | ||
| targets = bench_note_decryption | ||
| name = benches_vanilla; | ||
| config = create_config(); | ||
| targets = bench_note_decryption::<OrchardVanilla> | ||
| } | ||
| #[cfg(not(unix))] | ||
| criterion_group!(benches, bench_note_decryption); | ||
| criterion_main!(benches); | ||
|
|
||
| criterion_group! { | ||
| name = benches_zsa; | ||
| config = create_config(); | ||
| targets = bench_note_decryption::<OrchardZSA> | ||
| } | ||
|
|
||
| criterion_main!(benches_vanilla, benches_zsa); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| use criterion::{measurement::Measurement, BenchmarkGroup, Criterion}; | ||
|
|
||
| use orchard::orchard_flavor::{OrchardFlavor, OrchardVanilla, OrchardZSA}; | ||
|
|
||
| pub(crate) trait OrchardFlavorBench: OrchardFlavor { | ||
| fn benchmark_group<'a, M: Measurement>( | ||
| c: &'a mut Criterion<M>, | ||
| group_name: &str, | ||
| ) -> BenchmarkGroup<'a, M>; | ||
| } | ||
|
|
||
| impl OrchardFlavorBench for OrchardVanilla { | ||
| fn benchmark_group<'a, M: Measurement>( | ||
| c: &'a mut Criterion<M>, | ||
| group_name: &str, | ||
| ) -> BenchmarkGroup<'a, M> { | ||
| c.benchmark_group(format!("[OrchardVanilla] {}", group_name)) | ||
| } | ||
| } | ||
|
|
||
| impl OrchardFlavorBench for OrchardZSA { | ||
| fn benchmark_group<'a, M: Measurement>( | ||
| c: &'a mut Criterion<M>, | ||
| group_name: &str, | ||
| ) -> BenchmarkGroup<'a, M> { | ||
| c.benchmark_group(format!("[OrchardZSA] {}", group_name)) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
str4d (Link): I checked these revisions.