From d205cafb2fa7adde27d67a159230fbf8f201b151 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Thu, 3 Jun 2021 17:34:46 +0300 Subject: [PATCH 1/4] fix(sync-service): prevent underflows --- l2geth/rollup/sync_service.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/l2geth/rollup/sync_service.go b/l2geth/rollup/sync_service.go index 98460aa7387a..e2a7a3a668f5 100644 --- a/l2geth/rollup/sync_service.go +++ b/l2geth/rollup/sync_service.go @@ -244,8 +244,12 @@ func (s *SyncService) initializeLatestL1(ctcDeployHeight *big.Int) error { s.SetLatestL1Timestamp(context.Timestamp) s.SetLatestL1BlockNumber(context.BlockNumber) } else { + // Prevent underflows + if *index != 0 { + *index = *index - 1 + } log.Info("Found latest index", "index", *index) - block := s.bc.GetBlockByNumber(*index - 1) + block := s.bc.GetBlockByNumber(*index) if block == nil { block = s.bc.CurrentBlock() idx := block.Number().Uint64() @@ -254,11 +258,12 @@ func (s *SyncService) initializeLatestL1(ctcDeployHeight *big.Int) error { return fmt.Errorf("Current block height greater than index") } s.SetLatestIndex(&idx) - log.Info("Block not found, resetting index", "new", idx, "old", *index-1) + log.Info("Block not found, resetting index", "new", idx, "old", *index) } txs := block.Transactions() if len(txs) != 1 { - log.Error("Unexpected number of transactions in block: %d", len(txs)) + log.Error("Unexpected number of transactions in block", "count", len(txs)) + panic("Cannot recover OVM Context") } tx := txs[0] s.SetLatestL1Timestamp(tx.L1Timestamp()) From 072e640c3b321248574e244fb64e476e6b558291 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Thu, 3 Jun 2021 17:39:20 +0300 Subject: [PATCH 2/4] chore: add changeset --- .changeset/kind-houses-rush.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/kind-houses-rush.md diff --git a/.changeset/kind-houses-rush.md b/.changeset/kind-houses-rush.md new file mode 100644 index 000000000000..1819a8f8c93e --- /dev/null +++ b/.changeset/kind-houses-rush.md @@ -0,0 +1,5 @@ +--- +'@eth-optimism/l2geth': patch +--- + +fix potential underflow when launching the chain when the last verified index is 0 From fe25d594a90402992b57de26d32b7d114c5e347f Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Thu, 3 Jun 2021 17:42:09 +0300 Subject: [PATCH 3/4] chore: remove dead confirmation depth --- l2geth/rollup/sync_service.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/l2geth/rollup/sync_service.go b/l2geth/rollup/sync_service.go index e2a7a3a668f5..473acff61afe 100644 --- a/l2geth/rollup/sync_service.go +++ b/l2geth/rollup/sync_service.go @@ -53,7 +53,6 @@ type SyncService struct { syncing atomic.Value chainHeadSub event.Subscription OVMContext OVMContext - confirmationDepth uint64 pollInterval time.Duration timestampRefreshThreshold time.Duration chainHeadCh chan core.ChainHeadEvent @@ -103,7 +102,6 @@ func NewSyncService(ctx context.Context, cfg Config, txpool *core.TxPool, bc *co cancel: cancel, verifier: cfg.IsVerifier, enable: cfg.Eth1SyncServiceEnable, - confirmationDepth: cfg.Eth1ConfirmationDepth, syncing: atomic.Value{}, bc: bc, txpool: txpool, From 4077c03fb92af9cc527f192d075da6f3356a33c7 Mon Sep 17 00:00:00 2001 From: Georgios Konstantopoulos Date: Thu, 3 Jun 2021 17:46:49 +0300 Subject: [PATCH 4/4] chore: remove eth1conf depth from rollup config --- l2geth/rollup/config.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/l2geth/rollup/config.go b/l2geth/rollup/config.go index 22d9b3f35ce5..2ce695201645 100644 --- a/l2geth/rollup/config.go +++ b/l2geth/rollup/config.go @@ -10,8 +10,6 @@ import ( type Config struct { // Maximum calldata size for a Queue Origin Sequencer Tx MaxCallDataSize int - // Number of confs before applying a L1 to L2 tx - Eth1ConfirmationDepth uint64 // Verifier mode IsVerifier bool // Enable the sync service