Skip to content
Open
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 @@ -153,7 +153,7 @@ public class ZkCounter implements LineCountingTracer {
new CountingOnlyModule(BLOCK_HASH, trace.blockhash().spillage());
final BlsData blsdata;
final EcData ecdata;
final Euc euc;
final Euc euc = new Euc();
final Exp exp = new Exp();
final Ext ext = new Ext();
final CountingOnlyModule gas = new CountingOnlyModule(GAS, trace.gas().spillage());
Expand Down Expand Up @@ -327,7 +327,6 @@ public List<Module> checkedModules() {
}

public ZkCounter(LineaL1L2BridgeSharedConfiguration bridgeConfiguration) {
euc = new Euc(wcp);
keccak = new Keccak(ecRecoverEffectiveCall, blockTransactions);
ecdata =
new EcData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import net.consensys.linea.zktracer.container.stacked.CountOnlyOperation;
import net.consensys.linea.zktracer.container.stacked.ModuleOperationStackedSet;
import net.consensys.linea.zktracer.module.ModuleName;
import net.consensys.linea.zktracer.module.wcp.Wcp;
import org.apache.tuweni.bytes.Bytes;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.evm.worldstate.WorldView;
Expand All @@ -38,7 +37,6 @@
@RequiredArgsConstructor
@Accessors(fluent = true)
public class Euc implements OperationSetModule<EucOperation> {
private final Wcp wcp;

@Getter
private final ModuleOperationStackedSet<EucOperation> operations =
Expand Down Expand Up @@ -102,13 +100,8 @@ public EucOperation callEUC(final Bytes dividend, final Bytes divisor) {
final Bytes quotient = bigIntegerToBytes(dividendBI.divide(divisorBI));
final Bytes remainder = bigIntegerToBytes(dividendBI.remainder(divisorBI));

final EucOperation operation = new EucOperation(dividend, divisor, quotient, remainder);

final boolean isNew = operations.add(operation);
if (isNew) {
wcp.callLT(operation.remainder(), operation.divisor());
}

return operation;
final EucOperation op = new EucOperation(dividend, divisor, quotient, remainder);
operations.add(op);
return op;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public EucOperation(
final Bytes divisorTrim = divisor.trimLeadingZeros();
final Bytes quotientTrim = quotient.trimLeadingZeros();

this.dividend = dividend;
this.divisor = divisorTrim;
this.dividend = dividend.trimLeadingZeros();
this.divisor = divisorTrim.trimLeadingZeros();
Copy link

Choose a reason for hiding this comment

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

Bug: Optimize Divisor Field Trimming

The divisor field is trimmed twice: divisorTrim already contains the result of divisor.trimLeadingZeros() from line 38, so calling trimLeadingZeros() again on it is redundant. The assignment should be this.divisor = divisorTrim; to match the original behavior and avoid unnecessary computation.

Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

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

Bug: Unnecessary Trimming Impacts Performance

The divisor field is trimmed twice: once when creating divisorTrim at line 38, then again when assigning to this.divisor. This redundant operation wastes CPU cycles. The assignment should be this.divisor = divisorTrim; to match the pattern used for quotient at line 43.

Fix in Cursor Fix in Web

this.quotient = quotientTrim;
this.remainder = remainder;
}
Expand All @@ -54,10 +54,10 @@ void trace(Trace.Euc trace) {
final Bytes ceil = this.ceiling();

trace
.dividend(this.dividend)
.divisor(this.divisor)
.quotient(this.quotient)
.remainder(this.remainder)
.dividend(dividend)
.divisor(divisor)
.quotient(quotient)
.remainder(remainder)
.ceil(ceil)
.validateRow();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import static com.google.common.base.Preconditions.*;
import static com.google.common.math.BigIntegerMath.log2;
import static java.lang.Math.min;
import static net.consensys.linea.zktracer.Trace.EXP_INST_EXPLOG;
import static net.consensys.linea.zktracer.Trace.EXP_INST_MODEXPLOG;
import static net.consensys.linea.zktracer.Trace.*;
import static net.consensys.linea.zktracer.module.hub.precompiles.ModexpMetadata.BASE_MIN_OFFSET;
import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes;

Expand Down Expand Up @@ -62,8 +61,8 @@ public ExpOperation(ExpCall expCall) {
"MODEXP call data unexpectedly short");
final EWord rawLead = modexpMetadata.rawLeadingWord();
final int cdsCutoff =
Math.min(modexpMetadata.callData().size() - BASE_MIN_OFFSET - bbsInt, 32);
final int ebsCutoff = Math.min(ebsInt, 32);
Math.min(modexpMetadata.callData().size() - BASE_MIN_OFFSET - bbsInt, WORD_SIZE);
final int ebsCutoff = Math.min(ebsInt, WORD_SIZE);
final BigInteger leadLog =
BigInteger.valueOf(LeadLogTrimLead.fromArgs(rawLead, cdsCutoff, ebsCutoff).leadLog());
// Fill expCall
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public ModuleName moduleKey() {
return GAS;
}

public void call(GasParameters gasParameters, Hub hub, CommonFragmentValues commonValues) {
public void call(Hub hub, CommonFragmentValues commonValues) {
this.commonValues = commonValues;
this.gasParameters = gasParameters;
gasParameters = new GasParameters();
hub.defers().scheduleForPostExecution(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,10 @@ public int spillage(Trace trace) {

// stateless modules
private final Wcp wcp = new Wcp();

private final Add add = new Add();
private final Bin bin = new Bin();
private final Blockhash blockhash;
private final Euc euc = new Euc(wcp);
private final Euc euc = new Euc();
private final Ext ext = new Ext();
private final Gas gas = new Gas();
private final Mul mul = new Mul();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.consensys.linea.zktracer.module.gas.GasParameters;
import net.consensys.linea.zktracer.module.hub.Hub;
import net.consensys.linea.zktracer.module.hub.HubProcessingPhase;
import net.consensys.linea.zktracer.module.hub.TransactionProcessingType;
Expand Down Expand Up @@ -124,7 +123,7 @@ public CommonFragmentValues(Hub hub) {

if (contextMayChange) {
// Trigger the gas module in case contextMayChange is true
hub.gas().call(new GasParameters(), hub, this);
hub.gas().call(hub, this);
}

if (none(exceptions)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public class StpCall implements TraceSubFragment {
private final OpCodeData opCodeData;

public StpCall(Hub hub, MessageFrame frame, long memoryExpansionGas) {
this.opCode = hub.opCode();
this.opCodeData = hub.opCodeData();
opCodeData = hub.opCodeData();
opCode = opCodeData.mnemonic();

checkArgument(
opCodeData.isCall() || opCodeData.isCreate(),
Expand All @@ -74,21 +74,20 @@ public StpCall(Hub hub, MessageFrame frame, long memoryExpansionGas) {
this.gasActual = frame.getRemainingGas();

if (this.opCodeData.isCall()) {
this.stpCallForCalls(hub);
this.stpCallForCalls(hub, frame, opCode);
} else {
this.stpCallForCreates(frame);
}
}

private void stpCallForCalls(Hub hub) {
final MessageFrame frame = hub.messageFrame();
private void stpCallForCalls(Hub hub, MessageFrame frame, OpCode opCode) {

final Address to = Words.toAddress(frame.getStackItem(1));
final Account toAccount = frame.getWorldUpdater().get(to);
this.gas = EWord.of(frame.getStackItem(0));
this.value = opCodeData.callHasValueArgument() ? EWord.of(frame.getStackItem(2)) : ZERO;
this.exists =
switch (hub.opCode()) {
switch (opCode) {
case CALL -> toAccount != null && !toAccount.isEmpty();
case CALLCODE, DELEGATECALL, STATICCALL -> false;
default -> throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ void testExpLogSingleCase(TestInfo testInfo) {
bytecodeRunner.run(chainConfig, testInfo);
}

@Test
void testExpLogDuplicate(TestInfo testInfo) {
BytecodeRunner bytecodeRunner =
BytecodeRunner.of(
BytecodeCompiler.newProgram(chainConfig)
.push(256)
.push(256)
.op(OpCode.EXP)
.op(OpCode.POP)
.push(256)
.push(256)
.op(OpCode.EXP)
.op(OpCode.POP));
bytecodeRunner.run(chainConfig, testInfo);
}

@Test
void testModexpLogSingleCase(TestInfo testInfo) {
BytecodeCompiler program =
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
releaseVersion=beta-v4.0-rc12
releaseVersion=beta-v5.0-integration-test-wo-modexp-secp256r1
besuVersion=25.11.0-RC1-linea2
shomeiVersion=2.4-develop
besuShomeiPluginVersion=v0.7.4
Expand Down
Loading