Skip to content

Commit

Permalink
tweak(l1sync): discard pre-etrog verifications for rollupid > 1
Browse files Browse the repository at this point in the history
  • Loading branch information
revitteth committed Aug 29, 2024
1 parent 4409b4f commit 7cb30b0
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions zk/stages/stage_l1syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,9 @@ 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:
if err := hermezDb.WriteSequence(info.L1BlockNo, info.BatchNo, info.L1TxHash, info.StateRoot); err != nil {
Expand All @@ -145,6 +136,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 @@ -213,24 +209,18 @@ var (
logUnknown BatchLogType = 0
logSequence BatchLogType = 1
logVerify BatchLogType = 2
logVerifyEtrog BatchLogType = 3
logL1InfoTreeUpdate BatchLogType = 4

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
)

if l1RollupId != 1 && isRollupIdMatching == false {
return types.L1BatchInfo{}, logIncompatible
}

switch log.Topics[0] {
case contracts.SequencedBatchTopicPreEtrog:
batchLogType = logSequence
Expand All @@ -244,16 +234,20 @@ func parseLogType(l1RollupId uint64, log *ethTypes.Log) (l1BatchInfo types.L1Bat
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 7cb30b0

Please sign in to comment.