Skip to content

Commit

Permalink
Fix redundant conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel-Trintinalia committed Apr 25, 2023
1 parent 81372de commit 4aac8e5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
package net.consensys.linea.zktracer.module.alu.ext.calculator;
package net.consensys.linea.zktracer.module;

import java.math.BigInteger;

Expand Down Expand Up @@ -46,8 +46,7 @@ public static BigInteger calculateProduct(Bytes32 arg1, Bytes32 arg2) {
* @return The quotient of the given BigInteger and arg3 as a BigInteger.
*/
public static BigInteger calculateQuotient(BigInteger prod, Bytes32 arg3) {
byte[] prodBytes = prod.toByteArray(); // Convert the product to a byte array.
return new BigInteger(1, prodBytes).divide(arg3.toUnsignedBigInteger());
return prod.divide(arg3.toUnsignedBigInteger());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import net.consensys.linea.zktracer.bytestheta.BaseTheta;
import net.consensys.linea.zktracer.bytestheta.BytesArray;
import net.consensys.linea.zktracer.module.UtilCalculator;
import net.consensys.linea.zktracer.module.alu.ext.BigIntegerConverter;
import net.consensys.linea.zktracer.module.alu.ext.calculator.UtilCalculator;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@

import static net.consensys.linea.zktracer.module.Util.isUInt256;
import static net.consensys.linea.zktracer.module.Util.uInt64ToBytes;
import static net.consensys.linea.zktracer.module.alu.ext.calculator.UtilCalculator.calculateProduct;
import static net.consensys.linea.zktracer.module.alu.ext.calculator.UtilCalculator.calculateQuotient;
import static net.consensys.linea.zktracer.module.alu.ext.calculator.UtilCalculator.convertToBaseTheta;

import java.math.BigInteger;

import net.consensys.linea.zktracer.bytestheta.BaseTheta;
import net.consensys.linea.zktracer.bytestheta.BytesArray;
import net.consensys.linea.zktracer.module.UtilCalculator;
import net.consensys.linea.zktracer.module.alu.ext.BigIntegerConverter;
import org.apache.tuweni.bytes.Bytes32;

public class MulModBytesQCalculator {
/**
* Computes the quotient of the product of arg1 and arg2 divided by arg3, all of Bytes32 type, and
* returns the result as a BytesArray.
* (arg1 * arg2 ) / arg3
* returns the result as a BytesArray. (arg1 * arg2 ) / arg3
*
* @param arg1 The first Bytes32 argument.
* @param arg2 The second Bytes32 argument.
* @param arg3 The third Bytes32 argument.
Expand All @@ -40,11 +38,11 @@ public class MulModBytesQCalculator {
public static BytesArray computeQs(Bytes32 arg1, Bytes32 arg2, Bytes32 arg3) {
byte[][] qBytes = new byte[8][8];

BigInteger prod = calculateProduct(arg1, arg2);
BigInteger prod = UtilCalculator.calculateProduct(arg1, arg2);

if (isUInt256(prod)) {
BigInteger quotBigInteger = calculateQuotient(prod, arg3);
BaseTheta quotBaseTheta = convertToBaseTheta(quotBigInteger);
BigInteger quotBigInteger = UtilCalculator.calculateQuotient(prod, arg3);
BaseTheta quotBaseTheta = UtilCalculator.convertToBaseTheta(quotBigInteger);

for (int i = 0; i < 4; i++) {
// Copy the BaseTheta byte arrays into the result byte array.
Expand Down

0 comments on commit 4aac8e5

Please sign in to comment.