Skip to content
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

Activate custom gates in JS and add rangeCheck64 gadget #179

Merged
merged 10 commits into from
Oct 16, 2023

Conversation

mitschabaude
Copy link
Collaborator

@mitschabaude mitschabaude commented Oct 11, 2023

companion of o1-labs/o1js#1176, see PR description there

@mitschabaude mitschabaude requested a review from a team as a code owner October 11, 2023 10:07
@mitschabaude mitschabaude changed the title Active custom gates in JS and add rangeCheck64 gadget Activate custom gates in JS and add rangeCheck64 gadget Oct 11, 2023
Base automatically changed from merge-main-develop to develop October 11, 2023 12:32
@mitschabaude mitschabaude changed the base branch from develop to merge-develop-back October 11, 2023 15:54
@@ -20,6 +20,41 @@ use std::path::Path;
use std::sync::Arc;
use wasm_bindgen::prelude::*;

pub struct SimpleFeatureFlags {
pub range_check0: bool,
pub range_check1: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a clarifying question for me: what does range_check1 correspond to? range_check0 is the 64 bit range check; what is the other one?

Copy link
Collaborator Author

@mitschabaude mitschabaude Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's how I understand it (@jspada would know the full details):

range_check0 actually has space for up to 88 bits (for the 64-bit check we set the upper two 12-bit limbs to constant zero). However, when used in the 88-bit mode it doesn't fully constrain all limbs by itself and needs to "collaborate" with subsequent gates.

The main objective for both range check gates was to enable a 3x88-bit check (used in foreign field arithmetic, supports bigint sizes up to 264 = 3 * 88 bits). The range_check1 gate is what is needed together with two range_check0 gates and one Zero gate to collaboratively do this 3*88 bit check.

Note that that's 264 bits of range check in 4 gates, which is 264 / 4 = 66 bits per gate on average. So the collaborative approach gives you a 2 bit edge over the single gate version here 😅 Just doing 4 64-bit range checks separately would have only given us 256 bit checks which would've been to small for important use cases in foreign field multiplication.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ocaml/lib/snarky_bindings.mli Show resolved Hide resolved
ocaml/lib/pickles_bindings.mli Show resolved Hide resolved
kimchi/wasm/src/plonk_verifier_index.rs Outdated Show resolved Hide resolved
Base automatically changed from merge-develop-back to main October 16, 2023 15:50
@mitschabaude mitschabaude merged commit 827e6a6 into main Oct 16, 2023
1 check passed
@mitschabaude mitschabaude deleted the feature/range-check-64-develop branch October 16, 2023 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants