-
Notifications
You must be signed in to change notification settings - Fork 315
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: add a srs key loading bench #1474
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4d9a054
feat: add a srs key loading bench
cryptonemo 336e2fd
feat: add an aggregate proof encode/decode test
cryptonemo b0bfcbf
fix: separate aggregate proof test bytes from test
cryptonemo aff6b33
fix: improve tests by adding specific constants expected
cryptonemo eeea59e
doc: update comment and rename argument variable
cryptonemo fa076a9
feat: re-factor aggregation testing
cryptonemo 8f7b5f5
fix: comment out tests too big to run on CI
cryptonemo 8559ff6
fix: remove no longer needed imports
cryptonemo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -82,3 +82,7 @@ blst = [ | |
[[bench]] | ||
name = "preprocessing" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "aggregation" | ||
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,166 @@ | ||
use std::sync::Once; | ||
use std::time::Duration; | ||
|
||
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput}; | ||
use filecoin_proofs::{ | ||
caches::{get_stacked_srs_key, get_stacked_srs_verifier_key}, | ||
get_seal_inputs, PoRepConfig, PoRepProofPartitions, SectorShape2KiB, SectorShape32GiB, | ||
SectorSize, POREP_PARTITIONS, SECTOR_SIZE_2_KIB, SECTOR_SIZE_32_GIB, | ||
}; | ||
use rand::{thread_rng, Rng}; | ||
use storage_proofs_core::{api_version::ApiVersion, is_legacy_porep_id}; | ||
|
||
static INIT_LOGGER: Once = Once::new(); | ||
fn init_logger() { | ||
INIT_LOGGER.call_once(|| { | ||
fil_logger::init(); | ||
}); | ||
} | ||
|
||
fn bench_seal_inputs(c: &mut Criterion) { | ||
let params = vec![1, 256, 512, 1024]; | ||
|
||
let mut rng = thread_rng(); | ||
|
||
let porep_id_v1_1: u64 = 5; // This is a RegisteredSealProof value | ||
|
||
let mut porep_id = [0u8; 32]; | ||
porep_id[..8].copy_from_slice(&porep_id_v1_1.to_le_bytes()); | ||
assert!(!is_legacy_porep_id(porep_id)); | ||
|
||
let config = PoRepConfig { | ||
sector_size: SectorSize(SECTOR_SIZE_2_KIB), | ||
partitions: PoRepProofPartitions( | ||
*POREP_PARTITIONS | ||
.read() | ||
.expect("POREP_PARTITIONS poisoned") | ||
.get(&SECTOR_SIZE_2_KIB) | ||
.expect("unknown sector size"), | ||
), | ||
porep_id, | ||
api_version: ApiVersion::V1_1_0, | ||
}; | ||
let comm_r: [u8; 32] = [5u8; 32]; | ||
let comm_d: [u8; 32] = [6u8; 32]; | ||
let prover_id: [u8; 32] = [7u8; 32]; | ||
|
||
let ticket = rng.gen(); | ||
let seed = rng.gen(); | ||
let sector_id = rng.gen::<u64>().into(); | ||
|
||
let mut group = c.benchmark_group("bench_seal_inputs"); | ||
for iterations in params { | ||
group | ||
.bench_function(format!("get-seal-inputs-{}", iterations), |b| { | ||
b.iter(|| { | ||
for _ in 0..iterations { | ||
get_seal_inputs::<SectorShape2KiB>( | ||
config, comm_r, comm_d, prover_id, sector_id, ticket, seed, | ||
) | ||
.expect("get seal inputs failed"); | ||
} | ||
}); | ||
}) | ||
.sample_size(10) | ||
.throughput(Throughput::Bytes(iterations as u64)) | ||
.warm_up_time(Duration::from_secs(1)); | ||
} | ||
|
||
group.finish(); | ||
} | ||
|
||
fn bench_stacked_srs_key(c: &mut Criterion) { | ||
init_logger(); | ||
let params = vec![128, 256, 512, 1024]; | ||
|
||
let porep_id_v1_1: u64 = 5; // This is a RegisteredSealProof value | ||
|
||
let mut porep_id = [0u8; 32]; | ||
porep_id[..8].copy_from_slice(&porep_id_v1_1.to_le_bytes()); | ||
assert!(!is_legacy_porep_id(porep_id)); | ||
|
||
let config = PoRepConfig { | ||
sector_size: SectorSize(SECTOR_SIZE_32_GIB), | ||
partitions: PoRepProofPartitions( | ||
*POREP_PARTITIONS | ||
.read() | ||
.expect("POREP_PARTITIONS poisoned") | ||
.get(&SECTOR_SIZE_32_GIB) | ||
.expect("unknown sector size"), | ||
), | ||
porep_id, | ||
api_version: ApiVersion::V1_1_0, | ||
}; | ||
|
||
let mut group = c.benchmark_group("bench-stacked-srs-key"); | ||
for num_proofs_to_aggregate in params { | ||
group.bench_function( | ||
format!("get-stacked-srs-key-{}", num_proofs_to_aggregate), | ||
|b| { | ||
b.iter(|| { | ||
black_box( | ||
get_stacked_srs_key::<SectorShape32GiB>(config, num_proofs_to_aggregate) | ||
.expect("get stacked srs key failed"), | ||
) | ||
}) | ||
}, | ||
); | ||
} | ||
|
||
group.finish(); | ||
} | ||
|
||
fn bench_stacked_srs_verifier_key(c: &mut Criterion) { | ||
init_logger(); | ||
let params = vec![128, 256, 512, 1024]; | ||
|
||
let porep_id_v1_1: u64 = 5; // This is a RegisteredSealProof value | ||
|
||
let mut porep_id = [0u8; 32]; | ||
porep_id[..8].copy_from_slice(&porep_id_v1_1.to_le_bytes()); | ||
assert!(!is_legacy_porep_id(porep_id)); | ||
|
||
let config = PoRepConfig { | ||
sector_size: SectorSize(SECTOR_SIZE_32_GIB), | ||
partitions: PoRepProofPartitions( | ||
*POREP_PARTITIONS | ||
.read() | ||
.expect("POREP_PARTITIONS poisoned") | ||
.get(&SECTOR_SIZE_32_GIB) | ||
.expect("unknown sector size"), | ||
), | ||
porep_id, | ||
api_version: ApiVersion::V1_1_0, | ||
}; | ||
|
||
let mut group = c.benchmark_group("bench-stacked-srs-verifier-key"); | ||
for num_proofs_to_aggregate in params { | ||
group | ||
.bench_function( | ||
format!("get-stacked-srs-verifier-key-{}", num_proofs_to_aggregate), | ||
|b| { | ||
b.iter(|| { | ||
black_box( | ||
get_stacked_srs_verifier_key::<SectorShape32GiB>( | ||
config, | ||
num_proofs_to_aggregate, | ||
) | ||
.expect("get stacked srs key failed"), | ||
) | ||
}) | ||
}, | ||
) | ||
.sample_size(10) | ||
.warm_up_time(Duration::from_secs(1)); | ||
} | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group!( | ||
benches, | ||
bench_seal_inputs, | ||
bench_stacked_srs_key, | ||
bench_stacked_srs_verifier_key, | ||
); | ||
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
Binary file not shown.
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 |
---|---|---|
|
@@ -5,7 +5,9 @@ use std::path::{Path, PathBuf}; | |
use std::sync::Once; | ||
|
||
use anyhow::{ensure, Result}; | ||
use bellperson::bls::Fr; | ||
use bellperson::bls::{Bls12, Fr}; | ||
use bellperson::groth16; | ||
use bincode::serialize; | ||
use ff::Field; | ||
use filecoin_hashers::Hasher; | ||
use filecoin_proofs::{ | ||
|
@@ -231,6 +233,13 @@ fn test_seal_proof_aggregation_5_2kib_porep_id_v1_1_base_8() -> Result<()> { | |
inner_test_seal_proof_aggregation_2kib_porep_id_v1_1_base_8(proofs_to_aggregate) | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn test_seal_proof_aggregation_257_2kib_porep_id_v1_1_base_8() -> Result<()> { | ||
let proofs_to_aggregate = 257; // Requires auto-padding | ||
inner_test_seal_proof_aggregation_2kib_porep_id_v1_1_base_8(proofs_to_aggregate) | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn test_seal_proof_aggregation_2_4kib_porep_id_v1_1_base_8() -> Result<()> { | ||
|
@@ -1474,3 +1483,26 @@ fn create_fake_seal<R: rand::Rng, Tree: 'static + MerkleTreeTrait>( | |
|
||
Ok((sector_id, sealed_sector_file, comm_r, cache_dir)) | ||
} | ||
|
||
#[test] | ||
fn test_aggregate_proof_encode_decode() -> Result<()> { | ||
// This byte vector is a natively serialized aggregate proof. | ||
let aggregate_proof_bytes = std::include_bytes!("./aggregate_proof_bytes"); | ||
|
||
// Re-construct the aggregate proof from the bytes, using the native deserialization method. | ||
let aggregate_proof: groth16::aggregate::AggregateProof<Bls12> = | ||
groth16::aggregate::AggregateProof::read(std::io::Cursor::new(&aggregate_proof_bytes))?; | ||
|
||
// Re-serialize the proof to ensure a round-trip match. | ||
let mut aggregate_proof_bytes2 = Vec::new(); | ||
aggregate_proof.write(&mut aggregate_proof_bytes2)?; | ||
|
||
assert_eq!(aggregate_proof_bytes.len(), aggregate_proof_bytes2.len()); | ||
assert_eq!(aggregate_proof_bytes, aggregate_proof_bytes2.as_slice()); | ||
|
||
// Note: the native serialization format is more compact than bincode serialization, so assert that here. | ||
let bincode_serialized_proof = serialize(&aggregate_proof)?; | ||
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. lets actually weite the numbers as constants in here as well |
||
assert!(aggregate_proof_bytes2.len() < bincode_serialized_proof.len()); | ||
|
||
Ok(()) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
no need to specify the type