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 e900674c..ab2ad40d 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/DataWord.java @@ -227,7 +227,6 @@ public class DataWord implements Comparable { this.data = ByteUtil.copyToArray(result.and(MAX_VALUE)); } - // TODO: improve with no BigInteger public void sMod(DataWord word) { if (word.isZero()) { @@ -239,6 +238,17 @@ public class DataWord implements Comparable { this.data = ByteUtil.copyToArray(result.and(MAX_VALUE)); } + public void addmod(DataWord word1, DataWord word2) { + this.add(word1); + BigInteger result = this.value().mod(word2.value()); + this.data = ByteUtil.copyToArray(result.and(MAX_VALUE)); + } + + public void mulmod(DataWord word1, DataWord word2) { + BigInteger result = value().multiply(word1.value()).mod(word2.value()); + this.data = ByteUtil.copyToArray(result.and(MAX_VALUE)); + } + public String toString() { return Hex.toHexString(data); } 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 d772a3b4..a11dae9b 100644 --- a/ethereumj-core/src/main/java/org/ethereum/vm/VM.java +++ b/ethereumj-core/src/main/java/org/ethereum/vm/VM.java @@ -476,16 +476,18 @@ public class VM { case ADDMOD:{ program.stackRequire(3); DataWord word1 = program.stackPop(); - word1.add(program.stackPop()); - word1.mod(program.stackPop()); + DataWord word2 = program.stackPop(); + DataWord word3 = program.stackPop(); + word1.addmod(word2, word3); program.stackPush(word1); program.step(); } break; case MULMOD:{ program.stackRequire(3); DataWord word1 = program.stackPop(); - word1.mul(program.stackPop()); - word1.mod(program.stackPop()); + DataWord word2 = program.stackPop(); + DataWord word3 = program.stackPop(); + word1.mulmod(word2, word3); program.stackPush(word1); program.step(); } break;