mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-11 22:16:53 +00:00
validate EL block hash when running consensus block tests (#6406)
* validate EL block hash when running consensus block tests We currently don't have an easy way to test EL block hash computation. As the EL block hash in consensus-spec-tests is computed correctly, update the test runners that load block from test files to also verify the EL block hash. This increases missing test coverage. Requires https://github.com/ethereum/consensus-specs/pull/3829 * fix * resolve merge conflicts * fix genesis case, and deal with `incorrect_block_hash` test * add missing export marker * fix import * htr mutates underlying data, messing with differ, create copy in test * Handle payloads with empty tx (unsupported in ordered trie tool) * Update copyright years --------- Co-authored-by: tersec <tersec@users.noreply.github.com>
This commit is contained in:
parent
adda9738a4
commit
c63862cf88
@ -2408,7 +2408,7 @@ func upgrade_to_fulu*(
|
|||||||
|
|
||||||
post
|
post
|
||||||
|
|
||||||
func latest_block_root(state: ForkyBeaconState, state_root: Eth2Digest):
|
func latest_block_root*(state: ForkyBeaconState, state_root: Eth2Digest):
|
||||||
Eth2Digest =
|
Eth2Digest =
|
||||||
# The root of the last block that was successfully applied to this state -
|
# The root of the last block that was successfully applied to this state -
|
||||||
# normally, when a block is applied, the data from the header is stored in
|
# normally, when a block is applied, the data from the header is stored in
|
||||||
|
@ -389,14 +389,17 @@ func is_merge_transition_complete*(
|
|||||||
state.latest_execution_payload_header != defaultExecutionPayloadHeader
|
state.latest_execution_payload_header != defaultExecutionPayloadHeader
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.9/sync/optimistic.md#helpers
|
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.9/sync/optimistic.md#helpers
|
||||||
func is_execution_block*(blck: SomeForkyBeaconBlock): bool =
|
func is_execution_block*(body: SomeForkyBeaconBlockBody): bool =
|
||||||
when typeof(blck).kind >= ConsensusFork.Bellatrix:
|
when typeof(body).kind >= ConsensusFork.Bellatrix:
|
||||||
const defaultExecutionPayload =
|
const defaultExecutionPayload =
|
||||||
default(typeof(blck.body.execution_payload))
|
default(typeof(body.execution_payload))
|
||||||
blck.body.execution_payload != defaultExecutionPayload
|
body.execution_payload != defaultExecutionPayload
|
||||||
else:
|
else:
|
||||||
false
|
false
|
||||||
|
|
||||||
|
func is_execution_block*(blck: SomeForkyBeaconBlock): bool =
|
||||||
|
blck.body.is_execution_block
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.8/specs/bellatrix/beacon-chain.md#is_merge_transition_block
|
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.8/specs/bellatrix/beacon-chain.md#is_merge_transition_block
|
||||||
func is_merge_transition_block(
|
func is_merge_transition_block(
|
||||||
state: bellatrix.BeaconState | capella.BeaconState | deneb.BeaconState |
|
state: bellatrix.BeaconState | capella.BeaconState | deneb.BeaconState |
|
||||||
@ -480,9 +483,10 @@ func computeRequestsHash(
|
|||||||
|
|
||||||
requestsHash.to(EthHash32)
|
requestsHash.to(EthHash32)
|
||||||
|
|
||||||
proc blockToBlockHeader*(blck: ForkyBeaconBlock): EthHeader =
|
proc toExecutionBlockHeader(
|
||||||
template payload: auto = blck.body.execution_payload
|
payload: ForkyExecutionPayload,
|
||||||
|
parentRoot: Eth2Digest,
|
||||||
|
requestsHash = Opt.none(EthHash32)): EthHeader =
|
||||||
static: # `GasInt` is signed. We only use it for hashing.
|
static: # `GasInt` is signed. We only use it for hashing.
|
||||||
doAssert sizeof(GasInt) == sizeof(payload.gas_limit)
|
doAssert sizeof(GasInt) == sizeof(payload.gas_limit)
|
||||||
doAssert sizeof(GasInt) == sizeof(payload.gas_used)
|
doAssert sizeof(GasInt) == sizeof(payload.gas_used)
|
||||||
@ -506,12 +510,7 @@ proc blockToBlockHeader*(blck: ForkyBeaconBlock): EthHeader =
|
|||||||
Opt.none(uint64)
|
Opt.none(uint64)
|
||||||
parentBeaconBlockRoot =
|
parentBeaconBlockRoot =
|
||||||
when typeof(payload).kind >= ConsensusFork.Deneb:
|
when typeof(payload).kind >= ConsensusFork.Deneb:
|
||||||
Opt.some EthHash32(blck.parent_root.data)
|
Opt.some EthHash32(parentRoot.data)
|
||||||
else:
|
|
||||||
Opt.none(EthHash32)
|
|
||||||
requestsHash =
|
|
||||||
when typeof(payload).kind >= ConsensusFork.Electra:
|
|
||||||
Opt.some blck.body.execution_requests.computeRequestsHash()
|
|
||||||
else:
|
else:
|
||||||
Opt.none(EthHash32)
|
Opt.none(EthHash32)
|
||||||
|
|
||||||
@ -538,8 +537,19 @@ proc blockToBlockHeader*(blck: ForkyBeaconBlock): EthHeader =
|
|||||||
parentBeaconBlockRoot : parentBeaconBlockRoot, # EIP-4788
|
parentBeaconBlockRoot : parentBeaconBlockRoot, # EIP-4788
|
||||||
requestsHash : requestsHash) # EIP-7685
|
requestsHash : requestsHash) # EIP-7685
|
||||||
|
|
||||||
|
proc compute_execution_block_hash*(
|
||||||
|
body: ForkyBeaconBlockBody,
|
||||||
|
parentRoot: Eth2Digest): Eth2Digest =
|
||||||
|
when typeof(body).kind >= ConsensusFork.Electra:
|
||||||
|
body.execution_payload.toExecutionBlockHeader(
|
||||||
|
parentRoot, Opt.some body.execution_requests.computeRequestsHash())
|
||||||
|
.rlpHash().to(Eth2Digest)
|
||||||
|
else:
|
||||||
|
body.execution_payload.toExecutionBlockHeader(parentRoot)
|
||||||
|
.rlpHash().to(Eth2Digest)
|
||||||
|
|
||||||
proc compute_execution_block_hash*(blck: ForkyBeaconBlock): Eth2Digest =
|
proc compute_execution_block_hash*(blck: ForkyBeaconBlock): Eth2Digest =
|
||||||
rlpHash(blockToBlockHeader(blck)).to(Eth2Digest)
|
blck.body.compute_execution_block_hash(blck.parent_root)
|
||||||
|
|
||||||
from std/math import exp, ln
|
from std/math import exp, ln
|
||||||
from std/sequtils import foldl
|
from std/sequtils import foldl
|
||||||
|
@ -20,11 +20,11 @@ import
|
|||||||
../fixtures_utils, ../os_ops,
|
../fixtures_utils, ../os_ops,
|
||||||
../../helpers/debug_state
|
../../helpers/debug_state
|
||||||
|
|
||||||
from std/sequtils import mapIt, toSeq
|
from std/sequtils import anyIt, mapIt, toSeq
|
||||||
from std/strutils import contains
|
from std/strutils import contains
|
||||||
from ../../../beacon_chain/spec/beaconstate import
|
from ../../../beacon_chain/spec/beaconstate import
|
||||||
get_base_reward_per_increment, get_state_exit_queue_info,
|
get_base_reward_per_increment, get_state_exit_queue_info,
|
||||||
get_total_active_balance, process_attestation
|
get_total_active_balance, latest_block_root, process_attestation
|
||||||
|
|
||||||
const
|
const
|
||||||
OpDir = SszTestsDir/const_preset/"bellatrix"/"operations"
|
OpDir = SszTestsDir/const_preset/"bellatrix"/"operations"
|
||||||
@ -110,9 +110,12 @@ suite baseDescription & "Attester Slashing " & preset():
|
|||||||
applyAttesterSlashing, path)
|
applyAttesterSlashing, path)
|
||||||
|
|
||||||
suite baseDescription & "Block Header " & preset():
|
suite baseDescription & "Block Header " & preset():
|
||||||
func applyBlockHeader(
|
proc applyBlockHeader(
|
||||||
preState: var bellatrix.BeaconState, blck: bellatrix.BeaconBlock):
|
preState: var bellatrix.BeaconState, blck: bellatrix.BeaconBlock):
|
||||||
Result[void, cstring] =
|
Result[void, cstring] =
|
||||||
|
if blck.is_execution_block:
|
||||||
|
check blck.body.execution_payload.block_hash ==
|
||||||
|
blck.compute_execution_block_hash()
|
||||||
var cache: StateCache
|
var cache: StateCache
|
||||||
process_block_header(preState, blck, {}, cache)
|
process_block_header(preState, blck, {}, cache)
|
||||||
|
|
||||||
@ -144,6 +147,13 @@ suite baseDescription & "Execution Payload " & preset():
|
|||||||
let payloadValid = os_ops.readFile(
|
let payloadValid = os_ops.readFile(
|
||||||
OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml"
|
OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml"
|
||||||
).contains("execution_valid: true")
|
).contains("execution_valid: true")
|
||||||
|
if payloadValid and body.is_execution_block and
|
||||||
|
not body.execution_payload.transactions.anyIt(it.len == 0):
|
||||||
|
let expectedOk = (path != "incorrect_block_hash")
|
||||||
|
check expectedOk == (body.execution_payload.block_hash ==
|
||||||
|
body.compute_execution_block_hash(
|
||||||
|
preState.latest_block_root(
|
||||||
|
assignClone(preState)[].hash_tree_root())))
|
||||||
func executePayload(_: bellatrix.ExecutionPayload): bool = payloadValid
|
func executePayload(_: bellatrix.ExecutionPayload): bool = payloadValid
|
||||||
process_execution_payload(
|
process_execution_payload(
|
||||||
preState, body.execution_payload, executePayload)
|
preState, body.execution_payload, executePayload)
|
||||||
@ -199,4 +209,4 @@ suite baseDescription & "Voluntary Exit " & preset():
|
|||||||
for path in walkTests(OpVoluntaryExitDir):
|
for path in walkTests(OpVoluntaryExitDir):
|
||||||
runTest[SignedVoluntaryExit, typeof applyVoluntaryExit](
|
runTest[SignedVoluntaryExit, typeof applyVoluntaryExit](
|
||||||
OpVoluntaryExitDir, suiteName, "Voluntary Exit", "voluntary_exit",
|
OpVoluntaryExitDir, suiteName, "Voluntary Exit", "voluntary_exit",
|
||||||
applyVoluntaryExit, path)
|
applyVoluntaryExit, path)
|
||||||
|
@ -20,11 +20,11 @@ import
|
|||||||
../fixtures_utils, ../os_ops,
|
../fixtures_utils, ../os_ops,
|
||||||
../../helpers/debug_state
|
../../helpers/debug_state
|
||||||
|
|
||||||
from std/sequtils import mapIt, toSeq
|
from std/sequtils import anyIt, mapIt, toSeq
|
||||||
from std/strutils import contains
|
from std/strutils import contains
|
||||||
from ../../../beacon_chain/spec/beaconstate import
|
from ../../../beacon_chain/spec/beaconstate import
|
||||||
get_base_reward_per_increment, get_state_exit_queue_info,
|
get_base_reward_per_increment, get_state_exit_queue_info,
|
||||||
get_total_active_balance, process_attestation
|
get_total_active_balance, latest_block_root, process_attestation
|
||||||
|
|
||||||
const
|
const
|
||||||
OpDir = SszTestsDir/const_preset/"capella"/"operations"
|
OpDir = SszTestsDir/const_preset/"capella"/"operations"
|
||||||
@ -114,9 +114,12 @@ suite baseDescription & "Attester Slashing " & preset():
|
|||||||
applyAttesterSlashing, path)
|
applyAttesterSlashing, path)
|
||||||
|
|
||||||
suite baseDescription & "Block Header " & preset():
|
suite baseDescription & "Block Header " & preset():
|
||||||
func applyBlockHeader(
|
proc applyBlockHeader(
|
||||||
preState: var capella.BeaconState, blck: capella.BeaconBlock):
|
preState: var capella.BeaconState, blck: capella.BeaconBlock):
|
||||||
Result[void, cstring] =
|
Result[void, cstring] =
|
||||||
|
if blck.is_execution_block:
|
||||||
|
check blck.body.execution_payload.block_hash ==
|
||||||
|
blck.compute_execution_block_hash()
|
||||||
var cache: StateCache
|
var cache: StateCache
|
||||||
process_block_header(preState, blck, {}, cache)
|
process_block_header(preState, blck, {}, cache)
|
||||||
|
|
||||||
@ -161,6 +164,13 @@ suite baseDescription & "Execution Payload " & preset():
|
|||||||
let payloadValid = os_ops.readFile(
|
let payloadValid = os_ops.readFile(
|
||||||
OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml"
|
OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml"
|
||||||
).contains("execution_valid: true")
|
).contains("execution_valid: true")
|
||||||
|
if payloadValid and body.is_execution_block and
|
||||||
|
not body.execution_payload.transactions.anyIt(it.len == 0):
|
||||||
|
let expectedOk = (path != "incorrect_block_hash")
|
||||||
|
check expectedOk == (body.execution_payload.block_hash ==
|
||||||
|
body.compute_execution_block_hash(
|
||||||
|
preState.latest_block_root(
|
||||||
|
assignClone(preState)[].hash_tree_root())))
|
||||||
func executePayload(_: capella.ExecutionPayload): bool = payloadValid
|
func executePayload(_: capella.ExecutionPayload): bool = payloadValid
|
||||||
process_execution_payload(
|
process_execution_payload(
|
||||||
preState, body.execution_payload, executePayload)
|
preState, body.execution_payload, executePayload)
|
||||||
@ -227,4 +237,4 @@ suite baseDescription & "Withdrawals " & preset():
|
|||||||
for path in walkTests(OpWithdrawalsDir):
|
for path in walkTests(OpWithdrawalsDir):
|
||||||
runTest[capella.ExecutionPayload, typeof applyWithdrawals](
|
runTest[capella.ExecutionPayload, typeof applyWithdrawals](
|
||||||
OpWithdrawalsDir, suiteName, "Withdrawals", "execution_payload",
|
OpWithdrawalsDir, suiteName, "Withdrawals", "execution_payload",
|
||||||
applyWithdrawals, path)
|
applyWithdrawals, path)
|
||||||
|
@ -20,11 +20,11 @@ import
|
|||||||
../fixtures_utils, ../os_ops,
|
../fixtures_utils, ../os_ops,
|
||||||
../../helpers/debug_state
|
../../helpers/debug_state
|
||||||
|
|
||||||
from std/sequtils import mapIt, toSeq
|
from std/sequtils import anyIt, mapIt, toSeq
|
||||||
from std/strutils import contains
|
from std/strutils import contains
|
||||||
from ../../../beacon_chain/spec/beaconstate import
|
from ../../../beacon_chain/spec/beaconstate import
|
||||||
get_base_reward_per_increment, get_state_exit_queue_info,
|
get_base_reward_per_increment, get_state_exit_queue_info,
|
||||||
get_total_active_balance, process_attestation
|
get_total_active_balance, latest_block_root, process_attestation
|
||||||
|
|
||||||
const
|
const
|
||||||
OpDir = SszTestsDir/const_preset/"deneb"/"operations"
|
OpDir = SszTestsDir/const_preset/"deneb"/"operations"
|
||||||
@ -114,9 +114,12 @@ suite baseDescription & "Attester Slashing " & preset():
|
|||||||
applyAttesterSlashing, path)
|
applyAttesterSlashing, path)
|
||||||
|
|
||||||
suite baseDescription & "Block Header " & preset():
|
suite baseDescription & "Block Header " & preset():
|
||||||
func applyBlockHeader(
|
proc applyBlockHeader(
|
||||||
preState: var deneb.BeaconState, blck: deneb.BeaconBlock):
|
preState: var deneb.BeaconState, blck: deneb.BeaconBlock):
|
||||||
Result[void, cstring] =
|
Result[void, cstring] =
|
||||||
|
if blck.is_execution_block:
|
||||||
|
check blck.body.execution_payload.block_hash ==
|
||||||
|
blck.compute_execution_block_hash()
|
||||||
var cache: StateCache
|
var cache: StateCache
|
||||||
process_block_header(preState, blck, {}, cache)
|
process_block_header(preState, blck, {}, cache)
|
||||||
|
|
||||||
@ -164,6 +167,13 @@ suite baseDescription & "Execution Payload " & preset():
|
|||||||
let payloadValid = os_ops.readFile(
|
let payloadValid = os_ops.readFile(
|
||||||
OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml"
|
OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml"
|
||||||
).contains("execution_valid: true")
|
).contains("execution_valid: true")
|
||||||
|
if payloadValid and body.is_execution_block and
|
||||||
|
not body.execution_payload.transactions.anyIt(it.len == 0):
|
||||||
|
let expectedOk = (path != "incorrect_block_hash")
|
||||||
|
check expectedOk == (body.execution_payload.block_hash ==
|
||||||
|
body.compute_execution_block_hash(
|
||||||
|
preState.latest_block_root(
|
||||||
|
assignClone(preState)[].hash_tree_root())))
|
||||||
func executePayload(_: deneb.ExecutionPayload): bool = payloadValid
|
func executePayload(_: deneb.ExecutionPayload): bool = payloadValid
|
||||||
process_execution_payload(preState, body, executePayload)
|
process_execution_payload(preState, body, executePayload)
|
||||||
|
|
||||||
@ -229,4 +239,4 @@ suite baseDescription & "Withdrawals " & preset():
|
|||||||
for path in walkTests(OpWithdrawalsDir):
|
for path in walkTests(OpWithdrawalsDir):
|
||||||
runTest[deneb.ExecutionPayload, typeof applyWithdrawals](
|
runTest[deneb.ExecutionPayload, typeof applyWithdrawals](
|
||||||
OpWithdrawalsDir, suiteName, "Withdrawals", "execution_payload",
|
OpWithdrawalsDir, suiteName, "Withdrawals", "execution_payload",
|
||||||
applyWithdrawals, path)
|
applyWithdrawals, path)
|
||||||
|
@ -20,11 +20,11 @@ import
|
|||||||
../fixtures_utils, ../os_ops,
|
../fixtures_utils, ../os_ops,
|
||||||
../../helpers/debug_state
|
../../helpers/debug_state
|
||||||
|
|
||||||
from std/sequtils import mapIt, toSeq
|
from std/sequtils import anyIt, mapIt, toSeq
|
||||||
from std/strutils import contains
|
from std/strutils import contains
|
||||||
from ../../../beacon_chain/spec/beaconstate import
|
from ../../../beacon_chain/spec/beaconstate import
|
||||||
get_base_reward_per_increment, get_state_exit_queue_info,
|
get_base_reward_per_increment, get_state_exit_queue_info,
|
||||||
get_total_active_balance, process_attestation
|
get_total_active_balance, latest_block_root, process_attestation
|
||||||
|
|
||||||
const
|
const
|
||||||
OpDir = SszTestsDir/const_preset/"electra"/"operations"
|
OpDir = SszTestsDir/const_preset/"electra"/"operations"
|
||||||
@ -121,9 +121,12 @@ suite baseDescription & "Attester Slashing " & preset():
|
|||||||
applyAttesterSlashing, path)
|
applyAttesterSlashing, path)
|
||||||
|
|
||||||
suite baseDescription & "Block Header " & preset():
|
suite baseDescription & "Block Header " & preset():
|
||||||
func applyBlockHeader(
|
proc applyBlockHeader(
|
||||||
preState: var electra.BeaconState, blck: electra.BeaconBlock):
|
preState: var electra.BeaconState, blck: electra.BeaconBlock):
|
||||||
Result[void, cstring] =
|
Result[void, cstring] =
|
||||||
|
if blck.is_execution_block:
|
||||||
|
check blck.body.execution_payload.block_hash ==
|
||||||
|
blck.compute_execution_block_hash()
|
||||||
var cache: StateCache
|
var cache: StateCache
|
||||||
process_block_header(preState, blck, {}, cache)
|
process_block_header(preState, blck, {}, cache)
|
||||||
|
|
||||||
@ -199,6 +202,13 @@ suite baseDescription & "Execution Payload " & preset():
|
|||||||
let payloadValid = os_ops.readFile(
|
let payloadValid = os_ops.readFile(
|
||||||
OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml"
|
OpExecutionPayloadDir/"pyspec_tests"/path/"execution.yaml"
|
||||||
).contains("execution_valid: true")
|
).contains("execution_valid: true")
|
||||||
|
if payloadValid and body.is_execution_block and
|
||||||
|
not body.execution_payload.transactions.anyIt(it.len == 0):
|
||||||
|
let expectedOk = (path != "incorrect_block_hash")
|
||||||
|
check expectedOk == (body.execution_payload.block_hash ==
|
||||||
|
body.compute_execution_block_hash(
|
||||||
|
preState.latest_block_root(
|
||||||
|
assignClone(preState)[].hash_tree_root())))
|
||||||
func executePayload(_: electra.ExecutionPayload): bool = payloadValid
|
func executePayload(_: electra.ExecutionPayload): bool = payloadValid
|
||||||
process_execution_payload(
|
process_execution_payload(
|
||||||
defaultRuntimeConfig, preState, body, executePayload)
|
defaultRuntimeConfig, preState, body, executePayload)
|
||||||
@ -281,4 +291,4 @@ suite baseDescription & "Withdrawals " & preset():
|
|||||||
for path in walkTests(OpWithdrawalsDir):
|
for path in walkTests(OpWithdrawalsDir):
|
||||||
runTest[electra.ExecutionPayload, typeof applyWithdrawals](
|
runTest[electra.ExecutionPayload, typeof applyWithdrawals](
|
||||||
OpWithdrawalsDir, suiteName, "Withdrawals", "execution_payload",
|
OpWithdrawalsDir, suiteName, "Withdrawals", "execution_payload",
|
||||||
applyWithdrawals, path)
|
applyWithdrawals, path)
|
||||||
|
@ -9,18 +9,18 @@
|
|||||||
|
|
||||||
import
|
import
|
||||||
# Standard library
|
# Standard library
|
||||||
std/[strutils, typetraits],
|
std/[sequtils, strutils, typetraits],
|
||||||
# Internals
|
# Internals
|
||||||
./os_ops,
|
./os_ops,
|
||||||
../../beacon_chain/spec/datatypes/[phase0, altair, bellatrix],
|
../../beacon_chain/spec/datatypes/[phase0, altair, bellatrix],
|
||||||
../../beacon_chain/spec/[
|
../../beacon_chain/spec/[
|
||||||
eth2_merkleization, eth2_ssz_serialization, forks],
|
eth2_merkleization, eth2_ssz_serialization, forks, helpers],
|
||||||
# Status libs,
|
# Status libs,
|
||||||
snappy,
|
snappy,
|
||||||
stew/byteutils
|
stew/byteutils
|
||||||
|
|
||||||
export
|
export
|
||||||
eth2_merkleization, eth2_ssz_serialization
|
eth2_merkleization, eth2_ssz_serialization, helpers
|
||||||
|
|
||||||
# Process current EF test format
|
# Process current EF test format
|
||||||
# ---------------------------------------------
|
# ---------------------------------------------
|
||||||
@ -173,4 +173,22 @@ proc loadForkedState*(
|
|||||||
withState(state[]):
|
withState(state[]):
|
||||||
forkyState.data = parseTest(path, SSZ, consensusFork.BeaconState)
|
forkyState.data = parseTest(path, SSZ, consensusFork.BeaconState)
|
||||||
forkyState.root = hash_tree_root(forkyState.data)
|
forkyState.root = hash_tree_root(forkyState.data)
|
||||||
state
|
state
|
||||||
|
|
||||||
|
proc loadBlock*(
|
||||||
|
path: string,
|
||||||
|
consensusFork: static ConsensusFork,
|
||||||
|
validateBlockHash = true): auto =
|
||||||
|
var blck = parseTest(path, SSZ, consensusFork.SignedBeaconBlock)
|
||||||
|
blck.root = hash_tree_root(blck.message)
|
||||||
|
when consensusFork >= ConsensusFork.Bellatrix:
|
||||||
|
if blck.message.is_execution_block and
|
||||||
|
not blck.message.body.execution_payload.transactions.anyIt(it.len == 0):
|
||||||
|
if blck.message.body.execution_payload.block_hash !=
|
||||||
|
blck.message.compute_execution_block_hash():
|
||||||
|
try:
|
||||||
|
stderr.write "Invalid `block_hash`: ", path, "\n"
|
||||||
|
except IOError:
|
||||||
|
discard
|
||||||
|
quit 1
|
||||||
|
blck
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# beacon_chain
|
# beacon_chain
|
||||||
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
# Copyright (c) 2018-2025 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
@ -119,10 +119,7 @@ proc loadOps(
|
|||||||
doAssert step.hasKey"blobs" == step.hasKey"proofs"
|
doAssert step.hasKey"blobs" == step.hasKey"proofs"
|
||||||
withConsensusFork(fork):
|
withConsensusFork(fork):
|
||||||
let
|
let
|
||||||
blck = parseTest(
|
blck = loadBlock(path/filename & ".ssz_snappy", consensusFork)
|
||||||
path/filename & ".ssz_snappy",
|
|
||||||
SSZ, consensusFork.SignedBeaconBlock)
|
|
||||||
|
|
||||||
blobData =
|
blobData =
|
||||||
when consensusFork >= ConsensusFork.Deneb:
|
when consensusFork >= ConsensusFork.Deneb:
|
||||||
if step.hasKey"blobs":
|
if step.hasKey"blobs":
|
||||||
|
@ -221,7 +221,7 @@ proc runComputeCellsAndKzgProofsTest(suiteName, suitePath, path: string) =
|
|||||||
check output.kind == JNull
|
check output.kind == JNull
|
||||||
else:
|
else:
|
||||||
let p_val = p[].get
|
let p_val = p[].get
|
||||||
for i in 0..<CELLS_PER_EXT_BLOB:
|
for i in 0..<kzg_abi.CELLS_PER_EXT_BLOB:
|
||||||
check p_val.cells[i].bytes == fromHex[2048](output[0][i].getStr).get
|
check p_val.cells[i].bytes == fromHex[2048](output[0][i].getStr).get
|
||||||
check p_val.proofs[i].bytes == fromHex[48](output[1][i].getStr).get
|
check p_val.proofs[i].bytes == fromHex[48](output[1][i].getStr).get
|
||||||
|
|
||||||
@ -281,7 +281,7 @@ proc runRecoverCellsAndKzgProofsTest(suiteName, suitePath, path: string) =
|
|||||||
check output.kind == JNull
|
check output.kind == JNull
|
||||||
else:
|
else:
|
||||||
let val = v[].get
|
let val = v[].get
|
||||||
for i in 0..<CELLS_PER_EXT_BLOB:
|
for i in 0..<kzg_abi.CELLS_PER_EXT_BLOB:
|
||||||
check val.cells[i].bytes == fromHex[2048](output[0][i].getStr).get
|
check val.cells[i].bytes == fromHex[2048](output[0][i].getStr).get
|
||||||
check val.proofs[i].bytes == fromHex[48](output[1][i].getStr).get
|
check val.proofs[i].bytes == fromHex[48](output[1][i].getStr).get
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# beacon_chain
|
# beacon_chain
|
||||||
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
# Copyright (c) 2018-2025 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
@ -10,8 +10,7 @@
|
|||||||
|
|
||||||
import
|
import
|
||||||
chronicles,
|
chronicles,
|
||||||
../../beacon_chain/spec/forks,
|
../../beacon_chain/spec/[helpers, state_transition, state_transition_epoch],
|
||||||
../../beacon_chain/spec/[state_transition, state_transition_epoch],
|
|
||||||
./os_ops,
|
./os_ops,
|
||||||
../testutil
|
../testutil
|
||||||
|
|
||||||
@ -20,7 +19,8 @@ from std/strutils import toLowerAscii
|
|||||||
from ../../beacon_chain/spec/presets import
|
from ../../beacon_chain/spec/presets import
|
||||||
const_preset, defaultRuntimeConfig
|
const_preset, defaultRuntimeConfig
|
||||||
from ./fixtures_utils import
|
from ./fixtures_utils import
|
||||||
SSZ, SszTestsDir, hash_tree_root, parseTest, readSszBytes, toSszType
|
SSZ, SszTestsDir, hash_tree_root, loadBlock, parseTest,
|
||||||
|
readSszBytes, toSszType
|
||||||
from ../teststateutil import checkPerValidatorBalanceCalc
|
from ../teststateutil import checkPerValidatorBalanceCalc
|
||||||
|
|
||||||
proc runTest(
|
proc runTest(
|
||||||
@ -44,8 +44,9 @@ proc runTest(
|
|||||||
# so purely lexicographic sorting wouldn't sort properly.
|
# so purely lexicographic sorting wouldn't sort properly.
|
||||||
let numBlocks = toSeq(walkPattern(testPath/"blocks_*.ssz_snappy")).len
|
let numBlocks = toSeq(walkPattern(testPath/"blocks_*.ssz_snappy")).len
|
||||||
for i in 0 ..< numBlocks:
|
for i in 0 ..< numBlocks:
|
||||||
let blck = parseTest(testPath/"blocks_" & $i & ".ssz_snappy",
|
let blck = loadBlock(
|
||||||
SSZ, consensusFork.SignedBeaconBlock)
|
testPath/"blocks_" & $i & ".ssz_snappy", consensusFork,
|
||||||
|
validateBlockHash = hasPostState)
|
||||||
|
|
||||||
if hasPostState:
|
if hasPostState:
|
||||||
# The return value is the block rewards, which aren't tested here;
|
# The return value is the block rewards, which aren't tested here;
|
||||||
@ -100,4 +101,4 @@ template runForkBlockTests(consensusFork: static ConsensusFork) =
|
|||||||
RandomDir, suiteName, path)
|
RandomDir, suiteName, path)
|
||||||
|
|
||||||
withAllButFulu(ConsensusFork):
|
withAllButFulu(ConsensusFork):
|
||||||
runForkBlockTests(consensusFork)
|
runForkBlockTests(consensusFork)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# beacon_chain
|
# beacon_chain
|
||||||
# Copyright (c) 2021-2024 Status Research & Development GmbH
|
# Copyright (c) 2021-2025 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
@ -16,7 +16,7 @@ import
|
|||||||
from std/sequtils import toSeq
|
from std/sequtils import toSeq
|
||||||
from std/streams import close, openFileStream
|
from std/streams import close, openFileStream
|
||||||
from ../testutil import preset, suite, test
|
from ../testutil import preset, suite, test
|
||||||
from ./fixtures_utils import SszTestsDir, parseTest
|
from ./fixtures_utils import SszTestsDir, loadBlock, parseTest
|
||||||
|
|
||||||
type
|
type
|
||||||
TransitionInfo = object
|
TransitionInfo = object
|
||||||
@ -54,8 +54,8 @@ proc runTest(
|
|||||||
for i in 0 ..< numBlocks:
|
for i in 0 ..< numBlocks:
|
||||||
if i <= fork_block:
|
if i <= fork_block:
|
||||||
let
|
let
|
||||||
blck = parseTest(
|
blck = loadBlock(
|
||||||
testPath/"blocks_" & $i & ".ssz_snappy", SSZ, AnteBeaconBlock)
|
testPath/"blocks_" & $i & ".ssz_snappy", AnteBeaconBlock.kind)
|
||||||
res = state_transition(
|
res = state_transition(
|
||||||
cfg, fhPreState[], blck, cache, info,
|
cfg, fhPreState[], blck, cache, info,
|
||||||
flags = {skipStateRootValidation}, noRollback)
|
flags = {skipStateRootValidation}, noRollback)
|
||||||
@ -65,8 +65,8 @@ proc runTest(
|
|||||||
discard res.expect("no failure when applying block " & $i)
|
discard res.expect("no failure when applying block " & $i)
|
||||||
else:
|
else:
|
||||||
let
|
let
|
||||||
blck = parseTest(
|
blck = loadBlock(
|
||||||
testPath/"blocks_" & $i & ".ssz_snappy", SSZ, PostBeaconBlock)
|
testPath/"blocks_" & $i & ".ssz_snappy", PostBeaconBlock.kind)
|
||||||
res = state_transition(
|
res = state_transition(
|
||||||
cfg, fhPreState[], blck, cache, info,
|
cfg, fhPreState[], blck, cache, info,
|
||||||
flags = {skipStateRootValidation}, noRollback)
|
flags = {skipStateRootValidation}, noRollback)
|
||||||
@ -161,4 +161,4 @@ suite "EF - Electra - Transition " & preset():
|
|||||||
runTest(
|
runTest(
|
||||||
deneb.BeaconState, electra.BeaconState, deneb.SignedBeaconBlock,
|
deneb.BeaconState, electra.BeaconState, deneb.SignedBeaconBlock,
|
||||||
electra.SignedBeaconBlock, cfg, "EF - Electra - Transition",
|
electra.SignedBeaconBlock, cfg, "EF - Electra - Transition",
|
||||||
TransitionDir, suiteName, path, transitionInfo.fork_block)
|
TransitionDir, suiteName, path, transitionInfo.fork_block)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# beacon_chain
|
# beacon_chain
|
||||||
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
# Copyright (c) 2018-2025 Status Research & Development GmbH
|
||||||
# Licensed and distributed under either of
|
# Licensed and distributed under either of
|
||||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
@ -112,7 +112,7 @@ proc build_empty_merge_execution_payload(state: bellatrix.BeaconState):
|
|||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
base_fee_per_gas: EIP1559_INITIAL_BASE_FEE)
|
base_fee_per_gas: EIP1559_INITIAL_BASE_FEE)
|
||||||
|
|
||||||
payload.block_hash = rlpHash blockToBlockHeader(bellatrix.BeaconBlock(body:
|
payload.block_hash = compute_execution_block_hash(bellatrix.BeaconBlock(body:
|
||||||
bellatrix.BeaconBlockBody(execution_payload: payload)))
|
bellatrix.BeaconBlockBody(execution_payload: payload)))
|
||||||
|
|
||||||
bellatrix.ExecutionPayloadForSigning(executionPayload: payload,
|
bellatrix.ExecutionPayloadForSigning(executionPayload: payload,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user