From 994a42e6b1207fb91925e81faaf7cc282871fee8 Mon Sep 17 00:00:00 2001 From: Ben Edgington Date: Tue, 8 Jan 2019 19:47:14 +0000 Subject: [PATCH] Add getter to Vyper contract for Merkle branches Returns the Merkle branch for the leaf at index `index`. This getter provides an alternative way for beacon chain proposers to access the Merkle tree of deposits rather than being Ethereum 1.0 light clients. The method can be called on a trusted Ethereum 1.0 archive node at specific past block numbers to retrieve the Merkle branch needed to register a validator. --- specs/core/0_beacon-chain.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 23b35fc6f..c86b4b6b5 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -692,6 +692,18 @@ def deposit(deposit_input: bytes[2048]): def get_deposit_root() -> bytes32: return self.deposit_tree[1] +@public +@constant +def get_merkle_branch(index: uint256) -> bytes32[32]: # size is DEPOSIT_CONTRACT_TREE_DEPTH (symbolic const not supported) + idx: uint256 = index + TWO_TO_POWER_OF_TREE_DEPTH + ret: bytes32[32] # size is DEPOSIT_CONTRACT_TREE_DEPTH + for i in range(DEPOSIT_CONTRACT_TREE_DEPTH): + if idx % 2 == 1: + ret[i] = self.deposit_tree[idx - 1] + else: + ret[i] = self.deposit_tree[idx + 1] + idx /= 2 + return ret ``` ## Beacon chain processing