Fix MULMOD to avoid using mod in between
This commit is contained in:
parent
21e029c125
commit
bfee3b2251
|
@ -227,7 +227,6 @@ public class DataWord implements Comparable<DataWord> {
|
|||
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<DataWord> {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue