Revert "Implement push_leaf for MerkleTree (#563)" (#572)

This reverts commit 13faa47da1.
This commit is contained in:
Paul Hauner
2019-10-26 15:17:29 +11:00
committed by GitHub
parent 13faa47da1
commit dd370b2e33
2 changed files with 13 additions and 138 deletions

View File

@@ -210,19 +210,22 @@ fn interop_genesis_state<T: EthSpec>(
.collect::<Vec<_>>();
let mut proofs = vec![];
let depth = spec.deposit_contract_tree_depth as usize;
let mut tree = MerkleTree::create(&[], depth);
for (i, deposit_leaf) in deposit_root_leaves.iter().enumerate() {
if let Err(_) = tree.push_leaf(*deposit_leaf, depth) {
return Err(String::from("Failed to push leaf"))
}
for i in 1..=deposit_root_leaves.len() {
// Note: this implementation is not so efficient.
//
// If `MerkleTree` had a push method, we could just build one tree and sample it instead of
// rebuilding the tree for each deposit.
let tree = MerkleTree::create(
&deposit_root_leaves[0..i],
spec.deposit_contract_tree_depth as usize,
);
let (_, mut proof) = tree.generate_proof(i, depth);
proof.push(Hash256::from_slice(&int_to_bytes32(i + 1)));
let (_, mut proof) = tree.generate_proof(i - 1, spec.deposit_contract_tree_depth as usize);
proof.push(Hash256::from_slice(&int_to_bytes32(i)));
assert_eq!(
proof.len(),
depth + 1,
spec.deposit_contract_tree_depth as usize + 1,
"Deposit proof should be correct len"
);