Rename back
jump to
@@ -22,7 +22,7 @@ )
type BenchmarkPlonky2VerifierCircuit struct { Proof types.Proof - PublicInputs []gl.GoldilocksVariable `gnark:",public"` + PublicInputs []gl.Variable `gnark:",public"` verifierChip *verifier.VerifierChip `gnark:"-"` plonky2CircuitName string `gnark:"-"`
@@ -23,7 +23,7 @@ )
type BenchmarkPlonky2VerifierCircuitPlonk struct { Proof types.Proof - PublicInputs []gl.GoldilocksVariable `gnark:",public"` + PublicInputs []gl.Variable `gnark:",public"` verifierChip *verifier.VerifierChip `gnark:"-"` plonky2CircuitName string `gnark:"-"`
@@ -14,15 +14,15 @@ type Chip struct {
api frontend.API `gnark:"-"` poseidonChip *poseidon.GoldilocksChip poseidonBN254Chip *poseidon.BN254Chip - spongeState [poseidon.SPONGE_WIDTH]gl.GoldilocksVariable - inputBuffer []gl.GoldilocksVariable - outputBuffer []gl.GoldilocksVariable + spongeState [poseidon.SPONGE_WIDTH]gl.Variable + inputBuffer []gl.Variable + outputBuffer []gl.Variable } func NewChip(api frontend.API) *Chip { - var spongeState [poseidon.SPONGE_WIDTH]gl.GoldilocksVariable - var inputBuffer []gl.GoldilocksVariable - var outputBuffer []gl.GoldilocksVariable + var spongeState [poseidon.SPONGE_WIDTH]gl.Variable + var inputBuffer []gl.Variable + var outputBuffer []gl.Variable for i := 0; i < poseidon.SPONGE_WIDTH; i++ { spongeState[i] = gl.Zero() }@@ -38,7 +38,7 @@ outputBuffer: outputBuffer,
} } -func (c *Chip) ObserveElement(element gl.GoldilocksVariable) { +func (c *Chip) ObserveElement(element gl.Variable) { c.outputBuffer = clearBuffer(c.outputBuffer) c.inputBuffer = append(c.inputBuffer, element) if len(c.inputBuffer) == poseidon.SPONGE_RATE {@@ -46,7 +46,7 @@ c.duplexing()
} } -func (c *Chip) ObserveElements(elements []gl.GoldilocksVariable) { +func (c *Chip) ObserveElements(elements []gl.Variable) { for i := 0; i < len(elements); i++ { c.ObserveElement(elements[i]) }@@ -84,7 +84,7 @@ c.ObserveExtensionElements(openings.Batches[i].Values)
} } -func (c *Chip) GetChallenge() gl.GoldilocksVariable { +func (c *Chip) GetChallenge() gl.Variable { if len(c.inputBuffer) != 0 || len(c.outputBuffer) == 0 { c.duplexing() }@@ -95,8 +95,8 @@
return challenge } -func (c *Chip) GetNChallenges(n uint64) []gl.GoldilocksVariable { - challenges := make([]gl.GoldilocksVariable, n) +func (c *Chip) GetNChallenges(n uint64) []gl.Variable { + challenges := make([]gl.Variable, n) for i := uint64(0); i < n; i++ { challenges[i] = c.GetChallenge() }@@ -109,13 +109,13 @@ return gl.QuadraticExtensionVariable{values[0], values[1]}
} func (c *Chip) GetHash() poseidon.GoldilocksHashOut { - return [4]gl.GoldilocksVariable{c.GetChallenge(), c.GetChallenge(), c.GetChallenge(), c.GetChallenge()} + return [4]gl.Variable{c.GetChallenge(), c.GetChallenge(), c.GetChallenge(), c.GetChallenge()} } func (c *Chip) GetFriChallenges( commitPhaseMerkleCaps []types.FriMerkleCap, finalPoly types.PolynomialCoeffs, - powWitness gl.GoldilocksVariable, + powWitness gl.Variable, degreeBits uint64, config types.FriConfig, ) types.FriChallenges {@@ -142,8 +142,8 @@ FriQueryIndices: friQueryIndices,
} } -func clearBuffer(buffer []gl.GoldilocksVariable) []gl.GoldilocksVariable { - return make([]gl.GoldilocksVariable, 0) +func clearBuffer(buffer []gl.Variable) []gl.Variable { + return make([]gl.Variable, 0) } func (c *Chip) duplexing() {
@@ -33,7 +33,7 @@ gl: *gl.NewGoldilocksApi(api),
} } -func (f *Chip) assertLeadingZeros(powWitness gl.GoldilocksVariable, friConfig types.FriConfig) { +func (f *Chip) assertLeadingZeros(powWitness gl.Variable, friConfig types.FriConfig) { // Asserts that powWitness'es big-endian bit representation has at least `leading_zeros` leading zeros. // Note that this is assuming that the Goldilocks field is being used. Specfically that the // field is 64 bits long@@ -58,7 +58,7 @@ return reducedOpenings
} func (f *Chip) verifyMerkleProofToCapWithCapIndex( - leafData []gl.GoldilocksVariable, + leafData []gl.Variable, leafIndexBits []frontend.Variable, capIndexBits []frontend.Variable, merkleCap types.FriMerkleCap,@@ -139,7 +139,7 @@
func (f *Chip) expFromBitsConstBase( base goldilocks.Element, exponentBits []frontend.Variable, -) gl.GoldilocksVariable { +) gl.Variable { product := gl.One() for i, bit := range exponentBits { // If the bit is on, we multiply product by base^pow.@@ -167,7 +167,7 @@
func (f *Chip) calculateSubgroupX( xIndexBits []frontend.Variable, nLog uint64, -) gl.GoldilocksVariable { +) gl.Variable { // Compute x from its index // `subgroup_x` is `subgroup[x_index]`, i.e., the actual field element in the domain. // TODO - Make these as global values@@ -284,7 +284,7 @@ return returnField
} func (f *Chip) computeEvaluation( - x gl.GoldilocksVariable, + x gl.Variable, xIndexWithinCosetBits []frontend.Variable, arityBits uint64, evals []gl.QuadraticExtensionVariable,@@ -359,7 +359,7 @@ challenges *types.FriChallenges,
precomputedReducedEval []gl.QuadraticExtensionVariable, initialMerkleCaps []types.FriMerkleCap, proof *types.FriProof, - xIndex gl.GoldilocksVariable, + xIndex gl.Variable, n uint64, nLog uint64, roundProof *types.FriQueryRound,@@ -437,7 +437,7 @@ challenges.FriBetas[i],
) // Convert evals (array of QE) to fields by taking their 0th degree coefficients - fieldEvals := make([]gl.GoldilocksVariable, 0, 2*len(evals)) + fieldEvals := make([]gl.Variable, 0, 2*len(evals)) for j := 0; j < len(evals); j++ { fieldEvals = append(fieldEvals, evals[j][0]) fieldEvals = append(fieldEvals, evals[j][1])
@@ -50,28 +50,28 @@ solver.RegisterHint(SplitLimbsHint)
} // A type alias used to represent Goldilocks field elements. -type GoldilocksVariable struct { +type Variable struct { Limb frontend.Variable } // Creates a new Goldilocks field element from an existing variable. Assumes that the element is // already reduced. -func NewVariable(x frontend.Variable) GoldilocksVariable { - return GoldilocksVariable{Limb: x} +func NewVariable(x frontend.Variable) Variable { + return Variable{Limb: x} } // The zero element in the Golidlocks field. -func Zero() GoldilocksVariable { +func Zero() Variable { return NewVariable(0) } // The one element in the Goldilocks field. -func One() GoldilocksVariable { +func One() Variable { return NewVariable(1) } // The negative one element in the Goldilocks field. -func NegOne() GoldilocksVariable { +func NegOne() Variable { return NewVariable(MODULUS.Uint64() - 1) }@@ -88,38 +88,38 @@ return &GoldilocksApi{api: api, rangeChecker: rangeChecker}
} // Adds two field elements such that x + y = z within the Golidlocks field. -func (p *GoldilocksApi) Add(a GoldilocksVariable, b GoldilocksVariable) GoldilocksVariable { +func (p *GoldilocksApi) Add(a Variable, b Variable) Variable { return p.MulAdd(a, NewVariable(1), b) } // Adds two field elements such that x + y = z within the Golidlocks field without reducing. -func (p *GoldilocksApi) AddNoReduce(a GoldilocksVariable, b GoldilocksVariable) GoldilocksVariable { +func (p *GoldilocksApi) AddNoReduce(a Variable, b Variable) Variable { return NewVariable(p.api.Add(a.Limb, b.Limb)) } // Subtracts two field elements such that x + y = z within the Golidlocks field. -func (p *GoldilocksApi) Sub(a GoldilocksVariable, b GoldilocksVariable) GoldilocksVariable { +func (p *GoldilocksApi) Sub(a Variable, b Variable) Variable { return p.MulAdd(b, NewVariable(MODULUS.Uint64()-1), a) } // Subtracts two field elements such that x + y = z within the Golidlocks field without reducing. -func (p *GoldilocksApi) SubNoReduce(a GoldilocksVariable, b GoldilocksVariable) GoldilocksVariable { +func (p *GoldilocksApi) SubNoReduce(a Variable, b Variable) Variable { return NewVariable(p.api.Add(a.Limb, p.api.Mul(b.Limb, MODULUS.Uint64()-1))) } // Multiplies two field elements such that x * y = z within the Golidlocks field. -func (p *GoldilocksApi) Mul(a GoldilocksVariable, b GoldilocksVariable) GoldilocksVariable { +func (p *GoldilocksApi) Mul(a Variable, b Variable) Variable { return p.MulAdd(a, b, Zero()) } // Multiplies two field elements such that x * y = z within the Golidlocks field without reducing. -func (p *GoldilocksApi) MulNoReduce(a GoldilocksVariable, b GoldilocksVariable) GoldilocksVariable { +func (p *GoldilocksApi) MulNoReduce(a Variable, b Variable) Variable { return NewVariable(p.api.Mul(a.Limb, b.Limb)) } // Multiplies two field elements and adds a field element such that x * y + z = c within the // Golidlocks field. -func (p *GoldilocksApi) MulAdd(a GoldilocksVariable, b GoldilocksVariable, c GoldilocksVariable) GoldilocksVariable { +func (p *GoldilocksApi) MulAdd(a Variable, b Variable, c Variable) Variable { result, err := p.api.Compiler().NewHint(MulAddHint, 2, a.Limb, b.Limb, c.Limb) if err != nil { panic(err)@@ -140,7 +140,7 @@ }
// Multiplies two field elements and adds a field element such that x * y + z = c within the // Golidlocks field without reducing. -func (p *GoldilocksApi) MulAddNoReduce(a GoldilocksVariable, b GoldilocksVariable, c GoldilocksVariable) GoldilocksVariable { +func (p *GoldilocksApi) MulAddNoReduce(a Variable, b Variable, c Variable) Variable { return p.AddNoReduce(p.MulNoReduce(a, b), c) }@@ -168,7 +168,7 @@ return nil
} // Reduces a field element x such that x % MODULUS = y. -func (p *GoldilocksApi) Reduce(x GoldilocksVariable) GoldilocksVariable { +func (p *GoldilocksApi) Reduce(x Variable) Variable { // Witness a `quotient` and `remainder` such that: // // MODULUS * quotient + remainder = x@@ -192,7 +192,7 @@ return remainder
} // Reduces a field element x such that x % MODULUS = y. -func (p *GoldilocksApi) ReduceWithMaxBits(x GoldilocksVariable, maxNbBits uint64) GoldilocksVariable { +func (p *GoldilocksApi) ReduceWithMaxBits(x Variable, maxNbBits uint64) Variable { // Witness a `quotient` and `remainder` such that: // // MODULUS * quotient + remainder = x@@ -227,7 +227,7 @@ return nil
} // Computes the inverse of a field element x such that x * x^-1 = 1. -func (p *GoldilocksApi) Inverse(x GoldilocksVariable) GoldilocksVariable { +func (p *GoldilocksApi) Inverse(x Variable) Variable { result, err := p.api.Compiler().NewHint(InverseHint, 1, x.Limb) if err != nil { panic(err)@@ -261,7 +261,7 @@ return nil
} // Computes a field element raised to some power. -func (p *GoldilocksApi) Exp(x GoldilocksVariable, k *big.Int) GoldilocksVariable { +func (p *GoldilocksApi) Exp(x Variable, k *big.Int) Variable { if k.IsUint64() && k.Uint64() == 0 { return One() }@@ -306,7 +306,7 @@ return nil
} // Range checks a field element x to be less than the Golidlocks modulus 2 ^ 64 - 2 ^ 32 + 1. -func (p *GoldilocksApi) RangeCheck(x GoldilocksVariable) { +func (p *GoldilocksApi) RangeCheck(x Variable) { // The Goldilocks' modulus is 2^64 - 2^32 + 1, which is: // // 1111111111111111111111111111111100000000000000000000000000000001@@ -350,7 +350,7 @@ frontend.Variable(0),
) } -func (p *GoldilocksApi) AssertIsEqual(x, y GoldilocksVariable) { +func (p *GoldilocksApi) AssertIsEqual(x, y Variable) { p.api.AssertIsEqual(x.Limb, y.Limb) }
@@ -9,13 +9,13 @@
const W uint64 = 7 const DTH_ROOT uint64 = 18446744069414584320 -type QuadraticExtensionVariable [2]GoldilocksVariable +type QuadraticExtensionVariable [2]Variable -func NewQuadraticExtensionVariable(x GoldilocksVariable, y GoldilocksVariable) QuadraticExtensionVariable { +func NewQuadraticExtensionVariable(x Variable, y Variable) QuadraticExtensionVariable { return QuadraticExtensionVariable{x, y} } -func (p GoldilocksVariable) ToQuadraticExtension() QuadraticExtensionVariable { +func (p Variable) ToQuadraticExtension() QuadraticExtensionVariable { return NewQuadraticExtensionVariable(p, Zero()) }@@ -101,7 +101,7 @@
// Multiplies quadratic extension variable in the Goldilocks field by a scalar. func (p *GoldilocksApi) ScalarMulExtension( a QuadraticExtensionVariable, - b GoldilocksVariable, + b Variable, ) QuadraticExtensionVariable { return NewQuadraticExtensionVariable( p.Mul(a[0], b),@@ -111,7 +111,7 @@ }
// Computes an inner product over quadratic extension variable vectors in the Goldilocks field. func (p *GoldilocksApi) InnerProductExtension( - constant GoldilocksVariable, + constant Variable, startingAcc QuadraticExtensionVariable, pairs [][2]QuadraticExtensionVariable, ) QuadraticExtensionVariable {
@@ -24,8 +24,8 @@ }
return output } -func Uint64ArrayToVariableArray(input []uint64) []GoldilocksVariable { - var output []GoldilocksVariable +func Uint64ArrayToVariableArray(input []uint64) []Variable { + var output []Variable for i := 0; i < len(input); i++ { output = append(output, NewVariable(input[i])) }
@@ -13,8 +13,8 @@ api frontend.API `gnark:"-"`
commonData types.CommonCircuitData `gnark:"-"` - DEGREE gl.GoldilocksVariable `gnark:"-"` - DEGREE_BITS_F gl.GoldilocksVariable `gnark:"-"` + DEGREE gl.Variable `gnark:"-"` + DEGREE_BITS_F gl.Variable `gnark:"-"` DEGREE_QE gl.QuadraticExtensionVariable `gnark:"-"` evaluateGatesChip *gates.EvaluateGatesChip
@@ -39,7 +39,7 @@ state = c.fullRounds(state, false)
return state } -func (c *BN254Chip) HashNoPad(input []gl.GoldilocksVariable) BN254HashOut { +func (c *BN254Chip) HashNoPad(input []gl.Variable) BN254HashOut { state := BN254State{ frontend.Variable(0), frontend.Variable(0),@@ -69,7 +69,7 @@
return BN254HashOut(state[0]) } -func (c *BN254Chip) HashOrNoop(input []gl.GoldilocksVariable) BN254HashOut { +func (c *BN254Chip) HashOrNoop(input []gl.Variable) BN254HashOut { if len(input) <= 3 { returnVal := frontend.Variable(0)@@ -94,10 +94,10 @@ state := c.Poseidon(inputs)
return state[0] } -func (c *BN254Chip) ToVec(hash BN254HashOut) []gl.GoldilocksVariable { +func (c *BN254Chip) ToVec(hash BN254HashOut) []gl.Variable { bits := c.api.ToBinary(hash) - returnElements := []gl.GoldilocksVariable{} + returnElements := []gl.Variable{} // Split into 7 byte chunks, since 8 byte chunks can result in collisions chunkSize := 56
@@ -11,9 +11,9 @@ const MAX_WIDTH = 12
const SPONGE_WIDTH = 12 const SPONGE_RATE = 8 -type GoldilocksState = [SPONGE_WIDTH]gl.GoldilocksVariable +type GoldilocksState = [SPONGE_WIDTH]gl.Variable type GoldilocksStateExtension = [SPONGE_WIDTH]gl.QuadraticExtensionVariable -type GoldilocksHashOut = [4]gl.GoldilocksVariable +type GoldilocksHashOut = [4]gl.Variable type GoldilocksChip struct { api frontend.API `gnark:"-"`@@ -38,7 +38,7 @@ }
// The input elements MUST have all it's elements be within Goldilocks field. // The returned slice's elements will all be within Goldilocks field. -func (c *GoldilocksChip) HashNToMNoPad(input []gl.GoldilocksVariable, nbOutputs int) []gl.GoldilocksVariable { +func (c *GoldilocksChip) HashNToMNoPad(input []gl.Variable, nbOutputs int) []gl.Variable { var state GoldilocksState for i := 0; i < SPONGE_WIDTH; i++ {@@ -54,7 +54,7 @@ }
state = c.Poseidon(state) } - var outputs []gl.GoldilocksVariable + var outputs []gl.Variable for { for i := 0; i < SPONGE_RATE; i++ {@@ -69,9 +69,9 @@ }
// The input elements can be outside of the Goldilocks field. // The returned slice's elements will all be within Goldilocks field. -func (c *GoldilocksChip) HashNoPad(input []gl.GoldilocksVariable) GoldilocksHashOut { +func (c *GoldilocksChip) HashNoPad(input []gl.Variable) GoldilocksHashOut { var hash GoldilocksHashOut - inputVars := []gl.GoldilocksVariable{} + inputVars := []gl.Variable{} for i := 0; i < len(input); i++ { inputVars = append(inputVars, c.gl.Reduce(input[i]))@@ -85,7 +85,7 @@
return hash } -func (c *GoldilocksChip) ToVec(hash GoldilocksHashOut) []gl.GoldilocksVariable { +func (c *GoldilocksChip) ToVec(hash GoldilocksHashOut) []gl.Variable { return hash[:] }@@ -135,7 +135,7 @@ }
return state } -func (c *GoldilocksChip) sBoxMonomial(x gl.GoldilocksVariable) gl.GoldilocksVariable { +func (c *GoldilocksChip) sBoxMonomial(x gl.Variable) gl.Variable { x2 := c.gl.MulNoReduce(x, x) x3 := c.gl.MulNoReduce(x, x2) x3 = c.gl.ReduceWithMaxBits(x3, 192)@@ -169,7 +169,7 @@ }
return state } -func (c *GoldilocksChip) mdsRowShf(r int, v [SPONGE_WIDTH]gl.GoldilocksVariable) gl.GoldilocksVariable { +func (c *GoldilocksChip) mdsRowShf(r int, v [SPONGE_WIDTH]gl.Variable) gl.Variable { res := gl.Zero() for i := 0; i < 12; i++ {
@@ -21,7 +21,7 @@ func (circuit *TestPublicInputsHashCircuit) Define(api frontend.API) error {
glAPI := gl.NewGoldilocksApi(api) // BN254 -> Binary(64) -> F - var input [3]gl.GoldilocksVariable + var input [3]gl.Variable for i := 0; i < 3; i++ { input[i] = gl.NewVariable(api.FromBinary(api.ToBinary(circuit.In[i], 64)...)) }
@@ -16,7 +16,7 @@ }
type ProofWithPublicInputs struct { Proof Proof - PublicInputs []gl.GoldilocksVariable // Length = CommonCircuitData.NumPublicInputs + PublicInputs []gl.Variable // Length = CommonCircuitData.NumPublicInputs } type VerifierOnlyCircuitData struct {@@ -46,6 +46,6 @@ QuotientDegreeFactor uint64
NumGateConstraints uint64 NumConstants uint64 NumPublicInputs uint64 - KIs []gl.GoldilocksVariable + KIs []gl.Variable NumPartialProducts uint64 }
@@ -47,11 +47,11 @@ return FriMerkleProof{Siblings: make([]poseidon.BN254HashOut, merkleProofLen)}
} type FriEvalProof struct { - Elements []gl.GoldilocksVariable // Length = [CommonCircuitData.Constants + CommonCircuitData.NumRoutedWires, CommonCircuitData.NumWires + CommonCircuitData.FriParams.Hiding ? 4 : 0, CommonCircuitData.NumChallenges * (1 + CommonCircuitData.NumPartialProducts) + salt, CommonCircuitData.NumChallenges * CommonCircuitData.QuotientDegreeFactor + salt] + Elements []gl.Variable // Length = [CommonCircuitData.Constants + CommonCircuitData.NumRoutedWires, CommonCircuitData.NumWires + CommonCircuitData.FriParams.Hiding ? 4 : 0, CommonCircuitData.NumChallenges * (1 + CommonCircuitData.NumPartialProducts) + salt, CommonCircuitData.NumChallenges * CommonCircuitData.QuotientDegreeFactor + salt] MerkleProof FriMerkleProof } -func NewFriEvalProof(elements []gl.GoldilocksVariable, merkleProof FriMerkleProof) FriEvalProof { +func NewFriEvalProof(elements []gl.Variable, merkleProof FriMerkleProof) FriEvalProof { return FriEvalProof{Elements: elements, MerkleProof: merkleProof} }@@ -88,12 +88,12 @@ type FriProof struct {
CommitPhaseMerkleCaps []FriMerkleCap // Length = Len(CommonCircuitData.FriParams.ReductionArityBits) QueryRoundProofs []FriQueryRound // Length = CommonCircuitData.FriConfig.FriParams.NumQueryRounds FinalPoly PolynomialCoeffs - PowWitness gl.GoldilocksVariable + PowWitness gl.Variable } type FriChallenges struct { FriAlpha gl.QuadraticExtensionVariable FriBetas []gl.QuadraticExtensionVariable - FriPowResponse gl.GoldilocksVariable - FriQueryIndices []gl.GoldilocksVariable + FriPowResponse gl.Variable + FriQueryIndices []gl.Variable }
@@ -25,9 +25,9 @@ }
} type ProofChallenges struct { - PlonkBetas []gl.GoldilocksVariable - PlonkGammas []gl.GoldilocksVariable - PlonkAlphas []gl.GoldilocksVariable + PlonkBetas []gl.Variable + PlonkGammas []gl.Variable + PlonkAlphas []gl.Variable PlonkZeta gl.QuadraticExtensionVariable FriChallenges FriChallenges }
@@ -35,7 +35,7 @@ friChip: friChip,
} } -func (c *VerifierChip) GetPublicInputsHash(publicInputs []gl.GoldilocksVariable) poseidon.GoldilocksHashOut { +func (c *VerifierChip) GetPublicInputsHash(publicInputs []gl.Variable) poseidon.GoldilocksHashOut { return c.poseidonGlChip.HashNoPad(publicInputs) }@@ -206,7 +206,7 @@ }
func (c *VerifierChip) Verify( proof types.Proof, - publicInputs []gl.GoldilocksVariable, + publicInputs []gl.Variable, verifierData types.VerifierOnlyCircuitData, commonData types.CommonCircuitData, ) {
@@ -15,7 +15,7 @@ )
type TestVerifierCircuit struct { Proof types.Proof - PublicInputs []gl.GoldilocksVariable `gnark:",public"` + PublicInputs []gl.Variable `gnark:",public"` verifierChip *verifier.VerifierChip `gnark:"-"` plonky2CircuitName string `gnark:"-"`