From 3a96e254d89f4e73d3d530e1bda485bed01db2dc Mon Sep 17 00:00:00 2001 From: Igor Machado Date: Thu, 13 Jun 2019 11:54:19 -0300 Subject: [PATCH 1/3] PUSH0 -> Integer(0) --- src/neo-vm/ExecutionEngine.cs | 4 +- src/neo-vm/Types/Integer.cs | 2 +- .../Tests/OpCodes/Arrays/PICKITEM.json | 4 +- .../Tests/OpCodes/Arrays/REMOVE.json | 8 +-- .../Tests/OpCodes/Arrays/SETITEM.json | 24 +++---- .../Tests/OpCodes/Numeric/SHL.json | 20 +++--- .../Tests/OpCodes/Numeric/SHR.json | 20 +++--- .../Tests/OpCodes/Push/PUSHM1_to_PUSH16.json | 8 +-- .../Tests/OpCodes/Splice/CAT.json | 8 +-- .../Tests/OpCodes/Splice/SUBSTR.json | 65 +++++++++---------- .../neo-vm.Tests/Tests/OpCodes/Stack/NIP.json | 4 +- .../Tests/OpCodes/Stack/OVER.json | 8 +-- .../neo-vm.Tests/Tests/OpCodes/Stack/ROT.json | 8 +-- .../Tests/OpCodes/Stack/SWAP.json | 8 +-- .../Tests/OpCodes/Stack/XSWAP.json | 4 +- .../Tests/Others/ScriptLogic.json | 4 +- 16 files changed, 99 insertions(+), 100 deletions(-) diff --git a/src/neo-vm/ExecutionEngine.cs b/src/neo-vm/ExecutionEngine.cs index b8f519d2..61fc9b6d 100644 --- a/src/neo-vm/ExecutionEngine.cs +++ b/src/neo-vm/ExecutionEngine.cs @@ -219,7 +219,7 @@ private bool ExecuteInstruction() // Push value case OpCode.PUSH0: { - context.EvaluationStack.Push(EmptyBytes); + context.EvaluationStack.Push(new Integer(0)); if (!CheckStackSize(true)) return false; break; } @@ -241,7 +241,7 @@ private bool ExecuteInstruction() case OpCode.PUSH15: case OpCode.PUSH16: { - context.EvaluationStack.Push((int)instruction.OpCode - (int)OpCode.PUSH1 + 1); + context.EvaluationStack.Push(new Integer((int)instruction.OpCode - (int)OpCode.PUSH1 + 1)); if (!CheckStackSize(true)) return false; break; } diff --git a/src/neo-vm/Types/Integer.cs b/src/neo-vm/Types/Integer.cs index b3f91ca0..a1792757 100644 --- a/src/neo-vm/Types/Integer.cs +++ b/src/neo-vm/Types/Integer.cs @@ -41,7 +41,7 @@ public override bool GetBoolean() public override byte[] GetByteArray() { - return value.ToByteArray(); + return value.IsZero ? new byte[0] : value.ToByteArray(); } private int _length = -1; diff --git a/tests/neo-vm.Tests/Tests/OpCodes/Arrays/PICKITEM.json b/tests/neo-vm.Tests/Tests/OpCodes/Arrays/PICKITEM.json index a9d6db04..0087ec70 100644 --- a/tests/neo-vm.Tests/Tests/OpCodes/Arrays/PICKITEM.json +++ b/tests/neo-vm.Tests/Tests/OpCodes/Arrays/PICKITEM.json @@ -594,8 +594,8 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { "type": "ByteArray", diff --git a/tests/neo-vm.Tests/Tests/OpCodes/Arrays/REMOVE.json b/tests/neo-vm.Tests/Tests/OpCodes/Arrays/REMOVE.json index a2ac6f9e..ed580085 100644 --- a/tests/neo-vm.Tests/Tests/OpCodes/Arrays/REMOVE.json +++ b/tests/neo-vm.Tests/Tests/OpCodes/Arrays/REMOVE.json @@ -150,8 +150,8 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { "type": "Array", @@ -266,8 +266,8 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { "type": "Struct", diff --git a/tests/neo-vm.Tests/Tests/OpCodes/Arrays/SETITEM.json b/tests/neo-vm.Tests/Tests/OpCodes/Arrays/SETITEM.json index b1745d2b..4200e8d0 100644 --- a/tests/neo-vm.Tests/Tests/OpCodes/Arrays/SETITEM.json +++ b/tests/neo-vm.Tests/Tests/OpCodes/Arrays/SETITEM.json @@ -26,8 +26,8 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { "type": "Map", @@ -93,16 +93,16 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -311,8 +311,8 @@ "value": 5 }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { "type": "Array", @@ -423,8 +423,8 @@ "value": 5 }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { "type": "Struct", diff --git a/tests/neo-vm.Tests/Tests/OpCodes/Numeric/SHL.json b/tests/neo-vm.Tests/Tests/OpCodes/Numeric/SHL.json index b8e7c3d9..84cceceb 100644 --- a/tests/neo-vm.Tests/Tests/OpCodes/Numeric/SHL.json +++ b/tests/neo-vm.Tests/Tests/OpCodes/Numeric/SHL.json @@ -29,8 +29,8 @@ "value": "0x0101" }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -53,8 +53,8 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -89,8 +89,8 @@ "value": "0xFFFE" }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -113,8 +113,8 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -149,8 +149,8 @@ "value": "0x0001" }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } diff --git a/tests/neo-vm.Tests/Tests/OpCodes/Numeric/SHR.json b/tests/neo-vm.Tests/Tests/OpCodes/Numeric/SHR.json index 46a7e902..42327403 100644 --- a/tests/neo-vm.Tests/Tests/OpCodes/Numeric/SHR.json +++ b/tests/neo-vm.Tests/Tests/OpCodes/Numeric/SHR.json @@ -29,8 +29,8 @@ "value": "0x0101" }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -53,8 +53,8 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -89,8 +89,8 @@ "value": "0xFFFE" }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -113,8 +113,8 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -149,8 +149,8 @@ "value": "0x0001" }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } diff --git a/tests/neo-vm.Tests/Tests/OpCodes/Push/PUSHM1_to_PUSH16.json b/tests/neo-vm.Tests/Tests/OpCodes/Push/PUSHM1_to_PUSH16.json index 3b662cb5..ce990ffb 100644 --- a/tests/neo-vm.Tests/Tests/OpCodes/Push/PUSHM1_to_PUSH16.json +++ b/tests/neo-vm.Tests/Tests/OpCodes/Push/PUSHM1_to_PUSH16.json @@ -104,8 +104,8 @@ "value": 1 }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { "type": "Integer", @@ -191,8 +191,8 @@ "value": 1 }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { "type": "Integer", diff --git a/tests/neo-vm.Tests/Tests/OpCodes/Splice/CAT.json b/tests/neo-vm.Tests/Tests/OpCodes/Splice/CAT.json index cc8e7cb5..640e32a7 100644 --- a/tests/neo-vm.Tests/Tests/OpCodes/Splice/CAT.json +++ b/tests/neo-vm.Tests/Tests/OpCodes/Splice/CAT.json @@ -30,7 +30,7 @@ ] }, { - "name": "Wrong type [Map,ByteArray]", + "name": "Wrong type [Map,Integer]", "script": "0x00C77E", "steps": [ @@ -52,8 +52,8 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -63,7 +63,7 @@ ] }, { - "name": "Wrong type [ByteArray,Map]", + "name": "Wrong type [Integer,Map]", "script": "0xC7007E", "steps": [ diff --git a/tests/neo-vm.Tests/Tests/OpCodes/Splice/SUBSTR.json b/tests/neo-vm.Tests/Tests/OpCodes/Splice/SUBSTR.json index fc2f055a..04c99ce6 100644 --- a/tests/neo-vm.Tests/Tests/OpCodes/Splice/SUBSTR.json +++ b/tests/neo-vm.Tests/Tests/OpCodes/Splice/SUBSTR.json @@ -83,12 +83,12 @@ "value": -1 }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -111,12 +111,12 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -148,12 +148,12 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { "type": "Map", @@ -217,12 +217,12 @@ } }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -246,12 +246,12 @@ [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -284,19 +284,18 @@ [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { "type": "Map", "value": { - } }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -320,8 +319,8 @@ [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -354,16 +353,16 @@ [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { "type": "Integer", "value": -1 }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -387,8 +386,8 @@ [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } diff --git a/tests/neo-vm.Tests/Tests/OpCodes/Stack/NIP.json b/tests/neo-vm.Tests/Tests/OpCodes/Stack/NIP.json index cf84ca12..b3d6fdeb 100644 --- a/tests/neo-vm.Tests/Tests/OpCodes/Stack/NIP.json +++ b/tests/neo-vm.Tests/Tests/OpCodes/Stack/NIP.json @@ -109,8 +109,8 @@ "value": true }, { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } diff --git a/tests/neo-vm.Tests/Tests/OpCodes/Stack/OVER.json b/tests/neo-vm.Tests/Tests/OpCodes/Stack/OVER.json index bb742cc8..38dbe4c1 100644 --- a/tests/neo-vm.Tests/Tests/OpCodes/Stack/OVER.json +++ b/tests/neo-vm.Tests/Tests/OpCodes/Stack/OVER.json @@ -48,8 +48,8 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -72,8 +72,8 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } diff --git a/tests/neo-vm.Tests/Tests/OpCodes/Stack/ROT.json b/tests/neo-vm.Tests/Tests/OpCodes/Stack/ROT.json index 5ff85c50..f79973ea 100644 --- a/tests/neo-vm.Tests/Tests/OpCodes/Stack/ROT.json +++ b/tests/neo-vm.Tests/Tests/OpCodes/Stack/ROT.json @@ -48,8 +48,8 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -72,8 +72,8 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } diff --git a/tests/neo-vm.Tests/Tests/OpCodes/Stack/SWAP.json b/tests/neo-vm.Tests/Tests/OpCodes/Stack/SWAP.json index bbdb25a9..b1e4c89f 100644 --- a/tests/neo-vm.Tests/Tests/OpCodes/Stack/SWAP.json +++ b/tests/neo-vm.Tests/Tests/OpCodes/Stack/SWAP.json @@ -48,8 +48,8 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } @@ -72,8 +72,8 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } diff --git a/tests/neo-vm.Tests/Tests/OpCodes/Stack/XSWAP.json b/tests/neo-vm.Tests/Tests/OpCodes/Stack/XSWAP.json index d72d4882..1c094e75 100644 --- a/tests/neo-vm.Tests/Tests/OpCodes/Stack/XSWAP.json +++ b/tests/neo-vm.Tests/Tests/OpCodes/Stack/XSWAP.json @@ -391,8 +391,8 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 }, { "type": "Integer", diff --git a/tests/neo-vm.Tests/Tests/Others/ScriptLogic.json b/tests/neo-vm.Tests/Tests/Others/ScriptLogic.json index 578798c7..f1dadea9 100644 --- a/tests/neo-vm.Tests/Tests/Others/ScriptLogic.json +++ b/tests/neo-vm.Tests/Tests/Others/ScriptLogic.json @@ -24,8 +24,8 @@ "evaluationStack": [ { - "type": "ByteArray", - "value": "" + "type": "Integer", + "value": 0 } ] } From 642938126f6cfa0e0cadfce9d28dcc9e0913c0a1 Mon Sep 17 00:00:00 2001 From: Igor Machado Date: Thu, 13 Jun 2019 12:02:20 -0300 Subject: [PATCH 2/3] cat 0 0 test --- .../Tests/OpCodes/Splice/CAT.json | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/neo-vm.Tests/Tests/OpCodes/Splice/CAT.json b/tests/neo-vm.Tests/Tests/OpCodes/Splice/CAT.json index 640e32a7..37a84e6c 100644 --- a/tests/neo-vm.Tests/Tests/OpCodes/Splice/CAT.json +++ b/tests/neo-vm.Tests/Tests/OpCodes/Splice/CAT.json @@ -161,6 +161,59 @@ } } ] + }, + { + "name": "CAT int(0) int(0)", + "script": "0x00007E", + "steps": + [ + { + "actions": + [ + "StepInto", + "StepInto" + ], + "result": + { + "state": "Break", + "invocationStack": + [ + { + "instructionPointer": 2, + "nextInstruction": "CAT", + "evaluationStack": + [ + { + "type": "Integer", + "value": 0 + }, + { + "type": "Integer", + "value": 0 + } + ] + } + ] + } + }, + { + "actions": + [ + "Execute" + ], + "result": + { + "state": "Halt", + "resultStack": + [ + { + "type": "ByteArray", + "value": "" + } + ] + } + } + ] } ] } \ No newline at end of file From 14bd899e97793cbb1bd0afba89fe73a219d65bec Mon Sep 17 00:00:00 2001 From: Igor Machado Date: Thu, 13 Jun 2019 12:15:25 -0300 Subject: [PATCH 3/3] fix comment --- src/neo-vm/OpCode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/neo-vm/OpCode.cs b/src/neo-vm/OpCode.cs index b7258ded..fcbf5e40 100644 --- a/src/neo-vm/OpCode.cs +++ b/src/neo-vm/OpCode.cs @@ -4,7 +4,7 @@ public enum OpCode : byte { // Constants /// - /// An empty array of bytes is pushed onto the stack. + /// Integer value zero is pushed onto the stack. /// PUSH0 = 0x00, PUSHF = PUSH0,