Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prover/feat/Adding field extension support to Smartvectors #499

Draft
wants to merge 73 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
de7e6b7
bug fix
bogdanbear Jan 6, 2025
101b5ec
bug fix
bogdanbear Jan 6, 2025
48ebaf9
replace fext with Youssef's field extensions
bogdanbear Jan 7, 2025
9ced951
remove dedicated field operations that break CI
bogdanbear Jan 7, 2025
ce1448c
Extensions for FFT + fast poly WIP
bogdanbear Jan 8, 2025
e0d820e
Feat/adding gnark support for extension (#522)
AlexandreBelling Jan 9, 2025
016adea
interpolation compiles, must be debugged
bogdanbear Jan 10, 2025
21296d2
interpolation test pass
bogdanbear Jan 10, 2025
9a9e853
tests for smartvectors ext
bogdanbear Jan 11, 2025
92b5958
fixing failing smartvectors tests, wip
bogdanbear Jan 13, 2025
35b492e
need an API for test vectors of field extensions
bogdanbear Jan 13, 2025
c0a7b5d
inner prod test fix
bogdanbear Jan 13, 2025
5f5917c
alex: help fixing the TestScalarMul test
AlexandreBelling Jan 13, 2025
3196e44
ruffini test
bogdanbear Jan 14, 2025
eb6f62f
TestBivariatePolynomial
bogdanbear Jan 14, 2025
3b9f8ea
polyext, wip
bogdanbear Jan 14, 2025
d052473
more meaningful tests for polyext, wip
bogdanbear Jan 14, 2025
c4c594b
polyexp tests, wip
bogdanbear Jan 14, 2025
6a84765
polyext tests
bogdanbear Jan 14, 2025
111b34c
refactor
bogdanbear Jan 14, 2025
5316649
fixing linter errors
bogdanbear Jan 14, 2025
8406726
refactor fuzz parameters
bogdanbear Jan 14, 2025
475c966
refactor and more vector tests
bogdanbear Jan 14, 2025
3ca1b9b
refactor E2 -> Variable
bogdanbear Jan 14, 2025
0d682c4
intognarkassignmenttest in vectorext test
bogdanbear Jan 14, 2025
f719734
vectorext tests
bogdanbear Jan 14, 2025
b82be08
Merge branch 'main' into prover/feat/small-field-exploratory-2
bogdanbear Jan 15, 2025
4cb0c60
coordinator: decouple configs test from real configs (#552)
jpnovais Jan 15, 2025
d29cdd4
feat: added async retryer for currentL2BlockNumber in case the contra…
jonesho Jan 15, 2025
9ccd8e4
lagrange basis evaluation random test
bogdanbear Jan 15, 2025
ee308c7
Merge branch 'prover/feat/small-field-exploratory-2' of https://githu…
bogdanbear Jan 15, 2025
fe967c7
State recover part 4 (#324)
jpnovais Jan 16, 2025
26ba22e
[Fix] Make codecov action optional in workflows (#559)
kyzooghost Jan 16, 2025
05d3ee2
fix(ecpair): ensure last non-trivial input pair goes to ML+finalexp c…
ivokub Jan 16, 2025
be18423
Staterecover part5 (#565)
jpnovais Jan 16, 2025
aeb8685
Prover: connect the codehash and the statesummary module (#463)
AlexandreBelling Jan 16, 2025
5deb91f
marshal/unmarshal tests, wip
bogdanbear Jan 16, 2025
e8ace87
async unmarshalling iwp
bogdanbear Jan 17, 2025
5c2bbf7
finished marshalling tests + bug fix
bogdanbear Jan 17, 2025
4f13fb5
removed _GITHUB_TOKEN_RELEASE_ACCESS from pull_request workflows (#563)
kyzooghost Jan 17, 2025
006bcbb
[Fix] remove SELF_GITHUB_SSH_KEY (#561)
kyzooghost Jan 17, 2025
f67f2a0
bug fix
bogdanbear Jan 6, 2025
5816b79
bug fix
bogdanbear Jan 6, 2025
5922a86
replace fext with Youssef's field extensions
bogdanbear Jan 7, 2025
847f6c3
remove dedicated field operations that break CI
bogdanbear Jan 7, 2025
31ccc90
Extensions for FFT + fast poly WIP
bogdanbear Jan 8, 2025
7e00adb
Feat/adding gnark support for extension (#522)
AlexandreBelling Jan 9, 2025
9fc3ef0
interpolation compiles, must be debugged
bogdanbear Jan 10, 2025
f1256ea
interpolation test pass
bogdanbear Jan 10, 2025
3262f8e
tests for smartvectors ext
bogdanbear Jan 11, 2025
2af431c
fixing failing smartvectors tests, wip
bogdanbear Jan 13, 2025
0d5ed5d
need an API for test vectors of field extensions
bogdanbear Jan 13, 2025
fdb52fd
inner prod test fix
bogdanbear Jan 13, 2025
57faff8
alex: help fixing the TestScalarMul test
AlexandreBelling Jan 13, 2025
e4c0976
ruffini test
bogdanbear Jan 14, 2025
bb13c44
TestBivariatePolynomial
bogdanbear Jan 14, 2025
9af6865
polyext, wip
bogdanbear Jan 14, 2025
53905be
more meaningful tests for polyext, wip
bogdanbear Jan 14, 2025
e483762
polyexp tests, wip
bogdanbear Jan 14, 2025
6140595
polyext tests
bogdanbear Jan 14, 2025
c6613b7
refactor
bogdanbear Jan 14, 2025
3533272
fixing linter errors
bogdanbear Jan 14, 2025
e1dc9e3
refactor fuzz parameters
bogdanbear Jan 14, 2025
e3d8861
refactor and more vector tests
bogdanbear Jan 14, 2025
e375876
refactor E2 -> Variable
bogdanbear Jan 14, 2025
fb6c987
intognarkassignmenttest in vectorext test
bogdanbear Jan 14, 2025
958e450
vectorext tests
bogdanbear Jan 14, 2025
85d6b91
lagrange basis evaluation random test
bogdanbear Jan 15, 2025
9293e26
marshal/unmarshal tests, wip
bogdanbear Jan 16, 2025
7b7a034
async unmarshalling iwp
bogdanbear Jan 17, 2025
c3c38d6
finished marshalling tests + bug fix
bogdanbear Jan 17, 2025
859ea53
Merge commit with main after rebase
bogdanbear Jan 17, 2025
4fa3996
fix linter error
bogdanbear Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions prover/maths/common/polyext/gnarkpoly.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package polyext

import (
"github.com/consensys/gnark/frontend"
"github.com/consensys/linea-monorepo/prover/maths/field"
"github.com/consensys/linea-monorepo/prover/maths/field/fext/gnarkfext"
)

// EvaluateLagrangeAnyDomainGnark mirrors [EvaluateLagrangesAnyDomain] but in
// a gnark circuit. The same usage precautions applies for it.
func EvaluateLagrangeAnyDomainGnark(api frontend.API, domain []gnarkfext.Variable, x gnarkfext.Variable) []gnarkfext.Variable {

outerAPI := gnarkfext.API{Inner: api}
lagrange := make([]gnarkfext.Variable, len(domain))

for i, hi := range domain {
lhix := gnarkfext.Variable{field.One(), field.Zero()}
for j, hj := range domain {
if i == j {
// Skip it
continue
}
// more convenient to store -h instead of h
factor := outerAPI.Sub(x, hj)
den := outerAPI.Sub(hi, hj) // so x - h
den = outerAPI.Inverse(den)

// accumulate the product
lhix = outerAPI.Mul(lhix, factor, den)
}
lagrange[i] = lhix
}

return lagrange

}

// EvaluateUnivariateGnark evaluate a univariate polynomial in a gnark circuit.
// It mirrors [EvalUnivariate].
func EvaluateUnivariateGnark(api frontend.API, pol []gnarkfext.Variable, x gnarkfext.Variable) gnarkfext.Variable {
res := gnarkfext.Variable{frontend.Variable(0), frontend.Variable(0)}
outerAPI := gnarkfext.API{Inner: api}
for i := len(pol) - 1; i >= 0; i-- {
res = outerAPI.Mul(res, x)
res = outerAPI.Add(res, pol[i])
}
return res
}
99 changes: 99 additions & 0 deletions prover/maths/common/polyext/gnarkpoly_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package polyext

import (
"github.com/consensys/linea-monorepo/prover/maths/common/vectorext"
"github.com/consensys/linea-monorepo/prover/maths/field/fext"
"github.com/consensys/linea-monorepo/prover/maths/field/fext/gnarkfext"
"testing"

"github.com/consensys/gnark/frontend"
"github.com/consensys/linea-monorepo/prover/utils/gnarkutil"
"github.com/stretchr/testify/require"
)

func TestGnarkEval(t *testing.T) {

t.Run("normal-poly", func(t *testing.T) {

def := func(api frontend.API) error {
outerAPI := gnarkfext.API{Inner: api}
var (
pol = vectorext.IntoGnarkAssignment(vectorext.ForTestFromPairs(1, 2, 3, 4, -1, -2))
x = gnarkfext.Variable{2, 1}
expected = gnarkfext.Variable{
-5*fext.RootPowers[1] + 3,
-2*fext.RootPowers[1] + 1,
}
res = EvaluateUnivariateGnark(api, pol, x)
)
outerAPI.AssertIsEqual(expected, res)
return nil
}

gnarkutil.AssertCircuitSolved(t, def)
})

t.Run("empty-poly", func(t *testing.T) {
def := func(api frontend.API) error {
outerAPI := gnarkfext.API{Inner: api}
var (
pol = vectorext.IntoGnarkAssignment([]fext.Element{})
x = gnarkfext.Variable{2, 3}
expected = gnarkfext.NewZero()
res = EvaluateUnivariateGnark(api, pol, x)
)
outerAPI.AssertIsEqual(expected, res)
return nil
}
gnarkutil.AssertCircuitSolved(t, def)
})

}

func TestGnarkEvalAnyDomain(t *testing.T) {

t.Run("single-variable", func(t *testing.T) {

def := func(api frontend.API) error {
outerAPI := gnarkfext.API{Inner: api}
var (
domain = vectorext.IntoGnarkAssignment(vectorext.ForTestFromPairs(0, 0))
x = gnarkfext.Variable{42, 0}
expected = vectorext.IntoGnarkAssignment(vectorext.ForTestFromPairs(1, 0))
res = EvaluateLagrangeAnyDomainGnark(api, domain, x)
)

require.Len(t, res, len(expected))
for i := range expected {
outerAPI.AssertIsEqual(expected[i], res[i])
}

return nil
}

gnarkutil.AssertCircuitSolved(t, def)
})

t.Run("multiple-variable", func(t *testing.T) {

def := func(api frontend.API) error {
outerAPI := gnarkfext.API{Inner: api}
var (
domain = vectorext.IntoGnarkAssignment(vectorext.ForTestFromPairs(0, 0, 1, 0))
x = gnarkfext.Variable{42, 0}
expected = vectorext.IntoGnarkAssignment(vectorext.ForTestFromPairs(-41, 0, 42, 0))
res = EvaluateLagrangeAnyDomainGnark(api, domain, x)
)

require.Len(t, res, len(expected))
for i := range expected {
outerAPI.AssertIsEqual(expected[i], res[i])
}

return nil
}

gnarkutil.AssertCircuitSolved(t, def)
})

}
8 changes: 7 additions & 1 deletion prover/maths/common/polyext/poly.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package polyext

import (
"github.com/consensys/linea-monorepo/prover/maths/common/smartvectors/vectorext"
"github.com/consensys/linea-monorepo/prover/maths/common/vectorext"
"github.com/consensys/linea-monorepo/prover/maths/field"
"github.com/consensys/linea-monorepo/prover/maths/field/fext"
"github.com/consensys/linea-monorepo/prover/utils"
)
Expand All @@ -22,6 +23,11 @@ func EvalUnivariate(pol []fext.Element, x fext.Element) fext.Element {
return res
}

func EvalUnivariateBase(pol []fext.Element, x field.Element) fext.Element {
wrappedX := fext.Element{x, field.Zero()}
return EvalUnivariate(pol, wrappedX)
}

// Mul multiplies two polynomials expressed by their coefficients using the
// naive method and writes the result in res. `a` and `b` may have distinct
// degrees and the result is returned in a slice of size len(a) + len(b) - 1.
Expand Down
Loading
Loading