Skip to content

Commit

Permalink
use EF consensus spec v1.5.0-alpha.6 test vectors (#6568)
Browse files Browse the repository at this point in the history
* use EF consensus spec v1.5.0-alpha.6 test vectors

* LC changes are good as is, no need for the debug comment

* Fix indentation

* Use `execution_requests` for requests root

* fill in spec reference URLs for ExecutionPayload(Header)

* copy `execution_requests` when blidning blocks for Electra and add test

* fix `test_engine_api_conversions`

---------

Co-authored-by: Etan Kissling <[email protected]>
  • Loading branch information
tersec and etan-status authored Sep 20, 2024
1 parent 9df3d07 commit 193a982
Show file tree
Hide file tree
Showing 19 changed files with 2,940 additions and 2,810 deletions.
8 changes: 5 additions & 3 deletions ConsensusSpecPreset-mainnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -2914,6 +2914,7 @@ OK: 24/24 Fail: 0/24 Skip: 0/24
+ [Valid] EF - Electra - Operations - Withdrawal Request - activation_epoch_less_than_shar OK
+ [Valid] EF - Electra - Operations - Withdrawal Request - basic_withdrawal_request OK
+ [Valid] EF - Electra - Operations - Withdrawal Request - basic_withdrawal_request_with_c OK
+ [Valid] EF - Electra - Operations - Withdrawal Request - basic_withdrawal_request_with_f OK
+ [Valid] EF - Electra - Operations - Withdrawal Request - incorrect_source_address OK
+ [Valid] EF - Electra - Operations - Withdrawal Request - incorrect_withdrawal_credential OK
+ [Valid] EF - Electra - Operations - Withdrawal Request - insufficient_effective_balance OK
Expand All @@ -2926,7 +2927,7 @@ OK: 24/24 Fail: 0/24 Skip: 0/24
+ [Valid] EF - Electra - Operations - Withdrawal Request - partial_withdrawal_on_exit_init OK
+ [Valid] EF - Electra - Operations - Withdrawal Request - pending_withdrawals_consume_all OK
```
OK: 14/14 Fail: 0/14 Skip: 0/14
OK: 15/15 Fail: 0/15 Skip: 0/15
## EF - Electra - Operations - Withdrawals [Preset: mainnet]
```diff
+ [Invalid] EF - Electra - Operations - Withdrawals - invalid_a_lot_fully_withdrawable_too_f OK
Expand Down Expand Up @@ -3063,6 +3064,7 @@ OK: 34/34 Fail: 0/34 Skip: 0/34
+ Testing Eth1Data OK
+ Testing ExecutionPayload OK
+ Testing ExecutionPayloadHeader OK
+ Testing ExecutionRequests OK
+ Testing Fork OK
+ Testing ForkData OK
+ Testing HistoricalBatch OK
Expand Down Expand Up @@ -3096,7 +3098,7 @@ OK: 34/34 Fail: 0/34 Skip: 0/34
+ Testing Withdrawal OK
+ Testing WithdrawalRequest OK
```
OK: 54/54 Fail: 0/54 Skip: 0/54
OK: 55/55 Fail: 0/55 Skip: 0/55
## EF - Electra - Sanity - Blocks [Preset: mainnet]
```diff
+ [Invalid] EF - Electra - Sanity - Blocks - deposit_transition__invalid_eth1_deposits_overl OK
Expand Down Expand Up @@ -3761,4 +3763,4 @@ OK: 69/88 Fail: 0/88 Skip: 19/88
OK: 3/3 Fail: 0/3 Skip: 0/3

---TOTAL---
OK: 3035/3055 Fail: 0/3055 Skip: 20/3055
OK: 3037/3057 Fail: 0/3057 Skip: 20/3057
8 changes: 5 additions & 3 deletions ConsensusSpecPreset-minimal.md
Original file line number Diff line number Diff line change
Expand Up @@ -3060,6 +3060,7 @@ OK: 20/20 Fail: 0/20 Skip: 0/20
+ [Valid] EF - Electra - Operations - Withdrawal Request - basic_withdrawal_request OK
+ [Valid] EF - Electra - Operations - Withdrawal Request - basic_withdrawal_request_with_c OK
+ [Valid] EF - Electra - Operations - Withdrawal Request - basic_withdrawal_request_with_f OK
+ [Valid] EF - Electra - Operations - Withdrawal Request - basic_withdrawal_request_with_f OK
+ [Valid] EF - Electra - Operations - Withdrawal Request - incorrect_source_address OK
+ [Valid] EF - Electra - Operations - Withdrawal Request - incorrect_withdrawal_credential OK
+ [Valid] EF - Electra - Operations - Withdrawal Request - insufficient_effective_balance OK
Expand All @@ -3078,7 +3079,7 @@ OK: 20/20 Fail: 0/20 Skip: 0/20
+ [Valid] EF - Electra - Operations - Withdrawal Request - partial_withdrawal_request_with OK
+ [Valid] EF - Electra - Operations - Withdrawal Request - pending_withdrawals_consume_all OK
```
OK: 24/24 Fail: 0/24 Skip: 0/24
OK: 25/25 Fail: 0/25 Skip: 0/25
## EF - Electra - Operations - Withdrawals [Preset: minimal]
```diff
+ [Invalid] EF - Electra - Operations - Withdrawals - invalid_a_lot_fully_withdrawable_too_f OK
Expand Down Expand Up @@ -3216,6 +3217,7 @@ OK: 34/34 Fail: 0/34 Skip: 0/34
+ Testing Eth1Data OK
+ Testing ExecutionPayload OK
+ Testing ExecutionPayloadHeader OK
+ Testing ExecutionRequests OK
+ Testing Fork OK
+ Testing ForkData OK
+ Testing HistoricalBatch OK
Expand Down Expand Up @@ -3249,7 +3251,7 @@ OK: 34/34 Fail: 0/34 Skip: 0/34
+ Testing Withdrawal OK
+ Testing WithdrawalRequest OK
```
OK: 54/54 Fail: 0/54 Skip: 0/54
OK: 55/55 Fail: 0/55 Skip: 0/55
## EF - Electra - Sanity - Blocks [Preset: minimal]
```diff
+ [Invalid] EF - Electra - Sanity - Blocks - deposit_transition__invalid_eth1_deposits_overl OK
Expand Down Expand Up @@ -4098,4 +4100,4 @@ OK: 185/207 Fail: 0/207 Skip: 22/207
OK: 3/3 Fail: 0/3 Skip: 0/3

---TOTAL---
OK: 3341/3364 Fail: 0/3364 Skip: 23/3364
OK: 3343/3366 Fail: 0/3366 Skip: 23/3366
2 changes: 1 addition & 1 deletion beacon_chain/el/el_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ proc sendNewPayload*(
let
startTime = Moment.now()
deadline = sleepAsync(NEWPAYLOAD_TIMEOUT)
payload = blck.body.execution_payload.asEngineExecutionPayload
payload = blck.body.asEngineExecutionPayload
var
responseProcessor = ELConsensusViolationDetector.init()

Expand Down
37 changes: 17 additions & 20 deletions beacon_chain/el/engine_api_conversions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,7 @@ func asConsensusType*(rpcExecutionPayload: ExecutionPayloadV4):
withdrawals: List[capella.Withdrawal, MAX_WITHDRAWALS_PER_PAYLOAD].init(
mapIt(rpcExecutionPayload.withdrawals, it.asConsensusWithdrawal)),
blob_gas_used: rpcExecutionPayload.blobGasUsed.uint64,
excess_blob_gas: rpcExecutionPayload.excessBlobGas.uint64,
deposit_requests:
List[electra.DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD].init(
mapIt(rpcExecutionPayload.depositRequests, it.getDepositRequest)),
withdrawal_requests: List[electra.WithdrawalRequest,
MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD].init(
mapIt(rpcExecutionPayload.withdrawalRequests,
it.getWithdrawalRequest)),
consolidation_requests: List[electra.ConsolidationRequest,
Limit MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD].init(
mapIt(rpcExecutionPayload.consolidationRequests,
it.getConsolidationRequest)))
excess_blob_gas: rpcExecutionPayload.excessBlobGas.uint64)

func asConsensusType*(payload: engine_api.GetPayloadV4Response):
electra.ExecutionPayloadForSigning =
Expand All @@ -229,8 +218,10 @@ func asConsensusType*(payload: engine_api.GetPayloadV4Response):
blobs: Blobs.init(
payload.blobsBundle.blobs.mapIt(it.bytes))))

func asEngineExecutionPayload*(executionPayload: bellatrix.ExecutionPayload):
func asEngineExecutionPayload*(blockBody: bellatrix.BeaconBlockBody):
ExecutionPayloadV1 =
template executionPayload(): untyped = blockBody.execution_payload

template getTypedTransaction(tt: bellatrix.Transaction): TypedTransaction =
TypedTransaction(tt.distinctBase)

Expand Down Expand Up @@ -258,8 +249,10 @@ template toEngineWithdrawal*(w: capella.Withdrawal): WithdrawalV1 =
address: Address(w.address.data),
amount: Quantity(w.amount))

func asEngineExecutionPayload*(executionPayload: capella.ExecutionPayload):
func asEngineExecutionPayload*(blockBody: capella.BeaconBlockBody):
ExecutionPayloadV2 =
template executionPayload(): untyped = blockBody.execution_payload

template getTypedTransaction(tt: bellatrix.Transaction): TypedTransaction =
TypedTransaction(tt.distinctBase)
engine_api.ExecutionPayloadV2(
Expand All @@ -280,8 +273,10 @@ func asEngineExecutionPayload*(executionPayload: capella.ExecutionPayload):
transactions: mapIt(executionPayload.transactions, it.getTypedTransaction),
withdrawals: mapIt(executionPayload.withdrawals, it.toEngineWithdrawal))

func asEngineExecutionPayload*(executionPayload: deneb.ExecutionPayload):
func asEngineExecutionPayload*(blockBody: deneb.BeaconBlockBody):
ExecutionPayloadV3 =
template executionPayload(): untyped = blockBody.execution_payload

template getTypedTransaction(tt: bellatrix.Transaction): TypedTransaction =
TypedTransaction(tt.distinctBase)

Expand All @@ -305,8 +300,10 @@ func asEngineExecutionPayload*(executionPayload: deneb.ExecutionPayload):
blobGasUsed: Quantity(executionPayload.blob_gas_used),
excessBlobGas: Quantity(executionPayload.excess_blob_gas))

func asEngineExecutionPayload*(executionPayload: electra.ExecutionPayload):
func asEngineExecutionPayload*(blockBody: electra.BeaconBlockBody):
ExecutionPayloadV4 =
template executionPayload(): untyped = blockBody.execution_payload

template getTypedTransaction(tt: bellatrix.Transaction): TypedTransaction =
TypedTransaction(tt.distinctBase)

Expand Down Expand Up @@ -352,9 +349,9 @@ func asEngineExecutionPayload*(executionPayload: electra.ExecutionPayload):
withdrawals: mapIt(executionPayload.withdrawals, it.asEngineWithdrawal),
blobGasUsed: Quantity(executionPayload.blob_gas_used),
excessBlobGas: Quantity(executionPayload.excess_blob_gas),
depositRequests: mapIt(
executionPayload.deposit_requests, it.getDepositRequest),
depositRequests:
mapIt(blockBody.execution_requests.deposits, it.getDepositRequest),
withdrawalRequests: mapIt(
executionPayload.withdrawal_requests, it.getWithdrawalRequest),
blockBody.execution_requests.withdrawals, it.getWithdrawalRequest),
consolidationRequests: mapIt(
executionPayload.consolidation_requests, it.getConsolidationRequest))
blockBody.execution_requests.consolidations, it.getConsolidationRequest))
5 changes: 1 addition & 4 deletions beacon_chain/spec/beaconstate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2038,10 +2038,7 @@ func upgrade_to_electra*(
transactions_root: pre.latest_execution_payload_header.transactions_root,
withdrawals_root: pre.latest_execution_payload_header.withdrawals_root,
blob_gas_used: 0,
excess_blob_gas: 0,
deposit_requests_root: ZERO_HASH, # [New in Electra:EIP6110]
withdrawal_requests_root: ZERO_HASH, # [New in Electra:EIP7002],
consolidation_requests_root: ZERO_HASH # [New in Electra:EIP7251]
excess_blob_gas: 0
)

var max_exit_epoch = FAR_FUTURE_EPOCH
Expand Down
2 changes: 1 addition & 1 deletion beacon_chain/spec/datatypes/base.nim
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export
tables, results, endians2, json_serialization, sszTypes, beacon_time, crypto,
digest, presets

const SPEC_VERSION* = "1.5.0-alpha.5"
const SPEC_VERSION* = "1.5.0-alpha.6"
## Spec version we're aiming to be compatible with, right now

const
Expand Down
3 changes: 0 additions & 3 deletions beacon_chain/spec/datatypes/constants.nim
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ const
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.5/specs/capella/beacon-chain.md#domain-types
DOMAIN_BLS_TO_EXECUTION_CHANGE* = DomainType([byte 0x0a, 0x00, 0x00, 0x00])

# https://github.com/ethereum/consensus-specs/blob/82133085a1295e93394ebdf71df8f2f6e0962588/specs/electra/beacon-chain.md#domains
DOMAIN_CONSOLIDATION* = DomainType([byte 0x0b, 0x00, 0x00, 0x00])

# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.5/specs/phase0/fork-choice.md#configuration
PROPOSER_SCORE_BOOST*: uint64 = 40
REORG_HEAD_WEIGHT_THRESHOLD*: uint64 = 20
Expand Down
50 changes: 22 additions & 28 deletions beacon_chain/spec/datatypes/electra.nim
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type
attestation_1*: TrustedIndexedAttestation # Modified in Electra:EIP7549]
attestation_2*: TrustedIndexedAttestation # Modified in Electra:EIP7549]

# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/specs/electra/beacon-chain.md#executionpayload
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.6/specs/deneb/beacon-chain.md#executionpayload
ExecutionPayload* = object
# Execution block header fields
parent_hash*: Eth2Digest
Expand All @@ -114,21 +114,13 @@ type
withdrawals*: List[Withdrawal, MAX_WITHDRAWALS_PER_PAYLOAD]
blob_gas_used*: uint64
excess_blob_gas*: uint64
deposit_requests*: List[DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD]
## [New in Electra:EIP6110]
withdrawal_requests*:
List[WithdrawalRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD]
## [New in Electra:EIP7002:EIP7251]
consolidation_requests*:
List[ConsolidationRequest, Limit MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD]
## [New in Electra:EIP7251]

ExecutionPayloadForSigning* = object
executionPayload*: ExecutionPayload
blockValue*: Wei
blobsBundle*: BlobsBundle

# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/specs/electra/beacon-chain.md#executionpayloadheader
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.6/specs/deneb/beacon-chain.md#executionpayloadheader
ExecutionPayloadHeader* = object
# Execution block header fields
parent_hash*: Eth2Digest
Expand All @@ -151,9 +143,6 @@ type
withdrawals_root*: Eth2Digest
blob_gas_used*: uint64
excess_blob_gas*: uint64
deposit_requests_root*: Eth2Digest # [New in Electra:EIP6110]
withdrawal_requests_root*: Eth2Digest # [New in Electra:EIP7002:EIP7251]
consolidation_requests_root*: Eth2Digest # [New in Electra:EIP7251]

ExecutePayload* = proc(
execution_payload: ExecutionPayload): bool {.gcsafe, raises: [].}
Expand Down Expand Up @@ -304,6 +293,18 @@ type
## (used to compute safety threshold)
current_max_active_participants*: uint64

# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.6/specs/electra/beacon-chain.md#executionrequests
ExecutionRequests* = object
deposits*:
List[DepositRequest,
Limit MAX_DEPOSIT_REQUESTS_PER_PAYLOAD] # [New in Electra:EIP6110]
withdrawals*:
List[WithdrawalRequest,
Limit MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD] # [New in Electra:EIP7002:EIP7251]
consolidations*:
List[ConsolidationRequest,
Limit MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD] # [New in Electra:EIP7251]

# https://github.com/ethereum/consensus-specs/blob/82133085a1295e93394ebdf71df8f2f6e0962588/specs/electra/beacon-chain.md#beaconstate
BeaconState* = object
# Versioning
Expand Down Expand Up @@ -456,7 +457,7 @@ type
state_root*: Eth2Digest
body*: TrustedBeaconBlockBody

# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/specs/electra/beacon-chain.md#beaconblockbody
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.6/specs/electra/beacon-chain.md#beaconblockbody
BeaconBlockBody* = object
randao_reveal*: ValidatorSig
eth1_data*: Eth1Data
Expand All @@ -481,6 +482,7 @@ type
execution_payload*: electra.ExecutionPayload # [Modified in Electra:EIP6110:EIP7002]
bls_to_execution_changes*: SignedBLSToExecutionChangeList
blob_kzg_commitments*: KzgCommitments
execution_requests*: ExecutionRequests # [New in Electra]

SigVerifiedBeaconBlockBody* = object
## A BeaconBlock body with signatures verified
Expand Down Expand Up @@ -520,6 +522,7 @@ type
execution_payload*: ExecutionPayload # [Modified in Electra:EIP6110:EIP7002]
bls_to_execution_changes*: SignedBLSToExecutionChangeList
blob_kzg_commitments*: KzgCommitments
execution_requests*: ExecutionRequests # [New in Electra]

TrustedBeaconBlockBody* = object
## A full verified block
Expand Down Expand Up @@ -547,6 +550,7 @@ type
execution_payload*: ExecutionPayload # [Modified in Electra:EIP6110:EIP7002]
bls_to_execution_changes*: SignedBLSToExecutionChangeList
blob_kzg_commitments*: KzgCommitments
execution_requests*: ExecutionRequests # [New in Electra]

# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#signedbeaconblock
SignedBeaconBlock* = object
Expand Down Expand Up @@ -731,26 +735,19 @@ func get_lc_execution_root*(

ZERO_HASH

# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/specs/electra/light-client/sync-protocol.md#modified-is_valid_light_client_header
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.6/specs/electra/light-client/sync-protocol.md#modified-is_valid_light_client_header
func is_valid_light_client_header*(
header: LightClientHeader, cfg: RuntimeConfig): bool =
let epoch = header.beacon.slot.epoch

# [New in Electra:EIP6110:EIP7002:EIP7251]
if epoch < cfg.ELECTRA_FORK_EPOCH:
if not header.execution.deposit_requests_root.isZero or
not header.execution.withdrawal_requests_root.isZero or
not header.execution.consolidation_requests_root.isZero:
return false

if epoch < cfg.DENEB_FORK_EPOCH:
if header.execution.blob_gas_used != 0 or
header.execution.excess_blob_gas != 0:
return false

if epoch < cfg.CAPELLA_FORK_EPOCH:
return
header.execution == static(default(ExecutionPayloadHeader)) and
header.execution == static(default(electra.ExecutionPayloadHeader)) and
header.execution_branch == static(default(ExecutionBranch))

is_valid_merkle_branch(
Expand All @@ -776,7 +773,7 @@ func normalize_merkle_branch*[N](
res[0 ..< depth] = branch[num_extra ..< branch.len]
res

# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/specs/electra/light-client/fork.md#upgrading-light-client-data
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.6/specs/electra/light-client/fork.md#upgrading-light-client-data
func upgrade_lc_header_to_electra*(
pre: deneb.LightClientHeader): LightClientHeader =
LightClientHeader(
Expand All @@ -798,10 +795,7 @@ func upgrade_lc_header_to_electra*(
transactions_root: pre.execution.transactions_root,
withdrawals_root: pre.execution.withdrawals_root,
blob_gas_used: pre.execution.blob_gas_used,
excess_blob_gas: pre.execution.excess_blob_gas,
deposit_requests_root: ZERO_HASH, # [New in Electra:EIP6110]
withdrawal_requests_root: ZERO_HASH, # [New in Electra:EIP7002:EIP7251]
consolidation_requests_root: ZERO_HASH), # [New in Electra:EIP7251]
excess_blob_gas: pre.execution.excess_blob_gas),
execution_branch: pre.execution_branch)

# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/specs/electra/light-client/fork.md#upgrading-light-client-data
Expand Down
1 change: 1 addition & 0 deletions beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ RestJson.useDefaultSerializationFor(
EmptyBody,
Eth1Data,
EventBeaconBlockObject,
ExecutionRequests,
Fork,
GetBlockAttestationsResponse,
GetBlockHeaderResponse,
Expand Down
6 changes: 1 addition & 5 deletions beacon_chain/spec/forks_light_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1229,11 +1229,7 @@ func toElectraLightClientHeader(
transactions_root: hash_tree_root(payload.transactions),
withdrawals_root: hash_tree_root(payload.withdrawals),
blob_gas_used: payload.blob_gas_used,
excess_blob_gas: payload.excess_blob_gas,
deposit_requests_root: hash_tree_root(payload.deposit_requests),
withdrawal_requests_root: hash_tree_root(payload.withdrawal_requests),
consolidation_requests_root:
hash_tree_root(payload.consolidation_requests)),
excess_blob_gas: payload.excess_blob_gas),
execution_branch: blck.message.body.build_proof(
capella.EXECUTION_PAYLOAD_GINDEX).get)

Expand Down
Loading

0 comments on commit 193a982

Please sign in to comment.