Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Compressed BigInteger format #171

Closed
Closed
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
4 changes: 2 additions & 2 deletions src/neo-vm/ExecutionEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/neo-vm/OpCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public enum OpCode : byte
{
// Constants
/// <summary>
/// An empty array of bytes is pushed onto the stack.
/// Integer value zero is pushed onto the stack.
/// </summary>
PUSH0 = 0x00,
PUSHF = PUSH0,
Expand Down
2 changes: 1 addition & 1 deletion src/neo-vm/Types/Integer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/neo-vm.Tests/Tests/OpCodes/Arrays/PICKITEM.json
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,8 @@
"evaluationStack":
[
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
},
{
"type": "ByteArray",
Expand Down
8 changes: 4 additions & 4 deletions tests/neo-vm.Tests/Tests/OpCodes/Arrays/REMOVE.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@
"evaluationStack":
[
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
},
{
"type": "Array",
Expand Down Expand Up @@ -266,8 +266,8 @@
"evaluationStack":
[
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
},
{
"type": "Struct",
Expand Down
24 changes: 12 additions & 12 deletions tests/neo-vm.Tests/Tests/OpCodes/Arrays/SETITEM.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"evaluationStack":
[
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
},
{
"type": "Map",
Expand Down Expand Up @@ -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
}
]
}
Expand Down Expand Up @@ -311,8 +311,8 @@
"value": 5
},
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
},
{
"type": "Array",
Expand Down Expand Up @@ -423,8 +423,8 @@
"value": 5
},
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
},
{
"type": "Struct",
Expand Down
20 changes: 10 additions & 10 deletions tests/neo-vm.Tests/Tests/OpCodes/Numeric/SHL.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"value": "0x0101"
},
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
}
]
}
Expand All @@ -53,8 +53,8 @@
"evaluationStack":
[
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
}
]
}
Expand Down Expand Up @@ -89,8 +89,8 @@
"value": "0xFFFE"
},
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
}
]
}
Expand All @@ -113,8 +113,8 @@
"evaluationStack":
[
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
}
]
}
Expand Down Expand Up @@ -149,8 +149,8 @@
"value": "0x0001"
},
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
}
]
}
Expand Down
20 changes: 10 additions & 10 deletions tests/neo-vm.Tests/Tests/OpCodes/Numeric/SHR.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"value": "0x0101"
},
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
}
]
}
Expand All @@ -53,8 +53,8 @@
"evaluationStack":
[
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
}
]
}
Expand Down Expand Up @@ -89,8 +89,8 @@
"value": "0xFFFE"
},
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
}
]
}
Expand All @@ -113,8 +113,8 @@
"evaluationStack":
[
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
}
]
}
Expand Down Expand Up @@ -149,8 +149,8 @@
"value": "0x0001"
},
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
}
]
}
Expand Down
8 changes: 4 additions & 4 deletions tests/neo-vm.Tests/Tests/OpCodes/Push/PUSHM1_to_PUSH16.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@
"value": 1
},
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
},
{
"type": "Integer",
Expand Down Expand Up @@ -191,8 +191,8 @@
"value": 1
},
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
},
{
"type": "Integer",
Expand Down
61 changes: 57 additions & 4 deletions tests/neo-vm.Tests/Tests/OpCodes/Splice/CAT.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
]
},
{
"name": "Wrong type [Map,ByteArray]",
"name": "Wrong type [Map,Integer]",
"script": "0x00C77E",
"steps":
[
Expand All @@ -52,8 +52,8 @@
"evaluationStack":
[
{
"type": "ByteArray",
"value": ""
"type": "Integer",
"value": 0
}
]
}
Expand All @@ -63,7 +63,7 @@
]
},
{
"name": "Wrong type [ByteArray,Map]",
"name": "Wrong type [Integer,Map]",
"script": "0xC7007E",
"steps":
[
Expand Down Expand Up @@ -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": ""
}
]
}
}
]
}
]
}
Loading