From abdcbc4972682644eb3f607d07c37be386fd1a66 Mon Sep 17 00:00:00 2001 From: protolambda Date: Sun, 30 Jun 2019 14:32:38 +0200 Subject: [PATCH 01/23] update epoch processing tests generation and format --- specs/test_formats/epoch_processing/README.md | 14 +++++++++----- test_generators/epoch_processing/main.py | 13 ++++++++++++- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/specs/test_formats/epoch_processing/README.md b/specs/test_formats/epoch_processing/README.md index 6384a0eda..6998184f6 100644 --- a/specs/test_formats/epoch_processing/README.md +++ b/specs/test_formats/epoch_processing/README.md @@ -17,13 +17,17 @@ post: BeaconState -- state after applying the epoch sub-transition. ## Condition A handler of the `epoch_processing` test-runner should process these cases, - calling the corresponding processing implementation. + calling the corresponding processing implementation (same name, prefixed with `process_`). +This excludes the other parts of the epoch-transition. +The provided pre-state is already transitioned to just before the specific sub-transition of focus of the handler. Sub-transitions: -| *`sub-transition-name`* | *`processing call`* | -|-------------------------|-----------------------------------| -| `crosslinks` | `process_crosslinks(state)` | -| `registry_updates` | `process_registry_updates(state)` | +- `justification_and_finalization` +- `crosslinks` +- *`justification_and_finalization` - planned testing extension* +- `registry_updates` +- `slashings` +- `final_updates` The resulting state should match the expected `post` state. diff --git a/test_generators/epoch_processing/main.py b/test_generators/epoch_processing/main.py index 846f463a1..6a578c598 100644 --- a/test_generators/epoch_processing/main.py +++ b/test_generators/epoch_processing/main.py @@ -4,7 +4,10 @@ from eth2spec.phase0 import spec as spec_phase0 from eth2spec.phase1 import spec as spec_phase1 from eth2spec.test.phase_0.epoch_processing import ( test_process_crosslinks, - test_process_registry_updates + test_process_final_updates, + test_process_justification_and_finalization, + test_process_registry_updates, + test_process_slashings ) from gen_base import gen_runner, gen_suite, gen_typing from gen_from_tests.gen import generate_from_tests @@ -35,8 +38,16 @@ if __name__ == "__main__": gen_runner.run_generator("epoch_processing", [ create_suite('crosslinks', 'minimal', lambda: generate_from_tests(test_process_crosslinks, 'phase0')), create_suite('crosslinks', 'mainnet', lambda: generate_from_tests(test_process_crosslinks, 'phase0')), + create_suite('final_updates', 'minimal', lambda: generate_from_tests(test_process_final_updates, 'phase0')), + create_suite('final_updates', 'mainnet', lambda: generate_from_tests(test_process_final_updates, 'phase0')), + create_suite('justification_and_finalization', 'minimal', + lambda: generate_from_tests(test_process_justification_and_finalization, 'phase0')), + create_suite('justification_and_finalization', 'mainnet', + lambda: generate_from_tests(test_process_justification_and_finalization, 'phase0')), create_suite('registry_updates', 'minimal', lambda: generate_from_tests(test_process_registry_updates, 'phase0')), create_suite('registry_updates', 'mainnet', lambda: generate_from_tests(test_process_registry_updates, 'phase0')), + create_suite('slashings', 'minimal', lambda: generate_from_tests(test_process_slashings, 'phase0')), + create_suite('slashings', 'mainnet', lambda: generate_from_tests(test_process_slashings, 'phase0')), ]) From 992a51b5876f27d3bae23067ebd5b7c38bdb559d Mon Sep 17 00:00:00 2001 From: protolambda Date: Sun, 30 Jun 2019 14:35:07 +0200 Subject: [PATCH 02/23] add note to block operatiosn test format --- specs/test_formats/operations/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/specs/test_formats/operations/README.md b/specs/test_formats/operations/README.md index cc7e43f3f..37c5df498 100644 --- a/specs/test_formats/operations/README.md +++ b/specs/test_formats/operations/README.md @@ -16,13 +16,14 @@ post: BeaconState -- state after applying the operation. No A handler of the `operations` test-runner should process these cases, calling the corresponding processing implementation. +This excludes the other parts of the block-transition. Operations: | *`operation-name`* | *`operation-object`* | *`input name`* | *`processing call`* | |-------------------------|----------------------|----------------------|--------------------------------------------------------| -| `attestation` | `Attestation` | `attestation` | `process_attestation(state, attestation)` | -| `attester_slashing` | `AttesterSlashing` | `attester_slashing` | `process_attester_slashing(state, attester_slashing)` | +| `attestation` | `Attestation` | `attestation` | `process_attestation(state, attestation)` | +| `attester_slashing` | `AttesterSlashing` | `attester_slashing` | `process_attester_slashing(state, attester_slashing)` | | `block_header` | `Block` | `block` | `process_block_header(state, block)` | | `deposit` | `Deposit` | `deposit` | `process_deposit(state, deposit)` | | `proposer_slashing` | `ProposerSlashing` | `proposer_slashing` | `process_proposer_slashing(state, proposer_slashing)` | From da090b67f69a570d3db9a435301e22f07734b508 Mon Sep 17 00:00:00 2001 From: protolambda Date: Sun, 30 Jun 2019 14:58:53 +0200 Subject: [PATCH 03/23] document genesis test vector format, fix missing label and assertion in tests --- specs/test_formats/genesis/README.md | 8 +++++++ specs/test_formats/genesis/initialization.md | 22 +++++++++++++++++++ specs/test_formats/genesis/validity.md | 19 ++++++++++++++++ .../genesis/test_is_valid_genesis_state.py | 6 ++--- 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 specs/test_formats/genesis/README.md create mode 100644 specs/test_formats/genesis/initialization.md create mode 100644 specs/test_formats/genesis/validity.md diff --git a/specs/test_formats/genesis/README.md b/specs/test_formats/genesis/README.md new file mode 100644 index 000000000..25761e2f6 --- /dev/null +++ b/specs/test_formats/genesis/README.md @@ -0,0 +1,8 @@ +# Genesis tests + +The aim of the genesis tests is to provide a baseline to test genesis-state initialization and test + if the proposed genesis-validity conditions are working. + +There are two handlers, documented individually: +- [`validity`](./validity.md): Tests if a genesis state is valid, i.e. if it counts as trigger to launch. +- [`initialization`](./initialization.md): Tests the initialization of a genesis state based on Eth1 data. diff --git a/specs/test_formats/genesis/initialization.md b/specs/test_formats/genesis/initialization.md new file mode 100644 index 000000000..437dd91a3 --- /dev/null +++ b/specs/test_formats/genesis/initialization.md @@ -0,0 +1,22 @@ +# Genesis creation testing + +Tests the initialization of a genesis state based on Eth1 data. + +## Test case format + +```yaml +description: string -- description of test case, purely for debugging purposes +bls_setting: int -- see general test-format spec. +eth1_block_hash: Bytes32 -- the root of the Eth-1 block, hex encoded, with prefix 0x +eth1_timestamp: int -- the timestamp of the block, in seconds. +deposits: [Deposit] -- list of deposits to build the genesis state with +state: BeaconState -- the expected genesis state. +``` + +To process this test, build a genesis state with the provided `eth1_block_hash`, `eth1_timestamp` and `deposits`: +`initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits)`, + as described in the Beacon Chain specification. + +## Condition + +The resulting state should match the expected `state`. diff --git a/specs/test_formats/genesis/validity.md b/specs/test_formats/genesis/validity.md new file mode 100644 index 000000000..792923e3a --- /dev/null +++ b/specs/test_formats/genesis/validity.md @@ -0,0 +1,19 @@ +# Genesis validity testing + +Tests if a genesis state is valid, i.e. if it counts as trigger to launch. + +## Test case format + +```yaml +description: string -- description of test case, purely for debugging purposes +bls_setting: int -- see general test-format spec. +genesis: BeaconState -- state to validate. +is_valid: bool -- true if the genesis state is deemed valid as to launch with, false otherwise. +``` + +To process the data, call `is_valid_genesis_state(genesis)`. + + +## Condition + +The result of calling `is_valid_genesis_state(genesis)` should match the expected `is_valid` boolean. diff --git a/test_libs/pyspec/eth2spec/test/genesis/test_is_valid_genesis_state.py b/test_libs/pyspec/eth2spec/test/genesis/test_is_valid_genesis_state.py index 4ad509200..2dc9eb7fd 100644 --- a/test_libs/pyspec/eth2spec/test/genesis/test_is_valid_genesis_state.py +++ b/test_libs/pyspec/eth2spec/test/genesis/test_is_valid_genesis_state.py @@ -16,13 +16,13 @@ def create_valid_beacon_state(spec): def run_is_valid_genesis_state(spec, state, valid=True): """ Run ``is_valid_genesis_state``, yielding: - - state ('state') + - genesis ('state') - is_valid ('is_valid') - If ``valid == False``, run expecting ``AssertionError`` """ - yield state + yield 'genesis', state is_valid = spec.is_valid_genesis_state(state) yield 'is_valid', is_valid + assert is_valid == valid @with_phases(['phase0']) From 64b02ebecc912ad8b54cea30c02cbd60e0e507e8 Mon Sep 17 00:00:00 2001 From: protolambda Date: Sun, 30 Jun 2019 15:01:30 +0200 Subject: [PATCH 04/23] fix genesis tests --- .../test/genesis/test_is_valid_genesis_state.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test_libs/pyspec/eth2spec/test/genesis/test_is_valid_genesis_state.py b/test_libs/pyspec/eth2spec/test/genesis/test_is_valid_genesis_state.py index 2dc9eb7fd..bb95bb2b0 100644 --- a/test_libs/pyspec/eth2spec/test/genesis/test_is_valid_genesis_state.py +++ b/test_libs/pyspec/eth2spec/test/genesis/test_is_valid_genesis_state.py @@ -39,7 +39,7 @@ def test_is_valid_genesis_state_false_invalid_timestamp(spec): state = create_valid_beacon_state(spec) state.genesis_time = spec.MIN_GENESIS_TIME - 1 - yield from run_is_valid_genesis_state(spec, state, valid=True) + yield from run_is_valid_genesis_state(spec, state, valid=False) @with_phases(['phase0']) @@ -51,13 +51,14 @@ def test_is_valid_genesis_state_true_more_balance(spec): yield from run_is_valid_genesis_state(spec, state, valid=True) -@with_phases(['phase0']) -@spectest_with_bls_switch -def test_is_valid_genesis_state_false_not_enough_balance(spec): - state = create_valid_beacon_state(spec) - state.validators[0].effective_balance = spec.MAX_EFFECTIVE_BALANCE - 1 - - yield from run_is_valid_genesis_state(spec, state, valid=False) +# TODO: not part of the genesis function yet. Erroneously merged. +# @with_phases(['phase0']) +# @spectest_with_bls_switch +# def test_is_valid_genesis_state_false_not_enough_balance(spec): +# state = create_valid_beacon_state(spec) +# state.validators[0].effective_balance = spec.MAX_EFFECTIVE_BALANCE - 1 +# +# yield from run_is_valid_genesis_state(spec, state, valid=False) @with_phases(['phase0']) From 83d91f81db8530da9faffb23b0910c4ebfd20957 Mon Sep 17 00:00:00 2001 From: protolambda Date: Sun, 30 Jun 2019 15:03:50 +0200 Subject: [PATCH 05/23] update sanity slots description to match new transition naming --- specs/test_formats/sanity/slots.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/specs/test_formats/sanity/slots.md b/specs/test_formats/sanity/slots.md index eb0f336b4..04fecd186 100644 --- a/specs/test_formats/sanity/slots.md +++ b/specs/test_formats/sanity/slots.md @@ -12,11 +12,10 @@ slots: N -- amount of slots to process, N being a positive number. post: BeaconState -- state after applying all the transitions. ``` -The transition with pure time, no blocks, is known as `state_transition_to(state, slot)` in the spec. +The transition with pure time, no blocks, is known as `process_slots(state, slot)` in the spec. This runs state-caching (pure slot transition) and epoch processing (every E slots). -To process the data, call `state_transition_to(pre, pre.slot + N)`. And see if `pre` mutated into the equivalent of `post`. - +To process the data, call `process_slots(pre, pre.slot + N)`. ## Condition From c1317640c4111cfcb4e8ae6e294e2d7920fb2278 Mon Sep 17 00:00:00 2001 From: protolambda Date: Sun, 30 Jun 2019 15:26:54 +0200 Subject: [PATCH 06/23] genesis tests generator --- test_generators/genesis/README.md | 8 +++++ test_generators/genesis/main.py | 33 +++++++++++++++++++ test_generators/genesis/requirements.txt | 4 +++ ...te_from_eth1.py => test_initialization.py} | 0 ...alid_genesis_state.py => test_validity.py} | 0 5 files changed, 45 insertions(+) create mode 100644 test_generators/genesis/README.md create mode 100644 test_generators/genesis/main.py create mode 100644 test_generators/genesis/requirements.txt rename test_libs/pyspec/eth2spec/test/genesis/{test_initialize_beacon_state_from_eth1.py => test_initialization.py} (100%) rename test_libs/pyspec/eth2spec/test/genesis/{test_is_valid_genesis_state.py => test_validity.py} (100%) diff --git a/test_generators/genesis/README.md b/test_generators/genesis/README.md new file mode 100644 index 000000000..8a2b01c62 --- /dev/null +++ b/test_generators/genesis/README.md @@ -0,0 +1,8 @@ +# Genesis test generator + +Genesis tests cover the initialization and validity-based launch trigger for the Beacon Chain genesis state. + +Information on the format of the tests can be found in the [genesis test formats documentation](../../specs/test_formats/genesis/README.md). + + + diff --git a/test_generators/genesis/main.py b/test_generators/genesis/main.py new file mode 100644 index 000000000..82899b967 --- /dev/null +++ b/test_generators/genesis/main.py @@ -0,0 +1,33 @@ +from typing import Callable, Iterable + +from eth2spec.test.genesis import test_initialization, test_validity + +from gen_base import gen_runner, gen_suite, gen_typing +from gen_from_tests.gen import generate_from_tests +from preset_loader import loader +from eth2spec.phase0 import spec as spec + + +def create_suite(handler_name: str, config_name: str, get_cases: Callable[[], Iterable[gen_typing.TestCase]]) \ + -> Callable[[str], gen_typing.TestSuiteOutput]: + def suite_definition(configs_path: str) -> gen_typing.TestSuiteOutput: + presets = loader.load_presets(configs_path, config_name) + spec.apply_constants_preset(presets) + + return ("genesis_%s_%s" % (handler_name, config_name), handler_name, gen_suite.render_suite( + title="genesis testing", + summary="Genesis test suite, %s type, generated from pytests" % handler_name, + forks_timeline="testing", + forks=["phase0"], + config=config_name, + runner="genesis", + handler=handler_name, + test_cases=get_cases())) + return suite_definition + + +if __name__ == "__main__": + gen_runner.run_generator("genesis", [ + create_suite('initialization', 'minimal', lambda: generate_from_tests(test_initialization, 'phase0')), + create_suite('validity', 'minimal', lambda: generate_from_tests(test_validity, 'phase0')), + ]) diff --git a/test_generators/genesis/requirements.txt b/test_generators/genesis/requirements.txt new file mode 100644 index 000000000..595cee69c --- /dev/null +++ b/test_generators/genesis/requirements.txt @@ -0,0 +1,4 @@ +eth-utils==1.6.0 +../../test_libs/gen_helpers +../../test_libs/config_helpers +../../test_libs/pyspec \ No newline at end of file diff --git a/test_libs/pyspec/eth2spec/test/genesis/test_initialize_beacon_state_from_eth1.py b/test_libs/pyspec/eth2spec/test/genesis/test_initialization.py similarity index 100% rename from test_libs/pyspec/eth2spec/test/genesis/test_initialize_beacon_state_from_eth1.py rename to test_libs/pyspec/eth2spec/test/genesis/test_initialization.py diff --git a/test_libs/pyspec/eth2spec/test/genesis/test_is_valid_genesis_state.py b/test_libs/pyspec/eth2spec/test/genesis/test_validity.py similarity index 100% rename from test_libs/pyspec/eth2spec/test/genesis/test_is_valid_genesis_state.py rename to test_libs/pyspec/eth2spec/test/genesis/test_validity.py From b38802ced06aab88e919f66adecafa13e3c58112 Mon Sep 17 00:00:00 2001 From: protolambda Date: Sun, 30 Jun 2019 15:27:31 +0200 Subject: [PATCH 07/23] accept yielded lists, encode per item --- test_libs/pyspec/eth2spec/test/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test_libs/pyspec/eth2spec/test/utils.py b/test_libs/pyspec/eth2spec/test/utils.py index 817c952b7..bc91053e8 100644 --- a/test_libs/pyspec/eth2spec/test/utils.py +++ b/test_libs/pyspec/eth2spec/test/utils.py @@ -1,6 +1,6 @@ from typing import Dict, Any, Callable, Iterable from eth2spec.debug.encode import encode -from eth2spec.utils.ssz.ssz_typing import Container +from eth2spec.utils.ssz.ssz_typing import SSZValue def spectest(description: str = None): @@ -31,8 +31,10 @@ def spectest(description: str = None): else: # Otherwise, try to infer the type, but keep it as-is if it's not a SSZ container. (key, value) = data - if isinstance(value, Container): + if isinstance(value, SSZValue): out[key] = encode(value, value.__class__) + elif isinstance(value, list) and all([isinstance(el, SSZValue) for el in value]): + out[key] = [encode(el, el.__class__) for el in value] else: # not a ssz value. # It could be vector or bytes still, but it is a rare case, From bf618f8d282dd76e226fdd261dc0745ca7f8ad90 Mon Sep 17 00:00:00 2001 From: protolambda Date: Sun, 30 Jun 2019 15:36:54 +0200 Subject: [PATCH 08/23] fix encoder to also encode bytes nicely --- test_libs/pyspec/eth2spec/debug/encode.py | 4 ++-- test_libs/pyspec/eth2spec/test/utils.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test_libs/pyspec/eth2spec/debug/encode.py b/test_libs/pyspec/eth2spec/debug/encode.py index 670f580b2..9080bb573 100644 --- a/test_libs/pyspec/eth2spec/debug/encode.py +++ b/test_libs/pyspec/eth2spec/debug/encode.py @@ -1,10 +1,10 @@ from eth2spec.utils.ssz.ssz_impl import hash_tree_root from eth2spec.utils.ssz.ssz_typing import ( - SSZValue, uint, Container, boolean + uint, Container, boolean ) -def encode(value: SSZValue, include_hash_tree_roots=False): +def encode(value, include_hash_tree_roots=False): if isinstance(value, uint): # Larger uints are boxed and the class declares their byte length if value.type().byte_len > 8: diff --git a/test_libs/pyspec/eth2spec/test/utils.py b/test_libs/pyspec/eth2spec/test/utils.py index bc91053e8..253691764 100644 --- a/test_libs/pyspec/eth2spec/test/utils.py +++ b/test_libs/pyspec/eth2spec/test/utils.py @@ -29,12 +29,12 @@ def spectest(description: str = None): (key, value, typ) = data out[key] = encode(value, typ) else: - # Otherwise, try to infer the type, but keep it as-is if it's not a SSZ container. + # Otherwise, try to infer the type, but keep it as-is if it's not a SSZ type or bytes. (key, value) = data - if isinstance(value, SSZValue): - out[key] = encode(value, value.__class__) - elif isinstance(value, list) and all([isinstance(el, SSZValue) for el in value]): - out[key] = [encode(el, el.__class__) for el in value] + if isinstance(value, (SSZValue, bytes)): + out[key] = encode(value) + elif isinstance(value, list) and all([isinstance(el, (SSZValue, bytes)) for el in value]): + out[key] = [encode(el) for el in value] else: # not a ssz value. # It could be vector or bytes still, but it is a rare case, From 91f55f55b532eaa422459702153876b961844dfb Mon Sep 17 00:00:00 2001 From: protolambda Date: Sun, 30 Jun 2019 16:07:54 +0200 Subject: [PATCH 09/23] make BLS test format and output consistent with spec --- specs/test_formats/bls/msg_hash_g2_compressed.md | 2 +- specs/test_formats/bls/msg_hash_g2_uncompressed.md | 4 ++-- specs/test_formats/bls/sign_msg.md | 2 +- test_generators/bls/main.py | 9 +++------ 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/specs/test_formats/bls/msg_hash_g2_compressed.md b/specs/test_formats/bls/msg_hash_g2_compressed.md index 2feeb92ba..44ea8ded7 100644 --- a/specs/test_formats/bls/msg_hash_g2_compressed.md +++ b/specs/test_formats/bls/msg_hash_g2_compressed.md @@ -7,7 +7,7 @@ A BLS compressed-hash to G2. ```yaml input: message: bytes32, - domain: bytes -- any number + domain: uint64 -- the BLS domain output: List[bytes48] -- length of two ``` diff --git a/specs/test_formats/bls/msg_hash_g2_uncompressed.md b/specs/test_formats/bls/msg_hash_g2_uncompressed.md index 792fe1f03..847b5f61d 100644 --- a/specs/test_formats/bls/msg_hash_g2_uncompressed.md +++ b/specs/test_formats/bls/msg_hash_g2_uncompressed.md @@ -6,8 +6,8 @@ A BLS uncompressed-hash to G2. ```yaml input: - message: bytes32, - domain: bytes -- any number + message: bytes32 + domain: uint64 -- the BLS domain output: List[List[bytes48]] -- 3 lists, each a length of two ``` diff --git a/specs/test_formats/bls/sign_msg.md b/specs/test_formats/bls/sign_msg.md index 9916f2cc2..b17e6246d 100644 --- a/specs/test_formats/bls/sign_msg.md +++ b/specs/test_formats/bls/sign_msg.md @@ -8,7 +8,7 @@ Message signing with BLS should produce a signature. input: privkey: bytes32 -- the private key used for signing message: bytes32 -- input message to sign (a hash) - domain: bytes -- BLS domain + domain: uint64 -- the BLS domain output: bytes96 -- expected signature ``` diff --git a/test_generators/bls/main.py b/test_generators/bls/main.py index 8a6a7dafe..a792dda9a 100644 --- a/test_generators/bls/main.py +++ b/test_generators/bls/main.py @@ -27,9 +27,6 @@ def hex_to_int(x: str) -> int: return int(x, 16) -# Note: even though a domain is only an uint64, -# To avoid issues with YAML parsers that are limited to 53-bit (JS language limit) -# It is serialized as an hex string as well. DOMAINS = [ 0, 1, @@ -92,7 +89,7 @@ def case01_message_hash_G2_uncompressed(): yield { 'input': { 'message': '0x' + msg.hex(), - 'domain': int_to_hex(domain) + 'domain': domain }, 'output': hash_message(msg, domain) } @@ -104,7 +101,7 @@ def case02_message_hash_G2_compressed(): yield { 'input': { 'message': '0x' + msg.hex(), - 'domain': int_to_hex(domain) + 'domain': domain }, 'output': hash_message_compressed(msg, domain) } @@ -129,7 +126,7 @@ def case04_sign_messages(): 'input': { 'privkey': int_to_hex(privkey), 'message': '0x' + message.hex(), - 'domain': int_to_hex(domain) + 'domain': domain }, 'output': '0x' + sig.hex() } From 7b91c289d4166fdb5ccea93173cdace7d6ddde93 Mon Sep 17 00:00:00 2001 From: protolambda Date: Sun, 30 Jun 2019 16:46:40 +0200 Subject: [PATCH 10/23] fix shuffling generator, convert ValidatorIndex output to normal int --- test_generators/shuffling/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_generators/shuffling/main.py b/test_generators/shuffling/main.py index 291aa2c47..7e7b3f94b 100644 --- a/test_generators/shuffling/main.py +++ b/test_generators/shuffling/main.py @@ -10,7 +10,7 @@ from preset_loader import loader def shuffling_case(seed, count): yield 'seed', '0x' + seed.hex() yield 'count', count - yield 'shuffled', [spec.get_shuffled_index(i, count, seed) for i in range(count)] + yield 'shuffled', [int(spec.get_shuffled_index(i, count, seed)) for i in range(count)] @to_tuple From 4b93f5d9211c81e40c6f03dcc357156de4da43bf Mon Sep 17 00:00:00 2001 From: protolambda Date: Sun, 30 Jun 2019 18:15:36 +0200 Subject: [PATCH 11/23] disable some super-long tests, and fix a few attestation signatures --- .../block_processing/test_process_attestation.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py b/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py index e7c753f40..af55c3ec6 100644 --- a/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py +++ b/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py @@ -68,6 +68,9 @@ def test_success_previous_epoch(spec, state): @with_all_phases @spec_state_test def test_success_since_max_epochs_per_crosslink(spec, state): + # Do not run mainnet (64 epochs), that would mean the equivalent of ~7 hours chain simulation. + if spec.MAX_EPOCHS_PER_CROSSLINK > 4: + return for _ in range(spec.MAX_EPOCHS_PER_CROSSLINK + 2): next_epoch(spec, state) apply_empty_block(spec, state) @@ -87,6 +90,9 @@ def test_success_since_max_epochs_per_crosslink(spec, state): @with_all_phases @spec_state_test def test_wrong_end_epoch_with_max_epochs_per_crosslink(spec, state): + # Do not run mainnet (64 epochs), that would mean the equivalent of ~7 hours chain simulation. + if spec.MAX_EPOCHS_PER_CROSSLINK > 4: + return for _ in range(spec.MAX_EPOCHS_PER_CROSSLINK + 2): next_epoch(spec, state) apply_empty_block(spec, state) @@ -293,12 +299,13 @@ def test_bad_parent_crosslink(spec, state): next_epoch(spec, state) apply_empty_block(spec, state) - attestation = get_valid_attestation(spec, state, signed=True) + attestation = get_valid_attestation(spec, state, signed=False) for _ in range(spec.MIN_ATTESTATION_INCLUSION_DELAY): next_slot(spec, state) apply_empty_block(spec, state) attestation.data.crosslink.parent_root = b'\x27' * 32 + sign_attestation(spec, state, attestation) yield from run_attestation_processing(spec, state, attestation, False) @@ -309,12 +316,13 @@ def test_bad_crosslink_start_epoch(spec, state): next_epoch(spec, state) apply_empty_block(spec, state) - attestation = get_valid_attestation(spec, state, signed=True) + attestation = get_valid_attestation(spec, state, signed=False) for _ in range(spec.MIN_ATTESTATION_INCLUSION_DELAY): next_slot(spec, state) apply_empty_block(spec, state) attestation.data.crosslink.start_epoch += 1 + sign_attestation(spec, state, attestation) yield from run_attestation_processing(spec, state, attestation, False) @@ -325,12 +333,13 @@ def test_bad_crosslink_end_epoch(spec, state): next_epoch(spec, state) apply_empty_block(spec, state) - attestation = get_valid_attestation(spec, state, signed=True) + attestation = get_valid_attestation(spec, state, signed=False) for _ in range(spec.MIN_ATTESTATION_INCLUSION_DELAY): next_slot(spec, state) apply_empty_block(spec, state) attestation.data.crosslink.end_epoch += 1 + sign_attestation(spec, state, attestation) yield from run_attestation_processing(spec, state, attestation, False) From cb01f3ccd9ff1b3b9c8e5bd8a0d5b823d2dafcc2 Mon Sep 17 00:00:00 2001 From: protolambda Date: Sun, 30 Jun 2019 18:40:43 +0200 Subject: [PATCH 12/23] speed up remaining attestation tests by mocking slots --- .../phase_0/block_processing/test_process_attestation.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py b/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py index af55c3ec6..cb49a2baf 100644 --- a/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py +++ b/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py @@ -59,6 +59,7 @@ def test_success(spec, state): @spec_state_test def test_success_previous_epoch(spec, state): attestation = get_valid_attestation(spec, state, signed=True) + state.slot = spec.SLOTS_PER_EPOCH - 1 next_epoch(spec, state) apply_empty_block(spec, state) @@ -136,8 +137,9 @@ def test_before_inclusion_delay(spec, state): @spec_state_test def test_after_epoch_slots(spec, state): attestation = get_valid_attestation(spec, state, signed=True) + state.slot = spec.SLOTS_PER_EPOCH - 1 # increment past latest inclusion slot - spec.process_slots(state, state.slot + spec.SLOTS_PER_EPOCH + 1) + spec.process_slots(state, state.slot + 2) apply_empty_block(spec, state) yield from run_attestation_processing(spec, state, attestation, False) @@ -296,6 +298,7 @@ def test_non_zero_crosslink_data_root(spec, state): @with_all_phases @spec_state_test def test_bad_parent_crosslink(spec, state): + state.slot = spec.SLOTS_PER_EPOCH - 1 next_epoch(spec, state) apply_empty_block(spec, state) @@ -313,6 +316,7 @@ def test_bad_parent_crosslink(spec, state): @with_all_phases @spec_state_test def test_bad_crosslink_start_epoch(spec, state): + state.slot = spec.SLOTS_PER_EPOCH - 1 next_epoch(spec, state) apply_empty_block(spec, state) @@ -330,6 +334,7 @@ def test_bad_crosslink_start_epoch(spec, state): @with_all_phases @spec_state_test def test_bad_crosslink_end_epoch(spec, state): + state.slot = spec.SLOTS_PER_EPOCH - 1 next_epoch(spec, state) apply_empty_block(spec, state) From 8415e6c79d81538f2715479ba1f29dc322214b63 Mon Sep 17 00:00:00 2001 From: protolambda Date: Sun, 30 Jun 2019 18:42:54 +0200 Subject: [PATCH 13/23] mark incompatible mainnet tests --- .../phase_0/block_processing/test_process_attestation.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py b/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py index cb49a2baf..761fed633 100644 --- a/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py +++ b/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py @@ -207,6 +207,12 @@ def test_old_target_epoch(spec, state): @with_all_phases @spec_state_test def test_future_target_epoch(spec, state): + # TODO: fails in mainnet, + # something with committee indices resulting in out of range validator indices (we only have 512 test validators). + # Disabled in mainnet for now. + if spec.SHARD_COUNT > 8: + return + assert spec.MIN_ATTESTATION_INCLUSION_DELAY < spec.SLOTS_PER_EPOCH * 2 attestation = get_valid_attestation(spec, state) From ed182e5e9d3036a59f6683a046bfe66fc1ade6a2 Mon Sep 17 00:00:00 2001 From: protolambda Date: Sun, 30 Jun 2019 19:44:35 +0200 Subject: [PATCH 14/23] disable mainnet transfer test output --- test_generators/operations/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test_generators/operations/main.py b/test_generators/operations/main.py index 38fa42f68..b61e98526 100644 --- a/test_generators/operations/main.py +++ b/test_generators/operations/main.py @@ -49,7 +49,9 @@ if __name__ == "__main__": create_suite('proposer_slashing', 'minimal', lambda: generate_from_tests(test_process_proposer_slashing, 'phase0')), create_suite('proposer_slashing', 'mainnet', lambda: generate_from_tests(test_process_proposer_slashing, 'phase0')), create_suite('transfer', 'minimal', lambda: generate_from_tests(test_process_transfer, 'phase0')), - create_suite('transfer', 'mainnet', lambda: generate_from_tests(test_process_transfer, 'phase0')), + # Disabled, due to the high amount of different transfer tests, this produces a shocking size of tests. + # Unnecessarily, as transfer are disabled currently, so not a priority. + # create_suite('transfer', 'mainnet', lambda: generate_from_tests(test_process_transfer, 'phase0')), create_suite('voluntary_exit', 'minimal', lambda: generate_from_tests(test_process_voluntary_exit, 'phase0')), create_suite('voluntary_exit', 'mainnet', lambda: generate_from_tests(test_process_voluntary_exit, 'phase0')), ]) From 4aa676bae7ed01a6deaf34d5ad1f6d8484a3bbb0 Mon Sep 17 00:00:00 2001 From: Danny Ryan Date: Sun, 30 Jun 2019 13:52:35 -0500 Subject: [PATCH 15/23] fix mainnet attestation test --- .../test_process_attestation.py | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py b/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py index 761fed633..ab46a0d8c 100644 --- a/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py +++ b/test_libs/pyspec/eth2spec/test/phase_0/block_processing/test_process_attestation.py @@ -1,6 +1,7 @@ from eth2spec.test.context import spec_state_test, expect_assertion_error, always_bls, with_all_phases, with_phases from eth2spec.test.helpers.attestations import ( get_valid_attestation, + sign_aggregate_attestation, sign_attestation, ) from eth2spec.test.helpers.state import ( @@ -207,20 +208,21 @@ def test_old_target_epoch(spec, state): @with_all_phases @spec_state_test def test_future_target_epoch(spec, state): - # TODO: fails in mainnet, - # something with committee indices resulting in out of range validator indices (we only have 512 test validators). - # Disabled in mainnet for now. - if spec.SHARD_COUNT > 8: - return - assert spec.MIN_ATTESTATION_INCLUSION_DELAY < spec.SLOTS_PER_EPOCH * 2 attestation = get_valid_attestation(spec, state) - state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY - + participants = spec.get_attesting_indices( + state, + attestation.data, + attestation.aggregation_bits + ) attestation.data.target.epoch = spec.get_current_epoch(state) + 1 # target epoch will be too new to handle - sign_attestation(spec, state, attestation) + + # manually add signature for correct participants + attestation.signature = sign_aggregate_attestation(spec, state, attestation.data, participants) + + state.slot += spec.MIN_ATTESTATION_INCLUSION_DELAY yield from run_attestation_processing(spec, state, attestation, False) From 1ba955b5f0fa1832f582741bcbd946e0a42068d3 Mon Sep 17 00:00:00 2001 From: Diederik Loerakker Date: Sun, 30 Jun 2019 21:19:19 +0200 Subject: [PATCH 16/23] Update specs/test_formats/epoch_processing/README.md Co-Authored-By: Danny Ryan --- specs/test_formats/epoch_processing/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/test_formats/epoch_processing/README.md b/specs/test_formats/epoch_processing/README.md index 6998184f6..dbd4ca639 100644 --- a/specs/test_formats/epoch_processing/README.md +++ b/specs/test_formats/epoch_processing/README.md @@ -25,7 +25,7 @@ Sub-transitions: - `justification_and_finalization` - `crosslinks` -- *`justification_and_finalization` - planned testing extension* +- *`rewards_and_penalties` - planned testing extension* - `registry_updates` - `slashings` - `final_updates` From e0a0f6e1569950a020fa9def1d733f5b8abe9338 Mon Sep 17 00:00:00 2001 From: Carl Beekhuizen Date: Sun, 30 Jun 2019 21:25:58 +0200 Subject: [PATCH 17/23] Makes markdown comply with linter --- scripts/build_spec.py | 3 +- specs/core/0_beacon-chain.md | 14 +++--- specs/core/0_deposit-contract.md | 4 +- specs/core/0_fork-choice.md | 8 +-- specs/core/1_custody-game.md | 25 +++++----- specs/core/1_shard-data-chains.md | 24 ++++----- specs/validator/0_beacon-chain-validator.md | 50 ++++++++++--------- .../validator/0_beacon-node-validator-api.md | 6 +-- 8 files changed, 68 insertions(+), 66 deletions(-) diff --git a/scripts/build_spec.py b/scripts/build_spec.py index fe66a72d5..1542973f2 100644 --- a/scripts/build_spec.py +++ b/scripts/build_spec.py @@ -6,7 +6,6 @@ from function_puller import ( from argparse import ArgumentParser from typing import ( Dict, - List, Optional, ) @@ -106,7 +105,7 @@ def apply_constants_preset(preset: Dict[str, Any]) -> None: def strip_comments(raw: str) -> str: - comment_line_regex = re.compile('^\s+# ') + comment_line_regex = re.compile(r'^\s+# ') lines = raw.split('\n') out = [] for line in lines: diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 68915177c..7dd6a71bf 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -181,7 +181,7 @@ The following values are (non-configurable) constants used throughout the specif | `JUSTIFICATION_BITS_LENGTH` | `4` | | `ENDIANNESS` | `'little'` | -* For the safety of crosslinks, `TARGET_COMMITTEE_SIZE` exceeds [the recommended minimum committee size of 111](https://vitalik.ca/files/Ithaca201807_Sharding.pdf); with sufficient active validators (at least `SLOTS_PER_EPOCH * TARGET_COMMITTEE_SIZE`), the shuffling algorithm ensures committee sizes of at least `TARGET_COMMITTEE_SIZE`. (Unbiasable randomness with a Verifiable Delay Function (VDF) will improve committee robustness and lower the safe minimum committee size.) +- For the safety of crosslinks, `TARGET_COMMITTEE_SIZE` exceeds [the recommended minimum committee size of 111](https://vitalik.ca/files/Ithaca201807_Sharding.pdf); with sufficient active validators (at least `SLOTS_PER_EPOCH * TARGET_COMMITTEE_SIZE`), the shuffling algorithm ensures committee sizes of at least `TARGET_COMMITTEE_SIZE`. (Unbiasable randomness with a Verifiable Delay Function (VDF) will improve committee robustness and lower the safe minimum committee size.) ### Gwei values @@ -215,7 +215,7 @@ The following values are (non-configurable) constants used throughout the specif | `MAX_EPOCHS_PER_CROSSLINK` | `2**6` (= 64) | epochs | ~7 hours | | `MIN_EPOCHS_TO_INACTIVITY_PENALTY` | `2**2` (= 4) | epochs | 25.6 minutes | -* `MAX_EPOCHS_PER_CROSSLINK` should be a small constant times `SHARD_COUNT // SLOTS_PER_EPOCH`. +- `MAX_EPOCHS_PER_CROSSLINK` should be a small constant times `SHARD_COUNT // SLOTS_PER_EPOCH`. ### State list lengths @@ -236,7 +236,7 @@ The following values are (non-configurable) constants used throughout the specif | `INACTIVITY_PENALTY_QUOTIENT` | `2**25` (= 33,554,432) | | `MIN_SLASHING_PENALTY_QUOTIENT` | `2**5` (= 32) | -* The `INACTIVITY_PENALTY_QUOTIENT` equals `INVERSE_SQRT_E_DROP_TIME**2` where `INVERSE_SQRT_E_DROP_TIME := 2**12 epochs` (about 18 days) is the time it takes the inactivity penalty to reduce the balance of non-participating validators to about `1/sqrt(e) ~= 60.6%`. Indeed, the balance retained by offline validators after `n` epochs is about `(1 - 1/INACTIVITY_PENALTY_QUOTIENT)**(n**2/2)`; so after `INVERSE_SQRT_E_DROP_TIME` epochs, it is roughly `(1 - 1/INACTIVITY_PENALTY_QUOTIENT)**(INACTIVITY_PENALTY_QUOTIENT/2) ~= 1/sqrt(e)`. +- The `INACTIVITY_PENALTY_QUOTIENT` equals `INVERSE_SQRT_E_DROP_TIME**2` where `INVERSE_SQRT_E_DROP_TIME := 2**12 epochs` (about 18 days) is the time it takes the inactivity penalty to reduce the balance of non-participating validators to about `1/sqrt(e) ~= 60.6%`. Indeed, the balance retained by offline validators after `n` epochs is about `(1 - 1/INACTIVITY_PENALTY_QUOTIENT)**(n**2/2)`; so after `INVERSE_SQRT_E_DROP_TIME` epochs, it is roughly `(1 - 1/INACTIVITY_PENALTY_QUOTIENT)**(INACTIVITY_PENALTY_QUOTIENT/2) ~= 1/sqrt(e)`. ### Max operations per block @@ -1116,9 +1116,9 @@ def slash_validator(state: BeaconState, Before the Ethereum 2.0 genesis has been triggered, and for every Ethereum 1.0 block, let `candidate_state = initialize_beacon_state_from_eth1(eth1_block_hash, eth1_timestamp, deposits)` where: -* `eth1_block_hash` is the hash of the Ethereum 1.0 block -* `eth1_timestamp` is the Unix timestamp corresponding to `eth1_block_hash` -* `deposits` is the sequence of all deposits, ordered chronologically, up to the block with hash `eth1_block_hash` +- `eth1_block_hash` is the hash of the Ethereum 1.0 block +- `eth1_timestamp` is the Unix timestamp corresponding to `eth1_block_hash` +- `deposits` is the sequence of all deposits, ordered chronologically, up to the block with hash `eth1_block_hash` ```python def initialize_beacon_state_from_eth1(eth1_block_hash: Hash, @@ -1171,7 +1171,7 @@ Let `genesis_block = BeaconBlock(state_root=hash_tree_root(genesis_state))`. ## Beacon chain state transition function -The post-state corresponding to a pre-state `state` and a block `block` is defined as `state_transition(state, block)`. State transitions that trigger an unhandled excpetion (e.g. a failed `assert` or an out-of-range list access) are considered invalid. +The post-state corresponding to a pre-state `state` and a block `block` is defined as `state_transition(state, block)`. State transitions that trigger an unhandled exception (e.g. a failed `assert` or an out-of-range list access) are considered invalid. ```python def state_transition(state: BeaconState, block: BeaconBlock, validate_state_root: bool=False) -> BeaconState: diff --git a/specs/core/0_deposit-contract.md b/specs/core/0_deposit-contract.md index 0efc15f25..b95748ae6 100644 --- a/specs/core/0_deposit-contract.md +++ b/specs/core/0_deposit-contract.md @@ -48,8 +48,8 @@ The amount of ETH (rounded down to the closest Gwei) sent to the deposit contrac One of the `DepositData` fields is `withdrawal_credentials`. It is a commitment to credentials for withdrawing validator balance (e.g. to another validator, or to shards). The first byte of `withdrawal_credentials` is a version number. As of now, the only expected format is as follows: -* `withdrawal_credentials[:1] == BLS_WITHDRAWAL_PREFIX_BYTE` -* `withdrawal_credentials[1:] == hash(withdrawal_pubkey)[1:]` where `withdrawal_pubkey` is a BLS pubkey +- `withdrawal_credentials[:1] == BLS_WITHDRAWAL_PREFIX_BYTE` +- `withdrawal_credentials[1:] == hash(withdrawal_pubkey)[1:]` where `withdrawal_pubkey` is a BLS pubkey The private key corresponding to `withdrawal_pubkey` will be required to initiate a withdrawal. It can be stored separately until a withdrawal is required, e.g. in cold storage. diff --git a/specs/core/0_fork-choice.md b/specs/core/0_fork-choice.md index a45d79fbe..89eecff02 100644 --- a/specs/core/0_fork-choice.md +++ b/specs/core/0_fork-choice.md @@ -41,9 +41,9 @@ This document is the beacon chain fork choice spec, part of Ethereum 2.0 Phase 0 The head block root associated with a `store` is defined as `get_head(store)`. At genesis, let `store = get_genesis_store(genesis_state)` and update `store` by running: -* `on_tick(time)` whenever `time > store.time` where `time` is the current Unix time -* `on_block(block)` whenever a block `block` is received -* `on_attestation(attestation)` whenever an attestation `attestation` is received +- `on_tick(time)` whenever `time > store.time` where `time` is the current Unix time +- `on_block(block)` whenever a block `block` is received +- `on_attestation(attestation)` whenever an attestation `attestation` is received *Notes*: @@ -188,7 +188,7 @@ def on_attestation(store: Store, attestation: Attestation) -> None: # Cannot calculate the current shuffling if have not seen the target assert target.root in store.blocks - # Attestations cannot be from future epochs. If they are, delay consideration until the epoch arrivesr + # Attestations cannot be from future epochs. If they are, delay consideration until the epoch arrives base_state = store.block_states[target.root].copy() assert store.time >= base_state.genesis_time + epoch_start_slot(target.epoch) * SECONDS_PER_SLOT diff --git a/specs/core/1_custody-game.md b/specs/core/1_custody-game.md index 54a1ca34b..babe4f991 100644 --- a/specs/core/1_custody-game.md +++ b/specs/core/1_custody-game.md @@ -56,18 +56,18 @@ This document details the beacon chain additions and changes in Phase 1 of Ether ## Terminology -* **Custody game**— -* **Custody period**— -* **Custody chunk**— -* **Custody chunk bit**— -* **Custody chunk challenge**— -* **Custody bit**— -* **Custody bit challenge**— -* **Custody key**— -* **Custody key reveal**— -* **Custody key mask**— -* **Custody response**— -* **Custody response deadline**— +- **Custody game**— +- **Custody period**— +- **Custody chunk**— +- **Custody chunk bit**— +- **Custody chunk challenge**— +- **Custody bit**— +- **Custody bit challenge**— +- **Custody key**— +- **Custody key reveal**— +- **Custody key mask**— +- **Custody response**— +- **Custody response deadline**— ## Constants @@ -113,7 +113,6 @@ This document details the beacon chain additions and changes in Phase 1 of Ether | - | - | | `DOMAIN_CUSTODY_BIT_CHALLENGE` | `6` | - ### TODO PLACEHOLDER | Name | Value | diff --git a/specs/core/1_shard-data-chains.md b/specs/core/1_shard-data-chains.md index fd0e41b4f..745d437c2 100644 --- a/specs/core/1_shard-data-chains.md +++ b/specs/core/1_shard-data-chains.md @@ -282,10 +282,10 @@ def compute_crosslink_data_root(blocks: Sequence[ShardBlock]) -> Bytes32: Let: -* `beacon_blocks` be the `BeaconBlock` list such that `beacon_blocks[slot]` is the canonical `BeaconBlock` at slot `slot` -* `beacon_state` be the canonical `BeaconState` after processing `beacon_blocks[-1]` -* `valid_shard_blocks` be the list of valid `ShardBlock`, recursively defined -* `candidate` be a candidate `ShardBlock` for which validity is to be determined by running `is_valid_shard_block` +- `beacon_blocks` be the `BeaconBlock` list such that `beacon_blocks[slot]` is the canonical `BeaconBlock` at slot `slot` +- `beacon_state` be the canonical `BeaconState` after processing `beacon_blocks[-1]` +- `valid_shard_blocks` be the list of valid `ShardBlock`, recursively defined +- `candidate` be a candidate `ShardBlock` for which validity is to be determined by running `is_valid_shard_block` ```python def is_valid_shard_block(beacon_blocks: Sequence[BeaconBlock], @@ -349,9 +349,9 @@ def is_valid_shard_block(beacon_blocks: Sequence[BeaconBlock], Let: -* `valid_shard_blocks` be the list of valid `ShardBlock` -* `beacon_state` be the canonical `BeaconState` -* `candidate` be a candidate `ShardAttestation` for which validity is to be determined by running `is_valid_shard_attestation` +- `valid_shard_blocks` be the list of valid `ShardBlock` +- `beacon_state` be the canonical `BeaconState` +- `candidate` be a candidate `ShardAttestation` for which validity is to be determined by running `is_valid_shard_attestation` ```python def is_valid_shard_attestation(valid_shard_blocks: Sequence[ShardBlock], @@ -376,11 +376,11 @@ def is_valid_shard_attestation(valid_shard_blocks: Sequence[ShardBlock], Let: -* `shard` be a valid `Shard` -* `shard_blocks` be the `ShardBlock` list such that `shard_blocks[slot]` is the canonical `ShardBlock` for shard `shard` at slot `slot` -* `beacon_state` be the canonical `BeaconState` -* `valid_attestations` be the set of valid `Attestation` objects, recursively defined -* `candidate` be a candidate `Attestation` which is valid under Phase 0 rules, and for which validity is to be determined under Phase 1 rules by running `is_valid_beacon_attestation` +- `shard` be a valid `Shard` +- `shard_blocks` be the `ShardBlock` list such that `shard_blocks[slot]` is the canonical `ShardBlock` for shard `shard` at slot `slot` +- `beacon_state` be the canonical `BeaconState` +- `valid_attestations` be the set of valid `Attestation` objects, recursively defined +- `candidate` be a candidate `Attestation` which is valid under Phase 0 rules, and for which validity is to be determined under Phase 1 rules by running `is_valid_beacon_attestation` ```python def is_valid_beacon_attestation(shard: Shard, diff --git a/specs/validator/0_beacon-chain-validator.md b/specs/validator/0_beacon-chain-validator.md index 0b6857a72..e354345fa 100644 --- a/specs/validator/0_beacon-chain-validator.md +++ b/specs/validator/0_beacon-chain-validator.md @@ -86,8 +86,9 @@ Validator public keys are [G1 points](../bls_signature.md#g1-points) on the [BLS A secondary withdrawal private key, `withdrawal_privkey`, must also be securely generated along with the resultant `withdrawal_pubkey`. This `withdrawal_privkey` does not have to be available for signing during the normal lifetime of a validator and can live in "cold storage". The validator constructs their `withdrawal_credentials` via the following: -* Set `withdrawal_credentials[:1] == BLS_WITHDRAWAL_PREFIX_BYTE`. -* Set `withdrawal_credentials[1:] == hash(withdrawal_pubkey)[1:]`. + +- Set `withdrawal_credentials[:1] == BLS_WITHDRAWAL_PREFIX_BYTE`. +- Set `withdrawal_credentials[1:] == hash(withdrawal_pubkey)[1:]`. ### Submit deposit @@ -95,11 +96,11 @@ In Phase 0, all incoming validator deposits originate from the Ethereum 1.0 proo To submit a deposit: -* Pack the validator's [initialization parameters](#initialization) into `deposit_data`, a [`DepositData`](../core/0_beacon-chain.md#depositdata) SSZ object. -* Let `amount` be the amount in Gwei to be deposited by the validator where `MIN_DEPOSIT_AMOUNT <= amount <= MAX_EFFECTIVE_BALANCE`. -* Set `deposit_data.amount = amount`. -* Let `signature` be the result of `bls_sign` of the `signing_root(deposit_data)` with `domain=bls_domain(DOMAIN_DEPOSIT)`. (Deposits are valid regardless of fork version, `bls_domain` will default to zeroes there). -* Send a transaction on the Ethereum 1.0 chain to `DEPOSIT_CONTRACT_ADDRESS` executing `def deposit(pubkey: bytes[48], withdrawal_credentials: bytes[32], signature: bytes[96])` along with a deposit of `amount` Gwei. +- Pack the validator's [initialization parameters](#initialization) into `deposit_data`, a [`DepositData`](../core/0_beacon-chain.md#depositdata) SSZ object. +- Let `amount` be the amount in Gwei to be deposited by the validator where `MIN_DEPOSIT_AMOUNT <= amount <= MAX_EFFECTIVE_BALANCE`. +- Set `deposit_data.amount = amount`. +- Let `signature` be the result of `bls_sign` of the `signing_root(deposit_data)` with `domain=bls_domain(DOMAIN_DEPOSIT)`. (Deposits are valid regardless of fork version, `bls_domain` will default to zeroes there). +- Send a transaction on the Ethereum 1.0 chain to `DEPOSIT_CONTRACT_ADDRESS` executing `def deposit(pubkey: bytes[48], withdrawal_credentials: bytes[32], signature: bytes[96])` along with a deposit of `amount` Gwei. *Note*: Deposits made for the same `pubkey` are treated as for the same validator. A singular `Validator` will be added to `state.validators` with each additional deposit amount added to the validator's balance. A validator can only be activated when total deposits for the validator pubkey meet or exceed `MAX_EFFECTIVE_BALANCE`. @@ -292,8 +293,8 @@ A validator should create and broadcast the attestation halfway through the `slo First, the validator should construct `attestation_data`, an [`AttestationData`](../core/0_beacon-chain.md#attestationdata) object based upon the state at the assigned slot. -* Let `head_block` be the result of running the fork choice during the assigned slot. -* Let `head_state` be the state of `head_block` processed through any empty slots up to the assigned slot using `process_slots(state, slot)`. +- Let `head_block` be the result of running the fork choice during the assigned slot. +- Let `head_state` be the state of `head_block` processed through any empty slots up to the assigned slot using `process_slots(state, slot)`. ##### LMD GHOST vote @@ -301,25 +302,26 @@ Set `attestation_data.beacon_block_root = signing_root(head_block)`. ##### FFG vote -* Set `attestation_data.source_epoch = head_state.current_justified_epoch`. -* Set `attestation_data.source_root = head_state.current_justified_root`. -* Set `attestation_data.target_epoch = get_current_epoch(head_state)` -* Set `attestation_data.target_root = epoch_boundary_block_root` where `epoch_boundary_block_root` is the root of block at the most recent epoch boundary. +- Set `attestation_data.source_epoch = head_state.current_justified_epoch`. +- Set `attestation_data.source_root = head_state.current_justified_root`. +- Set `attestation_data.target_epoch = get_current_epoch(head_state)` +- Set `attestation_data.target_root = epoch_boundary_block_root` where `epoch_boundary_block_root` is the root of block at the most recent epoch boundary. *Note*: `epoch_boundary_block_root` can be looked up in the state using: -* Let `start_slot = epoch_start_slot(get_current_epoch(head_state))`. -* Let `epoch_boundary_block_root = signing_root(head_block) if start_slot == head_state.slot else get_block_root(state, start_slot)`. + +- Let `start_slot = epoch_start_slot(get_current_epoch(head_state))`. +- Let `epoch_boundary_block_root = signing_root(head_block) if start_slot == head_state.slot else get_block_root(state, start_slot)`. ##### Crosslink vote Construct `attestation_data.crosslink` via the following. -* Set `attestation_data.crosslink.shard = shard` where `shard` is the shard associated with the validator's committee. -* Let `parent_crosslink = head_state.current_crosslinks[shard]`. -* Set `attestation_data.crosslink.start_epoch = parent_crosslink.end_epoch`. -* Set `attestation_data.crosslink.end_epoch = min(attestation_data.target_epoch, parent_crosslink.end_epoch + MAX_EPOCHS_PER_CROSSLINK)`. -* Set `attestation_data.crosslink.parent_root = hash_tree_root(head_state.current_crosslinks[shard])`. -* Set `attestation_data.crosslink.data_root = ZERO_HASH`. *Note*: This is a stub for Phase 0. +- Set `attestation_data.crosslink.shard = shard` where `shard` is the shard associated with the validator's committee. +- Let `parent_crosslink = head_state.current_crosslinks[shard]`. +- Set `attestation_data.crosslink.start_epoch = parent_crosslink.end_epoch`. +- Set `attestation_data.crosslink.end_epoch = min(attestation_data.target_epoch, parent_crosslink.end_epoch + MAX_EPOCHS_PER_CROSSLINK)`. +- Set `attestation_data.crosslink.parent_root = hash_tree_root(head_state.current_crosslinks[shard])`. +- Set `attestation_data.crosslink.data_root = ZERO_HASH`. *Note*: This is a stub for Phase 0. #### Construct attestation @@ -331,13 +333,13 @@ Set `attestation.data = attestation_data` where `attestation_data` is the `Attes ##### Aggregation bits -* Let `attestation.aggregation_bits` be a `Bitlist[MAX_INDICES_PER_ATTESTATION]` where the bits at the index in the aggregated validator's `committee` is set to `0b1`. +- Let `attestation.aggregation_bits` be a `Bitlist[MAX_INDICES_PER_ATTESTATION]` where the bits at the index in the aggregated validator's `committee` is set to `0b1`. *Note*: Calling `get_attesting_indices(state, attestation.data, attestation.aggregation_bits)` should return a list of length equal to 1, containing `validator_index`. ##### Custody bits -* Let `attestation.custody_bits` be a `Bitlist[MAX_INDICES_PER_ATTESTATION]` filled with zeros of length `len(committee)`. +- Let `attestation.custody_bits` be a `Bitlist[MAX_INDICES_PER_ATTESTATION]` filled with zeros of length `len(committee)`. *Note*: This is a stub for Phase 0. @@ -376,6 +378,7 @@ To avoid "proposer slashings", a validator must not sign two conflicting [`Beaco *In Phase 0, as long as the validator does not sign two different beacon blocks for the same epoch, the validator is safe against proposer slashings.* Specifically, when signing a `BeaconBlock`, a validator should perform the following steps in the following order: + 1. Save a record to hard disk that a beacon block has been signed for the `epoch=slot_to_epoch(block.slot)`. 2. Generate and broadcast the block. @@ -386,6 +389,7 @@ If the software crashes at some point within this routine, then when the validat To avoid "attester slashings", a validator must not sign two conflicting [`AttestationData`](../core/0_beacon-chain.md#attestationdata) objects, i.e. two attestations that satisfy [`is_slashable_attestation_data`](../core/0_beacon-chain.md#is_slashable_attestation_data). Specifically, when signing an `Attestation`, a validator should perform the following steps in the following order: + 1. Save a record to hard disk that an attestation has been signed for source (i.e. `attestation_data.source_epoch`) and target (i.e. `slot_to_epoch(attestation_data.slot)`). 2. Generate and broadcast attestation. diff --git a/specs/validator/0_beacon-node-validator-api.md b/specs/validator/0_beacon-node-validator-api.md index 20379eef0..e87d36701 100644 --- a/specs/validator/0_beacon-node-validator-api.md +++ b/specs/validator/0_beacon-node-validator-api.md @@ -8,7 +8,8 @@ This document outlines a minimal application programming interface (API) which i The API is a REST interface, accessed via HTTP, designed for use as a local communications protocol between binaries. Currently, the only supported return data type is JSON. -## Background +## Background + The beacon node maintains the state of the beacon chain by communicating with other beacon nodes in the Ethereum 2.0 network. Conceptually, it does not maintain keypairs that participate with the beacon chain. The validator client is a conceptually separate entity which utilizes private keys to perform validator related tasks, called "duties", on the beacon chain. These duties include the production of beacon blocks and signing of attestations. @@ -19,8 +20,7 @@ The goal of this specification is to promote interoperability between beacon nod This specification is derived from a proposal and discussion on Issues [#1011](https://github.com/ethereum/eth2.0-specs/issues/1011) and [#1012](https://github.com/ethereum/eth2.0-specs/issues/1012). - -## Specification +## Specification The API specification has been written in [OpenAPI 3.0](https://swagger.io/docs/specification/about/) and is provided in the [beacon_node_oapi.yaml](beacon_node_oapi.yaml) file alongside this document. From fb598bc70c53debaf869c6b6bee11cca0f79a8d5 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Mon, 1 Jul 2019 04:11:17 +0800 Subject: [PATCH 18/23] Update ToC --- specs/core/0_beacon-chain.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 7dd6a71bf..e10d0c011 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -49,9 +49,9 @@ - [`BeaconState`](#beaconstate) - [Helper functions](#helper-functions) - [Math](#math) + - [`int_to_bytes`](#int_to_bytes) - [`integer_squareroot`](#integer_squareroot) - [`xor`](#xor) - - [`int_to_bytes`](#int_to_bytes) - [`bytes_to_int`](#bytes_to_int) - [Crypto](#crypto) - [`hash`](#hash) @@ -65,7 +65,7 @@ - [`is_slashable_validator`](#is_slashable_validator) - [`is_slashable_attestation_data`](#is_slashable_attestation_data) - [`is_valid_merkle_branch`](#is_valid_merkle_branch) - - [Misc](#misc) + - [Misc](#misc-1) - [`shuffle_index`](#shuffle_index) - [`compute_committee`](#compute_committee) - [`validate_indexed_attestation`](#validate_indexed_attestation) @@ -90,6 +90,7 @@ - [`get_attestation_data_slot`](#get_attestation_data_slot) - [`get_compact_committees_root`](#get_compact_committees_root) - [`get_total_balance`](#get_total_balance) + - [`get_total_active_balance`](#get_total_active_balance) - [`get_domain`](#get_domain) - [`get_indexed_attestation`](#get_indexed_attestation) - [`get_attesting_indices`](#get_attesting_indices) From d329e90aa5daaf73285808807987476d5f1945cc Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Sun, 30 Jun 2019 21:27:01 +0100 Subject: [PATCH 19/23] Fix effective balance --- specs/core/0_beacon-chain.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 7dd6a71bf..cd4d09903 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1139,7 +1139,9 @@ def initialize_beacon_state_from_eth1(eth1_block_hash: Hash, # Process activations for index, validator in enumerate(state.validators): - if state.balances[index] >= MAX_EFFECTIVE_BALANCE: + balance = state.balances[index] + validator.effective_balance = min(balance - balance % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE) + if validator.effective_balance == MAX_EFFECTIVE_BALANCE: validator.activation_eligibility_epoch = GENESIS_EPOCH validator.activation_epoch = GENESIS_EPOCH @@ -1689,7 +1691,6 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None: activation_epoch=FAR_FUTURE_EPOCH, exit_epoch=FAR_FUTURE_EPOCH, withdrawable_epoch=FAR_FUTURE_EPOCH, - effective_balance=min(amount - amount % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE) )) state.balances.append(amount) else: From 67b0b4ad333484e8f5a3948f8122d5b4c2136497 Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Mon, 1 Jul 2019 04:57:42 +0800 Subject: [PATCH 20/23] Update other spec files --- specs/core/0_fork-choice.md | 2 +- specs/core/1_custody-game.md | 2 ++ specs/core/1_shard-data-chains.md | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/specs/core/0_fork-choice.md b/specs/core/0_fork-choice.md index 89eecff02..d28087a1a 100644 --- a/specs/core/0_fork-choice.md +++ b/specs/core/0_fork-choice.md @@ -12,7 +12,7 @@ - [Time parameters](#time-parameters) - [Fork choice](#fork-choice) - [Helpers](#helpers) - - [`Checkpoint`](#checkpoint) + - [`LatestMessage`](#latestmessage) - [`Store`](#store) - [`get_genesis_store`](#get_genesis_store) - [`get_ancestor`](#get_ancestor) diff --git a/specs/core/1_custody-game.md b/specs/core/1_custody-game.md index babe4f991..5c05ae2fc 100644 --- a/specs/core/1_custody-game.md +++ b/specs/core/1_custody-game.md @@ -16,6 +16,7 @@ - [Max operations per block](#max-operations-per-block) - [Reward and penalty quotients](#reward-and-penalty-quotients) - [Signature domains](#signature-domains) + - [TODO PLACEHOLDER](#todo-placeholder) - [Data structures](#data-structures) - [Custody objects](#custody-objects) - [`CustodyChunkChallenge`](#custodychunkchallenge) @@ -33,6 +34,7 @@ - [Helpers](#helpers) - [`ceillog2`](#ceillog2) - [`get_crosslink_chunk_count`](#get_crosslink_chunk_count) + - [`get_bit`](#get_bit) - [`get_custody_chunk_bit`](#get_custody_chunk_bit) - [`get_chunk_bits_root`](#get_chunk_bits_root) - [`get_randao_epoch_for_custody_period`](#get_randao_epoch_for_custody_period) diff --git a/specs/core/1_shard-data-chains.md b/specs/core/1_shard-data-chains.md index 745d437c2..093e381cc 100644 --- a/specs/core/1_shard-data-chains.md +++ b/specs/core/1_shard-data-chains.md @@ -14,6 +14,7 @@ - [Initial values](#initial-values) - [Time parameters](#time-parameters) - [Signature domains](#signature-domains) + - [TODO PLACEHOLDER](#todo-placeholder) - [Data structures](#data-structures) - [`ShardBlockBody`](#shardblockbody) - [`ShardAttestation`](#shardattestation) From fe68a8d1f0febab6524e232a50cac136b5b02af9 Mon Sep 17 00:00:00 2001 From: Carl Beekhuizen Date: Sun, 30 Jun 2019 22:59:12 +0200 Subject: [PATCH 21/23] Minor python style tweaks --- specs/core/0_beacon-chain.md | 10 +++++----- specs/core/0_fork-choice.md | 4 ++-- specs/core/1_shard-data-chains.md | 8 ++++---- specs/light_client/sync_protocol.md | 4 ++-- specs/validator/0_beacon-chain-validator.md | 7 +++---- test_libs/pyspec/eth2spec/test/sanity/test_blocks.py | 4 ++-- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 7dd6a71bf..9bb562bb6 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1438,8 +1438,8 @@ def process_registry_updates(state: BeaconState) -> None: # Process activation eligibility and ejections for index, validator in enumerate(state.validators): if ( - validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH and - validator.effective_balance == MAX_EFFECTIVE_BALANCE + validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH + and validator.effective_balance == MAX_EFFECTIVE_BALANCE ): validator.activation_eligibility_epoch = get_current_epoch(state) @@ -1448,9 +1448,9 @@ def process_registry_updates(state: BeaconState) -> None: # Queue validators eligible for activation and not dequeued for activation prior to finalized epoch activation_queue = sorted([ - index for index, validator in enumerate(state.validators) if - validator.activation_eligibility_epoch != FAR_FUTURE_EPOCH and - validator.activation_epoch >= compute_activation_exit_epoch(state.finalized_checkpoint.epoch) + index for index, validator in enumerate(state.validators) + if validator.activation_eligibility_epoch != FAR_FUTURE_EPOCH + and validator.activation_epoch >= compute_activation_exit_epoch(state.finalized_checkpoint.epoch) ], key=lambda index: state.validators[index].activation_eligibility_epoch) # Dequeued validators for activation up to churn limit (without resetting activation epoch) for index in activation_queue[:get_validator_churn_limit(state)]: diff --git a/specs/core/0_fork-choice.md b/specs/core/0_fork-choice.md index 89eecff02..40ca305dc 100644 --- a/specs/core/0_fork-choice.md +++ b/specs/core/0_fork-choice.md @@ -113,8 +113,8 @@ def get_latest_attesting_balance(store: Store, root: Hash) -> Gwei: active_indices = get_active_validator_indices(state, get_current_epoch(state)) return Gwei(sum( state.validators[i].effective_balance for i in active_indices - if (i in store.latest_messages and - get_ancestor(store, store.latest_messages[i].root, store.blocks[root].slot) == root) + if (i in store.latest_messages + and get_ancestor(store, store.latest_messages[i].root, store.blocks[root].slot) == root) )) ``` diff --git a/specs/core/1_shard-data-chains.md b/specs/core/1_shard-data-chains.md index 745d437c2..05f95e16a 100644 --- a/specs/core/1_shard-data-chains.md +++ b/specs/core/1_shard-data-chains.md @@ -181,8 +181,8 @@ def get_persistent_committee(state: BeaconState, # Take not-yet-cycled-out validators from earlier committee and already-cycled-in validators from # later committee; return a sorted list of the union of the two, deduplicated return sorted(list(set( - [i for i in earlier_committee if epoch % PERSISTENT_COMMITTEE_PERIOD < get_switchover_epoch(state, epoch, i)] + - [i for i in later_committee if epoch % PERSISTENT_COMMITTEE_PERIOD >= get_switchover_epoch(state, epoch, i)] + [i for i in earlier_committee if epoch % PERSISTENT_COMMITTEE_PERIOD < get_switchover_epoch(state, epoch, i)] + + [i for i in later_committee if epoch % PERSISTENT_COMMITTEE_PERIOD >= get_switchover_epoch(state, epoch, i)] ))) ``` @@ -398,8 +398,8 @@ def is_valid_beacon_attestation(shard: Shard, assert candidate.data.previous_crosslink.data_root == Hash() else: previous_attestation = next( - (attestation for attestation in valid_attestations if - attestation.data.crosslink.data_root == candidate.data.previous_crosslink.data_root), + (attestation for attestation in valid_attestations + if attestation.data.crosslink.data_root == candidate.data.previous_crosslink.data_root), None, ) assert previous_attestation is not None diff --git a/specs/light_client/sync_protocol.md b/specs/light_client/sync_protocol.md index 2b1703f21..15f13b15b 100644 --- a/specs/light_client/sync_protocol.md +++ b/specs/light_client/sync_protocol.md @@ -153,8 +153,8 @@ def compute_committee(header: BeaconBlockHeader, # Take not-yet-cycled-out validators from earlier committee and already-cycled-in validators from # later committee; return a sorted list of the union of the two, deduplicated return sorted(list(set( - [i for i in actual_earlier_committee if epoch % PERSISTENT_COMMITTEE_PERIOD < get_switchover_epoch(i)] + - [i for i in actual_later_committee if epoch % PERSISTENT_COMMITTEE_PERIOD >= get_switchover_epoch(i)] + [i for i in actual_earlier_committee if epoch % PERSISTENT_COMMITTEE_PERIOD < get_switchover_epoch(i)] + + [i for i in actual_later_committee if epoch % PERSISTENT_COMMITTEE_PERIOD >= get_switchover_epoch(i)] ))) ``` diff --git a/specs/validator/0_beacon-chain-validator.md b/specs/validator/0_beacon-chain-validator.md index e354345fa..2626b50aa 100644 --- a/specs/validator/0_beacon-chain-validator.md +++ b/specs/validator/0_beacon-chain-validator.md @@ -132,10 +132,9 @@ Once a validator is activated, the validator is assigned [responsibilities](#bea A validator can get committee assignments for a given epoch using the following helper via `get_committee_assignment(state, epoch, validator_index)` where `epoch <= next_epoch`. ```python -def get_committee_assignment( - state: BeaconState, - epoch: Epoch, - validator_index: ValidatorIndex) -> Tuple[List[ValidatorIndex], Shard, Slot]: +def get_committee_assignment(state: BeaconState, + epoch: Epoch, + validator_index: ValidatorIndex) -> Tuple[List[ValidatorIndex], Shard, Slot]: """ Return the committee assignment in the ``epoch`` for ``validator_index``. ``assignment`` returned is a tuple of the following form: diff --git a/test_libs/pyspec/eth2spec/test/sanity/test_blocks.py b/test_libs/pyspec/eth2spec/test/sanity/test_blocks.py index b6f0ecba2..886f9bf6a 100644 --- a/test_libs/pyspec/eth2spec/test/sanity/test_blocks.py +++ b/test_libs/pyspec/eth2spec/test/sanity/test_blocks.py @@ -188,8 +188,8 @@ def test_attester_slashing(spec, state): pre_state = deepcopy(state) attester_slashing = get_valid_attester_slashing(spec, state, signed_1=True, signed_2=True) - validator_index = (attester_slashing.attestation_1.custody_bit_0_indices + - attester_slashing.attestation_1.custody_bit_1_indices)[0] + validator_index = (attester_slashing.attestation_1.custody_bit_0_indices + + attester_slashing.attestation_1.custody_bit_1_indices)[0] assert not state.validators[validator_index].slashed From 8b10ed598e9ce99d16181fcf3d7cff1f675fe678 Mon Sep 17 00:00:00 2001 From: Carl Beekhuizen Date: Sun, 30 Jun 2019 23:14:16 +0200 Subject: [PATCH 22/23] Adds a lone space --- specs/core/1_shard-data-chains.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/core/1_shard-data-chains.md b/specs/core/1_shard-data-chains.md index 05f95e16a..6213169d7 100644 --- a/specs/core/1_shard-data-chains.md +++ b/specs/core/1_shard-data-chains.md @@ -399,7 +399,7 @@ def is_valid_beacon_attestation(shard: Shard, else: previous_attestation = next( (attestation for attestation in valid_attestations - if attestation.data.crosslink.data_root == candidate.data.previous_crosslink.data_root), + if attestation.data.crosslink.data_root == candidate.data.previous_crosslink.data_root), None, ) assert previous_attestation is not None From b582afed84b2835b2db911dbfeee7e9b15621656 Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Sun, 30 Jun 2019 23:49:53 +0100 Subject: [PATCH 23/23] Add back effective balance initialisation --- specs/core/0_beacon-chain.md | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index cd4d09903..0bcc1174e 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -1691,6 +1691,7 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None: activation_epoch=FAR_FUTURE_EPOCH, exit_epoch=FAR_FUTURE_EPOCH, withdrawable_epoch=FAR_FUTURE_EPOCH, + effective_balance=min(amount - amount % EFFECTIVE_BALANCE_INCREMENT, MAX_EFFECTIVE_BALANCE), )) state.balances.append(amount) else: