Example #1
0
        public void TestVerifyProof()
        {
            var mpt = new MPTTrie <TestKey, TestValue>(mptdb.GetSnapshot(), root.Hash);
            HashSet <byte[]> proof = mpt.GetProof("ac01".HexToBytes());
            TestValue        value = MPTTrie <TestKey, TestValue> .VerifyProof(root.Hash, "ac01".HexToBytes(), proof);

            Assert.IsNotNull(value);
            Assert.AreEqual(value.ToString(), "abcd");
        }
Example #2
0
        public void TestVerifyProof()
        {
            var mpt    = new MPTTrie(rootHash, mptdb);
            var result = mpt.GetProof("ac01".HexToBytes(), out HashSet <byte[]> proof);

            Assert.IsTrue(result);
            result = MPTTrie.VerifyProof(rootHash, "ac01".HexToBytes(), proof, out byte[] value);
            Assert.IsTrue(result);
        }
        public bool VerifyProof(UInt256 root, byte[] key, HashSet <byte[]> proof, out byte[] value)
        {
            var result = MPTTrie.VerifyProof(root, key, proof, out value);

            if (result)
            {
                value = value.AsSerializable <StorageItem>().Value;
            }
            return(result);
        }
Example #4
0
        public void TestVerifyProof()
        {
            var mpt    = new MPTTrie <TestKey, TestValue>(mptdb.GetSnapshot(), root.Hash);
            var result = mpt.TryGetProof("ac01".HexToBytes(), out var proof);

            Assert.IsTrue(result);
            TestValue value = MPTTrie <TestKey, TestValue> .VerifyProof(root.Hash, "ac01".HexToBytes(), proof);

            Assert.IsNotNull(value);
            Assert.AreEqual(value.ToString(), "abcd");
        }
Example #5
0
        public void TestEmptyValueIssue633()
        {
            var key      = "01".HexToBytes();
            var snapshot = new TestSnapshot();
            var mpt      = new MPTTrie <TestKey, TestValue>(snapshot, null);

            mpt.Put(key, Array.Empty <byte>());
            var val = mpt["01".HexToBytes()];

            Assert.IsNotNull(val);
            Assert.AreEqual(0, val.Size);
            var r = mpt.TryGetProof(key, out var proof);

            Assert.IsTrue(r);
            val = MPTTrie <TestKey, TestValue> .VerifyProof(mpt.Root.Hash, key, proof);

            Assert.IsNotNull(val);
            Assert.AreEqual(0, val.Size);
        }
Example #6
0
        private string VerifyProof(UInt256 root_hash, byte[] proof)
        {
            var proofs = new HashSet <byte[]>();

            using MemoryStream ms     = new MemoryStream(proof, false);
            using BinaryReader reader = new BinaryReader(ms, Utility.StrictUTF8);

            var key   = reader.ReadVarBytes(MPTNode.MaxKeyLength);
            var count = reader.ReadVarInt();

            for (ulong i = 0; i < count; i++)
            {
                proofs.Add(reader.ReadVarBytes());
            }

            var skey  = key.AsSerializable <StorageKey>();
            var sitem = MPTTrie <StorageKey, StorageItem> .VerifyProof(root_hash, skey, proofs);

            if (sitem is null)
            {
                throw new RpcException(-100, "Verification failed");
            }
            return(Convert.ToBase64String(sitem.Value));
        }