コード例 #1
0
        private static void CheckBlockIsMutated(BlockTemplate newBlock)
        {
            List <uint256> transactionHashes = newBlock.Block.Transactions.Select(t => t.GetHash()).ToList();

            BlockMerkleRootRule.ComputeMerkleRoot(transactionHashes, out bool isMutated);
            isMutated.Should().Be(true);
        }
コード例 #2
0
        /// <summary>
        /// Sets the receipt root based on all the receipts generated in smart contract execution inside this block.
        /// </summary>
        private void UpdateReceiptRoot(SmartContractBlockHeader scHeader)
        {
            List <uint256> leaves  = this.receipts.Select(x => x.GetHash()).ToList();
            bool           mutated = false; // TODO: Do we need this?

            scHeader.ReceiptRoot = BlockMerkleRootRule.ComputeMerkleRoot(leaves, out mutated);
        }
コード例 #3
0
 private uint256 ComputeMerkleRoot(List <uint256> leaves, out bool mutated)
 {
     using (new StaticFlagIsolator(Network.Main))
     {
         Network.Main.Consensus.Options = new PosConsensusOptions();
         return(BlockMerkleRootRule.ComputeMerkleRoot(leaves, out mutated));
     }
 }
コード例 #4
0
        /// <inheritdoc />
        public uint256 BlockMerkleRoot(Block block, out bool mutated)
        {
            var leaves = new List <uint256>(block.Transactions.Count);

            foreach (Transaction tx in block.Transactions)
            {
                leaves.Add(tx.GetHash());
            }

            return(BlockMerkleRootRule.ComputeMerkleRoot(leaves, out mutated));
        }
コード例 #5
0
        /// <inheritdoc />
        public uint256 BlockWitnessMerkleRoot(Block block, out bool mutated)
        {
            var leaves = new List <uint256>();

            leaves.Add(uint256.Zero); // The witness hash of the coinbase is 0.
            foreach (Transaction tx in block.Transactions.Skip(1))
            {
                leaves.Add(tx.GetWitHash());
            }

            return(BlockMerkleRootRule.ComputeMerkleRoot(leaves, out mutated));
        }
        /// <summary>
        /// Throws a consensus exception if the receipt roots don't match.
        /// </summary>
        public void ValidateAndStoreReceipts(uint256 receiptRoot)
        {
            List <uint256> leaves              = this.receipts.Select(x => x.GetHash()).ToList();
            bool           mutated             = false; // TODO: Do we need this?
            uint256        expectedReceiptRoot = BlockMerkleRootRule.ComputeMerkleRoot(leaves, out mutated);

            if (receiptRoot != expectedReceiptRoot)
            {
                SmartContractConsensusErrors.UnequalReceiptRoots.Throw();
            }

            this.ContractCoinviewRule.ReceiptRepository.Store(this.receipts);
        }
コード例 #7
0
        public void MerkleRootComputationNotMutated()
        {
            var leaves = new List <uint256>()
            {
                new uint256("281f5acb40a15640bc48b90b5296a87d09341e3510608b191c9bc3a511f8e436"),
                new uint256("f4570fd8c54fded84b696ba3eb986a5421b0a41109dea6e10ba96aec70f78f00")
            };
            bool    mutated;
            uint256 root = BlockMerkleRootRule.ComputeMerkleRoot(leaves, out mutated);

            Assert.Equal("cd00f5d5aada62c8e49a9f01378998cbd016d04b725d0d8497877e5f75ffc722", root.ToString());
            Assert.False(mutated);
        }
コード例 #8
0
        public void MerkleRootComputationMutated()
        {
            var leaves = new List <uint256>()
            {
                new uint256("281f5acb40a65640bc48b90b5296a87d09341e3510608b191c9bc3a511f8e436"),
                new uint256("d0249653efaaa999f0278bb390c0f4ec3e5465a10f35264ebcfbb6dd6a677abd"),
                new uint256("7897c117fddbf98ea9749cc868a9d1e663b198dd3ac0ae5837734007f0060b20"),
                new uint256("ced314892a97f342a136269e2842fd0dbd1cab1fa84557bc48420f7cf96f0bc7"),

                new uint256("5b98af3d7554916483bca1a52f16570a93f07c95d6aeb8d08b0794c86cf58128"),
                new uint256("5b98af3d7554916483bca1a52f16570a93f07c95d6aeb8d08b0794c86cf58128"),
                new uint256("5b98af3d7554916483bca1a52f16570a93f07c95d6aeb8d08b0794c86cf58128"),

                new uint256("91be5a63b4b70c8329f20960e49a8bd3adeb77fcbadf78014ac54efaf1647a31"),
                new uint256("ac2dcf5c46d9a801389b6c0630b435ce5c2fa850cfac5456f16937dd8ae697d3")
            };
            bool    mutated;
            uint256 root = BlockMerkleRootRule.ComputeMerkleRoot(leaves, out mutated);

            Assert.Equal("95aa5bba66381c3817df338895349acd3fc3e8ce226e04a5e2acbb53db18b9c0", root.ToString());
            Assert.True(mutated);
        }
コード例 #9
0
 private uint256 ComputeMerkleRoot(List <uint256> leaves, out bool mutated)
 {
     KnownNetworks.Main.Consensus.Options = new PosConsensusOptions();
     return(BlockMerkleRootRule.ComputeMerkleRoot(leaves, out mutated));
 }