Skip to content

EIP-7934 #3376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions execution_chain/constants.nim
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,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
5 changes: 5 additions & 0 deletions execution_chain/core/executor/process_block.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import
../../common/common,
../../constants,
../../utils/utils,
../../constants,
../../db/ledger,
Expand Down Expand Up @@ -118,6 +119,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")
Expand Down
4 changes: 4 additions & 0 deletions execution_chain/core/tx_pool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,13 @@ proc assembleBlock*(
blobsBundle = BlobsBundle(
wrapperVersion: getWrapperVersion(com, blk.header.timestamp)
)
currentRlpSize = rlp.getEncodedLength(blk.header) + rlp.getEncodedLength(blk.withdrawals)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blk.withdrawals = Opt.some(xp.withdrawals)

withdrawals are fork dependant.


for item in pst.packedTxs:
let tx = item.pooledTx
if currentRlpSize > MAX_RLP_BLOCK_SIZE - 7:
break
currentRlpSize = currentRlpSize + rlp.getEncodedLength(tx.tx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calculating the rlp length like this might works to some extent. But considering how rlp algorithm works, there are and there will be edge cases where this calculation will produce invalid result. To produce a reliable result for all cases, we need a specially crafted getEncodedLength or we make a compromise to never exceeds the dangerous limit.

And that dangerous limit is MAX_RLP_BLOCK_SIZE - 5. The 5 represent the maximum number of bytes might be produced by the rlp for the length prefix which is 3 bytes for 10 MiB, and additional 2 bytes to compensate for missing rlp list marker when we skip the body. (This is my rough calculation, I may missed something), but you got the point.

And also a break from that loop must be executed before currentRlpSize exceeds MAX_RLP_BLOCK_SIZE - X.

blk.txs.add tx.tx
if tx.blobsBundle != nil:
doAssert(tx.blobsBundle.wrapperVersion == blobsBundle.wrapperVersion)
Expand Down
Loading