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 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 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
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
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: 23 additions & 8 deletions prover/circuits/blobdecompression/v1/snark.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ package v1
import (
"errors"

mimcGnark "github.com/consensys/gnark/std/hash/mimc"
"github.com/consensys/gnark/std/lookup/logderivlookup"

"math/big"
"math/bits"

"github.com/consensys/linea-monorepo/prover/circuits/internal"
"github.com/consensys/linea-monorepo/prover/crypto/mimc"
"github.com/consensys/linea-monorepo/prover/crypto/mimc/gkrmimc"
"github.com/consensys/linea-monorepo/prover/utils"
"github.com/consensys/linea-monorepo/prover/utils/gnarkutil"

"github.com/consensys/gnark/constraint/solver"
Expand Down Expand Up @@ -172,11 +176,21 @@ func CheckBatchesSums(api frontend.API, hasher snarkHash.FieldHasher, nbBatches
inputAt31B.Insert(nr.Next())
}

_hsh := func(a, b frontend.Variable) frontend.Variable {
hasher.Reset()
hasher.Write(a, b)
res := hasher.Sum()
return res
_hsh := func(prevState frontend.Variable, a frontend.Variable, noHash frontend.Variable) frontend.Variable {

var b frontend.Variable

switch hasherT := hasher.(type) {

case *gkrmimc.Hasher:
b = hasherT.Compress(prevState, a)
case *mimcGnark.MiMC:
b = mimc.GnarkBlockCompression(api, prevState, a)
default:
utils.Panic("unexpected hasher type %T", hasherT)
}

return api.Select(noHash, prevState, b)
}

var (
Expand Down Expand Up @@ -213,10 +227,11 @@ func CheckBatchesSums(api frontend.API, hasher snarkHash.FieldHasher, nbBatches
noHash := api.IsZero(hashLen) // or equivalently, isZero(currNbBytesRemaining)

if i != 0 {
batchSum = api.Select(
noHash,

batchSum = _hsh(
batchSum,
_hsh(batchSum, inputAt(api.Add(31*i, startR), hashLen)),
inputAt(api.Add(31*i, startR), hashLen),
noHash,
)

internal.AssertEqualIf(api, startNext, batchSum, partialSumsT.Lookup(batchI)[0]) // if we're done with the current checksum, check that the claimed one from the table is equal to it
Expand Down
8 changes: 5 additions & 3 deletions prover/crypto/mimc/gkrmimc/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (h *Hasher) Sum() frontend.Variable {
// 1 - Call the compression function in a loop
curr := h.state
for _, stream := range h.data {
curr = h.compress(curr, stream)
curr = h.Compress(curr, stream)
}
// flush the data already hashed
h.data = nil
Expand Down Expand Up @@ -132,10 +132,12 @@ func (h *Hasher) State() []frontend.Variable {
return []frontend.Variable{h.state}
}

// compress calls returns a frontend.Variable holding the result of applying
// Compress calls returns a frontend.Variable holding the result of applying
// the compression function of MiMC over state and block. The alleged returned
// result is pushed on the stack of all the claims to verify.
func (h *Hasher) compress(state, block frontend.Variable) frontend.Variable {
//
// This function does not modify the state of the hasher.
func (h *Hasher) Compress(state, block frontend.Variable) frontend.Variable {

newState, err := h.factory.api.Compiler().NewHint(mimcHintfunc, 1, state, block)
if err != nil {
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
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
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
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
16 changes: 14 additions & 2 deletions prover/symbolic/simplify/cost_stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package simplify

import (
"math/bits"
"sync"

sym "github.com/consensys/linea-monorepo/prover/symbolic"
)
Expand All @@ -21,10 +22,21 @@ func (s *costStats) add(cost costStats) {
// Returns the cost stats of a boarded expression
func evaluateCostStat(expr *sym.Expression) (s costStats) {
board := expr.Board()
var wg sync.WaitGroup
var mu sync.Mutex

for i := 1; i < len(board.Nodes); i++ {
s_ := evaluateNodeCosts(board.Nodes[i]...)
s.add(s_)
wg.Add(1)
go func(nodes []sym.Node) {
defer wg.Done()
s_ := evaluateNodeCosts(nodes...)
mu.Lock()
s.add(s_)
mu.Unlock()
}(board.Nodes[i])
}
wg.Wait()

return s
}

Expand Down
31 changes: 15 additions & 16 deletions prover/symbolic/simplify/factor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math"
"sort"
"sync"

"github.com/consensys/linea-monorepo/prover/maths/field"
sym "github.com/consensys/linea-monorepo/prover/symbolic"
Expand All @@ -17,7 +18,8 @@ import (
func factorizeExpression(expr *sym.Expression, iteration int) *sym.Expression {
res := expr
initEsh := expr.ESHash
alreadyWalked := map[field.Element]*sym.Expression{}
alreadyWalked := sync.Map{}
factorMemo := sync.Map{}

logrus.Infof("factoring expression : init stats %v", evaluateCostStat(expr))

Expand All @@ -26,10 +28,9 @@ func factorizeExpression(expr *sym.Expression, iteration int) *sym.Expression {
scoreInit := evaluateCostStat(res)

res = res.ReconstructBottomUp(func(lincomb *sym.Expression, newChildren []*sym.Expression) *sym.Expression {

// Time save, we reuse the results we got for that particular node.
if ret, ok := alreadyWalked[lincomb.ESHash]; ok {
return ret
if ret, ok := alreadyWalked.Load(lincomb.ESHash); ok {
return ret.(*sym.Expression)
}

// Incorporate the new children inside of the expression to account
Expand All @@ -55,31 +56,29 @@ func factorizeExpression(expr *sym.Expression, iteration int) *sym.Expression {

group := findGdChildrenGroup(new)

logrus.Tracef("found children group: %v\n", group)

if len(group) < 1 {
if k > 0 {
logrus.Tracef("finished factoring : %v opportunities", k)
}
return new
}

logrus.Tracef(
"factoring an expression with a set of %v siblings",
len(group),
)
// Memoize the factorLinCompFromGroup result
cacheKey := fmt.Sprintf("%v-%v", new.ESHash, group)

new = factorLinCompFromGroup(new, group)
if cachedResult, ok := factorMemo.Load(cacheKey); ok {
new = cachedResult.(*sym.Expression)

} else {
new = factorLinCompFromGroup(new, group)
factorMemo.Store(cacheKey, new)
}

if len(new.Children) >= prevSize {
logrus.Tracef("factorization did not help. stopping")
return new
}

prevSize = len(new.Children)
}

logrus.Tracef("finished factoring slow node")
alreadyWalked.Store(new.ESHash, new)
return new
})

Expand Down
25 changes: 16 additions & 9 deletions prover/symbolic/simplify/rmpolyeval.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,27 @@ func removePolyEval(e *sym.Expression) *sym.Expression {
x := newChildren[0]
cs := newChildren[1:]

if len(cs) == 0 {
return oldExpr // Handle edge case where there are no coefficients
}

acc := cs[0]
xPowi := x

// Precompute powers of x
powersOfX := make([]*sym.Expression, len(cs))
powersOfX[0] = x
for i := 1; i < len(cs); i++ {
// We don't use the default constructor because it will collapse the
// intermediate terms into a single term. The intermediates are useful because
// they tell the evaluator to reuse the intermediate terms instead of
// computing x^i for every term.
powersOfX[i] = sym.NewProduct([]*sym.Expression{powersOfX[i-1], x}, []int{1, 1})
}

for i := 1; i < len(cs); i++ {
// Here we want to use the default constructor to ensure that we
// will have a merged sum at the end.
acc = sym.Add(acc, sym.Mul(xPowi, cs[i]))
if i+1 < len(cs) {
// We don't use the default construct because it will collapse the
// xPowi into a single term. The intermediate are useful because
// it tells the evaluator to reuse the intermediate terms instead of
// computing x^i for every term.
xPowi = sym.NewProduct([]*sym.Expression{xPowi, x}, []int{1, 1})
}
acc = sym.Add(acc, sym.Mul(powersOfX[i-1], cs[i]))
}

if oldExpr.ESHash != acc.ESHash {
Expand Down
Loading
Loading