Skip to content

Commit

Permalink
Fix tx reverify (neo-project#1116)
Browse files Browse the repository at this point in the history
* add internal to DB and WriteBatch

* tx.reverify add hashes.length != witnesses.length condition

* reset db.cs writebatch.cs

* format
  • Loading branch information
Tommo-L committed Jun 22, 2020
1 parent cee078e commit 3a4327b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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

0 comments on commit 3a4327b

Please sign in to comment.