From f1846d8b19cb53634c26d0618fcceaa6111e12d2 Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Thu, 27 Aug 2015 22:12:25 +0300 Subject: [PATCH] Use code contracts. RunCodeAnalysis=True CodeContractsEnableRuntimeChecking=True --- Novacoin/AddressTools.cs | 1 + Novacoin/ByteQueue.cs | 57 +++++++++++++------------- Novacoin/CBlockHeader.cs | 3 + Novacoin/CKeyID.cs | 31 ++++++++------ Novacoin/CKeyPair.cs | 36 ++-------------- Novacoin/CKeyStore.cs | 33 +++++++++++++-- Novacoin/CNovacoinAddress.cs | 69 ++++++++++++++++++------------- Novacoin/COutPoint.cs | 3 + Novacoin/CPubKey.cs | 2 +- Novacoin/CScript.cs | 23 +--------- Novacoin/CScriptID.cs | 36 ++++++++++------ Novacoin/Hash.cs | 6 +++ Novacoin/Interop.cs | 17 -------- Novacoin/Novacoin.csproj | 45 ++++++++++++++++++++ Novacoin/ScriptCode.cs | 84 ++++++++++++++----------------------- NovacoinTest/NovacoinTest.csproj | 45 ++++++++++++++++++++ 16 files changed, 281 insertions(+), 210 deletions(-) diff --git a/Novacoin/AddressTools.cs b/Novacoin/AddressTools.cs index c0073fe..9ca95b4 100644 --- a/Novacoin/AddressTools.cs +++ b/Novacoin/AddressTools.cs @@ -6,6 +6,7 @@ using Org.BouncyCastle.Math; namespace Novacoin { + [Serializable] public class Base58Exception : Exception { public Base58Exception() diff --git a/Novacoin/ByteQueue.cs b/Novacoin/ByteQueue.cs index 5513a5d..11601bb 100644 --- a/Novacoin/ByteQueue.cs +++ b/Novacoin/ByteQueue.cs @@ -18,9 +18,11 @@ using System; using System.Collections.Generic; +using System.Diagnostics.Contracts; namespace Novacoin { + [Serializable] public class ByteQueueException : Exception { public ByteQueueException() @@ -40,69 +42,63 @@ namespace Novacoin public class ByteQueue { - private int Index; - private List Elements; + private int _Index; + private List _Elements; public ByteQueue(byte[] List, int Start) { - Elements = new List(List); - Index = Start; + _Elements = new List(List); + _Index = Start; } public ByteQueue(byte[] List) { - Elements = new List(List); - Index = 0; + _Elements = new List(List); + _Index = 0; } public ByteQueue(List List, int Start) { - Elements = new List(List); - Index = Start; + _Elements = new List(List); + _Index = Start; } public ByteQueue(List List) { - Elements = new List(List); - Index = 0; + _Elements = new List(List); + _Index = 0; } public byte Get() { - if (Elements.Count <= Index) + if (_Elements.Count <= _Index) { throw new ByteQueueException("No elements left."); } - return Elements[Index++]; + return _Elements[_Index++]; } public byte GetCurrent() { - return Elements[Index]; + return _Elements[_Index]; } - public byte[] Get(int Count) + public byte[] Get(int nCount) { - if (Elements.Count - Index < Count) - { - throw new ByteQueueException("Unable to read requested amount of data."); - } + Contract.Requires(Count - Index >= nCount, "nCount is greater than amount of elements."); - var result = Elements.GetRange(Index, Count).ToArray(); - Index += Count; + var result = _Elements.GetRange(_Index, nCount).ToArray(); + _Index += nCount; return result; } - public byte[] GetCurrent(int Count) + public byte[] GetCurrent(int nCount) { - if (Elements.Count - Index < Count) - { - throw new ByteQueueException("Unable to read requested amount of data."); - } + Contract.Requires(Count - Index >= nCount, "nCount is greater than amount of elements."); - var result = Elements.GetRange(Index, Count).ToArray(); + var result = _Elements.GetRange(_Index, nCount).ToArray(); return result; } @@ -110,9 +106,14 @@ namespace Novacoin /// /// Current index value /// - public int CurrentIndex + public int Index + { + get { return _Index; } + } + + public int Count { - get { return Index; } + get { return _Elements.Count; } } public ulong GetVarInt() diff --git a/Novacoin/CBlockHeader.cs b/Novacoin/CBlockHeader.cs index d7c1dc6..b9c9a4c 100644 --- a/Novacoin/CBlockHeader.cs +++ b/Novacoin/CBlockHeader.cs @@ -19,6 +19,7 @@ using System; using System.Text; using System.Collections.Generic; +using System.Diagnostics.Contracts; namespace Novacoin { @@ -76,6 +77,8 @@ namespace Novacoin public CBlockHeader(byte[] bytes) { + Contract.Requires(bytes.Length == 80, "Any valid block header is exactly 80 bytes long."); + nVersion = BitConverter.ToUInt32(bytes, 0); prevHash = new Hash256(bytes, 4); merkleRoot = new Hash256(bytes, 36); diff --git a/Novacoin/CKeyID.cs b/Novacoin/CKeyID.cs index ea8e561..d7130a8 100644 --- a/Novacoin/CKeyID.cs +++ b/Novacoin/CKeyID.cs @@ -1,20 +1,23 @@ /** - * Novacoin classes library - * Copyright (C) 2015 Alex D. (balthazar.ad@gmail.com) +* Novacoin classes library +* Copyright (C) 2015 Alex D. (balthazar.ad@gmail.com) - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +*/ + +using System; +using System.Diagnostics.Contracts; namespace Novacoin { @@ -27,6 +30,8 @@ namespace Novacoin internal CKeyID(byte[] hashBytes) { + Contract.Requires(hashBytes.Length == 20, "Your data doesn't seem like a hash160 of some value."); + _hashBytes = hashBytes; } diff --git a/Novacoin/CKeyPair.cs b/Novacoin/CKeyPair.cs index adecb9b..a1d50a8 100644 --- a/Novacoin/CKeyPair.cs +++ b/Novacoin/CKeyPair.cs @@ -16,7 +16,6 @@ * along with this program. If not, see . */ -using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Generators; using System.Security.Cryptography; @@ -27,21 +26,20 @@ using Org.BouncyCastle.Security; using System.Collections.Generic; using System.Linq; using System; +using System.Diagnostics.Contracts; namespace Novacoin { + public class CKeyPair : CKey { private ECPrivateKeyParameters _Private; - private RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); /// /// Initialize new CKeyPair instance with random secret. /// public CKeyPair(bool Compressed = true) { - - var genParams = new ECKeyGenerationParameters(domain, new SecureRandom()); var generator = new ECKeyPairGenerator("ECDSA"); generator.Init(genParams); @@ -50,29 +48,6 @@ namespace Novacoin _Private = (ECPrivateKeyParameters)ecKeyPair.Private; _Public = (ECPublicKeyParameters)ecKeyPair.Public; - /* - BigInteger D; - var buffer1 = new byte[32]; - var buffer2 = new byte[32]; - - do - { - rng.GetBytes(buffer1); - rng.GetNonZeroBytes(buffer2); - - D = new BigInteger(Hash256.ComputeRaw256(ref buffer1, ref buffer2)); - - if (D.BitLength < 249) - System.Console.WriteLine(D.BitLength); - } - while (D.SignValue == -1); - - var Q = curve.G.Multiply(D); - - _Private = new ECPrivateKeyParameters(D, domain); - _Public = new ECPublicKeyParameters(Q, domain); - */ - if (Compressed) { _Public = Compress(_Public); @@ -86,10 +61,7 @@ namespace Novacoin /// Compression flag public CKeyPair(byte[] secretBytes, bool Compressed=true) { - if (secretBytes.Length != 32) - { - throw new ArgumentException("Serialized secret key must be 32 bytes long."); - } + Contract.Requires(secretBytes.Length == 32, "Serialized secret key must be 32 bytes long."); // Deserialize secret value var D = new BigInteger(secretBytes); @@ -127,7 +99,7 @@ namespace Novacoin { var rawSecretBytes = AddressTools.Base58DecodeCheck(strBase58); - if (rawSecretBytes.Length > 34 || rawSecretBytes.Length < 33) + if (rawSecretBytes.Length != 33 && rawSecretBytes.Length != 34) { throw new ArgumentException("Though you have provided a correct Base58 representation of some data, this data doesn't represent a valid private key."); } diff --git a/Novacoin/CKeyStore.cs b/Novacoin/CKeyStore.cs index 8d6ab98..ac7d811 100644 --- a/Novacoin/CKeyStore.cs +++ b/Novacoin/CKeyStore.cs @@ -21,6 +21,7 @@ using SQLite.Net; using SQLite.Net.Attributes; using SQLite.Net.Interop; using SQLite.Net.Platform.Generic; +using System; using System.IO; using System.Linq; @@ -106,11 +107,11 @@ namespace Novacoin /// /// Key storage /// - public class CKeyStore + public class CKeyStore : IDisposable { + private bool disposed = false; private object LockObj = new object(); private SQLiteConnection dbConn = null; - private int nKeyPoolSize = 100; /// @@ -139,13 +140,35 @@ namespace Novacoin ~CKeyStore() { - if (dbConn != null) + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (!disposed) { - dbConn.Close(); - dbConn = null; + if (disposing) + { + // Free other state (managed objects). + } + + if (dbConn != null) + { + dbConn.Close(); + dbConn = null; + } + + disposed = true; } } + /// /// Generate keys and insert them to key store. /// diff --git a/Novacoin/CNovacoinAddress.cs b/Novacoin/CNovacoinAddress.cs index bf5321a..c652b22 100644 --- a/Novacoin/CNovacoinAddress.cs +++ b/Novacoin/CNovacoinAddress.cs @@ -1,23 +1,25 @@ /** - * Novacoin classes library - * Copyright (C) 2015 Alex D. (balthazar.ad@gmail.com) +* Novacoin classes library +* Copyright (C) 2015 Alex D. (balthazar.ad@gmail.com) - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +*/ using System.Collections.Generic; using System.Linq; +using System; +using System.Diagnostics.Contracts; namespace Novacoin { @@ -38,7 +40,7 @@ namespace Novacoin public class CNovacoinAddress { private byte nVersion; - private List addrData; + private byte[] addrData = new byte[20]; /// /// Initialize with custom data and version @@ -47,8 +49,10 @@ namespace Novacoin /// public CNovacoinAddress(byte nVersionIn, byte[] addrDataIn) { + Contract.Requires(addrDataIn.Length == 20, "Your data doesn't look like a valid hash160 of some value."); + nVersion = nVersionIn; - addrData = new List(addrDataIn); + addrDataIn.CopyTo(addrData, 0); } /// @@ -58,15 +62,7 @@ namespace Novacoin public CNovacoinAddress(CKeyID keyID) { nVersion = (byte)AddrType.PUBKEY_ADDRESS; - addrData = new List((byte[])keyID); - } - - public CNovacoinAddress(string strNovacoinAddress) - { - addrData = AddressTools.Base58DecodeCheck(strNovacoinAddress).ToList(); - - nVersion = addrData[0]; - addrData.RemoveAt(0); + addrData = keyID; } /// @@ -76,15 +72,32 @@ namespace Novacoin public CNovacoinAddress(CScriptID scriptID) { nVersion = (byte)AddrType.SCRIPT_ADDRESS; - addrData = new List((byte[])scriptID); + addrData = scriptID; + } + + /// + /// Initialize new instance from base58 string + /// + /// + public CNovacoinAddress(string strNovacoinAddress) + { + var RawAddrData = AddressTools.Base58DecodeCheck(strNovacoinAddress); + + if (RawAddrData.Length != 21) + { + throw new ArgumentException("Though you have provided a correct Base58 representation of some data, this data doesn't represent a valid Novacoin address."); + } + + nVersion = RawAddrData[0]; + Array.Copy(RawAddrData, 1, addrData, 0, 20); } /// /// 20 bytes, Hash160 of script or public key /// - public byte[] HashBytes + public static implicit operator byte[](CNovacoinAddress addr) { - get { return addrData.ToArray(); } + return addr.addrData; } /// @@ -115,7 +128,7 @@ namespace Novacoin return false; } - return addrData.Count == nExpectedSize; + return addrData.Length == nExpectedSize; } } diff --git a/Novacoin/COutPoint.cs b/Novacoin/COutPoint.cs index a8db03d..a65204e 100644 --- a/Novacoin/COutPoint.cs +++ b/Novacoin/COutPoint.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.Contracts; using System.Text; namespace Novacoin @@ -54,6 +55,8 @@ namespace Novacoin public COutPoint(byte[] bytes) { + Contract.Requires(bytes.Length == 36, "Any valid outpoint reference data item is exactly 36 bytes long."); + hash = new Hash256(bytes); n = BitConverter.ToUInt32(bytes, 32); } diff --git a/Novacoin/CPubKey.cs b/Novacoin/CPubKey.cs index 543a261..6d8b2d3 100644 --- a/Novacoin/CPubKey.cs +++ b/Novacoin/CPubKey.cs @@ -52,7 +52,7 @@ namespace Novacoin /// public CPubKey(string strBase58) { - var pQ = curve.Curve.DecodePoint(AddressTools.Base58DecodeCheck(strBase58).ToArray()); + var pQ = curve.Curve.DecodePoint(AddressTools.Base58DecodeCheck(strBase58)); _Public = new ECPublicKeyParameters(pQ, domain); } diff --git a/Novacoin/CScript.cs b/Novacoin/CScript.cs index a9ca8ef..2762f6c 100644 --- a/Novacoin/CScript.cs +++ b/Novacoin/CScript.cs @@ -20,26 +20,10 @@ using System; using System.Linq; using System.Text; using System.Collections.Generic; +using System.Diagnostics.Contracts; namespace Novacoin { - public class CScriptException : Exception - { - public CScriptException() - { - } - - public CScriptException(string message) - : base(message) - { - } - - public CScriptException(string message, Exception inner) - : base(message, inner) - { - } - } - /// /// Representation of script code /// @@ -79,10 +63,7 @@ namespace Novacoin /// public void AddInstruction(instruction opcode) { - if (opcode < instruction.OP_0 || opcode > instruction.OP_INVALIDOPCODE) - { - throw new CScriptException("CScript::AddInstruction() : invalid instruction"); - } + Contract.Requires(opcode >= instruction.OP_0 && opcode <= instruction.OP_INVALIDOPCODE, "Invalid instruction."); codeBytes.Add((byte)opcode); } diff --git a/Novacoin/CScriptID.cs b/Novacoin/CScriptID.cs index c2cbc1f..bd4dea5 100644 --- a/Novacoin/CScriptID.cs +++ b/Novacoin/CScriptID.cs @@ -1,20 +1,23 @@ /** - * Novacoin classes library - * Copyright (C) 2015 Alex D. (balthazar.ad@gmail.com) +* Novacoin classes library +* Copyright (C) 2015 Alex D. (balthazar.ad@gmail.com) - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +*/ + +using System; +using System.Diagnostics.Contracts; namespace Novacoin { @@ -25,6 +28,13 @@ namespace Novacoin _hashBytes = scriptHash; } + internal CScriptID(byte[] hashBytes) + { + Contract.Requires(hashBytes.Length == 20, "Your data doesn't seem like a hash160 of some value."); + + _hashBytes = hashBytes; + } + public override string ToString() { return (new CNovacoinAddress(this)).ToString(); diff --git a/Novacoin/Hash.cs b/Novacoin/Hash.cs index d11f0b0..0a988df 100644 --- a/Novacoin/Hash.cs +++ b/Novacoin/Hash.cs @@ -17,6 +17,7 @@ */ using System; +using System.Diagnostics.Contracts; using System.Linq; namespace Novacoin @@ -50,6 +51,11 @@ namespace Novacoin /// Array of bytes public Hash(byte[] bytes, int offset = 0) { + if (bytes.Length - offset < hashSize) + { + throw new ArgumentException("You need to provide a sufficient amount of data to initialize new instance of hash object."); + } + _hashBytes = new byte[hashSize]; Array.Copy(bytes, offset, _hashBytes, 0, hashSize); } diff --git a/Novacoin/Interop.cs b/Novacoin/Interop.cs index 49481c9..6771afd 100644 --- a/Novacoin/Interop.cs +++ b/Novacoin/Interop.cs @@ -22,23 +22,6 @@ using System.Text; namespace Novacoin { - public class InteropException : Exception - { - public InteropException() - { - } - - public InteropException(string message) - : base(message) - { - } - - public InteropException(string message, Exception inner) - : base(message, inner) - { - } - } - /// /// Miscellaneous functions /// diff --git a/Novacoin/Novacoin.csproj b/Novacoin/Novacoin.csproj index 788ff16..57f12c6 100644 --- a/Novacoin/Novacoin.csproj +++ b/Novacoin/Novacoin.csproj @@ -8,6 +8,7 @@ Novacoin Novacoin v4.5 + 1 true @@ -18,6 +19,50 @@ prompt 4 false + true + True + False + True + False + False + False + True + True + True + True + True + True + True + True + False + True + False + True + False + False + False + False + True + False + True + True + True + False + False + + + + + + + + True + False + False + True + Full + %28none%29 + 0 full diff --git a/Novacoin/ScriptCode.cs b/Novacoin/ScriptCode.cs index 52c36f7..7a0f105 100644 --- a/Novacoin/ScriptCode.cs +++ b/Novacoin/ScriptCode.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.Contracts; using System.Linq; using System.Numerics; using System.Text; @@ -369,23 +370,18 @@ namespace Novacoin /// Small integer public static int DecodeOP_N(instruction opcode, bool AllowNegate = false) { - if (AllowNegate && opcode == instruction.OP_1NEGATE) - { - return -1; - } - - if (opcode == instruction.OP_0) - { - return 0; - } - // Only OP_n instructions are supported, throw exception otherwise. - if (opcode < instruction.OP_1 || opcode > instruction.OP_16) + Contract.Requires((opcode == instruction.OP_1NEGATE && AllowNegate) || (opcode >= instruction.OP_0 && opcode <= instruction.OP_16), "Invalid integer instruction."); + + switch (opcode) { - throw new ArgumentException("Invalid integer instruction."); + case instruction.OP_1NEGATE: + return -1; + case instruction.OP_0: + return 0; + default: + return (int)opcode - (int)(instruction.OP_1 - 1); } - - return (int)opcode - (int)(instruction.OP_1 - 1); } /// @@ -395,20 +391,18 @@ namespace Novacoin /// Corresponding instruction. public static instruction EncodeOP_N(int n, bool allowNegate = false) { - if (allowNegate && n == -1) - { - return instruction.OP_1NEGATE; - } + // The n value must be in the range of 1 to 16. + Contract.Requires((n == -1 && allowNegate) || (n >= 0 && n <= 16), "Invalid integer value."); - if (n == 0) + switch (n) { - return instruction.OP_0; + case -1: + return instruction.OP_1NEGATE; + case 0: + return instruction.OP_0; + default: + return (instruction.OP_1 + n - 1); } - - // The n value must be in the range of 0 to 16. - if (n < 0 || n > 16) - throw new ArgumentException("Invalid integer value."); - return (instruction.OP_1 + n - 1); } public static int ScriptSigArgsExpected(txnouttype t, IList solutions) @@ -478,7 +472,7 @@ namespace Novacoin /// Result public static bool Solver(CScript scriptPubKey, out txnouttype typeRet, out IList solutions) { - var scriptBytes = ((byte[])scriptPubKey); + byte[] scriptBytes = scriptPubKey; solutions = new List(); @@ -562,12 +556,12 @@ namespace Novacoin byte[] args1, args2; - int last1 = ((byte[])script1).Length -1; + int last1 = ((byte[])script1).Length - 1; int last2 = ((byte[])script2).Length - 1; while (true) { - if (bq1.CurrentIndex == last1 && bq2.CurrentIndex == last2) + if (bq1.Index == last1 && bq2.Index == last2) { // Found a match typeRet = templateTuple.Item1; @@ -759,6 +753,7 @@ namespace Novacoin /// /// Script machine exception /// + [Serializable] public class StackMachineException : Exception { public StackMachineException() @@ -784,7 +779,10 @@ namespace Novacoin { int nCount = stack.Count; if (nCount == 0) - throw new StackMachineException("popstack() : stack empty"); + { + throw new StackMachineException("Stack is empty"); + } + stack.RemoveAt(nCount - 1); } @@ -796,25 +794,10 @@ namespace Novacoin /// Byte sequence private static byte[] stacktop(ref List stack, int nDepth) { - int nStackElement = stack.Count + nDepth; - - if (nDepth >= 0) - { - StringBuilder sb = new StringBuilder(); - sb.AppendFormat("stacktop() : positive depth ({0}) has no sense.", nDepth); - - throw new StackMachineException(sb.ToString()); - } + Contract.Requires(nDepth < 0, "Positive stack depth makes no sense."); + Contract.Requires(stack.Count + nDepth > 0, "Value exceeds real stack depth."); - if (nStackElement < 0) - { - StringBuilder sb = new StringBuilder(); - sb.AppendFormat("stacktop() : nDepth={0} exceeds real stack depth ({1})", nDepth, stack.Count); - - throw new StackMachineException(sb.ToString()); - } - - return stack[nStackElement]; + return stack[stack.Count + nDepth]; } /// @@ -848,10 +831,7 @@ namespace Novacoin /// private static BigInteger CastToBigInteger(byte[] value) { - if (value.Length > 4) - { - throw new StackMachineException("CastToBigInteger() : overflow"); - } + Contract.Requires(value.Length <= 4, "Size limit failed."); return new BigInteger(value); } @@ -1558,7 +1538,7 @@ namespace Novacoin case instruction.OP_CODESEPARATOR: { // Hash starts after the code separator - nCodeHashBegin = CodeQueue.CurrentIndex; + nCodeHashBegin = CodeQueue.Index; } break; diff --git a/NovacoinTest/NovacoinTest.csproj b/NovacoinTest/NovacoinTest.csproj index 18fa9b3..1ad2fad 100644 --- a/NovacoinTest/NovacoinTest.csproj +++ b/NovacoinTest/NovacoinTest.csproj @@ -11,6 +11,7 @@ NovacoinTest v4.5 512 + 1 AnyCPU @@ -21,6 +22,50 @@ DEBUG;TRACE prompt 4 + true + True + False + True + False + False + False + True + True + True + True + True + True + True + True + False + True + False + True + False + False + False + False + True + False + True + True + True + False + False + + + + + + + + True + False + False + True + Full + %28none%29 + 0 AnyCPU -- 1.7.1