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

Add more VerifyResult states #2549

Merged
merged 7 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/neo/Ledger/VerifyResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ public enum VerifyResult : byte
/// </summary>
Invalid,

/// <summary>
/// Indicates that the <see cref="Transaction"/> has an invalid script.
/// </summary>
InvalidScript,

/// <summary>
/// Indicates that the <see cref="Transaction"/> has an invalid attribute.
/// </summary>
InvalidAttribute,

/// <summary>
/// Indicates that the <see cref="IInventory"/> has an invalid signature.
/// </summary>
InvalidSignature,

/// <summary>
/// Indicates that the size of the <see cref="IInventory"/> is not allowed.
/// </summary>
OverSize,

/// <summary>
/// Indicates that the <see cref="Transaction"/> has expired.
/// </summary>
Expand Down
10 changes: 5 additions & 5 deletions src/neo/Network/P2P/Payloads/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public virtual VerifyResult VerifyStateDependent(ProtocolSettings settings, Data
if (!(context?.CheckTransaction(this, snapshot) ?? true)) return VerifyResult.InsufficientFunds;
foreach (TransactionAttribute attribute in Attributes)
if (!attribute.Verify(snapshot, this))
return VerifyResult.Invalid;
return VerifyResult.InvalidAttribute;
long net_fee = NetworkFee - Size * NativeContract.Policy.GetFeePerByte(snapshot);
if (net_fee < 0) return VerifyResult.InsufficientFunds;

Expand Down Expand Up @@ -396,14 +396,14 @@ public virtual VerifyResult VerifyStateDependent(ProtocolSettings settings, Data
/// <returns>The result of the verification.</returns>
public virtual VerifyResult VerifyStateIndependent(ProtocolSettings settings)
{
if (Size > MaxTransactionSize) return VerifyResult.Invalid;
if (Size > MaxTransactionSize) return VerifyResult.OverSize;
try
{
_ = new Script(Script, true);
}
catch (BadScriptException)
{
return VerifyResult.Invalid;
return VerifyResult.InvalidScript;
}
UInt160[] hashes = GetScriptHashesForVerifying(null);
for (int i = 0; i < hashes.Length; i++)
Expand All @@ -415,7 +415,7 @@ public virtual VerifyResult VerifyStateIndependent(ProtocolSettings settings)
try
{
if (!Crypto.VerifySignature(this.GetSignData(settings.Network), witnesses[i].InvocationScript.AsSpan(2), pubkey, ECCurve.Secp256r1))
return VerifyResult.Invalid;
return VerifyResult.InvalidSignature;
}
catch
{
Expand All @@ -437,7 +437,7 @@ public virtual VerifyResult VerifyStateIndependent(ProtocolSettings settings)
x++;
y++;
if (m - x > n - y)
return VerifyResult.Invalid;
return VerifyResult.InvalidSignature;
}
}
catch
Expand Down
2 changes: 1 addition & 1 deletion tests/neo.UnitTests/Network/P2P/Payloads/UT_Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ public void Test_VerifyStateIndependent()
}
}
};
tx.VerifyStateIndependent(ProtocolSettings.Default).Should().Be(VerifyResult.Invalid);
tx.VerifyStateIndependent(ProtocolSettings.Default).Should().Be(VerifyResult.OverSize);
tx.Script = Array.Empty<byte>();
tx.VerifyStateIndependent(ProtocolSettings.Default).Should().Be(VerifyResult.Succeed);

Expand Down