Commit Graph

188 Commits

Author SHA1 Message Date
Etan Kissling c4dbd241ac
Root `next_sync_committee` in `attested_header`
`LightClientUpdate` structures currently use different merkle proof root
depending on the presence of `finalized_header`. By always rooting it in
the same state (the `attested_header.state_root`), logic gets simpler.

Caveats:
- In periods of extended non-finality, `update.finalized_header` may now
  be outdated by several sync committee periods. The old implementation
  rejected such updates as the `next_sync_committee` in them was stale,
  but the new implementation can properly handle this case.
- The `next_sync_committee` can no longer be considered finalized based
  on `is_finality_update`. Instead, waiting until `finalized_header` is
  in the `attested_header`'s sync committee period is now necessary.
- Because `update.finalized_header > store.finalized_header` no longer
  holds (for updates with finality), an `is_better_update` helper is
  added to improve `best_valid_update` tracking (in the past, finalized
  updates with supermajority participation would always directly apply)

This PR builds on prior work from:
- @hwwhww at https://github.com/ethereum/consensus-specs/pull/2829
2022-07-01 14:49:24 -07:00
Etan Kissling e269b305b9
Cleanup light client tests
Various cleanups and minor fixes:
- Consistent terminology:
  - `signed_block` -> `attested_block`
  - `finalized_block_header` -> `finalized_header`
  - `snapshot_period` -> `store_period`
- Use correct block in finality test (`blocks[-1]` instead of new one)
- Add `signed_block_header` func to get header from `SignedBeaconBlock`
- Remove `block_header` from `get_sync_aggregate` helper arguments
- Use `state_transition_with_full_block` as shortcut for multiple calls
- Have `finalized_header` actually be header instead of full block body
- Consistent ordering of `assert` to match structure definition
2022-06-30 11:09:49 +02:00
Etan Kissling f5f3031c5e
Allow passing redundant `next_sync_committee`
The producer of `LightClientUpdate` structures usually does not know how
far the `LightClientStore` on the client side has advanced. Updates are
currently rejected when including a redundant `next_sync_committee` not
advancing the `LightClientStore`. Behaviour is changed to allow this.
2022-06-29 13:16:03 +02:00
Etan Kissling 9a253e437d
create decorator for tests with matching config 2022-06-24 01:05:11 +02:00
Etan Kissling 0b8ab23bd4
Remove `fork_version` from `LightClientUpdate`
The `fork_version` field in `LightClientUpdate` can be derived from the
`update.signature_slot` value by consulting the locally configured fork
schedule. The light client already needs access to the fork schedule to
determine the `GeneralizedIndex` values used for merkle proofs, and the
memory layouts of the structures (including `LightClientUpdate`). The
`fork_version` itself is network dependent and doesn't reveal that info.
2022-06-16 17:17:24 +02:00
Hsiao-Wei Wang 8cc008d11c
Merge pull request #2805 from etan-status/lc-period
Allow light client to verify signatures at period boundary
2022-06-16 16:53:12 +02:00
Justin Traglia a7bda480fe Convert sets to sorted lists prior to sampling
This is because sampling of sets has been deprecated in Python 3.9. I used
sorted() instead of list() so that things are deterministic.
2022-05-09 14:09:27 -05:00
Etan Kissling 5653649ca8
Allow light client to verify signatures at period boundary
As the sync committee signs the previous block, the situation arises at
every sync committee period boundary, that the new sync committee signs
a block in the previous sync committee period. The light client cannot
reliably detect this condition (e.g., assume that this is the case when
it is currently on the last slot of a sync committee period), because
the last couple slots of a sync committee period may not have a block.

For example, when receiving a `LightClientUpdate` that is constructed
as in the following illustration, it is unknown whether `sync_aggregate`
was signed by the current or next sync committee at `attested_header`.

```

        slot N           N + 1   |            N + 2   (slot not sent!)
                                 |
  +-----------------+     \ /    |     +----------------+
  | attested_header | <--- X ----|---- | sync_aggregate |
  +-----------------+     / \    |     +----------------+
                        missed   |
                                 |
                          sync committee
                          period boundary
```

This patch addresses this edge case by including the slot at which the
`sync_aggregate` was created into the `LightClientUpdate` object.

Note that the `signature_slot` cannot be trusted beyond the purpose of
signature verification, as it could be manipulated to any other slot
within the same sync committee period and fork version, without making
the `sync_aggregate` invalid.
2022-05-02 13:08:20 +02:00
Hsiao-Wei Wang 3d7f307020 Refactor test_sync_protocol.py a bit 2022-02-04 17:46:37 -08:00
Etan Kissling 8319d07084
Consistently use `compute_sync_committee_period`
There were a couple instances where a division was used on an epoch
to derive the corresponding sync committee period instead of calling the
`compute_sync_committee_period` function.
These instances were changed to also use the function.
2022-01-17 17:38:24 +01:00
Etan Kissling 48e19b15ae
Rename `sync_committee_aggregate` > `sync_aggregate`
This renames the `sync_committee_aggregate` field of `LightClientUpdate`
to `sync_aggregate` for consistency with the terminology in the rest of
the spec.
2022-01-11 11:22:39 +01:00
Hsiao-Wei Wang 257c2413a5
Update test_sync_protocol.py per the new optimistic_header and data structure 2021-12-14 22:06:25 +08:00
Hsiao-Wei Wang f0bb032eb1
Fix `test_transition_with_one_fourth_exiting_validators_exit_at_fork` assertions 2021-11-15 23:46:40 +08:00
Hsiao-Wei Wang 0641d1c184
`ALL_FORKS` sounds like a list of fork names. Rename it to `ALL_FORK_UPGRADES` 2021-11-02 19:01:32 +08:00
Hsiao-Wei Wang 0b0fe15c75
Make altair transition tests support merge forks 2021-11-02 14:47:24 +08:00
Hsiao-Wei Wang 7480fad8cd
Add `test_transition_with_activation_at_fork_epoch` 2021-10-15 22:46:16 +08:00
Hsiao-Wei Wang 40869d6e39
PR feedback on `exit_random_validators` helper 2021-10-15 22:14:30 +08:00
Hsiao-Wei Wang be6d2017bb
fix typo 2021-10-15 22:05:07 +08:00
Hsiao-Wei Wang 162711ea56
PR feedback. Rework `transition_to_next_epoch_and_append_blocks` a bit 2021-10-15 22:00:48 +08:00
Hsiao-Wei Wang a4e5d50660
Fix/ignore mainnet preset cases 2021-10-15 11:57:10 +08:00
Hsiao-Wei Wang f62167c4ab
pr feedback 2021-10-15 00:30:24 +08:00
Hsiao-Wei Wang 3a242a1e0b
Refactor and add test cases of having operation right before the fork 2021-10-15 00:02:33 +08:00
Hsiao-Wei Wang 49bf78d431
PR feedback 2021-10-14 22:40:29 +08:00
Hsiao-Wei Wang cbba5426fe
PR feedback 2021-10-14 20:22:03 +08:00
Hsiao-Wei Wang 67da1ba2bf
Minor refactoring
- sanity check: deposit operation is independent of spec fork versions
- refactoring
- add comments
2021-10-14 00:06:29 +08:00
Hsiao-Wei Wang 53d4fa5187
Make operation (attester_slashing, proposer_slashing, voluntary_exit) at the fork block 2021-10-13 02:01:13 +08:00
Hsiao-Wei Wang f0980a4ab9
Refactoring. Sort tests to specific files. 2021-10-13 00:26:23 +08:00
Hsiao-Wei Wang 95f940cc74
ensure that some of the current sync committee members are the slashed 2021-10-12 23:33:48 +08:00
Hsiao-Wei Wang 4dd8b7c98a
[WIP] Add new transition tests 2021-10-12 23:05:14 +08:00
Hsiao-Wei Wang ff15d0bc39
Apply PR feedback from @ralexstokes 2021-10-07 16:04:06 +08:00
Hsiao-Wei Wang 4ae8fb182e
Fix `run_sync_committee_sanity_test` so that it works with duplicate committee indices 2021-10-07 03:29:09 +08:00
Etan Kissling 939e6c7e8e
run tests against future forks by default
Some tests are currently restricted to a single phase using @with_phases
even though they could likely run unchanged in later phases. This patch
changes the default for such tests to also run in later phases. If the
beacon chain changes enough in later phases to break these tests, this
highlights that the tests need to be adjusted or extended accordingly.
2021-09-30 10:28:02 +02:00
protolambda bd8c978965
move merkle tests, output proof.yaml, update format 2021-09-27 18:07:59 +02:00
Etan Kissling e7317e2283
merkle proof test generator
Building merkle proofs is required functionality for implementing light
client sync. Although the spec currently only defines a function to
verify merkle proofs (`is_valid_merkle_branch`) there are still a few
PySpec unit tests that produce merkle proofs. This patch adds a new
generator to extract test vectors from those static unit tests, so that
light client implementations can validate their merkle proof logic.
2021-09-27 17:34:51 +02:00
Etan Kissling 0c65f79d82
fix merkle proof test for mainnet
The `test_next_sync_committee_tree` currently only supports the minimal
preset, as it incorrectly initializes the `next_sync_committee`. On the
mainnet preset, `SYNC_COMMITTEE_SIZE` is 512, but the default states use
only 256 validators, leading to an IndexError during the test execution.
`next_sync_committee` is already initialized correctly prior to the test
run using the spec's `get_next_sync_committee` function, which fills up
extra committee slots with duplicate validators in this scenario. This
makes it unnecessary to manually initialize the `next_sync_committee`.
Removed the incorrect initialization to allow testing on mainnet preset.
2021-09-23 15:20:18 +02:00
Etan Kissling 370b9e86e3
pass sync committee sig consistently in tests
There are three defined unit tests for the light client sync protocol.
They all follow a similar structure. However, there is an inconcistency
how they pass the slot to compute_aggregate_sync_committee_signature.
In one instance it is passed as `block.slot`. In the other two cases
it is passed as `block_header.slot`. As the `block_header` is created
from the `block`, they share the same value. This patch makes the way
how the slot is passed consistent across all of the test cases.
2021-09-15 21:34:10 +02:00
Danny Ryan d6b5cbd94c
fix sync agg test for mainnet 2021-09-09 19:53:30 -06:00
Alex Stokes 0cee5660db
pr feedback 2021-09-09 15:43:42 -07:00
Alex Stokes c0994e6736
Add sync committee tests with exited and withdrawable members 2021-09-09 13:27:54 -07:00
Alex Stokes fb4a4f6694
Update tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate_random.py
Co-authored-by: Danny Ryan <dannyjryan@gmail.com>
2021-09-07 13:09:23 -06:00
Alex Stokes 30596fb8a1
Update tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate_random.py 2021-09-02 15:35:15 -06:00
Alex Stokes ad076697f4
add test case for active/exited difference for sync rewards processing 2021-09-02 09:50:39 -07:00
Antonio Sanso ae8c0447ef
Update tests/core/pyspec/eth2spec/test/altair/block_processing/sync_aggregate/test_process_sync_aggregate.py
Co-authored-by: Alex Stokes <r.alex.stokes@gmail.com>
2021-09-02 14:57:47 +02:00
Antonio Sanso 5f1a444e70
Update test_process_sync_aggregate.py 2021-09-02 11:34:42 +02:00
Antonio Sanso 2206a58335
Update test_process_sync_aggregate.py 2021-09-02 11:33:12 +02:00
Antonio Sanso 2d736139d5
Update test_process_sync_aggregate.py 2021-09-02 11:19:58 +02:00
Antonio Sanso 9bf8ad9130
Update test_process_sync_aggregate.py 2021-09-02 11:00:51 +02:00
Alex Stokes 874ea80cb8
use more precise name for altair block randomizer and re-gen tests 2021-08-25 17:18:02 -07:00
Alex Stokes e2dc9f9ec2
update generation of randomized scenarios for more variability 2021-08-25 14:42:41 -07:00
Alex Stokes 14518d4d64
update name of utility module to be more specific 2021-08-25 11:15:59 -07:00