Skip to content

Commit 37d0a21

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

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-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: 45 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,
@@ -349,6 +352,48 @@ def test_process_execution_payload_bid_slashed_builder(spec, state):
349352
yield from run_execution_payload_bid_processing(spec, state, block, valid=False)
350353

351354

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

0 commit comments

Comments
 (0)