From 3037ade3a784d1b64fb409104a1db9d132673ac8 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Thu, 10 Oct 2024 18:17:53 +0530 Subject: [PATCH] some more fixes Signed-off-by: Francois Bojarski --- .../hub/fragment/imc/mmu/opcode/CodeCopy.java | 4 +-- .../hub/section/copy/CodeCopySection.java | 19 +++----------- .../zktracer/module/mmu/MmuOperation.java | 26 ++++++++++--------- .../linea/zktracer/types/Bytecode.java | 14 +++------- linea-constraints | 2 +- 5 files changed, 24 insertions(+), 41 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/CodeCopy.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/CodeCopy.java index 1ae9b31323..2534e6955f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/CodeCopy.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/imc/mmu/opcode/CodeCopy.java @@ -38,7 +38,7 @@ public CodeCopy(final Hub hub) { this.hub = hub; this.contract = hub.currentFrame().metadata(); - this.exoBytes(Optional.of(hub.romLex().getCodeByMetadata(contract))) + this.exoBytes(Optional.of(hub.currentFrame().code().bytecode())) .targetId(hub.currentFrame().contextNumber()) .targetRamBytes( Optional.of( @@ -54,6 +54,6 @@ public CodeCopy(final Hub hub) { @Override public int sourceId() { - return this.hub.romLex().getCodeFragmentIndexByMetadata(this.contract); + return hub.romLex().getCodeFragmentIndexByMetadata(contract); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java index c56f8b7dbc..abe1df070e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/copy/CodeCopySection.java @@ -28,9 +28,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.evm.account.Account; -import org.hyperledger.besu.evm.frame.MessageFrame; public class CodeCopySection extends TraceSection { @@ -66,19 +63,9 @@ public CodeCopySection(Hub hub) { this.addFragment(contextFragment); // Account row - final MessageFrame frame = hub.messageFrame(); - final Address codeAddress = frame.getContractAddress(); - final Account codeAccount = frame.getWorldUpdater().get(codeAddress); - - final boolean warmth = frame.isAddressWarm(codeAddress); - checkArgument(warmth); - final AccountSnapshot codeAccountSnapshot = - AccountSnapshot.fromAccount( - codeAccount, - warmth, - hub.deploymentNumberOf(codeAddress), - hub.deploymentStatusOf(codeAddress)); + AccountSnapshot.canonical(hub, hub.messageFrame().getContractAddress()); + checkArgument(codeAccountSnapshot.isWarm()); final DomSubStampsSubFragment doingDomSubStamps = DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0); // Specifics for CODECOPY @@ -94,7 +81,7 @@ public CodeCopySection(Hub hub) { final boolean triggerMmu = mxpCall.mayTriggerNontrivialMmuOperation; if (triggerMmu) { - MmuCall mmuCall = MmuCall.codeCopy(hub); + final MmuCall mmuCall = MmuCall.codeCopy(hub); imcFragment.callMmu(mmuCall); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java index b040713d97..cc38b9783c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/mmu/MmuOperation.java @@ -35,6 +35,7 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_RIGHT_PADDED_WORD_EXTRACTION; import static net.consensys.linea.zktracer.module.mmio.MmioData.lineCountOfMmioInstruction; import static net.consensys.linea.zktracer.types.Bytecodes.readBytes; +import static net.consensys.linea.zktracer.types.Bytecodes.readLimb; import static net.consensys.linea.zktracer.types.Conversions.*; import java.util.ArrayList; @@ -164,18 +165,19 @@ public void fillLimb() { // Limb remains zero for LIMB_VANISHES instructions if (mmioInst.mmioInstruction() != MMIO_INST_LIMB_VANISHES) { - final int offset = - (int) - (exoIsSource - ? mmioInst.sourceLimbOffset() * LLARGE + mmioInst.sourceByteOffset() - : mmioInst.targetLimbOffset() * LLARGE + mmioInst.targetByteOffset()); - final int sizeToExtract = mmioInst.size() == 0 ? LLARGE : mmioInst.size(); - final int exoByteOffset = - exoIsSource ? mmioInst.sourceByteOffset() : mmioInst.targetByteOffset(); - final Bytes16 exoLimb = - readBytes(mmuData.exoBytes(), offset, sizeToExtract, exoByteOffset); - ; - mmioInst.limb(exoLimb); + + if (exoIsSource) { + mmioInst.limb(readLimb(mmuData.exoBytes(), mmioInst.sourceLimbOffset())); + } else { + final int offset = + (int) mmioInst.targetLimbOffset() * LLARGE + mmioInst.targetByteOffset(); + final int sizeToExtract = mmioInst.size() == 0 ? LLARGE : mmioInst.size(); + final int exoByteOffset = mmioInst.targetByteOffset(); + final Bytes16 exoLimb = + readBytes(mmuData.exoBytes(), offset, sizeToExtract, exoByteOffset); + ; + mmioInst.limb(exoLimb); + } } } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Bytecode.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Bytecode.java index d5c9ad76df..f916ef74be 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Bytecode.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/Bytecode.java @@ -18,12 +18,15 @@ import java.util.Objects; import java.util.concurrent.*; +import lombok.Getter; +import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.evm.Code; @Slf4j +@Accessors(fluent = true) /** This class is intended to store a bytecode and its memoized hash. */ public final class Bytecode { /** initializing the executor service before creating the EMPTY bytecode. */ @@ -33,7 +36,7 @@ public final class Bytecode { public static Bytecode EMPTY = new Bytecode(Bytes.EMPTY); /** The bytecode. */ - private final Bytes bytecode; + @Getter private final Bytes bytecode; /** The bytecode hash; precomputed & memoized asynchronously. */ private Future hash; @@ -67,15 +70,6 @@ public int getSize() { return this.bytecode.size(); } - /** - * Expose the wrapped bytecode as {@link Bytes}. - * - * @return the bytecode - */ - public Bytes getBytes() { - return this.bytecode; - } - /** * Returns whether the bytecode is empty or not. * diff --git a/linea-constraints b/linea-constraints index 1bebc8a68e..60e2dcaecb 160000 --- a/linea-constraints +++ b/linea-constraints @@ -1 +1 @@ -Subproject commit 1bebc8a68e7c8cc46171dd8ecce339f2a2559513 +Subproject commit 60e2dcaecb79be6c3a1b0cf0482dd14f3beabbfa