Skip to content

Commit

Permalink
Check witnesses on isStandard (neo-project#1754)
Browse files Browse the repository at this point in the history
* Check witness on isStandard

* Add IsDeployed

* Add IsPayable

* Fix UT

* format

* Add coverage

* Remove IsPayable, IsDeployed
  • Loading branch information
shargon authored Jul 8, 2020
1 parent 699a28c commit 5952ad2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
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

0 comments on commit 5952ad2

Please sign in to comment.