-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67d47d9
commit fb33424
Showing
19 changed files
with
2,131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"editor.tokenColorCustomizations": { | ||
"textMateRules": [ | ||
{ | ||
"scope": "googletest.failed", | ||
"settings": { | ||
"foreground": "#f00" | ||
} | ||
}, | ||
{ | ||
"scope": "googletest.passed", | ||
"settings": { | ||
"foreground": "#0f0" | ||
} | ||
}, | ||
{ | ||
"scope": "googletest.run", | ||
"settings": { | ||
"foreground": "#0f0" | ||
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/target | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"editor.tokenColorCustomizations": { | ||
"textMateRules": [ | ||
{ | ||
"scope": "googletest.failed", | ||
"settings": { | ||
"foreground": "#f00" | ||
} | ||
}, | ||
{ | ||
"scope": "googletest.passed", | ||
"settings": { | ||
"foreground": "#0f0" | ||
} | ||
}, | ||
{ | ||
"scope": "googletest.run", | ||
"settings": { | ||
"foreground": "#0f0" | ||
} | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[package] | ||
name = "ipa-multipoint" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
rand = "0.6" | ||
criterion = "0.3.4" | ||
bandersnatch = "0.1.1" | ||
ark-ff = { version = "^0.3.0", default-features = false } | ||
ark-ec = { version = "^0.3.0", default-features = false } | ||
ark-std = { version = "^0.3.0", default-features = false } | ||
ark-serialize = { version = "^0.3.0", default-features = false } | ||
ark-poly = { version = "^0.3.0", default-features = false } | ||
rand_chacha = { version = "0.3.0", default-features = false } | ||
itertools = "0.10.1" | ||
sha2 = "0.9.8" | ||
hex = "0.4.3" | ||
banderwagon = { git = "https://github.com/crate-crypto/banderwagon" } | ||
|
||
[[bench]] | ||
name = "benchmark_main" | ||
harness = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Kevaundray Wedderburn | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
## IPA Multipoint | ||
|
||
A polynomial commitment scheme for opening multiple polynomials at different points using the inner product argument. | ||
|
||
This library uses the banderwagon prime group (https://hackmd.io/@6iQDuIePQjyYBqDChYw_jg/BJ2-L6Nzc) built on top of bandersnatch curve described in [https://eprint.iacr.org/2021/1152.pdf]. | ||
|
||
|
||
**Do not use in production.** | ||
|
||
### Security | ||
|
||
- The CRS is not being generated in a secure manner. The relative DLOG is known. In actuality, we want to use a hash_to_group algorithm. Try and increment would be the easiest one to implement as we do not care about timing attacks. | ||
|
||
- Even with this, the code has not been reviewed, so should not be used in production. | ||
|
||
## Efficiency | ||
|
||
- Parallelism is not being used | ||
- We have not modified pippenger to take benefit of the GLV endomorphism | ||
|
||
## API | ||
|
||
- We should wrap the IPA proof in a poly commit struct, so that users cannot mix up the `a_vec` and `b_vec`, we will not commit to `b_vec` as a poly-commit | ||
|
||
## Tentative benchmarks | ||
|
||
Bandersnatch (old): | ||
|
||
Machine : 2.4 GHz 8-Core Intel Core i9 | ||
|
||
- To verify the opening of a polynomial of degree 255 (256 points in lagrange basis): `11.92ms` | ||
|
||
- To verify a multi-opening proof of 10,000 polynomials: `232.12ms` | ||
|
||
- To verify a multi-opening proof of 20,000 polynomials: `405.87ms` | ||
|
||
- To prove a multi-opening proof of 10,000 polynomials: `266.49ms` | ||
|
||
- To prove a multi-opening proof of 20,000 polynomials: `422.94ms` | ||
|
||
|
||
|
||
New benchmark on banderwagon subgroup: Apple M1 Pro 16GB RAM | ||
|
||
- ipa - prove (256): `28.700 ms` | ||
|
||
- ipa - verify (multi exp2 256): `2.1628 ms` | ||
|
||
- ipa - verify (256): `20.818 ms` | ||
|
||
- multipoint - verify (256)/1: `2.6983 ms` | ||
|
||
- multipoint - verify (256)/1000: `8.5925 ms` | ||
|
||
- multipoint - verify (256)/2000: `12.688 ms` | ||
|
||
- multipoint - verify (256)/4000: `21.726 ms` | ||
|
||
- multipoint - verify (256)/8000: `36.616 ms` | ||
|
||
- multipoint - verify (256)/16000: `69.401 ms` | ||
|
||
- multipoint - verify (256)/128000: `490.23 ms` | ||
|
||
- multiproof - prove (256)/1: `33.231 ms` | ||
|
||
- multiproof - prove (256)/1000: `47.764 ms` | ||
|
||
- multiproof - prove (256)/2000: `56.670 ms` | ||
|
||
- multiproof - prove (256)/4000: `74.597 ms` | ||
|
||
- multiproof - prove (256)/8000: `114.39 ms` | ||
|
||
- multiproof - prove (256)/16000: `189.94 ms` | ||
|
||
- multiproof - prove (256)/128000: `1.2693 s` | ||
|
||
|
||
|
||
*These benchmarks are tentative because on one hand, the machine being used may not be the what the average user uses, while on the other hand, we have not optimised the verifier algorithm to remove `bH` , the pippenger algorithm does not take into consideration GLV and we are not using rayon to parallelise.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use criterion::criterion_main; | ||
|
||
mod benchmarks; | ||
criterion_main! { | ||
benchmarks::ipa_prove::benches, | ||
benchmarks::ipa_verify::benches, | ||
benchmarks::multipoint_verify::benches, | ||
benchmarks::multipoint_prove::benches, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use ark_std::rand::SeedableRng; | ||
use ark_std::UniformRand; | ||
use banderwagon::Fr; | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use ipa_multipoint::ipa::create; | ||
use ipa_multipoint::lagrange_basis::LagrangeBasis; | ||
use ipa_multipoint::math_utils::powers_of; | ||
use ipa_multipoint::crs::CRS; | ||
use ipa_multipoint::transcript::Transcript; | ||
use rand_chacha::ChaCha20Rng; | ||
|
||
pub fn criterion_benchmark(c: &mut Criterion) { | ||
let n = 256; | ||
let mut rng = ChaCha20Rng::from_seed([0u8; 32]); | ||
|
||
let a: Vec<Fr> = (0..n).map(|_| Fr::rand(&mut rng)).collect(); | ||
let input_point = Fr::rand(&mut rng); | ||
let b_vec = powers_of(input_point, n); | ||
|
||
let crs = CRS::new(n, "lol".as_bytes()); | ||
|
||
let mut prover_transcript = Transcript::new(b"ip_no_zk"); | ||
|
||
let a_lagrange = LagrangeBasis::new(a.clone()); | ||
let a_comm = crs.commit_lagrange_poly(&a_lagrange); | ||
|
||
c.bench_function("ipa - prove (256)", |b| { | ||
b.iter(|| { | ||
black_box(create( | ||
&mut prover_transcript, | ||
crs.clone(), | ||
a.clone(), | ||
a_comm, | ||
b_vec.clone(), | ||
input_point, | ||
)) | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use ark_std::rand::SeedableRng; | ||
use ark_std::UniformRand; | ||
use banderwagon::Fr; | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use ipa_multipoint::ipa::create; | ||
use ipa_multipoint::lagrange_basis::LagrangeBasis; | ||
use ipa_multipoint::math_utils::{inner_product, powers_of}; | ||
use ipa_multipoint::crs::CRS; | ||
use ipa_multipoint::transcript::Transcript; | ||
use rand_chacha::ChaCha20Rng; | ||
|
||
pub fn criterion_benchmark(c: &mut Criterion) { | ||
let n = 256; | ||
let mut rng = ChaCha20Rng::from_seed([0u8; 32]); | ||
|
||
let a: Vec<Fr> = (0..n).map(|_| Fr::rand(&mut rng)).collect(); | ||
let input_point = Fr::rand(&mut rng); | ||
let b_vec = powers_of(input_point, n); | ||
let output_point = inner_product(&a, &b_vec); | ||
|
||
let crs = CRS::new(n, "lol".as_bytes()); | ||
|
||
let mut prover_transcript = Transcript::new(b"ip_no_zk"); | ||
|
||
let a_lagrange = LagrangeBasis::new(a.clone()); | ||
let a_comm = crs.commit_lagrange_poly(&a_lagrange); | ||
|
||
let proof = create( | ||
&mut prover_transcript, | ||
crs.clone(), | ||
a, | ||
a_comm, | ||
b_vec.clone(), | ||
input_point, | ||
); | ||
|
||
c.bench_function("ipa - verify (multi exp2 256)", |b| { | ||
b.iter(|| { | ||
let mut verifier_transcript = Transcript::new(b"ip_no_zk"); | ||
black_box(proof.verify_multiexp( | ||
&mut verifier_transcript, | ||
&crs, | ||
b_vec.clone(), | ||
a_comm, | ||
input_point, | ||
output_point, | ||
)) | ||
}) | ||
}); | ||
|
||
c.bench_function("ipa - verify (256)", |b| { | ||
b.iter(|| { | ||
let mut verifier_transcript = Transcript::new(b"ip_no_zk"); | ||
black_box(proof.verify( | ||
&mut verifier_transcript, | ||
crs.clone(), | ||
b_vec.clone(), | ||
a_comm, | ||
input_point, | ||
output_point, | ||
)) | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub mod ipa_prove; | ||
pub mod ipa_verify; | ||
pub mod multipoint_prove; | ||
pub mod multipoint_verify; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use ark_std::UniformRand; | ||
use banderwagon::Fr; | ||
use criterion::BenchmarkId; | ||
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion}; | ||
use ipa_multipoint::lagrange_basis::*; | ||
use ipa_multipoint::multiproof::*; | ||
use ipa_multipoint::transcript::Transcript; | ||
use ipa_multipoint::crs::CRS; | ||
|
||
pub fn criterion_benchmark(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("multiproof - prove (256)"); | ||
|
||
use ark_std::test_rng; | ||
|
||
// Setup parameters, n is the degree + 1 | ||
// CRs is the G_Vec, H_Vec, Q group elements | ||
let n = 256; | ||
let crs = CRS::new(n, b"random seed"); | ||
|
||
let mut rng = test_rng(); | ||
let poly = LagrangeBasis::new((0..n).map(|_| Fr::rand(&mut rng)).collect()); | ||
let poly_comm = crs.commit_lagrange_poly(&poly); | ||
|
||
for num_polynomials in [1, 1_000, 2_000, 4_000, 8_000, 16_000, 128_000] { | ||
let mut polys: Vec<LagrangeBasis> = Vec::with_capacity(num_polynomials); | ||
for _ in 0..num_polynomials { | ||
polys.push(poly.clone()) | ||
} | ||
|
||
let mut prover_queries = Vec::with_capacity(num_polynomials); | ||
for (i, poly) in polys.into_iter().enumerate() { | ||
let point = i % n; | ||
|
||
let y_i = poly.evaluate_in_domain(point); | ||
|
||
let prover_query = ProverQuery { | ||
commitment: poly_comm, | ||
poly, | ||
point, | ||
result: y_i, | ||
}; | ||
|
||
prover_queries.push(prover_query); | ||
} | ||
|
||
let precomp = PrecomputedWeights::new(n); | ||
|
||
group.bench_with_input( | ||
BenchmarkId::from_parameter(num_polynomials), | ||
&num_polynomials, | ||
|b, _| { | ||
b.iter_batched( | ||
|| (Transcript::new(b"foo"), prover_queries.clone()), | ||
|(mut transcript, prover_queries)| { | ||
black_box(MultiPoint::open( | ||
crs.clone(), | ||
&precomp, | ||
&mut transcript, | ||
prover_queries, | ||
)) | ||
}, | ||
BatchSize::SmallInput, | ||
) | ||
}, | ||
); | ||
} | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
Oops, something went wrong.