Skip to content

Commit

Permalink
feat: phase2-cli verify raw g1 points (#1256)
Browse files Browse the repository at this point in the history
* feat: phase2-cli verify raw g1 points

* Use phase2 v0.8.0.

Co-authored-by: DrPeterVanNostrand <jnz@riseup.net>
Co-authored-by: porcuquine <porcuquine@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 12, 2020
1 parent 6e38487 commit f36696b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
2 changes: 1 addition & 1 deletion filecoin-proofs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ sha2 = "0.9.1"
typenum = "1.11.2"
bitintr = "0.3.0"
gperftools = { version = "0.2", optional = true }
phase2 = { version = "0.7.0", package = "phase21" }
phase2 = { version = "0.8.0", package = "phase21" }
simplelog = "0.8.0"
rand_chacha = "0.2.1"
dialoguer = "0.6.2"
Expand Down
60 changes: 56 additions & 4 deletions filecoin-proofs/src/bin/phase2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,12 @@ fn convert_small(path_before: &str) {
);
}

fn verify_contribution(path_before: &str, path_after: &str, participant_contrib: [u8; 64]) {
fn verify_contribution(
path_before: &str,
path_after: &str,
participant_contrib: [u8; 64],
raw_subgroup_checks: bool,
) {
#[allow(clippy::large_enum_variant)]
enum Message {
Done(MPCSmall),
Expand Down Expand Up @@ -722,6 +727,10 @@ fn verify_contribution(path_before: &str, path_after: &str, participant_contrib:
warn!("using non-raw 'before' params");
}

if is_raw && !raw_subgroup_checks {
warn!("skipping subgroup checks when deserializing small-raw 'before' params");
}

let read_res: io::Result<MPCSmall> = if is_large {
info!(
"reading large 'before' params as `MPCSmall`: {}",
Expand All @@ -735,7 +744,7 @@ fn verify_contribution(path_before: &str, path_after: &str, participant_contrib:
);
File::open(&path_before).and_then(|file| {
let mut reader = BufReader::with_capacity(1024 * 1024, file);
MPCSmall::read(&mut reader, is_raw)
MPCSmall::read(&mut reader, is_raw, raw_subgroup_checks)
})
};

Expand All @@ -761,14 +770,18 @@ fn verify_contribution(path_before: &str, path_after: &str, participant_contrib:
warn!("using non-raw 'after' params");
}

if is_raw && !raw_subgroup_checks {
warn!("skipping subgroup checks when deserializing small-raw 'after' params")
}

let read_res: io::Result<MPCSmall> = if is_large {
info!("reading large 'after' params as `MPCSmall`: {}", path_after);
read_small_params_from_large_file(&path_after)
} else {
info!("reading small 'after' params as `MPCSmall`: {}", path_after);
File::open(&path_after).and_then(|file| {
let mut reader = BufReader::with_capacity(1024 * 1024, file);
MPCSmall::read(&mut reader, is_raw)
MPCSmall::read(&mut reader, is_raw, raw_subgroup_checks)
})
};

Expand Down Expand Up @@ -1201,6 +1214,12 @@ fn main() {
Arg::with_name("path-after")
.required(true)
.help("The path to the params file containing the contribution to be verified"),
)
.arg(
Arg::with_name("skip-raw-subgroup-checks")
.long("skip-raw-subgroup-checks")
.short("s")
.help("Skip the slow subgroup check when deserializing each raw G1 point"),
);

let small_command = SubCommand::with_name("small")
Expand Down Expand Up @@ -1248,6 +1267,14 @@ fn main() {
.help("Path to params file."),
);

let verify_g1_command = SubCommand::with_name("verify-g1")
.about("Verifies that all points in small-raw params are valid G1")
.arg(
Arg::with_name("path")
.required(true)
.help("Path to small-raw params file."),
);

let matches = App::new("phase2")
.version("1.0")
.setting(AppSettings::ArgRequiredElseHelp)
Expand All @@ -1260,6 +1287,7 @@ fn main() {
.subcommand(merge_command)
.subcommand(split_keys_command)
.subcommand(parse_command)
.subcommand(verify_g1_command)
.get_matches();

if let (subcommand, Some(matches)) = matches.subcommand() {
Expand Down Expand Up @@ -1359,6 +1387,7 @@ fn main() {
}
"verify" => {
let path_after = matches.value_of("path-after").unwrap();
let raw_subgroup_checks = !matches.is_present("skip-raw-subgroup-checks");

assert!(
Path::new(&path_after).exists(),
Expand Down Expand Up @@ -1458,7 +1487,7 @@ fn main() {
bytes
};

verify_contribution(&path_before, &path_after, contrib);
verify_contribution(&path_before, &path_after, contrib, raw_subgroup_checks);
}
"small" => {
let large_path = matches.value_of("large-path").unwrap();
Expand Down Expand Up @@ -1803,6 +1832,29 @@ fn main() {

println!("{:#?}", file_info);
}
"verify-g1" => {
let path = matches.value_of("path").unwrap();
let (_, _, _, _, _, _, raw) = parse_params_filename(&path);

assert!(
raw,
"found non-raw params, `verify-g1` is relevant only when verifying small-raw \
params"
);

let file = File::open(&path).expect("failed to open params file");
let mut reader = BufReader::with_capacity(1024 * 1024, file);

println!("starting deserialization");

let start = Instant::now();
let _params = MPCSmall::read(&mut reader, raw, true).unwrap();

println!(
"succesfully verified h and l G1 points, dt={}s",
start.elapsed().as_secs()
);
}
_ => unreachable!(),
}
}
Expand Down

0 comments on commit f36696b

Please sign in to comment.