-
Notifications
You must be signed in to change notification settings - Fork 39
Complete integration of Mavros (including lookups) #443
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [package] | ||
| name = "sha256_35" | ||
| type = "bin" | ||
| authors = [""] | ||
| compiler_version = ">=1.0.0" | ||
|
|
||
| [dependencies] | ||
| sha256 = { tag = "v0.3.0", git = "https://github.com/noir-lang/sha256" } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| input = [104, 101, 108, 108, 111] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| use std::hash::sha256_compression; | ||
|
|
||
| global H: [u32; 8] = [ | ||
| 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, | ||
| 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, | ||
| ]; | ||
|
|
||
| fn main(input: [u8; 5]) { | ||
| let mut block: [u32; 16] = [0; 16]; | ||
| block[0] = (input[0] as u32) * 16777216 | ||
| + (input[1] as u32) * 65536 | ||
| + (input[2] as u32) * 256 | ||
| + (input[3] as u32); | ||
| block[1] = (input[4] as u32) * 16777216 + 0x800000; | ||
| block[15] = 40; | ||
|
|
||
| let mut state = H; | ||
| for _ in 0..35 { | ||
| state = sha256_compression(block, state); | ||
| } | ||
|
|
||
| assert(state[0] == 0x2b431f1f); | ||
| assert(state[1] == 0x9f7ccc65); | ||
| assert(state[2] == 0xb39b5188); | ||
| assert(state[3] == 0x8b7e8689); | ||
| assert(state[4] == 0x8ad1bc84); | ||
| assert(state[5] == 0x09f78be6); | ||
| assert(state[6] == 0xf0431b8d); | ||
| assert(state[7] == 0x97fcfb9c); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,14 +5,14 @@ use { | |
| r1cs::{CompressedLayers, CompressedR1CS}, | ||
| whir_r1cs::WhirR1CSProver, | ||
| }, | ||
| ::tracing::{debug, info, info_span, instrument}, | ||
| acir::native_types::{Witness, WitnessMap}, | ||
| anyhow::{Context, Result}, | ||
| provekit_common::{ | ||
| utils::noir_to_native, FieldElement, NoirElement, NoirProof, NoirProver, Prover, | ||
| PublicInputs, TranscriptSponge, | ||
| }, | ||
| std::mem::size_of, | ||
| tracing::{debug, info_span, instrument}, | ||
| std::mem::{size_of, take}, | ||
| whir::transcript::ProverState, | ||
| }; | ||
| #[cfg(all(feature = "witness-generation", not(target_arch = "wasm32")))] | ||
|
|
@@ -31,6 +31,7 @@ pub(crate) mod ec_arith; | |
| #[cfg(not(target_arch = "wasm32"))] | ||
| pub mod input_utils; | ||
| pub(crate) mod r1cs; | ||
| mod tracing; | ||
|
Collaborator
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.
|
||
| mod whir_r1cs; | ||
| mod witness; | ||
|
|
||
|
|
@@ -184,6 +185,7 @@ impl Prove for NoirProver { | |
| .collect::<Result<Vec<_>>>()? | ||
| }; | ||
|
|
||
| crate::tracing::log_commit_input("noir_w1", &w1, 1usize << self.whir_for_witness.m); | ||
| let commitment_1 = self | ||
| .whir_for_witness | ||
| .commit(&mut merlin, num_witnesses, num_constraints, w1, true) | ||
|
|
@@ -221,6 +223,7 @@ impl Prove for NoirProver { | |
| .collect::<Result<Vec<_>>>()? | ||
| }; | ||
|
|
||
| crate::tracing::log_commit_input("noir_w2", &w2, 1usize << self.whir_for_witness.m); | ||
| let commitment_2 = self | ||
| .whir_for_witness | ||
| .commit(&mut merlin, num_witnesses, num_constraints, w2, false) | ||
|
|
@@ -280,6 +283,7 @@ impl Prove for MavrosProver { | |
| self.constraints_layout, | ||
| ¶ms, | ||
| ); | ||
| drop(self.witgen_binary); | ||
|
|
||
| let num_public_inputs = self.num_public_inputs; | ||
| let public_inputs = if num_public_inputs == 0 { | ||
|
|
@@ -296,56 +300,84 @@ impl Prove for MavrosProver { | |
| .instance(&instance); | ||
| let mut merlin = ProverState::new(&ds, TranscriptSponge::from_config(self.hash_config)); | ||
|
|
||
| info!( | ||
|
Collaborator
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. this 11-field info! can collapse to |
||
| algebraic_size = self.witness_layout.algebraic_size, | ||
| multiplicities_size = self.witness_layout.multiplicities_size, | ||
| challenges_size = self.witness_layout.challenges_size, | ||
| tables_data_size = self.witness_layout.tables_data_size, | ||
| lookups_data_size = self.witness_layout.lookups_data_size, | ||
| pre_commitment_size = self.witness_layout.pre_commitment_size(), | ||
| post_commitment_size = self.witness_layout.post_commitment_size(), | ||
| total_witness_size = self.witness_layout.size(), | ||
| constraints_algebraic_size = self.constraints_layout.algebraic_size, | ||
| constraints_total_size = self.constraints_layout.size(), | ||
| scheme_domain_len = 1usize << self.whir_for_witness.m, | ||
|
Collaborator
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. nit: |
||
| "Mavros witness layout" | ||
| ); | ||
|
|
||
| let w1 = phase1.out_wit_pre_comm.clone(); | ||
| crate::tracing::log_commit_input( | ||
| "mavros_w1_pre_commitment", | ||
| &w1, | ||
| 1usize << self.whir_for_witness.m, | ||
| ); | ||
| let commitment_1 = self | ||
| .whir_for_witness | ||
| .commit( | ||
| &mut merlin, | ||
| self.witness_layout.size(), | ||
| self.constraints_layout.algebraic_size, | ||
| phase1.out_wit_pre_comm.clone(), | ||
| w1, | ||
| true, | ||
| ) | ||
| .context("While committing to w1")?; | ||
|
|
||
| let commitments = if self.whir_for_witness.num_challenges > 0 { | ||
| let (commitments, witgen_result) = if self.whir_for_witness.num_challenges > 0 { | ||
| let challenges: Vec<FieldElement> = (0..self.witness_layout.challenges_size) | ||
| .map(|_| merlin.verifier_message()) | ||
| .collect(); | ||
|
|
||
| let witgen_result = mavros_interpreter::run_phase2( | ||
| phase1.clone(), | ||
| phase1, | ||
| &challenges, | ||
| self.witness_layout, | ||
| self.constraints_layout, | ||
| ); | ||
|
|
||
| let mut witgen_result = witgen_result; | ||
| let w2 = take(&mut witgen_result.out_wit_post_comm); | ||
| crate::tracing::log_commit_input( | ||
| "mavros_w2_post_commitment", | ||
| &w2, | ||
| 1usize << self.whir_for_witness.m, | ||
| ); | ||
| let commitment_2 = self | ||
| .whir_for_witness | ||
| .commit( | ||
| &mut merlin, | ||
| self.witness_layout.size(), | ||
| self.constraints_layout.algebraic_size, | ||
| witgen_result.out_wit_post_comm.clone(), | ||
| w2, | ||
| false, | ||
| ) | ||
| .context("While committing to w2")?; | ||
|
|
||
| vec![commitment_1, commitment_2] | ||
| (vec![commitment_1, commitment_2], witgen_result) | ||
| } else { | ||
| mavros_interpreter::run_phase2( | ||
| phase1.clone(), | ||
| let witgen_result = mavros_interpreter::run_phase2( | ||
| phase1, | ||
| &[], | ||
| self.witness_layout, | ||
| self.constraints_layout, | ||
| ); | ||
| vec![commitment_1] | ||
| (vec![commitment_1], witgen_result) | ||
| }; | ||
|
|
||
| let whir_r1cs_proof = self | ||
| .whir_for_witness | ||
| .prove_mavros( | ||
| merlin, | ||
| phase1, | ||
| witgen_result, | ||
| commitments, | ||
| &public_inputs, | ||
| self.witness_layout, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| use { | ||
| ::tracing::{debug, enabled, Level}, | ||
| ark_std::Zero, | ||
| provekit_common::FieldElement, | ||
| }; | ||
|
|
||
| pub(crate) fn log_commit_input(label: &str, values: &[FieldElement], scheme_domain_len: usize) { | ||
| if !enabled!(Level::DEBUG) { | ||
| return; | ||
| } | ||
|
|
||
| let input_len = values.len(); | ||
| let input_padded_len = input_len.max(1).next_power_of_two(); | ||
| let nonzero_entries = values.iter().filter(|v| !v.is_zero()).count(); | ||
| debug!( | ||
| label, | ||
| input_len, input_padded_len, scheme_domain_len, nonzero_entries, "WHIR commit input" | ||
| ); | ||
| } |
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.
The new
size()/pre_commitment_size()/post_commitment_size()methods are pub but have no///docs. Workspace lintscargo doc -D warnings, so one-liners each.