Merge branch 'dev' into pr3052
This commit is contained in:
commit
ee0e2a03d2
|
@ -69,6 +69,24 @@ Since the `eip4844.BeaconState` format is equal to the `capella.BeaconState` for
|
||||||
```python
|
```python
|
||||||
def upgrade_to_eip4844(pre: capella.BeaconState) -> BeaconState:
|
def upgrade_to_eip4844(pre: capella.BeaconState) -> BeaconState:
|
||||||
epoch = capella.get_current_epoch(pre)
|
epoch = capella.get_current_epoch(pre)
|
||||||
|
latest_execution_payload_header = ExecutionPayloadHeader(
|
||||||
|
parent_hash=pre.latest_execution_payload_header.parent_hash,
|
||||||
|
fee_recipient=pre.latest_execution_payload_header.fee_recipient,
|
||||||
|
state_root=pre.latest_execution_payload_header.state_root,
|
||||||
|
receipts_root=pre.latest_execution_payload_header.receipts_root,
|
||||||
|
logs_bloom=pre.latest_execution_payload_header.logs_bloom,
|
||||||
|
prev_randao=pre.latest_execution_payload_header.prev_randao,
|
||||||
|
block_number=pre.latest_execution_payload_header.block_number,
|
||||||
|
gas_limit=pre.latest_execution_payload_header.gas_limit,
|
||||||
|
gas_used=pre.latest_execution_payload_header.gas_used,
|
||||||
|
timestamp=pre.latest_execution_payload_header.timestamp,
|
||||||
|
extra_data=pre.latest_execution_payload_header.extra_data,
|
||||||
|
base_fee_per_gas=pre.latest_execution_payload_header.base_fee_per_gas,
|
||||||
|
excess_data_gas=uint256(0), # [New in EIP-4844]
|
||||||
|
block_hash=pre.latest_execution_payload_header.block_hash,
|
||||||
|
transactions_root=pre.latest_execution_payload_header.transactions_root,
|
||||||
|
withdrawals_root=pre.latest_execution_payload_header.withdrawals_root,
|
||||||
|
)
|
||||||
post = BeaconState(
|
post = BeaconState(
|
||||||
# Versioning
|
# Versioning
|
||||||
genesis_time=pre.genesis_time,
|
genesis_time=pre.genesis_time,
|
||||||
|
@ -109,7 +127,7 @@ def upgrade_to_eip4844(pre: capella.BeaconState) -> BeaconState:
|
||||||
current_sync_committee=pre.current_sync_committee,
|
current_sync_committee=pre.current_sync_committee,
|
||||||
next_sync_committee=pre.next_sync_committee,
|
next_sync_committee=pre.next_sync_committee,
|
||||||
# Execution-layer
|
# Execution-layer
|
||||||
latest_execution_payload_header=pre.latest_execution_payload_header,
|
latest_execution_payload_header=latest_execution_payload_header, # [Modified in EIP4844]
|
||||||
# Withdrawals
|
# Withdrawals
|
||||||
next_withdrawal_index=pre.next_withdrawal_index,
|
next_withdrawal_index=pre.next_withdrawal_index,
|
||||||
next_withdrawal_validator_index=pre.next_withdrawal_validator_index,
|
next_withdrawal_validator_index=pre.next_withdrawal_validator_index,
|
||||||
|
|
|
@ -49,7 +49,7 @@ def generate_from_tests(runner_name: str, handler_name: str, src: Any,
|
||||||
preset_name=preset_name,
|
preset_name=preset_name,
|
||||||
runner_name=runner_name,
|
runner_name=runner_name,
|
||||||
handler_name=handler_name,
|
handler_name=handler_name,
|
||||||
suite_name='pyspec_tests',
|
suite_name=getattr(tfn, 'suite_name', 'pyspec_tests'),
|
||||||
case_name=case_name,
|
case_name=case_name,
|
||||||
# TODO: with_all_phases and other per-phase tooling, should be replaced with per-fork equivalent.
|
# TODO: with_all_phases and other per-phase tooling, should be replaced with per-fork equivalent.
|
||||||
case_fn=lambda: tfn(generator_mode=True, phase=phase, preset=preset_name, bls_active=bls_active)
|
case_fn=lambda: tfn(generator_mode=True, phase=phase, preset=preset_name, bls_active=bls_active)
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
from eth2spec.test.context import (
|
from eth2spec.test.context import (
|
||||||
spec_state_test,
|
spec_state_test,
|
||||||
with_altair_and_later,
|
with_altair_and_later,
|
||||||
|
with_test_suite_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@with_test_suite_name("BeaconState")
|
||||||
@with_altair_and_later
|
@with_altair_and_later
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_current_sync_committee_merkle_proof(spec, state):
|
def test_current_sync_committee_merkle_proof(spec, state):
|
||||||
yield "state", state
|
yield "object", state
|
||||||
current_sync_committee_branch = spec.compute_merkle_proof_for_state(state, spec.CURRENT_SYNC_COMMITTEE_INDEX)
|
current_sync_committee_branch = \
|
||||||
|
spec.compute_merkle_proof_for_state(state, spec.CURRENT_SYNC_COMMITTEE_INDEX)
|
||||||
yield "proof", {
|
yield "proof", {
|
||||||
"leaf": "0x" + state.current_sync_committee.hash_tree_root().hex(),
|
"leaf": "0x" + state.current_sync_committee.hash_tree_root().hex(),
|
||||||
"leaf_index": spec.CURRENT_SYNC_COMMITTEE_INDEX,
|
"leaf_index": spec.CURRENT_SYNC_COMMITTEE_INDEX,
|
||||||
|
@ -23,11 +26,13 @@ def test_current_sync_committee_merkle_proof(spec, state):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@with_test_suite_name("BeaconState")
|
||||||
@with_altair_and_later
|
@with_altair_and_later
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_next_sync_committee_merkle_proof(spec, state):
|
def test_next_sync_committee_merkle_proof(spec, state):
|
||||||
yield "state", state
|
yield "object", state
|
||||||
next_sync_committee_branch = spec.compute_merkle_proof_for_state(state, spec.NEXT_SYNC_COMMITTEE_INDEX)
|
next_sync_committee_branch = \
|
||||||
|
spec.compute_merkle_proof_for_state(state, spec.NEXT_SYNC_COMMITTEE_INDEX)
|
||||||
yield "proof", {
|
yield "proof", {
|
||||||
"leaf": "0x" + state.next_sync_committee.hash_tree_root().hex(),
|
"leaf": "0x" + state.next_sync_committee.hash_tree_root().hex(),
|
||||||
"leaf_index": spec.NEXT_SYNC_COMMITTEE_INDEX,
|
"leaf_index": spec.NEXT_SYNC_COMMITTEE_INDEX,
|
||||||
|
@ -42,11 +47,13 @@ def test_next_sync_committee_merkle_proof(spec, state):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@with_test_suite_name("BeaconState")
|
||||||
@with_altair_and_later
|
@with_altair_and_later
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_finality_root_merkle_proof(spec, state):
|
def test_finality_root_merkle_proof(spec, state):
|
||||||
yield "state", state
|
yield "object", state
|
||||||
finality_branch = spec.compute_merkle_proof_for_state(state, spec.FINALIZED_ROOT_INDEX)
|
finality_branch = \
|
||||||
|
spec.compute_merkle_proof_for_state(state, spec.FINALIZED_ROOT_INDEX)
|
||||||
yield "proof", {
|
yield "proof", {
|
||||||
"leaf": "0x" + state.finalized_checkpoint.root.hex(),
|
"leaf": "0x" + state.finalized_checkpoint.root.hex(),
|
||||||
"leaf_index": spec.FINALIZED_ROOT_INDEX,
|
"leaf_index": spec.FINALIZED_ROOT_INDEX,
|
||||||
|
|
|
@ -615,6 +615,13 @@ def only_generator(reason):
|
||||||
return _decorator
|
return _decorator
|
||||||
|
|
||||||
|
|
||||||
|
def with_test_suite_name(suite_name: str):
|
||||||
|
def _decorator(inner):
|
||||||
|
inner.suite_name = suite_name
|
||||||
|
return inner
|
||||||
|
return _decorator
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Fork transition state tests
|
# Fork transition state tests
|
||||||
#
|
#
|
||||||
|
|
|
@ -5,24 +5,26 @@ generation and verification of merkle proofs based on static data.
|
||||||
|
|
||||||
## Test case format
|
## Test case format
|
||||||
|
|
||||||
### `state.ssz_snappy`
|
Tests for each individual SSZ type are grouped into a `suite` indicating the SSZ type name.
|
||||||
|
|
||||||
An SSZ-snappy encoded `BeaconState` object from which other data is generated.
|
### `object.yaml`
|
||||||
|
|
||||||
|
A SSZ-snappy encoded object from which other data is generated. The SSZ type can be determined from the test `suite` name.
|
||||||
|
|
||||||
### `proof.yaml`
|
### `proof.yaml`
|
||||||
|
|
||||||
A proof of the leaf value (a merkle root) at generalized-index `leaf_index` in the given `state`.
|
A proof of the leaf value (a merkle root) at generalized-index `leaf_index` in the given `object`.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
leaf: Bytes32 # string, hex encoded, with 0x prefix
|
leaf: Bytes32 # string, hex encoded, with 0x prefix
|
||||||
leaf_index: int # integer, decimal
|
leaf_index: int # integer, decimal
|
||||||
branch: list of Bytes32 # list, each element is a string, hex encoded, with 0x prefix
|
branch: list of Bytes32 # list, each element is a string, hex encoded, with 0x prefix
|
||||||
```
|
```
|
||||||
|
|
||||||
## Condition
|
## Condition
|
||||||
|
|
||||||
A test-runner can implement the following assertions:
|
A test-runner can implement the following assertions:
|
||||||
- Check that `is_valid_merkle_branch` confirms `leaf` at `leaf_index` to verify
|
- Check that `is_valid_merkle_branch` confirms `leaf` at `leaf_index` to verify
|
||||||
against `has_tree_root(state)` and `proof`.
|
against `hash_tree_root(object)` and `branch`.
|
||||||
- If the implementation supports generating merkle proofs, check that the
|
- If the implementation supports generating merkle proofs, check that the
|
||||||
self-generated proof matches the `proof` provided with the test.
|
self-generated proof matches the `branch` provided with the test.
|
||||||
|
|
Loading…
Reference in New Issue