Ejemplo n.º 1
0
        public void Can_verify_zero_and_one_elements(uint nodesCount)
        {
            BaselineTree baselineTree = BuildATree();
            Keccak       root         = baselineTree.Root;

            Console.WriteLine(root);
            for (int i = 0; i < nodesCount; i++)
            {
                baselineTree.Insert(_testLeaves[i]);
                Keccak newRoot = baselineTree.Root;
                Console.WriteLine(newRoot);
                newRoot.Should().NotBeEquivalentTo(root);
                root = newRoot;
                var proof0 = baselineTree.GetProof(0);
                var proof1 = baselineTree.GetProof(1);
                baselineTree.Verify(root, _testLeaves[0], proof0).Should().BeTrue("left in " + i);
                if (i > 0)
                {
                    baselineTree.Verify(root, _testLeaves[1], proof1).Should().BeTrue("right in " + i);
                }
            }
        }
Ejemplo n.º 2
0
        public void Keccak_a_b_verify()
        {
            BaselineTree baselineTree = BuildATree();
            Keccak       root0        = baselineTree.Root;

            Console.WriteLine("root0 " + root0);
            Console.WriteLine("KeccakA " + TestItem.KeccakA);
            baselineTree.Insert(TestItem.KeccakA);
            var    proof0_0 = baselineTree.GetProof(0);
            Keccak root1    = baselineTree.Root;

            Console.WriteLine("root1 " + root1);
            Console.WriteLine("KeccakB " + TestItem.KeccakB);
            baselineTree.Insert(TestItem.KeccakB);
            Keccak root2 = baselineTree.Root;

            Console.WriteLine("root2 " + root2);
            var proof1_0 = baselineTree.GetProof(0);
            var proof1_1 = baselineTree.GetProof(1);

            baselineTree.Verify(root1, TestItem.KeccakA, proof0_0).Should().BeTrue();
            baselineTree.Verify(root2, TestItem.KeccakA, proof1_0).Should().BeTrue();
            baselineTree.Verify(root2, TestItem.KeccakB, proof1_1).Should().BeTrue();
        }
Ejemplo n.º 3
0
        public void Can_get_proof_on_a_populated_trie_on_an_index(uint nodesCount)
        {
            BaselineTree baselineTree = BuildATree();

            for (int i = 0; i < nodesCount; i++)
            {
                baselineTree.Insert(_testLeaves[0]);
            }

            BaselineTreeNode[] proof = baselineTree.GetProof(0);
            proof.Should().HaveCount(BaselineTree.TreeHeight);

            for (int proofRow = 0; proofRow < BaselineTree.TreeHeight; proofRow++)
            {
                if (nodesCount > 1 >> proofRow)
                {
                    proof[proofRow].Should().NotBe(Keccak.Zero, proofRow.ToString());
                }
                else
                {
                    proof[proofRow].Hash.Should().Be(Keccak.Zero, proofRow.ToString());
                }
            }
        }