-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1534 from o1-labs/fix/lookup-gate-range-check
Bump bindings and Mina repo for lookup gate fix
- Loading branch information
Showing
8 changed files
with
165 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
Submodule bindings
updated
12 files
This file contains 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
This file contains 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,20 @@ | ||
import { Field } from '../field.js'; | ||
import { Gates } from '../gates.js'; | ||
|
||
export { rangeCheck3x12 }; | ||
|
||
function rangeCheck3x12(v0: Field, v1: Field, v2: Field) { | ||
// Checks that all three input values exist in the RANGE_CHECK_TABLE (tableId: 1) | ||
// v0, v1, v2 are used as the table keys | ||
// The table "values" (inputs no 3, 5, 7) are 0 because the table only has one column | ||
Gates.lookup( | ||
// table id | ||
Field.from(1), | ||
v0, | ||
Field.from(0), | ||
v1, | ||
Field.from(0), | ||
v2, | ||
Field.from(0) | ||
); | ||
} |
This file contains 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
This file contains 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,61 @@ | ||
import { mod } from '../../../bindings/crypto/finite-field.js'; | ||
import { Field } from '../field.js'; | ||
import { ZkProgram } from '../../proof-system/zkprogram.js'; | ||
import { | ||
Spec, | ||
boolean, | ||
equivalentAsync, | ||
fieldWithRng, | ||
} from '../../testing/equivalent.js'; | ||
import { Random } from '../../testing/property.js'; | ||
import { assert } from '../gadgets/common.js'; | ||
import { Gadgets } from '../gadgets/gadgets.js'; | ||
import { constraintSystem, contains } from '../../testing/constraint-system.js'; | ||
|
||
let uint = (n: number | bigint): Spec<bigint, Field> => { | ||
return fieldWithRng(Random.bignat((1n << BigInt(n)) - 1n)); | ||
}; | ||
|
||
let maybeUint = (n: number | bigint): Spec<bigint, Field> => { | ||
let uint = Random.bignat((1n << BigInt(n)) - 1n); | ||
return fieldWithRng( | ||
Random.map(Random.oneOf(uint, uint.invalid), (x) => mod(x, Field.ORDER)) | ||
); | ||
}; | ||
|
||
let Lookup = ZkProgram({ | ||
name: 'lookup', | ||
methods: { | ||
three12Bit: { | ||
privateInputs: [Field, Field, Field], | ||
async method(v0: Field, v1: Field, v2: Field) { | ||
// Dummy range check to make sure the lookup table is initialized | ||
// It should never fail because 64 > 12 | ||
Gadgets.rangeCheck64(v0); | ||
Gadgets.rangeCheck3x12(v0, v1, v2); | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
// constraint system sanity check | ||
|
||
constraintSystem.fromZkProgram(Lookup, 'three12Bit', contains(['Lookup'])); | ||
|
||
await Lookup.compile(); | ||
|
||
await equivalentAsync( | ||
{ from: [uint(12), uint(12), maybeUint(12)], to: boolean }, | ||
{ runs: 3 } | ||
)( | ||
(x, y, z) => { | ||
assert(x < 1n << 12n); | ||
assert(y < 1n << 12n); | ||
assert(z < 1n << 12n); | ||
return true; | ||
}, | ||
async (x, y, z) => { | ||
let proof = await Lookup.three12Bit(x, y, z); | ||
return await Lookup.verify(proof); | ||
} | ||
); |
Submodule mina
updated
4 files
+1 −1 | src/lib/crypto/proof-systems | |
+1 −1 | src/lib/pickles/test/optional_custom_gates/dune | |
+105 −0 | src/lib/pickles/test/optional_custom_gates/lookup_range_check.ml | |
+1 −1 | src/lib/snarky |
Oops, something went wrong.