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

fix last MMU call issues #1569

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Bytes> 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) {
Expand All @@ -70,7 +76,7 @@ public Optional<Bytes> exoBytes() {
@Override
public long referenceSize() {
try {
return (hub.romLex().getCodeByMetadata(contract).size());
return contract.underDeployment() ? 0 : (hub.romLex().getCodeByMetadata(contract).size());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fix

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

} catch (Exception ignored) {
// Can be 0 in case the ext account is empty. In this case, no associated CFI
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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()
Expand All @@ -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);

Expand Down
Loading