Fix python execution 2

This commit is contained in:
Potuz 2024-07-02 17:30:59 -03:00
parent 2a43ce54d6
commit 4500eabf8c
3 changed files with 61 additions and 42 deletions

View File

@ -288,9 +288,12 @@ def bit_floor(n: uint64) -> uint64:
#### `is_valid_indexed_payload_attestation`
```python
def is_valid_indexed_payload_attestation(state: BeaconState, indexed_payload_attestation: IndexedPayloadAttestation) -> bool:
def is_valid_indexed_payload_attestation(
state: BeaconState,
indexed_payload_attestation: IndexedPayloadAttestation) -> bool:
"""
Check if ``indexed_payload_attestation`` is not empty, has sorted and unique indices and has a valid aggregate signature.
Check if ``indexed_payload_attestation`` is not empty, has sorted and unique indices and has
a valid aggregate signature.
"""
# Verify the data is valid
if indexed_payload_attestation.data.payload_status >= PAYLOAD_INVALID_STATUS:
@ -415,7 +418,7 @@ def process_block(state: BeaconState, block: BeaconBlock) -> None:
```python
def process_withdrawals(state: BeaconState) -> None:
## return early if the parent block was empty
# return early if the parent block was empty
if not is_parent_block_full(state):
return
@ -518,17 +521,16 @@ def remove_flag(flags: ParticipationFlags, flag_index: int) -> ParticipationFlag
```python
def process_payload_attestation(state: BeaconState, payload_attestation: PayloadAttestation) -> None:
## Check that the attestation is for the parent beacon block
# Check that the attestation is for the parent beacon block
data = payload_attestation.data
assert data.beacon_block_root == state.latest_block_header.parent_root
## Check that the attestation is for the previous slot
# Check that the attestation is for the previous slot
assert data.slot + 1 == state.slot
#Verify signature
# Verify signature
indexed_payload_attestation = get_indexed_payload_attestation(state, data.slot, payload_attestation)
assert is_valid_indexed_payload_attestation(state, indexed_payload_attestation)
ptc = get_ptc(state, data.slot)
if state.slot % SLOTS_PER_EPOCH == 0:
epoch_participation = state.previous_epoch_participation
else:
@ -548,7 +550,7 @@ def process_payload_attestation(state: BeaconState, payload_attestation: Payload
epoch_participation[index] = remove_flag(epoch_participation[index], flag_index)
proposer_penalty_numerator += get_base_reward(state, index) * weight
# Penalize the proposer
proposer_penalty = Gwei(2*proposer_penalty_numerator // proposer_reward_denominator)
proposer_penalty = Gwei(2 * proposer_penalty_numerator // proposer_reward_denominator)
decrease_balance(state, proposer_index, proposer_penalty)
return
@ -568,7 +570,8 @@ def process_payload_attestation(state: BeaconState, payload_attestation: Payload
#### New `verify_execution_payload_envelope_signature`
```python
def verify_execution_payload_envelope_signature(state: BeaconState, signed_envelope: SignedExecutionPayloadEnvelope) -> bool:
def verify_execution_payload_envelope_signature(
state: BeaconState, signed_envelope: SignedExecutionPayloadEnvelope) -> bool:
builder = state.validators[signed_envelope.message.builder_index]
signing_root = compute_signing_root(signed_envelope.message, get_domain(state, DOMAIN_BEACON_BUILDER))
return bls.Verify(builder.pubkey, signing_root, signed_envelope.signature)
@ -578,7 +581,9 @@ def verify_execution_payload_envelope_signature(state: BeaconState, signed_envel
*Note*: `process_execution_payload` is now an independent check in state transition. It is called when importing a signed execution payload proposed by the builder of the current slot.
```python
def process_execution_payload(state: BeaconState, signed_envelope: SignedExecutionPayloadEnvelope, execution_engine: ExecutionEngine, verify = True) -> None:
def process_execution_payload(state: BeaconState,
signed_envelope: SignedExecutionPayloadEnvelope,
execution_engine: ExecutionEngine, verify=True) -> None:
# Verify signature
if verify:
assert verify_execution_payload_envelope_signature(state, signed_envelope)
@ -607,7 +612,8 @@ def process_execution_payload(state: BeaconState, signed_envelope: SignedExecuti
# Verify timestamp
assert payload.timestamp == compute_timestamp_at_slot(state, state.slot)
# Verify the execution payload is valid
versioned_hashes = [kzg_commitment_to_versioned_hash(commitment) for commitment in envelope.blob_kzg_commitments]
versioned_hashes = [kzg_commitment_to_versioned_hash(commitment)
for commitment in envelope.blob_kzg_commitments]
assert execution_engine.verify_and_notify_new_payload(
NewPayloadRequest(
execution_payload=payload,

View File

@ -41,7 +41,8 @@ Builders can broadcast a payload bid for the current or the next slot's proposer
After building the `header`, the builder obtains a `signature` of the header by using
```python
def get_execution_payload_header_signature(state: BeaconState, header: ExecutionPayloadHeader, privkey: int) -> BLSSignature:
def get_execution_payload_header_signature(
state: BeaconState, header: ExecutionPayloadHeader, privkey: int) -> BLSSignature:
domain = get_domain(state, DOMAIN_BEACON_BUILDER, compute_epoch_at_slot(header.slot))
signing_root = compute_signing_root(header, domain)
return bls.Sign(privkey, signing_root)
@ -101,7 +102,8 @@ After setting these parameters, the builder should run `process_execution_payloa
6. Set `state_root` to `hash_tree_root(state)`.
After preparing the `envelope` the builder should sign the envelope using:
```python
def get_execution_payload_envelope_signature(state: BeaconState, envelope: ExecutionPayloadEnvelope, privkey: int) -> BLSSignature:
def get_execution_payload_envelope_signature(
state: BeaconState, envelope: ExecutionPayloadEnvelope, privkey: int) -> BLSSignature:
domain = get_domain(state, DOMAIN_BEACON_BUILDER, compute_epoch_at_slot(state.slot))
signing_root = compute_signing_root(envelope, domain)
return bls.Sign(privkey, signing_root)

View File

@ -44,7 +44,7 @@ This is the modification of the fork choice accompanying the ePBS upgrade.
| Name | Value |
| -------------------- | ----------- |
| `PAYLOAD_TIMELY_THRESHOLD` | `PTC_SIZE/2` (=`uint64(256)`) |
| `PAYLOAD_TIMELY_THRESHOLD` | `PTC_SIZE / 2` (=`uint64(256)`) |
| `INTERVALS_PER_SLOT` | `4` # [modified in EIP-XXXX] |
| `PROPOSER_SCORE_BOOST` | `20` # [modified in EIP-XXXX] |
| `PAYLOAD_WITHHOLD_BOOST` | `40` |
@ -156,8 +156,9 @@ def notify_ptc_messages(store: Store, state: BeaconState, payload_attestations:
for payload_attestation in payload_attestations:
indexed_payload_attestation = get_indexed_payload_attestation(state, Slot(state.slot - 1), payload_attestation)
for idx in indexed_payload_attestation.attesting_indices:
on_payload_attestation_message(store, PayloadAttestationMessage(validator_index=idx,
data=payload_attestation.data, signature= BLSSignature(), is_from_block=True))
on_payload_attestation_message(store,
PayloadAttestationMessage(validator_index=idx,
data=payload_attestation.data, signature=BLSSignature(), is_from_block=True))
```
### `is_payload_present`
@ -333,19 +334,29 @@ def get_head(store: Store) -> ChildNode:
children = [
ChildNode(root=root, slot=block.slot, is_payload_present=present) for (root, block) in blocks.items()
if block.parent_root == best_child.root and
is_parent_node_full(store, block) == best_child.is_payload_present if root != store.justified_checkpoint.root
for present in (True, False) if root in store.execution_payload_states or present == False
is_parent_node_full(store, block) == best_child.is_payload_present if
root != store.justified_checkpoint.root
for present in (True, False) if root in store.execution_payload_states or not present
]
if len(children) == 0:
return best_child
# if we have children we consider the current head advanced as a possible head
children += [ChildNode(root=best_child.root, slot=best_child.slot + 1, is_payload_present=best_child.is_payload_present)]
children += [
ChildNode(root=best_child.root, slot=best_child.slot + 1, is_payload_present=best_child.is_payload_present)
]
# Sort by latest attesting balance with ties broken lexicographically
# Ties broken by favoring full blocks according to the PTC vote
# Ties are then broken by favoring full blocks
# Ties broken then by favoring higher slot numbers
# Ties then broken by favoring block with lexicographically higher root
new_best_child = max(children, key=lambda child: (get_weight(store, child), is_payload_present(store, child.root), child.is_payload_present, child.slot, child.root))
new_best_child = max(children, key=lambda child: (
get_weight(store, child),
is_payload_present(store, child.root),
child.is_payload_present,
child.slot,
child.root
)
)
if new_best_child.root == best_child.root:
return new_best_child
best_child = new_best_child
@ -402,7 +413,7 @@ def on_block(store: Store, signed_block: SignedBeaconBlock) -> None:
# Add new state for this block to the store
store.block_states[block_root] = state
# Add a new PTC voting for this block to the store
store.ptc_vote[block_root] = [PAYLOAD_ABSENT]*PTC_SIZE
store.ptc_vote[block_root] = [PAYLOAD_ABSENT] * PTC_SIZE
# Notify the store about the payload_attestations in the block
notify_ptc_messages(store, state, block.body.payload_attestations)