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

clean: some cleaning #1850

Merged
merged 29 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
47decaa
clean: rm unused columns
letypequividelespoubelles Feb 19, 2025
5b1a657
clean: some cleaning
letypequividelespoubelles Feb 25, 2025
a6c1045
clean
letypequividelespoubelles Feb 25, 2025
af03dbb
more cleanng
letypequividelespoubelles Feb 25, 2025
686ee19
feat: added tests for Hub.unlatchStack() wrt CALL/CREATE and exceptions
OlivierBBB Feb 25, 2025
24adb0a
spotless
OlivierBBB Feb 25, 2025
c44461f
clean finish ?
letypequividelespoubelles Feb 25, 2025
163faf1
update go-corset
letypequividelespoubelles Feb 25, 2025
278d392
mxp cleaning
letypequividelespoubelles Feb 25, 2025
36e3b3e
Merge branch 'arith-dev' into 1849-some-cleaning
letypequividelespoubelles Feb 25, 2025
2a77de0
ras
letypequividelespoubelles Feb 25, 2025
15f633a
Merge branch '1834-rm-dep-number-status-infinity' into 1849-some-clea…
letypequividelespoubelles Feb 25, 2025
2154ba1
make it compile
letypequividelespoubelles Feb 25, 2025
85d7f00
make it compile again
letypequividelespoubelles Feb 25, 2025
1e5590c
update constrants
letypequividelespoubelles Feb 25, 2025
ca4b258
rm dead code + constraints
letypequividelespoubelles Feb 25, 2025
b94e065
more cleaning
letypequividelespoubelles Feb 25, 2025
eb283f1
update constraints
letypequividelespoubelles Feb 25, 2025
044dca8
clean: get rid of signals
letypequividelespoubelles Feb 25, 2025
d26aaae
ras
letypequividelespoubelles Feb 25, 2025
5b3f8a5
adjusted asserts for OobRdcTest
lorenzogentile404 Feb 26, 2025
711041b
spotless
lorenzogentile404 Feb 26, 2025
2a4c4ba
feat: factorise exceptions logic
letypequividelespoubelles Feb 26, 2025
f86693a
Merge branch '1849-some-cleaning' of github.com:Consensys/linea-trace…
letypequividelespoubelles Feb 26, 2025
929a7ae
Merge branch 'arith-dev' into 1849-some-cleaning
letypequividelespoubelles Feb 26, 2025
9c692dc
fixed null case in OobRdcTest
lorenzogentile404 Feb 26, 2025
b88a945
Merge branch '1849-some-cleaning' of github.com:Consensys/linea-trace…
lorenzogentile404 Feb 26, 2025
e92b3c1
fix typo
letypequividelespoubelles Feb 26, 2025
0eb2c3d
Merge branch '1849-some-cleaning' of github.com:Consensys/linea-trace…
letypequividelespoubelles Feb 26, 2025
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
2 changes: 1 addition & 1 deletion .github/actions/setup-go-corset/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ runs:

- name: Install Go Corset
shell: bash
run: go install github.com/consensys/go-corset/cmd/go-corset@a899fbd
run: go install github.com/consensys/go-corset/cmd/go-corset@4e884ec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;

import net.consensys.linea.zktracer.ColumnHeader;
import net.consensys.linea.zktracer.opcode.OpCode;
import net.consensys.linea.zktracer.types.TransactionProcessingMetadata;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.evm.frame.MessageFrame;
Expand Down Expand Up @@ -50,7 +51,7 @@ default void traceContextEnter(MessageFrame frame) {}

default void traceContextExit(MessageFrame frame) {}

default void tracePreOpcode(MessageFrame frame) {}
default void tracePreOpcode(MessageFrame frame, OpCode opcode) {}

/**
* Called when a bundle of transaction execution is cancelled; should revert the state of the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;

import com.google.common.base.Preconditions;
import lombok.Getter;
Expand Down Expand Up @@ -126,4 +127,8 @@ public List<E> sortOperations(Comparator<E> comparator) {
sortedOperations.sort(comparator);
return sortedOperations;
}

public Stream<E> stream() {
return this.getAll().stream();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

package net.consensys.linea.zktracer.module.add;

import static net.consensys.linea.zktracer.opcode.OpCode.ADD;
import static net.consensys.linea.zktracer.opcode.OpCode.SUB;

import java.math.BigInteger;
import java.nio.MappedByteBuffer;
import java.util.List;
Expand Down Expand Up @@ -45,12 +48,14 @@ public String moduleKey() {
}

@Override
public void tracePreOpcode(MessageFrame frame) {
operations.add(
new AddOperation(
OpCode.of(frame.getCurrentOperation().getOpcode()),
Bytes32.leftPad(frame.getStackItem(0)),
Bytes32.leftPad(frame.getStackItem(1))));
public void tracePreOpcode(MessageFrame frame, OpCode opcode) {
if ((opcode == ADD || opcode == SUB)) {
operations.add(
new AddOperation(
opcode,
Bytes32.leftPad(frame.getStackItem(0)),
Bytes32.leftPad(frame.getStackItem(1))));
}
}

@Override
Expand All @@ -68,7 +73,7 @@ public void commit(List<MappedByteBuffer> buffers) {
}

public BigInteger callADD(Bytes32 arg1, Bytes32 arg2) {
operations.add(new AddOperation(OpCode.ADD, arg1, arg2));
operations.add(new AddOperation(ADD, arg1, arg2));
return arg1.toUnsignedBigInteger().add(arg2.toUnsignedBigInteger());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package net.consensys.linea.zktracer.module.bin;

import static net.consensys.linea.zktracer.opcode.OpCode.*;

import java.nio.MappedByteBuffer;
import java.util.List;

Expand Down Expand Up @@ -45,14 +47,21 @@ public String moduleKey() {
}

@Override
public void tracePreOpcode(MessageFrame frame) {
final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode());
final Bytes32 arg1 = Bytes32.leftPad(frame.getStackItem(0));
final Bytes32 arg2 =
opCode == OpCode.NOT ? Bytes32.ZERO : Bytes32.leftPad(frame.getStackItem(1));
public void tracePreOpcode(MessageFrame frame, OpCode opcode) {
if (opcode == AND
|| opcode == OR
|| opcode == XOR
|| opcode == NOT
|| opcode == SIGNEXTEND
|| opcode == BYTE) {

final Bytes32 arg1 = Bytes32.leftPad(frame.getStackItem(0));
final Bytes32 arg2 =
opcode == OpCode.NOT ? Bytes32.ZERO : Bytes32.leftPad(frame.getStackItem(1));

operations.add(
new BinOperation(opCode, BaseBytes.fromBytes32(arg1), BaseBytes.fromBytes32(arg2)));
operations.add(
new BinOperation(opcode, BaseBytes.fromBytes32(arg1), BaseBytes.fromBytes32(arg2)));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

package net.consensys.linea.zktracer.module.blockhash;

import static com.google.common.base.Preconditions.checkArgument;
import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGE;
import static net.consensys.linea.zktracer.opcode.OpCode.*;

import java.nio.MappedByteBuffer;
import java.util.HashMap;
Expand Down Expand Up @@ -76,21 +76,19 @@ public void traceStartBlock(
}

@Override
public void tracePreOpcode(MessageFrame frame) {
final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode());
checkArgument(opCode == OpCode.BLOCKHASH, "Expected BLOCKHASH opcode");
public void tracePreOpcode(MessageFrame frame, OpCode opcode) {
if (opcode == BLOCKHASH) {

blockhashArg = Bytes32.leftPad(frame.getStackItem(0));
blockhashArg = Bytes32.leftPad(frame.getStackItem(0));

hub.defers().scheduleForPostExecution(this);
hub.defers().scheduleForPostExecution(this);
}
}

@Override
public void resolvePostExecution(
Hub hub, MessageFrame frame, Operation.OperationResult operationResult) {

final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode());
checkArgument(opCode == OpCode.BLOCKHASH);
final Bytes32 blockhashRes = Bytes32.leftPad(frame.getStackItem(0));
operations.add(new BlockhashOperation(relBlock, absBlock, blockhashArg, blockhashRes, wcp));
// We have 4 LLARGE and one OLI call to WCP, made at the end of the conflation, so we need to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

package net.consensys.linea.zktracer.module.ext;

import static net.consensys.linea.zktracer.opcode.OpCode.*;

import java.nio.MappedByteBuffer;
import java.util.List;

Expand All @@ -26,7 +28,6 @@
import net.consensys.linea.zktracer.container.stacked.ModuleOperationStackedSet;
import net.consensys.linea.zktracer.module.hub.Hub;
import net.consensys.linea.zktracer.opcode.OpCode;
import net.consensys.linea.zktracer.opcode.OpCodeData;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.hyperledger.besu.evm.frame.MessageFrame;
Expand All @@ -46,14 +47,15 @@ public String moduleKey() {
}

@Override
public void tracePreOpcode(final MessageFrame frame) {
final OpCodeData opCode = hub.opCodeData();
operations.add(
new ExtOperation(
opCode.mnemonic(),
Bytes32.leftPad(frame.getStackItem(0)),
Bytes32.leftPad(frame.getStackItem(1)),
Bytes32.leftPad(frame.getStackItem(2))));
public void tracePreOpcode(MessageFrame frame, OpCode opcode) {
if (opcode == ADDMOD || opcode == MULMOD) {
operations.add(
new ExtOperation(
opcode,
Bytes32.leftPad(frame.getStackItem(0)),
Bytes32.leftPad(frame.getStackItem(1)),
Bytes32.leftPad(frame.getStackItem(2))));
}
}

public Bytes call(OpCode opCode, Bytes _arg1, Bytes _arg2, Bytes _arg3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public class AccountSnapshot {
private int deploymentNumber;
private boolean deploymentStatus;

// TODO: is there a "canonical" way to take a snapshot fo an account
// where getWorldUpdater().get(address) return null ?

/**
* Canonical way of creating an account snapshot.
*
Expand Down Expand Up @@ -241,9 +238,9 @@ public AccountSnapshot setDeploymentNumber(DeploymentInfo deploymentInfo) {
return this.deploymentNumber(deploymentInfo.deploymentNumber(address));
}

public AccountSnapshot decrementDeploymentNumberByOne() {
public void decrementDeploymentNumberByOne() {
checkState(deploymentNumber > 0);
return this.deploymentNumber(deploymentNumber - 1);
this.deploymentNumber(deploymentNumber - 1);
}

public AccountSnapshot setDeploymentInfo(Hub hub) {
Expand All @@ -261,9 +258,4 @@ public AccountSnapshot deployByteCode(Bytecode code) {

return new AccountSnapshot(address, nonce, balance, true, code, deploymentNumber, false);
}

public AccountSnapshot copyDeploymentInfoFrom(AccountSnapshot snapshot) {
return this.deploymentNumber(snapshot.deploymentNumber)
.deploymentStatus(snapshot.deploymentStatus);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,6 @@ public void traceContextEnter(MessageFrame frame) {

@Override
public void traceContextExit(MessageFrame frame) {
this.currentFrame().initializeFrame(frame); // TODO: is it needed ?

exitDeploymentFromDeploymentInfoPov(frame);

// We take a snapshot before exiting the transaction
Expand All @@ -672,7 +670,6 @@ public void traceContextExit(MessageFrame frame) {
}

defers.resolveUponContextExit(this, this.currentFrame());
// TODO: verify me please @Olivier
if (this.currentFrame().opCode() == REVERT || Exceptions.any(pch.exceptions())) {
defers.resolveUponRollback(this, frame, this.currentFrame());
}
Expand All @@ -685,7 +682,6 @@ public void traceContextExit(MessageFrame frame) {
public void traceContextReEnter(MessageFrame frame) {
// Note: the update of the currentId call frame is made during traceContextExit of the child
// frame
this.currentFrame().initializeFrame(frame); // TODO: is it needed ?
defers.resolveUponContextReEntry(this, this.currentFrame());
this.unlatchStack(frame, this.currentFrame().childSpanningSection());
}
Expand Down Expand Up @@ -848,33 +844,6 @@ private void handleStack(MessageFrame frame) {
.processInstruction(this, frame, MULTIPLIER___STACK_STAMP * (stamp() + 1));
}

void triggerModules(MessageFrame frame) {
if (pch.signals().add()) {
add.tracePreOpcode(frame);
}
if (pch.signals().bin()) {
bin.tracePreOpcode(frame);
}
if (pch.signals().mul()) {
mul.tracePreOpcode(frame);
}
if (pch.signals().ext()) {
ext.tracePreOpcode(frame);
}
if (pch.signals().mod()) {
mod.tracePreOpcode(frame);
}
if (pch.signals().wcp()) {
wcp.tracePreOpcode(frame);
}
if (pch.signals().shf()) {
shf.tracePreOpcode(frame);
}
if (pch.signals().blockhash()) {
blockhash.tracePreOpcode(frame);
}
}

public int stamp() {
return state.stamps().hub();
}
Expand Down Expand Up @@ -914,9 +883,8 @@ public void unlatchStack(MessageFrame frame, TraceSection section) {

if (line.needsResult()) {
Bytes result = Bytes.EMPTY;
// Only pop from the stack if no exceptions have been encountered
// TODO: when we call this from contextReenter, pch.exceptions is not the one from the
// caller/creater ?
// Note: when we call this from contextReenter, pch.exceptions is the one from the last
// opcode of the caller/creater ?
if (Exceptions.none(pch.exceptions())) {
result = frame.getStackItem(0).copy();
}
Expand All @@ -934,9 +902,16 @@ void processStateExec(MessageFrame frame) {
pch.setup(frame);

this.handleStack(frame);
this.triggerModules(frame);

// Trigger basic operations modules
if (Exceptions.none(pch.exceptions())) {
for (Module m : modules) {
m.tracePreOpcode(frame, opCode());
}
}

if (currentFrame().stack().isOk()) {
// Tracer for the HUB
this.traceOpcode(frame);
} else {
this.squashCurrentFrameOutputData();
Expand All @@ -949,10 +924,6 @@ void processStateExec(MessageFrame frame) {
}
}

// TODO: how do these implementations of remainingGas()
// and expectedGas() behave with respect to resuming
// execution after a CALL / CREATE ? One of them is
// necessarily false ...
public long remainingGas() {
return this.state().processingPhase() == TX_EXEC
? this.currentFrame().frame().getRemainingGas()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import net.consensys.linea.zktracer.module.hub.signals.AbortingConditions;
import net.consensys.linea.zktracer.module.hub.signals.Exceptions;
import net.consensys.linea.zktracer.module.hub.signals.TracedException;
import net.consensys.linea.zktracer.module.hub.state.State;
import net.consensys.linea.zktracer.opcode.InstructionFamily;
import net.consensys.linea.zktracer.opcode.OpCode;
import net.consensys.linea.zktracer.opcode.gas.MxpType;
Expand All @@ -60,8 +59,6 @@ public final class StackFragment implements TraceFragment {
@Getter private final OpCode opCode;
@Getter private final int rawOpCode;
@Setter private boolean jumpDestinationVettingRequired;
@Setter private boolean validJumpDestination;
private final State.HubTransactionState.Stamps stamps;
private final CommonFragmentValues commonFragmentValues;
private final EWord pushValue;

Expand Down Expand Up @@ -139,7 +136,6 @@ private StackFragment(
jumpDestinationVettingRequired = false;
}

this.stamps = hub.state().stamps();
this.commonFragmentValues = commonFragmentValues;
this.pushValue = opCode.isPush() ? EWord.of(getPushValue(hub)) : EWord.ZERO;
}
Expand Down Expand Up @@ -278,7 +274,7 @@ public Trace trace(Trace trace) {
.pStackStaticFlag(stack.getCurrentOpcodeData().stackSettings().forbiddenInStatic())
.pStackPushValueHi(pushValue.hi())
.pStackPushValueLo(pushValue.lo())
.pStackJumpDestinationVettingRequired(jumpDestinationVettingRequired) // TODO: confirm this
.pStackJumpDestinationVettingRequired(jumpDestinationVettingRequired)
// Exception flag
.pStackOpcx(tracedException == INVALID_OPCODE)
.pStackSux(tracedException == STACK_UNDERFLOW)
Expand All @@ -295,8 +291,7 @@ public Trace trace(Trace trace) {
.pStackHashInfoFlag(hashInfoFlag)
.pStackHashInfoKeccakHi(hashInfoKeccak.hi())
.pStackHashInfoKeccakLo(hashInfoKeccak.lo())
.pStackLogInfoFlag(this.traceLog()) // TODO: confirm this
;
.pStackLogInfoFlag(traceLog());
}

private void tracedExceptionSanityChecks(TracedException tracedException) {
Expand Down
Loading
Loading