Skip to content

Commit 5844fd4

Browse files
authored
Neo.VM.3.0.0-CI00243 (neo-project#1821)
1 parent 069b774 commit 5844fd4

File tree

7 files changed

+25
-16
lines changed

7 files changed

+25
-16
lines changed

src/neo/SmartContract/ApplicationEngine.Contract.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private void CallContractInternal(UInt160 contractHash, string method, Array arg
143143
ContractMethodDescriptor md = contract.Manifest.Abi.GetMethod(method);
144144
if (md is null) throw new InvalidOperationException($"Method {method} Does Not Exist In Contract {contractHash}");
145145
if (args.Count != md.Parameters.Length) throw new InvalidOperationException($"Method {method} Expects {md.Parameters.Length} Arguments But Receives {args.Count} Arguments");
146-
ExecutionContext context_new = LoadScript(contract.Script);
146+
ExecutionContext context_new = LoadScript(contract.Script, md.Offset);
147147
state = context_new.GetState<ExecutionContextState>();
148148
state.CallingScriptHash = callingScriptHash;
149149
state.CallFlags = flags & callingFlags;
@@ -157,11 +157,10 @@ private void CallContractInternal(UInt160 contractHash, string method, Array arg
157157
{
158158
for (int i = args.Count - 1; i >= 0; i--)
159159
context_new.EvaluationStack.Push(args[i]);
160-
context_new.InstructionPointer = md.Offset;
161160
}
162161

163162
md = contract.Manifest.Abi.GetMethod("_initialize");
164-
if (md != null) LoadClonedContext(md.Offset);
163+
if (md != null) LoadContext(context_new.Clone(md.Offset));
165164
}
166165

167166
protected internal bool IsStandardContract(UInt160 hash)

src/neo/SmartContract/ApplicationEngine.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,16 @@ protected override void LoadContext(ExecutionContext context)
139139
base.LoadContext(context);
140140
}
141141

142-
internal void LoadContext(ExecutionContext context, int initialPosition)
142+
internal void LoadContext(ExecutionContext context, bool checkReturnValue)
143143
{
144-
GetInvocationState(CurrentContext).NeedCheckReturnValue = true;
145-
context.InstructionPointer = initialPosition;
144+
if (checkReturnValue)
145+
GetInvocationState(CurrentContext).NeedCheckReturnValue = true;
146146
LoadContext(context);
147147
}
148148

149-
public ExecutionContext LoadScript(Script script, CallFlags callFlags)
149+
public ExecutionContext LoadScript(Script script, CallFlags callFlags, int initialPosition = 0)
150150
{
151-
ExecutionContext context = LoadScript(script);
151+
ExecutionContext context = LoadScript(script, initialPosition);
152152
context.GetState<ExecutionContextState>().CallFlags = callFlags;
153153
return context;
154154
}
@@ -298,7 +298,7 @@ public static ApplicationEngine Run(byte[] script, StoreView snapshot = null, IV
298298
snapshot.PersistingBlock = persistingBlock ?? snapshot.PersistingBlock ?? CreateDummyBlock(snapshot);
299299
ApplicationEngine engine = Create(TriggerType.Application, container, snapshot, gas);
300300
if (disposable != null) engine.Disposables.Add(disposable);
301-
engine.LoadScript(script).InstructionPointer = offset;
301+
engine.LoadScript(script, offset);
302302
engine.Execute();
303303
return engine;
304304
}

src/neo/SmartContract/Callbacks/PointerCallback.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public PointerCallback(ExecutionContext context, Pointer pointer, int parameters
1919

2020
public override void LoadContext(ApplicationEngine engine, Array args)
2121
{
22-
engine.LoadContext(context.Clone(), pointer);
22+
engine.LoadContext(context.Clone(pointer), true);
2323
for (int i = args.Count - 1; i >= 0; i--)
2424
engine.Push(args[i]);
2525
}

src/neo/SmartContract/Helper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ internal static bool VerifyWitnesses(this IVerifiable verifiable, StoreView snap
166166
}
167167
using (ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, verifiable, snapshot.Clone(), gas))
168168
{
169-
engine.LoadScript(verification, CallFlags.None).InstructionPointer = offset;
170-
if (init != null) engine.LoadClonedContext(init.Offset);
169+
ExecutionContext context = engine.LoadScript(verification, CallFlags.None, offset);
170+
if (init != null) engine.LoadContext(context.Clone(init.Offset), false);
171171
engine.LoadScript(verifiable.Witnesses[i].InvocationScript, CallFlags.None);
172172
if (engine.Execute() == VMState.FAULT) return false;
173173
if (engine.ResultStack.Count != 1 || !engine.ResultStack.Pop().GetBoolean()) return false;

src/neo/Wallets/Wallet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,8 @@ public long CalculateNetworkFee(StoreView snapshot, Transaction tx)
384384
if (verify is null) throw new ArgumentException($"The smart contract {contract.ScriptHash} haven't got verify method");
385385
ContractMethodDescriptor init = contract.Manifest.Abi.GetMethod("_initialize");
386386
using ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, tx, snapshot.Clone());
387-
engine.LoadScript(contract.Script, CallFlags.None).InstructionPointer = verify.Offset;
388-
if (init != null) engine.LoadClonedContext(init.Offset);
387+
ExecutionContext context = engine.LoadScript(contract.Script, CallFlags.None, verify.Offset);
388+
if (init != null) engine.LoadContext(context.Clone(init.Offset), false);
389389
engine.LoadScript(Array.Empty<byte>(), CallFlags.None);
390390
if (engine.Execute() == VMState.FAULT) throw new ArgumentException($"Smart contract {contract.ScriptHash} verification fault.");
391391
if (engine.ResultStack.Count != 1 || !engine.ResultStack.Pop().GetBoolean()) throw new ArgumentException($"Smart contract {contract.ScriptHash} returns false.");

src/neo/neo.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.2.1" />
2828
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.3" />
2929
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.3" />
30-
<PackageReference Include="Neo.VM" Version="3.0.0-preview3" />
30+
<PackageReference Include="Neo.VM" Version="3.0.0-CI00243" />
3131
</ItemGroup>
3232

3333
</Project>

tests/neo.UnitTests/SmartContract/UT_SmartContractHelper.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Neo.Network.P2P.Payloads;
44
using Neo.SmartContract;
55
using Neo.Wallets;
6+
using System;
67
using System.Linq;
78
using System.Security.Cryptography;
89
using ECPoint = Neo.Cryptography.ECC.ECPoint;
@@ -136,9 +137,18 @@ public void TestVerifyWitnesses()
136137
TrimmedBlock block3 = new TrimmedBlock();
137138
block3.NextConsensus = UInt160.Zero;
138139
snapshot3.Blocks.Add(index3, block3);
139-
Header header3 = new Header() { PrevHash = index3, Witness = new Witness { VerificationScript = new byte[0] } };
140+
Header header3 = new Header()
141+
{
142+
PrevHash = index3,
143+
Witness = new Witness
144+
{
145+
InvocationScript = Array.Empty<byte>(),
146+
VerificationScript = Array.Empty<byte>()
147+
}
148+
};
140149
snapshot3.Contracts.Add(UInt160.Zero, new ContractState()
141150
{
151+
Script = Array.Empty<byte>(),
142152
Manifest = TestUtils.CreateManifest(UInt160.Zero, "verify", ContractParameterType.Boolean, ContractParameterType.Signature),
143153
});
144154
Assert.AreEqual(false, Neo.SmartContract.Helper.VerifyWitnesses(header3, snapshot3, 100));

0 commit comments

Comments
 (0)