From 120dff31fee3a64ea170a7f4f4a45bf765b15704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 1 Oct 2024 01:03:16 +0200 Subject: [PATCH 1/8] fix(selfdestruct) There were several problems: - we were updating the deployment number to a fresh new deployment number twice per SELFDESTRUCT - the ROM_LEX module had no idea about these fresh new deployments - we were assuming that DEPLOYMENT_NUMBER_NEW = 1 for any deployment transaction, but this can be at fault in the EVM test suite --- .../zktracer/module/hub/AccountSnapshot.java | 12 ++++++++++-- .../linea/zktracer/module/hub/Hub.java | 12 ++++++++---- .../zktracer/module/hub/TransactionStack.java | 8 +++++++- .../hub/section/halt/SelfdestructSection.java | 10 +++++----- .../linea/zktracer/module/romlex/RomLex.java | 18 +++++++++++++++++- .../types/TransactionProcessingMetadata.java | 10 ++++++++++ 6 files changed, 57 insertions(+), 13 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java index d4c91fd37d..0ccc3ef7ee 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java @@ -141,9 +141,17 @@ public AccountSnapshot deepCopy() { address, nonce, balance, isWarm, code, deploymentNumber, deploymentStatus); } - public AccountSnapshot wipe() { + // + public AccountSnapshot wipe(DeploymentInfo deploymentInfo) { + Preconditions.checkArgument(!deploymentInfo.getDeploymentStatus(address)); return new AccountSnapshot( - address, 0, Wei.of(0), isWarm, Bytecode.EMPTY, deploymentNumber + 1, false); + address, + 0, + Wei.of(0), + isWarm, + Bytecode.EMPTY, + deploymentInfo.deploymentNumber(address), + deploymentInfo.getDeploymentStatus(address)); } /** diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 7021882495..ebb58ab27c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -503,13 +503,15 @@ public void traceStartTransaction(final WorldView world, final Transaction tx) { state.enter(); txStack.enterTransaction(world, tx, transients.block()); + TransactionProcessingMetadata transactionProcessingMetadata = txStack.current(); + this.enterTransaction(); - if (!txStack.current().requiresEvmExecution()) { + if (!transactionProcessingMetadata.requiresEvmExecution()) { state.setProcessingPhase(TX_SKIP); - new TxSkippedSection(this, world, txStack.current(), transients); + new TxSkippedSection(this, world, transactionProcessingMetadata, transients); } else { - if (txStack.current().requiresPrewarming()) { + if (transactionProcessingMetadata.requiresPrewarming()) { state.setProcessingPhase(TX_WARM); new TxPreWarmingMacroSection(world, this); } @@ -517,6 +519,8 @@ public void traceStartTransaction(final WorldView world, final Transaction tx) { new TxInitializationSection(this, world); } + transactionProcessingMetadata.captureInitialRecipientAddressDeploymentInfoValues(this); + /* * TODO: the ID = 0 (universal parent context) context should * 1. be shared by all transactions in a conflation (OK) @@ -526,7 +530,7 @@ public void traceStartTransaction(final WorldView world, final Transaction tx) { callStack.getById(0).universalParentReturnDataContextNumber(this.stamp() + 1); for (Module m : modules) { - m.traceStartTx(world, txStack.current()); + m.traceStartTx(world, transactionProcessingMetadata); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java index b8ea50b69b..22005cf5fc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java @@ -72,10 +72,16 @@ public void enterTransaction(final WorldView world, final Transaction tx, Block this.txs.add(newTx); } + // @françois what replaces this for message calls to smart contracts ? public void setCodeFragmentIndex(Hub hub) { for (TransactionProcessingMetadata tx : this.txs) { final int cfi = - tx.requiresCfiUpdate() ? hub.getCfiByMetaData(tx.getEffectiveRecipient(), 1, true) : 0; + tx.requiresCfiUpdate() + ? hub.getCfiByMetaData( + tx.getEffectiveRecipient(), + tx.getRecipientAddressDeploymentNumber(), + tx.isRecipientAddressDeploymentStatus()) + : 0; tx.setCodeFragmentIndex(cfi); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index 33e43c6b4b..7925065b9a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -31,7 +31,6 @@ import net.consensys.linea.zktracer.module.hub.fragment.scenario.SelfdestructScenarioFragment; import net.consensys.linea.zktracer.module.hub.section.TraceSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import net.consensys.linea.zktracer.module.hub.transients.DeploymentInfo; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata.AttemptedSelfDestruct; @@ -272,17 +271,18 @@ public void resolvePostTransaction( SelfdestructScenarioFragment.SelfdestructScenario .SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED); + // the hub's defers.resolvePostTransaction() gets called after the + // hub's completeLineaTransaction which in turn calls + // freshDeploymentNumberFinishingSelfdestruct() + // which raises the deployment number and sets the deployment status to false AccountFragment accountWipingFragment = hub.factories() .accountFragment() .make( accountBeforeSelfDestruct, - selfdestructorAccountAfter.wipe(), + selfdestructorAccountAfter.wipe(hub.transients().conflation().deploymentInfo()), DomSubStampsSubFragment.selfdestructDomSubStamps(hub)); - final DeploymentInfo deploymentInfo = hub.transients().conflation().deploymentInfo(); - deploymentInfo.freshDeploymentNumberFinishingSelfdestruct(addressWhichMaySelfDestruct); - this.addFragment(accountWipingFragment); } else { selfdestructScenarioFragment.setScenario( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java index 230ddf9d67..7b8325eb83 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java @@ -130,7 +130,7 @@ public void traceStartTx(WorldView worldView, TransactionProcessingMetadata txMe final Address deploymentAddress = Address.contractAddress(tx.getSender(), tx.getNonce()); final RomOperation operation = new RomOperation( - ContractMetadata.make(deploymentAddress, 1, true), false, false, tx.getInit().get()); + ContractMetadata.canonical(hub, deploymentAddress), false, false, tx.getInit().get()); operations.add(operation); } @@ -238,9 +238,25 @@ public void callRomLex(final MessageFrame frame) { } }); } + + default -> throw new RuntimeException( + String.format( + "%s does not trigger the creation of ROM_LEX", + OpCode.of(frame.getCurrentOperation().getOpcode()))); } } + public void callRomLexForSelfdestruct(final Address addressWhichWillSelfdestruct) { + + final RomOperation operation = + new RomOperation( + ContractMetadata.canonical(hub, addressWhichWillSelfdestruct), + false, + false, + Bytes.EMPTY); + operations.add(operation); + } + @Override public void resolveUponContextEntry(Hub hub) { checkArgument(hub.messageFrame().getType() == MessageFrame.Type.CONTRACT_CREATION); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index c8cecddd89..7404e96a12 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -53,6 +53,8 @@ public class TransactionProcessingMetadata { final long baseFee; final boolean isDeployment; + @Setter int recipientAddressDeploymentNumber; + @Setter boolean recipientAddressDeploymentStatus; @Accessors(fluent = true) final boolean requiresEvmExecution; @@ -160,6 +162,11 @@ public TransactionProcessingMetadata( this.effectiveGasPrice = computeEffectiveGasPrice(); } + public void captureInitialRecipientAddressDeploymentInfoValues(Hub hub) { + recipientAddressDeploymentNumber = hub.deploymentNumberOf(effectiveRecipient); + recipientAddressDeploymentStatus = hub.deploymentStatusOf(effectiveRecipient); + } + public void setPreFinalisationValues( final long leftOverGas, final long refundCounterMax, @@ -190,6 +197,9 @@ public void completeLineaTransaction( destructedAccountsSnapshot.add( AccountSnapshot.fromAddress( address, true, hub.deploymentNumberOf(address), hub.deploymentStatusOf(address))); + + // registering the "fresh new deployment number" (that doesn't correspond to any deployment) + hub.romLex().callRomLexForSelfdestruct(address); } determineSelfDestructTimeStamp(); From df225eefea0b68620794a2da73b458bda94d7652 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 1 Oct 2024 09:51:43 +0530 Subject: [PATCH 2/8] some cleaning Signed-off-by: Francois Bojarski --- .../zktracer/module/hub/AccountSnapshot.java | 18 +++++----- .../linea/zktracer/module/hub/Hub.java | 4 +-- .../zktracer/module/hub/TransactionStack.java | 4 +-- .../types/TransactionProcessingMetadata.java | 34 +++++++++---------- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java index 0ccc3ef7ee..2d6e3852c8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/AccountSnapshot.java @@ -15,11 +15,12 @@ package net.consensys.linea.zktracer.module.hub; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkState; import static net.consensys.linea.zktracer.types.AddressUtils.isAddressWarm; import java.util.Optional; -import com.google.common.base.Preconditions; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; @@ -141,9 +142,9 @@ public AccountSnapshot deepCopy() { address, nonce, balance, isWarm, code, deploymentNumber, deploymentStatus); } - // public AccountSnapshot wipe(DeploymentInfo deploymentInfo) { - Preconditions.checkArgument(!deploymentInfo.getDeploymentStatus(address)); + final boolean deploymentStatus = deploymentInfo.getDeploymentStatus(address); + checkArgument(!deploymentStatus); return new AccountSnapshot( address, 0, @@ -151,7 +152,7 @@ public AccountSnapshot wipe(DeploymentInfo deploymentInfo) { isWarm, Bytecode.EMPTY, deploymentInfo.deploymentNumber(address), - deploymentInfo.getDeploymentStatus(address)); + deploymentStatus); } /** @@ -162,7 +163,7 @@ public AccountSnapshot wipe(DeploymentInfo deploymentInfo) { * @return {@code this} with decremented balance */ public AccountSnapshot decrementBalanceBy(Wei quantity) { - Preconditions.checkState( + checkState( balance.greaterOrEqualThan(quantity), "Insufficient balance" + String.format("\n\t\tAddress: %s", address) @@ -231,14 +232,13 @@ public AccountSnapshot raiseNonceByOne() { } public AccountSnapshot setDeploymentInfo(DeploymentInfo deploymentInfo) { - this.deploymentNumber(deploymentInfo.deploymentNumber(address)); - this.deploymentStatus(deploymentInfo.getDeploymentStatus(address)); + deploymentNumber(deploymentInfo.deploymentNumber(address)); + deploymentStatus(deploymentInfo.getDeploymentStatus(address)); return this; } public AccountSnapshot deployByteCode(Bytecode code) { - Preconditions.checkState( - deploymentStatus, "Deployment status should be true before deploying byte code."); + checkState(deploymentStatus, "Deployment status should be true before deploying byte code."); return new AccountSnapshot(address, nonce, balance, true, code, deploymentNumber, false); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index ebb58ab27c..517b4f2451 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -501,9 +501,9 @@ public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBo public void traceStartTransaction(final WorldView world, final Transaction tx) { pch.reset(); state.enter(); - txStack.enterTransaction(world, tx, transients.block()); + txStack.enterTransaction(this, world, tx, transients.block()); - TransactionProcessingMetadata transactionProcessingMetadata = txStack.current(); + final TransactionProcessingMetadata transactionProcessingMetadata = txStack.current(); this.enterTransaction(); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java index 22005cf5fc..295712609e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java @@ -62,11 +62,11 @@ public void resetBlock() { this.relativeTransactionNumber = 0; } - public void enterTransaction(final WorldView world, final Transaction tx, Block block) { + public void enterTransaction(final Hub hub, final WorldView world, final Transaction tx, Block block) { this.enter(); final TransactionProcessingMetadata newTx = - new TransactionProcessingMetadata( + new TransactionProcessingMetadata(hub, world, tx, block, relativeTransactionNumber, currentAbsNumber); this.txs.add(newTx); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 7404e96a12..b7d3a33fb8 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -53,8 +53,8 @@ public class TransactionProcessingMetadata { final long baseFee; final boolean isDeployment; - @Setter int recipientAddressDeploymentNumber; - @Setter boolean recipientAddressDeploymentStatus; + final int recipientAddressDeploymentNumber; + final boolean recipientAddressDeploymentStatus; @Accessors(fluent = true) final boolean requiresEvmExecution; @@ -128,43 +128,43 @@ public record EphemeralAccount(Address address, int deploymentNumber) {} public record AttemptedSelfDestruct(int hubStamp, CallFrame callFrame) {} public TransactionProcessingMetadata( + final Hub hub, final WorldView world, final Transaction transaction, final Block block, final int relativeTransactionNumber, final int absoluteTransactionNumber) { this.absoluteTransactionNumber = absoluteTransactionNumber; - this.relativeBlockNumber = block.blockNumber(); - this.coinbase = block.coinbaseAddress(); - this.baseFee = block.baseFee().toLong(); + relativeBlockNumber = block.blockNumber(); + coinbase = block.coinbaseAddress(); + baseFee = block.baseFee().toLong(); - this.besuTransaction = transaction; + besuTransaction = transaction; this.relativeTransactionNumber = relativeTransactionNumber; - this.isDeployment = transaction.getTo().isEmpty(); - this.requiresEvmExecution = computeRequiresEvmExecution(world); - this.copyTransactionCallData = computeCopyCallData(); + isDeployment = transaction.getTo().isEmpty(); + requiresEvmExecution = computeRequiresEvmExecution(world); + copyTransactionCallData = computeCopyCallData(); - this.initialBalance = getInitialBalance(world); + initialBalance = getInitialBalance(world); // Note: Besu's dataCost computation contains // - the 21_000 transaction cost (we deduce it) // - the contract creation cost in case of deployment (we set deployment to false to not add it) - this.dataCost = + dataCost = ZkTracer.gasCalculator.transactionIntrinsicGasCost(besuTransaction.getPayload(), false) - GAS_CONST_G_TRANSACTION; - this.accessListCost = + accessListCost = besuTransaction.getAccessList().map(ZkTracer.gasCalculator::accessListGasCost).orElse(0L); - this.initiallyAvailableGas = getInitiallyAvailableGas(); + initiallyAvailableGas = getInitiallyAvailableGas(); - this.effectiveRecipient = effectiveToAddress(besuTransaction); + effectiveRecipient = effectiveToAddress(besuTransaction); - this.effectiveGasPrice = computeEffectiveGasPrice(); - } + effectiveGasPrice = computeEffectiveGasPrice(); - public void captureInitialRecipientAddressDeploymentInfoValues(Hub hub) { recipientAddressDeploymentNumber = hub.deploymentNumberOf(effectiveRecipient); recipientAddressDeploymentStatus = hub.deploymentStatusOf(effectiveRecipient); + } public void setPreFinalisationValues( From 9f0664945d92a41452819c6b7ee46d6e85199f89 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 1 Oct 2024 10:02:29 +0530 Subject: [PATCH 3/8] some more cleaning Signed-off-by: Francois Bojarski --- .../zktracer/module/hub/TransactionStack.java | 21 ++++++++++--------- .../hub/section/halt/SelfdestructSection.java | 8 +++---- .../linea/zktracer/module/romlex/RomLex.java | 5 ++--- .../types/TransactionProcessingMetadata.java | 3 +-- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java index 295712609e..caa0bf310b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java @@ -27,22 +27,22 @@ @Getter public class TransactionStack implements StackedContainer { - private final List txs = + private final List transactions = new ArrayList<>(200); // TODO: write the allocated memory from .toml file private int currentAbsNumber; private int relativeTransactionNumber; public TransactionProcessingMetadata current() { - return txs.getLast(); + return transactions.getLast(); } /* WARN: can't be called if currentAbsNumber == 1*/ public TransactionProcessingMetadata previous() { - return this.txs.get(this.txs.size() - 2); + return this.transactions.get(this.transactions.size() - 2); } public TransactionProcessingMetadata getByAbsoluteTransactionNumber(final int id) { - return this.txs.get(id - 1); + return this.transactions.get(id - 1); } @Override @@ -53,7 +53,7 @@ public void enter() { @Override public void pop() { - this.txs.remove(this.current()); + this.transactions.remove(this.current()); this.currentAbsNumber -= 1; this.relativeTransactionNumber -= 1; } @@ -62,19 +62,20 @@ public void resetBlock() { this.relativeTransactionNumber = 0; } - public void enterTransaction(final Hub hub, final WorldView world, final Transaction tx, Block block) { + public void enterTransaction( + final Hub hub, final WorldView world, final Transaction tx, Block block) { this.enter(); final TransactionProcessingMetadata newTx = - new TransactionProcessingMetadata(hub, - world, tx, block, relativeTransactionNumber, currentAbsNumber); + new TransactionProcessingMetadata( + hub, world, tx, block, relativeTransactionNumber, currentAbsNumber); - this.txs.add(newTx); + transactions.add(newTx); } // @françois what replaces this for message calls to smart contracts ? public void setCodeFragmentIndex(Hub hub) { - for (TransactionProcessingMetadata tx : this.txs) { + for (TransactionProcessingMetadata tx : transactions) { final int cfi = tx.requiresCfiUpdate() ? hub.getCfiByMetaData( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java index 7925065b9a..767863088b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/halt/SelfdestructSection.java @@ -245,9 +245,9 @@ public void resolvePostTransaction( return; } - Map effectiveSelfDestructMap = + final Map effectiveSelfDestructMap = transactionProcessingMetadata.getEffectiveSelfDestructMap(); - EphemeralAccount ephemeralAccount = + final EphemeralAccount ephemeralAccount = new EphemeralAccount( addressWhichMaySelfDestruct, selfdestructorAccountAfter.deploymentNumber()); @@ -259,7 +259,7 @@ public void resolvePostTransaction( checkArgument(hubStamp >= selfDestructTime); - AccountSnapshot accountBeforeSelfDestruct = + final AccountSnapshot accountBeforeSelfDestruct = transactionProcessingMetadata.getDestructedAccountsSnapshot().stream() .filter( accountSnapshot -> accountSnapshot.address().equals(addressWhichMaySelfDestruct)) @@ -275,7 +275,7 @@ public void resolvePostTransaction( // hub's completeLineaTransaction which in turn calls // freshDeploymentNumberFinishingSelfdestruct() // which raises the deployment number and sets the deployment status to false - AccountFragment accountWipingFragment = + final AccountFragment accountWipingFragment = hub.factories() .accountFragment() .make( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java index 7b8325eb83..91d3a5b4d6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.*; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGE; import static net.consensys.linea.zktracer.opcode.OpCode.*; +import static net.consensys.linea.zktracer.runtime.callstack.CallFrame.getOpCode; import static net.consensys.linea.zktracer.types.AddressUtils.getDeploymentAddress; import static net.consensys.linea.zktracer.types.AddressUtils.highPart; import static net.consensys.linea.zktracer.types.AddressUtils.lowPart; @@ -240,9 +241,7 @@ public void callRomLex(final MessageFrame frame) { } default -> throw new RuntimeException( - String.format( - "%s does not trigger the creation of ROM_LEX", - OpCode.of(frame.getCurrentOperation().getOpcode()))); + String.format("%s does not trigger the creation of ROM_LEX", getOpCode(frame))); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index b7d3a33fb8..be784d9893 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -128,7 +128,7 @@ public record EphemeralAccount(Address address, int deploymentNumber) {} public record AttemptedSelfDestruct(int hubStamp, CallFrame callFrame) {} public TransactionProcessingMetadata( - final Hub hub, + final Hub hub, final WorldView world, final Transaction transaction, final Block block, @@ -164,7 +164,6 @@ public TransactionProcessingMetadata( recipientAddressDeploymentNumber = hub.deploymentNumberOf(effectiveRecipient); recipientAddressDeploymentStatus = hub.deploymentStatusOf(effectiveRecipient); - } public void setPreFinalisationValues( From fd2419fba6ab724ae284f0ba5a4f6e470e85436a Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 1 Oct 2024 10:11:57 +0530 Subject: [PATCH 4/8] spotless Signed-off-by: Francois Bojarski --- .../main/java/net/consensys/linea/zktracer/module/hub/Hub.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 04bdbc7f3d..0aa7c7d58d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -518,8 +518,6 @@ public void traceStartTransaction(final WorldView world, final Transaction tx) { new TxInitializationSection(this, world); } - transactionProcessingMetadata.captureInitialRecipientAddressDeploymentInfoValues(this); - /* * TODO: the ID = 0 (universal parent context) context should * 1. be shared by all transactions in a conflation (OK) From 8e66fa34cc025efeae21d28a0f9ed92156030471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 1 Oct 2024 10:46:25 +0200 Subject: [PATCH 5/8] fix: removed ROM_LEX inclusion of "SELFDESTRUCT induced non deployments" --- .../linea/zktracer/module/romlex/RomLex.java | 11 ----------- .../zktracer/types/TransactionProcessingMetadata.java | 3 --- 2 files changed, 14 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java index 91d3a5b4d6..b3627d618e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romlex/RomLex.java @@ -245,17 +245,6 @@ public void callRomLex(final MessageFrame frame) { } } - public void callRomLexForSelfdestruct(final Address addressWhichWillSelfdestruct) { - - final RomOperation operation = - new RomOperation( - ContractMetadata.canonical(hub, addressWhichWillSelfdestruct), - false, - false, - Bytes.EMPTY); - operations.add(operation); - } - @Override public void resolveUponContextEntry(Hub hub) { checkArgument(hub.messageFrame().getType() == MessageFrame.Type.CONTRACT_CREATION); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index be784d9893..a7f28eba2b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -196,9 +196,6 @@ public void completeLineaTransaction( destructedAccountsSnapshot.add( AccountSnapshot.fromAddress( address, true, hub.deploymentNumberOf(address), hub.deploymentStatusOf(address))); - - // registering the "fresh new deployment number" (that doesn't correspond to any deployment) - hub.romLex().callRomLexForSelfdestruct(address); } determineSelfDestructTimeStamp(); From 1c20046638a42b267ef07c5180ac32eda3d96304 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Tue, 1 Oct 2024 14:18:37 +0530 Subject: [PATCH 6/8] fix my mistake Signed-off-by: Francois Bojarski --- .../consensys/linea/zktracer/module/hub/Hub.java | 4 +++- .../linea/zktracer/module/hub/TransactionStack.java | 5 ++--- .../types/TransactionProcessingMetadata.java | 13 +++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 0aa7c7d58d..263aed127b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -500,7 +500,7 @@ public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBo public void traceStartTransaction(final WorldView world, final Transaction tx) { pch.reset(); state.enter(); - txStack.enterTransaction(this, world, tx, transients.block()); + txStack.enterTransaction(world, tx, transients.block()); final TransactionProcessingMetadata transactionProcessingMetadata = txStack.current(); @@ -518,6 +518,8 @@ public void traceStartTransaction(final WorldView world, final Transaction tx) { new TxInitializationSection(this, world); } + transactionProcessingMetadata.captureInitialRecipientAddressDeploymentInfoValues(this); + /* * TODO: the ID = 0 (universal parent context) context should * 1. be shared by all transactions in a conflation (OK) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java index caa0bf310b..977ee929f9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java @@ -62,13 +62,12 @@ public void resetBlock() { this.relativeTransactionNumber = 0; } - public void enterTransaction( - final Hub hub, final WorldView world, final Transaction tx, Block block) { + public void enterTransaction(final WorldView world, final Transaction tx, Block block) { this.enter(); final TransactionProcessingMetadata newTx = new TransactionProcessingMetadata( - hub, world, tx, block, relativeTransactionNumber, currentAbsNumber); + world, tx, block, relativeTransactionNumber, currentAbsNumber); transactions.add(newTx); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index a7f28eba2b..17d0099e06 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -53,8 +53,8 @@ public class TransactionProcessingMetadata { final long baseFee; final boolean isDeployment; - final int recipientAddressDeploymentNumber; - final boolean recipientAddressDeploymentStatus; + int recipientAddressDeploymentNumber; + boolean recipientAddressDeploymentStatus; @Accessors(fluent = true) final boolean requiresEvmExecution; @@ -128,7 +128,6 @@ public record EphemeralAccount(Address address, int deploymentNumber) {} public record AttemptedSelfDestruct(int hubStamp, CallFrame callFrame) {} public TransactionProcessingMetadata( - final Hub hub, final WorldView world, final Transaction transaction, final Block block, @@ -161,9 +160,6 @@ public TransactionProcessingMetadata( effectiveRecipient = effectiveToAddress(besuTransaction); effectiveGasPrice = computeEffectiveGasPrice(); - - recipientAddressDeploymentNumber = hub.deploymentNumberOf(effectiveRecipient); - recipientAddressDeploymentStatus = hub.deploymentStatusOf(effectiveRecipient); } public void setPreFinalisationValues( @@ -330,4 +326,9 @@ private void determineSelfDestructTimeStamp() { } } } + + public void captureInitialRecipientAddressDeploymentInfoValues(Hub hub) { + recipientAddressDeploymentNumber = hub.deploymentNumberOf(effectiveRecipient); + recipientAddressDeploymentStatus = hub.deploymentStatusOf(effectiveRecipient); + } } From ac79de9c6891b3bcd1403a7963cdd31455212ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Tue, 1 Oct 2024 11:54:24 +0200 Subject: [PATCH 7/8] ras(renaming) --- .../net/consensys/linea/zktracer/module/hub/Hub.java | 5 ++++- .../linea/zktracer/module/hub/TransactionStack.java | 4 ++-- .../types/TransactionProcessingMetadata.java | 12 +++++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 263aed127b..8ff261aedb 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -518,7 +518,10 @@ public void traceStartTransaction(final WorldView world, final Transaction tx) { new TxInitializationSection(this, world); } - transactionProcessingMetadata.captureInitialRecipientAddressDeploymentInfoValues(this); + // Note: for deployment transactions the deployment number / status were updated during the + // initialization phase. We are thus capturing the respective XXX_NEW's + transactionProcessingMetadata + .captureUpdatedInitialRecipientAddressDeploymentInfoAtTransactionStart(this); /* * TODO: the ID = 0 (universal parent context) context should diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java index 977ee929f9..4634a6a0c2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java @@ -79,8 +79,8 @@ public void setCodeFragmentIndex(Hub hub) { tx.requiresCfiUpdate() ? hub.getCfiByMetaData( tx.getEffectiveRecipient(), - tx.getRecipientAddressDeploymentNumber(), - tx.isRecipientAddressDeploymentStatus()) + tx.getUpdatedRecipientAddressDeploymentNumberAtTransactionStart(), + tx.isUpdatedRecipientAddressDeploymentStatusAtTransactionStart()) : 0; tx.setCodeFragmentIndex(cfi); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java index 17d0099e06..0ad9a242c1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/types/TransactionProcessingMetadata.java @@ -53,8 +53,8 @@ public class TransactionProcessingMetadata { final long baseFee; final boolean isDeployment; - int recipientAddressDeploymentNumber; - boolean recipientAddressDeploymentStatus; + int updatedRecipientAddressDeploymentNumberAtTransactionStart; + boolean updatedRecipientAddressDeploymentStatusAtTransactionStart; @Accessors(fluent = true) final boolean requiresEvmExecution; @@ -327,8 +327,10 @@ private void determineSelfDestructTimeStamp() { } } - public void captureInitialRecipientAddressDeploymentInfoValues(Hub hub) { - recipientAddressDeploymentNumber = hub.deploymentNumberOf(effectiveRecipient); - recipientAddressDeploymentStatus = hub.deploymentStatusOf(effectiveRecipient); + public void captureUpdatedInitialRecipientAddressDeploymentInfoAtTransactionStart(Hub hub) { + updatedRecipientAddressDeploymentNumberAtTransactionStart = + hub.deploymentNumberOf(effectiveRecipient); + updatedRecipientAddressDeploymentStatusAtTransactionStart = + hub.deploymentStatusOf(effectiveRecipient); } } From 28bee3f741089057f7321e524eba453bafc1413c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= <38285177+OlivierBBB@users.noreply.github.com> Date: Tue, 1 Oct 2024 13:38:11 +0200 Subject: [PATCH 8/8] ras: delete comment --- .../consensys/linea/zktracer/module/hub/TransactionStack.java | 1 - 1 file changed, 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java index 4634a6a0c2..257375f238 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TransactionStack.java @@ -72,7 +72,6 @@ public void enterTransaction(final WorldView world, final Transaction tx, Block transactions.add(newTx); } - // @françois what replaces this for message calls to smart contracts ? public void setCodeFragmentIndex(Hub hub) { for (TransactionProcessingMetadata tx : transactions) { final int cfi =