Skip to content

Commit

Permalink
orgnising the package
Browse files Browse the repository at this point in the history
  • Loading branch information
Soleimani193 committed Sep 17, 2024
1 parent 749a257 commit 626c6bb
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 141 deletions.
117 changes: 117 additions & 0 deletions prover/protocol/compiler/splitter/splitter/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package alliance

import (
"github.com/consensys/linea-monorepo/prover/protocol/column"
"github.com/consensys/linea-monorepo/prover/protocol/ifaces"
"github.com/consensys/linea-monorepo/prover/symbolic"
)

// It stores the information regarding a single Alliance.
// used to update the content of [stitchingContex.Stitchings]
type Alliance struct {
// the result of the stitching
BigCol ifaces.Column
// sub columns that are stitched together
SubCols []ifaces.Column
// the Round in which the sub columns are committed.
Round int
// Status of the sub columns
// the only valid Status for the eligible sub columns are;
// committed, Precomputed, VerifierDefined
Status column.Status
}

type SummerizedAlliances struct {
// associate a group of the sub columns to their splitting
ByBigCol map[ifaces.ColID][]ifaces.Column
// for a sub column, it indicates its splitting column and its position in the splitting.
BySubCol map[ifaces.ColID]struct {
NameBigCol ifaces.ColID
PosInBigCol int
}
}

type MultiSummary []SummerizedAlliances

// it inserts the new stitching to [stitchingContex]
func (summary MultiSummary) InsertNew(s Alliance) {
// Initialize the bySubCol if necessary
if summary[s.Round].BySubCol == nil {
summary[s.Round].BySubCol = map[ifaces.ColID]struct {
NameBigCol ifaces.ColID
PosInBigCol int
}{}
}

// Populate the bySubCol
for posInNew, c := range s.SubCols {
summary[s.Round].BySubCol[c.GetColID()] = struct {
NameBigCol ifaces.ColID
PosInBigCol int
}{
NameBigCol: s.BigCol.GetColID(),
PosInBigCol: posInNew,
}
}

// Initialize ByBigCol if necessary
if summary[s.Round].ByBigCol == nil {
summary[s.Round].ByBigCol = make(map[ifaces.ColID][]ifaces.Column)
}
// populate ByBigCol
summary[s.Round].ByBigCol[s.BigCol.GetColID()] = s.SubCols
}

// It checks if the expression is over a set of the columns eligible to the stitching.
// Namely, it contains columns of proper size with status Precomputed, Committed, or Verifiercol.
// It panics if the expression includes a mixture of eligible columns and columns with status Proof/VerifiyingKey/Ignored.
//
// If all the columns are verifierCol the expression is not eligible to the compilation.
// This is an expected behavior, since the verifier checks such expression by itself.
func IsExprEligible(
isColEligible func(MultiSummary, ifaces.Column) bool,
stitchings MultiSummary,
board symbolic.ExpressionBoard,
) bool {
metadata := board.ListVariableMetadata()
hasAtLeastOneEligible := false
allAreEligible := true
allAreVeriferCol := true
for i := range metadata {
switch m := metadata[i].(type) {
// reminder: [verifiercol.VerifierCol] , [column.Natural] and [column.Shifted]
// all implement [ifaces.Column]
case ifaces.Column: // it is a Committed, Precomputed or verifierCol
natural := column.RootParents(m)[0]
switch natural.(type) {
case column.Natural: // then it is not a verifiercol
allAreVeriferCol = false
b := isColEligible(stitchings, m)

hasAtLeastOneEligible = hasAtLeastOneEligible || b
allAreEligible = allAreEligible && b
if m.Size() == 0 {
panic("found no columns in the expression")
}
}

}

}

if hasAtLeastOneEligible && !allAreEligible {
// 1. we expect no expression including Proof columns
// 2. we expect no expression over ignored columns
// 3. we expect no VerifiyingKey withing the stitching range.
panic("the expression is not valid, it is mixed with invalid columns of status Proof/Ingnored/verifierKey")
}
if allAreVeriferCol {
// 4. we expect no expression involving only and only the verifierCols.
// We expect that this case wont happen.
// Otherwise should be handled in the [github.com/consensys/linea-monorepo/prover/protocol/query] package.
// Namely, Local/Global queries should be checked directly by the verifer.
panic("all the columns in the expression are verifierCols, unsupported by the compiler")
}

return hasAtLeastOneEligible
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/consensys/linea-monorepo/prover/protocol/coin"
"github.com/consensys/linea-monorepo/prover/protocol/column"
"github.com/consensys/linea-monorepo/prover/protocol/column/verifiercol"
alliance "github.com/consensys/linea-monorepo/prover/protocol/compiler/splitter/splitter"
"github.com/consensys/linea-monorepo/prover/protocol/ifaces"
"github.com/consensys/linea-monorepo/prover/protocol/query"
"github.com/consensys/linea-monorepo/prover/protocol/variables"
Expand All @@ -27,7 +28,7 @@ func (ctx stitchingContext) LocalOpening() {
utils.Panic("got an uncompilable query %v", qName)
}

if !isColEligible(ctx, q.Pol) {
if !isColEligible(ctx.Stitchings, q.Pol) {
continue
}
// mark the query as ignored
Expand Down Expand Up @@ -62,7 +63,7 @@ func (ctx stitchingContext) LocalGlobalConstraints() {
board = q.Board()
// detect if the expression is eligible;
// i.e., it contains columns of proper size with status Precomputed, committed, or verifiercol.
if !isExprEligible(ctx, board) {
if !alliance.IsExprEligible(isColEligible, ctx.Stitchings, board) {
continue
}

Expand All @@ -75,7 +76,7 @@ func (ctx stitchingContext) LocalGlobalConstraints() {
case query.GlobalConstraint:
board = q.Board()
// detect if the expression is over the eligible columns.
if !isExprEligible(ctx, board) {
if !alliance.IsExprEligible(isColEligible, ctx.Stitchings, board) {
continue
}

Expand Down Expand Up @@ -112,13 +113,13 @@ func getStitchingCol(ctx stitchingContext, col ifaces.Column) ifaces.Column {

round := col.Round()
subColInfo := ctx.Stitchings[round].BySubCol[natural.GetColID()]
stitchingCol := ctx.comp.Columns.GetHandle(subColInfo.NameStitching)
stitchingCol := ctx.comp.Columns.GetHandle(subColInfo.NameBigCol)

// Shift the stitching column by the right position
position := column.StackOffsets(col)

scaling := stitchingCol.Size() / natural.Size()
newPosition := scaling*position + subColInfo.PosInNew
newPosition := scaling*position + subColInfo.PosInBigCol

return column.Shift(stitchingCol, newPosition)
}
Expand Down
Loading

0 comments on commit 626c6bb

Please sign in to comment.