Merge pull request #2977 from ethereum/dev

v1.2.0-rc.3
This commit is contained in:
Danny Ryan
2022-08-18 12:58:09 -06:00
committed by GitHub
13 changed files with 340 additions and 94 deletions

View File

@@ -19,7 +19,7 @@ Features are researched and developed in parallel, and then consolidated into se
| - | - | - | - |
| 0 | **Phase0** |`0` | <ul><li>Core</li><ul><li>[The beacon chain](specs/phase0/beacon-chain.md)</li><li>[Deposit contract](specs/phase0/deposit-contract.md)</li><li>[Beacon chain fork choice](specs/phase0/fork-choice.md)</li></ul><li>Additions</li><ul><li>[Honest validator guide](specs/phase0/validator.md)</li><li>[P2P networking](specs/phase0/p2p-interface.md)</li><li>[Weak subjectivity](specs/phase0/weak-subjectivity.md)</li></ul></ul> |
| 1 | **Altair** | `74240` | <ul><li>Core</li><ul><li>[Beacon chain changes](specs/altair/beacon-chain.md)</li><li>[Altair fork](specs/altair/fork.md)</li></ul><li>Additions</li><ul><li>[Light client sync protocol](specs/altair/light-client/sync-protocol.md) ([full node](specs/altair/light-client/full-node.md), [light client](specs/altair/light-client/light-client.md), [networking](specs/altair/light-client/p2p-interface.md))</li><li>[Honest validator guide changes](specs/altair/validator.md)</li><li>[P2P networking](specs/altair/p2p-interface.md)</li></ul></ul> |
| 2 | **Bellatrix** <br/> (["The Merge"](https://ethereum.org/en/upgrades/merge/)) | TBD | <ul><li>Core</li><ul><li>[Beacon Chain changes](specs/bellatrix/beacon-chain.md)</li><li>[Bellatrix fork](specs/bellatrix/fork.md)</li><li>[Fork choice changes](specs/bellatrix/fork-choice.md)</li></ul><li>Additions</li><ul><li>[Honest validator guide changes](specs/bellatrix/validator.md)</li><li>[P2P networking](specs/bellatrix/p2p-interface.md)</li></ul></ul> |
| 2 | **Bellatrix** <br/> (["The Merge"](https://ethereum.org/en/upgrades/merge/)) | `144896` | <ul><li>Core</li><ul><li>[Beacon Chain changes](specs/bellatrix/beacon-chain.md)</li><li>[Bellatrix fork](specs/bellatrix/fork.md)</li><li>[Fork choice changes](specs/bellatrix/fork-choice.md)</li></ul><li>Additions</li><ul><li>[Honest validator guide changes](specs/bellatrix/validator.md)</li><li>[P2P networking](specs/bellatrix/p2p-interface.md)</li></ul></ul> |
### In-development Specifications
| Code Name or Topic | Specs | Notes |

View File

@@ -4,11 +4,11 @@
# ---------------------------------------------------------------
# [customized] Just 4 committees for slot for testing purposes
MAX_COMMITTEES_PER_SLOT: 4
# [customized] unsecure, but fast
# [customized] insecure, but fast
TARGET_COMMITTEE_SIZE: 4
# 2**11 (= 2,048)
MAX_VALIDATORS_PER_COMMITTEE: 2048
# [customized] Faster, but unsecure.
# [customized] Faster, but insecure.
SHUFFLE_ROUND_COUNT: 10
# 4
HYSTERESIS_QUOTIENT: 4

View File

@@ -104,7 +104,7 @@ The following validations MUST pass before forwarding the `signed_blobs_sidecar`
Alias `sidecar = signed_blobs_sidecar.message`.
- _[IGNORE]_ the `sidecar.beacon_block_slot` is for the current slot (with a `MAXIMUM_GOSSIP_CLOCK_DISPARITY` allowance) -- i.e. `sidecar.beacon_block_slot == current_slot`.
- _[REJECT]_ the `sidecar.blobs` are all well formatted, i.e. the `BLSFieldElement` in valid range (`x < BLS_MODULUS`).
- _[REJECT]_ The KZG proof is a correctly encoded compressed BLS G1 Point -- i.e. `bls.KeyValidate(blobs_sidecar.kzg_aggregated_proof)
- _[REJECT]_ The KZG proof is a correctly encoded compressed BLS G1 Point -- i.e. `bls.KeyValidate(blobs_sidecar.kzg_aggregated_proof)`
- _[REJECT]_ the beacon proposer signature, `signed_blobs_sidecar.signature`, is valid -- i.e.
- Let `domain = get_domain(state, DOMAIN_BLOBS_SIDECAR, sidecar.beacon_block_slot // SLOTS_PER_EPOCH)`
- Let `signing_root = compute_signing_root(sidecar, domain)`

View File

@@ -1327,7 +1327,7 @@ Requests are segregated by protocol ID to:
1. This has the benefit that clients can explicitly choose which RFCs to deploy
without buying into all other RFCs that may be included in that top-level version.
2. Affording this level of granularity with a top-level protocol would imply creating as many variants
(e.g. /protocol/43-{a,b,c,d,...}) as the cartesian product of RFCs inflight, O(n^2).
(e.g. /protocol/43-{a,b,c,d,...}) as the cartesian product of RFCs in-flight, O(n^2).
7. Allow us to simplify the payload of requests.
Request-ids and method-ids no longer need to be sent.
The encoding/request type and version can all be handled by the framework.

View File

@@ -1 +1 @@
1.2.0-rc.2
1.2.0-rc.3

View File

@@ -0,0 +1,85 @@
from eth2spec.test.context import (
spec_state_test,
always_bls,
with_bellatrix_and_later,
)
from eth2spec.test.helpers.deposits import (
deposit_from_context,
run_deposit_processing,
)
from eth2spec.test.helpers.keys import (
privkeys,
pubkeys,
)
from eth2spec.utils import bls
def _run_deposit_processing_with_specific_fork_version(
spec,
state,
fork_version,
valid,
effective):
validator_index = len(state.validators)
amount = spec.MAX_EFFECTIVE_BALANCE
pubkey = pubkeys[validator_index]
privkey = privkeys[validator_index]
withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(pubkey)[1:]
deposit_message = spec.DepositMessage(pubkey=pubkey, withdrawal_credentials=withdrawal_credentials, amount=amount)
domain = spec.compute_domain(domain_type=spec.DOMAIN_DEPOSIT, fork_version=fork_version)
deposit_data = spec.DepositData(
pubkey=pubkey, withdrawal_credentials=withdrawal_credentials, amount=amount,
signature=bls.Sign(privkey, spec.compute_signing_root(deposit_message, domain))
)
deposit, root, _ = deposit_from_context(spec, [deposit_data], 0)
state.eth1_deposit_index = 0
state.eth1_data.deposit_root = root
state.eth1_data.deposit_count = 1
yield from run_deposit_processing(spec, state, deposit, validator_index, valid=valid, effective=effective)
@with_bellatrix_and_later
@spec_state_test
@always_bls
def test_deposit_with_previous_fork_version__valid_ineffective(spec, state):
assert state.fork.previous_version != state.fork.current_version
yield from _run_deposit_processing_with_specific_fork_version(
spec,
state,
fork_version=state.fork.previous_version,
valid=True,
effective=False,
)
@with_bellatrix_and_later
@spec_state_test
@always_bls
def test_deposit_with_genesis_fork_version__valid_effective(spec, state):
assert spec.config.GENESIS_FORK_VERSION not in (state.fork.previous_version, state.fork.current_version)
yield from _run_deposit_processing_with_specific_fork_version(
spec,
state,
fork_version=spec.config.GENESIS_FORK_VERSION,
valid=True,
effective=True,
)
@with_bellatrix_and_later
@spec_state_test
@always_bls
def test_deposit_with_bad_fork_version__valid_ineffective(spec, state):
yield from _run_deposit_processing_with_specific_fork_version(
spec,
state,
fork_version=spec.Version('0xAaBbCcDd'),
valid=True,
effective=False,
)

View File

@@ -0,0 +1,133 @@
from eth2spec.test.context import (
spec_state_test,
always_bls,
with_bellatrix_and_later,
)
from eth2spec.test.helpers.keys import pubkey_to_privkey
from eth2spec.test.helpers.state import (
next_epoch,
)
from eth2spec.test.helpers.voluntary_exits import (
run_voluntary_exit_processing,
sign_voluntary_exit,
)
def _run_voluntary_exit_processing_test(
spec,
state,
fork_version,
is_before_fork_epoch,
valid):
# create a fork
next_epoch(spec, state)
state.fork.epoch = spec.get_current_epoch(state)
voluntary_exit_epoch = 0 if is_before_fork_epoch else state.fork.epoch
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH
current_epoch = spec.get_current_epoch(state)
validator_index = spec.get_active_validator_indices(state, current_epoch)[0]
privkey = pubkey_to_privkey[state.validators[validator_index].pubkey]
voluntary_exit = spec.VoluntaryExit(
epoch=voluntary_exit_epoch,
validator_index=validator_index,
)
signed_voluntary_exit = sign_voluntary_exit(
spec,
state,
voluntary_exit,
privkey,
fork_version=fork_version,
)
yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit, valid=valid)
@with_bellatrix_and_later
@spec_state_test
@always_bls
def test_voluntary_exit_with_current_fork_version_is_before_fork_epoch__invalid(spec, state):
yield from _run_voluntary_exit_processing_test(
spec,
state,
fork_version=state.fork.current_version,
is_before_fork_epoch=True,
valid=False,
)
@with_bellatrix_and_later
@spec_state_test
@always_bls
def test_voluntary_exit_with_current_fork_version_not_is_before_fork_epoch__valid(spec, state):
yield from _run_voluntary_exit_processing_test(
spec,
state,
fork_version=state.fork.current_version,
is_before_fork_epoch=False,
valid=True,
)
@with_bellatrix_and_later
@spec_state_test
@always_bls
def test_voluntary_exit_with_previous_fork_version_is_before_fork_epoch__valid(spec, state):
assert state.fork.previous_version != state.fork.current_version
yield from _run_voluntary_exit_processing_test(
spec,
state,
fork_version=state.fork.previous_version,
is_before_fork_epoch=True,
valid=True,
)
@with_bellatrix_and_later
@spec_state_test
@always_bls
def test_voluntary_exit_with_previous_fork_version_not_is_before_fork_epoch__invalid(spec, state):
assert state.fork.previous_version != state.fork.current_version
yield from _run_voluntary_exit_processing_test(
spec,
state,
fork_version=state.fork.previous_version,
is_before_fork_epoch=False,
valid=False,
)
@with_bellatrix_and_later
@spec_state_test
@always_bls
def test_voluntary_exit_with_genesis_fork_version_is_before_fork_epoch__invalid(spec, state):
assert spec.config.GENESIS_FORK_VERSION not in (state.fork.previous_version, state.fork.current_version)
yield from _run_voluntary_exit_processing_test(
spec,
state,
fork_version=spec.config.GENESIS_FORK_VERSION,
is_before_fork_epoch=True,
valid=False,
)
@with_bellatrix_and_later
@spec_state_test
@always_bls
def test_voluntary_exit_with_genesis_fork_version_not_is_before_fork_epoch__invalid(spec, state):
assert spec.config.GENESIS_FORK_VERSION not in (state.fork.previous_version, state.fork.current_version)
yield from _run_voluntary_exit_processing_test(
spec,
state,
fork_version=spec.config.GENESIS_FORK_VERSION,
is_before_fork_epoch=False,
valid=False,
)

View File

@@ -1,7 +1,11 @@
from random import Random
from eth2spec.test.context import is_post_altair
from eth2spec.test.context import (
is_post_altair,
expect_assertion_error,
)
from eth2spec.test.helpers.keys import pubkeys, privkeys
from eth2spec.test.helpers.state import get_balance
from eth2spec.utils import bls
from eth2spec.utils.merkle_minimal import calc_merkle_tree_from_leaves, get_merkle_proof
from eth2spec.utils.ssz.ssz_impl import hash_tree_root
@@ -160,3 +164,57 @@ def prepare_state_and_deposit(spec, state, validator_index, amount, withdrawal_c
state.eth1_data.deposit_root = root
state.eth1_data.deposit_count = len(deposit_data_list)
return deposit
#
# Run processing
#
def run_deposit_processing(spec, state, deposit, validator_index, valid=True, effective=True):
"""
Run ``process_deposit``, yielding:
- pre-state ('pre')
- deposit ('deposit')
- post-state ('post').
If ``valid == False``, run expecting ``AssertionError``
"""
pre_validator_count = len(state.validators)
pre_balance = 0
if validator_index < pre_validator_count:
pre_balance = get_balance(state, validator_index)
yield 'pre', state
yield 'deposit', deposit
if not valid:
expect_assertion_error(lambda: spec.process_deposit(state, deposit))
yield 'post', None
return
spec.process_deposit(state, deposit)
yield 'post', state
if not effective:
assert len(state.validators) == pre_validator_count
assert len(state.balances) == pre_validator_count
if validator_index < pre_validator_count:
assert get_balance(state, validator_index) == pre_balance
else:
if validator_index < pre_validator_count:
# top-up
assert len(state.validators) == pre_validator_count
assert len(state.balances) == pre_validator_count
else:
# new validator
assert len(state.validators) == pre_validator_count + 1
assert len(state.balances) == pre_validator_count + 1
assert get_balance(state, validator_index) == pre_balance + deposit.data.amount
effective = min(spec.MAX_EFFECTIVE_BALANCE,
pre_balance + deposit.data.amount)
effective -= effective % spec.EFFECTIVE_BALANCE_INCREMENT
assert state.validators[validator_index].effective_balance == effective
assert state.eth1_deposit_index == state.eth1_data.deposit_count

View File

@@ -1,10 +1,14 @@
from random import Random
from eth2spec.utils import bls
from eth2spec.test.context import expect_assertion_error
from eth2spec.test.helpers.keys import privkeys
def prepare_signed_exits(spec, state, indices):
domain = spec.get_domain(state, spec.DOMAIN_VOLUNTARY_EXIT)
def prepare_signed_exits(spec, state, indices, fork_version=None):
if fork_version is None:
domain = spec.get_domain(state, spec.DOMAIN_VOLUNTARY_EXIT)
else:
domain = spec.compute_domain(spec.DOMAIN_VOLUNTARY_EXIT, fork_version, state.genesis_validators_root)
def create_signed_exit(index):
exit = spec.VoluntaryExit(
@@ -17,8 +21,12 @@ def prepare_signed_exits(spec, state, indices):
return [create_signed_exit(index) for index in indices]
def sign_voluntary_exit(spec, state, voluntary_exit, privkey):
domain = spec.get_domain(state, spec.DOMAIN_VOLUNTARY_EXIT, voluntary_exit.epoch)
def sign_voluntary_exit(spec, state, voluntary_exit, privkey, fork_version=None):
if fork_version is None:
domain = spec.get_domain(state, spec.DOMAIN_VOLUNTARY_EXIT, voluntary_exit.epoch)
else:
domain = spec.compute_domain(spec.DOMAIN_VOLUNTARY_EXIT, fork_version, state.genesis_validators_root)
signing_root = spec.compute_signing_root(voluntary_exit, domain)
return spec.SignedVoluntaryExit(
message=voluntary_exit,
@@ -49,3 +57,36 @@ def exit_validators(spec, state, validator_count, rng=None):
for index in indices:
spec.initiate_validator_exit(state, index)
return indices
#
# Run processing
#
def run_voluntary_exit_processing(spec, state, signed_voluntary_exit, valid=True):
"""
Run ``process_voluntary_exit``, yielding:
- pre-state ('pre')
- voluntary_exit ('voluntary_exit')
- post-state ('post').
If ``valid == False``, run expecting ``AssertionError``
"""
validator_index = signed_voluntary_exit.message.validator_index
yield 'pre', state
yield 'voluntary_exit', signed_voluntary_exit
if not valid:
expect_assertion_error(lambda: spec.process_voluntary_exit(state, signed_voluntary_exit))
yield 'post', None
return
pre_exit_epoch = state.validators[validator_index].exit_epoch
spec.process_voluntary_exit(state, signed_voluntary_exit)
yield 'post', state
assert pre_exit_epoch == spec.FAR_FUTURE_EPOCH
assert state.validators[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH

View File

@@ -1,63 +1,15 @@
from eth2spec.test.context import spec_state_test, expect_assertion_error, always_bls, with_all_phases
from eth2spec.test.context import spec_state_test, always_bls, with_all_phases
from eth2spec.test.helpers.deposits import (
build_deposit,
deposit_from_context,
prepare_state_and_deposit,
run_deposit_processing,
sign_deposit_data,
deposit_from_context)
from eth2spec.test.helpers.state import get_balance
)
from eth2spec.test.helpers.keys import privkeys, pubkeys
from eth2spec.utils import bls
def run_deposit_processing(spec, state, deposit, validator_index, valid=True, effective=True):
"""
Run ``process_deposit``, yielding:
- pre-state ('pre')
- deposit ('deposit')
- post-state ('post').
If ``valid == False``, run expecting ``AssertionError``
"""
pre_validator_count = len(state.validators)
pre_balance = 0
if validator_index < pre_validator_count:
pre_balance = get_balance(state, validator_index)
yield 'pre', state
yield 'deposit', deposit
if not valid:
expect_assertion_error(lambda: spec.process_deposit(state, deposit))
yield 'post', None
return
spec.process_deposit(state, deposit)
yield 'post', state
if not effective:
assert len(state.validators) == pre_validator_count
assert len(state.balances) == pre_validator_count
if validator_index < pre_validator_count:
assert get_balance(state, validator_index) == pre_balance
else:
if validator_index < pre_validator_count:
# top-up
assert len(state.validators) == pre_validator_count
assert len(state.balances) == pre_validator_count
else:
# new validator
assert len(state.validators) == pre_validator_count + 1
assert len(state.balances) == pre_validator_count + 1
assert get_balance(state, validator_index) == pre_balance + deposit.data.amount
effective = min(spec.MAX_EFFECTIVE_BALANCE,
pre_balance + deposit.data.amount)
effective -= effective % spec.EFFECTIVE_BALANCE_INCREMENT
assert state.validators[validator_index].effective_balance == effective
assert state.eth1_deposit_index == state.eth1_data.deposit_count
@with_all_phases
@spec_state_test
def test_new_deposit_under_max(spec, state):

View File

@@ -1,40 +1,15 @@
from eth2spec.test.helpers.constants import MINIMAL
from eth2spec.test.context import (
spec_state_test, expect_assertion_error,
spec_state_test,
always_bls, with_all_phases, with_presets,
spec_test, single_phase,
with_custom_state, scaled_churn_balances,
)
from eth2spec.test.helpers.keys import pubkey_to_privkey
from eth2spec.test.helpers.voluntary_exits import sign_voluntary_exit
def run_voluntary_exit_processing(spec, state, signed_voluntary_exit, valid=True):
"""
Run ``process_voluntary_exit``, yielding:
- pre-state ('pre')
- voluntary_exit ('voluntary_exit')
- post-state ('post').
If ``valid == False``, run expecting ``AssertionError``
"""
validator_index = signed_voluntary_exit.message.validator_index
yield 'pre', state
yield 'voluntary_exit', signed_voluntary_exit
if not valid:
expect_assertion_error(lambda: spec.process_voluntary_exit(state, signed_voluntary_exit))
yield 'post', None
return
pre_exit_epoch = state.validators[validator_index].exit_epoch
spec.process_voluntary_exit(state, signed_voluntary_exit)
yield 'post', state
assert pre_exit_epoch == spec.FAR_FUTURE_EPOCH
assert state.validators[validator_index].exit_epoch < spec.FAR_FUTURE_EPOCH
from eth2spec.test.helpers.voluntary_exits import (
run_voluntary_exit_processing,
sign_voluntary_exit,
)
@with_all_phases

View File

@@ -18,7 +18,9 @@ if __name__ == "__main__":
altair_mods = combine_mods(_new_altair_mods, phase_0_mods)
_new_bellatrix_mods = {key: 'eth2spec.test.bellatrix.block_processing.test_process_' + key for key in [
'deposit',
'execution_payload',
'voluntary_exit',
]}
bellatrix_mods = combine_mods(_new_bellatrix_mods, altair_mods)

View File

@@ -3,7 +3,7 @@ This test format currently uses code generation to assemble the tests
as the current test infra does not have a facility to dynamically
generate tests that can be seen by ``pytest``.
This will likley change in future releases of the testing infra.
This will likely change in future releases of the testing infra.
NOTE: To add additional scenarios, add test cases below in ``_generate_randomized_scenarios``.
"""