Ejemplo n.º 1
0
def validate_deposit_proof(state: BeaconState, deposit: Deposit,
                           deposit_contract_tree_depth: int) -> None:
    """
    Validate if deposit branch proof is valid.
    """
    # Should equal 8 bytes for deposit_data.amount +
    #              8 bytes for deposit_data.timestamp +
    #              176 bytes for deposit_data.deposit_input
    # It should match the deposit_data in the eth1.0 deposit contract
    serialized_deposit_data = ssz.encode(deposit.deposit_data)

    is_valid_proof = verify_merkle_branch(
        leaf=hash_eth2(serialized_deposit_data),
        proof=deposit.proof,
        depth=deposit_contract_tree_depth,
        index=deposit.index,
        root=state.latest_eth1_data.deposit_root,
    )
    if not is_valid_proof:
        raise ValidationError(
            f"deposit.proof ({deposit.proof}) is invalid against "
            f"leaf={hash_eth2(serialized_deposit_data)}, "
            f"deposit_contract_tree_depth={deposit_contract_tree_depth}, "
            f"deposit.index={deposit.index} "
            f"state.latest_eth1_data.deposit_root={state.latest_eth1_data.deposit_root.hex()}"
        )
Ejemplo n.º 2
0
 def verify_deposit(deposit_count, deposit_index, eth1_monitor) -> bool:
     deposit = eth1_monitor._get_deposit(deposit_count=deposit_count,
                                         deposit_index=deposit_index)
     _, root = make_deposit_tree_and_root(
         eth1_monitor._db.get_deposit_data_range(0, deposit_count))
     return verify_merkle_branch(
         deposit.data.hash_tree_root,
         deposit.proof,
         DEPOSIT_CONTRACT_TREE_DEPTH + 1,
         deposit_index,
         root,
     )
Ejemplo n.º 3
0
def validate_deposit_proof(state: BeaconState, deposit: Deposit,
                           deposit_contract_tree_depth: int) -> None:
    """
    Validate if deposit branch proof is valid.
    """
    is_valid_proof = verify_merkle_branch(
        leaf=deposit.data.hash_tree_root,
        proof=deposit.proof,
        depth=deposit_contract_tree_depth + 1,
        index=state.eth1_deposit_index,
        root=state.eth1_data.deposit_root,
    )
    if not is_valid_proof:
        raise ValidationError(
            f"deposit.proof ({list(map(encode_hex, deposit.proof))}) is invalid against "
            f"leaf={encode_hex(deposit.data.hash_tree_root)}, "
            f"deposit_contract_tree_depth={deposit_contract_tree_depth}, "
            f"deposit.index (via state) = {state.eth1_deposit_index} "
            f"state.eth1_data.deposit_root={state.eth1_data.deposit_root.hex()}"
        )