Coset Interpolation Gate (#15)

* helper functions for coset_interpolation_gate

* coset interpolation gate working

* hard coded the coset gate (for now)
This commit is contained in:
Kevin Jue
2023-05-18 13:06:30 -07:00
committed by GitHub
parent 67aa8b9d77
commit 5bb7cc6411
5 changed files with 309 additions and 7 deletions

View File

@@ -35,6 +35,7 @@ func NewFieldAPI(api frontend.API) frontend.API {
var ONE_F = NewFieldElement(1)
var ZERO_F = NewFieldElement(0)
var NEG_ONE_F = NewFieldElement(EmulatedField{}.Modulus().Uint64() - 1)
var GOLDILOCKS_MULTIPLICATIVE_GROUP_GENERATOR = goldilocks.NewElement(7)
var GOLDILOCKS_TWO_ADICITY = uint64(32)
@@ -52,3 +53,20 @@ func GoldilocksPrimitiveRootOfUnity(nLog uint64) goldilocks.Element {
return res
}
func TwoAdicSubgroup(nLog uint64) []goldilocks.Element {
if nLog > GOLDILOCKS_TWO_ADICITY {
panic("nLog is greater than GOLDILOCKS_TWO_ADICITY")
}
var res []goldilocks.Element
rootOfUnity := GoldilocksPrimitiveRootOfUnity(nLog)
res = append(res, goldilocks.NewElement(1))
for i := 0; i < (1 << nLog); i++ {
lastElement := res[len(res)-1]
res = append(res, *lastElement.Mul(&lastElement, &rootOfUnity))
}
return res
}

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"math/bits"
"github.com/consensys/gnark-crypto/field/goldilocks"
"github.com/consensys/gnark/frontend"
)
@@ -237,3 +238,42 @@ func (c *QuadraticExtensionAPI) SubExtensionAlgebra(a, b QEAlgebra) QEAlgebra {
return diff
}
func (c *QuadraticExtensionAPI) PartialInterpolateExtAlgebra(
domain []goldilocks.Element,
values []QEAlgebra,
barycentricWeights []goldilocks.Element,
point QEAlgebra,
initialEval QEAlgebra,
initialPartialProd QEAlgebra,
) (QEAlgebra, QEAlgebra) {
n := len(values)
if n == 0 {
panic("Cannot interpolate with no values")
}
if n != len(domain) {
panic("Domain and values must have the same length")
}
if n != len(barycentricWeights) {
panic("Domain and barycentric weights must have the same length")
}
newEval := initialEval
newPartialProd := initialPartialProd
for i := 0; i < n; i++ {
val := values[i]
x := domain[i]
xField := NewFieldElement(x.Uint64())
xQE := QuadraticExtension{xField, ZERO_F}
xQEAlgebra := QEAlgebra{xQE, c.ZERO_QE}
weight := QuadraticExtension{NewFieldElement(barycentricWeights[i].Uint64()), ZERO_F}
term := c.SubExtensionAlgebra(point, xQEAlgebra)
weightedVal := c.ScalarMulExtensionAlgebra(weight, val)
newEval = c.MulExtensionAlgebra(newEval, term)
tmp := c.MulExtensionAlgebra(weightedVal, newPartialProd)
newEval = c.AddExtensionAlgebra(newEval, tmp)
newPartialProd = c.MulExtensionAlgebra(newPartialProd, term)
}
return newEval, newPartialProd
}