Skip to content

Commit

Permalink
Tweak: RollupID (#1053)
Browse files Browse the repository at this point in the history
* tweak: print rollupid, and use from config in zkevm_api

* tweak(l1sync): disgard logs for wrong rollupid

* tweak(l1sync): discard pre-etrog verifications for rollupid > 1

* fix(l1syncer): sequences post etrog

* rejig of batch closing logic in the sequencer (#1095)

* catch post etrog sequence events

---------

Co-authored-by: hexoscott <70711990+hexoscott@users.noreply.github.com>
Co-authored-by: Scott Fairclough <scott@hexosoft.co.uk>
  • Loading branch information
3 people committed Sep 4, 2024
1 parent 88df27f commit 752bb82
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
6 changes: 2 additions & 4 deletions cmd/rpcdaemon/commands/zkevm_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ import (

var sha3UncleHash = common.HexToHash("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347")

const ApiRollupId = 1 // todo [zkevm] this should be read from config really

// ZkEvmAPI is a collection of functions that are exposed in the
type ZkEvmAPI interface {
ConsolidatedBlockNumber(ctx context.Context) (hexutil.Uint64, error)
Expand Down Expand Up @@ -664,7 +662,7 @@ func (api *ZkEvmAPIImpl) GetBatchByNumber(ctx context.Context, batchNumber rpc.B
}
batch.BatchL2Data = batchL2Data

oldAccInputHash, err := api.l1Syncer.GetOldAccInputHash(ctx, &api.config.AddressRollup, ApiRollupId, batchNo)
oldAccInputHash, err := api.l1Syncer.GetOldAccInputHash(ctx, &api.config.AddressRollup, api.config.L1RollupId, batchNo)
if err != nil {
log.Warn("Failed to get old acc input hash", "err", err)
batch.AccInputHash = common.Hash{}
Expand Down Expand Up @@ -1036,7 +1034,7 @@ func (api *ZkEvmAPIImpl) GetProverInput(ctx context.Context, batchNumber uint64,
return nil, err
}

oldAccInputHash, err := api.l1Syncer.GetOldAccInputHash(ctx, &api.config.AddressRollup, ApiRollupId, batchNumber)
oldAccInputHash, err := api.l1Syncer.GetOldAccInputHash(ctx, &api.config.AddressRollup, api.config.L1RollupId, batchNumber)
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,8 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
cfg.L1HighestBlockType,
)

log.Info("Rollup ID", "rollupId", cfg.L1RollupId)

// check contract addresses in config against L1
if cfg.Zk.L1ContractAddressCheck {
success, err := l1ContractAddressCheck(ctx, cfg.Zk, backend.l1Syncer)
Expand Down
40 changes: 22 additions & 18 deletions zk/stages/stage_l1syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,16 @@ Loop:
for {
select {
case logs := <-logsChan:
infos := make([]*types.L1BatchInfo, 0, len(logs))
batchLogTypes := make([]BatchLogType, 0, len(logs))
for _, l := range logs {
l := l
info, batchLogType := parseLogType(cfg.zkCfg.L1RollupId, &l)
infos = append(infos, &info)
batchLogTypes = append(batchLogTypes, batchLogType)
}

for i, l := range logs {
info := *infos[i]
batchLogType := batchLogTypes[i]
switch batchLogType {
case logSequence:
case logSequenceEtrog:
// prevent storing pre-etrog sequences for etrog rollups
if batchLogType == logSequence && cfg.zkCfg.L1RollupId > 1 {
continue
}
if err := hermezDb.WriteSequence(info.L1BlockNo, info.BatchNo, info.L1TxHash, info.StateRoot); err != nil {
return fmt.Errorf("failed to write batch info, %w", err)
}
Expand All @@ -152,6 +148,11 @@ Loop:
highestWrittenL1BlockNo = info.L1BlockNo
}
case logVerify:
case logVerifyEtrog:
// prevent storing pre-etrog verifications for etrog rollups
if batchLogType == logVerify && cfg.zkCfg.L1RollupId > 1 {
continue
}
if info.BatchNo > highestVerification.BatchNo {
highestVerification = info
}
Expand Down Expand Up @@ -219,17 +220,16 @@ type BatchLogType byte
var (
logUnknown BatchLogType = 0
logSequence BatchLogType = 1
logVerify BatchLogType = 2
logL1InfoTreeUpdate BatchLogType = 4
logRollbackBatches BatchLogType = 5
logSequenceEtrog BatchLogType = 2
logVerify BatchLogType = 3
logVerifyEtrog BatchLogType = 4
logL1InfoTreeUpdate BatchLogType = 5
logRollbackBatches BatchLogType = 6

logIncompatible BatchLogType = 100
)

func parseLogType(l1RollupId uint64, log *ethTypes.Log) (l1BatchInfo types.L1BatchInfo, batchLogType BatchLogType) {
bigRollupId := new(big.Int).SetUint64(l1RollupId)
isRollupIdMatching := log.Topics[1] == common.BigToHash(bigRollupId)

var (
batchNum uint64
stateRoot, l1InfoRoot common.Hash
Expand All @@ -240,24 +240,28 @@ func parseLogType(l1RollupId uint64, log *ethTypes.Log) (l1BatchInfo types.L1Bat
batchLogType = logSequence
batchNum = new(big.Int).SetBytes(log.Topics[1].Bytes()).Uint64()
case contracts.SequencedBatchTopicEtrog:
batchLogType = logSequence
batchLogType = logSequenceEtrog
batchNum = new(big.Int).SetBytes(log.Topics[1].Bytes()).Uint64()
l1InfoRoot = common.BytesToHash(log.Data[:32])
case contracts.VerificationTopicPreEtrog:
batchLogType = logVerify
batchNum = new(big.Int).SetBytes(log.Topics[1].Bytes()).Uint64()
stateRoot = common.BytesToHash(log.Data[:32])
case contracts.VerificationValidiumTopicEtrog:
bigRollupId := new(big.Int).SetUint64(l1RollupId)
isRollupIdMatching := log.Topics[1] == common.BigToHash(bigRollupId)
if isRollupIdMatching {
batchLogType = logVerify
batchLogType = logVerifyEtrog
batchNum = new(big.Int).SetBytes(log.Topics[1].Bytes()).Uint64()
stateRoot = common.BytesToHash(log.Data[:32])
} else {
batchLogType = logIncompatible
}
case contracts.VerificationTopicEtrog:
bigRollupId := new(big.Int).SetUint64(l1RollupId)
isRollupIdMatching := log.Topics[1] == common.BigToHash(bigRollupId)
if isRollupIdMatching {
batchLogType = logVerify
batchLogType = logVerifyEtrog
batchNum = common.BytesToHash(log.Data[:32]).Big().Uint64()
stateRoot = common.BytesToHash(log.Data[32:64])
} else {
Expand Down

0 comments on commit 752bb82

Please sign in to comment.