diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index e161c5ce8..05769186a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -1052,7 +1052,7 @@ void traceOpcode(MessageFrame frame) { case OpCode.CALLDATACOPY -> new CallDataCopySection(this); case OpCode.RETURNDATACOPY -> new ReturnDataCopySection(this); case OpCode.CODECOPY -> new CodeCopySection(this); - case OpCode.EXTCODECOPY -> new ExtCodeCopySection(this); + case OpCode.EXTCODECOPY -> new ExtCodeCopySection(this, frame); default -> throw new RuntimeException( "Invalid instruction: " + this.opCode().toString() + " not in the COPY family"); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/ExtCodeCopy.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/ExtCodeCopy.java index 0737faaad..b6d41b896 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/ExtCodeCopy.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/ExtCodeCopy.java @@ -23,9 +23,11 @@ import net.consensys.linea.zktracer.module.hub.defer.PostConflationDefer; import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.romlex.ContractMetadata; +import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.internal.Words; import org.hyperledger.besu.evm.worldstate.WorldView; @@ -42,23 +44,27 @@ public ExtCodeCopy(final Hub hub) { this.hub = hub; hub.defers().scheduleForPostConflation(this); - final Address foreignCodeAddress = Words.toAddress(hub.messageFrame().getStackItem(0)); + final CallFrame callFrame = hub.currentFrame(); + final MessageFrame frame = callFrame.frame(); + + final Address foreignCodeAddress = Words.toAddress(frame.getStackItem(0)); this.contract = ContractMetadata.canonical(hub, foreignCodeAddress); - this.targetId(hub.currentFrame().contextNumber()) - .targetRamBytes( - Optional.of( - hub.currentFrame() - .frame() - .shadowReadMemory(0, hub.currentFrame().frame().memoryByteSize()))) - .sourceOffset(EWord.of(hub.messageFrame().getStackItem(2))) - .targetOffset(EWord.of(hub.messageFrame().getStackItem(1))) - .size(Words.clampedToLong(hub.messageFrame().getStackItem(3))) + this.targetId(callFrame.contextNumber()) + .targetRamBytes(Optional.of(frame.shadowReadMemory(0, frame.memoryByteSize()))) + .sourceOffset(EWord.of(frame.getStackItem(2))) + .targetOffset(EWord.of(frame.getStackItem(1))) + .size(Words.clampedToLong(frame.getStackItem(3))) .setRom(); } @Override public Optional exoBytes() { + // If the EXT address is underDeployment, we set the ref size at 0, so we don't require exoBytes + // (which would be the init code) + if (contract.underDeployment()) { + return Optional.of(Bytes.EMPTY); + } try { return Optional.of(hub.romLex().getCodeByMetadata(contract)); } catch (Exception ignored) { @@ -70,7 +76,7 @@ public Optional exoBytes() { @Override public long referenceSize() { try { - return (hub.romLex().getCodeByMetadata(contract).size()); + return contract.underDeployment() ? 0 : (hub.romLex().getCodeByMetadata(contract).size()); } catch (Exception ignored) { // Can be 0 in case the ext account is empty. In this case, no associated CFI return 0; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java index e1338be95..f08827cda 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/ExtCodeCopySection.java @@ -51,11 +51,10 @@ public class ExtCodeCopySection extends TraceSection implements PostRollbackDefe AccountSnapshot undoingAccountSnapshotBefore; AccountSnapshot undoingAccountSnapshotAfter; - public ExtCodeCopySection(Hub hub) { + public ExtCodeCopySection(Hub hub, MessageFrame frame) { // 4 = 1 + 3 super(hub, maxNumberOfRows(hub)); - final MessageFrame frame = hub.messageFrame(); rawAddress = frame.getStackItem(0); address = Address.extract(Bytes32.leftPad(rawAddress)); incomingDeploymentNumber = hub.deploymentNumberOf(address); @@ -66,10 +65,6 @@ public ExtCodeCopySection(Hub hub) { this.addStack(hub); this.addFragment(imcFragment); - // triggerExp = false - // triggerOob = false - // triggerStp = false - // triggerMxp = true final MxpCall mxpCall = new MxpCall(hub); imcFragment.callMxp(mxpCall); @@ -122,8 +117,7 @@ public ExtCodeCopySection(Hub hub) { final boolean foreignAccountHasCode = foreignAccount != null && foreignAccount.hasCode(); final boolean triggerRomLex = triggerMmu && foreignAccountHasCode; - doingAccountSnapshotAfter = doingAccountSnapshotBefore.deepCopy(); - doingAccountSnapshotAfter.turnOnWarmth(); + doingAccountSnapshotAfter = doingAccountSnapshotBefore.deepCopy().turnOnWarmth(); final AccountFragment accountDoingFragment = hub.factories() @@ -135,7 +129,7 @@ public ExtCodeCopySection(Hub hub) { doingDomSubStamps); accountDoingFragment.requiresRomlex(triggerRomLex); if (triggerRomLex) { - hub.romLex().callRomLex(hub.messageFrame()); + hub.romLex().callRomLex(frame); } this.addFragment(accountDoingFragment);