Skip to content

Commit

Permalink
Merge branch 'prover/limitless-top-level' of github.com:Consensys/lin…
Browse files Browse the repository at this point in the history
…ea-monorepo into prover/limitless-circuits-as-queries
  • Loading branch information
AlexandreBelling committed Feb 22, 2025
2 parents 50837d7 + f97cd00 commit 4f51ada
Show file tree
Hide file tree
Showing 35 changed files with 2,634 additions and 82 deletions.
5 changes: 2 additions & 3 deletions prover/maths/common/poly/poly.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,10 @@ func EvaluateLagrangesAnyDomain(domain []field.Element, x field.Element) []field
return lagrange
}

// CmptHorner computes a random Horner accumulation of the filtered elements
// GetHornerTrace 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
func CmptHorner(c, fC []field.Element, x field.Element) []field.Element {
func GetHornerTrace(c, fC []field.Element, x field.Element) []field.Element {

var (
horner = make([]field.Element, len(c))
Expand Down
71 changes: 71 additions & 0 deletions prover/protocol/accessors/from_distributedprojection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package accessors

import (
"fmt"

"github.com/consensys/gnark/frontend"
"github.com/consensys/linea-monorepo/prover/maths/field"
"github.com/consensys/linea-monorepo/prover/protocol/ifaces"
"github.com/consensys/linea-monorepo/prover/protocol/query"
"github.com/consensys/linea-monorepo/prover/symbolic"
)

const (
DISTRIBUTED_PROJECTION_ACCESSOR = "DISTRIBUTED_PROJECTION_ACCESSOR"
)

// FromDistributedProjectionAccessor implements [ifaces.Accessor] and accesses the result of
// a [query.DISTRIBUTED_PROJECTION].
type FromDistributedProjectionAccessor struct {
// Q is the underlying query whose parameters are accessed by the current
// [ifaces.Accessor].
Q query.DistributedProjection
}

// NewDistributedProjectionAccessor creates an [ifaces.Accessor] returning the opening
// point of a [query.DISTRIBUTED_PROJECTION].
func NewDistributedProjectionAccessor(q query.DistributedProjection) ifaces.Accessor {
return &FromDistributedProjectionAccessor{Q: q}
}

// Name implements [ifaces.Accessor]
func (l *FromDistributedProjectionAccessor) Name() string {
return fmt.Sprintf("%v_%v", DISTRIBUTED_PROJECTION_ACCESSOR, l.Q.ID)
}

// String implements [github.com/consensys/linea-monorepo/prover/symbolic.Metadata]
func (l *FromDistributedProjectionAccessor) String() string {
return l.Name()
}

// GetVal implements [ifaces.Accessor]
func (l *FromDistributedProjectionAccessor) GetVal(run ifaces.Runtime) field.Element {
params := run.GetParams(l.Q.ID).(query.DistributedProjectionParams)
return params.ScaledHorner
}

func (l *FromDistributedProjectionAccessor) GetValCumSumCurr(run ifaces.Runtime) field.Element {
params := run.GetParams(l.Q.ID).(query.DistributedProjectionParams)
return params.HashCumSumOneCurr
}

func (l *FromDistributedProjectionAccessor) GetValCumSumPrev(run ifaces.Runtime) field.Element {
params := run.GetParams(l.Q.ID).(query.DistributedProjectionParams)
return params.HashCumSumOnePrev
}

// GetFrontendVariable implements [ifaces.Accessor]
func (l *FromDistributedProjectionAccessor) GetFrontendVariable(_ frontend.API, circ ifaces.GnarkRuntime) frontend.Variable {
params := circ.GetParams(l.Q.ID).(query.GnarkDistributedProjectionParams)
return params.Sum
}

// AsVariable implements the [ifaces.Accessor] interface
func (l *FromDistributedProjectionAccessor) AsVariable() *symbolic.Expression {
return symbolic.NewVariable(l)
}

// Round implements the [ifaces.Accessor] interface
func (l *FromDistributedProjectionAccessor) Round() int {
return l.Q.Round
}
68 changes: 68 additions & 0 deletions prover/protocol/compiler/distributedprojection/compiler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package distributedprojection

import (
"math/big"

"github.com/consensys/linea-monorepo/prover/maths/field"
"github.com/consensys/linea-monorepo/prover/protocol/coin"
"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/symbolic"
)

func CompileDistributedProjection(comp *wizard.CompiledIOP) {

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

// This ensures that the distributed 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.
round := comp.QueriesParams.Round(qName)
compile(comp, round, distributedprojection)
}
}

func compile(comp *wizard.CompiledIOP, round int, distributedprojection query.DistributedProjection) {
var (
pa = &distribuedProjectionProverAction{
Name: distributedprojection.ID,
Query: distributedprojection,
FilterA: make([]*symbolic.Expression, len(distributedprojection.Inp)),
FilterB: make([]*symbolic.Expression, len(distributedprojection.Inp)),
ColumnA: make([]*symbolic.Expression, len(distributedprojection.Inp)),
ColumnB: make([]*symbolic.Expression, len(distributedprojection.Inp)),
HornerA: make([]ifaces.Column, len(distributedprojection.Inp)),
HornerB: make([]ifaces.Column, len(distributedprojection.Inp)),
HornerA0: make([]query.LocalOpening, len(distributedprojection.Inp)),
HornerB0: make([]query.LocalOpening, len(distributedprojection.Inp)),
EvalCoins: make([]coin.Info, len(distributedprojection.Inp)),
IsA: make([]bool, len(distributedprojection.Inp)),
IsB: make([]bool, len(distributedprojection.Inp)),
}
)
pa.Push(comp, distributedprojection)
pa.RegisterQueries(comp, round, distributedprojection)
comp.RegisterProverAction(round, pa)
comp.RegisterVerifierAction(round, &distributedProjectionVerifierAction{
Name: pa.Name,
Query: pa.Query,
HornerA0: pa.HornerA0,
HornerB0: pa.HornerB0,
IsA: pa.IsA,
IsB: pa.IsB,
EvalCoins: pa.EvalCoins,
FilterA: pa.FilterA,
FilterB: pa.FilterB,
CumNumOnesPrevSegmentsA: make([]big.Int, len(distributedprojection.Inp)),
CumNumOnesPrevSegmentsB: make([]big.Int, len(distributedprojection.Inp)),
NumOnesCurrSegmentA: make([]field.Element, len(distributedprojection.Inp)),
NumOnesCurrSegmentB: make([]field.Element, len(distributedprojection.Inp)),
})

}
Loading

0 comments on commit 4f51ada

Please sign in to comment.