Skip to content

Commit

Permalink
some more fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Francois Bojarski <[email protected]>
  • Loading branch information
letypequividelespoubelles committed Oct 10, 2024
1 parent f2a4d0f commit 3037ade
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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> hash;
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 3037ade

Please sign in to comment.