-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP continuing fiat-shamir (step 20) * Upto step 20 implemented * Upto step 22 * Upto step 28 * Added tests * Fix build errors * Small fix
- Loading branch information
Showing
14 changed files
with
845 additions
and
381 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ArgumentType } from "./circuits/gate" | ||
import { Scalar } from "o1js" | ||
|
||
/** | ||
* This type can be used to create a mapping between powers of alpha and constraint types. | ||
* See `default()` to create one (not implemented yet), | ||
* and `register()` to register a new mapping (not implemented yet). | ||
* Once you know the alpha value, you can convert this type to a `Alphas`. | ||
*/ | ||
export class Alphas { | ||
/** | ||
* The next power of alpha to use. | ||
* The end result will be [1, alpha^(next_power - 1)] | ||
*/ | ||
next_power: number | ||
/** The mapping between constraint types and powers of alpha */ | ||
mapping: Map<ArgumentType, [number, number]> | ||
/** | ||
* The powers of alpha: 1, alpha, alpha^2, .. | ||
* If not undefined, you can't register new contraints. | ||
*/ | ||
alphas?: Scalar[] | ||
|
||
/** | ||
* Instantiates the ranges with an actual field element `alpha`. | ||
* Once you call this function, you cannot register new constraints. | ||
*/ | ||
instantiate(alpha: Scalar) { | ||
let last_power = Scalar.from(1); | ||
let alphas = Array<Scalar>(this.next_power); | ||
alphas.push(last_power); | ||
|
||
for (let _ = 1; _ < this.next_power; _++) { | ||
last_power = last_power.mul(alpha); | ||
alphas.push(last_power); | ||
} | ||
this.alphas = alphas; | ||
} | ||
} |
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,62 @@ | ||
export enum GateType { | ||
/** Zero gate */ | ||
Zero, | ||
/** Generic arithmetic gate */ | ||
Generic, | ||
/** Poseidon permutation gate */ | ||
Poseidon, | ||
/** Complete EC addition in Affine form */ | ||
CompleteAdd, | ||
/** EC variable base scalar multiplication */ | ||
VarBaseMul, | ||
/** EC variable base scalar multiplication with group endomorphim optimization */ | ||
EndoMul, | ||
/** Gate for computing the scalar corresponding to an endoscaling */ | ||
EndoMulScalar, | ||
/** Lookup */ | ||
Lookup, | ||
// Cairo | ||
CairoClaim, | ||
CairoInstruction, | ||
CairoFlags, | ||
CairoTransition, | ||
// Range check | ||
RangeCheck0, | ||
RangeCheck1, | ||
ForeignFieldAdd, | ||
ForeignFieldMul, | ||
// Gates for Keccak | ||
Xor16, | ||
Rot64, | ||
} | ||
|
||
/** | ||
* A constraint type represents a polynomial that will be part of the final | ||
* equation f (the circuit equation) | ||
*/ | ||
export namespace ArgumentType { | ||
/** | ||
* Gates in the PLONK constraint system. | ||
* As gates are mutually exclusive (a single gate is set per row), | ||
* we can reuse the same powers of alpha across gates. | ||
*/ | ||
export type Gate = { | ||
kind: "gate", | ||
type: GateType | ||
} | ||
|
||
/** The permutation argument */ | ||
export type Permutation = { | ||
kind: "permutation", | ||
} | ||
|
||
/** The lookup argument */ | ||
export type Lookup = { | ||
kind: "lookup", | ||
} | ||
} | ||
|
||
export type ArgumentType = | ||
| ArgumentType.Gate | ||
| ArgumentType.Permutation | ||
| ArgumentType.Lookup |
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,23 @@ | ||
import { Scalar } from "o1js" | ||
import { bPoly, bPolyCoefficients } from "./commitment"; | ||
|
||
test("bPoly", () => { | ||
const coeffs = [42, 25, 420].map(Scalar.from); | ||
const x = Scalar.from(10); | ||
|
||
const res = bPoly(coeffs, x); | ||
const expected = Scalar.from(15809371031233); | ||
// expected value taken from verify_circuit_tests/ | ||
|
||
expect(res).toEqual(expected); | ||
}) | ||
|
||
test("bPolyCoefficients", () => { | ||
const coeffs = [42, 25].map(Scalar.from); | ||
|
||
const res = bPolyCoefficients(coeffs); | ||
const expected = [1, 19, 42]; | ||
// expected values taken from verify_circuit_tests/ | ||
|
||
expect(res).toEqual(expected); | ||
}) |
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
Oops, something went wrong.