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

fixed the bug in PolyEval #214

Merged
merged 4 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions prover/maths/common/smartvectors/arithmetic_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ func PolyEval(vecs []SmartVector, x field.Element, p ...mempool.MemPool) (result
anyReg = true
v := *casted
accumulateReg(resReg, v, xPow)
case *Pooled: // e.g. from product
anyReg = true
v := casted.Regular
accumulateReg(resReg, v, xPow)
case *PaddedCircularWindow:
// treat it as a regular, reusing the buffer
anyReg = true
Expand Down
9 changes: 2 additions & 7 deletions prover/protocol/compiler/innerproduct/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,8 @@ func compileForSize(
}
}

// @Azam the following function is commented out due to the issue https://github.com/Consensys/linea-monorepo/issues/192
// ctx.Collapsed = symbolic.NewPolyEval(batchingCoin.AsVariable(), pairProduct)
res := symbolic.NewConstant(0)
for i := len(pairProduct) - 1; i >= 0; i-- {
res = symbolic.Mul(res, batchingCoin)
res = symbolic.Add(res, pairProduct[i])
}
// random linear combination over the pairs of inner-product.
res := symbolic.NewPolyEval(batchingCoin.AsVariable(), pairProduct)

ctx.Collapsed = res
ctx.CollapsedBoard = ctx.Collapsed.Board()
Expand Down
11 changes: 1 addition & 10 deletions prover/protocol/wizardutils/evaluation.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,13 @@ func EvalExprColumn(run *wizard.ProverRuntime, board symbolic.ExpressionBoard) s

// returns the symbolic expression of a column obtained as a random linear combinations of differents handles
// without committing to the column itself
// @Azam this function is temporarily ignored and addressed in issue https://github.com/Consensys/linea-monorepo/issues/192
/*func RandLinCombColSymbolic(x coin.Info, hs []ifaces.Column) *symbolic.Expression {
func RandLinCombColSymbolic(x coin.Info, hs []ifaces.Column) *symbolic.Expression {
cols := make([]*symbolic.Expression, len(hs))
for c := range cols {
cols[c] = ifaces.ColumnAsVariable(hs[c])
}
expr := symbolic.NewPolyEval(x.AsVariable(), cols)
return expr
}*/
func RandLinCombColSymbolic(x coin.Info, hs []ifaces.Column) *symbolic.Expression {
res := symbolic.NewConstant(0)
for i := len(hs) - 1; i >= 0; i-- {
res = symbolic.Mul(res, x)
res = symbolic.Add(res, hs[i])
}
return res
}

// return the runtime assignments of a linear combination column
Expand Down
81 changes: 81 additions & 0 deletions prover/protocol/wizardutils/wizardutils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package wizardutils

import (
"testing"

"github.com/consensys/linea-monorepo/prover/maths/common/smartvectors"
"github.com/consensys/linea-monorepo/prover/maths/field"
"github.com/consensys/linea-monorepo/prover/protocol/coin"
"github.com/consensys/linea-monorepo/prover/protocol/column/verifiercol"
"github.com/consensys/linea-monorepo/prover/protocol/compiler/dummy"
"github.com/consensys/linea-monorepo/prover/protocol/ifaces"
"github.com/consensys/linea-monorepo/prover/protocol/wizard"
"github.com/consensys/linea-monorepo/prover/symbolic"
"github.com/stretchr/testify/assert"
)

func TestWizarldutils(t *testing.T) {
var res1, res11, res2, res22 *symbolic.Expression
define := func(b *wizard.Builder) {
var (
size = 4
col1 = b.RegisterCommit("P1", size)
col2 = b.RegisterCommit("P2", size)

col5 = b.RegisterPrecomputed("P3", smartvectors.ForTest(1, 0, 1, 1))
col6 = verifiercol.NewConstantCol(field.NewElement(3), size)

coin = b.RegisterRandomCoin(coin.Namef("Coin"), coin.Field)
)

// PolyEval over columns
res1 = symbolic.NewPolyEval(coin.AsVariable(), []*symbolic.Expression{ifaces.ColumnAsVariable(col1), ifaces.ColumnAsVariable(col2)})
res11 = linCom(coin.AsVariable(), []*symbolic.Expression{ifaces.ColumnAsVariable(col1), ifaces.ColumnAsVariable(col2)})

// PolyEval over PolyEval and Mul.
expr := symbolic.Mul(col6, col5, coin)
res2 = symbolic.NewPolyEval(coin.AsVariable(), []*symbolic.Expression{res1, expr})
res22 = linCom(coin.AsVariable(), []*symbolic.Expression{res1, expr})

}
prover := func(run *wizard.ProverRuntime) {
var (
col1 = smartvectors.ForTest(1, 2, 1, 0)
col2 = smartvectors.ForTest(1, 1, 3, 1)
)
run.AssignColumn("P1", col1)
run.AssignColumn("P2", col2)

run.GetRandomCoinField(coin.Namef("Coin"))

res1Wit := EvalExprColumn(run, res1.Board()).IntoRegVecSaveAlloc()
res11Wit := EvalExprColumn(run, res11.Board()).IntoRegVecSaveAlloc()
for i := range res11Wit {
if res1Wit[i].Cmp(&res11Wit[i]) != 0 {
panic("err")
}
}

res2Wit := EvalExprColumn(run, res2.Board()).IntoRegVecSaveAlloc()
res22Wit := EvalExprColumn(run, res22.Board()).IntoRegVecSaveAlloc()
for i := range res11Wit {
if res2Wit[i].Cmp(&res22Wit[i]) != 0 {
panic("err")
}
}

}

comp := wizard.Compile(define, dummy.Compile)
proof := wizard.Prove(comp, prover)
assert.NoErrorf(t, wizard.Verify(comp, proof), "invalid proof")
}

func linCom(x *symbolic.Expression, coeff []*symbolic.Expression) *symbolic.Expression {
res := symbolic.NewConstant(0)
for i := len(coeff) - 1; i >= 0; i-- {
res = symbolic.Mul(res, x)
res = symbolic.Add(res, coeff[i])
}
return res
}
Loading