Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDENTITY size parameter fix #1561

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public static MmuCall fullResultTransferForShaTwoAndRipemd(
}
}

public static MmuCall partialReturnDataCopyForShaTwoAndRipemd(
public static MmuCall partialCopyOfReturnDataForShaTwoAndRipemd(
final Hub hub, PrecompileSubsection subsection) {

final PrecompileScenarioFragment.PrecompileFlag flag =
Expand All @@ -417,7 +417,8 @@ public static MmuCall partialReturnDataCopyForShaTwoAndRipemd(
.referenceSize(subsection.returnAtCapacity());
}

public static MmuCall forIdentityExtractCallData(final Hub hub, PrecompileSubsection subsection) {
public static MmuCall callDataExtractionForIdentity(
final Hub hub, PrecompileSubsection subsection) {

return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING)
.sourceId(hub.currentFrame().contextNumber()) // called at ContextReEntry
Expand All @@ -429,17 +430,20 @@ public static MmuCall forIdentityExtractCallData(final Hub hub, PrecompileSubsec
.referenceSize(subsection.callDataSize());
}

public static MmuCall forIdentityReturnData(
public static MmuCall partialCopyOfReturnDataForIdentity(
final Hub hub, final PrecompileSubsection subsection) {

checkState(subsection.callDataSize() == subsection.returnDataSize());
checkState(subsection.returnDataOffset() == 0);

return new MmuCall(hub, MMU_INST_RAM_TO_RAM_SANS_PADDING)
.sourceId(subsection.exoModuleOperationId())
.sourceRamBytes(Optional.of(subsection.returnDataRange.extract()))
.targetId(hub.currentFrame().contextNumber())
.targetRamBytes(Optional.of(subsection.rawCallerMemory()))
.sourceOffset(EWord.ZERO)
.size(subsection.returnDataSize())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the real fix.

.referenceOffset(subsection.returnAtOffset())
.size(subsection.returnAtCapacity())
.referenceSize(subsection.returnAtCapacity());
}

Expand All @@ -458,7 +462,7 @@ public static MmuCall callDataExtractionForEcadd(
.phase(PHASE_ECADD_DATA);
}

public static MmuCall fullReturnDataTransferForEcadd(
public static MmuCall fullTransferOfReturnDataForEcadd(
final Hub hub, PrecompileSubsection subsection, boolean successBit) {
return new MmuCall(hub, MMU_INST_EXO_TO_RAM_TRANSPLANTS)
.sourceId(subsection.exoModuleOperationId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) {
}
case PRC_ECADD -> {
if (nonemptyCallData) {
secondMmuCall = MmuCall.fullReturnDataTransferForEcadd(hub, this, successBitMmuCall);
secondMmuCall = MmuCall.fullTransferOfReturnDataForEcadd(hub, this, successBitMmuCall);
}
if (callerMayReceiveReturnData) {
thirdMmuCall = MmuCall.partialCopyOfReturnDataForEcadd(hub, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection;

import static com.google.common.base.Preconditions.*;
import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forIdentityExtractCallData;
import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.forIdentityReturnData;
import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.callDataExtractionForIdentity;
import static net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall.partialCopyOfReturnDataForIdentity;
import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_IDENTITY;
import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.PRC_FAILURE_KNOWN_TO_HUB;

Expand Down Expand Up @@ -57,14 +57,14 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) {

final boolean extractCallData = callSuccess && !getCallDataRange().isEmpty();
if (extractCallData) {
final MmuCall mmuCall = forIdentityExtractCallData(hub, this);
final MmuCall mmuCall = callDataExtractionForIdentity(hub, this);
firstImcFragment.callMmu(mmuCall);
}

final ImcFragment secondImcFragment = ImcFragment.empty(hub);
fragments().add(secondImcFragment);
if (extractCallData && !getReturnAtRange().isEmpty()) {
final MmuCall mmuCall = forIdentityReturnData(hub, this);
final MmuCall mmuCall = partialCopyOfReturnDataForIdentity(hub, this);
secondImcFragment.callMmu(mmuCall);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ public long returnAtCapacity() {
return getReturnAtRange().size();
}

public long returnDataOffset() {
return returnDataRange().offset();
}

public long returnDataSize() {
return returnDataRange().size();
}

public Bytes rawCallerMemory() {
return callSection.getCallDataRange().getRawData();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) {
// provided a nonempty return data target
if (!getReturnAtRange().isEmpty()) {
final MmuCall partialReturnDataCopy =
MmuCall.partialReturnDataCopyForShaTwoAndRipemd(hub, this);
MmuCall.partialCopyOfReturnDataForShaTwoAndRipemd(hub, this);
thirdImcFragment.callMmu(partialReturnDataCopy);
}
}
Expand Down
Loading