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

Neo.VM.3.0.0-CI00243 #1821

Merged
merged 7 commits into from
Aug 7, 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
5 changes: 2 additions & 3 deletions src/neo/SmartContract/ApplicationEngine.Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private void CallContractInternal(UInt160 contractHash, string method, Array arg
ContractMethodDescriptor md = contract.Manifest.Abi.GetMethod(method);
if (md is null) throw new InvalidOperationException($"Method {method} Does Not Exist In Contract {contractHash}");
if (args.Count != md.Parameters.Length) throw new InvalidOperationException($"Method {method} Expects {md.Parameters.Length} Arguments But Receives {args.Count} Arguments");
ExecutionContext context_new = LoadScript(contract.Script);
ExecutionContext context_new = LoadScript(contract.Script, md.Offset);
state = context_new.GetState<ExecutionContextState>();
state.CallingScriptHash = callingScriptHash;
state.CallFlags = flags & callingFlags;
Expand All @@ -157,11 +157,10 @@ private void CallContractInternal(UInt160 contractHash, string method, Array arg
{
for (int i = args.Count - 1; i >= 0; i--)
context_new.EvaluationStack.Push(args[i]);
context_new.InstructionPointer = md.Offset;
}

md = contract.Manifest.Abi.GetMethod("_initialize");
if (md != null) LoadClonedContext(md.Offset);
if (md != null) LoadContext(context_new.Clone(md.Offset));
}

protected internal bool IsStandardContract(UInt160 hash)
Expand Down
12 changes: 6 additions & 6 deletions src/neo/SmartContract/ApplicationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,16 @@ protected override void LoadContext(ExecutionContext context)
base.LoadContext(context);
}

internal void LoadContext(ExecutionContext context, int initialPosition)
internal void LoadContext(ExecutionContext context, bool checkReturnValue)
{
GetInvocationState(CurrentContext).NeedCheckReturnValue = true;
context.InstructionPointer = initialPosition;
if (checkReturnValue)
shargon marked this conversation as resolved.
Show resolved Hide resolved
GetInvocationState(CurrentContext).NeedCheckReturnValue = true;
LoadContext(context);
}

public ExecutionContext LoadScript(Script script, CallFlags callFlags)
public ExecutionContext LoadScript(Script script, CallFlags callFlags, int initialPosition = 0)
{
ExecutionContext context = LoadScript(script);
ExecutionContext context = LoadScript(script, initialPosition);
context.GetState<ExecutionContextState>().CallFlags = callFlags;
return context;
}
Expand Down Expand Up @@ -298,7 +298,7 @@ public static ApplicationEngine Run(byte[] script, StoreView snapshot = null, IV
snapshot.PersistingBlock = persistingBlock ?? snapshot.PersistingBlock ?? CreateDummyBlock(snapshot);
ApplicationEngine engine = Create(TriggerType.Application, container, snapshot, gas);
if (disposable != null) engine.Disposables.Add(disposable);
engine.LoadScript(script).InstructionPointer = offset;
engine.LoadScript(script, offset);
engine.Execute();
return engine;
}
Expand Down
2 changes: 1 addition & 1 deletion src/neo/SmartContract/Callbacks/PointerCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public PointerCallback(ExecutionContext context, Pointer pointer, int parameters

public override void LoadContext(ApplicationEngine engine, Array args)
{
engine.LoadContext(context.Clone(), pointer);
engine.LoadContext(context.Clone(pointer), true);
for (int i = args.Count - 1; i >= 0; i--)
engine.Push(args[i]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/neo/SmartContract/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ internal static bool VerifyWitnesses(this IVerifiable verifiable, StoreView snap
}
using (ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, verifiable, snapshot.Clone(), gas))
{
engine.LoadScript(verification, CallFlags.None).InstructionPointer = offset;
if (init != null) engine.LoadClonedContext(init.Offset);
ExecutionContext context = engine.LoadScript(verification, CallFlags.None, offset);
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
4 changes: 2 additions & 2 deletions src/neo/Wallets/Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ public long CalculateNetworkFee(StoreView snapshot, Transaction tx)
if (verify is null) throw new ArgumentException($"The smart contract {contract.ScriptHash} haven't got verify method");
ContractMethodDescriptor init = contract.Manifest.Abi.GetMethod("_initialize");
using ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, tx, snapshot.Clone());
engine.LoadScript(contract.Script, CallFlags.None).InstructionPointer = verify.Offset;
if (init != null) engine.LoadClonedContext(init.Offset);
ExecutionContext context = engine.LoadScript(contract.Script, CallFlags.None, verify.Offset);
if (init != null) engine.LoadContext(context.Clone(init.Offset), false);
engine.LoadScript(Array.Empty<byte>(), CallFlags.None);
if (engine.Execute() == VMState.FAULT) throw new ArgumentException($"Smart contract {contract.ScriptHash} verification fault.");
if (engine.ResultStack.Count != 1 || !engine.ResultStack.Pop().GetBoolean()) throw new ArgumentException($"Smart contract {contract.ScriptHash} returns false.");
Expand Down
2 changes: 1 addition & 1 deletion src/neo/neo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.2.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.3" />
<PackageReference Include="Neo.VM" Version="3.0.0-preview3" />
<PackageReference Include="Neo.VM" Version="3.0.0-CI00243" />
</ItemGroup>

</Project>
12 changes: 11 additions & 1 deletion tests/neo.UnitTests/SmartContract/UT_SmartContractHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Neo.Network.P2P.Payloads;
using Neo.SmartContract;
using Neo.Wallets;
using System;
using System.Linq;
using System.Security.Cryptography;
using ECPoint = Neo.Cryptography.ECC.ECPoint;
Expand Down Expand Up @@ -136,9 +137,18 @@ public void TestVerifyWitnesses()
TrimmedBlock block3 = new TrimmedBlock();
block3.NextConsensus = UInt160.Zero;
snapshot3.Blocks.Add(index3, block3);
Header header3 = new Header() { PrevHash = index3, Witness = new Witness { VerificationScript = new byte[0] } };
Header header3 = new Header()
{
PrevHash = index3,
Witness = new Witness
{
InvocationScript = Array.Empty<byte>(),
VerificationScript = Array.Empty<byte>()
}
};
snapshot3.Contracts.Add(UInt160.Zero, new ContractState()
{
Script = Array.Empty<byte>(),
Manifest = TestUtils.CreateManifest(UInt160.Zero, "verify", ContractParameterType.Boolean, ContractParameterType.Signature),
});
Assert.AreEqual(false, Neo.SmartContract.Helper.VerifyWitnesses(header3, snapshot3, 100));
Expand Down