Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow extending LC merkle proof tests #3066

Merged
merged 3 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
@with_altair_and_later
@spec_state_test
def test_current_sync_committee_merkle_proof(spec, state):
yield "state", state
current_sync_committee_branch = spec.compute_merkle_proof_for_state(state, spec.CURRENT_SYNC_COMMITTEE_INDEX)
yield "object_class", "meta", "BeaconState"
yield "object", state
current_sync_committee_branch = \
spec.compute_merkle_proof_for_state(state, spec.CURRENT_SYNC_COMMITTEE_INDEX)
yield "proof", {
"leaf": "0x" + state.current_sync_committee.hash_tree_root().hex(),
"leaf_index": spec.CURRENT_SYNC_COMMITTEE_INDEX,
Expand All @@ -26,8 +28,10 @@ def test_current_sync_committee_merkle_proof(spec, state):
@with_altair_and_later
@spec_state_test
def test_next_sync_committee_merkle_proof(spec, state):
yield "state", state
next_sync_committee_branch = spec.compute_merkle_proof_for_state(state, spec.NEXT_SYNC_COMMITTEE_INDEX)
yield "object_class", "meta", "BeaconState"
yield "object", state
next_sync_committee_branch = \
spec.compute_merkle_proof_for_state(state, spec.NEXT_SYNC_COMMITTEE_INDEX)
yield "proof", {
"leaf": "0x" + state.next_sync_committee.hash_tree_root().hex(),
"leaf_index": spec.NEXT_SYNC_COMMITTEE_INDEX,
Expand All @@ -45,8 +49,10 @@ def test_next_sync_committee_merkle_proof(spec, state):
@with_altair_and_later
@spec_state_test
def test_finality_root_merkle_proof(spec, state):
yield "state", state
finality_branch = spec.compute_merkle_proof_for_state(state, spec.FINALIZED_ROOT_INDEX)
yield "object_class", "meta", "BeaconState"
yield "object", state
finality_branch = \
spec.compute_merkle_proof_for_state(state, spec.FINALIZED_ROOT_INDEX)
yield "proof", {
"leaf": "0x" + state.finalized_checkpoint.root.hex(),
"leaf_index": spec.FINALIZED_ROOT_INDEX,
Expand Down
18 changes: 12 additions & 6 deletions tests/formats/light_client/single_merkle_proof.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@ generation and verification of merkle proofs based on static data.

## Test case format

### `state.ssz_snappy`
### `meta.yaml`

An SSZ-snappy encoded `BeaconState` object from which other data is generated.
```yaml
object_class: string -- 'BeaconState'
```

### `object.yaml`

A SSZ-snappy encoded object of type `object_class` from which other data is generated.

### `proof.yaml`

A proof of the leaf value (a merkle root) at generalized-index `leaf_index` in the given `state`.
A proof of the leaf value (a merkle root) at generalized-index `leaf_index` in the given `object`.

```yaml
leaf: Bytes32 # string, hex encoded, with 0x prefix
leaf_index: int # integer, decimal
branch: list of Bytes32 # list, each element is a string, hex encoded, with 0x prefix
branch: list of Bytes32 # list, each element is a string, hex encoded, with 0x prefix
```

## Condition

A test-runner can implement the following assertions:
- Check that `is_valid_merkle_branch` confirms `leaf` at `leaf_index` to verify
against `has_tree_root(state)` and `proof`.
against `hash_tree_root(object)` and `branch`.
- If the implementation supports generating merkle proofs, check that the
self-generated proof matches the `proof` provided with the test.
self-generated proof matches the `branch` provided with the test.