Skip to content

Commit

Permalink
Prover: fix full prover over Sepolia issues (#448)
Browse files Browse the repository at this point in the history
* fix(execution): assigns the functional public inputs
* revert(execution): reinstate the panic if the traes do not match the checksum.
* clean(circuit): remove the systematic circuit profiling
* fix(pi-interconnection): fix the check on the aggregation circuit
* chores(prover): remove the overly verbose log
* chores(zkevm.bin) commit the updated zkevm.bin
* fix(public-input): point to data_hilo instead of addr_hilo
* fixup: pi-interconnection fix in the circuit and the assignment

---------

Co-authored-by: Arya Tabaie <[email protected]>
  • Loading branch information
AlexandreBelling and Tabaie authored Dec 18, 2024
1 parent 8fa0a1c commit 7a67a21
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 41 deletions.
7 changes: 5 additions & 2 deletions prover/backend/execution/prove.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,11 @@ func mustProveAndPass(

if setupCfgChecksum != traces.Checksum() {
// This check is failing on prod but works locally.
// utils.Panic("traces checksum in the setup manifest does not match the one in the config")
logrus.Warnf("the setup checksum does not match the provided trace limits: provided=%++v", traces)
// @alex: since this is a setup-related constraint, it would likely be
// more interesting to directly include that information in the setup
// instead of the config. That way we are guaranteed to not pass the
// wrong value at runtime.
utils.Panic("traces checksum in the setup manifest does not match the one in the config")
}

// TODO: implements the collection of the functional inputs from the prover response
Expand Down
4 changes: 0 additions & 4 deletions prover/circuits/execution/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"github.com/consensys/gnark/constraint"
"github.com/consensys/gnark/frontend"
"github.com/consensys/gnark/frontend/cs/scs"
"github.com/consensys/gnark/profile"
"github.com/consensys/linea-monorepo/prover/zkevm"
)

Expand All @@ -25,9 +24,6 @@ func (b *builder) Compile() (constraint.ConstraintSystem, error) {
func makeCS(z *zkevm.ZkEvm) constraint.ConstraintSystem {
circuit := Allocate(z)

pro := profile.Start(profile.WithPath("./profiling-execution.pprof"))
defer pro.Stop()

scs, err := frontend.Compile(fr.Modulus(), scs.NewBuilder, &circuit, frontend.WithCapacity(1<<24))
if err != nil {
panic(err)
Expand Down
27 changes: 17 additions & 10 deletions prover/circuits/execution/circuit.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package execution

import (
"math/big"

"github.com/consensys/linea-monorepo/prover/config"
public_input "github.com/consensys/linea-monorepo/prover/public-input"
"math/big"

"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/backend/plonk"
Expand Down Expand Up @@ -63,17 +64,23 @@ func assign(
proof wizard.Proof,
funcInputs public_input.Execution,
) CircuitExecution {
wizardVerifier := wizard.GetWizardVerifierCircuitAssignment(comp, proof)

return CircuitExecution{
WizardVerifier: *wizardVerifier,
FuncInputs: FunctionalPublicInputSnark{
FunctionalPublicInputQSnark: FunctionalPublicInputQSnark{
L2MessageHashes: L2MessageHashes{Values: make([][32]frontend.Variable, limits.BlockL2L1Logs)}, // TODO use a maximum from config
var (
wizardVerifier = wizard.GetWizardVerifierCircuitAssignment(comp, proof)
res = CircuitExecution{
WizardVerifier: *wizardVerifier,
FuncInputs: FunctionalPublicInputSnark{
FunctionalPublicInputQSnark: FunctionalPublicInputQSnark{
L2MessageHashes: L2MessageHashes{Values: make([][32]frontend.Variable, limits.BlockL2L1Logs)}, // TODO use a maximum from config
},
},
},
PublicInput: new(big.Int).SetBytes(funcInputs.Sum(nil)),
}
PublicInput: new(big.Int).SetBytes(funcInputs.Sum(nil)),
}
)

res.FuncInputs.Assign(&funcInputs)

return res
}

// Define of the wizard circuit
Expand Down
10 changes: 10 additions & 0 deletions prover/circuits/internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ func AssertEqualIf(api frontend.API, cond, a, b frontend.Variable) {
api.AssertIsEqual(api.Mul(cond, a), api.Mul(cond, b))
}

// AssertIsLessIf asserts cond ≠ 0 ⇒ (a < b)
func AssertIsLessIf(api frontend.API, cond, a, b frontend.Variable) {
var (
condIsNonZero = api.Sub(1, api.IsZero(cond))
a_ = api.Mul(condIsNonZero, api.Add(a, 1))
b_ = api.Mul(condIsNonZero, b)
)
api.AssertIsLessOrEqual(a_, b_)
}

func SliceToTable(api frontend.API, slice []frontend.Variable) *logderivlookup.Table {
table := logderivlookup.New(api)
for i := range slice {
Expand Down
2 changes: 1 addition & 1 deletion prover/circuits/pi-interconnection/assign.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (c *Compiled) Assign(r Request) (a Circuit, err error) {
// @alex: Not sure this check is a duplicate because we already check
// that the state root hash is well-propagated and this should be
// enough that the rolling hash update events are emitted in sequence.
if executionFPI.FirstRollingHashUpdateNumber != lastRollingHashNumber+1 {
if executionFPI.FirstRollingHashUpdateNumber <= lastRollingHashNumber {
err = fmt.Errorf("execution #%d fails CHECK_RHASH_CONSEC:\n\tinitial rolling hash message number %d is not right after the last finalized one %d", i, executionFPI.FirstRollingHashUpdateNumber, lastRollingHashNumber)
return
}
Expand Down
2 changes: 1 addition & 1 deletion prover/circuits/pi-interconnection/circuit.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (c *Circuit) Define(api frontend.API) error {
rollingHashUpdated := api.Mul(inRange, api.Sub(1, finalRhMsgNumZero))

// CHECK_RHASH_CONSEC
internal.AssertEqualIf(api, rollingHashUpdated, pi.FirstRollingHashUpdateNumber, api.Add(finalRollingHashMsgNum, 1))
internal.AssertIsLessIf(api, rollingHashUpdated, finalRollingHashMsgNum, pi.FirstRollingHashUpdateNumber)
finalRollingHashMsgNum = api.Select(rollingHashUpdated, pi.LastRollingHashUpdateNumber, finalRollingHashMsgNum)
copy(finalRollingHash[:], internal.SelectMany(api, rollingHashUpdated, pi.FinalRollingHashUpdate[:], finalRollingHash[:]))

Expand Down
1 change: 0 additions & 1 deletion prover/protocol/compiler/vortex/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,6 @@ func (ctx *Ctx) processStatusPrecomputed() {

_, ok := ctx.PolynomialsTouchedByTheQuery[name]
if !ok {
logrus.Warnf("got an unconstrained column: %v -> marking as ignored", name)
comp.Columns.MarkAsIgnored(name)
continue
}
Expand Down
2 changes: 1 addition & 1 deletion prover/zkevm/arithmetization/zkevm.bin

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions prover/zkevm/prover/publicInput/logs/extracted_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func DefineExtractedData(comp *wizard.CompiledIOP, logCols LogColumns, sel Selec
}
// the LogColumns we extract data from, and which we will use to check for consistency
logsTable := []ifaces.Column{
logCols.OutgoingHi,
logCols.OutgoingLo,
logCols.DataHi,
logCols.DataLo,
}

comp.InsertGlobal(
Expand Down Expand Up @@ -97,8 +97,8 @@ func DefineExtractedData(comp *wizard.CompiledIOP, logCols LogColumns, sel Selec

// CheckBridgeAddress checks if a row does indeed contain the data corresponding to a the bridge address
func CheckBridgeAddress(run *wizard.ProverRuntime, lCols LogColumns, sel Selectors, pos int) bool {
outHi := lCols.OutgoingHi.GetColAssignmentAt(run, pos)
outLo := lCols.OutgoingLo.GetColAssignmentAt(run, pos)
outHi := lCols.DataHi.GetColAssignmentAt(run, pos)
outLo := lCols.DataLo.GetColAssignmentAt(run, pos)
bridgeAddrHi := sel.L2BridgeAddressColHI.GetColAssignmentAt(run, 0)
bridgeAddrLo := sel.L2BridgeAddressColLo.GetColAssignmentAt(run, 0)
if outHi.Equal(&bridgeAddrHi) && outLo.Equal(&bridgeAddrLo) {
Expand All @@ -113,8 +113,8 @@ func CheckFirstTopic(run *wizard.ProverRuntime, lCols LogColumns, pos int, logTy
firstTopicBytes := GetFirstTopic(logType) // fixed expected value for the topic on the first topic row
firstTopicHi.SetBytes(firstTopicBytes[:16])
firstTopicLo.SetBytes(firstTopicBytes[16:])
outHi := lCols.OutgoingHi.GetColAssignmentAt(run, pos)
outLo := lCols.OutgoingLo.GetColAssignmentAt(run, pos)
outHi := lCols.DataHi.GetColAssignmentAt(run, pos)
outLo := lCols.DataLo.GetColAssignmentAt(run, pos)
if firstTopicHi.Equal(&outHi) && firstTopicLo.Equal(&outLo) {
return true
}
Expand Down Expand Up @@ -155,8 +155,8 @@ func AssignExtractedData(run *wizard.ProverRuntime, lCols LogColumns, sel Select
for i := 0; i < lCols.Ct.Size(); i++ {
// the following conditional checks if row i contains a message that should be picked
if IsPositionTargetMessage(run, lCols, sel, i, logType) {
hi := lCols.OutgoingHi.GetColAssignmentAt(run, i)
lo := lCols.OutgoingLo.GetColAssignmentAt(run, i)
hi := lCols.DataHi.GetColAssignmentAt(run, i)
lo := lCols.DataLo.GetColAssignmentAt(run, i)
// pick the messages and add them to the msgHi/Lo ExtractedData columns
Hi[counter].Set(&hi)
Lo[counter].Set(&lo)
Expand Down
10 changes: 5 additions & 5 deletions prover/zkevm/prover/publicInput/logs/mock_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type LogColumns struct {
AbsLogNum ifaces.Column
AbsLogNumMax ifaces.Column // total number of logs in the conflated batch
Ct ifaces.Column // counter column used inside a column segment used for one specific log
OutgoingHi, OutgoingLo ifaces.Column // the Hi and Lo parts of outgoing data
DataHi, DataLo ifaces.Column // the Hi and Lo parts of outgoing data
TxEmitsLogs ifaces.Column
}

Expand Down Expand Up @@ -131,8 +131,8 @@ func NewLogColumns(comp *wizard.CompiledIOP, size int, name string) LogColumns {
AbsLogNum: createCol("ABS_LOG_NUM"),
AbsLogNumMax: createCol("ABS_LOG_NUM_MAX"),
Ct: createCol("CT"),
OutgoingHi: createCol("OUTGOING_HI"),
OutgoingLo: createCol("OUTGOING_LO"),
DataHi: createCol("OUTGOING_HI"),
DataLo: createCol("OUTGOING_LO"),
TxEmitsLogs: createCol("TX_EMITS_LOGS"),
}

Expand Down Expand Up @@ -160,8 +160,8 @@ func NewLogColumnsAssignmentBuilder(lc *LogColumns) LogColumnsAssignmentBuilder
AbsLogNum: common.NewVectorBuilder(lc.AbsLogNum),
AbsLogNumMax: common.NewVectorBuilder(lc.AbsLogNumMax),
Ct: common.NewVectorBuilder(lc.Ct),
OutgoingHi: common.NewVectorBuilder(lc.OutgoingHi),
OutgoingLo: common.NewVectorBuilder(lc.OutgoingLo),
OutgoingHi: common.NewVectorBuilder(lc.DataHi),
OutgoingLo: common.NewVectorBuilder(lc.DataLo),
TxEmitsLogs: common.NewVectorBuilder(lc.TxEmitsLogs),
}

Expand Down
12 changes: 6 additions & 6 deletions prover/zkevm/prover/publicInput/logs/selectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ func NewSelectorColumns(comp *wizard.CompiledIOP, lc LogColumns) Selectors {
// selectors that light up when OutgoingHi/OutgoingLo contain the expected first topic data
SelectFirstTopicL2L1Hi, ComputeSelectFirstTopicL2L1Hi := dedicated.IsZero(
comp,
sym.Sub(lc.OutgoingHi, firstTopicL2L1Hi),
sym.Sub(lc.DataHi, firstTopicL2L1Hi),
)

SelectFirstTopicL2L1Lo, ComputeSelectFirstTopicL2L1Lo := dedicated.IsZero(
comp,
sym.Sub(lc.OutgoingLo, firstTopicL2L1Lo),
sym.Sub(lc.DataLo, firstTopicL2L1Lo),
)

// compute the expected data in the first topic of a rolling hash log
Expand All @@ -212,12 +212,12 @@ func NewSelectorColumns(comp *wizard.CompiledIOP, lc LogColumns) Selectors {
// selectors that light up when OutgoingHi/OutgoingLo contain the expected first topic data
SelectFirstTopicRollingHi, ComputeSelectFirstTopicRollingHi := dedicated.IsZero(
comp,
sym.Sub(lc.OutgoingHi, firstTopicRollingHi),
sym.Sub(lc.DataHi, firstTopicRollingHi),
)

SelectFirstTopicRollingLo, ComputeSelectFirstTopicRollingLo := dedicated.IsZero(
comp,
sym.Sub(lc.OutgoingLo, firstTopicRollingLo),
sym.Sub(lc.DataLo, firstTopicRollingLo),
)

bridgeAddrColHi := comp.InsertProof(0, ifaces.ColIDf("LOGS_FETCHER_BRIDGE_ADDRESS_HI"), 1)
Expand All @@ -229,12 +229,12 @@ func NewSelectorColumns(comp *wizard.CompiledIOP, lc LogColumns) Selectors {
// selectors that light up when OutgoingHi/OutgoingLo contain the Hi/Lo parts of the l2BridgeAddress
SelectorL2BridgeAddressHi, ComputeSelectorL2BridgeAddressHi := dedicated.IsZero(
comp,
sym.Sub(lc.OutgoingHi, accessBridgeHi),
sym.Sub(lc.DataHi, accessBridgeHi),
)

SelectorL2BridgeAddressLo, ComputeSelectorL2BridgeAddressLo := dedicated.IsZero(
comp,
sym.Sub(lc.OutgoingLo, accessBridgeLo),
sym.Sub(lc.DataLo, accessBridgeLo),
)

// generate the final selector object
Expand Down
4 changes: 2 additions & 2 deletions prover/zkevm/prover/publicInput/public_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ func NewPublicInputZkEVM(comp *wizard.CompiledIOP, settings *Settings, ss *state
AbsLogNum: getCol("loginfo.ABS_LOG_NUM"),
AbsLogNumMax: getCol("loginfo.ABS_LOG_NUM_MAX"),
Ct: getCol("loginfo.CT"),
OutgoingHi: getCol("loginfo.ADDR_HI"),
OutgoingLo: getCol("loginfo.ADDR_LO"),
DataHi: getCol("loginfo.DATA_HI"),
DataLo: getCol("loginfo.DATA_LO"),
TxEmitsLogs: getCol("loginfo.TXN_EMITS_LOGS"),
},
StateSummary: ss,
Expand Down

0 comments on commit 7a67a21

Please sign in to comment.