Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tx reverify #1116

Merged
merged 14 commits into from
Sep 26, 2019
28 changes: 28 additions & 0 deletions neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
1 change: 1 addition & 0 deletions neo/Network/P2P/Payloads/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public virtual bool Reverify(Snapshot snapshot, IEnumerable<Transaction> 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;
Expand Down