From 5c2dd12dd2d675b0aeb95d72916858354b7fcfa3 Mon Sep 17 00:00:00 2001 From: Lakshminarayanan Nandakumar <45759699+srinathln7@users.noreply.github.com> Date: Sat, 15 Mar 2025 21:51:50 +0100 Subject: [PATCH] =?UTF-8?q?apply=20`manualCheckMiMCBlock`=20individually?= =?UTF-8?q?=20to=20each=20query=E2=80=99s=20columns=20(#782)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * apply `manualCheckMiMCBlock` individually to each query’s columns --- prover/protocol/compiler/mimc/mimc.go | 102 +++----------------------- 1 file changed, 10 insertions(+), 92 deletions(-) diff --git a/prover/protocol/compiler/mimc/mimc.go b/prover/protocol/compiler/mimc/mimc.go index 0de111c4..38a79bac 100644 --- a/prover/protocol/compiler/mimc/mimc.go +++ b/prover/protocol/compiler/mimc/mimc.go @@ -1,116 +1,34 @@ package mimc import ( - "github.com/consensys/linea-monorepo/prover/crypto/mimc" - "github.com/consensys/linea-monorepo/prover/maths/common/smartvectors" - "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/protocol/wizard" - "github.com/consensys/linea-monorepo/prover/utils" "github.com/sirupsen/logrus" ) -// Compiles the MiMC queries by instantiating a MiMC module +// CompileMiMC compiles the MiMC queries by checking each query individually in a single loop func CompileMiMC(comp *wizard.CompiledIOP) { - - // Scans the compiled IOP, looking for unignored MiMC queries. - // And mark them as ignored when encountered. - totalLen := 0 - round := 0 - mimcQueries := []query.MiMC{} + hasMiMCQueries := false for _, id := range comp.QueriesNoParams.AllUnignoredKeys() { - // Fetch the query q := comp.QueriesNoParams.Data(id) qMiMC, ok := q.(query.MiMC) if !ok { - // not a MiMC query, skip it + // Not a MiMC query, skip it continue } - // else mark it as ignored + // Mark it as ignored comp.QueriesNoParams.MarkAsIgnored(id) + hasMiMCQueries = true - mimcQueries = append(mimcQueries, qMiMC) - totalLen += qMiMC.Blocks.Size() - round = utils.Max(round, comp.QueriesNoParams.Round(id)) + // Apply manual check to the query immediately + logrus.Debugf("MiMC compiler: checking query %v individually", qMiMC.ID) + manualCheckMiMCBlock(comp, qMiMC.Blocks, qMiMC.OldState, qMiMC.NewState) } - if len(mimcQueries) == 0 { - // nothing to compile : - logrus.Debug("MiMC compiler exited : no MiMC queries to compile") - return + if !hasMiMCQueries { + logrus.Debug("MiMC compiler exited: no MiMC queries to compile") } - - if len(mimcQueries) == 1 { - // unroll the mimc check directly over the columns of the unique query - logrus.Debug("MiMC compiler : only one MiMC query to compile, no lookup needed") - manualCheckMiMCBlock(comp, mimcQueries[0].Blocks, mimcQueries[0].OldState, mimcQueries[0].NewState) - } - - // Else, we conflate every query in a single module and we apply the MiMC check over it. - totalLen = utils.NextPowerOfTwo(totalLen) - - blocks := comp.InsertCommit(round, ifaces.ColID(mimcName(comp, "ALL_BLOCKS")), totalLen) - oldStates := comp.InsertCommit(round, ifaces.ColID(mimcName(comp, "ALL_OLD_STATES")), totalLen) - newStates := comp.InsertCommit(round, ifaces.ColID(mimcName(comp, "ALL_NEW_STATES")), totalLen) - - // Assign these columns - comp.SubProvers.AppendToInner(round, func(run *wizard.ProverRuntime) { - - // Preallocate all the slices - blocksWit := make([]field.Element, 0, totalLen) - oldStatesWit := make([]field.Element, 0, totalLen) - newStatesWit := make([]field.Element, 0, totalLen) - - // Append all the blocks, old states and new states to the slices for all queries - for _, q := range mimcQueries { - blocksWit = append(blocksWit, - smartvectors.IntoRegVec(q.Blocks.GetColAssignment(run))..., - ) - oldStatesWit = append(oldStatesWit, - smartvectors.IntoRegVec(q.OldState.GetColAssignment(run))..., - ) - newStatesWit = append(newStatesWit, - smartvectors.IntoRegVec(q.NewState.GetColAssignment(run))..., - ) - } - - if len(blocksWit) == totalLen { - // Just allocate the slices as is and return - run.AssignColumn(blocks.GetColID(), smartvectors.NewRegular(blocksWit)) - run.AssignColumn(oldStates.GetColID(), smartvectors.NewRegular(oldStatesWit)) - run.AssignColumn(newStates.GetColID(), smartvectors.NewRegular(newStatesWit)) - return - } - - // Else, we need to pad with a dummy value - dumBlock, dumOld, dumNew := field.Zero(), field.Zero(), mimc.BlockCompression(field.Zero(), field.Zero()) - - run.AssignColumn(blocks.GetColID(), - smartvectors.RightPadded(blocksWit, dumBlock, totalLen), - ) - run.AssignColumn(oldStates.GetColID(), - smartvectors.RightPadded(oldStatesWit, dumOld, totalLen), - ) - run.AssignColumn(newStates.GetColID(), - smartvectors.RightPadded(newStatesWit, dumNew, totalLen), - ) - }) - - // Internal consistency of the new columns - manualCheckMiMCBlock(comp, blocks, oldStates, newStates) - - // And lookupize all MiMC queries parames into the central MiMC checking module - for _, q := range mimcQueries { - comp.InsertInclusion( - round, - ifaces.QueryID(mimcName(comp, "INCLUSION", q.ID)), - []ifaces.Column{blocks, oldStates, newStates}, - []ifaces.Column{q.Blocks, q.OldState, q.NewState}, - ) - } - }