BitSharper.Block.CheckProofOfWork C# (CSharp) Method

CheckProofOfWork() private method

Returns true if the hash of the block is OK (lower than difficulty target).
private CheckProofOfWork ( bool throwException ) : bool
throwException bool
return bool
        private bool CheckProofOfWork(bool throwException)
        {
            // This part is key - it is what proves the block was as difficult to make as it claims
            // to be. Note however that in the context of this function, the block can claim to be
            // as difficult as it wants to be .... if somebody was able to take control of our network
            // connection and fork us onto a different chain, they could send us valid blocks with
            // ridiculously easy difficulty and this function would accept them.
            //
            // To prevent this attack from being possible, elsewhere we check that the difficultyTarget
            // field is of the right value. This requires us to have the preceding blocks.
            var target = GetDifficultyTargetAsInteger();

            var h = Hash.ToBigInteger();
            if (h.CompareTo(target) > 0)
            {
                // Proof of work check failed!
                if (throwException)
                    throw new VerificationException("Hash is higher than target: " + HashAsString + " vs " +
                                                    target.ToString(16));
                return false;
            }
            return true;
        }