Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prover: beta v1.2 #605

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
195b086
bump go-corset
gusiri Jan 20, 2025
96447e8
fix compile errors
gusiri Jan 20, 2025
0045135
constraints: bump to v0.1.0-rc1 for beta-v1.2
gusiri Jan 20, 2025
fd6f176
bump to latest go-corset
gusiri Jan 20, 2025
755dd89
Merge branch 'main' into prover/beta-v1.2
gusiri Jan 27, 2025
f601b58
constraints: bump to beta-v1.2 / v0.1.0-rc2
gusiri Jan 27, 2025
191273b
bump go-corset
gusiri Jan 27, 2025
a1e1387
bump zkevm bin
gusiri Jan 27, 2025
582ce91
use next power of two value for non-power of two size columns (e.g., …
gusiri Jan 27, 2025
0da9a74
remove a check for the power of two size
gusiri Jan 27, 2025
dba6e50
bump corset to 9.7.18
gusiri Jan 27, 2025
523c236
bump zkevm.bin
gusiri Jan 27, 2025
251622b
bump corset to v9.7.18
gusiri Jan 27, 2025
69ae19e
update zkevm.bin
gusiri Jan 27, 2025
d94aae9
added interleaved to the compilediop columns
Soleimani193 Jan 28, 2025
b1a7319
adjusted size for corset columns
Soleimani193 Jan 28, 2025
4cf988c
Prover/Codehash Non Power of Two Column Size (#618)
arijitdutta67 Jan 29, 2025
168498b
adjusted size for corset columns
Soleimani193 Jan 28, 2025
d72e60b
constraints: bump to beta v1.2/v0.1.0-rc3
gusiri Jan 29, 2025
58ded37
update constraints version to rc3
gusiri Jan 29, 2025
1224826
bump to latest go-corset
gusiri Jan 29, 2025
04b99bc
apply hotfix for BLOCKDATA
gusiri Jan 30, 2025
8b87075
move NextPowerOfTwo unit test to utils
gusiri Jan 30, 2025
e4f4096
add logs for adjusted columns with non-power of two size
gusiri Jan 30, 2025
cbc43c2
turn off trace version check
gusiri Jan 30, 2025
28996d4
fix golangcli-lint
gusiri Jan 31, 2025
0ce3326
Merge branch 'main' into prover/beta-v1.2
gusiri Jan 31, 2025
1ffc046
Prover/fix public input timestamps from new blockdata (#644)
bogdanbear Feb 3, 2025
61d8454
Merge branch 'main' into prover/beta-v1.2
AlexandreBelling Feb 4, 2025
4465dc9
fix(codehash): uses 0x0 for the codehash of non-existing accounts ins…
gusiri Feb 4, 2025
564a064
fix(mimccodehash): unimport the rom codehash for initialization code
gusiri Feb 4, 2025
0b0e5e1
Merge branch 'prover/beta-v1.2' of github.com:Consensys/linea-monorep…
gusiri Feb 4, 2025
eb8d984
fixup(execDataHash): revert the exec-data hash check
gusiri Feb 5, 2025
e9ae001
timestamp byte change
bogdanbear Feb 5, 2025
0bb7969
fix(execdatahash): adds the real blockhash in the execdata hash inste…
gusiri Feb 5, 2025
aba6fce
fixup previous commit
gusiri Feb 5, 2025
44045bb
Merge branch 'prover/beta-v1.2' of github.com:Consensys/linea-monorep…
gusiri Feb 5, 2025
ad312d0
fixup(build): removes imports
gusiri Feb 5, 2025
73bc797
Revert "fixup(execDataHash): revert the exec-data hash check"
gusiri Feb 5, 2025
919e9af
fix(consistency): adds a smaller size to the consistency module
gusiri Feb 6, 2025
184771b
feat(mimc): alex -- mimc simplification -- start
AlexandreBelling Feb 6, 2025
eced66b
optimize factorExpression
gusiri Feb 6, 2025
319cd6e
feat(exec): uses the ProveCheck in the execution proof
gusiri Feb 7, 2025
359d6fb
Merge branch 'prover/beta-v1.2' of github.com:Consensys/linea-monorep…
gusiri Feb 7, 2025
2f43de1
Revert "feat(mimc): alex -- mimc simplification -- start"
gusiri Feb 7, 2025
5815d0d
fix (public-input): changed the hashing method to match compression
bogdanbear Feb 7, 2025
6eb1536
perf(mem): adds a detector for constant regular column.
AlexandreBelling Feb 7, 2025
3979fe4
fixup(mem): support the edge-case for smartvectors of size 1
gusiri Feb 7, 2025
b9efdb9
fix(codehash): support the case where the ROM is empty
gusiri Feb 7, 2025
aaa3c94
feat(csv): adds a feature to rename columns when using fmtcsv
AlexandreBelling Feb 11, 2025
df11f8b
fixup(codehash): supports the case where no codehash are available
AlexandreBelling Feb 11, 2025
15e7a1d
test(codehash): adds test for empty rom or statesummary
AlexandreBelling Feb 11, 2025
5afd73e
clean(naturalize): harmonize the implementation of the verifier
gusiri Feb 11, 2025
de983fa
fixup(plonk): generate the plonk with native verifier options and rem…
gusiri Feb 11, 2025
e820d15
update constraints version to rc3.1
gusiri Feb 12, 2025
c6d8c7f
clean(corset): use the lisp to name the constraints
AlexandreBelling Feb 13, 2025
0ba5075
fix(permutation): compile zcatalog in deterministic order
AlexandreBelling Feb 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion constraints
2 changes: 1 addition & 1 deletion corset
3 changes: 1 addition & 2 deletions prover/backend/execution/constraints-versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
v0.8.0-rc7
v0.8.0-rc8
beta-v1.2/v0.1.0-rc3.1
17 changes: 13 additions & 4 deletions prover/backend/execution/craft.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ func CraftProverOutput(
) Response {

// Split the embedded file contents into a string slice
constraintsVersions := strings.Split(strings.TrimSpace(constraintsVersionsStr), "\n")
// constraintsVersions := strings.Split(strings.TrimSpace(constraintsVersionsStr), "\n")

// Check the arithmetization version used to generate the trace is contained in the prover request
// and fail fast if the constraint version is not supported
if err := checkArithmetizationVersion(req.ConflatedExecutionTracesFile, req.TracesEngineVersion, constraintsVersions); err != nil {
panic(err.Error())
}
// if err := checkArithmetizationVersion(req.ConflatedExecutionTracesFile, req.TracesEngineVersion, constraintsVersions); err != nil {
// panic(err.Error())
// }

var (
l2BridgeAddress = cfg.Layer2.MsgSvcContract
Expand Down Expand Up @@ -238,6 +238,7 @@ func NewWitness(cfg *config.Config, req *Request, rsp *Response) *Witness {
TxHashes: txHashes,
L2BridgeAddress: cfg.Layer2.MsgSvcContract,
ChainID: cfg.Layer2.ChainID,
BlockHashList: getBlockHashList(rsp),
},
FuncInp: rsp.FuncInput(),
}
Expand Down Expand Up @@ -286,3 +287,11 @@ func validateAndExtractVersion(traceFileName string) (string, error) {
}
return "", fmt.Errorf("conflated trace file: %s not in the appropriate format or version not found", traceFileName)
}

func getBlockHashList(rsp *Response) []types.FullBytes32 {
res := []types.FullBytes32{}
for i := range rsp.BlocksData {
res = append(res, rsp.BlocksData[i].BlockHash)
}
return res
}
31 changes: 5 additions & 26 deletions prover/circuits/execution/circuit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
public_input "github.com/consensys/linea-monorepo/prover/public-input"

"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark/backend/plonk"
"github.com/consensys/gnark/frontend"
"github.com/consensys/linea-monorepo/prover/circuits"
"github.com/consensys/linea-monorepo/prover/protocol/wizard"
Expand Down Expand Up @@ -100,40 +99,20 @@ func MakeProof(
) string {

assignment := assign(limits, comp, wproof, funcInputs)
witness, err := frontend.NewWitness(&assignment, ecc.BLS12_377.ScalarField())
if err != nil {
panic(err)
}

proof, err := plonk.Prove(
setup.Circuit,
setup.ProvingKey,
witness,
proof, err := circuits.ProveCheck(
&setup,
&assignment,
emPlonk.GetNativeProverOptions(ecc.BW6_761.ScalarField(), setup.Circuit.Field()),
emPlonk.GetNativeVerifierOptions(ecc.BW6_761.ScalarField(), setup.Circuit.Field()),
)

if err != nil {
panic(err)
}

logrus.Infof("generated outer-circuit proof `%++v` for input `%v`", proof, assignment.PublicInput.(*big.Int).String())

// Sanity-check : the proof must pass
{
pubwitness, err := frontend.NewWitness(
&assignment,
ecc.BLS12_377.ScalarField(),
frontend.PublicOnly(),
)
if err != nil {
panic(err)
}

err = plonk.Verify(proof, setup.VerifyingKey, pubwitness, emPlonk.GetNativeVerifierOptions(ecc.BW6_761.ScalarField(), setup.Circuit.Field()))
if err != nil {
panic(err)
}
}

// Write the serialized proof
return circuits.SerializeProofRaw(proof)
}
3 changes: 2 additions & 1 deletion prover/circuits/prove.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package circuits
import (
"bytes"
"fmt"
"github.com/consensys/gnark/backend/witness"
"os"

"github.com/consensys/gnark/backend/witness"

"github.com/consensys/gnark/backend"
"github.com/consensys/gnark/backend/plonk"
"github.com/consensys/gnark/constraint/solver"
Expand Down
3 changes: 2 additions & 1 deletion prover/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ require (
github.com/consensys/compress v0.2.5
github.com/consensys/gnark v0.11.1-0.20250107100237-2cb190338a01
github.com/consensys/gnark-crypto v0.14.1-0.20241217134352-810063550bd4
github.com/consensys/go-corset v0.0.0-20241125005324-5cb0c289c021
github.com/consensys/go-corset v0.0.0-20250129030528-04c6bba7ccfd
github.com/crate-crypto/go-kzg-4844 v1.1.0
github.com/dlclark/regexp2 v1.11.2
github.com/fxamacker/cbor/v2 v2.7.0
github.com/go-playground/assert/v2 v2.2.0
github.com/go-playground/validator/v10 v10.22.0
github.com/iancoleman/strcase v0.3.0
github.com/icza/bitio v1.1.0
Expand Down
4 changes: 2 additions & 2 deletions prover/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ github.com/consensys/gnark v0.11.1-0.20250107100237-2cb190338a01 h1:YCHI04nMKFC6
github.com/consensys/gnark v0.11.1-0.20250107100237-2cb190338a01/go.mod h1:8YNyW/+XsYiLRzROLaj/PSktYO4VAdv6YW1b1P3UsZk=
github.com/consensys/gnark-crypto v0.14.1-0.20241217134352-810063550bd4 h1:Kp6egjRqKZf4469dfAWqFe6gi3MRs4VvNHmTfEjUlS8=
github.com/consensys/gnark-crypto v0.14.1-0.20241217134352-810063550bd4/go.mod h1:GMPeN3dUSslNBYJsK3WTjIGd3l0ccfMbcEh/d5knFrc=
github.com/consensys/go-corset v0.0.0-20241125005324-5cb0c289c021 h1:zAPMHjY72pXmjuyb/niQ816pd+B9RAmZoL/W/f5uJSU=
github.com/consensys/go-corset v0.0.0-20241125005324-5cb0c289c021/go.mod h1:J64guTfpmfXl4Yk2D7lsWdYg0ilP+N8JWPudP7+sZpA=
github.com/consensys/go-corset v0.0.0-20250129030528-04c6bba7ccfd h1:GQFLOm7l3hKtngBCuxw7f1NZajizIfWkK1gkUet+kFE=
github.com/consensys/go-corset v0.0.0-20250129030528-04c6bba7ccfd/go.mod h1:J64guTfpmfXl4Yk2D7lsWdYg0ilP+N8JWPudP7+sZpA=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
Expand Down
47 changes: 47 additions & 0 deletions prover/maths/common/smartvectors/smartvectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,50 @@ func WindowExt(v SmartVector) []fext.Element {
panic(fmt.Sprintf("unexpected type %T", v))
}
}

// TryReduceSize detects if the input smart-vector can be reduced to a constant
// smart-vector. It will only apply over the following types: [Regular].
func TryReduceSize(v SmartVector) SmartVector {

switch w := v.(type) {
case *Constant, *Rotated, *Pooled, *PaddedCircularWindow:
return w
case *Regular:

// to detect if a regular vector can be reduced to a constant, we need to
// check if all the values are equals. That's an expensive, so we instead
// by comparing values that would be likely to be unequal if it was not a
// constant. Also, we need to rule out the case where len(*w) because it
// is irrelevant to reducing the size.
if len(*w) <= 1 {
return w
}

if (*w)[0] != (*w)[1] {
return w
}

if (*w)[0] != (*w)[len(*w)-1] {
return w
}

if (*w)[0] != (*w)[len(*w)/2] {
return w
}

// This is expensive check where we check all the values in the vector
// to see if they are all equal. This is not the most efficient way to
// detect if a vector is a constant but the only reliable one.
for i := range *w {
if (*w)[i] != (*w)[0] {
return w
}
}

return NewConstant((*w)[0], len(*w))

default:
panic(fmt.Sprintf("unexpected type %T", v))
}

}
13 changes: 11 additions & 2 deletions prover/protocol/compiler/globalcs/factoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"reflect"
"sync"

"github.com/consensys/linea-monorepo/prover/protocol/accessors"
"github.com/consensys/linea-monorepo/prover/protocol/serialization"
Expand All @@ -13,12 +14,20 @@ import (
"github.com/consensys/linea-monorepo/prover/utils"
)

// factorExpressionList applies [factorExpression] over a list of expression
// factorExpressionList applies [factorExpression] over a list of expressions
func factorExpressionList(comp *wizard.CompiledIOP, exprList []*symbolic.Expression) []*symbolic.Expression {
res := make([]*symbolic.Expression, len(exprList))
var wg sync.WaitGroup

for i, expr := range exprList {
res[i] = factorExpression(comp, expr)
wg.Add(1)
go func(i int, expr *symbolic.Expression) {
defer wg.Done()
res[i] = factorExpression(comp, expr)
}(i, expr)
}

wg.Wait()
return res
}

Expand Down
33 changes: 31 additions & 2 deletions prover/protocol/compiler/permutation/compiler.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package permutation

import (
"slices"

"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/protocol/wizardutils"
"github.com/consensys/linea-monorepo/prover/symbolic"
"golang.org/x/exp/maps"
)

// CompileGrandProduct scans `comp`, looking for [query.Permutation] queries and
Expand Down Expand Up @@ -40,9 +43,16 @@ func CompileGrandProduct(comp *wizard.CompiledIOP) {
dispatchPermutation(comp, zCatalog, round, permutation)
}

for entry, zC := range zCatalog {
zCEntriesOrdered, zCsOrdered := mapAsTupleDeterministic(zCatalog)

for i := range zCEntriesOrdered {

var (
zC = zCsOrdered[i]
round = zCEntriesOrdered[i][0]
)

zC.compile(comp)
round := entry[0]
allProverActions[round] = append(allProverActions[round], zC)
}

Expand Down Expand Up @@ -108,3 +118,22 @@ func dispatchPermutation(
}
}
}

func mapAsTupleDeterministic(m map[[2]int]*ZCtx) (keys [][2]int, values []*ZCtx) {

keys = maps.Keys(m)
values = make([]*ZCtx, len(keys))

slices.SortFunc(keys, func(a, b [2]int) int {
if a[0] != b[0] {
return a[0] - b[0]
}
return a[1] - b[1]
})

for i := range keys {
values[i] = m[keys[i]]
}

return keys, values
}
17 changes: 5 additions & 12 deletions prover/protocol/compiler/univariates/naturalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,25 +348,20 @@ func (ctx naturalizationCtx) Verify(run *wizard.VerifierRuntime) error {

func (ctx naturalizationCtx) GnarkVerify(api frontend.API, c *wizard.WizardVerifierCircuit) {

logrus.Tracef("verifying naturalization")

// Get the original query
originalQuery := c.GetUnivariateEval(ctx.q.QueryID)
originalQueryParams := c.GetUnivariateParams(ctx.q.QueryID)

// Collect the subqueries and the collection in finalYs evaluations
subQueries := []query.UnivariateEval{}
subQueriesParamsX := []frontend.Variable{}
subQueriesParamsYs := [][]frontend.Variable{}
subQueriesParams := []query.GnarkUnivariateEvalParams{}
finalYs := collection.NewMapping[string, frontend.Variable]()

for qID, qName := range ctx.subQueriesNames {
subQueries = append(subQueries, c.GetUnivariateEval(qName))
params := c.GetUnivariateParams(qName)
subQueriesParamsX = append(subQueriesParamsX, params.X)
subQueriesParamsYs = append(subQueriesParamsYs, params.Ys)
subQueriesParams = append(subQueriesParams, c.GetUnivariateParams(qName))
repr := ctx.deduplicatedReprs[qID]
for j, derivedY := range subQueriesParamsYs[qID] {
for j, derivedY := range subQueriesParams[qID].Ys {
finalYs.InsertNew(column.DerivedYRepr(repr, subQueries[qID].Pols[j]), derivedY)
}
}
Expand Down Expand Up @@ -402,8 +397,8 @@ func (ctx naturalizationCtx) GnarkVerify(api frontend.API, c *wizard.WizardVerif
}
recoveredX := recoveredXs[i]
qID := ctx.reprToSubQueryID[subrepr]
submittedX := subQueriesParamsX[qID]
// Or it is a mismatch between the evaluation queries and the derived query
submittedX := subQueriesParams[qID].X

api.AssertIsEqual(recoveredX, submittedX)
}

Expand All @@ -412,7 +407,5 @@ func (ctx naturalizationCtx) GnarkVerify(api frontend.API, c *wizard.WizardVerif
*/
recoveredY := column.GnarkVerifyYConsistency(api, originH, "", cachedXs, finalYs)
api.AssertIsEqual(recoveredY, originalQueryParams.Ys[originPolID])

logrus.Tracef("verifying naturalization DONE")
}
}
5 changes: 4 additions & 1 deletion prover/protocol/wizard/compiled.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ func (c *CompiledIOP) InsertCommit(round int, name ifaces.ColID, size int) iface
// - if the size of the column is not a power of 2
// - if a column using the same name has already been registered
func (c *CompiledIOP) InsertColumn(round int, name ifaces.ColID, size int, status column.Status) ifaces.Column {

// Panic if the size is not a power of 2
if !utils.IsPowerOfTwo(size) {
utils.Panic("Registering column %v with a non power of two size = %v", name, size)
}
// @alex: this has actually caught a few typos. When wrongly setting an
// incorrect but very large size here, it will generate a disproportionate
// wizard
Expand Down
4 changes: 4 additions & 0 deletions prover/protocol/wizard/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ func (run *ProverRuntime) AssignColumn(name ifaces.ColID, witness ifaces.ColAssi
utils.Panic("Witness with non-power of two sizes, should have been caught earlier")
}

// This reduction is a trade-off between runtime and memory. It
// costs CPU but can save a significant amount of memory.
witness = smartvectors.TryReduceSize(witness)

// Adds it to the assignments
run.Columns.InsertNew(handle.GetColID(), witness)
}
Expand Down
11 changes: 10 additions & 1 deletion prover/symbolic/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package symbolic
import (
"fmt"
"reflect"
"sync"

"github.com/consensys/gnark/frontend"
"github.com/consensys/linea-monorepo/prover/maths/common/mempool"
Expand Down Expand Up @@ -244,9 +245,17 @@ func (e *Expression) ReconstructBottomUp(
// LinComb or Product or PolyEval. This is an intermediate expression.
case LinComb, Product, PolyEval:
children := make([]*Expression, len(e.Children))
var wg sync.WaitGroup
wg.Add(len(e.Children))

for i, c := range e.Children {
children[i] = c.ReconstructBottomUp(constructor)
go func(i int, c *Expression) {
defer wg.Done()
children[i] = c.ReconstructBottomUp(constructor)
}(i, c)
}

wg.Wait()
return constructor(e, children)
}

Expand Down
Loading
Loading