Skip to content
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

feat(vid): port VID from another repo #337

Merged
merged 6 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ and follow [semantic versioning](https://semver.org/) for our releases.
- [#291](https://github.com/EspressoSystems/jellyfish/pull/291) Non-native field operations and elliptic curve addition
- [#309](https://github.com/EspressoSystems/jellyfish/pull/309) Reed-Solomon decoder accept FFT domain
- [#320](https://github.com/EspressoSystems/jellyfish/pull/320) Non-native elliptic curve addition in short Weierstrass form
- [#337](https://github.com/EspressoSystems/jellyfish/pull/337) Port VID from another repo

### Changed

Expand Down
2 changes: 1 addition & 1 deletion plonk/src/circuit/plonk_verifier/gadgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ where
}
let mut transcript_var = RescueTranscriptVar::new(circuit);
if let Some(msg) = extra_transcript_init_msg {
let msg_fs = bytes_to_field_elements::<_, F>(msg);
let msg_fs = bytes_to_field_elements::<_, F>(<&Vec<u8> as AsRef<[u8]>>::as_ref(&msg));
alxiong marked this conversation as resolved.
Show resolved Hide resolved
let msg_vars = msg_fs
.iter()
.map(|x| circuit.create_variable(*x))
Expand Down
2 changes: 1 addition & 1 deletion plonk/src/circuit/transcript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ mod tests {
for _ in 0..10 {
for i in 0..10 {
let msg = format!("message {}", i);
let vals = bytes_to_field_elements(&msg);
let vals = bytes_to_field_elements(msg.as_bytes());
let message_vars: Vec<Variable> = vals
.iter()
.map(|x| circuit.create_variable(*x).unwrap())
Expand Down
5 changes: 5 additions & 0 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ license = { workspace = true }
rust-version = { workspace = true }

[dependencies]
anyhow = "1.0"
ark-bls12-377 = "0.4.0"
ark-bls12-381 = "0.4.0"
ark-bn254 = "0.4.0"
Expand Down Expand Up @@ -79,6 +80,10 @@ name = "reed-solomon"
path = "benches/reed_solomon.rs"
harness = false

[[bench]]
name = "advz"
harness = false

[features]
default = ["parallel"]
std = [
Expand Down
126 changes: 126 additions & 0 deletions primitives/benches/advz.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#![cfg(feature = "test-srs")]
use ark_bls12_381::Bls12_381;
use ark_bn254::Bn254;
use ark_ec::pairing::Pairing;
use ark_serialize::Write;
use ark_std::rand::RngCore;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use digest::{Digest, DynDigest, OutputSizeUser};
use generic_array::ArrayLength;
use jf_primitives::{
pcs::{checked_fft_size, prelude::UnivariateKzgPCS, PolynomialCommitmentScheme},
vid::{advz::Advz, VidScheme},
};
use sha2::Sha256;

const KB: usize = 1 << 10;
const MB: usize = KB << 10;

fn advz<E, H>(c: &mut Criterion, pairing_name: &str)
where
E: Pairing,
// TODO(Gus) clean up nasty trait bounds upstream
H: Digest + DynDigest + Default + Clone + Write,
<<H as OutputSizeUser>::OutputSize as ArrayLength<u8>>::ArrayType: Copy,
{
// play with these items
const RATE: usize = 4; // ratio of num_storage_nodes : polynomial_degree
let storage_node_counts = [600, 700, 800, 900, 1000];
let payload_byte_lens = [1 * MB];

// more items as a function of the above
let poly_degrees_iter = storage_node_counts.iter().map(|c| c / RATE);
let supported_degree = poly_degrees_iter.clone().max().unwrap();
let vid_sizes_iter = poly_degrees_iter.zip(storage_node_counts);
let mut rng = jf_utils::test_rng();
let srs = UnivariateKzgPCS::<E>::gen_srs_for_testing(
&mut rng,
checked_fft_size(supported_degree).unwrap(),
)
.unwrap();

// run all benches for each payload_byte_lens
for len in payload_byte_lens {
// random payload data
let mut payload_bytes = vec![0u8; len];
rng.fill_bytes(&mut payload_bytes);

let benchmark_group_name =
|op_name| format!("advz_{}_{}_{}KB", pairing_name, op_name, len / KB);

// commit
let mut grp = c.benchmark_group(benchmark_group_name("commit"));
grp.throughput(Throughput::Bytes(len as u64));
for (poly_degree, num_storage_nodes) in vid_sizes_iter.clone() {
let advz = Advz::<E, H>::new(poly_degree, num_storage_nodes, &srs).unwrap();
grp.bench_with_input(
BenchmarkId::from_parameter(num_storage_nodes),
&num_storage_nodes,
|b, _| {
b.iter(|| advz.commit(&payload_bytes).unwrap());
},
);
}
grp.finish();

// disperse
let mut grp = c.benchmark_group(benchmark_group_name("disperse"));
grp.throughput(Throughput::Bytes(len as u64));
for (poly_degree, num_storage_nodes) in vid_sizes_iter.clone() {
let advz = Advz::<E, H>::new(poly_degree, num_storage_nodes, &srs).unwrap();
grp.bench_with_input(
BenchmarkId::from_parameter(num_storage_nodes),
&num_storage_nodes,
|b, _| {
b.iter(|| advz.dispersal_data(&payload_bytes).unwrap());
},
);
}
grp.finish();

// verify
let mut grp = c.benchmark_group(benchmark_group_name("verify"));
grp.throughput(Throughput::Bytes(len as u64));
for (poly_degree, num_storage_nodes) in vid_sizes_iter.clone() {
let advz = Advz::<E, H>::new(poly_degree, num_storage_nodes, &srs).unwrap();
let (shares, common) = advz.dispersal_data(&payload_bytes).unwrap();
grp.bench_with_input(
BenchmarkId::from_parameter(num_storage_nodes),
&num_storage_nodes,
|b, _| {
// verify only the 0th share
b.iter(|| advz.verify_share(&shares[0], &common).unwrap().unwrap());
},
);
}
grp.finish();

// recover
let mut grp = c.benchmark_group(benchmark_group_name("recover"));
grp.throughput(Throughput::Bytes(len as u64));
for (poly_degree, num_storage_nodes) in vid_sizes_iter.clone() {
let advz = Advz::<E, H>::new(poly_degree, num_storage_nodes, &srs).unwrap();
let (shares, common) = advz.dispersal_data(&payload_bytes).unwrap();
grp.bench_with_input(
BenchmarkId::from_parameter(num_storage_nodes),
&num_storage_nodes,
|b, _| {
// recover from only the first poly_degree shares
b.iter(|| {
advz.recover_payload(&shares[..poly_degree], &common)
.unwrap()
});
},
);
}
grp.finish();
}
}

fn advz_main(c: &mut Criterion) {
advz::<Bls12_381, Sha256>(c, "Bls381");
advz::<Bn254, Sha256>(c, "Bn254");
}

criterion_group!(name = benches; config = Criterion::default().sample_size(10); targets = advz_main);
criterion_main!(benches);
1 change: 1 addition & 0 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub mod reed_solomon_code;
pub mod rescue;
pub mod signatures;
pub mod toeplitz;
pub mod vid;
pub mod vrf;

pub(crate) mod utils;
Loading
Loading