From a5c53622112777aea858190cfd6be6528406f71e Mon Sep 17 00:00:00 2001 From: Advaita Saha Date: Tue, 10 Jun 2025 17:16:26 +0200 Subject: [PATCH 1/4] add the block validation check --- execution_chain/constants.nim | 4 ++++ execution_chain/core/executor/process_block.nim | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/execution_chain/constants.nim b/execution_chain/constants.nim index 7fb60cdd66..4fa3a43776 100644 --- a/execution_chain/constants.nim +++ b/execution_chain/constants.nim @@ -103,4 +103,8 @@ const HISTORY_STORAGE_ADDRESS* = address"0x0000F90827F1C53a10cb7A02335B175320002935" WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS* = address"0x00000961Ef480Eb55e80D19ad83579A64c007002" CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS* = address"0x0000BBdDc7CE488642fb579F8B00f3a590007251" + + MAX_BLOCK_SIZE = 10_485_760 # 10 MiB + SAFETY_MARGIN = 2_097_152 # 2 MiB + MAX_RLP_BLOCK_SIZE = MAX_BLOCK_SIZE - SAFETY_MARGIN # End diff --git a/execution_chain/core/executor/process_block.nim b/execution_chain/core/executor/process_block.nim index ce1b0262db..3f830fc95e 100644 --- a/execution_chain/core/executor/process_block.nim +++ b/execution_chain/core/executor/process_block.nim @@ -118,6 +118,10 @@ proc procBlkPreamble( if blk.transactions.calcTxRoot != header.txRoot: return err("Mismatched txRoot") + if com.isOsakaOrLater(header.timestamp): + if rlp.getEncodedLength(blk) > MAX_RLP_BLOCK_SIZE: + return err("Post-Osaka block exceeded MAX_RLP_BLOCK_SIZE") + if com.isPragueOrLater(header.timestamp): if header.requestsHash.isNone: return err("Post-Prague block header must have requestsHash") From 08816a3d9f6ab0bec2586c9a8f79ff7d74559fa5 Mon Sep 17 00:00:00 2001 From: Advaita Saha Date: Wed, 11 Jun 2025 09:50:47 +0200 Subject: [PATCH 2/4] restrict block production to 10MB --- execution_chain/constants.nim | 6 +++--- execution_chain/core/executor/process_block.nim | 1 + execution_chain/core/tx_pool.nim | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/execution_chain/constants.nim b/execution_chain/constants.nim index 4fa3a43776..82785ddb7e 100644 --- a/execution_chain/constants.nim +++ b/execution_chain/constants.nim @@ -104,7 +104,7 @@ const WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS* = address"0x00000961Ef480Eb55e80D19ad83579A64c007002" CONSOLIDATION_REQUEST_PREDEPLOY_ADDRESS* = address"0x0000BBdDc7CE488642fb579F8B00f3a590007251" - MAX_BLOCK_SIZE = 10_485_760 # 10 MiB - SAFETY_MARGIN = 2_097_152 # 2 MiB - MAX_RLP_BLOCK_SIZE = MAX_BLOCK_SIZE - SAFETY_MARGIN + MAX_BLOCK_SIZE* = 10_485_760 # 10 MiB + SAFETY_MARGIN* = 2_097_152 # 2 MiB + MAX_RLP_BLOCK_SIZE* = MAX_BLOCK_SIZE - SAFETY_MARGIN # End diff --git a/execution_chain/core/executor/process_block.nim b/execution_chain/core/executor/process_block.nim index 3f830fc95e..0d664647c8 100644 --- a/execution_chain/core/executor/process_block.nim +++ b/execution_chain/core/executor/process_block.nim @@ -12,6 +12,7 @@ import ../../common/common, + ../../constants, ../../utils/utils, ../../constants, ../../db/ledger, diff --git a/execution_chain/core/tx_pool.nim b/execution_chain/core/tx_pool.nim index efba068c3f..009cf87956 100644 --- a/execution_chain/core/tx_pool.nim +++ b/execution_chain/core/tx_pool.nim @@ -159,9 +159,13 @@ proc assembleBlock*( blobsBundle = BlobsBundle( wrapperVersion: getWrapperVersion(com, blk.header.timestamp) ) + currentRlpSize = rlp.getEncodedLength(blk.header) + rlp.getEncodedLength(blk.withdrawals) for item in pst.packedTxs: let tx = item.pooledTx + if currentRlpSize > MAX_RLP_BLOCK_SIZE: + break + currentRlpSize = currentRlpSize + rlp.getEncodedLength(tx.tx) blk.txs.add tx.tx if tx.blobsBundle != nil: doAssert(tx.blobsBundle.wrapperVersion == blobsBundle.wrapperVersion) From bdf2591cfb6fb2bbf6f39129d51367f8d133373b Mon Sep 17 00:00:00 2001 From: Advaita Saha Date: Wed, 11 Jun 2025 12:27:08 +0200 Subject: [PATCH 3/4] temp fix --- execution_chain/core/tx_pool.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/execution_chain/core/tx_pool.nim b/execution_chain/core/tx_pool.nim index 009cf87956..0844e87857 100644 --- a/execution_chain/core/tx_pool.nim +++ b/execution_chain/core/tx_pool.nim @@ -163,7 +163,7 @@ proc assembleBlock*( for item in pst.packedTxs: let tx = item.pooledTx - if currentRlpSize > MAX_RLP_BLOCK_SIZE: + if currentRlpSize > MAX_RLP_BLOCK_SIZE - 10: break currentRlpSize = currentRlpSize + rlp.getEncodedLength(tx.tx) blk.txs.add tx.tx From 6c962ce18421f12882acdc3f850504f90456c01e Mon Sep 17 00:00:00 2001 From: Advaita Saha Date: Fri, 13 Jun 2025 16:19:08 +0200 Subject: [PATCH 4/4] Update execution_chain/core/tx_pool.nim --- execution_chain/core/tx_pool.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/execution_chain/core/tx_pool.nim b/execution_chain/core/tx_pool.nim index 0844e87857..94bbee7ef4 100644 --- a/execution_chain/core/tx_pool.nim +++ b/execution_chain/core/tx_pool.nim @@ -163,7 +163,7 @@ proc assembleBlock*( for item in pst.packedTxs: let tx = item.pooledTx - if currentRlpSize > MAX_RLP_BLOCK_SIZE - 10: + if currentRlpSize > MAX_RLP_BLOCK_SIZE - 7: break currentRlpSize = currentRlpSize + rlp.getEncodedLength(tx.tx) blk.txs.add tx.tx