-
Notifications
You must be signed in to change notification settings - Fork 135
(native prover) verifier index #3360
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| mod circuit; | ||
| pub mod plonk_verifier_index; | ||
| mod poseidon; | ||
| mod types; | ||
|
|
||
|
|
||
This file contains hidden or 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,121 @@ | ||
| use ark_poly::{EvaluationDomain, Radix2EvaluationDomain as Domain}; | ||
| use ark_serialize::CanonicalSerialize; | ||
| use kimchi::circuits::polynomials::permutation::Shifts as KimchiShifts; | ||
| use mina_curves::pasta::Fp; | ||
| use napi::bindgen_prelude::{Error, Result as NapiResult, Status}; | ||
| use napi_derive::napi; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| use super::WasmLookupInfo; | ||
|
|
||
| #[napi(object)] | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct WasmFpDomain { | ||
| pub log_size_of_group: i32, | ||
| pub group_gen: Vec<u8>, | ||
| } | ||
|
|
||
| #[napi(object)] | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct WasmFpPolyComm { | ||
| pub unshifted: Vec<Vec<u8>>, | ||
| pub shifted: Option<Vec<u8>>, | ||
| } | ||
|
|
||
| #[napi(object)] | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct WasmFpShifts { | ||
| pub s0: Vec<u8>, | ||
| pub s1: Vec<u8>, | ||
| pub s2: Vec<u8>, | ||
| pub s3: Vec<u8>, | ||
| pub s4: Vec<u8>, | ||
| pub s5: Vec<u8>, | ||
| pub s6: Vec<u8>, | ||
| } | ||
|
|
||
| #[napi(object)] | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct WasmFpLookupSelectors { | ||
| pub xor: Option<WasmFpPolyComm>, | ||
| pub lookup: Option<WasmFpPolyComm>, | ||
| pub range_check: Option<WasmFpPolyComm>, | ||
| pub ffmul: Option<WasmFpPolyComm>, | ||
| } | ||
|
|
||
| #[napi(object)] | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct WasmFpLookupVerifierIndex { | ||
| pub joint_lookup_used: bool, | ||
| pub lookup_table: Vec<WasmFpPolyComm>, | ||
| pub lookup_selectors: WasmFpLookupSelectors, | ||
| pub table_ids: Option<WasmFpPolyComm>, | ||
| pub lookup_info: WasmLookupInfo, | ||
| pub runtime_tables_selector: Option<WasmFpPolyComm>, | ||
| } | ||
|
|
||
| #[napi(object)] | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct WasmFpPlonkVerificationEvals { | ||
| pub sigma_comm: Vec<WasmFpPolyComm>, | ||
| pub coefficients_comm: Vec<WasmFpPolyComm>, | ||
| pub generic_comm: WasmFpPolyComm, | ||
| pub psm_comm: WasmFpPolyComm, | ||
| pub complete_add_comm: WasmFpPolyComm, | ||
| pub mul_comm: WasmFpPolyComm, | ||
| pub emul_comm: WasmFpPolyComm, | ||
| pub endomul_scalar_comm: WasmFpPolyComm, | ||
| pub xor_comm: Option<WasmFpPolyComm>, | ||
| pub range_check0_comm: Option<WasmFpPolyComm>, | ||
| pub range_check1_comm: Option<WasmFpPolyComm>, | ||
| pub foreign_field_add_comm: Option<WasmFpPolyComm>, | ||
| pub foreign_field_mul_comm: Option<WasmFpPolyComm>, | ||
| pub rot_comm: Option<WasmFpPolyComm>, | ||
| } | ||
|
|
||
| #[napi(object)] | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct WasmFpPlonkVerifierIndex { | ||
| pub domain: WasmFpDomain, | ||
| pub max_poly_size: i32, | ||
| pub public_: i32, | ||
| pub prev_challenges: i32, | ||
| pub srs: Vec<u8>, | ||
| pub evals: WasmFpPlonkVerificationEvals, | ||
| pub shifts: WasmFpShifts, | ||
| pub lookup_index: Option<WasmFpLookupVerifierIndex>, | ||
| pub zk_rows: i32, | ||
| } | ||
|
|
||
| #[napi] | ||
| pub fn caml_pasta_fp_plonk_verifier_index_shifts(log2_size: i32) -> NapiResult<WasmFpShifts> { | ||
| println!( | ||
| "from napi! caml_pasta_fp_plonk_verifier_index_shifts with log2_size {}", | ||
| log2_size | ||
| ); | ||
|
|
||
| let size = 1usize << (log2_size as u32); | ||
| let domain = Domain::<Fp>::new(size) | ||
| .ok_or_else(|| Error::new(Status::InvalidArg, "failed to create evaluation domain"))?; | ||
|
|
||
| let shifts = KimchiShifts::new(&domain); | ||
| let s = shifts.shifts(); | ||
|
|
||
| Ok(WasmFpShifts { | ||
| s0: serialize_fp(&s[0])?, | ||
| s1: serialize_fp(&s[1])?, | ||
| s2: serialize_fp(&s[2])?, | ||
| s3: serialize_fp(&s[3])?, | ||
| s4: serialize_fp(&s[4])?, | ||
| s5: serialize_fp(&s[5])?, | ||
| s6: serialize_fp(&s[6])?, | ||
| }) | ||
| } | ||
|
|
||
| fn serialize_fp(value: &Fp) -> NapiResult<Vec<u8>> { | ||
| let mut bytes = Vec::new(); | ||
| value | ||
| .serialize_compressed(&mut bytes) | ||
| .map_err(|err| Error::new(Status::GenericFailure, format!("serialize_fp: {err}")))?; | ||
| Ok(bytes) | ||
| } |
This file contains hidden or 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,121 @@ | ||
| use ark_poly::{EvaluationDomain, Radix2EvaluationDomain as Domain}; | ||
| use ark_serialize::CanonicalSerialize; | ||
| use kimchi::circuits::polynomials::permutation::Shifts as KimchiShifts; | ||
| use mina_curves::pasta::Fq; | ||
| use napi::bindgen_prelude::{Error, Result as NapiResult, Status}; | ||
| use napi_derive::napi; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| use super::WasmLookupInfo; | ||
|
|
||
| #[napi(object)] | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct WasmFqDomain { | ||
| pub log_size_of_group: i32, | ||
| pub group_gen: Vec<u8>, | ||
| } | ||
|
|
||
| #[napi(object)] | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct WasmFqPolyComm { | ||
| pub unshifted: Vec<Vec<u8>>, | ||
| pub shifted: Option<Vec<u8>>, | ||
| } | ||
|
|
||
| #[napi(object)] | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct WasmFqShifts { | ||
| pub s0: Vec<u8>, | ||
| pub s1: Vec<u8>, | ||
| pub s2: Vec<u8>, | ||
| pub s3: Vec<u8>, | ||
| pub s4: Vec<u8>, | ||
| pub s5: Vec<u8>, | ||
| pub s6: Vec<u8>, | ||
| } | ||
|
|
||
| #[napi(object)] | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct WasmFqLookupSelectors { | ||
| pub xor: Option<WasmFqPolyComm>, | ||
| pub lookup: Option<WasmFqPolyComm>, | ||
| pub range_check: Option<WasmFqPolyComm>, | ||
| pub ffmul: Option<WasmFqPolyComm>, | ||
| } | ||
|
|
||
| #[napi(object)] | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct WasmFqLookupVerifierIndex { | ||
| pub joint_lookup_used: bool, | ||
| pub lookup_table: Vec<WasmFqPolyComm>, | ||
| pub lookup_selectors: WasmFqLookupSelectors, | ||
| pub table_ids: Option<WasmFqPolyComm>, | ||
| pub lookup_info: WasmLookupInfo, | ||
| pub runtime_tables_selector: Option<WasmFqPolyComm>, | ||
| } | ||
|
|
||
| #[napi(object)] | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct WasmFqPlonkVerificationEvals { | ||
| pub sigma_comm: Vec<WasmFqPolyComm>, | ||
| pub coefficients_comm: Vec<WasmFqPolyComm>, | ||
| pub generic_comm: WasmFqPolyComm, | ||
| pub psm_comm: WasmFqPolyComm, | ||
| pub complete_add_comm: WasmFqPolyComm, | ||
| pub mul_comm: WasmFqPolyComm, | ||
| pub emul_comm: WasmFqPolyComm, | ||
| pub endomul_scalar_comm: WasmFqPolyComm, | ||
| pub xor_comm: Option<WasmFqPolyComm>, | ||
| pub range_check0_comm: Option<WasmFqPolyComm>, | ||
| pub range_check1_comm: Option<WasmFqPolyComm>, | ||
| pub foreign_field_add_comm: Option<WasmFqPolyComm>, | ||
| pub foreign_field_mul_comm: Option<WasmFqPolyComm>, | ||
| pub rot_comm: Option<WasmFqPolyComm>, | ||
| } | ||
|
|
||
| #[napi(object)] | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct WasmFqPlonkVerifierIndex { | ||
| pub domain: WasmFqDomain, | ||
| pub max_poly_size: i32, | ||
| pub public_: i32, | ||
| pub prev_challenges: i32, | ||
| pub srs: Vec<u8>, | ||
| pub evals: WasmFqPlonkVerificationEvals, | ||
| pub shifts: WasmFqShifts, | ||
| pub lookup_index: Option<WasmFqLookupVerifierIndex>, | ||
| pub zk_rows: i32, | ||
| } | ||
|
|
||
| #[napi] | ||
| pub fn caml_pasta_fq_plonk_verifier_index_shifts(log2_size: i32) -> NapiResult<WasmFqShifts> { | ||
| println!( | ||
| "from napi! caml_pasta_fp_plonk_verifier_index_shifts with log2_size {}", | ||
| log2_size | ||
| ); | ||
|
|
||
| let size = 1usize << (log2_size as u32); | ||
| let domain = Domain::<Fq>::new(size) | ||
| .ok_or_else(|| Error::new(Status::InvalidArg, "failed to create evaluation domain"))?; | ||
|
|
||
| let shifts = KimchiShifts::new(&domain); | ||
| let s = shifts.shifts(); | ||
|
|
||
| Ok(WasmFqShifts { | ||
| s0: serialize_fp(&s[0])?, | ||
| s1: serialize_fp(&s[1])?, | ||
| s2: serialize_fp(&s[2])?, | ||
| s3: serialize_fp(&s[3])?, | ||
| s4: serialize_fp(&s[4])?, | ||
| s5: serialize_fp(&s[5])?, | ||
| s6: serialize_fp(&s[6])?, | ||
| }) | ||
| } | ||
|
|
||
| fn serialize_fp(value: &Fq) -> NapiResult<Vec<u8>> { | ||
| let mut bytes = Vec::new(); | ||
| value | ||
| .serialize_uncompressed(&mut bytes) | ||
| .map_err(|err| Error::new(Status::GenericFailure, format!("serialize_fp: {err}")))?; | ||
| Ok(bytes) | ||
| } | ||
This file contains hidden or 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,35 @@ | ||
| use napi_derive::napi; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| #[napi(object)] | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct WasmLookupPatterns { | ||
|
Member
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. these types or a very very similar struct should be in plonk-napi/src/wrappers/lookups.rs |
||
| pub xor: bool, | ||
| pub lookup: bool, | ||
| pub range_check: bool, | ||
| pub foreign_field_mul: bool, | ||
| } | ||
|
|
||
| #[napi(object)] | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct WasmLookupFeatures { | ||
| pub patterns: WasmLookupPatterns, | ||
| pub joint_lookup_used: bool, | ||
| pub uses_runtime_tables: bool, | ||
| } | ||
|
|
||
| #[napi(object)] | ||
| #[derive(Clone, Debug, Serialize, Deserialize, Default)] | ||
| pub struct WasmLookupInfo { | ||
| pub max_per_row: i32, | ||
| pub max_joint_size: i32, | ||
| pub features: WasmLookupFeatures, | ||
| } | ||
|
|
||
| pub mod fp; | ||
| pub mod fq; | ||
|
|
||
| #[allow(unused_imports)] | ||
| pub use fp::*; | ||
| #[allow(unused_imports)] | ||
| pub use fq::*; | ||
Oops, something went wrong.
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.
There was a definition of polynomial commitments in plonk-napi/src/poly_comm.rs but using
instead, I am fine with using a simpler type for vectors given that we are using napi
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.
We should follow a uniform format when we merge the workflows