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

test: validator merkle proof #4132

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ venv
/.pytest_cache
*.swp
.eth2spec
.idea

build/
output/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,31 @@ def test_finality_root_merkle_proof(spec, state):
index=spec.get_subtree_index(gindex),
root=state.hash_tree_root(),
)


@with_test_suite_name("BeaconState")
@with_light_client
@spec_state_test
def test_validator_merkle_proof(spec, state):
"""
Demonstrates the validity of a Merkle proof for state.validators[0] in the BeaconState.
Ensures that a client can prove inclusion of a single validator record.
(for example, to verify the validator's public key or effective balance).
"""
yield "object", state
validator_0_gindex = spec.get_generalized_index(state, 'validators', 0)
branch = spec.compute_merkle_proof(state, validator_0_gindex)

yield "proof", {
"leaf": "0x" + state.validators[0].hash_tree_root().hex(),
"leaf_index": validator_0_gindex,
"branch": ['0x' + root.hex() for root in branch]
}

assert spec.is_valid_merkle_branch(
leaf=state.validators[0].hash_tree_root(),
branch=branch,
depth=spec.floorlog2(validator_0_gindex),
index=spec.get_subtree_index(validator_0_gindex),
root=state.hash_tree_root(),
)