add EF consensus spec test Electra deposit receipt operations fixture (#6245)

This commit is contained in:
tersec 2024-04-26 12:39:09 +00:00 committed by GitHub
parent 34ba05f4d3
commit 63d00931a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 150 additions and 72 deletions

View File

@ -2638,6 +2638,27 @@ OK: 11/11 Fail: 0/11 Skip: 0/11
+ [Valid] EF - Electra - Operations - Deposit - top_up__zero_balance OK
```
OK: 21/21 Fail: 0/21 Skip: 0/21
## EF - Electra - Operations - Deposit Receipt [Preset: mainnet]
```diff
+ [Valid] EF - Electra - Operations - Deposit Receipt - correct_sig_but_forked_state OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - effective_deposit_with_genesis_for OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - incorrect_sig_new_deposit OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - incorrect_sig_top_up OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - incorrect_withdrawal_credentials_t OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - ineffective_deposit_with_previous_ OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - key_validate_invalid_decompression OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - key_validate_invalid_subgroup OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - new_deposit_eth1_withdrawal_creden OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - new_deposit_max OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - new_deposit_non_versioned_withdraw OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - new_deposit_over_max OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - new_deposit_under_max OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - success_top_up_to_withdrawn_valida OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - top_up__less_effective_balance OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - top_up__max_effective_balance OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - top_up__zero_balance OK
```
OK: 17/17 Fail: 0/17 Skip: 0/17
## EF - Electra - Operations - Execution Layer Withdrawal Request [Preset: mainnet]
```diff
+ [Valid] EF - Electra - Operations - Execution Layer Withdrawal Request - activation_epoc OK
@ -3422,4 +3443,4 @@ OK: 69/88 Fail: 0/88 Skip: 19/88
OK: 3/3 Fail: 0/3 Skip: 0/3
---TOTAL---
OK: 2737/2756 Fail: 0/2756 Skip: 19/2756
OK: 2754/2773 Fail: 0/2773 Skip: 19/2773

View File

@ -2774,6 +2774,27 @@ OK: 20/20 Fail: 0/20 Skip: 0/20
+ [Valid] EF - Electra - Operations - Deposit - top_up__zero_balance OK
```
OK: 21/21 Fail: 0/21 Skip: 0/21
## EF - Electra - Operations - Deposit Receipt [Preset: minimal]
```diff
+ [Valid] EF - Electra - Operations - Deposit Receipt - correct_sig_but_forked_state OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - effective_deposit_with_genesis_for OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - incorrect_sig_new_deposit OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - incorrect_sig_top_up OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - incorrect_withdrawal_credentials_t OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - ineffective_deposit_with_previous_ OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - key_validate_invalid_decompression OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - key_validate_invalid_subgroup OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - new_deposit_eth1_withdrawal_creden OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - new_deposit_max OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - new_deposit_non_versioned_withdraw OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - new_deposit_over_max OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - new_deposit_under_max OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - success_top_up_to_withdrawn_valida OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - top_up__less_effective_balance OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - top_up__max_effective_balance OK
+ [Valid] EF - Electra - Operations - Deposit Receipt - top_up__zero_balance OK
```
OK: 17/17 Fail: 0/17 Skip: 0/17
## EF - Electra - Operations - Execution Layer Withdrawal Request [Preset: minimal]
```diff
+ [Valid] EF - Electra - Operations - Execution Layer Withdrawal Request - activation_epoc OK
@ -3724,4 +3745,4 @@ OK: 185/207 Fail: 0/207 Skip: 22/207
OK: 3/3 Fail: 0/3 Skip: 0/3
---TOTAL---
OK: 3008/3030 Fail: 0/3030 Skip: 22/3030
OK: 3025/3047 Fail: 0/3047 Skip: 22/3047

View File

@ -84,6 +84,7 @@ const
MAX_REQUEST_BLOCKS_DENEB*: uint64 = 128 # TODO Make use of in request code
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.0/specs/electra/beacon-chain.md#misc
UNSET_DEPOSIT_RECEIPTS_START_INDEX*: uint64 = not 0'u64
FULL_EXIT_REQUEST_AMOUNT*: uint64 = 0
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.0/specs/electra/beacon-chain.md#withdrawal-prefixes

View File

@ -305,6 +305,77 @@ from ".."/bloomfilter import
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.0/specs/phase0/beacon-chain.md#deposits
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.0/specs/electra/beacon-chain.md#updated--apply_deposit
proc apply_deposit(
cfg: RuntimeConfig, state: var ForkyBeaconState,
bloom_filter: var PubkeyBloomFilter, deposit_data: DepositData,
flags: UpdateFlags): Result[void, cstring] =
let
pubkey = deposit_data.pubkey
amount = deposit_data.amount
index =
if bloom_filter.mightContain(pubkey):
findValidatorIndex(state, pubkey)
else:
Opt.none(ValidatorIndex)
if index.isSome():
# Increase balance by deposit amount
when typeof(state).kind < ConsensusFork.Electra:
increase_balance(state, index.get(), amount)
else:
debugRaiseAssert "check hashlist add return"
discard state.pending_balance_deposits.add PendingBalanceDeposit(
index: index.get.uint64, amount: amount) # [Modified in Electra:EIP-7251]
# Check if valid deposit switch to compounding credentials
if is_compounding_withdrawal_credential(
deposit_data.withdrawal_credentials) and
has_eth1_withdrawal_credential(state.validators.item(index.get)) and
verify_deposit_signature(cfg, deposit_data):
switch_to_compounding_validator(state, index.get)
else:
# Verify the deposit signature (proof of possession) which is not checked
# by the deposit contract
if verify_deposit_signature(cfg, deposit_data):
# New validator! Add validator and balance entries
if not state.validators.add(
get_validator_from_deposit(state, deposit_data)):
return err("apply_deposit: too many validators")
let initial_balance =
when typeof(state).kind >= ConsensusFork.Electra:
0.Gwei
else:
amount
if not state.balances.add(initial_balance):
static: doAssert state.balances.maxLen == state.validators.maxLen
raiseAssert "adding validator succeeded, so should balances"
when typeof(state).kind >= ConsensusFork.Altair:
if not state.previous_epoch_participation.add(ParticipationFlags(0)):
return err("apply_deposit: too many validators (previous_epoch_participation)")
if not state.current_epoch_participation.add(ParticipationFlags(0)):
return err("apply_deposit: too many validators (current_epoch_participation)")
if not state.inactivity_scores.add(0'u64):
return err("apply_deposit: too many validators (inactivity_scores)")
when typeof(state).kind >= ConsensusFork.Electra:
debugRaiseAssert "check hashlist add return"
# [New in Electra:EIP7251]
discard state.pending_balance_deposits.add PendingBalanceDeposit(
index: state.validators.lenu64 - 1, amount: amount)
doAssert state.validators.len == state.balances.len
bloom_filter.incl pubkey
else:
# Deposits may come with invalid signatures - in that case, they are not
# turned into a validator but still get processed to keep the deposit
# index correct
trace "Skipping deposit with invalid signature",
deposit = shortLog(deposit_data)
ok()
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.0/specs/phase0/beacon-chain.md#deposits
proc process_deposit*(
cfg: RuntimeConfig, state: var ForkyBeaconState,
bloom_filter: var PubkeyBloomFilter, deposit: Deposit, flags: UpdateFlags):
@ -324,71 +395,7 @@ proc process_deposit*(
# Deposits must be processed in order
state.eth1_deposit_index += 1
let
pubkey = deposit.data.pubkey
amount = deposit.data.amount
index =
if bloom_filter.mightContain(pubkey):
findValidatorIndex(state, pubkey)
else:
Opt.none(ValidatorIndex)
if index.isSome():
# Increase balance by deposit amount
when typeof(state).kind < ConsensusFork.Electra:
increase_balance(state, index.get(), amount)
else:
debugRaiseAssert "check hashlist add return"
discard state.pending_balance_deposits.add PendingBalanceDeposit(
index: index.get.uint64, amount: amount) # [Modified in Electra:EIP-7251]
# Check if valid deposit switch to compounding credentials
if is_compounding_withdrawal_credential(
deposit.data.withdrawal_credentials) and
has_eth1_withdrawal_credential(state.validators.item(index.get)) and
verify_deposit_signature(cfg, deposit.data):
switch_to_compounding_validator(state, index.get)
else:
# Verify the deposit signature (proof of possession) which is not checked
# by the deposit contract
if verify_deposit_signature(cfg, deposit.data):
# New validator! Add validator and balance entries
if not state.validators.add(
get_validator_from_deposit(state, deposit.data)):
return err("process_deposit: too many validators")
let initial_balance =
when typeof(state).kind >= ConsensusFork.Electra:
0.Gwei
else:
amount
if not state.balances.add(initial_balance):
static: doAssert state.balances.maxLen == state.validators.maxLen
raiseAssert "adding validator succeeded, so should balances"
when typeof(state).kind >= ConsensusFork.Altair:
if not state.previous_epoch_participation.add(ParticipationFlags(0)):
return err("process_deposit: too many validators (previous_epoch_participation)")
if not state.current_epoch_participation.add(ParticipationFlags(0)):
return err("process_deposit: too many validators (current_epoch_participation)")
if not state.inactivity_scores.add(0'u64):
return err("process_deposit: too many validators (inactivity_scores)")
when typeof(state).kind >= ConsensusFork.Electra:
debugRaiseAssert "check hashlist add return"
# [New in Electra:EIP7251]
discard state.pending_balance_deposits.add PendingBalanceDeposit(
index: state.validators.lenu64 - 1, amount: amount)
doAssert state.validators.len == state.balances.len
bloom_filter.incl pubkey
else:
# Deposits may come with invalid signatures - in that case, they are not
# turned into a validator but still get processed to keep the deposit
# index correct
trace "Skipping deposit with invalid signature",
deposit = shortLog(deposit.data)
ok()
apply_deposit(cfg, state, bloom_filter, deposit.data, flags)
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/phase0/beacon-chain.md#voluntary-exits
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/deneb/beacon-chain.md#modified-process_voluntary_exit
@ -1066,6 +1073,23 @@ func process_consolidation*(
ok()
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.0/specs/electra/beacon-chain.md#new-process_deposit_receipt
func process_deposit_receipt*(
cfg: RuntimeConfig, state: var electra.BeaconState,
bloom_filter: var PubkeyBloomFilter, deposit_receipt: DepositReceipt,
flags: UpdateFlags): Result[void, cstring] =
# Set deposit receipt start index
if state.deposit_receipts_start_index ==
UNSET_DEPOSIT_RECEIPTS_START_INDEX:
state.deposit_receipts_start_index = deposit_receipt.index
apply_deposit(
cfg, state, bloom_filter, DepositData(
pubkey: deposit_receipt.pubkey,
withdrawal_credentials: deposit_receipt.withdrawal_credentials,
amount: deposit_receipt.amount,
signature: deposit_receipt.signature), flags)
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/deneb/beacon-chain.md#kzg_commitment_to_versioned_hash
func kzg_commitment_to_versioned_hash*(
kzg_commitment: KzgCommitment): VersionedHash =

View File

@ -145,7 +145,7 @@ suite baseDescription & "BLS to execution change " & preset():
from ".."/".."/".."/beacon_chain/bloomfilter import constructBloomFilter
suite baseDescription & "Deposit " & preset():
proc applyDeposit(
func applyDeposit(
preState: var deneb.BeaconState, deposit: Deposit):
Result[void, cstring] =
process_deposit(
@ -157,7 +157,7 @@ suite baseDescription & "Deposit " & preset():
OpDepositsDir, suiteName, "Deposit", "deposit", applyDeposit, path)
suite baseDescription & "Execution Payload " & preset():
proc makeApplyExecutionPayloadCb(path: string): auto =
func makeApplyExecutionPayloadCb(path: string): auto =
return proc(
preState: var deneb.BeaconState, body: deneb.BeaconBlockBody):
Result[void, cstring] {.raises: [IOError].} =
@ -221,7 +221,7 @@ suite baseDescription & "Voluntary Exit " & preset():
applyVoluntaryExit, path)
suite baseDescription & "Withdrawals " & preset():
proc applyWithdrawals(
func applyWithdrawals(
preState: var deneb.BeaconState,
executionPayload: deneb.ExecutionPayload): Result[void, cstring] =
process_withdrawals(preState, executionPayload)

View File

@ -183,6 +183,19 @@ suite baseDescription & "Deposit " & preset():
runTest[Deposit, typeof applyDeposit](
OpDepositsDir, suiteName, "Deposit", "deposit", applyDeposit, path)
suite baseDescription & "Deposit Receipt" & preset():
func applyDepositReceipt(
preState: var electra.BeaconState, depositReceipt: DepositReceipt):
Result[void, cstring] =
process_deposit_receipt(
defaultRuntimeConfig, preState,
constructBloomFilter(preState.validators.asSeq)[], depositReceipt, {})
for path in walkTests(OpDepositReceiptDir):
runTest[DepositReceipt, typeof applyDepositReceipt](
OpDepositReceiptDir, suiteName, "Deposit Receipt", "deposit_receipt",
applyDepositReceipt, path)
when false:
suite baseDescription & "Execution Payload " & preset():
func makeApplyExecutionPayloadCb(path: string): auto =
@ -201,8 +214,6 @@ when false:
OpExecutionPayloadDir, suiteName, "Execution Payload", "body",
applyExecutionPayload, path)
debugRaiseAssert "deposit receipts"
suite baseDescription & "Execution Layer Withdrawal Request " & preset():
func applyExecutionLayerWithdrawalRequest(
preState: var electra.BeaconState,