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

Tweak: RollupID #1053

Merged
merged 7 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
6 changes: 2 additions & 4 deletions cmd/rpcdaemon/commands/zkevm_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,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 @@ -676,7 +674,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 @@ -1048,7 +1046,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 @@ -846,6 +846,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
37 changes: 20 additions & 17 deletions zk/stages/stage_l1syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,15 @@ 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:
// 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 @@ -150,6 +145,11 @@ Loop:
}
newSequencesCount++
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 @@ -220,16 +220,15 @@ type BatchLogType byte
var (
logUnknown BatchLogType = 0
logSequence BatchLogType = 1
logVerify BatchLogType = 2
logL1InfoTreeUpdate BatchLogType = 4
logSequenceEtrog BatchLogType = 2
logVerify BatchLogType = 3
logVerifyEtrog BatchLogType = 4
logL1InfoTreeUpdate BatchLogType = 5

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 +239,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
Loading