Shuffle OpCodes

This commit is contained in:
nicksavers 2014-11-01 02:17:37 +01:00
parent e49dcec705
commit a112183442
6 changed files with 205 additions and 204 deletions

View File

@ -9,65 +9,67 @@ import java.util.Map;
* - Appendix G. Virtual Machine Specification
*/
public enum OpCode {
/** Halts execution (0x00) */
STOP(0x00, 0),
/* Arithmetic Operations */
/** (0x01) Addition operation */
ADD(0x01, 2),
/** (0x02) Multiplication operation */
MUL(0x02, 2),
/** (0x03) Subtraction operations */
SUB(0x03, 2),
/** (0x04) Integer division operation */
DIV(0x04, 2),
/** (0x05) Signed integer division operation*/
SDIV(0x05, 2),
/** (0x06) Modulo remainder operation */
MOD(0x06, 2),
/** (0x07) Signed modulo remainder operation*/
SMOD(0x07, 2),
/** (0x08) Exponential operation */
EXP(0x08, 2),
/** (0x09) Negation operation */
BNOT(0x09, 1),
/** (0x0a) Less-than comparison */
LT(0X0a, 2),
/** (0x0b) Greater-than comparison */
GT(0X0b, 2),
/** (0x0c) Signed less-than comparison */
SLT(0X0c, 2),
/** (0x0d) Signed greater-than comparison */
SGT(0X0d, 2),
/** (0x0e) Equality comparison */
EQ(0X0e, 2),
/** (0x0f) Simple not operator */
NOT(0X0f, 1),
/* Bitwise Logic Operations */
/** (0x10) Bitwise AND operation */
AND(0x10, 2),
/** (0x11) Bitwise OR operation */
OR(0x11, 2),
/** (0x12) Bitwise XOR operation */
XOR(0x12, 2),
/** (0x13) Retrieve single byte from word */
BYTE(0x13, 2),
/** (0x14) Addition combined with modulo
/** Halts execution (0x00) */
STOP(0x00, 0),
/* Arithmetic Operations */
/** (0x01) Addition operation */
ADD(0x01, 2),
/** (0x02) Multiplication operation */
MUL(0x02, 2),
/** (0x03) Subtraction operations */
SUB(0x03, 2),
/** (0x04) Integer division operation */
DIV(0x04, 2),
/** (0x05) Signed integer division operation*/
SDIV(0x05, 2),
/** (0x06) Modulo remainder operation */
MOD(0x06, 2),
/** (0x07) Signed modulo remainder operation*/
SMOD(0x07, 2),
/** (0x08) Addition combined with modulo
* remainder operation */
ADDMOD(0x14, 3),
/** (0x15) Multiplication combined with modulo
ADDMOD(0x08, 3),
/** (0x09) Multiplication combined with modulo
* remainder operation */
MULMOD(0x15, 3),
MULMOD(0x09, 3),
/** (0x0a) Exponential operation */
EXP(0x0a, 2),
/** (0x0b) Extend length of signed integer */
SIGNEXTEND(0x0b, 2),
/* Bitwise Logic & Comparison Operations */
/** (0x10) Less-than comparison */
LT(0X10, 2),
/** (0x11) Greater-than comparison */
GT(0X11, 2),
/** (0x12) Signed less-than comparison */
SLT(0X12, 2),
/** (0x13) Signed greater-than comparison */
SGT(0X13, 2),
/** (0x14) Equality comparison */
EQ(0X14, 2),
/** (0x15) Negation operation */
ISZERO(0x15, 1),
/** (0x16) Bitwise AND operation */
AND(0x16, 2),
/** (0x17) Bitwise OR operation */
OR(0x17, 2),
/** (0x18) Bitwise XOR operation */
XOR(0x18, 2),
/** (0x19) Retrieve single byte from word */
BYTE(0x19, 2),
/** (0x1a) Bitwise NOT operationr */
NOT(0x1a, 1),
/* Cryptographic Operations */
/** (0x20) Compute SHA3-256 hash */
SHA3(0x20, 2),
/* Environmental Information */
/** (0x30) Get address of currently
@ -108,9 +110,8 @@ public enum OpCode {
* environment to memory with given offset */
EXTCODECOPY(0x3c, 4),
/* Block Information */
/** (0x40) Get hash of most recent
* complete block */
PREVHASH(0x40, 0),
@ -124,37 +125,37 @@ public enum OpCode {
DIFFICULTY(0x44, 0),
/** (0x45) Get the blocks gas limit */
GASLIMIT(0x45, 0),
/* Memory, Storage and Flow Operations */
/** (0x50) Remove item from stack */
POP(0x50, 1),
/** (0x53) Load word from memory */
MLOAD(0x53, 1),
/** (0x54) Save word to memory */
MSTORE(0x54, 2),
/** (0x55) Save byte to memory */
MSTORE8(0x55, 2),
/** (0x56) Load word from storage */
SLOAD(0x56, 1),
/** (0x57) Save word to storage */
SSTORE(0x57, 2),
/** (0x58) Alter the program counter */
JUMP(0x58, 1),
/** (0x59) Conditionally alter the program
/** (0x51) Load word from memory */
MLOAD(0x51, 1),
/** (0x52) Save word to memory */
MSTORE(0x52, 2),
/** (0x53) Save byte to memory */
MSTORE8(0x53, 2),
/** (0x54) Load word from storage */
SLOAD(0x54, 1),
/** (0x55) Save word to storage */
SSTORE(0x55, 2),
/** (0x56) Alter the program counter */
JUMP(0x56, 1),
/** (0x57) Conditionally alter the program
* counter */
JUMPI(0x59, 2),
/** (0x5a) Get the program counter */
PC(0x5a, 0),
/** (0x5b) Get the size of active memory */
MSIZE(0x5b, 0),
/** (0x5c) Get the amount of available gas */
GAS(0x5c, 0),
/** (0x5d) */
JUMPDEST(0x5d, 0),
JUMPI(0x57, 2),
/** (0x58) Get the program counter */
PC(0x58, 0),
/** (0x59) Get the size of active memory */
MSIZE(0x59, 0),
/** (0x5a) Get the amount of available gas */
GAS(0x5a, 0),
/** (0x5b) */
JUMPDEST(0x5b, 0),
/* Push Operations */
/** (0x60) Place 1-byte item on stack */
PUSH1(0x60, 0),
/** (0x61) Place 2-byte item on stack */
@ -220,9 +221,9 @@ public enum OpCode {
/** (0x7f) Place 32-byte (full word)
* item on stack */
PUSH32(0x7f, 0),
/* Duplicate Nth item from the stack */
/** (0x80) Duplicate 1st item on stack */
DUP1(0x80, 1),
/** (0x81) Duplicate 2nd item on stack */
@ -255,9 +256,9 @@ public enum OpCode {
DUP15(0x8e, 15),
/** (0x8f) Duplicate 16th item on stack */
DUP16(0x8f, 16),
/* Swap the Nth item from the stack with the top */
/** (0x90) Exchange 2nd item from stack with the top */
SWAP1(0x90, 2),
/** (0x91) Exchange 3rd item from stack with the top */
@ -290,9 +291,9 @@ public enum OpCode {
SWAP15(0x9e, 16),
/** (0x9f) Exchange 17th item from stack with the top */
SWAP16(0x9f, 17),
/* System operations */
/** (0xf0) Create a new account with associated code */
CREATE(0xf0, 3), // [in_size] [in_offs] [gas_val] CREATE
/** (cxf1) Message-call into an account */
@ -305,7 +306,7 @@ public enum OpCode {
/** (0xff) Halt execution and register account for
* later deletion */
SUICIDE(0xff, 1);
private byte opcode;
private int require;

View File

@ -280,7 +280,7 @@ public class VM {
program.stackPush(word1);
program.step();
} break;
case BNOT:{
case NOT:{
DataWord word1 = program.stackPop();
word1.bnot();
@ -374,7 +374,7 @@ public class VM {
program.stackPush(word1);
program.step();
} break;
case NOT: {
case ISZERO: {
DataWord word1 = program.stackPop();
if (word1.isZero()) {
word1.getData()[31] = 1;

View File

@ -15,7 +15,7 @@ public class MachineCompileTest {
public void test1() {
String code = "a=2";
String expected = "6005600c60003960056000f26002600054";
String expected = "6005600c60003960056000f26002600052";
String asm = SerpentCompiler.compile(code);
byte[] machineCode = SerpentCompiler.compileAssemblyToMachine(asm);
byte[] vmReadyCode = SerpentCompiler.encodeMachineCodeForVMRun(machineCode, null);
@ -28,7 +28,7 @@ public class MachineCompileTest {
public void test2() {
String code = "a=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\na=2\n[asm PUSH10 asm]";
String expected = "610100600e6000396101006000f260026000546002600054600260005460026000546002600054600260005460026000546002600054600260005460026000546002600054600260005460026000546002600054600260005460026000546002600054600260005460026000546002600054600260005460026000546002600054600260005460026000546002600054600260005460026000546002600054600260005460026000546002600054600260005460026000546002600054600260005460026000546002600054600260005460026000546002600054600260005460026000546002600054600260005460026000546002600054600260005460026000546002600054600260005469";
String expected = "610100600e6000396101006000f260026000526002600052600260005260026000526002600052600260005260026000526002600052600260005260026000526002600052600260005260026000526002600052600260005260026000526002600052600260005260026000526002600052600260005260026000526002600052600260005260026000526002600052600260005260026000526002600052600260005260026000526002600052600260005260026000526002600052600260005260026000526002600052600260005260026000526002600052600260005260026000526002600052600260005260026000526002600052600260005260026000526002600052600260005269";
String asm = SerpentCompiler.compile(code);
byte[] machineCode = SerpentCompiler.compileAssemblyToMachine(asm);
byte[] vmReadyCode = SerpentCompiler.encodeMachineCodeForVMRun(machineCode, null);

View File

@ -47,7 +47,7 @@ public class VMComplexTest {
// Set contract into Database
String callerAddr = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826";
String contractAddr = "77045e71a7a2c50903d88e564cd72fab11e82051";
String code = "6103e75660005460006000530b0f630000004c596001600053036103e757600060006000600060007377045e71a7a2c50903d88e564cd72fab11e820516008600a5c0402f1630000004c585d00";
String code = "6103e75460005260006000511115630000004c576001600051036103e755600060006000600060007377045e71a7a2c50903d88e564cd72fab11e820516008600a5a0402f1630000004c565b00";
byte[] contractAddrB = Hex.decode(contractAddr);
byte[] callerAddrB = Hex.decode(callerAddr);
@ -124,8 +124,8 @@ public class VMComplexTest {
String contractA_addr = "77045e71a7a2c50903d88e564cd72fab11e82051";
String contractB_addr = "83c5541a6c8d2dbad642f385d8d06ca9b6c731ee";
String code_a = "60006020023560005460016020023560205460005360005760205360015700";
String code_b = "6000601f5560e05b60e05b54600060c05b015560605b6020015b80602001600b9054806040016016905480606001602190546080905460007377045e71a7a2c50903d88e564cd72fab11e820516103e8f1602060000260a00160200153600054";
String code_a = "60006020023560005260016020023560205260005160005560205160015500";
String code_b = "6000601f5360e05960e05952600060c05901536060596020015980602001600b9052806040016016905280606001602190526080905260007377045e71a7a2c50903d88e564cd72fab11e820516103e8f1602060000260a00160200151600052";
byte[] caller_addr_bytes = Hex.decode(callerAddr);
@ -221,8 +221,8 @@ public class VMComplexTest {
byte[] contractA_addr_bytes = Hex.decode("77045e71a7a2c50903d88e564cd72fab11e82051");
byte[] contractB_addr_bytes = Hex.decode("83c5541a6c8d2dbad642f385d8d06ca9b6c731ee");
byte[] codeA = Hex.decode("600b60005460166020546021604054602c6060546037608054604260a05460c06000f2");
byte[] codeB = Hex.decode("6000601f5560e05b60e05b54600060c05b015560605b6020015b80602001600b9054806040016016905480606001602190546080905460007377045e71a7a2c50903d88e564cd72fab11e820516103e8f1602060000260a00160200153600054");
byte[] codeA = Hex.decode("600b60005260166020526021604052602c6060526037608052604260a05260c06000f2");
byte[] codeB = Hex.decode("6000601f5360e05960e05952600060c05901536060596020015980602001600b9052806040016016905280606001602190526080905260007377045e71a7a2c50903d88e564cd72fab11e820516103e8f1602060000260a00160200151600052");
ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
pi.setOwnerAddress(contractB_addr_bytes);
@ -367,8 +367,8 @@ public class VMComplexTest {
byte[] contractA_addr_bytes = Hex.decode("945304eb96065b2a98b57a48a06ae28d285a71b5");
byte[] contractB_addr_bytes = Hex.decode("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6");
byte[] codeA = Hex.decode("600035560f6009590060203560003557");
byte[] codeB = Hex.decode("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6000547faaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa6020546000604060406000601773945304eb96065b2a98b57a48a06ae28d285a71b5620f4240f3600057");
byte[] codeA = Hex.decode("60003554156009570060203560003555");
byte[] codeB = Hex.decode("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6000527faaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa6020526000604060406000601773945304eb96065b2a98b57a48a06ae28d285a71b5620f4240f3600055");
ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl();
pi.setOwnerAddress(contractB_addr_bytes);

View File

@ -345,7 +345,7 @@ public class VMCustomTest {
VM vm = new VM();
program =
new Program(Hex.decode("60016000556001600020"), invoke);
new Program(Hex.decode("60016000536001600020"), invoke);
String s_expected_1 = "5FE7F977E71DBA2EA1A68E21057BEEBB9BE2AC30C6410AA38D4F3FBE41DCFFD2";
vm.step(program);
@ -364,7 +364,7 @@ public class VMCustomTest {
VM vm = new VM();
program =
new Program(Hex.decode("6102016000546002601E20"), invoke);
new Program(Hex.decode("6102016000526002601E20"), invoke);
String s_expected_1 = "114A3FE82A0219FCC31ABD15617966A125F12B0FD3409105FC83B487A9D82DE4";
vm.step(program);
@ -383,7 +383,7 @@ public class VMCustomTest {
VM vm = new VM();
program =
new Program(Hex.decode("610201600054600220"), invoke);
new Program(Hex.decode("610201600052600220"), invoke);
try {
vm.step(program);
vm.step(program);
@ -484,7 +484,7 @@ public class VMCustomTest {
VM vm = new VM();
program =
new Program(Hex.decode("5C"), invoke);
new Program(Hex.decode("5A"), invoke);
String s_expected_1 = "00000000000000000000000000000000000000000000000000000000000F423F";
vm.step(program);
@ -511,7 +511,7 @@ public class VMCustomTest {
public void testINVALID_1() {
VM vm = new VM();
program = new Program(Hex.decode("6001516002"), invoke);
program = new Program(Hex.decode("60012F6002"), invoke);
String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000001";
try {

View File

@ -484,7 +484,7 @@ public class VMTest {
public void testAND_1() {
VM vm = new VM();
program = new Program(Hex.decode("600A600A10"), invoke);
program = new Program(Hex.decode("600A600A16"), invoke);
String expected = "000000000000000000000000000000000000000000000000000000000000000A";
vm.step(program);
@ -498,7 +498,7 @@ public class VMTest {
public void testAND_2() {
VM vm = new VM();
program = new Program(Hex.decode("60C0600A10"), invoke);
program = new Program(Hex.decode("60C0600A16"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
@ -512,7 +512,7 @@ public class VMTest {
public void testAND_3() {
VM vm = new VM();
program = new Program(Hex.decode("60C010"), invoke);
program = new Program(Hex.decode("60C016"), invoke);
try {
vm.step(program);
vm.step(program);
@ -526,7 +526,7 @@ public class VMTest {
public void testOR_1() {
VM vm = new VM();
program = new Program(Hex.decode("60F0600F11"), invoke);
program = new Program(Hex.decode("60F0600F17"), invoke);
String expected = "00000000000000000000000000000000000000000000000000000000000000FF";
vm.step(program);
@ -540,7 +540,7 @@ public class VMTest {
public void testOR_2() {
VM vm = new VM();
program = new Program(Hex.decode("60C3603C11"), invoke);
program = new Program(Hex.decode("60C3603C17"), invoke);
String expected = "00000000000000000000000000000000000000000000000000000000000000FF";
vm.step(program);
@ -554,7 +554,7 @@ public class VMTest {
public void testOR_3() {
VM vm = new VM();
program = new Program(Hex.decode("60C011"), invoke);
program = new Program(Hex.decode("60C017"), invoke);
try {
vm.step(program);
vm.step(program);
@ -568,7 +568,7 @@ public class VMTest {
public void testXOR_1() {
VM vm = new VM();
program = new Program(Hex.decode("60FF60FF12"), invoke);
program = new Program(Hex.decode("60FF60FF18"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
@ -582,7 +582,7 @@ public class VMTest {
public void testXOR_2() {
VM vm = new VM();
program = new Program(Hex.decode("600F60F012"), invoke);
program = new Program(Hex.decode("600F60F018"), invoke);
String expected = "00000000000000000000000000000000000000000000000000000000000000FF";
vm.step(program);
@ -597,7 +597,7 @@ public class VMTest {
public void testXOR_3() {
VM vm = new VM();
program = new Program(Hex.decode("60C012"), invoke);
program = new Program(Hex.decode("60C018"), invoke);
try {
vm.step(program);
vm.step(program);
@ -611,7 +611,7 @@ public class VMTest {
public void testBYTE_1() {
VM vm = new VM();
program = new Program(Hex.decode("65AABBCCDDEEFF601E13"), invoke);
program = new Program(Hex.decode("65AABBCCDDEEFF601E19"), invoke);
String expected = "00000000000000000000000000000000000000000000000000000000000000EE";
vm.step(program);
@ -625,7 +625,7 @@ public class VMTest {
public void testBYTE_2() {
VM vm = new VM();
program = new Program(Hex.decode("65AABBCCDDEEFF602013"), invoke);
program = new Program(Hex.decode("65AABBCCDDEEFF602019"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
@ -639,7 +639,7 @@ public class VMTest {
public void testBYTE_3() {
VM vm = new VM();
program = new Program(Hex.decode("65AABBCCDDEE3A601F13"), invoke);
program = new Program(Hex.decode("65AABBCCDDEE3A601F19"), invoke);
String expected = "000000000000000000000000000000000000000000000000000000000000003A";
vm.step(program);
@ -654,7 +654,7 @@ public class VMTest {
public void testBYTE_4() {
VM vm = new VM();
program = new Program(Hex.decode("65AABBCCDDEE3A13"), invoke);
program = new Program(Hex.decode("65AABBCCDDEE3A19"), invoke);
try {
vm.step(program);
vm.step(program);
@ -664,11 +664,11 @@ public class VMTest {
}
}
@Test // NOT OP
public void testNOT_1() {
@Test // ISZERO OP
public void testISZERO_1() {
VM vm = new VM();
program = new Program(Hex.decode("60000F"), invoke);
program = new Program(Hex.decode("600015"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000001";
vm.step(program);
@ -677,11 +677,11 @@ public class VMTest {
assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase() );
}
@Test // NOT OP
public void testNOT_2() {
@Test // ISZERO OP
public void testISZERO_2() {
VM vm = new VM();
program = new Program(Hex.decode("602A0F"), invoke);
program = new Program(Hex.decode("602A15"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
@ -690,11 +690,11 @@ public class VMTest {
assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase() );
}
@Test(expected=StackTooSmallException.class) // NOT OP mal data
public void testNOT_3() {
@Test(expected=StackTooSmallException.class) // ISZERO OP mal data
public void testISZERO_3() {
VM vm = new VM();
program = new Program(Hex.decode("0F"), invoke);
program = new Program(Hex.decode("15"), invoke);
try {
vm.step(program);
vm.step(program);
@ -708,7 +708,7 @@ public class VMTest {
public void testEQ_1() {
VM vm = new VM();
program = new Program(Hex.decode("602A602A0E"), invoke);
program = new Program(Hex.decode("602A602A14"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000001";
vm.step(program);
@ -722,7 +722,7 @@ public class VMTest {
public void testEQ_2() {
VM vm = new VM();
program = new Program(Hex.decode("622A3B4C622A3B4C0E"), invoke);
program = new Program(Hex.decode("622A3B4C622A3B4C14"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000001";
vm.step(program);
@ -736,7 +736,7 @@ public class VMTest {
public void testEQ_3() {
VM vm = new VM();
program = new Program(Hex.decode("622A3B5C622A3B4C0E"), invoke);
program = new Program(Hex.decode("622A3B5C622A3B4C14"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
@ -750,7 +750,7 @@ public class VMTest {
public void testEQ_4() {
VM vm = new VM();
program = new Program(Hex.decode("622A3B4C0E"), invoke);
program = new Program(Hex.decode("622A3B4C14"), invoke);
try {
vm.step(program);
vm.step(program);
@ -764,7 +764,7 @@ public class VMTest {
public void testGT_1() {
VM vm = new VM();
program = new Program(Hex.decode("600160020B"), invoke);
program = new Program(Hex.decode("6001600211"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000001";
vm.step(program);
@ -778,7 +778,7 @@ public class VMTest {
public void testGT_2() {
VM vm = new VM();
program = new Program(Hex.decode("6001610F000B"), invoke);
program = new Program(Hex.decode("6001610F0011"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000001";
vm.step(program);
@ -792,7 +792,7 @@ public class VMTest {
public void testGT_3() {
VM vm = new VM();
program = new Program(Hex.decode("6301020304610F000B"), invoke);
program = new Program(Hex.decode("6301020304610F0011"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
@ -806,7 +806,7 @@ public class VMTest {
public void testGT_4() {
VM vm = new VM();
program = new Program(Hex.decode("622A3B4C0B"), invoke);
program = new Program(Hex.decode("622A3B4C11"), invoke);
try {
vm.step(program);
vm.step(program);
@ -820,7 +820,7 @@ public class VMTest {
public void testSGT_1() {
VM vm = new VM();
program = new Program(Hex.decode("600160020D"), invoke);
program = new Program(Hex.decode("6001600213"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000001";
vm.step(program);
@ -836,7 +836,7 @@ public class VMTest {
VM vm = new VM();
program = new Program(Hex.decode("7F000000000000000000000000000000000000000000000000000000000000001E" + // 30
"7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56" + // -170
"0D"), invoke);
"13"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000000";
@ -852,8 +852,8 @@ public class VMTest {
VM vm = new VM();
program = new Program(Hex.decode("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56" + // -170
"7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF57" + // -169
"0D"), invoke);
"7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF57" + // -169
"13"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000001";
@ -869,7 +869,7 @@ public class VMTest {
VM vm = new VM();
program = new Program(Hex.decode("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56" + // -170
"0D"), invoke);
"13"), invoke);
try {
vm.step(program);
vm.step(program);
@ -883,7 +883,7 @@ public class VMTest {
public void testLT_1() {
VM vm = new VM();
program = new Program(Hex.decode("600160020A"), invoke);
program = new Program(Hex.decode("6001600210"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
@ -897,7 +897,7 @@ public class VMTest {
public void testLT_2() {
VM vm = new VM();
program = new Program(Hex.decode("6001610F000A"), invoke);
program = new Program(Hex.decode("6001610F0010"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
@ -911,7 +911,7 @@ public class VMTest {
public void testLT_3() {
VM vm = new VM();
program = new Program(Hex.decode("6301020304610F000A"), invoke);
program = new Program(Hex.decode("6301020304610F0010"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000001";
vm.step(program);
@ -925,7 +925,7 @@ public class VMTest {
public void testLT_4() {
VM vm = new VM();
program = new Program(Hex.decode("622A3B4C0A"), invoke);
program = new Program(Hex.decode("622A3B4C10"), invoke);
try {
vm.step(program);
vm.step(program);
@ -939,7 +939,7 @@ public class VMTest {
public void testSLT_1() {
VM vm = new VM();
program = new Program(Hex.decode("600160020C"), invoke);
program = new Program(Hex.decode("6001600212"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
@ -955,7 +955,7 @@ public class VMTest {
VM vm = new VM();
program = new Program(Hex.decode("7F000000000000000000000000000000000000000000000000000000000000001E" + // 30
"7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56" + // -170
"0C"), invoke);
"12"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000001";
@ -972,7 +972,7 @@ public class VMTest {
VM vm = new VM();
program = new Program(Hex.decode("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56" + // -170
"7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF57" + // -169
"0C"), invoke);
"12"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000000";
@ -988,7 +988,7 @@ public class VMTest {
VM vm = new VM();
program = new Program(Hex.decode("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56" + // -170
"0D"), invoke);
"12"), invoke);
try {
vm.step(program);
vm.step(program);
@ -998,11 +998,11 @@ public class VMTest {
}
}
@Test // BNOT OP
public void testBNOT_1() {
@Test // NOT OP
public void testNOT_1() {
VM vm = new VM();
program = new Program(Hex.decode("600109"), invoke);
program = new Program(Hex.decode("60011a"), invoke);
String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE";
vm.step(program);
@ -1011,11 +1011,11 @@ public class VMTest {
assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase());
}
@Test // BNOT OP
public void testBNOT_2() {
@Test // NOT OP
public void testNOT_2() {
VM vm = new VM();
program = new Program(Hex.decode("61A00309"), invoke);
program = new Program(Hex.decode("61A0031a"), invoke);
String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5FFC";
vm.step(program);
@ -1024,11 +1024,11 @@ public class VMTest {
assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase());
}
@Test // BNOT OP
public void testBNOT_3() {
@Test // NOT OP
public void testNOT_3() {
VM vm = new VM();
program = new Program(Hex.decode("61000009"), invoke);
program = new Program(Hex.decode("6100001a"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
@ -1041,7 +1041,7 @@ public class VMTest {
public void testBNOT_4() {
VM vm = new VM();
program = new Program(Hex.decode("09"), invoke);
program = new Program(Hex.decode("1a"), invoke);
try {
vm.step(program);
vm.step(program);
@ -1200,7 +1200,7 @@ public class VMTest {
public void testMSTORE_1() {
VM vm = new VM();
program = new Program(Hex.decode("611234600054"), invoke);
program = new Program(Hex.decode("611234600052"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000001234";
vm.step(program);
@ -1214,7 +1214,7 @@ public class VMTest {
public void testMSTORE_2() {
VM vm = new VM();
program = new Program(Hex.decode("611234600054615566602054"), invoke);
program = new Program(Hex.decode("611234600052615566602052"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000001234" +
"0000000000000000000000000000000000000000000000000000000000005566";
@ -1232,7 +1232,7 @@ public class VMTest {
public void testMSTORE_3() {
VM vm = new VM();
program = new Program(Hex.decode("611234600054615566602054618888600054"), invoke);
program = new Program(Hex.decode("611234600052615566602052618888600052"), invoke);
String expected = "0000000000000000000000000000000000000000000000000000000000008888" +
"0000000000000000000000000000000000000000000000000000000000005566";
@ -1253,7 +1253,7 @@ public class VMTest {
public void testMSTORE_4() {
VM vm = new VM();
program = new Program(Hex.decode("61123460A054"), invoke);
program = new Program(Hex.decode("61123460A052"), invoke);
String expected = "" +
"0000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000" +
@ -1273,7 +1273,7 @@ public class VMTest {
public void testMSTORE_5() {
VM vm = new VM();
program = new Program(Hex.decode("61123454"), invoke);
program = new Program(Hex.decode("61123452"), invoke);
try {
vm.step(program);
vm.step(program);
@ -1286,7 +1286,7 @@ public class VMTest {
public void testMLOAD_1() {
VM vm = new VM();
program = new Program(Hex.decode("600053"), invoke);
program = new Program(Hex.decode("600051"), invoke);
String m_expected = "0000000000000000000000000000000000000000000000000000000000000000";
String s_expected = "0000000000000000000000000000000000000000000000000000000000000000";
@ -1301,7 +1301,7 @@ public class VMTest {
public void testMLOAD_2() {
VM vm = new VM();
program = new Program(Hex.decode("602253"), invoke);
program = new Program(Hex.decode("602251"), invoke);
String m_expected = "0000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000";
@ -1319,7 +1319,7 @@ public class VMTest {
public void testMLOAD_3() {
VM vm = new VM();
program = new Program(Hex.decode("602053"), invoke);
program = new Program(Hex.decode("602051"), invoke);
String m_expected = "0000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000";
String s_expected = "0000000000000000000000000000000000000000000000000000000000000000";
@ -1335,7 +1335,7 @@ public class VMTest {
public void testMLOAD_4() {
VM vm = new VM();
program = new Program(Hex.decode("611234602054602053"), invoke);
program = new Program(Hex.decode("611234602052602051"), invoke);
String m_expected = "0000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000001234";
String s_expected = "0000000000000000000000000000000000000000000000000000000000001234";
@ -1354,7 +1354,7 @@ public class VMTest {
public void testMLOAD_5() {
VM vm = new VM();
program = new Program(Hex.decode("611234602054601F53"), invoke);
program = new Program(Hex.decode("611234602052601F51"), invoke);
String m_expected = "0000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000001234";
String s_expected = "0000000000000000000000000000000000000000000000000000000000000012";
@ -1373,7 +1373,7 @@ public class VMTest {
public void testMLOAD_6() {
VM vm = new VM();
program = new Program(Hex.decode("53"), invoke);
program = new Program(Hex.decode("51"), invoke);
try {
vm.step(program);
} finally {
@ -1385,7 +1385,7 @@ public class VMTest {
public void testMSTORE8_1() {
VM vm = new VM();
program = new Program(Hex.decode("6011600055"), invoke);
program = new Program(Hex.decode("6011600053"), invoke);
String m_expected = "1100000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
@ -1400,7 +1400,7 @@ public class VMTest {
public void testMSTORE8_2() {
VM vm = new VM();
program = new Program(Hex.decode("6022600155"), invoke);
program = new Program(Hex.decode("6022600153"), invoke);
String m_expected = "0022000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
@ -1414,7 +1414,7 @@ public class VMTest {
public void testMSTORE8_3() {
VM vm = new VM();
program = new Program(Hex.decode("6022602155"), invoke);
program = new Program(Hex.decode("6022602153"), invoke);
String m_expected = "0000000000000000000000000000000000000000000000000000000000000000" +
"0022000000000000000000000000000000000000000000000000000000000000";
@ -1429,7 +1429,7 @@ public class VMTest {
public void testMSTORE8_4() {
VM vm = new VM();
program = new Program(Hex.decode("602255"), invoke);
program = new Program(Hex.decode("602253"), invoke);
try {
vm.step(program);
vm.step(program);
@ -1443,7 +1443,7 @@ public class VMTest {
VM vm = new VM();
program = new Program(Hex.decode("602260AA57"), invoke);
program = new Program(Hex.decode("602260AA55"), invoke);
String s_expected_key = "00000000000000000000000000000000000000000000000000000000000000AA";
String s_expected_val = "0000000000000000000000000000000000000000000000000000000000000022";
@ -1462,7 +1462,7 @@ public class VMTest {
VM vm = new VM();
program = new Program(Hex.decode("602260AA57602260BB57"), invoke);
program = new Program(Hex.decode("602260AA55602260BB55"), invoke);
String s_expected_key = "00000000000000000000000000000000000000000000000000000000000000BB";
String s_expected_val = "0000000000000000000000000000000000000000000000000000000000000022";
@ -1484,7 +1484,7 @@ public class VMTest {
public void testSSTORE_3() {
VM vm = new VM();
program = new Program(Hex.decode("602257"), invoke);
program = new Program(Hex.decode("602255"), invoke);
try {
vm.step(program);
vm.step(program);
@ -1497,7 +1497,7 @@ public class VMTest {
public void testSLOAD_1() {
VM vm = new VM();
program = new Program(Hex.decode("60AA56"), invoke);
program = new Program(Hex.decode("60AA54"), invoke);
String s_expected = "0000000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
@ -1510,7 +1510,7 @@ public class VMTest {
public void testSLOAD_2() {
VM vm = new VM();
program = new Program(Hex.decode("602260AA5760AA56"), invoke);
program = new Program(Hex.decode("602260AA5560AA54"), invoke);
String s_expected = "0000000000000000000000000000000000000000000000000000000000000022";
vm.step(program);
@ -1526,7 +1526,7 @@ public class VMTest {
public void testSLOAD_3() {
VM vm = new VM();
program = new Program(Hex.decode("602260AA57603360CC5760CC56"), invoke);
program = new Program(Hex.decode("602260AA55603360CC5560CC54"), invoke);
String s_expected = "0000000000000000000000000000000000000000000000000000000000000033";
vm.step(program);
@ -1557,7 +1557,7 @@ public class VMTest {
public void testPC_1() {
VM vm = new VM();
program = new Program(Hex.decode("5A"), invoke);
program = new Program(Hex.decode("58"), invoke);
String s_expected = "0000000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
@ -1570,7 +1570,7 @@ public class VMTest {
public void testPC_2() {
VM vm = new VM();
program = new Program(Hex.decode("602260AA5760AA565A"), invoke);
program = new Program(Hex.decode("602260AA5260AA5458"), invoke);
String s_expected = "0000000000000000000000000000000000000000000000000000000000000008";
vm.step(program);
@ -1587,7 +1587,7 @@ public class VMTest {
public void testJUMP_1() {
VM vm = new VM();
program = new Program(Hex.decode("60AA60BB600E5860CC60DD60EE5D60FF"), invoke);
program = new Program(Hex.decode("60AA60BB600E5660CC60DD60EE5B60FF"), invoke);
String s_expected = "00000000000000000000000000000000000000000000000000000000000000FF";
vm.step(program);
@ -1603,7 +1603,7 @@ public class VMTest {
public void testJUMP_2() {
VM vm = new VM();
program = new Program(Hex.decode("600C5860CC60DD60EE60FF"), invoke);
program = new Program(Hex.decode("600C5660CC60DD60EE60FF"), invoke);
try {
vm.step(program);
vm.step(program);
@ -1616,7 +1616,7 @@ public class VMTest {
public void testJUMPI_1() {
VM vm = new VM();
program = new Program(Hex.decode("60016006595D60CC"), invoke);
program = new Program(Hex.decode("60016006575B60CC"), invoke);
String s_expected = "00000000000000000000000000000000000000000000000000000000000000CC";
vm.step(program);
@ -1632,7 +1632,7 @@ public class VMTest {
public void testJUMPI_2() {
VM vm = new VM();
program = new Program(Hex.decode("630000000060445960CC60DD"), invoke);
program = new Program(Hex.decode("630000000060445760CC60DD"), invoke);
String s_expected_1 = "00000000000000000000000000000000000000000000000000000000000000DD";
String s_expected_2 = "00000000000000000000000000000000000000000000000000000000000000CC";
@ -1653,7 +1653,7 @@ public class VMTest {
public void testJUMPI_3() {
VM vm = new VM();
program = new Program(Hex.decode("600159"), invoke);
program = new Program(Hex.decode("600157"), invoke);
try {
vm.step(program);
vm.step(program);
@ -1666,7 +1666,7 @@ public class VMTest {
public void testJUMPI_4() {
VM vm = new VM();
program = new Program(Hex.decode("6001602259"), invoke);
program = new Program(Hex.decode("6001602257"), invoke);
try {
vm.step(program);
vm.step(program);
@ -1680,7 +1680,7 @@ public class VMTest {
public void testJUMPDEST_1() {
VM vm = new VM();
program = new Program(Hex.decode("602360085860015d600257"), invoke);
program = new Program(Hex.decode("602360085660015b600255"), invoke);
String s_expected_key = "0000000000000000000000000000000000000000000000000000000000000002";
String s_expected_val = "0000000000000000000000000000000000000000000000000000000000000023";
@ -1702,7 +1702,7 @@ public class VMTest {
public void testJUMPDEST_2() {
VM vm = new VM();
program = new Program(Hex.decode("60236001600a5960015d600257"), invoke);
program = new Program(Hex.decode("60236001600a5760015b600255"), invoke);
String s_expected_key = "0000000000000000000000000000000000000000000000000000000000000002";
String s_expected_val = "0000000000000000000000000000000000000000000000000000000000000023";
@ -1782,7 +1782,7 @@ public class VMTest {
@Test // ADDMOD OP mal
public void testADDMOD_1() {
VM vm = new VM();
program = new Program(Hex.decode("60026002600314"), invoke);
program = new Program(Hex.decode("60026002600308"), invoke);
String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000001";
vm.step(program);
@ -1798,7 +1798,7 @@ public class VMTest {
@Test // ADDMOD OP
public void testADDMOD_2() {
VM vm = new VM();
program = new Program(Hex.decode("6110006002611002146000"), invoke);
program = new Program(Hex.decode("6110006002611002086000"), invoke);
String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000004";
vm.step(program);
@ -1814,7 +1814,7 @@ public class VMTest {
@Test // ADDMOD OP
public void testADDMOD_3() {
VM vm = new VM();
program = new Program(Hex.decode("61100265123456789009600214"), invoke);
program = new Program(Hex.decode("61100265123456789009600208"), invoke);
String s_expected_1 = "000000000000000000000000000000000000000000000000000000000000093B";
vm.step(program);
@ -1830,7 +1830,7 @@ public class VMTest {
@Test(expected=StackTooSmallException.class) // ADDMOD OP mal
public void testADDMOD_4() {
VM vm = new VM();
program = new Program(Hex.decode("61123414"), invoke);
program = new Program(Hex.decode("61123408"), invoke);
try {
vm.step(program);
vm.step(program);
@ -1900,7 +1900,7 @@ public class VMTest {
@Test // MULMOD OP
public void testMULMOD_1() {
VM vm = new VM();
program = new Program(Hex.decode("60036002600415"), invoke);
program = new Program(Hex.decode("60036002600409"), invoke);
String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000002";
vm.step(program);
@ -1915,7 +1915,7 @@ public class VMTest {
@Test // MULMOD OP
public void testMULMOD_2() {
VM vm = new VM();
program = new Program(Hex.decode("622222226003600415"), invoke);
program = new Program(Hex.decode("622222226003600409"), invoke);
String s_expected_1 = "000000000000000000000000000000000000000000000000000000000000000C";
vm.step(program);
@ -1930,7 +1930,7 @@ public class VMTest {
@Test // MULMOD OP
public void testMULMOD_3() {
VM vm = new VM();
program = new Program(Hex.decode("62222222623333336244444415"), invoke);
program = new Program(Hex.decode("62222222623333336244444409"), invoke);
String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
@ -1945,7 +1945,7 @@ public class VMTest {
@Test(expected=StackTooSmallException.class) // MULMOD OP mal
public void testMULMOD_4() {
VM vm = new VM();
program = new Program(Hex.decode("600115"), invoke);
program = new Program(Hex.decode("600109"), invoke);
try {
vm.step(program);
vm.step(program);
@ -2165,7 +2165,7 @@ public class VMTest {
public void testMSIZE_1() {
VM vm = new VM();
program = new Program(Hex.decode("5B"), invoke);
program = new Program(Hex.decode("59"), invoke);
String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
@ -2178,7 +2178,7 @@ public class VMTest {
public void testMSIZE_2() {
VM vm = new VM();
program = new Program(Hex.decode("60206030545B"), invoke);
program = new Program(Hex.decode("602060305259"), invoke);
String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000060";
vm.step(program);
@ -2212,7 +2212,7 @@ public class VMTest {
public void testEXP_1() {
VM vm = new VM();
program = new Program(Hex.decode("6003600208"), invoke);
program = new Program(Hex.decode("600360020a"), invoke);
String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000008";
vm.step(program);
@ -2227,7 +2227,7 @@ public class VMTest {
public void testEXP_2() {
VM vm = new VM();
program = new Program(Hex.decode("60006212345608"), invoke);
program = new Program(Hex.decode("6000621234560a"), invoke);
String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000001";
vm.step(program);
@ -2242,7 +2242,7 @@ public class VMTest {
public void testEXP_3() {
VM vm = new VM();
program = new Program(Hex.decode("6212345608"), invoke);
program = new Program(Hex.decode("621234560a"), invoke);
try {
vm.step(program);
vm.step(program);
@ -2255,7 +2255,7 @@ public class VMTest {
public void testRETURN_1() {
VM vm = new VM();
program = new Program(Hex.decode("61123460005460206000F2"), invoke);
program = new Program(Hex.decode("61123460005260206000F2"), invoke);
String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000001234";
vm.step(program);
@ -2274,7 +2274,7 @@ public class VMTest {
public void testRETURN_2() {
VM vm = new VM();
program = new Program(Hex.decode("6112346000546020601FF2"), invoke);
program = new Program(Hex.decode("6112346000526020601FF2"), invoke);
String s_expected_1 = "3400000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
@ -2293,7 +2293,7 @@ public class VMTest {
VM vm = new VM();
program =
new Program(Hex.decode("7FA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B160005460206000F2"),
new Program(Hex.decode("7FA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B160005260206000F2"),
invoke);
String s_expected_1 = "A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1";
@ -2314,7 +2314,7 @@ public class VMTest {
VM vm = new VM();
program =
new Program(Hex.decode("7FA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B160005460206010F2"),
new Program(Hex.decode("7FA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B160005260206010F2"),
invoke);
String s_expected_1 = "E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B100000000000000000000000000000000";