-
Notifications
You must be signed in to change notification settings - Fork 118
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 #1182 from o1-labs/feat/ROT-gadget
Add rot gadget to o1js
- Loading branch information
Showing
12 changed files
with
329 additions
and
41 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
from dbe878 to 5e5bef
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
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
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,37 @@ | ||
import { Provable } from '../provable.js'; | ||
import { Field } from '../field.js'; | ||
|
||
const MAX_BITS = 64 as const; | ||
|
||
export { | ||
MAX_BITS, | ||
assert, | ||
witnessSlices, | ||
witnessNextValue, | ||
divideWithRemainder, | ||
}; | ||
|
||
function assert(stmt: boolean, message?: string) { | ||
if (!stmt) { | ||
throw Error(message ?? 'Assertion failed'); | ||
} | ||
} | ||
|
||
function witnessSlices(f: Field, start: number, length: number) { | ||
if (length <= 0) throw Error('Length must be a positive number'); | ||
|
||
return Provable.witness(Field, () => { | ||
let n = f.toBigInt(); | ||
return new Field((n >> BigInt(start)) & ((1n << BigInt(length)) - 1n)); | ||
}); | ||
} | ||
|
||
function witnessNextValue(current: Field) { | ||
return Provable.witness(Field, () => new Field(current.toBigInt() >> 16n)); | ||
} | ||
|
||
function divideWithRemainder(numerator: bigint, denominator: bigint) { | ||
const quotient = numerator / denominator; | ||
const remainder = numerator - denominator * quotient; | ||
return { quotient, remainder }; | ||
} |
Oops, something went wrong.