Skip to content

Commit

Permalink
cross checks for distributed global queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Soleimani193 committed Feb 19, 2025
1 parent 2c1d595 commit fc90254
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 18 deletions.
52 changes: 47 additions & 5 deletions prover/protocol/distributed/compiler/global/global.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package global

import (
"github.com/consensys/linea-monorepo/prover/maths/field"
"github.com/consensys/linea-monorepo/prover/protocol/accessors"
"github.com/consensys/linea-monorepo/prover/protocol/column"
"github.com/consensys/linea-monorepo/prover/protocol/column/verifiercol"
"github.com/consensys/linea-monorepo/prover/protocol/distributed"
"github.com/consensys/linea-monorepo/prover/protocol/distributed/constants"
"github.com/consensys/linea-monorepo/prover/protocol/ifaces"
"github.com/consensys/linea-monorepo/prover/protocol/query"
"github.com/consensys/linea-monorepo/prover/protocol/variables"
"github.com/consensys/linea-monorepo/prover/protocol/wizard"
"github.com/consensys/linea-monorepo/prover/symbolic"
"github.com/consensys/linea-monorepo/prover/utils"
"github.com/consensys/linea-monorepo/prover/utils/collection"
edc "github.com/consensys/linea-monorepo/prover/zkevm/prover/publicInput/execution_data_collector"
)

type segmentID int
Expand All @@ -25,6 +28,8 @@ type DistributionInputs struct {
ModuleName distributed.ModuleName
// number of segments for the module
NumSegments int
// the ID of the segment in the module
SegID int
}

func DistributeGlobal(in DistributionInputs) {
Expand Down Expand Up @@ -56,7 +61,6 @@ func DistributeGlobal(in DistributionInputs) {
)

// collect the boundaries for provider and receiver

BoundariesForProvider(&bInputs, q)
BoundariesForReceiver(&bInputs, q)

Expand All @@ -67,11 +71,44 @@ func DistributeGlobal(in DistributionInputs) {
// and at the end make sure that no query has remained in initial CompiledIOP.
}

in.ModuleComp.RegisterProverAction(0, &paramAssignments{
// get the hash of the provider and the receiver
var (
colOnes = verifiercol.NewConstantCol(field.One(), bInputs.provider.Size())
mimcHasherProvider = edc.NewMIMCHasher(in.ModuleComp, bInputs.provider, colOnes, "MIMC_HASHER_PROVIDER")
mimicHasherReceiver = edc.NewMIMCHasher(in.ModuleComp, bInputs.receiver, colOnes, "MIMC_HASHER_RECEIVER")
)

mimcHasherProvider.DefineHasher(in.ModuleComp, "DISTRIBUTED_GLOBAL_QUERY_MIMC_HASHER_PROVIDER")
mimcHasherProvider.DefineHasher(in.ModuleComp, "DISTRIBUTED_GLOBAL_QUERY_MIMC_HASHER_RECEIVER")

var (
openingHashProvider = in.ModuleComp.InsertLocalOpening(0, "ACCESSOR_FROM_HASH_PROVIDER", mimcHasherProvider.HashFinal)
openingHashReceiver = in.ModuleComp.InsertLocalOpening(0, "ACCESSOR_FROM_HASH_RECEIVER", mimicHasherReceiver.HashFinal)
)

// declare the hash of the provider/receiver as the public inputs.
in.ModuleComp.PublicInputs = append(in.ModuleComp.PublicInputs,
wizard.PublicInput{
Name: constants.GlobalProviderPublicInput,
Acc: accessors.NewLocalOpeningAccessor(openingHashProvider, 0),
})

in.ModuleComp.PublicInputs = append(in.ModuleComp.PublicInputs,
wizard.PublicInput{
Name: constants.GlobalReceiverPublicInput,
Acc: accessors.NewLocalOpeningAccessor(openingHashReceiver, 0),
})

in.ModuleComp.RegisterProverAction(0, &proverActionForBoundaries{
provider: bInputs.provider,
receiver: bInputs.receiver,
providerOpenings: bInputs.providerOpenings,
receiverOpenings: bInputs.receiverOpenings,

mimicHasherProvider: *mimcHasherProvider,
mimicHasherReceiver: *mimicHasherReceiver,
hashOpeningProvider: openingHashProvider,
hashOpeningReceiver: openingHashReceiver,
})

}
Expand All @@ -82,6 +119,7 @@ type boundaryInputs struct {
provider ifaces.Column
receiver ifaces.Column
providerOpenings, receiverOpenings []query.LocalOpening
segID int
}

func AdjustExpressionForGlobal(
Expand Down Expand Up @@ -252,9 +290,13 @@ func BoundariesForReceiver(in *boundaryInputs, q query.GlobalConstraint) {

}

expr := q.Expression.Replay(translationMap)
name := ifaces.QueryIDf("%v_%v_%v", "CONSISTENCY_AGAINST_RECEIVER", q.ID, i)
comp.InsertLocal(0, name, expr)
// If this is the first segment check for NoBoundCancel.
// q.NoBoundCancel is false by default, which in this case we should not check the boundaries.
if in.segID != 0 || q.NoBoundCancel {
expr := q.Expression.Replay(translationMap)
name := ifaces.QueryIDf("%v_%v_%v", "CONSISTENCY_AGAINST_RECEIVER", q.ID, i)
comp.InsertLocal(0, name, expr)
}

}

Expand Down
32 changes: 31 additions & 1 deletion prover/protocol/distributed/compiler/global/global_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package global_test

import (
"errors"
"testing"

"github.com/consensys/linea-monorepo/prover/maths/common/smartvectors"
"github.com/consensys/linea-monorepo/prover/protocol/column"
"github.com/consensys/linea-monorepo/prover/protocol/compiler/dummy"
"github.com/consensys/linea-monorepo/prover/protocol/distributed/compiler/global"
"github.com/consensys/linea-monorepo/prover/protocol/distributed/constants"
md "github.com/consensys/linea-monorepo/prover/protocol/distributed/namebaseddiscoverer"
segcomp "github.com/consensys/linea-monorepo/prover/protocol/distributed/segment_comp.go"
"github.com/consensys/linea-monorepo/prover/protocol/wizard"
Expand All @@ -20,6 +22,10 @@ func TestDistributedGlobal(t *testing.T) {
numSegModule = 2
)

var (
allVerfiers = []wizard.Runtime{}
)

//initialComp
define := func(b *wizard.Builder) {

Expand Down Expand Up @@ -51,6 +57,7 @@ func TestDistributedGlobal(t *testing.T) {

// initial compiledIOP is the parent to all the SegmentModuleComp objects.
initialComp := wizard.Compile(define)
var segID int

// Initialize the module discoverer
disc := md.QueryBasedDiscoverer{
Expand All @@ -65,6 +72,7 @@ func TestDistributedGlobal(t *testing.T) {
Disc: disc,
ModuleName: "module",
NumSegmentsInModule: numSegModule,
SegID: segID,
},
)

Expand All @@ -75,6 +83,7 @@ func TestDistributedGlobal(t *testing.T) {
Disc: disc.SimpleDiscoverer,
ModuleName: "module",
NumSegments: numSegModule,
SegID: segID,
})

// This dummy compiles the global/local queries of the segment.
Expand All @@ -90,8 +99,29 @@ func TestDistributedGlobal(t *testing.T) {
// inputs for vertical splitting of the witness
run.ProverID = proverID
})
valid := wizard.Verify(moduleComp, proof)
vRunTime, valid := wizard.VerifyWithRuntime(moduleComp, proof)
require.NoError(t, valid)

allVerfiers = append(allVerfiers, vRunTime)
}
// apply the crosse checks over the public inputs.
require.NoError(t, checkConsistency(allVerfiers))

}

func checkConsistency(runs []wizard.Runtime) error {

for i := range runs {

var (
hashProvider = runs[i].GetPublicInput(constants.GlobalProviderPublicInput)
hashNextReceiver = runs[(i+1)%len(runs)].GetPublicInput(constants.GlobalReceiverPublicInput)
)

if hashProvider != hashNextReceiver {
return errors.New("the provider and the next receiver have different values")
}
}

return nil
}
23 changes: 20 additions & 3 deletions prover/protocol/distributed/compiler/global/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@ import (
"github.com/consensys/linea-monorepo/prover/protocol/ifaces"
"github.com/consensys/linea-monorepo/prover/protocol/query"
"github.com/consensys/linea-monorepo/prover/protocol/wizard"
edc "github.com/consensys/linea-monorepo/prover/zkevm/prover/publicInput/execution_data_collector"
)

type paramAssignments struct {
type proverActionForBoundaries struct {
provider ifaces.Column
receiver ifaces.Column
providerOpenings []query.LocalOpening
receiverOpenings []query.LocalOpening

hashOpeningProvider query.LocalOpening
hashOpeningReceiver query.LocalOpening
mimicHasherProvider edc.MIMCHasher
mimicHasherReceiver edc.MIMCHasher
}

// it assigns the LocalOpening for the segment.
func (pa paramAssignments) Run(run *wizard.ProverRuntime) {
// it assigns all the LocalOpening covering the boundaries
func (pa proverActionForBoundaries) Run(run *wizard.ProverRuntime) {
var (
providerWit = run.GetColumn(pa.provider.GetColID()).IntoRegVecSaveAlloc()
receiverWit = run.GetColumn(pa.receiver.GetColID()).IntoRegVecSaveAlloc()
Expand All @@ -25,4 +31,15 @@ func (pa paramAssignments) Run(run *wizard.ProverRuntime) {
run.AssignLocalPoint(pa.providerOpenings[i].ID, providerWit[i])
run.AssignLocalPoint(pa.receiverOpenings[i].ID, receiverWit[i])
}

pa.mimicHasherProvider.AssignHasher(run)
pa.mimicHasherReceiver.AssignHasher(run)

var (
hashProvider = run.GetColumnAt(pa.mimicHasherProvider.HashFinal.GetColID(), 0)
hashReceiver = run.GetColumnAt(pa.mimicHasherReceiver.HashFinal.GetColID(), 0)
)

run.AssignLocalPoint(pa.hashOpeningProvider.ID, hashProvider)
run.AssignLocalPoint(pa.hashOpeningReceiver.ID, hashReceiver)
}
3 changes: 3 additions & 0 deletions prover/protocol/distributed/constants/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ const (
LogDerivativeSumPublicInput = "LOG_DERIVATE_SUM_PUBLIC_INPUT"
GrandProductPublicInput = "GRAND_PRODUCT_PUBLIC_INPUT"
GrandSumPublicInput = "GRAND_SUM_PUBLIC_INPUT"

GlobalProviderPublicInput = "GLOBAL_PROVIDER_PUBLIC_INPUT"
GlobalReceiverPublicInput = "GLOBAL_RECEIVER_PUBLIC_INPUT"
)
14 changes: 5 additions & 9 deletions prover/protocol/distributed/segment_comp.go/segcomp.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package segcomp

import (
"fmt"

"github.com/consensys/linea-monorepo/prover/maths/common/smartvectors"
"github.com/consensys/linea-monorepo/prover/maths/field"
"github.com/consensys/linea-monorepo/prover/protocol/column"
Expand All @@ -26,24 +24,22 @@ type SegmentInputs struct {
ModuleName distributed.ModuleName
// inputs for vertical splitting
NumSegmentsInModule int
SegID int
}

// It creates a segComp for GL sub-provers , it push LPP to round 0 and GL to round 1
// @Azam for the moment all is at round zero!
func GetFreshGLComp(in SegmentInputs) *wizard.CompiledIOP {

fmt.Printf("moduleName %v, glColumn %v\n", in.ModuleName, in.Disc.GLColumns.MustGet(in.ModuleName))
var (
initialComp = in.InitialComp
// initialize the compiledIOP of the segment by adding the lpp columns to round 0.
segComp = GetFreshLPPComp(in)
// extract glColumns of the module
glCols = in.Disc.GLColumns.MustGet(in.ModuleName)
segID int
)

// get the segment ID via a ProverAction
segComp.RegisterProverAction(0, segIDProvider{segID: segID})
segComp.RegisterProverAction(0, segIDProvider{segID: in.SegID})

// commit to GL columns
for _, col := range glCols {
Expand All @@ -56,18 +52,18 @@ func GetFreshGLComp(in SegmentInputs) *wizard.CompiledIOP {

precom := in.InitialComp.Precomputed.MustGet(col.GetColID())
segComp.InsertPrecomputed(col.GetColID(),
precom.SubVector(segSize*segID, segSize*(segID+1)))
precom.SubVector(segSize*in.SegID, segSize*(in.SegID+1)))

case column.VerifyingKey:

precom := in.InitialComp.Precomputed.MustGet(col.GetColID())
segComp.InsertPrecomputed(col.GetColID(),
precom.SubVector(segSize*segID, segSize*(segID+1)))
precom.SubVector(segSize*in.SegID, segSize*(in.SegID+1)))
segComp.Columns.SetStatus(col.GetColID(), column.VerifyingKey)

case column.VerifierDefined:
if vcol, ok := col.(verifiercol.VerifierCol); ok {
vcol.Split(segComp, segSize*segID, segSize*(segID+1))
vcol.Split(segComp, segSize*in.SegID, segSize*(in.SegID+1))
} else {
panic("unexpected type")
}
Expand Down

0 comments on commit fc90254

Please sign in to comment.