From f26303a8fc7686386e4bc513bef0248086881f73 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 24 Jul 2024 00:55:18 +0800 Subject: [PATCH 1/7] check param when calling contracts --- src/Neo/SmartContract/ApplicationEngine.cs | 4 ++++ tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Neo/SmartContract/ApplicationEngine.cs b/src/Neo/SmartContract/ApplicationEngine.cs index 6fd69439ab..375812c474 100644 --- a/src/Neo/SmartContract/ApplicationEngine.cs +++ b/src/Neo/SmartContract/ApplicationEngine.cs @@ -319,7 +319,11 @@ private ExecutionContext CallContractInternal(ContractState contract, ContractMe state.CallingContext = currentContext; for (int i = args.Count - 1; i >= 0; i--) + { + if(!CheckItemType(args[i], method.Parameters[i].Type)) + throw new InvalidOperationException($"Argument {i} type mismatch."); context_new.EvaluationStack.Push(args[i]); + } return context_new; } diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs index b08898aad5..d81511ea19 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_NeoToken.cs @@ -23,6 +23,7 @@ using System; using System.Linq; using System.Numerics; +using System.Reflection; using static Neo.SmartContract.Native.NeoToken; namespace Neo.UnitTests.SmartContract.Native @@ -436,8 +437,8 @@ public void Check_Transfer() // Bad inputs Assert.ThrowsException(() => NativeContract.NEO.Transfer(snapshot, from, to, BigInteger.MinusOne, true, persistingBlock)); - Assert.ThrowsException(() => NativeContract.NEO.Transfer(snapshot, new byte[19], to, BigInteger.One, false, persistingBlock)); - Assert.ThrowsException(() => NativeContract.NEO.Transfer(snapshot, from, new byte[19], BigInteger.One, false, persistingBlock)); + Assert.ThrowsException(() => NativeContract.NEO.Transfer(snapshot, new byte[19], to, BigInteger.One, false, persistingBlock)); + Assert.ThrowsException(() => NativeContract.NEO.Transfer(snapshot, from, new byte[19], BigInteger.One, false, persistingBlock)); // More than balance From ad3352792e0a127e869ce128d88e15b2c5e53cb4 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 24 Jul 2024 07:06:47 +0800 Subject: [PATCH 2/7] check tests --- .../ApplicationEngine.Runtime.cs | 13 ++-- src/Neo/SmartContract/ApplicationEngine.cs | 5 +- .../SmartContract/UT_InteropService.cs | 62 +++++++++---------- 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/Neo/SmartContract/ApplicationEngine.Runtime.cs b/src/Neo/SmartContract/ApplicationEngine.Runtime.cs index e54529f6d1..34db4fe3dd 100644 --- a/src/Neo/SmartContract/ApplicationEngine.Runtime.cs +++ b/src/Neo/SmartContract/ApplicationEngine.Runtime.cs @@ -449,6 +449,7 @@ protected internal Signer[] GetCurrentSigners() private static bool CheckItemType(StackItem item, ContractParameterType type) { StackItemType aType = item.Type; + if (aType == StackItemType.Any) return true; if (aType == StackItemType.Pointer) return false; switch (type) { @@ -459,7 +460,7 @@ private static bool CheckItemType(StackItem item, ContractParameterType type) case ContractParameterType.Integer: return aType == StackItemType.Integer; case ContractParameterType.ByteArray: - return aType is StackItemType.Any or StackItemType.ByteString or StackItemType.Buffer; + return aType is StackItemType.ByteString or StackItemType.Buffer; case ContractParameterType.String: { if (aType is StackItemType.ByteString or StackItemType.Buffer) @@ -474,27 +475,23 @@ private static bool CheckItemType(StackItem item, ContractParameterType type) return false; } case ContractParameterType.Hash160: - if (aType == StackItemType.Any) return true; if (aType != StackItemType.ByteString && aType != StackItemType.Buffer) return false; return item.GetSpan().Length == UInt160.Length; case ContractParameterType.Hash256: - if (aType == StackItemType.Any) return true; if (aType != StackItemType.ByteString && aType != StackItemType.Buffer) return false; return item.GetSpan().Length == UInt256.Length; case ContractParameterType.PublicKey: - if (aType == StackItemType.Any) return true; if (aType != StackItemType.ByteString && aType != StackItemType.Buffer) return false; return item.GetSpan().Length == 33; case ContractParameterType.Signature: - if (aType == StackItemType.Any) return true; if (aType != StackItemType.ByteString && aType != StackItemType.Buffer) return false; return item.GetSpan().Length == 64; case ContractParameterType.Array: - return aType is StackItemType.Any or StackItemType.Array or StackItemType.Struct; + return aType is StackItemType.Array or StackItemType.Struct; case ContractParameterType.Map: - return aType is StackItemType.Any or StackItemType.Map; + return aType is StackItemType.Map; case ContractParameterType.InteropInterface: - return aType is StackItemType.Any or StackItemType.InteropInterface; + return aType is StackItemType.InteropInterface; default: return false; } diff --git a/src/Neo/SmartContract/ApplicationEngine.cs b/src/Neo/SmartContract/ApplicationEngine.cs index 375812c474..ac1ac65f4f 100644 --- a/src/Neo/SmartContract/ApplicationEngine.cs +++ b/src/Neo/SmartContract/ApplicationEngine.cs @@ -320,8 +320,9 @@ private ExecutionContext CallContractInternal(ContractState contract, ContractMe for (int i = args.Count - 1; i >= 0; i--) { - if(!CheckItemType(args[i], method.Parameters[i].Type)) - throw new InvalidOperationException($"Argument {i} type mismatch."); + var a = args[i]; + if(!CheckItemType(a, method.Parameters[i].Type)) + throw new InvalidOperationException($"The type of the argument `{args[i]}` does not match the formal parameter."); context_new.EvaluationStack.Push(args[i]); } diff --git a/tests/Neo.UnitTests/SmartContract/UT_InteropService.cs b/tests/Neo.UnitTests/SmartContract/UT_InteropService.cs index 48203a644a..7f9dc225a7 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_InteropService.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_InteropService.cs @@ -58,28 +58,28 @@ public void Runtime_GetNotifications_Test() snapshot.DeleteContract(scriptHash2); var contract = TestUtils.GetContract(script.ToArray(), TestUtils.CreateManifest("test", ContractParameterType.Any, ContractParameterType.Integer, ContractParameterType.Integer)); - contract.Manifest.Abi.Events = new[] - { + contract.Manifest.Abi.Events = + [ new ContractEventDescriptor { Name = "testEvent2", - Parameters = new[] - { + Parameters = + [ new ContractParameterDefinition { Type = ContractParameterType.Any } - } + ] } - }; - contract.Manifest.Permissions = new ContractPermission[] - { + ]; + contract.Manifest.Permissions = + [ new ContractPermission { Contract = ContractPermissionDescriptor.Create(scriptHash2), - Methods = WildcardContainer.Create(new string[]{"test"}) + Methods = WildcardContainer.Create(["test"]) } - }; + ]; snapshot.AddContract(scriptHash2, contract); } @@ -128,29 +128,29 @@ public void Runtime_GetNotifications_Test() // Execute engine.LoadScript(script.ToArray()); - engine.CurrentContext.GetState().Contract = new() + engine.CurrentContext!.GetState().Contract = new ContractState { - Manifest = new() + Manifest = new ContractManifest { - Abi = new() + Abi = new ContractAbi { - Events = new[] - { + Events = + [ new ContractEventDescriptor { Name = "testEvent1", - Parameters = System.Array.Empty() + Parameters = [] } - } + ] }, - Permissions = new ContractPermission[] - { + Permissions = + [ new ContractPermission { Contract = ContractPermissionDescriptor.Create(scriptHash2), - Methods = WildcardContainer.Create(new string[]{"test"}) + Methods = WildcardContainer.Create(["test"]) } - } + ] } }; var currentScriptHash = engine.EntryScriptHash; @@ -205,29 +205,29 @@ public void Runtime_GetNotifications_Test() // Execute engine.LoadScript(script.ToArray()); - engine.CurrentContext.GetState().Contract = new() + engine.CurrentContext!.GetState().Contract = new() { - Manifest = new() + Manifest = new ContractManifest { - Abi = new() + Abi = new ContractAbi { - Events = new[] - { + Events = + [ new ContractEventDescriptor { Name = "testEvent1", Parameters = System.Array.Empty() } - } + ] }, - Permissions = new ContractPermission[] - { + Permissions = + [ new ContractPermission { Contract = ContractPermissionDescriptor.Create(scriptHash2), - Methods = WildcardContainer.Create(new string[]{"test"}) + Methods = WildcardContainer.Create(["test"]) } - } + ] } }; var currentScriptHash = engine.EntryScriptHash; From c01ac8f5e6bed19f01bc5b4d277f5192da768b66 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 24 Jul 2024 18:11:01 +0800 Subject: [PATCH 3/7] try fix --- src/Neo.VM/ExecutionEngine.cs | 8 +- src/Neo/SmartContract/ApplicationEngine.cs | 2 +- .../SmartContract/UT_InteropService.cs | 108 ------------------ 3 files changed, 5 insertions(+), 113 deletions(-) diff --git a/src/Neo.VM/ExecutionEngine.cs b/src/Neo.VM/ExecutionEngine.cs index bec60c4348..1655452e6a 100644 --- a/src/Neo.VM/ExecutionEngine.cs +++ b/src/Neo.VM/ExecutionEngine.cs @@ -135,14 +135,14 @@ protected internal void ExecuteNext() ExecutionContext context = CurrentContext!; Instruction instruction = context.CurrentInstruction ?? Instruction.RET; PreExecuteInstruction(instruction); -#if VMPERF +// #if VMPERF Console.WriteLine("op:[" + this.CurrentContext.InstructionPointer.ToString("X04") + "]" + this.CurrentContext.CurrentInstruction?.OpCode + " " + this.CurrentContext.EvaluationStack); -#endif +// #endif try { JumpTable[instruction.OpCode](this, instruction); @@ -236,12 +236,12 @@ protected virtual void OnFault(Exception ex) { State = VMState.FAULT; -#if VMPERF +// #if VMPERF if (ex != null) { Console.Error.WriteLine(ex); } -#endif +// #endif } /// diff --git a/src/Neo/SmartContract/ApplicationEngine.cs b/src/Neo/SmartContract/ApplicationEngine.cs index ac1ac65f4f..470431748f 100644 --- a/src/Neo/SmartContract/ApplicationEngine.cs +++ b/src/Neo/SmartContract/ApplicationEngine.cs @@ -321,7 +321,7 @@ private ExecutionContext CallContractInternal(ContractState contract, ContractMe for (int i = args.Count - 1; i >= 0; i--) { var a = args[i]; - if(!CheckItemType(a, method.Parameters[i].Type)) + if (!CheckItemType(a, method.Parameters[i].Type)) throw new InvalidOperationException($"The type of the argument `{args[i]}` does not match the formal parameter."); context_new.EvaluationStack.Push(args[i]); } diff --git a/tests/Neo.UnitTests/SmartContract/UT_InteropService.cs b/tests/Neo.UnitTests/SmartContract/UT_InteropService.cs index 7f9dc225a7..7f33cf4039 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_InteropService.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_InteropService.cs @@ -153,121 +153,13 @@ public void Runtime_GetNotifications_Test() ] } }; - var currentScriptHash = engine.EntryScriptHash; - Assert.AreEqual(VMState.HALT, engine.Execute()); - Assert.AreEqual(1, engine.ResultStack.Count); - Assert.AreEqual(2, engine.Notifications.Count); - - Assert.IsInstanceOfType(engine.ResultStack.Peek(), typeof(VM.Types.Array)); - - var array = (VM.Types.Array)engine.ResultStack.Pop(); - - // Check syscall result - - AssertNotification(array[1], scriptHash2, "testEvent2"); - AssertNotification(array[0], currentScriptHash, "testEvent1"); - - // Check notifications - - Assert.AreEqual(scriptHash2, engine.Notifications[1].ScriptHash); - Assert.AreEqual("testEvent2", engine.Notifications[1].EventName); - - Assert.AreEqual(currentScriptHash, engine.Notifications[0].ScriptHash); - Assert.AreEqual("testEvent1", engine.Notifications[0].EventName); } - - // Script notifications - - using (var engine = ApplicationEngine.Create(TriggerType.Application, null, snapshot, null, ProtocolSettings.Default)) - using (var script = new ScriptBuilder()) - { - // Notification - - script.EmitPush(0); - script.Emit(OpCode.NEWARRAY); - script.EmitPush("testEvent1"); - script.EmitSysCall(ApplicationEngine.System_Runtime_Notify); - - // Call script - - script.EmitDynamicCall(scriptHash2, "test", "testEvent2", 1); - - // Drop return - - script.Emit(OpCode.DROP); - - // Receive all notifications - - script.EmitPush(scriptHash2.ToArray()); - script.EmitSysCall(ApplicationEngine.System_Runtime_GetNotifications); - - // Execute - - engine.LoadScript(script.ToArray()); - engine.CurrentContext!.GetState().Contract = new() - { - Manifest = new ContractManifest - { - Abi = new ContractAbi - { - Events = - [ - new ContractEventDescriptor - { - Name = "testEvent1", - Parameters = System.Array.Empty() - } - ] - }, - Permissions = - [ - new ContractPermission - { - Contract = ContractPermissionDescriptor.Create(scriptHash2), - Methods = WildcardContainer.Create(["test"]) - } - ] - } - }; - var currentScriptHash = engine.EntryScriptHash; - - Assert.AreEqual(VMState.HALT, engine.Execute()); - Assert.AreEqual(1, engine.ResultStack.Count); - Assert.AreEqual(2, engine.Notifications.Count); - - Assert.IsInstanceOfType(engine.ResultStack.Peek(), typeof(VM.Types.Array)); - - var array = (VM.Types.Array)engine.ResultStack.Pop(); - - // Check syscall result - - AssertNotification(array[0], scriptHash2, "testEvent2"); - - // Check notifications - - Assert.AreEqual(scriptHash2, engine.Notifications[1].ScriptHash); - Assert.AreEqual("testEvent2", engine.Notifications[1].EventName); - - Assert.AreEqual(currentScriptHash, engine.Notifications[0].ScriptHash); - Assert.AreEqual("testEvent1", engine.Notifications[0].EventName); - } - // Clean storage snapshot.DeleteContract(scriptHash2); } - private static void AssertNotification(StackItem stackItem, UInt160 scriptHash, string notification) - { - Assert.IsInstanceOfType(stackItem, typeof(VM.Types.Array)); - - var array = (VM.Types.Array)stackItem; - Assert.AreEqual(3, array.Count); - CollectionAssert.AreEqual(scriptHash.ToArray(), array[0].GetSpan().ToArray()); - Assert.AreEqual(notification, array[1].GetString()); - } - [TestMethod] public void TestExecutionEngine_GetScriptContainer() { From 9f394f3766454733c614a6dadd3b425c405a582d Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 26 Jul 2024 02:47:33 +0800 Subject: [PATCH 4/7] revert change to UT --- .../SmartContract/Native/UT_GasToken.cs | 5 +- .../SmartContract/UT_InteropService.cs | 152 +++++++++++++++--- 2 files changed, 133 insertions(+), 24 deletions(-) diff --git a/tests/Neo.UnitTests/SmartContract/Native/UT_GasToken.cs b/tests/Neo.UnitTests/SmartContract/Native/UT_GasToken.cs index ebb66f0dff..635641854c 100644 --- a/tests/Neo.UnitTests/SmartContract/Native/UT_GasToken.cs +++ b/tests/Neo.UnitTests/SmartContract/Native/UT_GasToken.cs @@ -20,6 +20,7 @@ using System; using System.Linq; using System.Numerics; +using System.Reflection; using System.Threading.Tasks; namespace Neo.UnitTests.SmartContract.Native @@ -131,8 +132,8 @@ await Assert.ThrowsExceptionAsync(async () => // Bad inputs Assert.ThrowsException(() => NativeContract.GAS.Transfer(engine.Snapshot, from, to, BigInteger.MinusOne, true, persistingBlock)); - Assert.ThrowsException(() => NativeContract.GAS.Transfer(engine.Snapshot, new byte[19], to, BigInteger.One, false, persistingBlock)); - Assert.ThrowsException(() => NativeContract.GAS.Transfer(engine.Snapshot, from, new byte[19], BigInteger.One, false, persistingBlock)); + Assert.ThrowsException(() => NativeContract.GAS.Transfer(engine.Snapshot, new byte[19], to, BigInteger.One, false, persistingBlock)); + Assert.ThrowsException(() => NativeContract.GAS.Transfer(engine.Snapshot, from, new byte[19], BigInteger.One, false, persistingBlock)); } internal static StorageKey CreateStorageKey(byte prefix, uint key) diff --git a/tests/Neo.UnitTests/SmartContract/UT_InteropService.cs b/tests/Neo.UnitTests/SmartContract/UT_InteropService.cs index 7f33cf4039..ca54c205ff 100644 --- a/tests/Neo.UnitTests/SmartContract/UT_InteropService.cs +++ b/tests/Neo.UnitTests/SmartContract/UT_InteropService.cs @@ -57,29 +57,29 @@ public void Runtime_GetNotifications_Test() scriptHash2 = script.ToArray().ToScriptHash(); snapshot.DeleteContract(scriptHash2); - var contract = TestUtils.GetContract(script.ToArray(), TestUtils.CreateManifest("test", ContractParameterType.Any, ContractParameterType.Integer, ContractParameterType.Integer)); - contract.Manifest.Abi.Events = - [ + var contract = TestUtils.GetContract(script.ToArray(), TestUtils.CreateManifest("test", ContractParameterType.Any, ContractParameterType.String, ContractParameterType.Integer)); + contract.Manifest.Abi.Events = new[] + { new ContractEventDescriptor { Name = "testEvent2", - Parameters = - [ + Parameters = new[] + { new ContractParameterDefinition { Type = ContractParameterType.Any } - ] + } } - ]; - contract.Manifest.Permissions = - [ + }; + contract.Manifest.Permissions = new ContractPermission[] + { new ContractPermission { Contract = ContractPermissionDescriptor.Create(scriptHash2), - Methods = WildcardContainer.Create(["test"]) + Methods = WildcardContainer.Create(new string[]{"test"}) } - ]; + }; snapshot.AddContract(scriptHash2, contract); } @@ -128,38 +128,146 @@ public void Runtime_GetNotifications_Test() // Execute engine.LoadScript(script.ToArray()); - engine.CurrentContext!.GetState().Contract = new ContractState + engine.CurrentContext.GetState().Contract = new() { - Manifest = new ContractManifest + Manifest = new() { - Abi = new ContractAbi + Abi = new() { - Events = - [ + Events = new[] + { new ContractEventDescriptor { Name = "testEvent1", - Parameters = [] + Parameters = System.Array.Empty() } - ] + } }, - Permissions = - [ + Permissions = new ContractPermission[] + { new ContractPermission { Contract = ContractPermissionDescriptor.Create(scriptHash2), - Methods = WildcardContainer.Create(["test"]) + Methods = WildcardContainer.Create(new string[]{"test"}) } - ] + } } }; + var currentScriptHash = engine.EntryScriptHash; + Assert.AreEqual(VMState.HALT, engine.Execute()); + Assert.AreEqual(1, engine.ResultStack.Count); + Assert.AreEqual(2, engine.Notifications.Count); + + Assert.IsInstanceOfType(engine.ResultStack.Peek(), typeof(VM.Types.Array)); + + var array = (VM.Types.Array)engine.ResultStack.Pop(); + + // Check syscall result + + AssertNotification(array[1], scriptHash2, "testEvent2"); + AssertNotification(array[0], currentScriptHash, "testEvent1"); + + // Check notifications + + Assert.AreEqual(scriptHash2, engine.Notifications[1].ScriptHash); + Assert.AreEqual("testEvent2", engine.Notifications[1].EventName); + + Assert.AreEqual(currentScriptHash, engine.Notifications[0].ScriptHash); + Assert.AreEqual("testEvent1", engine.Notifications[0].EventName); } + + // Script notifications + + using (var engine = ApplicationEngine.Create(TriggerType.Application, null, snapshot, null, ProtocolSettings.Default)) + using (var script = new ScriptBuilder()) + { + // Notification + + script.EmitPush(0); + script.Emit(OpCode.NEWARRAY); + script.EmitPush("testEvent1"); + script.EmitSysCall(ApplicationEngine.System_Runtime_Notify); + + // Call script + + script.EmitDynamicCall(scriptHash2, "test", "testEvent2", 1); + + // Drop return + + script.Emit(OpCode.DROP); + + // Receive all notifications + + script.EmitPush(scriptHash2.ToArray()); + script.EmitSysCall(ApplicationEngine.System_Runtime_GetNotifications); + + // Execute + + engine.LoadScript(script.ToArray()); + engine.CurrentContext.GetState().Contract = new() + { + Manifest = new() + { + Abi = new() + { + Events = new[] + { + new ContractEventDescriptor + { + Name = "testEvent1", + Parameters = System.Array.Empty() + } + } + }, + Permissions = new ContractPermission[] + { + new ContractPermission + { + Contract = ContractPermissionDescriptor.Create(scriptHash2), + Methods = WildcardContainer.Create(new string[]{"test"}) + } + } + } + }; + var currentScriptHash = engine.EntryScriptHash; + + Assert.AreEqual(VMState.HALT, engine.Execute()); + Assert.AreEqual(1, engine.ResultStack.Count); + Assert.AreEqual(2, engine.Notifications.Count); + + Assert.IsInstanceOfType(engine.ResultStack.Peek(), typeof(VM.Types.Array)); + + var array = (VM.Types.Array)engine.ResultStack.Pop(); + + // Check syscall result + + AssertNotification(array[0], scriptHash2, "testEvent2"); + + // Check notifications + + Assert.AreEqual(scriptHash2, engine.Notifications[1].ScriptHash); + Assert.AreEqual("testEvent2", engine.Notifications[1].EventName); + + Assert.AreEqual(currentScriptHash, engine.Notifications[0].ScriptHash); + Assert.AreEqual("testEvent1", engine.Notifications[0].EventName); + } + // Clean storage snapshot.DeleteContract(scriptHash2); } + private static void AssertNotification(StackItem stackItem, UInt160 scriptHash, string notification) + { + Assert.IsInstanceOfType(stackItem, typeof(VM.Types.Array)); + + var array = (VM.Types.Array)stackItem; + Assert.AreEqual(3, array.Count); + CollectionAssert.AreEqual(scriptHash.ToArray(), array[0].GetSpan().ToArray()); + Assert.AreEqual(notification, array[1].GetString()); + } + [TestMethod] public void TestExecutionEngine_GetScriptContainer() { From bb6692b7e95c12a74482a7ed223db8cac212012e Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 26 Jul 2024 02:55:50 +0800 Subject: [PATCH 5/7] revert debug --- src/Neo.VM/ExecutionEngine.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Neo.VM/ExecutionEngine.cs b/src/Neo.VM/ExecutionEngine.cs index 1655452e6a..eb99f5ad85 100644 --- a/src/Neo.VM/ExecutionEngine.cs +++ b/src/Neo.VM/ExecutionEngine.cs @@ -135,14 +135,14 @@ protected internal void ExecuteNext() ExecutionContext context = CurrentContext!; Instruction instruction = context.CurrentInstruction ?? Instruction.RET; PreExecuteInstruction(instruction); -// #if VMPERF +#if VMPERF Console.WriteLine("op:[" - + this.CurrentContext.InstructionPointer.ToString("X04") + + CurrentContext.InstructionPointer.ToString("X04") + "]" - + this.CurrentContext.CurrentInstruction?.OpCode + + CurrentContext.CurrentInstruction?.OpCode + " " - + this.CurrentContext.EvaluationStack); -// #endif + + CurrentContext.EvaluationStack); +#endif try { JumpTable[instruction.OpCode](this, instruction); @@ -236,12 +236,12 @@ protected virtual void OnFault(Exception ex) { State = VMState.FAULT; -// #if VMPERF +#if VMPERF if (ex != null) { Console.Error.WriteLine(ex); } -// #endif +#endif } /// From 5aa0d307f03baf10e1065e8067c15dd115e15fbb Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 26 Jul 2024 02:57:14 +0800 Subject: [PATCH 6/7] revert change --- src/Neo.VM/ExecutionEngine.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Neo.VM/ExecutionEngine.cs b/src/Neo.VM/ExecutionEngine.cs index eb99f5ad85..bec60c4348 100644 --- a/src/Neo.VM/ExecutionEngine.cs +++ b/src/Neo.VM/ExecutionEngine.cs @@ -137,11 +137,11 @@ protected internal void ExecuteNext() PreExecuteInstruction(instruction); #if VMPERF Console.WriteLine("op:[" - + CurrentContext.InstructionPointer.ToString("X04") + + this.CurrentContext.InstructionPointer.ToString("X04") + "]" - + CurrentContext.CurrentInstruction?.OpCode + + this.CurrentContext.CurrentInstruction?.OpCode + " " - + CurrentContext.EvaluationStack); + + this.CurrentContext.EvaluationStack); #endif try { From df39d454af78ba871d19ea5b11e80ef14f2a86c3 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Fri, 26 Jul 2024 02:58:26 +0800 Subject: [PATCH 7/7] Update src/Neo/SmartContract/ApplicationEngine.cs --- src/Neo/SmartContract/ApplicationEngine.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Neo/SmartContract/ApplicationEngine.cs b/src/Neo/SmartContract/ApplicationEngine.cs index 470431748f..bc77c29494 100644 --- a/src/Neo/SmartContract/ApplicationEngine.cs +++ b/src/Neo/SmartContract/ApplicationEngine.cs @@ -320,8 +320,7 @@ private ExecutionContext CallContractInternal(ContractState contract, ContractMe for (int i = args.Count - 1; i >= 0; i--) { - var a = args[i]; - if (!CheckItemType(a, method.Parameters[i].Type)) + if (!CheckItemType(args[i], method.Parameters[i].Type)) throw new InvalidOperationException($"The type of the argument `{args[i]}` does not match the formal parameter."); context_new.EvaluationStack.Push(args[i]); }