-
Notifications
You must be signed in to change notification settings - Fork 34
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
debug memory replay tests #1473
Changes from 26 commits
918baeb
616ffe5
8c26a05
8307f74
c76c97c
a3ba12c
a7fb00d
e88fb28
b3ff25d
544e866
ee573c0
170262d
4a1f3f3
2366a42
da448e4
ad1833c
5749926
1f9b6e9
54a9d6d
15ed434
6bd8e5f
93f82b8
8694243
75c4bc3
759a600
e38c9c8
79ba83c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ public class CommonFragmentValues { | |
public final HubProcessingPhase hubProcessingPhase; | ||
public final int hubStamp; | ||
public final CallStack callStack; | ||
public final State.TxState.Stamps stamps; // for MMU and MXP stamps | ||
public final State.TxState.Stamps stamps; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You provide the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
@Setter public int logStamp = -1; | ||
@Getter final CallFrame callFrame; | ||
public final short exceptions; | ||
|
Large diffs are not rendered by default.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this instruction missing altogether ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, it was in the CallDataLoadSection. But it was missing the postExecutiondefers to get the stack item directly from Besu |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright ConsenSys Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.opcode; | ||
|
||
import static net.consensys.linea.zktracer.module.constants.GlobalConstants.MMU_INST_RIGHT_PADDED_WORD_EXTRACTION; | ||
|
||
import java.util.Optional; | ||
|
||
import net.consensys.linea.zktracer.module.hub.Hub; | ||
import net.consensys.linea.zktracer.module.hub.defer.PostOpcodeDefer; | ||
import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; | ||
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.evm.frame.MessageFrame; | ||
import org.hyperledger.besu.evm.operation.Operation; | ||
|
||
public class CallDataLoad extends MmuCall implements PostOpcodeDefer { | ||
|
||
public CallDataLoad(final Hub hub) { | ||
super(hub, MMU_INST_RIGHT_PADDED_WORD_EXTRACTION); | ||
hub.defers().scheduleForPostExecution(this); | ||
|
||
final CallFrame currentFrame = hub.currentFrame(); | ||
final long callDataSize = currentFrame.callDataInfo().memorySpan().length(); | ||
final long callDataOffset = currentFrame.callDataInfo().memorySpan().offset(); | ||
final EWord sourceOffset = EWord.of(currentFrame.frame().getStackItem(0)); | ||
final long callDataCN = currentFrame.callDataInfo().callDataContextNumber(); | ||
final Bytes sourceBytes = hub.callStack().getFullMemoryOfCaller(hub); | ||
|
||
this.sourceId((int) callDataCN) | ||
.sourceRamBytes(Optional.of(sourceBytes)) | ||
.sourceOffset(sourceOffset) | ||
.referenceOffset(callDataOffset) | ||
.referenceSize(callDataSize); | ||
} | ||
|
||
@Override | ||
public void resolvePostExecution( | ||
Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { | ||
final EWord stack = EWord.of(frame.getStackItem(0)); | ||
this.limb1(stack.hi()); | ||
this.limb2(stack.lo()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ public class Create2 extends MmuCall implements RomLexDefer { | |
private final Hub hub; | ||
private ContractMetadata contract; | ||
|
||
public Create2(final Hub hub, final boolean failedCreate) { | ||
public Create2(final Hub hub, final Bytes create2initCode, final boolean failedCreate) { | ||
super(hub, MMU_INST_RAM_TO_EXO_WITH_PADDING); | ||
this.hub = hub; | ||
this.hub.romLex().createDefers().register(this); | ||
|
@@ -55,6 +55,7 @@ public Create2(final Hub hub, final boolean failedCreate) { | |
currentFrame.frame(), | ||
MemorySpan.fromStartLength(clampedToLong(sourceOffset), size)))) | ||
.auxId(newIdentifierFromStamp(hub.stamp())) | ||
.exoBytes(Optional.of(create2initCode)) | ||
.sourceOffset(sourceOffset) | ||
.size(size) | ||
.referenceSize(size) | ||
|
@@ -70,11 +71,6 @@ public int targetId() { | |
return exoIsRom ? hub.romLex().getCodeFragmentIndexByMetadata(contract) : 0; | ||
} | ||
|
||
@Override | ||
public Optional<Bytes> exoBytes() { | ||
return exoIsRom ? Optional.of(hub.romLex().getCodeByMetadata(contract)) : Optional.empty(); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this grabbing the currently executing bytecode in stead ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this was working well, except when the ROM is not set (ie in the case failure CREATE2), because we weren't able to get the initCode to hash in this case |
||
@Override | ||
public void updateContractMetadata(ContractMetadata metadata) { | ||
contract = metadata; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
import net.consensys.linea.zktracer.module.hub.fragment.imc.mmu.MmuCall; | ||
import net.consensys.linea.zktracer.module.hub.signals.Exceptions; | ||
import net.consensys.linea.zktracer.opcode.OpCode; | ||
import net.consensys.linea.zktracer.runtime.callstack.CallFrame; | ||
import net.consensys.linea.zktracer.types.EWord; | ||
import net.consensys.linea.zktracer.types.MemorySpan; | ||
import org.apache.tuweni.bytes.Bytes; | ||
|
@@ -62,47 +63,45 @@ public StackRamSection(Hub hub) { | |
// the unexceptional case | ||
checkArgument(Exceptions.none(exceptions)); | ||
|
||
final EWord offset = EWord.of(hub.currentFrame().frame().getStackItem(0)); | ||
final CallFrame currentFrame = hub.currentFrame(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've never been a fan of the |
||
final EWord offset = EWord.of(currentFrame.frame().getStackItem(0)); | ||
final long longOffset = Words.clampedToLong(offset); | ||
final Bytes currentRam = | ||
extractContiguousLimbsFromMemory( | ||
hub.currentFrame().frame(), new MemorySpan(longOffset, WORD_SIZE)); | ||
final int currentContextNumber = hub.currentFrame().contextNumber(); | ||
currentFrame.frame(), new MemorySpan(longOffset, WORD_SIZE)); | ||
final int currentContextNumber = currentFrame.contextNumber(); | ||
final EWord value = | ||
instruction.equals(OpCode.MLOAD) | ||
? EWord.of(hub.messageFrame().shadowReadMemory(Words.clampedToLong(offset), WORD_SIZE)) | ||
: EWord.of(hub.currentFrame().frame().getStackItem(1)); | ||
? EWord.of(currentFrame.frame().shadowReadMemory(longOffset, WORD_SIZE)) | ||
: EWord.of(currentFrame.frame().getStackItem(1)); | ||
|
||
MmuCall mmuCall; | ||
|
||
switch (instruction) { | ||
case MSTORE -> { | ||
mmuCall = | ||
new MmuCall(hub, MMU_INST_MSTORE) | ||
.targetId(currentContextNumber) | ||
.targetOffset(offset) | ||
.limb1(value.hi()) | ||
.limb2(value.lo()) | ||
.targetRamBytes(Optional.of(currentRam)); | ||
} | ||
case MSTORE8 -> { | ||
mmuCall = | ||
new MmuCall(hub, MMU_INST_MSTORE8) | ||
.targetId(currentContextNumber) | ||
.targetOffset(offset) | ||
.limb1(value.hi()) | ||
.limb2(value.lo()) | ||
.targetRamBytes(Optional.of(currentRam)); | ||
} | ||
case MLOAD -> { | ||
mmuCall = | ||
new MmuCall(hub, MMU_INST_MLOAD) | ||
.sourceId(currentContextNumber) | ||
.sourceOffset(offset) | ||
.limb1(value.hi()) | ||
.limb2(value.lo()) | ||
.sourceRamBytes(Optional.of(currentRam)); | ||
} | ||
case MSTORE -> mmuCall = | ||
new MmuCall(hub, MMU_INST_MSTORE) | ||
.targetId(currentContextNumber) | ||
.targetOffset(offset) | ||
.limb1(value.hi()) | ||
.limb2(value.lo()) | ||
.targetRamBytes(Optional.of(currentRam)); | ||
|
||
case MSTORE8 -> mmuCall = | ||
new MmuCall(hub, MMU_INST_MSTORE8) | ||
.targetId(currentContextNumber) | ||
.targetOffset(offset) | ||
.limb1(value.hi()) | ||
.limb2(value.lo()) | ||
.targetRamBytes(Optional.of(currentRam)); | ||
|
||
case MLOAD -> mmuCall = | ||
new MmuCall(hub, MMU_INST_MLOAD) | ||
.sourceId(currentContextNumber) | ||
.sourceOffset(offset) | ||
.limb1(value.hi()) | ||
.limb2(value.lo()) | ||
.sourceRamBytes(Optional.of(currentRam)); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block is just formatting, right ? |
||
default -> throw new IllegalStateException("Not a STACK_RAM instruction"); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,8 @@ public PrecompileSubsection(final Hub hub, final CallSection callSection) { | |
this.callSection = callSection; | ||
fragments = new ArrayList<>(maxNumberOfLines()); | ||
|
||
final MessageFrame messageFrame = hub.messageFrame(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a very general comment: Reasons for doing so: avoid synchronization issues. Kind of like the one we had wrt |
||
hub.defers().scheduleForImmediateContextEntry(this); // gas & input data, ... | ||
hub.defers().scheduleForContextExit(this, hub.callStack().futureId()); | ||
hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); // success bit & return data | ||
|
@@ -114,16 +116,15 @@ public PrecompileSubsection(final Hub hub, final CallSection callSection) { | |
final long offset = | ||
Words.clampedToLong( | ||
opCode.callCanTransferValue() | ||
? hub.messageFrame().getStackItem(3) | ||
: hub.messageFrame().getStackItem(2)); | ||
? messageFrame.getStackItem(3) | ||
: messageFrame.getStackItem(2)); | ||
final long length = | ||
Words.clampedToLong( | ||
opCode.callCanTransferValue() | ||
? hub.messageFrame().getStackItem(4) | ||
: hub.messageFrame().getStackItem(3)); | ||
? messageFrame.getStackItem(4) | ||
: messageFrame.getStackItem(3)); | ||
callDataMemorySpan = new MemorySpan(offset, length); | ||
callerMemorySnapshot = | ||
extractContiguousLimbsFromMemory(hub.currentFrame().frame(), callDataMemorySpan); | ||
callerMemorySnapshot = extractContiguousLimbsFromMemory(messageFrame, callDataMemorySpan); | ||
final int lengthToExtract = | ||
(int) Math.min(length, Math.max(callerMemorySnapshot.size() - offset, 0)); | ||
callData = rightPadTo(callerMemorySnapshot.slice((int) offset, lengthToExtract), (int) length); | ||
|
@@ -150,10 +151,13 @@ public void resolveUponContextExit(Hub hub, CallFrame callFrame) { | |
|
||
@Override | ||
public void resolveAtContextReEntry(Hub hub, CallFrame frame) { | ||
callSuccess = bytesToBoolean(hub.messageFrame().getStackItem(0)); | ||
callSuccess = bytesToBoolean(frame.frame().getStackItem(0)); | ||
returnData = frame.frame().getReturnData(); | ||
|
||
frame.returnDataContextNumber(exoModuleOperationId()); | ||
final int returnerCn = exoModuleOperationId(); | ||
final CallFrame returnerFrame = hub.callStack().getByContextNumber(returnerCn); | ||
returnerFrame.returnData(returnData); | ||
frame.returnDataContextNumber(returnerCn); | ||
frame.returnDataSpan(new MemorySpan(0, returnData.size())); | ||
|
||
if (callSuccess) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should homogenize the names. In the spec it's
NON_STACK_ROWS
orNSR
.