Skip to content

Commit

Permalink
skip blob transaction parsing pre Deneb
Browse files Browse the repository at this point in the history
  • Loading branch information
etan-status committed Aug 21, 2024
1 parent 289ce0b commit 50904d4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 33 deletions.
13 changes: 10 additions & 3 deletions beacon_chain/gossip_processing/block_processor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,16 @@ proc storeBlock(
returnWithError "Execution block hash validation failed"

# [New in Deneb:EIP4844]
let blobsRes = signedBlock.message.is_valid_versioned_hashes
if blobsRes.isErr:
returnWithError "Blob versioned hashes invalid", blobsRes.error
when typeof(signedBlock).kind >= ConsensusFork.Deneb:
let blobsRes = signedBlock.message.is_valid_versioned_hashes
if blobsRes.isErr:
returnWithError "Blob versioned hashes invalid", blobsRes.error
else:
# If there are EIP-4844 (type 3) transactions in the payload with
# versioned hashes, the transactions would be rejected by the EL
# based on payload timestamp (only allowed post Deneb);
# There are no `blob_kzg_commitments` before Deneb to compare against
discard

let newPayloadTick = Moment.now()

Expand Down
47 changes: 17 additions & 30 deletions beacon_chain/spec/helpers_el.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,21 @@ func readExecutionTransaction(

# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.4/specs/deneb/beacon-chain.md#is_valid_versioned_hashes
func is_valid_versioned_hashes*(blck: ForkyBeaconBlock): Result[void, string] =
const consensusFork = typeof(blck).kind
when consensusFork >= ConsensusFork.Deneb:
template transactions: untyped = blck.body.execution_payload.transactions
template commitments: untyped = blck.body.blob_kzg_commitments
static: doAssert typeof(blck).kind >= ConsensusFork.Deneb
template transactions: untyped = blck.body.execution_payload.transactions
template commitments: untyped = blck.body.blob_kzg_commitments

var i = 0
for txBytes in transactions:
if txBytes.len == 0 or txBytes[0] != TxEip4844.byte:
continue # Only blob transactions may have blobs
let tx = ? txBytes.readExecutionTransaction()
for vHash in tx.versionedHashes:
if commitments.len <= i:
return err("Extra blobs without matching `blob_kzg_commitments`")
if vHash.data != kzg_commitment_to_versioned_hash(commitments[i]):
return err("Invalid `blob_versioned_hash` at index " & $i)
inc i
if i != commitments.len:
return err("Extra `blob_kzg_commitments` without matching blobs")
ok()
elif consensusFork >= ConsensusFork.Bellatrix:
template transactions: untyped = blck.body.execution_payload.transactions

for txBytes in transactions:
if txBytes.len == 0 or txBytes[0] != TxEip4844.byte:
continue # Only blob transactions may have blobs
let tx = ? txBytes.readExecutionTransaction()
if tx.versionedHashes.len > 0:
return err("No blob transaction allowed before Deneb")
ok()
else:
ok()
var i = 0
for txBytes in transactions:
if txBytes.len == 0 or txBytes[0] != TxEip4844.byte:
continue # Only blob transactions may have blobs
let tx = ? txBytes.readExecutionTransaction()
for vHash in tx.versionedHashes:
if commitments.len <= i:
return err("Extra blobs without matching `blob_kzg_commitments`")
if vHash.data != kzg_commitment_to_versioned_hash(commitments[i]):
return err("Invalid `blob_versioned_hash` at index " & $i)
inc i
if i != commitments.len:
return err("Extra `blob_kzg_commitments` without matching blobs")
ok()

0 comments on commit 50904d4

Please sign in to comment.