diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java index e4a4c781a5..1c8270e0d3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/precompiles/ModexpMetadata.java @@ -135,17 +135,19 @@ public boolean extractExponent() { public Bytes base() { Bytes unpadded = Bytes.EMPTY; - if (callData.size() >= BASE_MIN_OFFSET) { - final int sizeToExtract = Math.min(bbsInt(), callData.size() - MBS_MIN_OFFSET); - unpadded = callData.slice(MBS_MIN_OFFSET, sizeToExtract); + final int firstOffset = BASE_MIN_OFFSET; + if (callData.size() > firstOffset) { + final int sizeToExtract = Math.min(bbsInt(), callData.size() - firstOffset); + unpadded = callData.slice(BASE_MIN_OFFSET, sizeToExtract); } return rightPadTo(unpadded, bbsInt()); } public Bytes exp() { Bytes unpadded = Bytes.EMPTY; - if (callData.size() >= BASE_MIN_OFFSET + bbsInt()) { - final int sizeToExtract = Math.min(ebsInt(), callData.size() - BASE_MIN_OFFSET - bbsInt()); + final int firstOffset = BASE_MIN_OFFSET + bbsInt(); + if (callData.size() > firstOffset) { + final int sizeToExtract = Math.min(ebsInt(), callData.size() - firstOffset); unpadded = callData.slice(BASE_MIN_OFFSET + bbsInt(), sizeToExtract); } return rightPadTo(unpadded, ebsInt()); @@ -154,7 +156,7 @@ public Bytes exp() { public Bytes mod() { Bytes unpadded = Bytes.EMPTY; final int firstOffset = BASE_MIN_OFFSET + bbsInt() + ebsInt(); - if (callData.size() >= firstOffset) { + if (callData.size() > firstOffset) { final int sizeToExtract = Math.min(mbsInt(), callData.size() - firstOffset); unpadded = callData.slice(firstOffset, sizeToExtract); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java index a2dce628e4..b6b4151a5d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/ModexpSubsection.java @@ -49,25 +49,25 @@ public class ModexpSubsection extends PrecompileSubsection { - private final ModexpMetadata modExpMetadata; + private final ModexpMetadata modexpMetaData; private ModexpPricingOobCall sixthOobCall; private ImcFragment seventhImcFragment; public ModexpSubsection(final Hub hub, final CallSection callSection) { super(hub, callSection); - modExpMetadata = new ModexpMetadata(hub, callData); - if (modExpMetadata + modexpMetaData = new ModexpMetadata(hub, callData); + if (modexpMetaData .bbs() .toUnsignedBigInteger() .compareTo(BigInteger.valueOf(PROVER_MAX_INPUT_BYTE_SIZE)) >= 0 - || modExpMetadata + || modexpMetaData .mbs() .toUnsignedBigInteger() .compareTo(BigInteger.valueOf(PROVER_MAX_INPUT_BYTE_SIZE)) >= 0 - || modExpMetadata + || modexpMetaData .ebs() .toUnsignedBigInteger() .compareTo(BigInteger.valueOf(PROVER_MAX_INPUT_BYTE_SIZE)) @@ -81,8 +81,8 @@ public ModexpSubsection(final Hub hub, final CallSection callSection) { final ImcFragment secondImcFragment = ImcFragment.empty(hub); fragments().add(secondImcFragment); - if (modExpMetadata.extractBbs()) { - final MmuCall mmuCall = forModexpExtractBbs(hub, this, modExpMetadata); + if (modexpMetaData.extractBbs()) { + final MmuCall mmuCall = forModexpExtractBbs(hub, this, modexpMetaData); secondImcFragment.callMmu(mmuCall); } final ModexpXbsOobCall secondOobCall = new ModexpXbsOobCall(OOB_INST_MODEXP_BBS); @@ -90,8 +90,8 @@ public ModexpSubsection(final Hub hub, final CallSection callSection) { final ImcFragment thirdImcFragment = ImcFragment.empty(hub); fragments().add(thirdImcFragment); - if (modExpMetadata.extractEbs()) { - final MmuCall mmuCall = forModexpExtractEbs(hub, this, modExpMetadata); + if (modexpMetaData.extractEbs()) { + final MmuCall mmuCall = forModexpExtractEbs(hub, this, modexpMetaData); thirdImcFragment.callMmu(mmuCall); } final ModexpXbsOobCall thirdOobCall = new ModexpXbsOobCall(OOB_INST_MODEXP_EBS); @@ -99,8 +99,8 @@ public ModexpSubsection(final Hub hub, final CallSection callSection) { final ImcFragment fourthImcFragment = ImcFragment.empty(hub); fragments().add(fourthImcFragment); - if (modExpMetadata.extractMbs()) { - final MmuCall mmuCall = forModexpExtractMbs(hub, this, modExpMetadata); + if (modexpMetaData.extractMbs()) { + final MmuCall mmuCall = forModexpExtractMbs(hub, this, modexpMetaData); fourthImcFragment.callMmu(mmuCall); } final ModexpXbsOobCall fourthOobCall = new ModexpXbsOobCall(OOB_INST_MODEXP_MBS); @@ -110,10 +110,10 @@ public ModexpSubsection(final Hub hub, final CallSection callSection) { fragments().add(fifthImcFragment); final ModexpLeadOobCall fifthOobCall = new ModexpLeadOobCall(); fifthImcFragment.callOob(fifthOobCall); - if (modExpMetadata.loadRawLeadingWord()) { - final MmuCall mmuCall = forModexpLoadLead(hub, this, modExpMetadata); + if (modexpMetaData.loadRawLeadingWord()) { + final MmuCall mmuCall = forModexpLoadLead(hub, this, modexpMetaData); fifthImcFragment.callMmu(mmuCall); - final ExpCall modexpLogCallToExp = new ModexpLogExpCall(modExpMetadata); + final ExpCall modexpLogCallToExp = new ModexpLogExpCall(modexpMetaData); fifthImcFragment.callExp(modexpLogCallToExp); } @@ -143,40 +143,40 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { return; } - modExpMetadata.rawResult(returnData); - hub.blakeModexpData().callModexp(modExpMetadata, this.exoModuleOperationId()); + modexpMetaData.rawResult(returnData); + hub.blakeModexpData().callModexp(modexpMetaData, this.exoModuleOperationId()); fragments().add(seventhImcFragment); - if (modExpMetadata.extractModulus()) { - final MmuCall mmuCall = forModexpExtractBase(hub, this, modExpMetadata); + if (modexpMetaData.extractModulus()) { + final MmuCall mmuCall = forModexpExtractBase(hub, this, modexpMetaData); seventhImcFragment.callMmu(mmuCall); } final ImcFragment eighthImcFragment = ImcFragment.empty(hub); fragments().add(eighthImcFragment); - if (modExpMetadata.extractModulus()) { - final MmuCall mmuCall = forModexpExtractExponent(hub, this, modExpMetadata); + if (modexpMetaData.extractModulus()) { + final MmuCall mmuCall = forModexpExtractExponent(hub, this, modexpMetaData); eighthImcFragment.callMmu(mmuCall); } final ImcFragment ninthImcFragment = ImcFragment.empty(hub); fragments().add(ninthImcFragment); - if (modExpMetadata.extractModulus()) { - final MmuCall mmuCall = forModexpExtractModulus(hub, this, modExpMetadata); + if (modexpMetaData.extractModulus()) { + final MmuCall mmuCall = forModexpExtractModulus(hub, this, modexpMetaData); ninthImcFragment.callMmu(mmuCall); } final ImcFragment tenthImcFragment = ImcFragment.empty(hub); fragments().add(tenthImcFragment); - if (modExpMetadata.extractModulus()) { - final MmuCall mmuCall = forModexpFullResultCopy(hub, this, modExpMetadata); + if (modexpMetaData.extractModulus()) { + final MmuCall mmuCall = forModexpFullResultCopy(hub, this, modexpMetaData); tenthImcFragment.callMmu(mmuCall); } final ImcFragment eleventhImcFragment = ImcFragment.empty(hub); fragments().add(eleventhImcFragment); - if (modExpMetadata.mbsNonZero() && !parentReturnDataTarget.isEmpty()) { - final MmuCall mmuCall = forModexpPartialResultCopy(hub, this, modExpMetadata); + if (modexpMetaData.mbsNonZero() && !parentReturnDataTarget.isEmpty()) { + final MmuCall mmuCall = forModexpPartialResultCopy(hub, this, modexpMetaData); eleventhImcFragment.callMmu(mmuCall); } }