diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java b/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java index c06eab38..517caa12 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java @@ -151,6 +151,11 @@ public class DataWord implements Comparable { if (this.data[i] != 0) break; } } + + public void bnot() { + if (this.isZero()) return; + this.data = ByteUtil.copyToArray(MAX_VALUE.subtract(this.value())); + } // By : Holger // From : http://stackoverflow.com/a/24023466/459349 diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/OpCode.java b/ethereumj-core/src/main/java/org/ethereum/vm/OpCode.java index e4aae830..b3203e04 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/OpCode.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/OpCode.java @@ -32,7 +32,7 @@ public enum OpCode { /** (0x08) Exponential operation */ EXP(0x08, 2), /** (0x09) Negation operation */ - NEG(0x09, 1), + BNOT(0x09, 1), /** (0x0a) Less-than comparison */ LT(0X0a, 2), /** (0x0b) Greater-than comparison */ diff --git a/ethereumj-core/src/main/java/org/ethereum/vm/VM.java b/ethereumj-core/src/main/java/org/ethereum/vm/VM.java index 966acfe4..baf8d634 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/VM.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/VM.java @@ -282,9 +282,9 @@ public class VM { program.stackPush(word1); program.step(); } break; - case NEG:{ + case BNOT:{ DataWord word1 = program.stackPop(); - word1.negate(); + word1.bnot(); if (logger.isInfoEnabled()) hint = "" + word1.value(); diff --git a/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java b/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java index 4893b3a3..b28a5e1e 100644 --- a/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java @@ -998,12 +998,12 @@ public class VMTest { } } - @Test // NEG OP - public void testNEG_1() { + @Test // BNOT OP + public void testBNOT_1() { VM vm = new VM(); program = new Program(Hex.decode("600109"), invoke); - String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; + String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"; vm.step(program); vm.step(program); @@ -1011,12 +1011,12 @@ public class VMTest { assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase()); } - @Test // NEG OP - public void testNEG_2() { + @Test // BNOT OP + public void testBNOT_2() { VM vm = new VM(); program = new Program(Hex.decode("61A00309"), invoke); - String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5FFD"; + String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5FFC"; vm.step(program); vm.step(program); @@ -1024,8 +1024,8 @@ public class VMTest { assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase()); } - @Test // NEG OP - public void testNEG_3() { + @Test // BNOT OP + public void testBNOT_3() { VM vm = new VM(); program = new Program(Hex.decode("61000009"), invoke); @@ -1037,8 +1037,8 @@ public class VMTest { assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase()); } - @Test(expected=StackTooSmallException.class) // NEG OP - public void testNEG_4() { + @Test(expected=StackTooSmallException.class) // BNOT OP + public void testBNOT_4() { VM vm = new VM(); program = new Program(Hex.decode("09"), invoke);