Skip to content

Commit

Permalink
some HUB debugging (#1467)
Browse files Browse the repository at this point in the history
  • Loading branch information
letypequividelespoubelles authored Nov 4, 2024
1 parent 34122c0 commit 10d5745
Show file tree
Hide file tree
Showing 33 changed files with 1,691 additions and 1,340 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_INIT;
import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_SKIP;
import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_WARM;
import static net.consensys.linea.zktracer.module.hub.Trace.MULTIPLIER___STACK_HEIGHT;
import static net.consensys.linea.zktracer.module.hub.Trace.MULTIPLIER___STACK_STAMP;
import static net.consensys.linea.zktracer.module.hub.signals.TracedException.*;
import static net.consensys.linea.zktracer.opcode.OpCode.RETURN;
import static net.consensys.linea.zktracer.opcode.OpCode.REVERT;
Expand All @@ -36,7 +36,6 @@
import java.util.Set;
import java.util.stream.Stream;

import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -55,25 +54,7 @@
import net.consensys.linea.zktracer.module.hub.defer.DeferRegistry;
import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment;
import net.consensys.linea.zktracer.module.hub.fragment.StackFragment;
import net.consensys.linea.zktracer.module.hub.section.AccountSection;
import net.consensys.linea.zktracer.module.hub.section.CallDataLoadSection;
import net.consensys.linea.zktracer.module.hub.section.ContextSection;
import net.consensys.linea.zktracer.module.hub.section.CreateSection;
import net.consensys.linea.zktracer.module.hub.section.EarlyExceptionSection;
import net.consensys.linea.zktracer.module.hub.section.ExpSection;
import net.consensys.linea.zktracer.module.hub.section.JumpSection;
import net.consensys.linea.zktracer.module.hub.section.KeccakSection;
import net.consensys.linea.zktracer.module.hub.section.LogSection;
import net.consensys.linea.zktracer.module.hub.section.SloadSection;
import net.consensys.linea.zktracer.module.hub.section.SstoreSection;
import net.consensys.linea.zktracer.module.hub.section.StackOnlySection;
import net.consensys.linea.zktracer.module.hub.section.StackRamSection;
import net.consensys.linea.zktracer.module.hub.section.TraceSection;
import net.consensys.linea.zktracer.module.hub.section.TransactionSection;
import net.consensys.linea.zktracer.module.hub.section.TxFinalizationSection;
import net.consensys.linea.zktracer.module.hub.section.TxInitializationSection;
import net.consensys.linea.zktracer.module.hub.section.TxPreWarmingMacroSection;
import net.consensys.linea.zktracer.module.hub.section.TxSkippedSection;
import net.consensys.linea.zktracer.module.hub.section.*;
import net.consensys.linea.zktracer.module.hub.section.call.CallSection;
import net.consensys.linea.zktracer.module.hub.section.copy.CallDataCopySection;
import net.consensys.linea.zktracer.module.hub.section.copy.CodeCopySection;
Expand Down Expand Up @@ -228,7 +209,7 @@ public int lineCount() {
private final RlpTxnRcpt rlpTxnRcpt = new RlpTxnRcpt();
private final LogInfo logInfo = new LogInfo(rlpTxnRcpt);
private final LogData logData = new LogData(rlpTxnRcpt);
private final RlpAddr rlpAddr = new RlpAddr(this, trm);
@Getter private final RlpAddr rlpAddr = new RlpAddr(this, trm);

// modules triggered by sub-fragments of the MISCELLANEOUS / IMC perspective
@Getter private final Mxp mxp = new Mxp();
Expand Down Expand Up @@ -405,7 +386,7 @@ public Hub(
final Address l2l1ContractAddress,
final Bytes l2l1Topic,
final BigInteger nonnegativeChainId) {
Preconditions.checkState(nonnegativeChainId.signum() >= 0);
checkState(nonnegativeChainId.signum() >= 0);
chainId = nonnegativeChainId;
l2Block = new L2Block(l2l1ContractAddress, LogTopic.of(l2l1Topic));
l2L1Logs = new L2L1Logs(l2Block);
Expand Down Expand Up @@ -624,6 +605,10 @@ public void traceContextEnter(MessageFrame frame) {
// internal transaction (CALL) or internal deployment (CREATE)
if (frame.getDepth() > 0) {
final OpCode currentOpCode = callStack.currentCallFrame().opCode();
checkState(currentOpCode.isCall() || currentOpCode.isCreate());
checkState(
currentTraceSection() instanceof CallSection
|| currentTraceSection() instanceof CreateSection);
final boolean isDeployment = frame.getType() == CONTRACT_CREATION;
final CallFrameType frameType =
frame.isStatic() ? CallFrameType.STATIC : CallFrameType.STANDARD;
Expand Down Expand Up @@ -651,6 +636,11 @@ public void traceContextEnter(MessageFrame frame) {
currentFrame().rememberGasNextBeforePausing();
currentFrame().pauseCurrentFrame();

MemorySpan returnDataTargetInCaller =
(currentTraceSection() instanceof CallSection)
? ((CallSection) currentTraceSection()).getCallProvidedReturnDataTargetSpan()
: MemorySpan.empty();

callStack.enter(
frameType,
newChildContextNumber(),
Expand All @@ -666,7 +656,8 @@ public void traceContextEnter(MessageFrame frame) {
frame.getInputData(),
callDataOffset,
callDataSize,
callDataContextNumber);
callDataContextNumber,
returnDataTargetInCaller);

this.currentFrame().initializeFrame(frame);

Expand Down Expand Up @@ -905,7 +896,7 @@ public final MessageFrame messageFrame() {
private void handleStack(MessageFrame frame) {
this.currentFrame()
.stack()
.processInstruction(this, frame, MULTIPLIER___STACK_HEIGHT * (stamp() + 1));
.processInstruction(this, frame, MULTIPLIER___STACK_STAMP * (stamp() + 1));
}

void triggerModules(MessageFrame frame) {
Expand All @@ -915,9 +906,6 @@ void triggerModules(MessageFrame frame) {
if (pch.signals().bin()) {
bin.tracePreOpcode(frame);
}
if (pch.signals().rlpAddr()) {
rlpAddr.tracePreOpcode(frame);
}
if (pch.signals().mul()) {
mul.tracePreOpcode(frame);
}
Expand Down Expand Up @@ -1024,17 +1012,13 @@ void traceOpcode(MessageFrame frame) {
failureConditionForCreates = false;

switch (this.opCodeData().instructionFamily()) {
case ADD,
MOD,
SHF,
BIN,
WCP,
EXT,
BATCH,
MACHINE_STATE,
PUSH_POP,
DUP,
SWAP -> new StackOnlySection(this);
case ADD, MOD, SHF, BIN, WCP, EXT, BATCH, PUSH_POP, DUP, SWAP -> new StackOnlySection(this);
case MACHINE_STATE -> {
switch (this.opCode()) {
case OpCode.MSIZE -> new MsizeSection(this);
default -> new StackOnlySection(this);
}
}
case MUL -> {
switch (this.opCode()) {
case OpCode.EXP -> new ExpSection(this);
Expand Down
Loading

0 comments on commit 10d5745

Please sign in to comment.