diff --git a/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs b/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs index fc32744b96..74efe64dd2 100644 --- a/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs +++ b/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs @@ -774,6 +774,34 @@ public void FeeIsSignatureContract_TestScope_NoScopeFAULT() } } + [TestMethod] + public void Transaction_Reverify_Hashes_Length_Unequal_To_Witnesses_Length() + { + var snapshot = store.GetSnapshot(); + Transaction txSimple = new Transaction + { + Version = 0x00, + Nonce = 0x01020304, + Sender = UInt160.Zero, + SystemFee = (long)BigInteger.Pow(10, 8), // 1 GAS + NetworkFee = 0x0000000000000001, + ValidUntilBlock = 0x01020304, + Attributes = new TransactionAttribute[0] { }, + Cosigners = new Cosigner[] { + new Cosigner + { + Account = UInt160.Parse("0x0001020304050607080900010203040506070809"), + Scopes = WitnessScope.Global + } + }, + Script = new byte[] { (byte)OpCode.PUSH1 }, + Witnesses = new Witness[0] { } + }; + UInt160[] hashes = txSimple.GetScriptHashesForVerifying(snapshot); + Assert.AreEqual(2, hashes.Length); + Assert.IsFalse(txSimple.Reverify(snapshot, new Transaction[0])); + } + [TestMethod] public void Transaction_Serialize_Deserialize_Simple() { diff --git a/neo/Network/P2P/Payloads/Transaction.cs b/neo/Network/P2P/Payloads/Transaction.cs index a2586e6da2..74fc1ef3c7 100644 --- a/neo/Network/P2P/Payloads/Transaction.cs +++ b/neo/Network/P2P/Payloads/Transaction.cs @@ -140,6 +140,7 @@ public virtual bool Reverify(Snapshot snapshot, IEnumerable mempool fee += mempool.Where(p => p != this && p.Sender.Equals(Sender)).Select(p => (BigInteger)(p.SystemFee + p.NetworkFee)).Sum(); if (balance < fee) return false; UInt160[] hashes = GetScriptHashesForVerifying(snapshot); + if (hashes.Length != Witnesses.Length) return false; for (int i = 0; i < hashes.Length; i++) { if (Witnesses[i].VerificationScript.Length > 0) continue;