The Deposit Contract inserts all deposits into a Merkle tree. According to the Beacon Chains spec, when a deposit is processed on the Beacon Chain, it must be verified that the deposit is indeed a valid leaf the in the Merkle tree. This is specified in process_deposit():
def process_deposit(state: BeaconState, deposit: Deposit) -> None:
# Verify the Merkle branch
assert is_valid_merkle_branch(
leaf=hash_tree_root(deposit.data),
branch=deposit.proof,
depth=DEPOSIT_CONTRACT_TREE_DEPTH + 1, # Add 1 for the List length mix-in
index=state.eth1_deposit_index,
root=state.eth1_data.deposit_root,
)
# Deposits must be processed in order
state.eth1_deposit_index += 1
...
I don't understand the point of this. If the Eth1 data was trusted, then validating the data seems unnecessary. On the other hand, if the Eth1 data is not trusted, then the above check does not seem to help, because then we also wouldn't be able to trust state.eth1_data.deposit_root
, i.e., the Merkle root could conceivably be completely unrelated to the state of the actual Deposit Contract. Checking that some untrusted piece of data is in some untrusted Merkle tree does not seem to increase security in any way.
I feel I'm deeply misunderstanding something here.
is_valid_merkle_branch
code?