|
| 1 | +extern crate bellman; |
| 2 | +extern crate pairing; |
| 3 | +extern crate rand; |
| 4 | +extern crate sapling_crypto; |
| 5 | +#[macro_use] |
| 6 | +extern crate clap; |
| 7 | +#[cfg(feature = "profile")] |
| 8 | +extern crate gperftools; |
| 9 | +extern crate memmap; |
| 10 | +extern crate tempfile; |
| 11 | +#[macro_use] |
| 12 | +extern crate slog; |
| 13 | + |
| 14 | +extern crate filecoin_proofs; |
| 15 | +extern crate storage_proofs; |
| 16 | + |
| 17 | +use clap::{App, Arg}; |
| 18 | +#[cfg(feature = "profile")] |
| 19 | +use gperftools::profiler::PROFILER; |
| 20 | +use pairing::bls12_381::Bls12; |
| 21 | +use rand::{Rng, SeedableRng, XorShiftRng}; |
| 22 | +use std::time::{Duration, Instant}; |
| 23 | + |
| 24 | +use filecoin_proofs::FCP_LOG; |
| 25 | +use storage_proofs::beacon_post::*; |
| 26 | +use storage_proofs::drgraph::*; |
| 27 | +use storage_proofs::example_helper::prettyb; |
| 28 | +use storage_proofs::fr32::fr_into_bytes; |
| 29 | +use storage_proofs::hasher::pedersen::PedersenDomain; |
| 30 | +use storage_proofs::hasher::PedersenHasher; |
| 31 | +use storage_proofs::proof::ProofScheme; |
| 32 | +use storage_proofs::{vdf_post, vdf_sloth}; |
| 33 | + |
| 34 | +#[cfg(feature = "profile")] |
| 35 | +#[inline(always)] |
| 36 | +fn start_profile(stage: &str) { |
| 37 | + PROFILER |
| 38 | + .lock() |
| 39 | + .unwrap() |
| 40 | + .start(format!("./{}.profile", stage)) |
| 41 | + .unwrap(); |
| 42 | +} |
| 43 | + |
| 44 | +#[cfg(not(feature = "profile"))] |
| 45 | +#[inline(always)] |
| 46 | +fn start_profile(_stage: &str) {} |
| 47 | + |
| 48 | +#[cfg(feature = "profile")] |
| 49 | +#[inline(always)] |
| 50 | +fn stop_profile() { |
| 51 | + PROFILER.lock().unwrap().stop().unwrap(); |
| 52 | +} |
| 53 | + |
| 54 | +#[cfg(not(feature = "profile"))] |
| 55 | +#[inline(always)] |
| 56 | +fn stop_profile() {} |
| 57 | + |
| 58 | +fn do_the_work( |
| 59 | + size: usize, |
| 60 | + vdf: usize, |
| 61 | + challenge_count: usize, |
| 62 | + post_epochs: usize, |
| 63 | + post_periods_count: usize, |
| 64 | + sectors_count: usize, |
| 65 | +) { |
| 66 | + let rng = &mut XorShiftRng::from_seed([0x3dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); |
| 67 | + |
| 68 | + info!(FCP_LOG, "sector size: {}", prettyb(size); "target" => "config"); |
| 69 | + info!(FCP_LOG, "vdf: {}", vdf; "target" => "config"); |
| 70 | + info!(FCP_LOG, "challenge_count: {}", challenge_count; "target" => "config"); |
| 71 | + info!(FCP_LOG, "post_epochs: {}", post_epochs; "target" => "config"); |
| 72 | + info!(FCP_LOG, "post_periods_count: {:?}", post_periods_count; "target" => "config"); |
| 73 | + info!(FCP_LOG, "sectors_count: {:?}", sectors_count; "target" => "config"); |
| 74 | + |
| 75 | + info!(FCP_LOG, "generating fake data"; "target" => "status"); |
| 76 | + |
| 77 | + let nodes_size = size / 32; |
| 78 | + |
| 79 | + let data: Vec<Vec<u8>> = (0..sectors_count) |
| 80 | + .map(|_| { |
| 81 | + (0..nodes_size) |
| 82 | + .flat_map(|_| fr_into_bytes::<Bls12>(&rng.gen())) |
| 83 | + .collect() |
| 84 | + }) |
| 85 | + .collect(); |
| 86 | + |
| 87 | + let graphs: Vec<_> = (0..sectors_count) |
| 88 | + .map(|_| BucketGraph::<PedersenHasher>::new(nodes_size, 5, 0, new_seed())) |
| 89 | + .collect(); |
| 90 | + |
| 91 | + let trees: Vec<_> = graphs |
| 92 | + .iter() |
| 93 | + .zip(data.iter()) |
| 94 | + .map(|(graph, data)| graph.merkle_tree(data.as_slice()).unwrap()) |
| 95 | + .collect(); |
| 96 | + |
| 97 | + let sp = SetupParams::<PedersenDomain, vdf_sloth::Sloth> { |
| 98 | + vdf_post_setup_params: vdf_post::SetupParams::<PedersenDomain, vdf_sloth::Sloth> { |
| 99 | + challenge_count, |
| 100 | + sector_size: size, |
| 101 | + post_epochs, |
| 102 | + setup_params_vdf: vdf_sloth::SetupParams { |
| 103 | + key: rng.gen(), |
| 104 | + rounds: vdf, |
| 105 | + }, |
| 106 | + sectors_count, |
| 107 | + }, |
| 108 | + post_periods_count, |
| 109 | + }; |
| 110 | + |
| 111 | + info!(FCP_LOG, "running setup"); |
| 112 | + start_profile("setup"); |
| 113 | + let pub_params = BeaconPoSt::<PedersenHasher, vdf_sloth::Sloth>::setup(&sp).unwrap(); |
| 114 | + stop_profile(); |
| 115 | + |
| 116 | + let pub_inputs = PublicInputs { |
| 117 | + commitments: trees.iter().map(|t| t.root()).collect(), |
| 118 | + }; |
| 119 | + |
| 120 | + let trees_ref: Vec<_> = trees.iter().collect(); |
| 121 | + let replicas: Vec<&[u8]> = data.iter().map(|d| &d[..]).collect(); |
| 122 | + |
| 123 | + let priv_inputs = PrivateInputs::<PedersenHasher>::new(&replicas, &trees_ref[..]); |
| 124 | + |
| 125 | + let mut total_proving = Duration::new(0, 0); |
| 126 | + info!(FCP_LOG, "generating proofs"); |
| 127 | + |
| 128 | + let start = Instant::now(); |
| 129 | + start_profile("prove"); |
| 130 | + let proof = BeaconPoSt::prove(&pub_params, &pub_inputs, &priv_inputs).unwrap(); |
| 131 | + stop_profile(); |
| 132 | + |
| 133 | + total_proving += start.elapsed(); |
| 134 | + |
| 135 | + let proving_avg = total_proving; |
| 136 | + let proving_avg = |
| 137 | + f64::from(proving_avg.subsec_nanos()) / 1_000_000_000f64 + (proving_avg.as_secs() as f64); |
| 138 | + |
| 139 | + info!(FCP_LOG, "proving_time: {:?} seconds", proving_avg; "target" => "stats"); |
| 140 | + |
| 141 | + let samples: u32 = 5; |
| 142 | + info!(FCP_LOG, "sampling verifying (samples: {})", samples); |
| 143 | + let mut total_verifying = Duration::new(0, 0); |
| 144 | + |
| 145 | + start_profile("verify"); |
| 146 | + for _ in 0..samples { |
| 147 | + let start = Instant::now(); |
| 148 | + let verified = BeaconPoSt::verify(&pub_params, &pub_inputs, &proof).unwrap(); |
| 149 | + |
| 150 | + if !verified { |
| 151 | + info!(FCP_LOG, "Verification failed."; "target" => "results"); |
| 152 | + }; |
| 153 | + total_verifying += start.elapsed(); |
| 154 | + } |
| 155 | + info!(FCP_LOG, "Verification complete"; "target" => "status"); |
| 156 | + stop_profile(); |
| 157 | + |
| 158 | + let verifying_avg = total_verifying / samples; |
| 159 | + let verifying_avg = f64::from(verifying_avg.subsec_nanos()) / 1_000_000_000f64 |
| 160 | + + (verifying_avg.as_secs() as f64); |
| 161 | + info!(FCP_LOG, "average_verifying_time: {:?} seconds", verifying_avg; "target" => "stats"); |
| 162 | +} |
| 163 | + |
| 164 | +fn main() { |
| 165 | + let matches = App::new(stringify!("DrgPoRep Vanilla Bench")) |
| 166 | + .version("1.0") |
| 167 | + .arg( |
| 168 | + Arg::with_name("size") |
| 169 | + .required(true) |
| 170 | + .long("size") |
| 171 | + .help("The data size of a sector in KB") |
| 172 | + .takes_value(true), |
| 173 | + ) |
| 174 | + .arg( |
| 175 | + Arg::with_name("vdf") |
| 176 | + .help("The number of sloth iterations") |
| 177 | + .long("vdf") |
| 178 | + .default_value("10") |
| 179 | + .takes_value(true), |
| 180 | + ) |
| 181 | + .arg( |
| 182 | + Arg::with_name("challenges") |
| 183 | + .long("challenges") |
| 184 | + .help("How many challenges to execute") |
| 185 | + .default_value("1") |
| 186 | + .takes_value(true), |
| 187 | + ) |
| 188 | + .arg( |
| 189 | + Arg::with_name("post-epochs") |
| 190 | + .long("post-epochs") |
| 191 | + .help("How many epochs should the PoSt run for") |
| 192 | + .default_value("10") |
| 193 | + .takes_value(true), |
| 194 | + ) |
| 195 | + .arg( |
| 196 | + Arg::with_name("post-periods-count") |
| 197 | + .long("post-periods-count") |
| 198 | + .help("How many PoSt periods should there be") |
| 199 | + .default_value("10") |
| 200 | + .takes_value(true), |
| 201 | + ) |
| 202 | + .arg( |
| 203 | + Arg::with_name("sectors") |
| 204 | + .long("sectors") |
| 205 | + .help("How many sector are being proven") |
| 206 | + .default_value("5") |
| 207 | + .takes_value(true), |
| 208 | + ) |
| 209 | + .get_matches(); |
| 210 | + |
| 211 | + let size = value_t!(matches, "size", usize).unwrap() * 1024; |
| 212 | + let vdf = value_t!(matches, "vdf", usize).unwrap(); |
| 213 | + let challenge_count = value_t!(matches, "challenges", usize).unwrap(); |
| 214 | + let post_epochs = value_t!(matches, "post-epochs", usize).unwrap(); |
| 215 | + let post_periods_count = value_t!(matches, "post-periods-count", usize).unwrap(); |
| 216 | + let sectors_count = value_t!(matches, "sectors", usize).unwrap(); |
| 217 | + |
| 218 | + do_the_work( |
| 219 | + size, |
| 220 | + vdf, |
| 221 | + challenge_count, |
| 222 | + post_epochs, |
| 223 | + post_periods_count, |
| 224 | + sectors_count, |
| 225 | + ); |
| 226 | +} |
0 commit comments