Skip to content

Commit b359776

Browse files
committed
Merge branch 'upstream/v2.60.0-beta3' into zjg/base-dev-v2.60.0-beta3
2 parents 348755a + 642df8f commit b359776

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1658
-428
lines changed

.github/workflows/ci_zkevm.yml

+4-10
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,10 @@ jobs:
105105
sed -i '/zkevm.sequencer-non-empty-batch-seal-time:/d' templates/cdk-erigon/config.yml
106106
sed -i '/sentry.drop-useless-peers:/d' templates/cdk-erigon/config.yml
107107
108-
- name: Configure Kurtosis CDK
109-
working-directory: ./kurtosis-cdk
110-
run: |
111-
/usr/local/bin/yq -i '.args.data_availability_mode = "${{ matrix.da-mode }}"' params.yml
112-
/usr/local/bin/yq -i '.args.cdk_erigon_node_image = "cdk-erigon:local"' params.yml
113-
114108
- name: Deploy Kurtosis CDK package
115109
working-directory: ./kurtosis-cdk
116-
run: kurtosis run --enclave cdk-v1 --args-file params.yml --image-download always .
110+
run: |
111+
kurtosis run --enclave cdk-v1 --image-download always . '{"args": {"data_availability_mode": "${{ matrix.da-mode }}", "cdk_erigon_node_image": "cdk-erigon:local"}}'
117112
118113
- name: Monitor verified batches
119114
working-directory: ./kurtosis-cdk
@@ -233,8 +228,6 @@ jobs:
233228
- name: Configure Kurtosis CDK
234229
working-directory: ./kurtosis-cdk
235230
run: |
236-
/usr/local/bin/yq -i '.args.cdk_erigon_node_image = "cdk-erigon:local"' params.yml
237-
/usr/local/bin/yq -i '.args.erigon_strict_mode = false' params.yml
238231
sed -i 's/"londonBlock": [0-9]\+/"londonBlock": 0/' ./templates/cdk-erigon/chainspec.json
239232
sed -i 's/"normalcyBlock": [0-9]\+/"normalcyBlock": 0/' ./templates/cdk-erigon/chainspec.json
240233
sed -i 's/"shanghaiTime": [0-9]\+/"shanghaiTime": 0/' ./templates/cdk-erigon/chainspec.json
@@ -243,7 +236,8 @@ jobs:
243236
244237
- name: Deploy Kurtosis CDK package
245238
working-directory: ./kurtosis-cdk
246-
run: kurtosis run --enclave cdk-v1 --args-file params.yml --image-download always .
239+
run: |
240+
kurtosis run --enclave cdk-v1 --image-download always . '{"args": {"erigon_strict_mode": false, "cdk_erigon_node_image": "cdk-erigon:local"}}'
247241
248242
- name: Dynamic gas fee tx load test
249243
working-directory: ./kurtosis-cdk

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ jwt.hex
101101

102102
.tool-versions
103103

104-
*__debug_bin*
104+
**/*__debug_bin*
105105
yarn.lock
106106
node_modules
107107

@@ -116,3 +116,5 @@ data/
116116
start.sh
117117
xlayerconfig-mainnet.yaml
118118
xlayerconfig-testnet.yaml
119+
**/cover.out
120+
**/cover.html

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ For a full explanation of the config options, see below:
198198
Sequencer specific config:
199199
- `zkevm.executor-urls`: A csv list of the executor URLs. These will be used in a round robbin fashion by the sequencer
200200
- `zkevm.executor-strict`: Defaulted to true, but can be set to false when running the sequencer without verifications (use with extreme caution)
201-
- `zkevm.witness-full`: Defaulted to true. Controls whether the full or partial witness is used with the executor.
201+
- `zkevm.witness-full`: Defaulted to false. Controls whether the full or partial witness is used with the executor.
202202
- `zkevm.reject-smart-contract-deployments`: Defaulted to false. Controls whether smart contract deployments are rejected by the TxPool.
203203

204204
Resource Utilisation config:

cmd/integration/commands/stages.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ func stageHashState(db kv.RwDB, ctx context.Context, logger log.Logger) error {
12131213
cfg := stagedsync.StageHashStateCfg(db, dirs, historyV3, agg)
12141214
if unwind > 0 {
12151215
u := sync.NewUnwindState(stages.HashState, s.BlockNumber-unwind, s.BlockNumber)
1216-
err = stagedsync.UnwindHashStateStage(u, s, tx, cfg, ctx, logger)
1216+
err = stagedsync.UnwindHashStateStage(u, s, tx, cfg, ctx, logger, false)
12171217
if err != nil {
12181218
return err
12191219
}

cmd/integration/commands/state_stages.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ func loopIh(db kv.RwDB, ctx context.Context, unwind uint64, logger log.Logger) e
473473
to := execStage.BlockNumber - unwind
474474
_ = sync.SetCurrentStage(stages.HashState)
475475
u := &stagedsync.UnwindState{ID: stages.HashState, UnwindPoint: to}
476-
if err = stagedsync.UnwindHashStateStage(u, stage(sync, tx, nil, stages.HashState), tx, stagedsync.StageHashStateCfg(db, dirs, historyV3, agg), ctx, logger); err != nil {
476+
if err = stagedsync.UnwindHashStateStage(u, stage(sync, tx, nil, stages.HashState), tx, stagedsync.StageHashStateCfg(db, dirs, historyV3, agg), ctx, logger, false); err != nil {
477477
return err
478478
}
479479
_ = sync.SetCurrentStage(stages.IntermediateHashes)

cmd/utils/flags.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ var (
696696
WitnessFullFlag = cli.BoolFlag{
697697
Name: "zkevm.witness-full",
698698
Usage: "Enable/Diable witness full",
699-
Value: true,
699+
Value: false,
700700
}
701701
SyncLimit = cli.UintFlag{
702702
Name: "zkevm.sync-limit",
@@ -733,14 +733,24 @@ var (
733733
Usage: "The multiplier to reduce the SMT depth by when calculating virtual counters",
734734
Value: 0.6,
735735
}
736+
BadBatches = cli.StringFlag{
737+
Name: "zkevm.bad-batches",
738+
Usage: "A comma separated list of batch numbers that are known bad on the L1. These will automatically be marked as bad during L1 recovery",
739+
Value: "",
740+
}
736741
InitialBatchCfgFile = cli.StringFlag{
737742
Name: "zkevm.initial-batch.config",
738743
Usage: "The file that contains the initial (injected) batch data.",
739744
Value: "",
740745
}
746+
InfoTreeUpdateInterval = cli.DurationFlag{
747+
Name: "zkevm.info-tree-update-interval",
748+
Usage: "The interval at which the sequencer checks the L1 for new GER information",
749+
Value: 1 * time.Minute,
750+
}
741751
ACLPrintHistory = cli.IntFlag{
742752
Name: "acl.print-history",
743-
Usage: "Number of entries to print from the ACL history on node startup",
753+
Usage: "Number of entries to print from the ACL history on node start up",
744754
Value: 10,
745755
}
746756
DebugTimers = cli.BoolFlag{
@@ -1433,6 +1443,7 @@ func setNodeUserIdent(ctx *cli.Context, cfg *nodecfg.Config) {
14331443
cfg.UserIdent = identity
14341444
}
14351445
}
1446+
14361447
func setNodeUserIdentCobra(f *pflag.FlagSet, cfg *nodecfg.Config) {
14371448
if identity := f.String(IdentityFlag.Name, IdentityFlag.Value, IdentityFlag.Usage); identity != nil && len(*identity) > 0 {
14381449
cfg.UserIdent = *identity
@@ -1741,7 +1752,7 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config, nodeName, datadir string, l
17411752

17421753
if ctx.String(ChainFlag.Name) == networkname.DevChainName {
17431754
// --dev mode can't use p2p networking.
1744-
//cfg.MaxPeers = 0 // It can have peers otherwise local sync is not possible
1755+
// cfg.MaxPeers = 0 // It can have peers otherwise local sync is not possible
17451756
if !ctx.IsSet(ListenPortFlag.Name) {
17461757
cfg.ListenAddr = ":0"
17471758
}
@@ -1762,7 +1773,7 @@ func SetNodeConfig(ctx *cli.Context, cfg *nodecfg.Config, logger log.Logger) {
17621773

17631774
func SetNodeConfigCobra(cmd *cobra.Command, cfg *nodecfg.Config) {
17641775
flags := cmd.Flags()
1765-
//SetP2PConfig(ctx, &cfg.P2P)
1776+
// SetP2PConfig(ctx, &cfg.P2P)
17661777
setNodeUserIdentCobra(flags, cfg)
17671778
setDataDirCobra(flags, cfg)
17681779
}
@@ -2144,7 +2155,7 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C
21442155
}
21452156

21462157
cfg.Sync.UseSnapshots = ethconfig.UseSnapshotsByChainName(chain)
2147-
if ctx.IsSet(SnapshotFlag.Name) { //force override default by cli
2158+
if ctx.IsSet(SnapshotFlag.Name) { // force override default by cli
21482159
cfg.Sync.UseSnapshots = ctx.Bool(SnapshotFlag.Name)
21492160
}
21502161

@@ -2175,7 +2186,6 @@ func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.C
21752186
webseedsList = append(webseedsList, known...)
21762187
}
21772188
cfg.Downloader, err = downloadercfg2.New(cfg.Dirs, version, lvl, downloadRate, uploadRate, ctx.Int(TorrentPortFlag.Name), ctx.Int(TorrentConnsPerFileFlag.Name), ctx.Int(TorrentDownloadSlotsFlag.Name), libcommon.CliString2Array(ctx.String(TorrentStaticPeersFlag.Name)), webseedsList, chain, true)
2178-
21792189
if err != nil {
21802190
panic(err)
21812191
}

core/vm/contracts_zkevm.go

+54-11
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,34 @@ func (c *bigModExp_zkevm) RequiredGas(input []byte) uint64 {
299299
} else {
300300
input = input[:0]
301301
}
302+
303+
// Retrieve the operands and execute the exponentiation
304+
var (
305+
base = new(big.Int).SetBytes(getData(input, 0, baseLen.Uint64()))
306+
exp = new(big.Int).SetBytes(getData(input, baseLen.Uint64(), expLen.Uint64()))
307+
mod = new(big.Int).SetBytes(getData(input, baseLen.Uint64()+expLen.Uint64(), modLen.Uint64()))
308+
baseBitLen = base.BitLen()
309+
expBitLen = exp.BitLen()
310+
modBitLen = mod.BitLen()
311+
)
312+
313+
// zk special cases
314+
// - if mod = 0 we consume gas as normal
315+
// - if base is 0 and mod < 8192 we consume gas as normal
316+
// - if neither of the above are true we check for reverts and return 0 gas fee
317+
318+
if modBitLen == 0 {
319+
// consume as normal - will return 0
320+
} else if baseBitLen == 0 {
321+
if modBitLen > 8192 {
322+
return 0
323+
} else {
324+
// consume as normal - will return 0
325+
}
326+
} else if baseBitLen > 8192 || expBitLen > 8192 || modBitLen > 8192 {
327+
return 0
328+
}
329+
302330
// Retrieve the head 32 bytes of exp for the adjusted exponent length
303331
var expHead *big.Int
304332
if big.NewInt(int64(len(input))).Cmp(baseLen) <= 0 {
@@ -373,21 +401,36 @@ func (c *bigModExp_zkevm) Run(input []byte) ([]byte, error) {
373401
} else {
374402
input = input[:0]
375403
}
376-
// Handle a special case when both the base and mod length is zero
377-
if baseLen == 0 && modLen == 0 {
378-
return []byte{}, nil
379-
}
404+
380405
// Retrieve the operands and execute the exponentiation
381406
var (
382-
base = new(big.Int).SetBytes(getData(input, 0, baseLen))
383-
exp = new(big.Int).SetBytes(getData(input, baseLen, expLen))
384-
mod = new(big.Int).SetBytes(getData(input, baseLen+expLen, modLen))
385-
v []byte
407+
base = new(big.Int).SetBytes(getData(input, 0, baseLen))
408+
exp = new(big.Int).SetBytes(getData(input, baseLen, expLen))
409+
mod = new(big.Int).SetBytes(getData(input, baseLen+expLen, modLen))
410+
v []byte
411+
baseBitLen = base.BitLen()
412+
expBitLen = exp.BitLen()
413+
modBitLen = mod.BitLen()
386414
)
415+
416+
if modBitLen == 0 {
417+
return []byte{}, nil
418+
}
419+
420+
if baseBitLen == 0 {
421+
if modBitLen > 8192 {
422+
return nil, ErrExecutionReverted
423+
} else {
424+
return common.LeftPadBytes([]byte{}, int(modLen)), nil
425+
}
426+
}
427+
428+
// limit to 8192 bits for base, exp, and mod in ZK
429+
if baseBitLen > 8192 || expBitLen > 8192 || modBitLen > 8192 {
430+
return nil, ErrExecutionReverted
431+
}
432+
387433
switch {
388-
case mod.BitLen() == 0:
389-
// Modulo 0 is undefined, return zero
390-
return common.LeftPadBytes([]byte{}, int(modLen)), nil
391434
case base.Cmp(libcommon.Big1) == 0:
392435
//If base == 1, then we can just return base % mod (if mod >= 1, which it is)
393436
v = base.Mod(base, mod).Bytes()

core/vm/contracts_zkevm_test.go

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package vm
2+
3+
import (
4+
"testing"
5+
"math/big"
6+
)
7+
8+
var (
9+
big0 = big.NewInt(0)
10+
big10 = big.NewInt(10)
11+
big8194 = big.NewInt(0).Lsh(big.NewInt(1), 8194)
12+
)
13+
14+
func Test_ModExpZkevm_Gas(t *testing.T) {
15+
modExp := bigModExp_zkevm{enabled: true, eip2565: true}
16+
17+
cases := map[string]struct {
18+
base *big.Int
19+
exp *big.Int
20+
mod *big.Int
21+
expected uint64
22+
}{
23+
"simple test": {big10, big10, big10, 200},
24+
"0 mod - normal gas": {big10, big10, big0, 200},
25+
"base 0 - mod < 8192 - normal gas": {big0, big10, big10, 200},
26+
"base 0 - mod > 8192 - 0 gas": {big0, big10, big8194, 0},
27+
"base over 8192 - 0 gas": {big8194, big10, big10, 0},
28+
"exp over 8192 - 0 gas": {big10, big8194, big10, 0},
29+
"mod over 8192 - 0 gas": {big10, big10, big8194, 0},
30+
}
31+
32+
for name, test := range cases {
33+
t.Run(name, func(t *testing.T) {
34+
input := make([]byte, 0)
35+
36+
base := len(test.base.Bytes())
37+
exp := len(test.exp.Bytes())
38+
mod := len(test.mod.Bytes())
39+
40+
input = append(input, uint64To32Bytes(base)...)
41+
input = append(input, uint64To32Bytes(exp)...)
42+
input = append(input, uint64To32Bytes(mod)...)
43+
input = append(input, uint64ToDeterminedBytes(test.base, base)...)
44+
input = append(input, uint64ToDeterminedBytes(test.exp, exp)...)
45+
input = append(input, uint64ToDeterminedBytes(test.mod, mod)...)
46+
47+
gas := modExp.RequiredGas(input)
48+
49+
if gas != test.expected {
50+
t.Errorf("Expected %d, got %d", test.expected, gas)
51+
}
52+
})
53+
}
54+
}
55+
56+
func uint64To32Bytes(input int) []byte {
57+
bigInt := new(big.Int).SetUint64(uint64(input))
58+
bytes := bigInt.Bytes()
59+
result := make([]byte, 32)
60+
copy(result[32-len(bytes):], bytes)
61+
return result
62+
}
63+
64+
func uint64ToDeterminedBytes(input *big.Int, length int) []byte {
65+
bytes := input.Bytes()
66+
result := make([]byte, length)
67+
copy(result[length-len(bytes):], bytes)
68+
return result
69+
}

eth/backend.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ import (
132132
"github.com/ledgerwatch/erigon/zk/datastream/client"
133133
"github.com/ledgerwatch/erigon/zk/hermez_db"
134134
"github.com/ledgerwatch/erigon/zk/l1_cache"
135+
"github.com/ledgerwatch/erigon/zk/l1infotree"
135136
"github.com/ledgerwatch/erigon/zk/legacy_executor_verifier"
136137
zkStages "github.com/ledgerwatch/erigon/zk/stages"
137138
"github.com/ledgerwatch/erigon/zk/syncer"
@@ -1103,6 +1104,8 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
11031104
cfg.L1HighestBlockType,
11041105
)
11051106

1107+
l1InfoTreeUpdater := l1infotree.NewUpdater(cfg.Zk, l1InfoTreeSyncer)
1108+
11061109
if isSequencer {
11071110
// if we are sequencing transactions, we do the sequencing loop...
11081111
witnessGenerator := witness.NewGenerator(
@@ -1173,11 +1176,11 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
11731176
backend.dataStream,
11741177
backend.l1Syncer,
11751178
seqVerSyncer,
1176-
l1InfoTreeSyncer,
11771179
l1BlockSyncer,
11781180
backend.txPool2,
11791181
backend.txPool2DB,
11801182
verifier,
1183+
l1InfoTreeUpdater,
11811184
)
11821185

11831186
backend.syncUnwindOrder = zkStages.ZkSequencerUnwindOrder
@@ -1211,9 +1214,9 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
12111214
backend.forkValidator,
12121215
backend.engine,
12131216
backend.l1Syncer,
1214-
l1InfoTreeSyncer,
12151217
streamClient,
12161218
backend.dataStream,
1219+
l1InfoTreeUpdater,
12171220
)
12181221

12191222
backend.syncUnwindOrder = zkStages.ZkUnwindOrder

eth/ethconfig/config_zkevm.go

+3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ type Zk struct {
9292

9393
// For X Layer
9494
XLayer XLayerConfig
95+
96+
InfoTreeUpdateInterval time.Duration
97+
BadBatches []uint64
9598
}
9699

97100
var DefaultZkConfig = Zk{

eth/stagedsync/default_stages.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func DefaultStages(ctx context.Context,
138138
return SpawnHashStateStage(s, txc.Tx, hashState, ctx, logger)
139139
},
140140
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
141-
return UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger)
141+
return UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger, false)
142142
},
143143
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx, logger log.Logger) error {
144144
return PruneHashStateStage(p, tx, hashState, ctx)
@@ -318,7 +318,7 @@ func PipelineStages(ctx context.Context, snapshots SnapshotsCfg, blockHashCfg Bl
318318
return SpawnHashStateStage(s, txc.Tx, hashState, ctx, logger)
319319
},
320320
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
321-
return UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger)
321+
return UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger, false)
322322
},
323323
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx, logger log.Logger) error {
324324
return PruneHashStateStage(p, tx, hashState, ctx)
@@ -527,7 +527,7 @@ func UploaderPipelineStages(ctx context.Context, snapshots SnapshotsCfg, headers
527527
return SpawnHashStateStage(s, txc.Tx, hashState, ctx, logger)
528528
},
529529
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
530-
return UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger)
530+
return UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger, false)
531531
},
532532
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx, logger log.Logger) error {
533533
return PruneHashStateStage(p, tx, hashState, ctx)
@@ -701,7 +701,7 @@ func StateStages(ctx context.Context, headers HeadersCfg, bodies BodiesCfg, bloc
701701
return SpawnHashStateStage(s, txc.Tx, hashState, ctx, logger)
702702
},
703703
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
704-
return UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger)
704+
return UnwindHashStateStage(u, s, txc.Tx, hashState, ctx, logger, false)
705705
},
706706
},
707707
{

0 commit comments

Comments
 (0)