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

Check witnesses on isStandard #1754

Merged
merged 8 commits into from
Jul 8, 2020
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
23 changes: 22 additions & 1 deletion src/neo/SmartContract/ApplicationEngine.Contract.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Neo.Cryptography.ECC;
using Neo.IO;
using Neo.Ledger;
using Neo.Network.P2P.Payloads;
using Neo.SmartContract.Manifest;
using Neo.SmartContract.Native;
using Neo.VM;
Expand Down Expand Up @@ -164,7 +165,27 @@ private void CallContractInternal(UInt160 contractHash, string method, Array arg
internal bool IsStandardContract(UInt160 hash)
{
ContractState contract = Snapshot.Contracts.TryGet(hash);
return contract is null || contract.Script.IsStandardContract();

// It's a stored contract

if (contract != null) return contract.Script.IsStandardContract();

// Try to find it in the transaction

if (ScriptContainer is Transaction tx)
{
foreach (var witness in tx.Witnesses)
{
if (witness.ScriptHash == hash)
{
return witness.VerificationScript.IsStandardContract();
}
}
}

// It's not possible to determine if it's standard

return false;
}

internal CallFlags GetCallFlags()
Expand Down
7 changes: 6 additions & 1 deletion tests/neo.UnitTests/SmartContract/UT_InteropService.NEO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,19 @@ public void TestAccount_IsStandard()
0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01 };
engine.IsStandardContract(new UInt160(hash)).Should().BeTrue();
engine.IsStandardContract(new UInt160(hash)).Should().BeFalse();

var snapshot = Blockchain.Singleton.GetSnapshot();
var state = TestUtils.GetContract();
snapshot.Contracts.Add(state.ScriptHash, state);
engine = new ApplicationEngine(TriggerType.Application, null, snapshot, 0, true);
engine.LoadScript(new byte[] { 0x01 });
engine.IsStandardContract(state.ScriptHash).Should().BeFalse();

state.Script = Contract.CreateSignatureRedeemScript(Blockchain.StandbyValidators[0]);
engine = new ApplicationEngine(TriggerType.Application, null, snapshot, 0, true);
engine.LoadScript(new byte[] { 0x01 });
engine.IsStandardContract(state.ScriptHash).Should().BeTrue();
}

[TestMethod]
Expand Down