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/Convert projection protocol to a query #585

Merged
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
3 changes: 1 addition & 2 deletions prover/backend/execution/prove.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ func mustProveAndPass(
case config.ProverModeEncodeOnly:

profiling.ProfileTrace("encode-decode-no-circuit", true, false, func() {
//nolint:gosec // Ignoring weak randomness error
filepath := "/tmp/wizard-assignment/blob-" + strconv.Itoa(rand.Int()) + ".bin"
filepath := "/tmp/wizard-assignment/blob-" + strconv.Itoa(rand.Int()) + ".bin" //nolint:gosec // Ignoring weak randomness error

encodeOnlyZkEvm := zkevm.EncodeOnlyZkEvm(traces)
numChunks := runtime.GOMAXPROCS(0)
Expand Down
2 changes: 1 addition & 1 deletion prover/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/iancoleman/strcase v0.3.0
github.com/icza/bitio v1.1.0
github.com/leanovate/gopter v0.2.11
github.com/pierrec/lz4/v4 v4.1.21
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.19.1
github.com/rs/zerolog v1.33.0
Expand Down Expand Up @@ -76,7 +77,6 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
Expand Down
28 changes: 28 additions & 0 deletions prover/maths/common/poly/poly.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,31 @@ func EvaluateLagrangesAnyDomain(domain []field.Element, x field.Element) []field

return lagrange
}

// CmptHorner computes a random Horner accumulation of the filtered elements
// starting from the last entry down to the first entry. The final value is
// stored in the last entry of the returned slice.
// Todo: send it to a common utility package
arijitdutta67 marked this conversation as resolved.
Show resolved Hide resolved
func CmptHorner(c, fC []field.Element, x field.Element) []field.Element {
arijitdutta67 marked this conversation as resolved.
Show resolved Hide resolved

var (
horner = make([]field.Element, len(c))
prev field.Element
)

for i := len(horner) - 1; i >= 0; i-- {

if !fC[i].IsZero() && !fC[i].IsOne() {
utils.Panic("we expected the filter to be binary")
}

if fC[i].IsOne() {
prev.Mul(&prev, &x)
prev.Add(&prev, &c[i])
}

horner[i] = prev
}

return horner
}
9 changes: 9 additions & 0 deletions prover/protocol/column/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,12 @@ func RandLinCombColAssignment(run ifaces.Runtime, coinVal field.Element, hs []if
}
return witnessCollapsed
}

// maximal round of declaration for a list of commitment
func MaxRound(handles ...ifaces.Column) int {
res := 0
for _, handle := range handles {
res = utils.Max(res, handle.Round())
}
return res
}
2 changes: 2 additions & 0 deletions prover/protocol/compiler/arcane.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/consensys/linea-monorepo/prover/protocol/compiler/logdata"
"github.com/consensys/linea-monorepo/prover/protocol/compiler/lookup"
"github.com/consensys/linea-monorepo/prover/protocol/compiler/permutation"
"github.com/consensys/linea-monorepo/prover/protocol/compiler/projection"
"github.com/consensys/linea-monorepo/prover/protocol/compiler/specialqueries"
"github.com/consensys/linea-monorepo/prover/protocol/compiler/splitter"
"github.com/consensys/linea-monorepo/prover/protocol/compiler/splitter/sticker"
Expand All @@ -29,6 +30,7 @@ func Arcane(minStickSize, targetColSize int, noLog ...bool) func(comp *wizard.Co
permutation.CompileGrandProduct(comp)
lookup.CompileLogDerivative(comp)
innerproduct.Compile(comp)
projection.CompileProjection(comp)
if withLog_ {
logdata.Log("after-expansion")(comp)
}
Expand Down
2 changes: 1 addition & 1 deletion prover/protocol/compiler/mimc/manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func manualCheckMiMCBlock(comp *wizard.CompiledIOP, blocks, oldStates, newStates
newStates: newStates,
}

round := wizardutils.MaxRound(blocks, oldStates, newStates)
round := column.MaxRound(blocks, oldStates, newStates)

// Creates an intermediate column for each round
s := blocks
Expand Down
158 changes: 158 additions & 0 deletions prover/protocol/compiler/projection/compiler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package projection

import (
"github.com/consensys/linea-monorepo/prover/protocol/coin"
"github.com/consensys/linea-monorepo/prover/protocol/column"
"github.com/consensys/linea-monorepo/prover/protocol/ifaces"
"github.com/consensys/linea-monorepo/prover/protocol/query"
"github.com/consensys/linea-monorepo/prover/protocol/wizard"
"github.com/consensys/linea-monorepo/prover/protocol/wizardutils"
sym "github.com/consensys/linea-monorepo/prover/symbolic"
)

// CompileProjection compiles [query.Projection] queries
func CompileProjection(comp *wizard.CompiledIOP) {

for _, qName := range comp.QueriesNoParams.AllUnignoredKeys() {
// Filter out non projection queries
projection, ok := comp.QueriesNoParams.Data(qName).(query.Projection)
if !ok {
continue
}

// This ensures that the projection query is not used again in the
// compilation process. We know that the query was not already ignored at the beginning
// because we are iterating over the unignored keys.
comp.QueriesNoParams.MarkAsIgnored(qName)
round := comp.QueriesNoParams.Round(qName)
compile(comp, round, projection)
}

}

func compile(comp *wizard.CompiledIOP, round int, projection query.Projection) {
var (
compRound = round
sizeA = projection.Inp.FilterA.Size()
sizeB = projection.Inp.FilterB.Size()
numCol = len(projection.Inp.ColumnA)
a, b, af, bf any
queryName = projection.ID
columnsA = projection.Inp.ColumnA
columnsB = projection.Inp.ColumnB
filterA = projection.Inp.FilterA
filterB = projection.Inp.FilterB
)

// a and b are storing the columns used to compute the linear combination
// of the columnsA and columnsB. The initial assignment is for the case
// where there is only a single column. If there is more than one column
// then they will store an expression computing a random linear
// combination of the columns.
a, b = projection.Inp.ColumnA[0], projection.Inp.ColumnB[0]

// af and bf are as a and b but shifted by -1. They are initially
// assigned assuming the case where the number of column is 1 and
// replaced later by a random linear combination if not. They are meant
// to be used in the local constraints to point to the last entry of the
// "a" and "b".
af, bf = column.Shift(projection.Inp.ColumnA[0], -1), column.Shift(projection.Inp.ColumnB[0], -1)

if numCol > 0 {
compRound++
alpha := comp.InsertCoin(compRound, coin.Namef("%v_MERGING_COIN", queryName), coin.Field)
a = wizardutils.RandLinCombColSymbolic(alpha, columnsA)
b = wizardutils.RandLinCombColSymbolic(alpha, columnsB)

afs := make([]ifaces.Column, numCol)
bfs := make([]ifaces.Column, numCol)

for i := range afs {
afs[i] = column.Shift(columnsA[i], -1)
bfs[i] = column.Shift(columnsB[i], -1)
}

af = wizardutils.RandLinCombColSymbolic(alpha, afs)
bf = wizardutils.RandLinCombColSymbolic(alpha, bfs)
}

var (
aExpr, _, _ = wizardutils.AsExpr(a)
bExpr, _, _ = wizardutils.AsExpr(b)
pa = projectionProverAction{
Name: queryName,
EvalCoin: comp.InsertCoin(compRound, coin.Namef("%v_EVAL_COIN", queryName), coin.Field),
FilterA: filterA,
FilterB: filterB,
ColA: columnsA,
ColB: columnsB,
ABoard: aExpr.Board(),
BBoard: bExpr.Board(),
HornerA: comp.InsertCommit(compRound, ifaces.ColIDf("%v_HORNER_A", queryName), sizeA),
HornerB: comp.InsertCommit(compRound, ifaces.ColIDf("%v_HORNER_B", queryName), sizeB),
}
)

comp.InsertGlobal(
compRound,
ifaces.QueryIDf("%v_HORNER_A_GLOBAL", queryName),
sym.Sub(
pa.HornerA,
sym.Mul(
sym.Sub(1, pa.FilterA),
column.Shift(pa.HornerA, 1),
),
sym.Mul(
pa.FilterA,
sym.Add(
a,
sym.Mul(
pa.EvalCoin,
column.Shift(pa.HornerA, 1),
),
),
),
),
)

comp.InsertGlobal(
compRound,
ifaces.QueryIDf("%v_HORNER_B_GLOBAL", queryName),
sym.Sub(
pa.HornerB,
sym.Mul(
sym.Sub(1, pa.FilterB),
column.Shift(pa.HornerB, 1),
),
sym.Mul(
pa.FilterB,
sym.Add(b, sym.Mul(pa.EvalCoin, column.Shift(pa.HornerB, 1))),
),
),
)

comp.InsertLocal(
compRound,
ifaces.QueryIDf("%v_HORNER_A_LOCAL_END", queryName),
sym.Sub(
column.Shift(pa.HornerA, -1),
sym.Mul(column.Shift(pa.FilterA, -1), af),
),
)

comp.InsertLocal(
compRound,
ifaces.QueryIDf("%v_HORNER_B_LOCAL_END", queryName),
sym.Sub(
column.Shift(pa.HornerB, -1),
sym.Mul(column.Shift(pa.FilterB, -1), bf),
),
)

pa.HornerA0 = comp.InsertLocalOpening(compRound, ifaces.QueryIDf("%v_HORNER_A0", queryName), pa.HornerA)
pa.HornerB0 = comp.InsertLocalOpening(compRound, ifaces.QueryIDf("%v_HORNER_B0", queryName), pa.HornerB)

comp.RegisterProverAction(compRound, pa)
comp.RegisterVerifierAction(compRound, &projectionVerifierAction{HornerA0: pa.HornerA0, HornerB0: pa.HornerB0, Name: queryName})

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package projection
package projection_test

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/compiler/dummy"
"github.com/consensys/linea-monorepo/prover/protocol/compiler/projection"
"github.com/consensys/linea-monorepo/prover/protocol/ifaces"
"github.com/consensys/linea-monorepo/prover/protocol/query"
"github.com/consensys/linea-monorepo/prover/protocol/wizard"
"github.com/stretchr/testify/assert"
)
Expand All @@ -25,8 +27,7 @@ func makeTestCaseProjection() (
flagB = comp.InsertCommit(round, ifaces.ColID("FliterB"), flagSizeB)
columnA = comp.InsertCommit(round, ifaces.ColID("ColumnA"), flagSizeA)
columnB = comp.InsertCommit(round, ifaces.ColID("ColumnB"), flagSizeB)
InsertProjection(comp, ifaces.QueryIDf("OrderPreserving"),
[]ifaces.Column{columnA}, []ifaces.Column{columnB}, flagA, flagB)
comp.InsertProjection("Projection_Compilation_Test", query.ProjectionInput{ColumnA: []ifaces.Column{columnA}, ColumnB: []ifaces.Column{columnB}, FilterA: flagA, FilterB: flagB})

}
prover = func(run *wizard.ProverRuntime) {
Expand Down Expand Up @@ -54,7 +55,7 @@ func makeTestCaseProjection() (
func TestProjectionQuery(t *testing.T) {

define, prover := makeTestCaseProjection()
comp := wizard.Compile(define, dummy.Compile)
comp := wizard.Compile(define, projection.CompileProjection, dummy.CompileAtProverLvl)

proof := wizard.Prove(comp, prover)
assert.NoErrorf(t, wizard.Verify(comp, proof), "invalid proof")
Expand Down
Loading
Loading