From 7663a4b454f05931579cee477a08785baf744e6e Mon Sep 17 00:00:00 2001 From: nicksavers Date: Fri, 10 Oct 2014 13:56:03 +0200 Subject: [PATCH] Fix SMOD according to Yellow Paper --- .../src/main/java/org/ethereum/vm/DataWord.java | 2 +- ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) 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 763725aa..d7f9e6f5 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java @@ -235,7 +235,7 @@ public class DataWord implements Comparable { return; } - BigInteger result = sValue().mod(word.sValue()); + BigInteger result = sValue().remainder(word.sValue()); this.data = ByteUtil.copyToArray(result.and(MAX_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 96a70684..89d3f6dd 100644 --- a/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/vm/VMTest.java @@ -3182,7 +3182,7 @@ public class VMTest { Program program = new Program(Hex.decode("7F000000000000000000000000000000000000000000000000000000000000001E" + // 30 "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56" + // -170 "07"), new ProgramInvokeMockImpl()); - String s_expected_1 = "000000000000000000000000000000000000000000000000000000000000000A"; + String s_expected_1 = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEC"; vm.step(program); vm.step(program); @@ -3193,6 +3193,12 @@ public class VMTest { assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } + @Test + public void testSMOD_x() { + int x = -170 % 30; + System.out.println(x); + } + @Test(expected=StackTooSmallException.class) // SMOD OP mal public void testSMOD_4() { VM vm = new VM();