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

perf(MMU): discard CallStackReader #988

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@

package net.consensys.linea.zktracer.module.blake2fmodexpdata;

import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_BLAKE_DATA;
import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_BLAKE_RESULT;
import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_MODEXP_BASE;
import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_MODEXP_EXPONENT;
import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_MODEXP_MODULUS;
import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_MODEXP_RESULT;

import java.nio.MappedByteBuffer;
import java.util.List;

Expand All @@ -34,7 +27,6 @@
import net.consensys.linea.zktracer.module.limits.precompiles.BlakeRounds;
import net.consensys.linea.zktracer.module.limits.precompiles.ModexpEffectiveCall;
import net.consensys.linea.zktracer.module.wcp.Wcp;
import org.apache.tuweni.bytes.Bytes;

@RequiredArgsConstructor
public class BlakeModexpData implements Module {
Expand Down Expand Up @@ -98,27 +90,4 @@ public void commit(List<MappedByteBuffer> buffers) {
o.trace(trace, stamp);
}
}

// TODO: this should die, the MMU just have to read in MmuCall
public Bytes getInputDataByIdAndPhase(final int id, final int phase) {
final BlakeModexpDataOperation op = getOperationById(id);
return switch (phase) {
case PHASE_MODEXP_BASE -> op.modexpMetaData.get().base();
case PHASE_MODEXP_EXPONENT -> op.modexpMetaData.get().exp();
case PHASE_MODEXP_MODULUS -> op.modexpMetaData.get().mod();
case PHASE_MODEXP_RESULT -> Bytes.EMPTY; // TODO
case PHASE_BLAKE_DATA -> op.blake2fComponents.get().data();
case PHASE_BLAKE_RESULT -> Bytes.EMPTY; // TODO
default -> throw new IllegalStateException("Unexpected value: " + phase);
};
}

private BlakeModexpDataOperation getOperationById(final int id) {
for (BlakeModexpDataOperation operation : this.operations) {
if (id == operation.id) {
return operation;
}
}
throw new RuntimeException("BlakeModexpOperation not found");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

@Accessors(fluent = true)
public class BlakeModexpDataOperation extends ModuleOperation {
private static final int MODEXP_COMPONENT_BYTE_SIZE = LLARGE * (INDEX_MAX_MODEXP + 1);
public static final int MODEXP_COMPONENT_BYTE_SIZE = LLARGE * (INDEX_MAX_MODEXP + 1);
private static final int MODEXP_COMPONENTS_LINE_COUNT =
(INDEX_MAX_MODEXP_BASE + 1)
+ (INDEX_MAX_MODEXP_EXPONENT + 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,17 +386,8 @@ public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) {
this.keccak = new Keccak(ecRecoverEffectiveCall, l2Block);
this.shakiraData = new ShakiraData(wcp, sha256Blocks, keccak, ripemdBlocks);
this.blockdata = new Blockdata(this.wcp, this.txnData, this.rlpTxn);
this.mmu =
new Mmu(
this.euc,
this.wcp,
this.romLex,
this.rlpTxn,
this.rlpTxnRcpt,
this.ecData,
this.blakeModexpData,
this.callStack);
this.mmio = new Mmio(this.mmu);
this.mmu = new Mmu(euc, wcp);
this.mmio = new Mmio(mmu);

this.refTableModules = List.of(new BinRt(), new InstructionDecoder(), new ShfRt());

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public CodeCopy(final Hub hub) {
this.hub = hub;
this.contract = hub.currentFrame().metadata();

this.targetId(hub.currentFrame().contextNumber())
this.exoBytes(Optional.of(hub.romLex().getCodeByMetadata(contract)))
letypequividelespoubelles marked this conversation as resolved.
Show resolved Hide resolved
.targetId(hub.currentFrame().contextNumber())
.targetRamBytes(
Optional.of(
hub.currentFrame()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public Create(final Hub hub) {
hub.currentFrame()
.frame()
.shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize())))
.exoBytes(Optional.of(hub.romLex().getCodeByMetadata(contract)))
letypequividelespoubelles marked this conversation as resolved.
Show resolved Hide resolved
.sourceOffset(EWord.of(hub.messageFrame().getStackItem(1)))
.size(Words.clampedToLong(hub.messageFrame().getStackItem(2)))
.referenceSize(Words.clampedToLong(hub.messageFrame().getStackItem(2)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public Create2(final Hub hub, final boolean failedCreate) {
hub.currentFrame()
.frame()
.shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize())))
.exoBytes(Optional.of(hub.romLex().getCodeByMetadata(contract)))
.auxId(hub.state().stamps().hub())
.sourceOffset(EWord.of(hub.messageFrame().getStackItem(1)))
.size(Words.clampedToLong(hub.messageFrame().getStackItem(2)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public ExtCodeCopy(final Hub hub) {
hub.transients().conflation().deploymentInfo().number(sourceAddress),
hub.transients().conflation().deploymentInfo().isDeploying(sourceAddress));

this.targetId(hub.currentFrame().contextNumber())
this.exoBytes(Optional.of(hub.romLex().getCodeByMetadata(contract)))
.targetId(hub.currentFrame().contextNumber())
.targetRamBytes(
Optional.of(
hub.currentFrame()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_RAM_TO_EXO_WITH_PADDING;

import java.util.Optional;

import net.consensys.linea.zktracer.module.hub.Hub;
import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall;
import net.consensys.linea.zktracer.module.romlex.ContractMetadata;
Expand All @@ -43,6 +45,12 @@ public ReturnFromDeployment(final Hub hub) {
this.contract = ContractMetadata.underDeployment(contractAddress, depNumber);

this.sourceId(hub.currentFrame().contextNumber())
.sourceRamBytes(
Optional.of(
hub.currentFrame()
.frame()
.shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize())))
.exoBytes(Optional.of(hub.romLex().getCodeByMetadata(contract)))
.auxId(hub.state().stamps().hub())
.sourceOffset(EWord.of(hub.messageFrame().getStackItem(0)))
.size(Words.clampedToLong(hub.messageFrame().getStackItem(1)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
@Getter
@Accessors(fluent = true)
public class ModexpMetadata {
static final int BBS_MIN_OFFSET = 0x00;
static final int EBS_MIN_OFFSET = 0x20;
static final int MBS_MIN_OFFSET = 0x40;
static final int BASE_MIN_OFFSET = 0x60;
public static final int BBS_MIN_OFFSET = 0x00;
public static final int EBS_MIN_OFFSET = 0x20;
public static final int MBS_MIN_OFFSET = 0x40;
public static final int BASE_MIN_OFFSET = 0x60;

private final Bytes callData;
private final EWord rawLeadingWord;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public KeccakSection(Hub hub) {
triggerMmu = mayTriggerNonTrivialOperation & Exceptions.none(hub.pch().exceptions());

if (triggerMmu) {
final MmuCall mmuCall = MmuCall.sha3(hub);
imcFragment.callMmu(mmuCall);
final long offset = Words.clampedToLong(hub.messageFrame().getStackItem(0));
final long size = Words.clampedToLong(hub.messageFrame().getStackItem(1));
hashInput = hub.currentFrame().frame().shadowReadMemory(offset, size);
final MmuCall mmuCall = MmuCall.sha3(hub, hashInput);
imcFragment.callMmu(mmuCall);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@
import com.google.common.base.Preconditions;
import net.consensys.linea.zktracer.module.hub.Hub;
import net.consensys.linea.zktracer.module.hub.defer.PostRollbackDefer;
import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer;
import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment;
import net.consensys.linea.zktracer.module.hub.fragment.imc.ImcFragment;
import net.consensys.linea.zktracer.module.hub.fragment.imc.MxpCall;
import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall;
import net.consensys.linea.zktracer.module.hub.signals.Exceptions;
import net.consensys.linea.zktracer.runtime.LogData;
import net.consensys.linea.zktracer.runtime.callstack.CallFrame;
import org.hyperledger.besu.datatypes.Transaction;
import org.hyperledger.besu.evm.frame.MessageFrame;
import org.hyperledger.besu.evm.worldstate.WorldView;

public class LogSection extends TraceSection implements PostRollbackDefer {
public class LogSection extends TraceSection implements PostRollbackDefer, PostTransactionDefer {

MmuCall mmuCall;
private MmuCall mmuCall;
private boolean logReverted = false;

public LogSection(Hub hub) {
super(hub, maxNumberOfRows(hub));
Expand Down Expand Up @@ -69,6 +73,8 @@ public LogSection(Hub hub) {
// the unexceptional case
Preconditions.checkArgument(Exceptions.none(exceptions));

hub.defers().scheduleForPostTransaction(this);

final LogData logData = new LogData(hub);
Preconditions.checkArgument(
logData.nontrivialLog() == mxpCall.mayTriggerNontrivialMmuOperation);
Expand All @@ -88,8 +94,21 @@ private static short maxNumberOfRows(Hub hub) {

@Override
public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame callFrame) {
logReverted = true;
if (mmuCall != null) {
mmuCall.dontTraceMe();
}
}

@Override
public void resolvePostTransaction(
Hub hub, WorldView state, Transaction tx, boolean isSuccessful) {
if (!logReverted) {
hub.state.stamps().incrementLogStamp();
commonValues.logStamp(hub.state.stamps().log());
if (mmuCall != null) {
mmuCall.targetId(hub.state.stamps().log());
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.consensys.linea.zktracer.module.mmu.ExoSumDecoder;
import net.consensys.linea.zktracer.module.mmu.values.HubToMmuValues;
import net.consensys.linea.zktracer.module.mmu.values.MmuToMmioConstantValues;
import net.consensys.linea.zktracer.module.mmu.values.MmuToMmioInstruction;
Expand Down Expand Up @@ -90,7 +89,6 @@ public class MmioData {
private final int kecId;
private final int phase;
private final boolean successBit;
private final ExoSumDecoder exoSumDecoder;
private final boolean targetLimbIsTouchedTwice;

private long indexX;
Expand All @@ -112,8 +110,7 @@ public class MmioData {
public MmioData(
HubToMmuValues hubToMmuValues,
MmuToMmioConstantValues mmuToMmioConstantValues,
MmuToMmioInstruction mmuToMmioInstruction,
ExoSumDecoder exoSumDecoder) {
MmuToMmioInstruction mmuToMmioInstruction) {
this(
0,
0,
Expand Down Expand Up @@ -149,7 +146,6 @@ public MmioData(
mmuToMmioConstantValues.kecId(),
mmuToMmioConstantValues.phase(),
mmuToMmioConstantValues.successBit(),
exoSumDecoder,
mmuToMmioInstruction.targetLimbIsTouchedTwice(),
0,
new ArrayList<>(LLARGE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

@Accessors(fluent = true)
public class MmioInstructions {
private Map<Integer, MmioInstruction> mmioInstructionMap;
private final Map<Integer, MmioInstruction> mmioInstructionMap;

public MmioInstructions(final MmuData mmuData, final int mmioInstructionNumber) {
mmioInstructionMap =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,19 @@
import static net.consensys.linea.zktracer.module.mmio.MmioPatterns.updateTemporaryTargetRam;
import static net.consensys.linea.zktracer.types.Bytecodes.readLimb;

import lombok.RequiredArgsConstructor;
import net.consensys.linea.zktracer.module.mmio.MmioData;
import net.consensys.linea.zktracer.module.mmu.MmuData;
import net.consensys.linea.zktracer.module.mmu.values.MmuToMmioConstantValues;
import net.consensys.linea.zktracer.module.mmu.values.MmuToMmioInstruction;
import net.consensys.linea.zktracer.types.Bytes16;

@RequiredArgsConstructor
public class LimbToRamOneTarget implements MmioInstruction {
private final MmuData mmuData;
public class LimbToRamOneTarget extends MmioInstruction {

private final int instructionNumber;
public LimbToRamOneTarget(MmuData mmuData, int instructionNumber) {
super(mmuData, instructionNumber);
}

@Override
public MmioData execute() {
final MmuToMmioConstantValues mmuToMmioConstantValues = mmuData.mmuToMmioConstantValues();
final MmuToMmioInstruction mmuToMmioInstruction =
mmuData.mmuToMmioInstructions().get(instructionNumber);

MmioData mmioData =
new MmioData(
mmuData.hubToMmuValues(),
mmuToMmioConstantValues,
mmuToMmioInstruction,
mmuData.exoSumDecoder());
final MmioData mmioData = super.execute();
letypequividelespoubelles marked this conversation as resolved.
Show resolved Hide resolved

mmioData.cnA(mmioData.targetContext());
mmioData.cnB(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,19 @@

import static net.consensys.linea.zktracer.types.Bytecodes.readLimb;

import lombok.RequiredArgsConstructor;
import net.consensys.linea.zktracer.module.mmio.MmioData;
import net.consensys.linea.zktracer.module.mmu.MmuData;
import net.consensys.linea.zktracer.module.mmu.values.MmuToMmioConstantValues;
import net.consensys.linea.zktracer.module.mmu.values.MmuToMmioInstruction;
import net.consensys.linea.zktracer.types.Bytes16;

@RequiredArgsConstructor
public class LimbToRamTransplant implements MmioInstruction {
private final MmuData mmuData;
public class LimbToRamTransplant extends MmioInstruction {

private final int instructionNumber;
public LimbToRamTransplant(MmuData mmuData, int instructionNumber) {
super(mmuData, instructionNumber);
}

@Override
public MmioData execute() {
final MmuToMmioConstantValues mmuToMmioConstantValues = mmuData.mmuToMmioConstantValues();
final MmuToMmioInstruction mmuToMmioInstruction =
mmuData.mmuToMmioInstructions().get(instructionNumber);

MmioData mmioData =
new MmioData(
mmuData.hubToMmuValues(),
mmuToMmioConstantValues,
mmuToMmioInstruction,
mmuData.exoSumDecoder());
final MmioData mmioData = super.execute();

mmioData.cnA(mmioData.targetContext());
mmioData.cnB(0);
Expand Down
Loading
Loading