use of tech.pegasys.teku.spec.datastructures.util.OptimizedMerkleTree in project teku by ConsenSys.
the class DepositProviderTest method setup.
void setup(final int maxDeposits) {
when(state.getSlot()).thenReturn(UInt64.valueOf(1234));
SpecConfig specConfig = SpecConfigLoader.loadConfig("minimal", b -> b.maxDeposits(maxDeposits));
spec = TestSpecFactory.createPhase0(specConfig);
depositUtil = new DepositUtil(spec);
dataStructureUtil = new DataStructureUtil(spec);
depositProvider = new DepositProvider(new StubMetricsSystem(), recentChainData, eth1DataCache, spec);
depositMerkleTree = new OptimizedMerkleTree(spec.getGenesisSpecConfig().getDepositContractTreeDepth());
mockStateEth1DataVotes();
createDepositEvents(40);
randomEth1Data = dataStructureUtil.randomEth1Data();
}
use of tech.pegasys.teku.spec.datastructures.util.OptimizedMerkleTree in project teku by ConsenSys.
the class BlockProcessorTest method processDepositHelper.
private BeaconState processDepositHelper(BeaconState beaconState, DepositData depositData) throws BlockProcessingException {
// Add the deposit to a Merkle tree so that we can get the root to put into the state Eth1 data
MerkleTree depositMerkleTree = new OptimizedMerkleTree(specConfig.getDepositContractTreeDepth());
depositMerkleTree.add(depositData.hashTreeRoot());
beaconState = beaconState.updated(state -> state.setEth1_data(new Eth1Data(depositMerkleTree.getRoot(), UInt64.valueOf(1), Bytes32.ZERO)));
SszListSchema<Deposit, ?> schema = SszListSchema.create(DepositWithIndex.SSZ_SCHEMA, specConfig.getMaxDeposits());
SszBytes32Vector proof = Deposit.SSZ_SCHEMA.getProofSchema().of(depositMerkleTree.getProof(0));
SszList<Deposit> deposits = schema.of(new DepositWithIndex(proof, depositData, UInt64.valueOf(0)));
// Attempt to process deposit with above data.
return beaconState.updated(state -> blockProcessor.processDeposits(state, deposits));
}
use of tech.pegasys.teku.spec.datastructures.util.OptimizedMerkleTree in project teku by ConsenSys.
the class MerkleTreeTest method proofsWithViewBoundaryOptimizedTree_getProofForIndexAlwaysSmallerThanLimit.
@Test
void proofsWithViewBoundaryOptimizedTree_getProofForIndexAlwaysSmallerThanLimit() {
merkleTree1 = new OptimizedMerkleTree(treeDepth);
merkleTree2 = new OptimizedMerkleTree(treeDepth);
for (int i = 0; i < 8; i++) {
merkleTree2.add(leaves.get(i));
}
List<Boolean> results = new ArrayList<>();
for (int index = 0; index < 8; index++) {
Bytes32 leaf = leaves.get(index);
merkleTree1.add(leaf);
Bytes32 root = merkleTree1.getRoot();
results.add(genesisSpec.predicates().isValidMerkleBranch(leaf, toSszBytes32Vector(merkleTree2.getProofWithViewBoundary(leaf, index + 1)), // Add 1 for the `List` length mix-in
treeDepth + 1, index, root));
}
assertThat(results).allSatisfy(Assertions::assertTrue);
}
use of tech.pegasys.teku.spec.datastructures.util.OptimizedMerkleTree in project teku by ConsenSys.
the class MerkleTreeTest method proofsWithViewBoundary_getProofForEachIndexInTheSmallTree.
@Test
void proofsWithViewBoundary_getProofForEachIndexInTheSmallTree() {
merkleTree1 = new OptimizedMerkleTree(treeDepth);
merkleTree2 = new OptimizedMerkleTree(treeDepth);
for (int i = 0; i < 16; i++) {
merkleTree2.add(leaves.get(i));
}
for (int i = 0; i < 10; i++) {
merkleTree1.add(leaves.get(i));
}
Bytes32 root = merkleTree1.getRoot();
List<Boolean> results = new ArrayList<>();
for (int index = 0; index < 10; index++) {
results.add(genesisSpec.predicates().isValidMerkleBranch(leaves.get(index), toSszBytes32Vector(merkleTree2.getProofWithViewBoundary(index, 10)), // Add 1 for the `List` length mix-in
treeDepth + 1, index, root));
}
assertThat(results).allSatisfy(Assertions::assertTrue);
}
use of tech.pegasys.teku.spec.datastructures.util.OptimizedMerkleTree in project teku by ConsenSys.
the class MerkleTreeTest method getProof.
@Test
void getProof() {
merkleTree1 = new OptimizedMerkleTree(treeDepth);
List<Boolean> results = new ArrayList<>();
for (int index = 0; index < 7; index++) {
Bytes32 leaf = leaves.get(index);
merkleTree1.add(leaf);
Bytes32 root = merkleTree1.getRoot();
results.add(genesisSpec.predicates().isValidMerkleBranch(leaf, toSszBytes32Vector(merkleTree1.getProof(leaf)), // Add 1 for the `List` length mix-in
treeDepth + 1, index, root));
}
assertThat(results).allSatisfy(Assertions::assertTrue);
}
Aggregations