From 52bc229f350f180f79e8792dec07a85636562841 Mon Sep 17 00:00:00 2001 From: arijitdutta67 Date: Thu, 9 Jan 2025 17:00:49 +0530 Subject: [PATCH 1/5] adding size and zCatalog in the query --- prover/protocol/query/grand_product.go | 92 +++++++++++++-------- prover/protocol/query/grand_product_test.go | 11 ++- prover/protocol/wizard/compiled.go | 4 +- 3 files changed, 68 insertions(+), 39 deletions(-) diff --git a/prover/protocol/query/grand_product.go b/prover/protocol/query/grand_product.go index 9ad6e885c66..d10f30f2c14 100644 --- a/prover/protocol/query/grand_product.go +++ b/prover/protocol/query/grand_product.go @@ -5,6 +5,7 @@ import ( "github.com/consensys/gnark/frontend" "github.com/consensys/linea-monorepo/prover/crypto/fiatshamir" + "github.com/consensys/linea-monorepo/prover/maths/common/vector" "github.com/consensys/linea-monorepo/prover/maths/field" "github.com/consensys/linea-monorepo/prover/protocol/column" "github.com/consensys/linea-monorepo/prover/protocol/ifaces" @@ -15,11 +16,15 @@ import ( // The GrandProduct query is obtained by process all the permuation queries specific to a target module. // We store the randomised symbolic products of A and B of permuation queries combinedly // into the Numerators and the Denominators of the GrandProduct query -type GrandProduct struct { - ID ifaces.QueryID +type GrandProductInput struct { + Round, Size int Numerators []*symbolic.Expression // stores A as multi-column Denominators []*symbolic.Expression // stores B as multi-column - Round int +} + +type GrandProduct struct { + ID ifaces.QueryID + Inputs map[[2]int]*GrandProductInput } type GrandProductParams struct { @@ -39,12 +44,26 @@ type GrandProductParams struct { // // Returns: // - A pointer to a new instance of GrandProduct. -func NewGrandProduct(round int, id ifaces.QueryID, numerators, denominators []*symbolic.Expression) *GrandProduct { +func NewGrandProduct(inp map[[2]int]*GrandProductInput, id ifaces.QueryID) *GrandProduct { + // check the length consistency + for key := range inp { + // To check if the below is required or not + // if len(inp[key].Numerators) != len(inp[key].Denominator) || len(inp[key].Numerator) == 0 { + // utils.Panic("Numerator and Denominator should have the same (non-zero) length, %v , %v", len(inp[key].Numerator), len(inp[key].Denominator)) + // } + for i := range inp[key].Numerators { + if err := inp[key].Numerators[i].Validate(); err != nil { + utils.Panic(" Numerator[%v] is not a valid expression", i) + } + if err := inp[key].Denominators[i].Validate(); err != nil { + utils.Panic(" Denominator[%v] is not a valid expression", i) + } + } + } + return &GrandProduct{ - ID: id, - Numerators: numerators, - Denominators: denominators, - Round: round, + Inputs: inp, + ID: id, } } @@ -73,36 +92,39 @@ func (gp GrandProductParams) UpdateFS(fs *fiatshamir.State) { // Returns: // - An error if the grand product query is not satisfied, or nil if it is satisfied. func (g *GrandProduct) Check(run ifaces.Runtime) error { - var ( - numNumerators = len(g.Numerators) - numDenominators = len(g.Denominators) - numProd = symbolic.NewConstant(1) - denProd = symbolic.NewConstant(1) - ) - - for i := 0; i < numNumerators; i++ { - numProd = symbolic.Mul(numProd, g.Numerators[i]) - } - for j := 0; j < numDenominators; j++ { - denProd = symbolic.Mul(denProd, g.Denominators[j]) - } params := run.GetParams(g.ID).(GrandProductParams) - numProdFrVec := column.EvalExprColumn(run, numProd.Board()).IntoRegVecSaveAlloc() - denProdFrVec := column.EvalExprColumn(run, denProd.Board()).IntoRegVecSaveAlloc() - numProdFr := numProdFrVec[0] - denProdFr := denProdFrVec[0] - if len(numProdFrVec) > 1 { - for i := 1; i < len(numProdFrVec); i++ { - numProdFr.Mul(&numProdFr, &numProdFrVec[i]) - } - } - if len(numProdFrVec) > 1 { - for j := 1; j < len(denProdFrVec); j++ { - denProdFr.Mul(&denProdFr, &denProdFrVec[j]) + actualProd := field.One() + for key := range g.Inputs { + for i, num := range g.Inputs[key].Numerators { + + var ( + numBoard = num.Board() + denBoard = g.Inputs[key].Denominators[i].Board() + numeratorMetadata = numBoard.ListVariableMetadata() + denominator = column.EvalExprColumn(run, denBoard).IntoRegVecSaveAlloc() + numerator []field.Element + packedZ = field.BatchInvert(denominator) + ) + + if len(numeratorMetadata) == 0 { + numerator = vector.Repeat(field.One(), g.Inputs[key].Size) + } + + if len(numeratorMetadata) > 0 { + numerator = column.EvalExprColumn(run, numBoard).IntoRegVecSaveAlloc() + } + + for k := range packedZ { + packedZ[k].Mul(&numerator[k], &packedZ[k]) + if k > 0 { + packedZ[k].Mul(&packedZ[k], &packedZ[k-1]) + } + } + actualProd.Mul(&actualProd, &packedZ[len(packedZ)-1]) } } - if numProdFr != *denProdFr.Mul(&denProdFr, ¶ms.Y) { - return fmt.Errorf("the grand product query %v is not satisfied, numProd = %v, denProd = %v, param.Y = %v", g.ID, numProdFr, denProdFr, params.Y) + if actualProd != params.Y { + return fmt.Errorf("the grand product query %v is not satisfied, actualProd = %v, param.Y = %v", g.ID, actualProd, params.Y) } return nil diff --git a/prover/protocol/query/grand_product_test.go b/prover/protocol/query/grand_product_test.go index adbfcb2a0dd..a186d2c8096 100644 --- a/prover/protocol/query/grand_product_test.go +++ b/prover/protocol/query/grand_product_test.go @@ -7,6 +7,7 @@ import ( "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" ) @@ -33,7 +34,13 @@ func TestGrandProduct(t *testing.T) { symbolic.Add(B0, symbolic.Mul(C0, alpha)), symbolic.Add(A0, symbolic.Mul(B0, alpha)), } - G = builder.CompiledIOP.InsertGrandProduct(0, "G", A, B) + key := [2]int{0, 0} + zCat1 := map[[2]int]*query.GrandProductInput{} + zCat1[key] = &query.GrandProductInput{ + Numerators: A, + Denominators: B, + } + G = builder.CompiledIOP.InsertGrandProduct(0, "GrandProductTest", zCat1) } prove := func(run *wizard.ProverRuntime) { @@ -41,7 +48,7 @@ func TestGrandProduct(t *testing.T) { run.AssignColumn("A0", smartvectors.ForTest(1, 2, 3, 4)) run.AssignColumn("B0", smartvectors.ForTest(1, 2, 3, 4)) run.AssignColumn("C0", smartvectors.ForTest(1, 2, 3, 4)) - runS.AssignGrandProduct("G", field.One()) + runS.AssignGrandProduct("GrandProductTest", field.One()) } var ( diff --git a/prover/protocol/wizard/compiled.go b/prover/protocol/wizard/compiled.go index 94e7fe9a4db..76e68f7d4f0 100644 --- a/prover/protocol/wizard/compiled.go +++ b/prover/protocol/wizard/compiled.go @@ -642,9 +642,9 @@ func (c *CompiledIOP) RegisterVerifierAction(round int, action VerifierAction) { } // Register a GrandProduct query -func (c *CompiledIOP) InsertGrandProduct(round int, id ifaces.QueryID, numerators, denominators []*symbolic.Expression) *query.GrandProduct { +func (c *CompiledIOP) InsertGrandProduct(round int, id ifaces.QueryID, in map[[2]int]*query.GrandProductInput) *query.GrandProduct { c.assertConsistentRound(round) - q := query.NewGrandProduct(round, id, numerators, denominators) + q := query.NewGrandProduct(in, id) // Finally registers the query c.QueriesParams.AddToRound(round, q.Name(), q) return q From 42ca06fa234852f444feb3f5065ebbb4db8b08fd Mon Sep 17 00:00:00 2001 From: AlexandreBelling Date: Thu, 9 Jan 2025 16:19:47 +0100 Subject: [PATCH 2/5] feat: polish the implementation --- .../compiler/permutation/permutation.go | 346 ++++++++++-------- .../compiler/permutation/permutation_test.go | 283 +++++++------- .../compiler/permutation/settings.go | 6 +- prover/protocol/query/grand_product.go | 13 +- prover/protocol/query/grand_product_test.go | 4 +- prover/protocol/wizard/builder.go | 6 + prover/protocol/wizard/compiled.go | 4 +- 7 files changed, 367 insertions(+), 295 deletions(-) diff --git a/prover/protocol/distributed/compiler/permutation/permutation.go b/prover/protocol/distributed/compiler/permutation/permutation.go index 7e822489db9..70e6ef85605 100644 --- a/prover/protocol/distributed/compiler/permutation/permutation.go +++ b/prover/protocol/distributed/compiler/permutation/permutation.go @@ -4,7 +4,7 @@ import ( "github.com/consensys/linea-monorepo/prover/maths/field" "github.com/consensys/linea-monorepo/prover/protocol/coin" "github.com/consensys/linea-monorepo/prover/protocol/column" - modulediscoverer "github.com/consensys/linea-monorepo/prover/protocol/distributed/module_discoverer" + "github.com/consensys/linea-monorepo/prover/protocol/distributed" "github.com/consensys/linea-monorepo/prover/protocol/ifaces" "github.com/consensys/linea-monorepo/prover/protocol/query" "github.com/consensys/linea-monorepo/prover/protocol/wizard" @@ -15,95 +15,97 @@ import ( // Used for deriving names of queries and coins const grandProductStr = "GRAND_PRODUCT" -/* -The below function aims to process all the permutation queries specific to a target module -into a grand product query. We store the randomised symbolic products of A and B of permuation -queries combinedly into the Numerators and the Denominators of the GrandProduct query -*/ +// PermutationIntoGrandProductCtx is a compilation context object storing artefacts +// specific to a target module when compiling the [query.Permutation] into a +// [query.GrandProduct]. We store the randomised symbolic products of A and B of +// permutation queries combinedly into the Numerators and the Denominators of the +// GrandProduct query. type PermutationIntoGrandProductCtx struct { - // stores the expressions Ai + \beta_i for the ith permutation query, Ai is a linear combination with alpha_i - // in case of multi-column - Numerators []*symbolic.Expression - // stores the expressions Bi + \beta_i for the ith permutation query, Bi is a linear combination with alpha_i - // in case of multi-column - Denominators []*symbolic.Expression - // stores the field element obtained by collapsing the expression - // \prod(Numerators)/\prod(Denominators) - ParamY field.Element - // The query id specific to the target module - QueryId ifaces.QueryID + // GdProdInputs collect all the inputs of the permutation queries from the target + // module that are used as input of the [GrandProduct] query. The term stored + // are of the form $Ai + \beta_i$ or $Bi + \beta_i$. + GdProdInputs map[int]*query.GrandProductInput // The module name for which we are processing the grand product query TargetModuleName string + // Query stores the [query.GrandProduct] generated by the compilation + Query *query.GrandProduct + // LastRoundPerm indicates the highest round at which a compiled permutation + // occurs. + LastRoundPerm int } -// Returns a new PermutationIntoGrandProductCtx -func NewPermutationIntoGrandProductCtx(s Settings) *PermutationIntoGrandProductCtx { - permCtx := PermutationIntoGrandProductCtx{} - permCtx.Numerators = make([]*symbolic.Expression, 0, s.MaxNumOfQueryPerModule) - permCtx.Denominators = make([]*symbolic.Expression, 0, s.MaxNumOfQueryPerModule) - return &permCtx -} - -// AddGdProductQuery processes all permutation queries specific to a target module -// into a grand product query. It stores the randomised symbolic products of A and B -// of permutation queries combinedly into the Numerators and the Denominators of the -// GrandProduct query. +// NewPermutationIntoGrandProductCtx processes all permutation queries specific to a +// target module into a grand product query. It stores the randomised symbolic products +// of A and B of permutation queries combinedly into the Numerators and the Denominators +// of the GrandProduct query. // // Parameters: -// - initialComp: The initial compiledIOP -// - moduleComp: The compiledIOP for the target module -// - targetModuleName: The name of the module for which we are processing the grand product query -// - run: The prover runtime +// - s: The compilation settings +// - initialComp: The initial compiledIOP +// - moduleComp: The compiledIOP for the target module +// - disc: The [distributed.ModuleDiscoverer] object used to detect the queries belonging +// to the current module. // // Returns: -// - An instance of the grand product query (ifaces.Query) -func (p *PermutationIntoGrandProductCtx) AddGdProductQuery(initialComp, moduleComp *wizard.CompiledIOP, - targetModuleName modulediscoverer.ModuleName, run *wizard.ProverRuntime) ifaces.Query { - numRounds := initialComp.NumRounds() - // Initialise the period separating module discoverer - disc := modulediscoverer.PeriodSeperatingModuleDiscoverer{} - disc.Analyze(initialComp) - qId := deriveName[ifaces.QueryID](ifaces.QueryID(targetModuleName)) - p.QueryId = qId - p.TargetModuleName = string(targetModuleName) +// - The function returns a [PermutationIntoGrandProductCtx] collecting all the compilation +// artefacts. +func NewPermutationIntoGrandProductCtx( + s Settings, + initialComp, moduleComp *wizard.CompiledIOP, + disc distributed.ModuleDiscoverer, +) *PermutationIntoGrandProductCtx { + + var ( + p = &PermutationIntoGrandProductCtx{ + GdProdInputs: make(map[int]*query.GrandProductInput), + TargetModuleName: s.TargetModuleName, + LastRoundPerm: getLastRoundPerm(initialComp), + } + numRounds = initialComp.NumRounds() + qId = p.QueryID() + targetModuleName = p.TargetModuleName + ) + + if p.LastRoundPerm < 0 { + return p + } + /* Handles the lookups and permutations checks */ - for i := 0; i < numRounds; i++ { - queries := initialComp.QueriesNoParams.AllKeysAt(i) - for j, qName := range queries { + for round := 0; round < numRounds; round++ { + queries := initialComp.QueriesNoParams.AllKeysAt(round) + for queryInRound, qName := range queries { // Skip if it was already compiled if initialComp.QueriesNoParams.IsIgnored(qName) { continue } - switch q_ := initialComp.QueriesNoParams.Data(qName).(type) { - case query.Permutation: - { - moduleNameA := disc.FindModule(q_.A[0][0]) - moduleNameB := disc.FindModule(q_.B[0][0]) - if moduleNameA == targetModuleName && moduleNameB != targetModuleName { - p.push(moduleComp, &q_, i, j, true, false) - } else if moduleNameA != targetModuleName && moduleNameB == targetModuleName { - p.push(moduleComp, &q_, i, j, false, false) - } else if moduleNameA == targetModuleName && moduleNameB == targetModuleName { - p.push(moduleComp, &q_, i, j, true, true) - } else { - continue - } - } - default: + q_, ok := initialComp.QueriesNoParams.Data(qName).(query.Permutation) + if !ok { continue } + + for k := range q_.A { + if disc.FindModule(q_.A[k][0]) == targetModuleName { + p.push(moduleComp, q_.A[k], round, queryInRound, true) + } + } + + for k := range q_.B { + if disc.FindModule(q_.B[k][0]) == targetModuleName { + p.push(moduleComp, q_.B[k], round, queryInRound, false) + } + } } } // We register the grand product query in round one because // alphas, betas, and the query param are assigned in round one - G := moduleComp.InsertGrandProduct(1, qId, p.Numerators, p.Denominators) - // The below prover action is responsible for computing the query parameter - // and assign it in round one - moduleComp.RegisterProverAction(1, p.AssignParam(run, qId)) - return G + p.Query = moduleComp.InsertGrandProduct(p.LastRoundPerm+1, qId, p.GdProdInputs) + + moduleComp.RegisterProverAction(p.LastRoundPerm+1, p) + + return p } // push processes a permutation query and adds its symbolic factors to the Numerators or Denominators @@ -111,39 +113,54 @@ func (p *PermutationIntoGrandProductCtx) AddGdProductQuery(initialComp, moduleCo // // Parameters: // - comp: The compiled IOP for the target module -// - q: The permutation query to be processed +// - aOrB: The side of permutation query to be processed // - round: The round number of the permutation query // - queryInRound: The index of the permutation query within the round // - isNumerator: A flag indicating whether to add the symbolic factor to the Numerators -// - isBoth: A flag indicating whether we need to add the symbolic factor to both Numerators and Denominators -func (p *PermutationIntoGrandProductCtx) push(comp *wizard.CompiledIOP, q *query.Permutation, round, queryInRound int, isNumerator, isBoth bool) { +func (p *PermutationIntoGrandProductCtx) push(comp *wizard.CompiledIOP, aOrb []ifaces.Column, round, queryInRound int, isNumerator bool) { + var ( - isMultiColumn = len(q.A[0]) > 1 + isMultiColumn = len(aOrb) > 1 + alphaName = getCoinName("ALPHA", round, queryInRound) + betaName = getCoinName("BETA", round, queryInRound) alpha coin.Info beta coin.Info ) + if isMultiColumn { - // alpha has to be different for different queries for a particular round for the soundness of z-packing - alpha = comp.InsertCoin(1, deriveName[coin.Name](ifaces.QueryID(p.TargetModuleName), "ALPHA", round, queryInRound), coin.Field) + if comp.Coins.Exists(alphaName) { + alpha = comp.Coins.Data(alphaName) + } else { + // alpha has to be different for different queries for a particular round for the soundness of z-packing + alpha = comp.InsertCoin(p.LastRoundPerm+1, alphaName, coin.Field) + } } + // beta has to be different for different queries for a particular round for the soundness of z-packing - beta = comp.InsertCoin(1, deriveName[coin.Name](ifaces.QueryID(p.TargetModuleName), "BETA", round, queryInRound), coin.Field) - if isNumerator && !isBoth { - // Take only the numerator - factor := computeFactor(q.A, isMultiColumn, &alpha, &beta) - p.Numerators = append(p.Numerators, factor) - } else if !isNumerator && !isBoth { - // Take only the denominator - factor := computeFactor(q.B, isMultiColumn, &alpha, &beta) - p.Denominators = append(p.Denominators, factor) - } else if isNumerator && isBoth { - // Take both the numerator and the denominator - numFactor := computeFactor(q.A, isMultiColumn, &alpha, &beta) - denFactor := computeFactor(q.B, isMultiColumn, &alpha, &beta) - p.Numerators = append(p.Numerators, numFactor) - p.Denominators = append(p.Denominators, denFactor) - } else if !isNumerator && isBoth { - panic("Invalid case") + if comp.Coins.Exists(betaName) { + beta = comp.Coins.Data(betaName) + } else { + beta = comp.InsertCoin(p.LastRoundPerm+1, betaName, coin.Field) + } + + var ( + factor = computeFactor(aOrb, alpha, beta) + size = aOrb[0].Size() + ) + + ce, ok := p.GdProdInputs[size] + if !ok { + ce = &query.GrandProductInput{ + Size: size, + } + + p.GdProdInputs[size] = ce + } + + if isNumerator { + ce.Numerators = append(ce.Numerators, factor) + } else { + ce.Denominators = append(ce.Denominators, factor) } } @@ -160,26 +177,14 @@ func (p *PermutationIntoGrandProductCtx) push(comp *wizard.CompiledIOP, q *query // // Returns: // - A pointer to a symbolic.Expression representing the computed factor for the permutation query. -func computeFactor(aOrB [][]ifaces.Column, isMultiColumn bool, alpha, beta *coin.Info) *symbolic.Expression { - var ( - numFrag = len(aOrB) - factor = symbolic.NewConstant(1) - fragFactor *symbolic.Expression - ) - - for frag := range numFrag { - if isMultiColumn { - fragFactor = wizardutils.RandLinCombColSymbolic(*alpha, aOrB[frag]) - } else { - fragFactor = ifaces.ColumnAsVariable(aOrB[frag][0]) - } - fragFactor = symbolic.Add(fragFactor, *beta) - factor = symbolic.Mul(factor, fragFactor) +func computeFactor(aOrB []ifaces.Column, alpha, beta coin.Info) *symbolic.Expression { + if len(aOrB) > 1 { + return symbolic.Add(beta, wizardutils.RandLinCombColSymbolic(alpha, aOrB)) } - return factor + return symbolic.Add(beta, aOrB[0]) } -// AssignParam computes the query parameter for the grand product query and assigns it in round one. +// computeQueryParam computes the query parameter for the grand product query and assigns it in round one. // It multiplies the products of the Numerators and Denominators, evaluates the resulting symbolic expressions, // and assigns the result to the field element ParamY. // @@ -189,44 +194,58 @@ func computeFactor(aOrB [][]ifaces.Column, isMultiColumn bool, alpha, beta *coin // // Returns: // - A pointer to the PermutationIntoGrandProductCtx instance with the updated ParamY field. -func (p *PermutationIntoGrandProductCtx) AssignParam(run *wizard.ProverRuntime, name ifaces.QueryID) *PermutationIntoGrandProductCtx { - var ( - numNumerators = len(p.Numerators) - numDenominators = len(p.Denominators) - numProd = symbolic.NewConstant(1) - denProd = symbolic.NewConstant(1) - ) - // Multiply all Numerators - for i := 0; i < numNumerators; i++ { - numProd = symbolic.Mul(numProd, p.Numerators[i]) - } - // Multiply all Denominators - for j := 0; j < numDenominators; j++ { - denProd = symbolic.Mul(denProd, p.Denominators[j]) - } - // Evaluate the symbolic expressions for Numerator and Denominator products - numProdFrVec := column.EvalExprColumn(run, numProd.Board()).IntoRegVecSaveAlloc() - denProdFrVec := column.EvalExprColumn(run, denProd.Board()).IntoRegVecSaveAlloc() - numProdFr := numProdFrVec[0] - denProdFr := denProdFrVec[0] - // Multiply all field elements in the Numerator product vector - if len(numProdFrVec) > 1 { - for i := 1; i < len(numProdFrVec); i++ { - numProdFr.Mul(&numProdFr, &numProdFrVec[i]) +func (p *PermutationIntoGrandProductCtx) computeQueryParam(run *wizard.ProverRuntime) field.Element { + + var y field.Element + + for _, ce := range p.GdProdInputs { + + var ( + numNumerators = len(ce.Numerators) + numDenominators = len(ce.Denominators) + numProd = symbolic.NewConstant(1) + denProd = symbolic.NewConstant(1) + ) + + // Multiply all Numerators + for i := 0; i < numNumerators; i++ { + numProd = symbolic.Mul(numProd, ce.Numerators[i]) } - } - // Multiply all field elements in the Denominator product vector - if len(denProdFrVec) > 1 { - for j := 1; j < len(denProdFrVec); j++ { - denProdFr.Mul(&denProdFr, &denProdFrVec[j]) + // Multiply all Denominators + for j := 0; j < numDenominators; j++ { + denProd = symbolic.Mul(denProd, ce.Denominators[j]) + } + + // Evaluate the symbolic expressions for Numerator and Denominator products + var ( + numProdFrVec = column.EvalExprColumn(run, numProd.Board()).IntoRegVecSaveAlloc() + denProdFrVec = column.EvalExprColumn(run, denProd.Board()).IntoRegVecSaveAlloc() + numProdFr = numProdFrVec[0] + denProdFr = denProdFrVec[0] + ) + + // Multiply all field elements in the Numerator product vector + if len(numProdFrVec) > 1 { + for i := 1; i < len(numProdFrVec); i++ { + numProdFr.Mul(&numProdFr, &numProdFrVec[i]) + } + } + // Multiply all field elements in the Denominator product vector + if len(denProdFrVec) > 1 { + for j := 1; j < len(denProdFrVec); j++ { + denProdFr.Mul(&denProdFr, &denProdFrVec[j]) + } } + + // Invert the Denominator product field element + denProdFr.Inverse(&denProdFr) + + // Compute the final query parameter Y + numProdFr.Mul(&numProdFr, &denProdFr) + y.Mul(&y, &numProdFr) } - // Invert the Denominator product field element - denProdFr.Inverse(&denProdFr) - // Compute the final query parameter Y - Y := numProdFr.Mul(&numProdFr, &denProdFr) - p.ParamY = *Y - return p + + return y } // Run executes the grand product query by assigning the computed parameter Y to the prover runtime. @@ -237,7 +256,7 @@ func (p *PermutationIntoGrandProductCtx) AssignParam(run *wizard.ProverRuntime, // The function does not return any value. It directly assigns the computed parameter Y to the prover runtime // using the AssignGrandProduct method of the runtime. func (p *PermutationIntoGrandProductCtx) Run(run *wizard.ProverRuntime) { - run.AssignGrandProduct(p.QueryId, p.ParamY) + run.AssignGrandProduct(p.QueryID(), p.computeQueryParam(run)) } // deriveName constructs a name for the PermutationIntoGrandProduct context @@ -245,3 +264,44 @@ func deriveName[R ~string](q ifaces.QueryID, ss ...any) R { ss = append([]any{grandProductStr, q}, ss...) return wizardutils.DeriveName[R](ss...) } + +// QueryID formats and returns a name of the [query.GrandProduct] generated by the current context +func (p *PermutationIntoGrandProductCtx) QueryID() ifaces.QueryID { + return deriveName[ifaces.QueryID](ifaces.QueryID(p.TargetModuleName)) +} + +// getCoinName returns a pre-formatted for the coins \alpha and \beta that are used +// to construct the GrandProduct operands. The function takes a string (expectedly either +// "ALPHA" or "BETA") and two integers identifying the query. +func getCoinName(name string, round, queryInRound int) coin.Name { + return deriveName[coin.Name](grandProductStr, name, round, queryInRound) +} + +// getLastRoundPerm scans the initialComp and looks for uncompiled permutation queries. It returns +// the highest round found for a matched permutation query. It returns -1 if no queries are found. +func getLastRoundPerm(initialComp *wizard.CompiledIOP) int { + + var ( + lastRound = -1 + numRounds = initialComp.NumRounds() + ) + + for round := 0; round < numRounds; round++ { + queries := initialComp.QueriesNoParams.AllKeysAt(round) + for _, qName := range queries { + + if initialComp.QueriesNoParams.IsIgnored(qName) { + continue + } + + _, ok := initialComp.QueriesNoParams.Data(qName).(query.Permutation) + if !ok { + continue + } + + lastRound = max(lastRound, round) + } + } + + return lastRound +} diff --git a/prover/protocol/distributed/compiler/permutation/permutation_test.go b/prover/protocol/distributed/compiler/permutation/permutation_test.go index 74a23932b7d..3eebeec95af 100644 --- a/prover/protocol/distributed/compiler/permutation/permutation_test.go +++ b/prover/protocol/distributed/compiler/permutation/permutation_test.go @@ -4,168 +4,167 @@ import ( "testing" "github.com/consensys/linea-monorepo/prover/maths/common/smartvectors" + "github.com/consensys/linea-monorepo/prover/protocol/compiler/dummy" dist_permutation "github.com/consensys/linea-monorepo/prover/protocol/distributed/compiler/permutation" + modulediscoverer "github.com/consensys/linea-monorepo/prover/protocol/distributed/module_discoverer" "github.com/consensys/linea-monorepo/prover/protocol/ifaces" "github.com/consensys/linea-monorepo/prover/protocol/wizard" ) -func TestDistPermutationNoMultiColumnNoFragment(t *testing.T) { +func TestPermutationAlex(t *testing.T) { + var ( - runS *wizard.ProverRuntime - G ifaces.Query - permCtx *dist_permutation.PermutationIntoGrandProductCtx + moduleAName = "MODULE_A" + // Initialise the period separating module discoverer + disc = modulediscoverer.PeriodSeperatingModuleDiscoverer{} ) - permCtx = dist_permutation.NewPermutationIntoGrandProductCtx(dist_permutation.Settings{MaxNumOfQueryPerModule: 4}) - initialDefine := func(builder *wizard.Builder) { - A := []ifaces.Column{ - builder.RegisterCommit("MODULE_A.A0", 4), - } - B := []ifaces.Column{ - builder.RegisterCommit("MODULE_B.B0", 4), - } - C := []ifaces.Column{ - builder.RegisterCommit("MODULE_C.C0", 4), - } - _ = builder.CompiledIOP.InsertPermutation(0, "P_MOD_A_MOD_B", A, B) - _ = builder.CompiledIOP.InsertPermutation(0, "P_MOD_C_MOD_A", C, A) - _ = builder.CompiledIOP.InsertPermutation(0, "P_MOD_B_MOD_C", B, C) - } - moduleADefine := func(builder *wizard.Builder) { - builder.RegisterCommit("MODULE_A.A0", 4) + testcases := []struct { + Name string + DefineFunc func(builder *wizard.Builder) + }{ + { + Name: "single-column-no-fragment", + DefineFunc: func(builder *wizard.Builder) { + a := []ifaces.Column{ + builder.RegisterCommit("MODULE_A.A0", 4), + } + b := []ifaces.Column{ + builder.RegisterCommit("MODULE_B.B0", 4), + } + c := []ifaces.Column{ + builder.RegisterCommit("MODULE_C.C0", 4), + } + _ = builder.CompiledIOP.InsertPermutation(0, "P_MOD_A_MOD_B", a, b) + _ = builder.CompiledIOP.InsertPermutation(0, "P_MOD_C_MOD_A", c, a) + _ = builder.CompiledIOP.InsertPermutation(0, "P_MOD_B_MOD_C", b, c) + }, + }, + { + Name: "multi-column-no-fragment", + DefineFunc: func(builder *wizard.Builder) { + a := []ifaces.Column{ + builder.RegisterCommit("MODULE_A.A0", 4), + builder.RegisterCommit("MODULE_A.A1", 4), + builder.RegisterCommit("MODULE_A.A2", 4), + } + b := []ifaces.Column{ + builder.RegisterCommit("MODULE_B.B0", 4), + builder.RegisterCommit("MODULE_B.B1", 4), + builder.RegisterCommit("MODULE_B.B2", 4), + } + c := []ifaces.Column{ + builder.RegisterCommit("MODULE_C.C0", 4), + builder.RegisterCommit("MODULE_C.C1", 4), + builder.RegisterCommit("MODULE_C.C2", 4), + } + _ = builder.CompiledIOP.InsertPermutation(0, "P_MOD_A_MOD_B", a, b) + _ = builder.CompiledIOP.InsertPermutation(0, "P_MOD_C_MOD_A", c, a) + _ = builder.CompiledIOP.InsertPermutation(0, "P_MOD_B_MOD_C", b, c) + }, + }, + { + Name: "multi-column-multi-fragment", + DefineFunc: func(builder *wizard.Builder) { + a := [][]ifaces.Column{ + { + builder.RegisterCommit("MODULE_A.A00", 4), + builder.RegisterCommit("MODULE_A.A10", 4), + builder.RegisterCommit("MODULE_A.A20", 4), + }, + { + builder.RegisterCommit("MODULE_A.A01", 4), + builder.RegisterCommit("MODULE_A.A11", 4), + builder.RegisterCommit("MODULE_A.A21", 4), + }, + } + b := [][]ifaces.Column{ + { + builder.RegisterCommit("MODULE_B.B00", 4), + builder.RegisterCommit("MODULE_B.B10", 4), + builder.RegisterCommit("MODULE_B.B20", 4), + }, + { + builder.RegisterCommit("MODULE_B.B01", 4), + builder.RegisterCommit("MODULE_B.B11", 4), + builder.RegisterCommit("MODULE_B.B21", 4), + }, + } + c := [][]ifaces.Column{ + { + builder.RegisterCommit("MODULE_C.C00", 4), + builder.RegisterCommit("MODULE_C.C10", 4), + builder.RegisterCommit("MODULE_C.C20", 4), + }, + { + builder.RegisterCommit("MODULE_C.C01", 4), + builder.RegisterCommit("MODULE_C.C11", 4), + builder.RegisterCommit("MODULE_C.C21", 4), + }, + } + _ = builder.CompiledIOP.InsertFragmentedPermutation(0, "P_MOD_A_MOD_B", a, b) + _ = builder.CompiledIOP.InsertFragmentedPermutation(0, "P_MOD_C_MOD_A", c, a) + _ = builder.CompiledIOP.InsertFragmentedPermutation(0, "P_MOD_B_MOD_C", b, c) + }, + }, } - initialComp := wizard.Compile(initialDefine) - moduleAComp := wizard.Compile(moduleADefine) + for _, tc := range testcases { - moduleAProve := func(run *wizard.ProverRuntime) { - runS = run - run.AssignColumn("MODULE_A.A0", smartvectors.ForTest(1, 2, 3, 4)) - G = permCtx.AddGdProductQuery(initialComp, moduleAComp, "MODULE_A", run) - } - _ = wizard.Prove(moduleAComp, moduleAProve) - errG := G.Check(runS) + t.Run(tc.Name, func(t *testing.T) { - if errG != nil { - t.Fatalf("error verifying the grand product: %v", errG.Error()) - } -} + initialComp := wizard.Compile(tc.DefineFunc) -func TestDistPermutationNoFragment(t *testing.T) { - var ( - runS *wizard.ProverRuntime - G ifaces.Query - permCtx *dist_permutation.PermutationIntoGrandProductCtx - ) - permCtx = dist_permutation.NewPermutationIntoGrandProductCtx(dist_permutation.Settings{MaxNumOfQueryPerModule: 4}) - initialDefine := func(builder *wizard.Builder) { - A := []ifaces.Column{ - builder.RegisterCommit("MODULE_A.A0", 4), - builder.RegisterCommit("MODULE_A.A1", 4), - builder.RegisterCommit("MODULE_A.A2", 4), - } - B := []ifaces.Column{ - builder.RegisterCommit("MODULE_B.B0", 4), - builder.RegisterCommit("MODULE_B.B1", 4), - builder.RegisterCommit("MODULE_B.B2", 4), - } - C := []ifaces.Column{ - builder.RegisterCommit("MODULE_C.C0", 4), - builder.RegisterCommit("MODULE_C.C1", 4), - builder.RegisterCommit("MODULE_C.C2", 4), - } - _ = builder.CompiledIOP.InsertPermutation(0, "P_MOD_A_MOD_B", A, B) - _ = builder.CompiledIOP.InsertPermutation(0, "P_MOD_C_MOD_A", C, A) - _ = builder.CompiledIOP.InsertPermutation(0, "P_MOD_B_MOD_C", B, C) - } + disc.Analyze(initialComp) - moduleADefine := func(builder *wizard.Builder) { - builder.RegisterCommit("MODULE_A.A0", 4) - builder.RegisterCommit("MODULE_A.A1", 4) - builder.RegisterCommit("MODULE_A.A2", 4) - } + moduleAComp := wizard.Compile(func(build *wizard.Builder) { - initialComp := wizard.Compile(initialDefine) - moduleAComp := wizard.Compile(moduleADefine) + for _, colName := range initialComp.Columns.AllKeys() { - moduleAProve := func(run *wizard.ProverRuntime) { - runS = run - run.AssignColumn("MODULE_A.A0", smartvectors.ForTest(1, 2, 3, 4)) - run.AssignColumn("MODULE_A.A1", smartvectors.ForTest(1, 2, 3, 4)) - run.AssignColumn("MODULE_A.A2", smartvectors.ForTest(1, 2, 3, 4)) - G = permCtx.AddGdProductQuery(initialComp, moduleAComp, "MODULE_A", run) - } - _ = wizard.Prove(moduleAComp, moduleAProve) - errG := G.Check(runS) + col := initialComp.Columns.GetHandle(colName) + if !disc.ColumnIsInModule(col, moduleAName) { + continue + } - if errG != nil { - t.Fatalf("error verifying the grand product: %v", errG.Error()) - } -} + build.RegisterCommit(col.GetColID(), col.Size()) + } + }, dummy.CompileAtProverLvl) -func TestDistPermutationFragment(t *testing.T) { - var ( - runS *wizard.ProverRuntime - G ifaces.Query - permCtx *dist_permutation.PermutationIntoGrandProductCtx - ) - permCtx = dist_permutation.NewPermutationIntoGrandProductCtx(dist_permutation.Settings{MaxNumOfQueryPerModule: 4}) - initialDefine := func(builder *wizard.Builder) { - A := [][]ifaces.Column{ - {builder.RegisterCommit("MODULE_A.A00", 4), - builder.RegisterCommit("MODULE_A.A10", 4), - builder.RegisterCommit("MODULE_A.A20", 4)}, - {builder.RegisterCommit("MODULE_A.A01", 4), - builder.RegisterCommit("MODULE_A.A11", 4), - builder.RegisterCommit("MODULE_A.A21", 4)}, - } - B := [][]ifaces.Column{ - {builder.RegisterCommit("MODULE_B.B00", 4), - builder.RegisterCommit("MODULE_B.B10", 4), - builder.RegisterCommit("MODULE_B.B20", 4)}, - {builder.RegisterCommit("MODULE_B.B01", 4), - builder.RegisterCommit("MODULE_B.B11", 4), - builder.RegisterCommit("MODULE_B.B21", 4)}, - } - C := [][]ifaces.Column{ - {builder.RegisterCommit("MODULE_C.C00", 4), - builder.RegisterCommit("MODULE_C.C10", 4), - builder.RegisterCommit("MODULE_C.C20", 4)}, - {builder.RegisterCommit("MODULE_C.C01", 4), - builder.RegisterCommit("MODULE_C.C11", 4), - builder.RegisterCommit("MODULE_C.C21", 4)}, - } - _ = builder.CompiledIOP.InsertFragmentedPermutation(0, "P_MOD_A_MOD_B", A, B) - _ = builder.CompiledIOP.InsertFragmentedPermutation(0, "P_MOD_C_MOD_A", C, A) - _ = builder.CompiledIOP.InsertFragmentedPermutation(0, "P_MOD_B_MOD_C", B, C) - } + var ( + _ = dist_permutation.NewPermutationIntoGrandProductCtx( + dist_permutation.Settings{TargetModuleName: moduleAName}, + initialComp, moduleAComp, &disc, + ) + initialRun *wizard.ProverRuntime + ) - moduleADefine := func(builder *wizard.Builder) { - builder.RegisterCommit("MODULE_A.A00", 4) - builder.RegisterCommit("MODULE_A.A10", 4) - builder.RegisterCommit("MODULE_A.A20", 4) - builder.RegisterCommit("MODULE_A.A01", 4) - builder.RegisterCommit("MODULE_A.A11", 4) - builder.RegisterCommit("MODULE_A.A21", 4) - } + initialProve := func(run *wizard.ProverRuntime) { + for _, colName := range run.Spec.Columns.AllKeys() { + run.AssignColumn(colName, smartvectors.ForTest(1, 2, 3, 4)) + } - initialComp := wizard.Compile(initialDefine) - moduleAComp := wizard.Compile(moduleADefine) - - moduleAProve := func(run *wizard.ProverRuntime) { - runS = run - run.AssignColumn("MODULE_A.A00", smartvectors.ForTest(1, 2, 3, 4)) - run.AssignColumn("MODULE_A.A10", smartvectors.ForTest(1, 2, 3, 4)) - run.AssignColumn("MODULE_A.A20", smartvectors.ForTest(1, 2, 3, 4)) - run.AssignColumn("MODULE_A.A01", smartvectors.ForTest(1, 2, 3, 4)) - run.AssignColumn("MODULE_A.A11", smartvectors.ForTest(1, 2, 3, 4)) - run.AssignColumn("MODULE_A.A21", smartvectors.ForTest(1, 2, 3, 4)) - G = permCtx.AddGdProductQuery(initialComp, moduleAComp, "MODULE_A", run) - } - _ = wizard.Prove(moduleAComp, moduleAProve) - errG := G.Check(runS) + initialRun = run + } + + _ = wizard.Prove(initialComp, initialProve) + + moduleAProve := func(run *wizard.ProverRuntime) { + for _, colName := range initialComp.Columns.AllKeys() { + + col := initialComp.Columns.GetHandle(colName) + if !disc.ColumnIsInModule(col, moduleAName) { + continue + } + + c := initialRun.GetColumn(colName) + run.AssignColumn(colName, c) + } + } + + _ = wizard.Prove(moduleAComp, moduleAProve) + + }) - if errG != nil { - t.Fatalf("error verifying the grand product: %v", errG.Error()) } + } diff --git a/prover/protocol/distributed/compiler/permutation/settings.go b/prover/protocol/distributed/compiler/permutation/settings.go index a19a6b3afb4..fad99e6dbf4 100644 --- a/prover/protocol/distributed/compiler/permutation/settings.go +++ b/prover/protocol/distributed/compiler/permutation/settings.go @@ -1,6 +1,8 @@ package dist_permutation +import modulediscoverer "github.com/consensys/linea-monorepo/prover/protocol/distributed/module_discoverer" + type Settings struct { - // Maximum number of permutation queries per module - MaxNumOfQueryPerModule int + // Name of the target module + TargetModuleName modulediscoverer.ModuleName } diff --git a/prover/protocol/query/grand_product.go b/prover/protocol/query/grand_product.go index d10f30f2c14..fcbcd1ad99b 100644 --- a/prover/protocol/query/grand_product.go +++ b/prover/protocol/query/grand_product.go @@ -17,14 +17,18 @@ import ( // We store the randomised symbolic products of A and B of permuation queries combinedly // into the Numerators and the Denominators of the GrandProduct query type GrandProductInput struct { - Round, Size int + Size int Numerators []*symbolic.Expression // stores A as multi-column Denominators []*symbolic.Expression // stores B as multi-column } +// GrandProduct is a query for computing the grand-product of several vector expressions. The +// query returns a unique field element result. type GrandProduct struct { - ID ifaces.QueryID - Inputs map[[2]int]*GrandProductInput + Round int + ID ifaces.QueryID + // The list of the inputs of the query, grouped by sizes + Inputs map[int]*GrandProductInput } type GrandProductParams struct { @@ -44,7 +48,7 @@ type GrandProductParams struct { // // Returns: // - A pointer to a new instance of GrandProduct. -func NewGrandProduct(inp map[[2]int]*GrandProductInput, id ifaces.QueryID) *GrandProduct { +func NewGrandProduct(round int, inp map[int]*GrandProductInput, id ifaces.QueryID) *GrandProduct { // check the length consistency for key := range inp { // To check if the below is required or not @@ -62,6 +66,7 @@ func NewGrandProduct(inp map[[2]int]*GrandProductInput, id ifaces.QueryID) *Gran } return &GrandProduct{ + Round: round, Inputs: inp, ID: id, } diff --git a/prover/protocol/query/grand_product_test.go b/prover/protocol/query/grand_product_test.go index a186d2c8096..2ed047fcb52 100644 --- a/prover/protocol/query/grand_product_test.go +++ b/prover/protocol/query/grand_product_test.go @@ -34,8 +34,8 @@ func TestGrandProduct(t *testing.T) { symbolic.Add(B0, symbolic.Mul(C0, alpha)), symbolic.Add(A0, symbolic.Mul(B0, alpha)), } - key := [2]int{0, 0} - zCat1 := map[[2]int]*query.GrandProductInput{} + key := 0 + zCat1 := map[int]*query.GrandProductInput{} zCat1[key] = &query.GrandProductInput{ Numerators: A, Denominators: B, diff --git a/prover/protocol/wizard/builder.go b/prover/protocol/wizard/builder.go index 9bab4cfb6ba..d85bcc5c067 100644 --- a/prover/protocol/wizard/builder.go +++ b/prover/protocol/wizard/builder.go @@ -69,6 +69,12 @@ func Compile(define DefineFunc, compilers ...func(*CompiledIOP)) *CompiledIOP { builder.equalizeRounds(numRounds) } + if comp.SubProvers.Len() < comp.NumRounds() { + utils.Panic("There are coin sampling rounds that are not followed by an action of the prover. numRoundProver=%v numRoundCoins=%v", + comp.SubProvers.Len(), comp.NumRounds(), + ) + } + return builder.CompiledIOP } diff --git a/prover/protocol/wizard/compiled.go b/prover/protocol/wizard/compiled.go index 76e68f7d4f0..8f762a6b953 100644 --- a/prover/protocol/wizard/compiled.go +++ b/prover/protocol/wizard/compiled.go @@ -642,9 +642,9 @@ func (c *CompiledIOP) RegisterVerifierAction(round int, action VerifierAction) { } // Register a GrandProduct query -func (c *CompiledIOP) InsertGrandProduct(round int, id ifaces.QueryID, in map[[2]int]*query.GrandProductInput) *query.GrandProduct { +func (c *CompiledIOP) InsertGrandProduct(round int, id ifaces.QueryID, in map[int]*query.GrandProductInput) *query.GrandProduct { c.assertConsistentRound(round) - q := query.NewGrandProduct(in, id) + q := query.NewGrandProduct(round, in, id) // Finally registers the query c.QueriesParams.AddToRound(round, q.Name(), q) return q From 3fc8a52f368efdc64dcf8a25c06bc73a4e21e46e Mon Sep 17 00:00:00 2001 From: arijitdutta67 Date: Fri, 10 Jan 2025 15:25:04 +0530 Subject: [PATCH 3/5] minor fix --- .../distributed/compiler/permutation/permutation_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prover/protocol/distributed/compiler/permutation/permutation_test.go b/prover/protocol/distributed/compiler/permutation/permutation_test.go index 3eebeec95af..2377de2337d 100644 --- a/prover/protocol/distributed/compiler/permutation/permutation_test.go +++ b/prover/protocol/distributed/compiler/permutation/permutation_test.go @@ -11,7 +11,7 @@ import ( "github.com/consensys/linea-monorepo/prover/protocol/wizard" ) -func TestPermutationAlex(t *testing.T) { +func TestPermutation(t *testing.T) { var ( moduleAName = "MODULE_A" From 906abe0d29b76af7289cf33a36790890bbec76f6 Mon Sep 17 00:00:00 2001 From: arijitdutta67 Date: Fri, 10 Jan 2025 16:34:01 +0530 Subject: [PATCH 4/5] minor fixes in the comments --- .../distributed/compiler/permutation/permutation.go | 7 ++----- prover/protocol/query/grand_product.go | 9 +-------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/prover/protocol/distributed/compiler/permutation/permutation.go b/prover/protocol/distributed/compiler/permutation/permutation.go index 70e6ef85605..cceddcb828c 100644 --- a/prover/protocol/distributed/compiler/permutation/permutation.go +++ b/prover/protocol/distributed/compiler/permutation/permutation.go @@ -166,8 +166,7 @@ func (p *PermutationIntoGrandProductCtx) push(comp *wizard.CompiledIOP, aOrb []i // computeFactor computes the symbolic factor for a permutation query based on the given parameters. // It iterates through the fragments of the query, computes the linear combination of columns with alpha -// (if multi-column) or directly uses the column as a variable, adds the beta value, and multiplies it with -// the current factor. The final computed factor is returned. +// (if multi-column) or directly uses the column as a variable, adds the beta value and returns the result. // // Parameters: // - aOrB: A 2D slice of Column interfaces representing the fragments of the permutation query. @@ -184,10 +183,8 @@ func computeFactor(aOrB []ifaces.Column, alpha, beta coin.Info) *symbolic.Expres return symbolic.Add(beta, aOrB[0]) } -// computeQueryParam computes the query parameter for the grand product query and assigns it in round one. +// computeQueryParam computes the query parameter for the grand product query. // It multiplies the products of the Numerators and Denominators, evaluates the resulting symbolic expressions, -// and assigns the result to the field element ParamY. -// // Parameters: // - run: The prover runtime. // - name: The query ID specific to the target module. diff --git a/prover/protocol/query/grand_product.go b/prover/protocol/query/grand_product.go index fcbcd1ad99b..69387be1115 100644 --- a/prover/protocol/query/grand_product.go +++ b/prover/protocol/query/grand_product.go @@ -13,7 +13,7 @@ import ( "github.com/consensys/linea-monorepo/prover/utils" ) -// The GrandProduct query is obtained by process all the permuation queries specific to a target module. +// The GrandProduct query is obtained by processing all the permuation queries specific to a target module. // We store the randomised symbolic products of A and B of permuation queries combinedly // into the Numerators and the Denominators of the GrandProduct query type GrandProductInput struct { @@ -36,9 +36,6 @@ type GrandProductParams struct { } // NewGrandProduct creates a new instance of a GrandProduct query. -// The GrandProduct query is obtained by processing all permutation queries specific to a target module. -// We store the randomized symbolic products of A and B of permutation queries combinedly -// into the Numerators and the Denominators of the GrandProduct query. // // Parameters: // - round: The round number of the query. @@ -51,10 +48,6 @@ type GrandProductParams struct { func NewGrandProduct(round int, inp map[int]*GrandProductInput, id ifaces.QueryID) *GrandProduct { // check the length consistency for key := range inp { - // To check if the below is required or not - // if len(inp[key].Numerators) != len(inp[key].Denominator) || len(inp[key].Numerator) == 0 { - // utils.Panic("Numerator and Denominator should have the same (non-zero) length, %v , %v", len(inp[key].Numerator), len(inp[key].Denominator)) - // } for i := range inp[key].Numerators { if err := inp[key].Numerators[i].Validate(); err != nil { utils.Panic(" Numerator[%v] is not a valid expression", i) From 559426364820065880382ec153443df9d2d02862 Mon Sep 17 00:00:00 2001 From: arijitdutta67 Date: Fri, 10 Jan 2025 17:11:49 +0530 Subject: [PATCH 5/5] Azam's suggestion added --- .../distributed/compiler/permutation/permutation_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/prover/protocol/distributed/compiler/permutation/permutation_test.go b/prover/protocol/distributed/compiler/permutation/permutation_test.go index 2377de2337d..1fe81863ede 100644 --- a/prover/protocol/distributed/compiler/permutation/permutation_test.go +++ b/prover/protocol/distributed/compiler/permutation/permutation_test.go @@ -9,6 +9,7 @@ import ( modulediscoverer "github.com/consensys/linea-monorepo/prover/protocol/distributed/module_discoverer" "github.com/consensys/linea-monorepo/prover/protocol/ifaces" "github.com/consensys/linea-monorepo/prover/protocol/wizard" + "github.com/stretchr/testify/require" ) func TestPermutation(t *testing.T) { @@ -161,7 +162,9 @@ func TestPermutation(t *testing.T) { } } - _ = wizard.Prove(moduleAComp, moduleAProve) + proof := wizard.Prove(moduleAComp, moduleAProve) + valid := wizard.Verify(moduleAComp, proof) + require.NoError(t, valid) })