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/Adding Initial Compiler for Permutation Query #386

Draft
wants to merge 8 commits into
base: prover/limitless-top-level
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 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: 2 additions & 2 deletions prover/protocol/compiler/permutation/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ func dispatchPermutation(
var (
isMultiColumn = len(q.A[0]) > 1
alpha coin.Info
beta = comp.InsertCoin(round+1, deriveName[coin.Name](q, "BETA"), coin.Field)
beta = comp.InsertCoin(round+1, DeriveName[coin.Name](q, "BETA"), coin.Field)
)

if isMultiColumn {
alpha = comp.InsertCoin(round+1, deriveName[coin.Name](q, "ALPHA"), coin.Field)
alpha = comp.InsertCoin(round+1, DeriveName[coin.Name](q, "ALPHA"), coin.Field)
}

for k, aOrB := range [2][][]ifaces.Column{q.A, q.B} {
Expand Down
4 changes: 2 additions & 2 deletions prover/protocol/compiler/permutation/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

const permutationStr = "PERMUTATION"

// deriveName constructs a name for the permutation context
func deriveName[R ~string](q query.Permutation, ss ...any) R {
// DeriveName constructs a name for the permutation context
func DeriveName[R ~string](q query.Permutation, ss ...any) R {
ss = append([]any{permutationStr, q}, ss...)
return wizardutils.DeriveName[R](ss...)
}
Expand Down
7 changes: 7 additions & 0 deletions prover/protocol/distributed/compiler/global/global.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package global

import "github.com/consensys/linea-monorepo/prover/protocol/wizard"

func IntoDistributedGlobal(comp *wizard.CompiledIOP) {
panic("unimplemented")
}
7 changes: 7 additions & 0 deletions prover/protocol/distributed/compiler/inclusion/inclusion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package inclusion

import "github.com/consensys/linea-monorepo/prover/protocol/wizard"

func IntoLogDerivativeSum(comp *wizard.CompiledIOP) {
panic("unimplemented")
}
7 changes: 7 additions & 0 deletions prover/protocol/distributed/compiler/local/local.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package local

import "github.com/consensys/linea-monorepo/prover/protocol/wizard"

func IntoDistributedLocal(comp *wizard.CompiledIOP) {
panic("unimplemented")
}
50 changes: 50 additions & 0 deletions prover/protocol/distributed/compiler/permutation/permutation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package permutation

import (
"github.com/consensys/linea-monorepo/prover/protocol/coin"
"github.com/consensys/linea-monorepo/prover/protocol/compiler/permutation"
"github.com/consensys/linea-monorepo/prover/protocol/query"
"github.com/consensys/linea-monorepo/prover/protocol/wizard"
)

func IntoGrandProduct(comp *wizard.CompiledIOP) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes considering that we will skip the preparation phase:

AddGdProductQuery(initialComp, moduleComp, disc, targetModuleName)

numRounds := comp.NumRounds()

/*
Handles the lookups and permutations checks
*/
for i := 0; i < numRounds; i++ {
queries := comp.QueriesNoParams.AllKeysAt(i)
for _, qName := range queries {
// Skip if it was already compiled
if comp.QueriesNoParams.IsIgnored(qName) {
continue
}

switch q_ := comp.QueriesNoParams.Data(qName).(type) {
case query.Permutation:
reducePermutationIntoGrandProduct(comp, q_, i)
}
}
}
}
// The below function does the following:
// 1. Register beta and alpha (for the random linear combination in case A and B are multi-columns)
// 2. Tell the prover that they are not needed to be sampled as they are to be fetched from the randomness beacon
func reducePermutationIntoGrandProduct(comp *wizard.CompiledIOP, q query.Permutation, round int) {
var (
isMultiColumn = len(q.A[0]) > 1
alpha coin.Info
// beta has to be different for different for different queries for the soundness of z-packing
beta = comp.InsertCoin(round+1, permutation.DeriveName[coin.Name](q, "BETA"), coin.Field)
)

if isMultiColumn {
alpha = comp.InsertCoin(round+1, permutation.DeriveName[coin.Name](q, "ALPHA"), coin.Field)
}

// Reduce a permutation query into a GrandProduct query
comp.InsertGrandProduct(round, q.Name(), alpha, beta)
arijitdutta67 marked this conversation as resolved.
Show resolved Hide resolved


}
7 changes: 7 additions & 0 deletions prover/protocol/distributed/compiler/projection/projection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package projection

import "github.com/consensys/linea-monorepo/prover/protocol/wizard"

func IntoGrandSum(comp *wizard.CompiledIOP) {
panic("unimplemented")
}
98 changes: 98 additions & 0 deletions prover/protocol/distributed/distributed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package distributed

import (
"github.com/consensys/linea-monorepo/prover/maths/field"
"github.com/consensys/linea-monorepo/prover/protocol/compiler/mimc"
"github.com/consensys/linea-monorepo/prover/protocol/compiler/specialqueries"
"github.com/consensys/linea-monorepo/prover/protocol/distributed/compiler/global"
"github.com/consensys/linea-monorepo/prover/protocol/distributed/compiler/inclusion"
"github.com/consensys/linea-monorepo/prover/protocol/distributed/compiler/local"
"github.com/consensys/linea-monorepo/prover/protocol/distributed/compiler/permutation"
"github.com/consensys/linea-monorepo/prover/protocol/distributed/compiler/projection"
"github.com/consensys/linea-monorepo/prover/protocol/ifaces"
"github.com/consensys/linea-monorepo/prover/protocol/wizard"
)

type moduleName = string

type DistributedWizard struct {
Bootstrapper *wizard.CompiledIOP
DistributedModules []DistributedModule
Aggregator *wizard.CompiledIOP
}

// DistributedModule implements the utilities relevant to a single segment.
type DistributedModule struct {
LookupPermProj *wizard.CompiledIOP
GlobalLocal *wizard.CompiledIOP
VK [2]field.Element
}

type ModuleDiscoverer interface {
// Analyze is responsible for letting the module discoverer compute how to
// group best the columns into modules.
Analyze(comp *wizard.CompiledIOP)
NbModules() int
ModuleList(comp *wizard.CompiledIOP) []string
arijitdutta67 marked this conversation as resolved.
Show resolved Hide resolved
FindModule(col ifaces.Column) moduleName
}

// This transforms the initial wizard. So it is not really the initial
// wizard anymore. That means the caller can forget about "initialWizard"
// after calling the function.
// maxNbSegment is a large max for the number of segments in a module.
func Distribute(initialWizard *wizard.CompiledIOP, disc ModuleDiscoverer, maxNbSegments int) DistributedWizard {

// prepare the initialWizard for the distribution. e.g.,
// adding auxiliary columns or dividing a lookup query to two queries one over T and the other over S.
prepare(initialWizard)
// it updates the map of Modules-Columns (that is a field of initialWizard).
disc.Analyze(initialWizard)

moduleLs := disc.ModuleList(initialWizard)
distModules := []DistributedModule{}

for _, modName := range moduleLs {
// Segment Compilation;
// Compile every dist module with the same sequence of compilation steps for uniformity
distMod := extractDistModule(initialWizard, disc, modName)
distModules = append(distModules, distMod)
}

// for each [DistributedModule] it checks the consistency among
// its replications where the number of replications is maxNbSegments.
aggr := aggregator(maxNbSegments, distModules, moduleLs)

return DistributedWizard{
Bootstrapper: initialWizard,
DistributedModules: distModules,
Aggregator: aggr,
}
}

// It adds the compilation steps
func prepare(comp *wizard.CompiledIOP) {

mimc.CompileMiMC(comp)
specialqueries.RangeProof(comp)
specialqueries.CompileFixedPermutations(comp)

inclusion.IntoLogDerivativeSum(comp)
permutation.IntoGrandProduct(comp)
projection.IntoGrandSum(comp)
local.IntoDistributedLocal(comp)
global.IntoDistributedGlobal(comp)
}

func addSplittingStep(comp *wizard.CompiledIOP, disc ModuleDiscoverer) {
panic("unimplemented")
}

func extractDistModule(comp *wizard.CompiledIOP, disc ModuleDiscoverer, moduleName moduleName) DistributedModule {
panic("unimplemented")
}


func aggregator(n int, idsModules []DistributedModule, moduleNames []string) *wizard.CompiledIOP {
panic("unimplemented")
}
5 changes: 5 additions & 0 deletions prover/protocol/wizard/compiled.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,3 +629,8 @@ func (c *CompiledIOP) RegisterVerifierAction(round int, action VerifierAction) {
// switch.
c.InsertVerifier(round, action.Run, action.RunGnark)
}

// Register a GrandProduct query for the sub-provers
func (c *CompiledIOP) InsertGrandProduct(round int, name ifaces.QueryID, alpha, beta coin.Info) {
panic("Unimplemented")
}
Loading