Skip to content

Commit e0d251b

Browse files
committed
Fix Process same-slot slashings before builder payments in Gloas #4561
1 parent f96d3e7 commit e0d251b

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

specs/gloas/beacon-chain.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,6 @@ def process_builder_pending_payments(state: BeaconState) -> None:
729729

730730
```python
731731
def process_block(state: BeaconState, block: BeaconBlock) -> None:
732-
process_block_header(state, block)
733-
# [Modified in Gloas:EIP7732]
734732
process_withdrawals(state)
735733
# [Modified in Gloas:EIP7732]
736734
# Removed `process_execution_payload`
@@ -741,6 +739,8 @@ def process_block(state: BeaconState, block: BeaconBlock) -> None:
741739
# [Modified in Gloas:EIP7732]
742740
process_operations(state, block.body)
743741
process_sync_aggregate(state, block.body.sync_aggregate)
742+
# [Modified in Gloas:EIP7732]
743+
process_block_header(state, block)
744744
```
745745

746746
#### Withdrawals

tests/core/pyspec/eth2spec/test/gloas/block_processing/test_process_execution_payload_bid.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import random
2+
from eth2spec.test.helpers.state import next_epoch
3+
14
from eth2spec.test.context import (
25
always_bls,
36
spec_state_test,
@@ -9,6 +12,7 @@
912
set_builder_withdrawal_credential,
1013
set_builder_withdrawal_credential_with_balance,
1114
)
15+
from eth2spec.test.helpers.execution_payload import build_empty_execution_payload
1216

1317

1418
def run_execution_payload_bid_processing(spec, state, block, valid=True):
@@ -349,6 +353,50 @@ def test_process_execution_payload_bid_slashed_builder(spec, state):
349353
yield from run_execution_payload_bid_processing(spec, state, block, valid=False)
350354

351355

356+
@with_gloas_and_later
357+
@spec_state_test
358+
def test_process_block_then_slash_non_timely_builder(spec, state):
359+
"""
360+
Test proposer is rewarded if builder is slashed after a successful bid.
361+
This test case tests the third fork choice - "Empty", The beacon block has been included on-chain, but the committed execution payload has not.
362+
The beacon block proposer received payment from the corresponding builder.
363+
"""
364+
365+
# Advance to a state past genesis so the builder is active
366+
next_epoch(spec, state)
367+
next_epoch(spec, state)
368+
state.slot += random.randrange(spec.SLOTS_PER_EPOCH)
369+
370+
# Prepare block and assign a builder who is not the proposer
371+
block, builder_index = prepare_block_with_non_proposer_builder(spec, state)
372+
proposer_index = block.proposer_index
373+
374+
# Give builder enough balance for the bid to succeed
375+
value = spec.Gwei(1_000_000)
376+
state.balances[builder_index] = value + spec.MIN_ACTIVATION_BALANCE
377+
378+
# Prepare and insert a valid signed bid from the builder
379+
signed_bid = prepare_signed_execution_payload_bid(
380+
spec,
381+
state,
382+
builder_index=builder_index,
383+
value=value,
384+
slot=block.slot,
385+
parent_block_root=block.parent_root,
386+
)
387+
388+
block.body.signed_execution_payload_bid = signed_bid
389+
payload = build_empty_execution_payload(spec, state)
390+
391+
# Capture proposer balance before processing
392+
pre_balance = state.balances[proposer_index]
393+
394+
spec.process_block(state, block)
395+
396+
post_balance = state.balances[proposer_index]
397+
assert post_balance >= pre_balance + value, "Proposer did not receive builder's slashed bid value"
398+
399+
352400
@with_gloas_and_later
353401
@spec_state_test
354402
def test_process_execution_payload_bid_self_build_non_zero_value(spec, state):

0 commit comments

Comments
 (0)