Skip to content

Commit

Permalink
Add sanity-check on checkL1InfoTreeUpdate to check state L1 blockhash…
Browse files Browse the repository at this point in the history
… matches ethereum blockhash (L1 reorg check) (0xPolygonHermez#3480)

* Add sanity check on checkL1InfoTreeUpdate to check state L1 blockhash matches ethereum blockhash (L1 reorg check)

* fix L1 block is 0 (empty l1infotree)

* Update Prover image to v5.0.9
  • Loading branch information
agnusmor authored Mar 25, 2024
1 parent 6c76bf4 commit 968568f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ services:
zkevm-prover:
container_name: zkevm-prover
restart: unless-stopped
image: hermeznetwork/zkevm-prover:v5.0.6
image: hermeznetwork/zkevm-prover:v5.0.9
depends_on:
zkevm-state-db:
condition: service_healthy
Expand Down
35 changes: 31 additions & 4 deletions sequencer/finalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,19 @@ func (f *finalizer) updateFlushIDs(newPendingFlushID, newStoredFlushID uint64) {

func (f *finalizer) checkL1InfoTreeUpdate(ctx context.Context) {
firstL1InfoRootUpdate := true
skipFirstSleep := true

for {
if skipFirstSleep {
skipFirstSleep = false
} else {
time.Sleep(f.cfg.L1InfoTreeCheckInterval.Duration)
}

lastL1BlockNumber, err := f.etherman.GetLatestBlockNumber(ctx)
if err != nil {
log.Errorf("error getting latest L1 block number, error: %v", err)
continue
}

maxBlockNumber := uint64(0)
Expand All @@ -246,9 +254,30 @@ func (f *finalizer) checkL1InfoTreeUpdate(ctx context.Context) {
}

if firstL1InfoRootUpdate || l1InfoRoot.L1InfoTreeIndex > f.lastL1InfoTree.L1InfoTreeIndex {
firstL1InfoRootUpdate = false
log.Infof("received new L1InfoRoot, l1InfoTreeIndex: %d, l1InfoTreeRoot: %s, l1Block: %d",
l1InfoRoot.L1InfoTreeIndex, l1InfoRoot.L1InfoTreeRoot, l1InfoRoot.BlockNumber)

log.Debugf("received new L1InfoRoot. L1InfoTreeIndex: %d", l1InfoRoot.L1InfoTreeIndex)
// Sanity check l1BlockState (l1InfoRoot.BlockNumber) blockhash matches blockhash on ethereum. We skip it if l1InfoRoot.BlockNumber == 0 (empty tree)
if l1InfoRoot.BlockNumber > 0 {
l1BlockState, err := f.stateIntf.GetBlockByNumber(ctx, l1InfoRoot.BlockNumber, nil)
if err != nil {
log.Errorf("error getting L1 block %d from the state, error: %v", l1InfoRoot.BlockNumber, err)
continue
}

l1BlockEth, err := f.etherman.HeaderByNumber(ctx, new(big.Int).SetUint64(l1InfoRoot.BlockNumber))
if err != nil {
log.Errorf("error getting L1 block %d from ethereum, error: %v", l1InfoRoot.BlockNumber, err)
continue
}
if l1BlockState.BlockHash != l1BlockEth.Hash() {
log.Warnf("skipping use of l1InfoTreeIndex %d, L1 block %d blockhash %s doesn't match blockhash on ethereum %s (L1 reorg?)",
l1InfoRoot.L1InfoTreeIndex, l1InfoRoot.BlockNumber, l1BlockState.BlockHash, l1BlockEth.Hash())
continue
}
}

firstL1InfoRootUpdate = false

f.lastL1InfoTreeMux.Lock()
f.lastL1InfoTree = l1InfoRoot
Expand All @@ -261,8 +290,6 @@ func (f *finalizer) checkL1InfoTreeUpdate(ctx context.Context) {
f.lastL1InfoTreeCond.L.Unlock()
}
}

time.Sleep(f.cfg.L1InfoTreeCheckInterval.Duration)
}
}

Expand Down
1 change: 1 addition & 0 deletions sequencer/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type etherman interface {
TrustedSequencer() (common.Address, error)
GetLatestBatchNumber() (uint64, error)
GetLatestBlockNumber(ctx context.Context) (uint64, error)
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
}

// stateInterface gathers the methods required to interact with the state.
Expand Down
33 changes: 33 additions & 0 deletions sequencer/mock_etherman.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ services:

zkevm-prover:
container_name: zkevm-prover
image: hermeznetwork/zkevm-prover:v5.0.6
image: hermeznetwork/zkevm-prover:v5.0.9
ports:
- 50061:50061 # MT
- 50071:50071 # Executor
Expand Down Expand Up @@ -602,7 +602,7 @@ services:

zkevm-permissionless-prover:
container_name: zkevm-permissionless-prover
image: hermeznetwork/zkevm-prover:v5.0.6
image: hermeznetwork/zkevm-prover:v5.0.9
ports:
# - 50058:50058 # Prover
- 50059:50052 # Mock prover
Expand Down

0 comments on commit 968568f

Please sign in to comment.