Skip to content

Commit

Permalink
Fix VerifyWitnesses() of native contracts (neo-project#1998)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang authored and Shawn committed Jan 8, 2021
1 parent 6b5e887 commit 74c1696
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/neo/SmartContract/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Neo.Network.P2P.Payloads;
using Neo.Persistence;
using Neo.SmartContract.Manifest;
using Neo.SmartContract.Native;
using Neo.VM;
using System;
using System.Buffers.Binary;
Expand Down Expand Up @@ -169,14 +170,25 @@ internal static bool VerifyWitnesses(this IVerifiable verifiable, StoreView snap
}
else
{
if (NativeContract.IsNative(hashes[i])) return false;
if (hashes[i] != verifiable.Witnesses[i].ScriptHash) return false;
offset = 0;
}
using (ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, verifiable, snapshot?.Clone(), gas))
{
CallFlags callFlags = verifiable.Witnesses[i].StateDependent ? CallFlags.AllowStates : CallFlags.None;
ExecutionContext context = engine.LoadScript(verification, callFlags, offset);
if (init != null) engine.LoadContext(context.Clone(init.Offset), false);
if (NativeContract.IsNative(hashes[i]))
{
using ScriptBuilder sb = new ScriptBuilder();
sb.Emit(OpCode.DEPTH, OpCode.PACK);
sb.EmitPush("verify");
engine.LoadScript(sb.ToArray(), CallFlags.None);
}
else if (init != null)
{
engine.LoadContext(context.Clone(init.Offset), false);
}
engine.LoadScript(verifiable.Witnesses[i].InvocationScript, CallFlags.None);
if (engine.Execute() == VMState.FAULT) return false;
if (engine.ResultStack.Count != 1 || !engine.ResultStack.Pop().GetBoolean()) return false;
Expand Down

0 comments on commit 74c1696

Please sign in to comment.