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

Remove redundant range check in rotation gadget #1201

Merged
merged 9 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/examples/primitive_constraint_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const GroupMock = {
const BitwiseMock = {
rot() {
let a = Provable.witness(Field, () => new Field(12));
Gadgets.rangeCheck64(a); // `rotate()` doesn't do this
Copy link
Member

Choose a reason for hiding this comment

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

Oh good, for checking the input is 64 bits in a stand-alone test

Gadgets.rotate(a, 2, 'left');
Gadgets.rotate(a, 2, 'right');
Gadgets.rotate(a, 4, 'left');
Expand Down
4 changes: 2 additions & 2 deletions src/examples/regression_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@
"digest": "Bitwise Primitive",
"methods": {
"rot": {
"rows": 13,
"digest": "2c0dadbba96fd7ddb9adb7d643425ce3"
"rows": 10,
"digest": "c38703de755b10edf77bf24269089274"
},
"xor": {
"rows": 15,
Expand Down
6 changes: 4 additions & 2 deletions src/lib/gadgets/bitwise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ function rot(
);
// Compute next row
Gates.rangeCheck64(shifted);
// Compute following row
Gates.rangeCheck64(excess);
// note: range-checking `shifted` and `field` is enough.
// * excess < 2^rot follows from the bound check and the rotation equation in the gate
// * rotated < 2^64 follows from rotated = excess + shifted (because shifted has to be a multiple of 2^rot)
// for a proof, see https://github.com/o1-labs/o1js/pull/1201
return [rotated, excess, shifted];
}
2 changes: 1 addition & 1 deletion src/lib/gadgets/bitwise.unit-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ZkProgram } from '../proof_system.js';
import {
Spec,
equivalent,
equivalentProvable as equivalent,
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated fix: Unit tests need equivalentProvable which tests implementations in a circuit

equivalentAsync,
field,
fieldWithRng,
Expand Down