Skip to content

Commit

Permalink
Add mock witness generation stable 2.0 (#1440)
Browse files Browse the repository at this point in the history
* cherry-pick b0ceb0d

* chore: remove logging of index for mock witness generation

* feat: log start and end block number, instead of each block for mock witness
  • Loading branch information
MorettiGeorgiev authored Nov 11, 2024
1 parent eddaa9a commit 61114d6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,11 @@ var (
Usage: "Seal the batch immediately when detecting a counter overflow",
Value: false,
}
MockWitnessGeneration = cli.BoolFlag{
Name: "zkevm.mock-witness-generation",
Usage: "Mock the witness generation",
Value: false,
}
ACLPrintHistory = cli.IntFlag{
Name: "acl.print-history",
Usage: "Number of entries to print from the ACL history on node start up",
Expand Down
1 change: 1 addition & 0 deletions eth/ethconfig/config_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type Zk struct {
InfoTreeUpdateInterval time.Duration
BadBatches []uint64
SealBatchImmediatelyOnOverflow bool
MockWitnessGeneration bool
}

var DefaultZkConfig = &Zk{}
Expand Down
1 change: 1 addition & 0 deletions turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,5 @@ var DefaultFlags = []cli.Flag{
&utils.InfoTreeUpdateInterval,
&utils.BadBatches,
&utils.SealBatchImmediatelyOnOverflow,
&utils.MockWitnessGeneration,
}
5 changes: 2 additions & 3 deletions turbo/cli/flags_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package cli
import (
"fmt"
"math"

"strconv"
"strings"

"time"

libcommon "github.com/gateway-fm/cdk-erigon-lib/common"
Expand All @@ -14,7 +13,6 @@ import (
"github.com/ledgerwatch/erigon/zk/sequencer"
utils2 "github.com/ledgerwatch/erigon/zk/utils"
"github.com/urfave/cli/v2"
"strconv"
)

func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {
Expand Down Expand Up @@ -197,6 +195,7 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {
InfoTreeUpdateInterval: ctx.Duration(utils.InfoTreeUpdateInterval.Name),
BadBatches: badBatches,
SealBatchImmediatelyOnOverflow: ctx.Bool(utils.SealBatchImmediatelyOnOverflow.Name),
MockWitnessGeneration: ctx.Bool(utils.MockWitnessGeneration.Name),
}

utils2.EnableTimer(cfg.DebugTimers)
Expand Down
25 changes: 24 additions & 1 deletion zk/witness/witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ func (g *Generator) generateWitness(tx kv.Tx, ctx context.Context, batchNum uint
log.Info("Generating witness timing", "batch", batchNum, "blockFrom", blocks[0].NumberU64(), "blockTo", blocks[len(blocks)-1].NumberU64(), "taken", diff)
}()

areExecutorUrlsEmpty := len(g.zkConfig.ExecutorUrls) == 0 || g.zkConfig.ExecutorUrls[0] == ""
shouldGenerateMockWitness := g.zkConfig.MockWitnessGeneration && areExecutorUrlsEmpty
if shouldGenerateMockWitness {
return g.generateMockWitness(batchNum, blocks, debug)
}

endBlock := blocks[len(blocks)-1].NumberU64()
startBlock := blocks[0].NumberU64()

Expand Down Expand Up @@ -325,7 +331,6 @@ func (g *Generator) generateWitness(tx kv.Tx, ctx context.Context, batchNum uint
chainReader := stagedsync.NewChainReaderImpl(g.chainCfg, tx, nil)

_, err = core.ExecuteBlockEphemerallyZk(g.chainCfg, &vmConfig, getHashFn, engine, block, tds, trieStateWriter, chainReader, nil, hermezDb, &prevStateRoot)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -363,3 +368,21 @@ func getWitnessBytes(witness *trie.Witness, debug bool) ([]byte, error) {
}
return buf.Bytes(), nil
}

func (g *Generator) generateMockWitness(batchNum uint64, blocks []*eritypes.Block, debug bool) ([]byte, error) {
mockWitness := []byte("mockWitness")
startBlockNumber := blocks[0].NumberU64()
endBlockNumber := blocks[len(blocks)-1].NumberU64()

if debug {
log.Info(
"Generated mock witness",
"witness", mockWitness,
"batch", batchNum,
"startBlockNumber", startBlockNumber,
"endBlockNumber", endBlockNumber,
)
}

return mockWitness, nil
}

0 comments on commit 61114d6

Please sign in to comment.