Skip to content

Commit

Permalink
Merge branch 'arith-dev' into 1802-update-linea-besu-delivery49
Browse files Browse the repository at this point in the history
  • Loading branch information
fab-10 authored Feb 12, 2025
2 parents 049be9d + 680cf13 commit be175db
Show file tree
Hide file tree
Showing 41 changed files with 382 additions and 315 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,9 @@ private void handleGasLimit() {
// row i + 2
final Bytes maxDeviation = eucCall(2, prevGasLimit, EWord.of(GAS_LIMIT_ADJUSTMENT_FACTOR));
// row i + 3
final BigInteger safeGasLimitUpperBound =
prevGasLimit.getAsBigInteger().add(maxDeviation.toUnsignedBigInteger());
wcpCallToLT(3, data, EWord.of(safeGasLimitUpperBound));

wcpCallToLT(3, data, EWord.of(prevGasLimit.toLong() + maxDeviation.toLong()));
// row i + 4
wcpCallToGT(
4,
data,
EWord.of(prevGasLimit.toLong() - maxDeviation.toLong())); // TODO: double check this
wcpCallToGT(4, data, EWord.of(prevGasLimit.toLong() - maxDeviation.toLong()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package net.consensys.linea.zktracer.module.ecdata;

import static com.google.common.base.Preconditions.*;
import static net.consensys.linea.zktracer.module.Util.rightPaddedSlice;
import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_ECADD_DATA;
import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_ECADD_RESULT;
import static net.consensys.linea.zktracer.module.constants.GlobalConstants.PHASE_ECMUL_DATA;
Expand Down Expand Up @@ -49,7 +50,6 @@
import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.*;
import static net.consensys.linea.zktracer.types.Containers.repeat;
import static net.consensys.linea.zktracer.types.Utils.leftPadTo;
import static net.consensys.linea.zktracer.types.Utils.rightPadTo;

import java.util.List;

Expand Down Expand Up @@ -155,13 +155,7 @@ private EcDataOperation(
+ precompileFlag.name());
};

if (callData.size() < paddedCallDataLength) {
this.rightPaddedCallData = rightPadTo(callData, paddedCallDataLength);
} else {
// TODO: why keep the entire rightPaddedCallData rather than
// rightPaddedCallData[0:paddedCallDataLength] ?
this.rightPaddedCallData = callData;
}
rightPaddedCallData = rightPaddedSlice(callData, 0, paddedCallDataLength);

if (precompileFlag == PRC_ECPAIRING) {
totalPairings = callDataSize / TOTAL_SIZE_ECPAIRING_DATA_MIN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,11 @@ public class AccountSnapshot {
* @return
*/
public static AccountSnapshot canonical(Hub hub, Address address) {
AccountSnapshot canonicalSnapshot =
fromArguments(
hub.messageFrame().getWorldUpdater(),
address,
hub.transients.conflation().deploymentInfo(),
isAddressWarm(hub.messageFrame(), address));

return canonicalSnapshot;
return fromArguments(
hub.messageFrame().getWorldUpdater(),
address,
hub.transients.conflation().deploymentInfo(),
isAddressWarm(hub.messageFrame(), address));
}

public static AccountSnapshot canonical(Hub hub, WorldView world, Address address) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,6 @@ private List<Module> precompileLimitModules() {
/** reference table modules */
private final List<Module> refTableModules;

/**
* boolean which remembers whether a {@link CreateSection} detected Failure Condition F. Gets
* reset with every new opcode.
*/
public boolean failureConditionForCreates = false;

public Address coinbaseAddress;
public boolean coinbaseWarmthAtTransactionEnd = false;

Expand Down Expand Up @@ -535,10 +529,6 @@ public void traceEndTransaction(
boolean isSuccessful,
List<Log> logs,
Set<Address> selfDestructs) {
// TODO: see issue #875. It is currently unclear which, if any,
// rollbacks already took place at traceEndTransaction.

// TODO: add the following resolution this.defers.resolvePostRollback(this, ...

txStack.current().completeLineaTransaction(this, world, isSuccessful, logs, selfDestructs);
defers.resolveAtEndTransaction(this, world, tx, isSuccessful);
Expand Down Expand Up @@ -854,7 +844,8 @@ private void exitDeploymentFromDeploymentInfoPov(MessageFrame frame) {
* address A; bytecode A executes exactly the same CREATE2 raising the Failure Condition F for
* address B;
*/
if (failureConditionForCreates) {
if (this.currentTraceSection() instanceof CreateSection
&& ((CreateSection) this.currentTraceSection()).scenarioFragment.isFailedCreate()) {
return;
}
// from here on out: no failure condition
Expand Down Expand Up @@ -1023,9 +1014,6 @@ public int cumulatedTxCount() {

void traceOpcode(MessageFrame frame) {

// TODO: supremely ugly hack, somebody please clean up this mess
failureConditionForCreates = false;

switch (this.opCodeData().instructionFamily()) {
case ADD, MOD, SHF, BIN, WCP, EXT, BATCH, PUSH_POP, DUP, SWAP -> new StackOnlySection(this);
case MACHINE_STATE -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,14 @@ public void scheduleForPostRollback(PostRollbackDefer defer, CallFrame callFrame
* @param world a {@link WorldView} on the state
* @param tx the current {@link Transaction}
*/
// TODO: should use the TransactionProcessingMetadata

// TODO add docs to understand why we do two rounds of resolving (due to AccountFragment created
// at endTx which are too deferEndTx), maybe no more the case, so not needed anymore
@Override
public void resolveAtEndTransaction(
Hub hub, WorldView world, Transaction tx, boolean isSuccessful) {
/**
* AccountFragment could be created at resolveAtEndTransaction for some sections. As those
* accountFragments are too endTransactionDeferred, we need to resolveAtEndTransaction in two
* steps.
*/
final List<EndTransactionDefer> endTransactionDefersFirstRound =
new ArrayList<>(endTransactionDefers);
endTransactionDefers.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import lombok.RequiredArgsConstructor;
import net.consensys.linea.zktracer.module.hub.Hub;
import net.consensys.linea.zktracer.module.hub.Trace;
import net.consensys.linea.zktracer.runtime.callstack.CallFrame;

@RequiredArgsConstructor
public class DomSubStampsSubFragment implements TraceSubFragment {
Expand All @@ -43,40 +42,18 @@ public static DomSubStampsSubFragment standardDomSubStamps(final int h, final in
return new DomSubStampsSubFragment(DomSubType.STANDARD, h, domOffset, 0, 0, 0, 0);
}

// TODO: to be use with care, as stamps might have changed
// TODO: remove altogether
public static DomSubStampsSubFragment revertWithCurrentDomSubStamps(
final Hub hub, final int subOffset) {
return new DomSubStampsSubFragment(
DomSubType.REVERTS_WITH_CURRENT,
hub.stamp(),
0,
subOffset,
hub.callStack().currentCallFrame().revertStamp(),
0,
0);
}

public static DomSubStampsSubFragment revertWithCurrentDomSubStamps(
final int h, final int revertStamp, final int subOffset) {
return new DomSubStampsSubFragment(
DomSubType.REVERTS_WITH_CURRENT, h, 0, subOffset, revertStamp, 0, 0);
}

// TODO: to be use with care, as stamps might have changed
public static DomSubStampsSubFragment revertsWithChildDomSubStamps(
final Hub hub, final CallFrame child, final int subOffset) {
return new DomSubStampsSubFragment(
DomSubType.REVERTS_WITH_CHILD, hub.stamp(), 0, subOffset, 0, child.revertStamp(), 0);
}

public static DomSubStampsSubFragment revertsWithChildDomSubStamps(
final int h, final int childRevertStamp, final int subOffset) {
return new DomSubStampsSubFragment(
DomSubType.REVERTS_WITH_CHILD, h, 0, subOffset, 0, childRevertStamp, 0);
}

// TODO: to be use with care, as stamps might have changed
public static DomSubStampsSubFragment selfdestructDomSubStamps(Hub hub, int hubStamp) {
return new DomSubStampsSubFragment(
DomSubType.SELFDESTRUCT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ public Trace trace(Trace trace) {
return trace;
}

// TODO: The most natural thing would be to implement resolveAtContextEntry instead.
@Override
public void resolveAtContextReEntry(Hub hub, CallFrame frame) {
childFrame = hub.callStack().getById(frame.childFrameIds().getLast());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@

import lombok.RequiredArgsConstructor;
import net.consensys.linea.zktracer.module.hub.fragment.TraceSubFragment;
import org.apache.tuweni.bytes.Bytes;

/** This interface defines the API required to execute a call to the OOB module. */
@RequiredArgsConstructor
public abstract class OobCall implements TraceSubFragment {
// TODO: move these constants somewhere else
public static final Bytes ZERO = Bytes.EMPTY;
public static final Bytes ONE = Bytes.of(1);

public final OobInstruction oobInstruction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes;

import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_CDL;
import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes;
import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes;
import static net.consensys.linea.zktracer.types.Conversions.*;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes;

import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_CALL;
import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes;
import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes;
import static net.consensys.linea.zktracer.types.Conversions.*;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes;

import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_DEPLOYMENT;
import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes;
import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes;
import static net.consensys.linea.zktracer.types.Conversions.*;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes;

import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.*;
import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes;
import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes;
import static net.consensys.linea.zktracer.types.Conversions.*;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes;

import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_JUMPI;
import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes;
import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes;
import static net.consensys.linea.zktracer.types.Conversions.*;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes;

import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.*;
import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes;
import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes;
import static net.consensys.linea.zktracer.types.Conversions.*;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes;

import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.*;
import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes;
import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes;
import static net.consensys.linea.zktracer.types.Conversions.*;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.opcodes;

import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.*;
import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes;
import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes;
import static net.consensys.linea.zktracer.types.Conversions.*;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles;

import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_BLAKE_CDS;
import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes;
import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes;
import static net.consensys.linea.zktracer.types.Conversions.*;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles;

import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_BLAKE_PARAMS;
import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes;
import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes;
import static net.consensys.linea.zktracer.types.Conversions.*;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles;

import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_CDS;
import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes;
import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes;
import static net.consensys.linea.zktracer.types.Conversions.*;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles;

import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_EXTRACT;
import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes;
import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes;
import static net.consensys.linea.zktracer.types.Conversions.*;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles;

import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.OOB_INST_MODEXP_LEAD;
import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes;
import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes;
import static net.consensys.linea.zktracer.types.Conversions.*;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles;

import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.*;
import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes;
import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes;
import static net.consensys.linea.zktracer.types.Conversions.*;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles;

import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.OobInstruction.*;
import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes;
import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes;
import static net.consensys.linea.zktracer.types.Conversions.*;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
package net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles;

import static com.google.common.base.Preconditions.*;
import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes;
import static net.consensys.linea.zktracer.types.Conversions.booleanToBytes;
import static net.consensys.linea.zktracer.types.Conversions.*;

import java.math.BigInteger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ public static CreateScenario switchToRevertingScenario(final CreateScenario curr
@Setter @Getter private CreateScenario scenario;

public CreateScenarioFragment() {
this.scenario = CreateScenario.UNDEFINED;
scenario = CreateScenario.UNDEFINED;
}

public boolean isAbortedCreate() {
return scenario == CreateScenario.CREATE_ABORT;
}

public boolean isFailedCreate() {
return scenario.isAnyOf(CreateScenario.CREATE_FAILURE_CONDITION_WONT_REVERT);
}

@Override
public Trace trace(Trace trace) {
return trace
Expand Down
Loading

0 comments on commit be175db

Please sign in to comment.