From 13fab2cb865be2ca6792b9fa432c22df59701d4e Mon Sep 17 00:00:00 2001 From: hexoscott <70711990+hexoscott@users.noreply.github.com> Date: Wed, 28 Aug 2024 09:59:16 +0100 Subject: [PATCH] fix for using an info tree index with a re-used L1 block hash (#1041) --- core/state/intra_block_state_zkevm.go | 1 - zk/hermez_db/db.go | 25 ------------------------- zk/stages/stage_batches.go | 24 ++---------------------- 3 files changed, 2 insertions(+), 48 deletions(-) diff --git a/core/state/intra_block_state_zkevm.go b/core/state/intra_block_state_zkevm.go index 654b19d7b2f..c39287f3ff4 100644 --- a/core/state/intra_block_state_zkevm.go +++ b/core/state/intra_block_state_zkevm.go @@ -31,7 +31,6 @@ type ReadOnlyHermezDb interface { GetBatchGlobalExitRoots(fromBatchNum, toBatchNum uint64) (*[]dstypes.GerUpdate, error) GetBlockGlobalExitRoot(l2BlockNo uint64) (libcommon.Hash, error) GetBlockL1BlockHash(l2BlockNo uint64) (libcommon.Hash, error) - GetGerForL1BlockHash(l1BlockHash libcommon.Hash) (libcommon.Hash, error) GetIntermediateTxStateRoot(blockNum uint64, txhash libcommon.Hash) (libcommon.Hash, error) GetReusedL1InfoTreeIndex(blockNum uint64) (bool, error) GetSequenceByBatchNo(batchNo uint64) (*zktypes.L1BatchInfo, error) diff --git a/zk/hermez_db/db.go b/zk/hermez_db/db.go index 2adbf23cee7..4759133d7fc 100644 --- a/zk/hermez_db/db.go +++ b/zk/hermez_db/db.go @@ -694,19 +694,6 @@ func (db *HermezDb) DeleteReusedL1InfoTreeIndexes(fromBlock, toBlock uint64) err return nil } -func (db *HermezDb) WriteGerForL1BlockHash(l1BlockHash common.Hash, ger common.Hash) error { - return db.tx.Put(L1_BLOCK_HASH_GER, l1BlockHash.Bytes(), ger.Bytes()) -} - -func (db *HermezDbReader) GetGerForL1BlockHash(l1BlockHash common.Hash) (common.Hash, error) { - bytes, err := db.tx.GetOne(L1_BLOCK_HASH_GER, l1BlockHash.Bytes()) - if err != nil { - return common.Hash{}, err - } - - return common.BytesToHash(bytes), nil -} - func (db *HermezDb) DeleteL1BlockHashGers(l1BlockHashes *[]common.Hash) error { for _, l1BlockHash := range *l1BlockHashes { err := db.tx.Delete(L1_BLOCK_HASH_GER, l1BlockHash.Bytes()) @@ -718,18 +705,6 @@ func (db *HermezDb) DeleteL1BlockHashGers(l1BlockHashes *[]common.Hash) error { return nil } -func (db *HermezDb) WriteL1BlockHash(l1BlockHash common.Hash) error { - return db.tx.Put(L1_BLOCK_HASHES, l1BlockHash.Bytes(), []byte{1}) -} - -func (db *HermezDbReader) CheckL1BlockHashWritten(l1BlockHash common.Hash) (bool, error) { - bytes, err := db.tx.GetOne(L1_BLOCK_HASHES, l1BlockHash.Bytes()) - if err != nil { - return false, err - } - return len(bytes) > 0, nil -} - func (db *HermezDb) DeleteL1BlockHashes(l1BlockHashes *[]common.Hash) error { for _, l1BlockHash := range *l1BlockHashes { err := db.tx.Delete(L1_BLOCK_HASHES, l1BlockHash.Bytes()) diff --git a/zk/stages/stage_batches.go b/zk/stages/stage_batches.go index cbce1c28be9..a565bae4e63 100644 --- a/zk/stages/stage_batches.go +++ b/zk/stages/stage_batches.go @@ -60,10 +60,7 @@ type HermezDb interface { DeleteReusedL1InfoTreeIndexes(fromBlockNum, toBlockNum uint64) error WriteBlockL1BlockHash(l2BlockNo uint64, l1BlockHash common.Hash) error DeleteBlockL1BlockHashes(fromBlockNum, toBlockNum uint64) error - WriteL1BlockHash(l1BlockHash common.Hash) error - CheckL1BlockHashWritten(l1BlockHash common.Hash) (bool, error) DeleteL1BlockHashes(l1BlockHashes *[]common.Hash) error - WriteGerForL1BlockHash(l1BlockHash, ger common.Hash) error DeleteL1BlockHashGers(l1BlockHashes *[]common.Hash) error WriteBatchGlobalExitRoot(batchNumber uint64, ger *types.GerUpdate) error WriteIntermediateTxStateRoot(l2BlockNumber uint64, txHash common.Hash, rpcRoot common.Hash) error @@ -816,25 +813,8 @@ func writeL2Block(eriDb ErigonDb, hermezDb HermezDb, l2Block *types.FullL2Block, } if l2Block.L1BlockHash != emptyHash { - l1BlockHashWritten, err := hermezDb.CheckL1BlockHashWritten(l2Block.L1BlockHash) - if err != nil { - return fmt.Errorf("get global exit root error: %v", err) - } - - if !l1BlockHashWritten { - if err := hermezDb.WriteBlockL1BlockHash(l2Block.L2BlockNumber, l2Block.L1BlockHash); err != nil { - return fmt.Errorf("write block global exit root error: %v", err) - } - - if err := hermezDb.WriteL1BlockHash(l2Block.L1BlockHash); err != nil { - return fmt.Errorf("write global exit root error: %v", err) - } - - if l2Block.GlobalExitRoot != emptyHash { - if err := hermezDb.WriteGerForL1BlockHash(l2Block.L1BlockHash, l2Block.GlobalExitRoot); err != nil { - return fmt.Errorf("write ger for l1 block hash error: %v", err) - } - } + if err := hermezDb.WriteBlockL1BlockHash(l2Block.L2BlockNumber, l2Block.L1BlockHash); err != nil { + return fmt.Errorf("write block global exit root error: %v", err) } }