From f8b457711462fa2de9ee4df6eec9278c4fadc88a Mon Sep 17 00:00:00 2001 From: arijitdutta67 Date: Tue, 10 Sep 2024 12:55:34 +0530 Subject: [PATCH 01/74] Adding transaction level map --- .../hub/fragment/account/AccountFragment.java | 27 ++++++++++++++++++- .../types/TransactionProcessingMetadata.java | 13 +++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index a1974871d3..0ecb852a8e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -39,6 +39,7 @@ import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.worldstate.WorldView; @@ -170,7 +171,7 @@ public Trace trace(Trace trace) { @Override public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { final Map effectiveSelfDestructMap = transactionProcessingMetadata.getEffectiveSelfDestructMap(); final TransactionProcessingMetadata.EphemeralAccount ephemeralAccount = @@ -184,6 +185,30 @@ public void resolvePostTransaction( markedForSelfDestruct = false; markedForSelfDestructNew = false; } + // Setting the post transaction first and last value + // Initialise the Account First and Last map + // Todo: Check if this is buggy + final Map txnAccountFirstAndLastMap = + transactionProcessingMetadata.getTransactAccountFirstAndLastMap(); + if (!txnAccountFirstAndLastMap.containsKey(oldState.address())) { + TransactionProcessingMetadata.TransactAccountFirstAndLast txnFirstAndLast = new TransactionProcessingMetadata.TransactAccountFirstAndLast(); + txnFirstAndLast.setFirst(this); + txnFirstAndLast.setLast(this); + txnFirstAndLast.setDom(this.domSubStampsSubFragment.domStamp()); + txnFirstAndLast.setSub(this.domSubStampsSubFragment.subStamp()); + txnAccountFirstAndLastMap.put(oldState.address(), txnFirstAndLast); + } else { + TransactionProcessingMetadata.TransactAccountFirstAndLast txnFirstAndLast = txnAccountFirstAndLastMap.get(oldState.address()); + // Replace condition + if (txnFirstAndLast.getDom() < this.domSubStampsSubFragment.domStamp() || + (txnFirstAndLast.getDom() == this.domSubStampsSubFragment.domStamp() && + txnFirstAndLast.getSub() > this.domSubStampsSubFragment.subStamp())) { + txnFirstAndLast.setLast(this); + txnFirstAndLast.setDom(this.domSubStampsSubFragment.domStamp()); + txnFirstAndLast.setSub(this.domSubStampsSubFragment.subStamp()); + txnAccountFirstAndLastMap.put(oldState.address(), txnFirstAndLast); + } + } } @Override 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 f3560ed54e..19731607b2 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 @@ -33,6 +33,8 @@ import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; +import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.transients.Block; import net.consensys.linea.zktracer.module.hub.transients.StorageInitialValues; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; @@ -119,6 +121,17 @@ public class TransactionProcessingMetadata implements PostTransactionDefer { @Getter Map effectiveSelfDestructMap = new HashMap<>(); + // Map for the first and last account occurance + @Getter @Setter + public static class TransactAccountFirstAndLast { + AccountFragment first; + AccountFragment last; + int dom; + int sub; + } + @Getter + Map transactAccountFirstAndLastMap = new HashMap<>(); + // Ephermeral accounts are both accounts that have been deployed on-chain // and accounts that live for a limited time public record EphemeralAccount(Address address, int deploymentNumber) {} From b3fee907e744c0eb06ef3ac04ef520257dd47cc2 Mon Sep 17 00:00:00 2001 From: arijitdutta67 Date: Tue, 10 Sep 2024 15:25:00 +0530 Subject: [PATCH 02/74] adding map update method --- .../hub/fragment/account/AccountFragment.java | 42 +++++++++++-------- .../types/TransactionProcessingMetadata.java | 6 +++ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 0ecb852a8e..f325cd4b3c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -108,6 +108,8 @@ public AccountFragment( isDeployment = newState.deploymentStatus(); this.addressToTrim = addressToTrim; this.domSubStampsSubFragment = domSubStampsSubFragment; + // Updating the map + updateAccountFirstAndLast(); // This allows us to properly fill EXISTS_INFTY, DEPLOYMENT_NUMBER_INFTY and CODE_FRAGMENT_INDEX hub.defers().scheduleForPostConflation(this); @@ -185,17 +187,30 @@ public void resolvePostTransaction( markedForSelfDestruct = false; markedForSelfDestructNew = false; } + updateAccountFirstAndLast(); + + } + + @Override + public void resolvePostConflation(Hub hub, WorldView world) { + deploymentNumberInfinity = hub.deploymentNumberOf(oldState.address()); + existsInfinity = world.get(oldState.address()) != null; + codeFragmentIndex = + requiresRomlex + ? hub.romLex() + .getCodeFragmentIndexByMetadata( + ContractMetadata.make(oldState.address(), deploymentNumber, isDeployment)) + : 0; + } + public void updateAccountFirstAndLast() { // Setting the post transaction first and last value // Initialise the Account First and Last map - // Todo: Check if this is buggy final Map txnAccountFirstAndLastMap = - transactionProcessingMetadata.getTransactAccountFirstAndLastMap(); + this. transactionProcessingMetadata.getTransactAccountFirstAndLastMap(); if (!txnAccountFirstAndLastMap.containsKey(oldState.address())) { - TransactionProcessingMetadata.TransactAccountFirstAndLast txnFirstAndLast = new TransactionProcessingMetadata.TransactAccountFirstAndLast(); - txnFirstAndLast.setFirst(this); - txnFirstAndLast.setLast(this); - txnFirstAndLast.setDom(this.domSubStampsSubFragment.domStamp()); - txnFirstAndLast.setSub(this.domSubStampsSubFragment.subStamp()); + TransactionProcessingMetadata.TransactAccountFirstAndLast txnFirstAndLast = + new TransactionProcessingMetadata.TransactAccountFirstAndLast(this, this, this.domSubStampsSubFragment.domStamp(), + this.domSubStampsSubFragment.subStamp()); txnAccountFirstAndLastMap.put(oldState.address(), txnFirstAndLast); } else { TransactionProcessingMetadata.TransactAccountFirstAndLast txnFirstAndLast = txnAccountFirstAndLastMap.get(oldState.address()); @@ -209,17 +224,8 @@ public void resolvePostTransaction( txnAccountFirstAndLastMap.put(oldState.address(), txnFirstAndLast); } } - } - @Override - public void resolvePostConflation(Hub hub, WorldView world) { - deploymentNumberInfinity = hub.deploymentNumberOf(oldState.address()); - existsInfinity = world.get(oldState.address()) != null; - codeFragmentIndex = - requiresRomlex - ? hub.romLex() - .getCodeFragmentIndexByMetadata( - ContractMetadata.make(oldState.address(), deploymentNumber, isDeployment)) - : 0; } } + + 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 19731607b2..ea477810b5 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,6 +128,12 @@ public static class TransactAccountFirstAndLast { AccountFragment last; int dom; int sub; + public TransactAccountFirstAndLast(AccountFragment first, AccountFragment last, int dom, int sub) { + this.first = first; + this.last = last; + this.dom = dom; + this.sub = sub; + } } @Getter Map transactAccountFirstAndLastMap = new HashMap<>(); From 58ec254e3e10b786416f52082698cc0ce3e4b4b4 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Wed, 11 Sep 2024 14:12:46 +0200 Subject: [PATCH 03/74] =?UTF-8?q?block=20level=20maps=E2=80=94first=20idea?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Arijit Dutta <37040536+arijitdutta67@users.noreply.github.com> --- .../linea/zktracer/module/hub/Hub.java | 61 +++++++++++++++++-- .../zktracer/module/hub/TransactionStack.java | 2 + .../hub/fragment/account/AccountFragment.java | 15 ++--- .../module/hub/transients/Transients.java | 25 ++++++++ .../types/TransactionProcessingMetadata.java | 17 ++++-- 5 files changed, 104 insertions(+), 16 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 557f2fb493..2fa4c8230a 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 @@ -26,13 +26,11 @@ import static org.hyperledger.besu.evm.frame.MessageFrame.Type.*; import java.nio.MappedByteBuffer; -import java.util.HashMap; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.stream.Stream; import lombok.Getter; +import lombok.Setter; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; import net.consensys.linea.zktracer.ColumnHeader; @@ -50,6 +48,7 @@ import net.consensys.linea.zktracer.module.hub.defer.DeferRegistry; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.StackFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.section.AccountSection; import net.consensys.linea.zktracer.module.hub.section.CallDataLoadSection; import net.consensys.linea.zktracer.module.hub.section.ContextSection; @@ -128,6 +127,7 @@ import net.consensys.linea.zktracer.types.Bytecode; import net.consensys.linea.zktracer.types.MemorySpan; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import org.apache.commons.lang3.tuple.Pair; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; @@ -485,11 +485,13 @@ public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBo for (Module m : modules) { m.traceEndBlock(blockHeader, blockBody); } + updateBlockMap(); } public void traceStartTransaction(final WorldView world, final Transaction tx) { pch.reset(); state.enter(); + var myBlock = transients.block(); txStack.enterTransaction(world, tx, transients.block()); defers.scheduleForPostTransaction(txStack.current()); @@ -1162,4 +1164,55 @@ public final int deploymentNumberOfAccountAddress() { public final boolean deploymentStatusOfAccountAddress() { return deploymentStatusOf(this.accountAddress()); } + + + + public void updateBlockMap() { + Map blockMap = transients.txnAccountFirstLastBlockMap(); + List txn = txStack.getTxs(); + for (int i = 0; i < txn.size(); i++) { + TransactionProcessingMetadata metadata = txn.get(i); + if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) + { + int blockNumber = transients.block().blockNumber(); + Map localMap = metadata.getTransactAccountFirstAndLastMap(); + for (Address addr:localMap.keySet()) { + TransactionProcessingMetadata.TransactAccountFirstAndLast localInfo = localMap.get(addr); + Transients.AddrBlockPair pairAddrBlock = new Transients.AddrBlockPair(addr, blockNumber); + // localValue exists for sure because addr belongs to the keySet of the local map + TransactionProcessingMetadata.TransactAccountFirstAndLast localValue = localMap.get(addr); + if (!blockMap.containsKey(pairAddrBlock)) { + // the pair is not present in the map + blockMap.put(pairAddrBlock, localValue); + } else { + TransactionProcessingMetadata.TransactAccountFirstAndLast blockValue = blockMap.get(pairAddrBlock); + // update the first part of the blockValue + if (TransactionProcessingMetadata.TransactAccountFirstAndLast.strictlySmallerStamps( + localValue.getFirstDom(), localValue.getFirstSub(), blockValue.getFirstDom(), blockValue.getFirstSub())) { + // chronologically checks that localValue.First is before blockValue.First + // localValue comes chronologically before, and should be the first value of the map. + blockValue.setFirst(localValue.getFirst()); + blockValue.setFirstDom(localValue.getFirstDom()); + blockValue.setFirstSub(localValue.getFirstSub()); + + // update the last part of the blockValue + if (TransactionProcessingMetadata.TransactAccountFirstAndLast.strictlySmallerStamps( + blockValue.getLastDom(), blockValue.getLastSub(), localValue.getLastDom(), localValue.getLastSub())) { + // chronologically checks that blockValue.Last is before localValue.Last + // localValue comes chronologically after, and should be the final value of the map. + blockValue.setLast(localValue.getLast()); + blockValue.setLastDom(localValue.getLastDom()); + blockValue.setLastSub(localValue.getLastSub()); + } + blockMap.put(pairAddrBlock, blockValue); + } + } + + } + } + } + } +} + + 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..673af31b4f 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 @@ -19,6 +19,7 @@ import java.util.List; import lombok.Getter; +import lombok.Setter; import net.consensys.linea.zktracer.container.StackedContainer; import net.consensys.linea.zktracer.module.hub.transients.Block; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; @@ -27,6 +28,7 @@ @Getter public class TransactionStack implements StackedContainer { + @Getter private final List txs = new ArrayList<>(200); // TODO: write the allocated memory from .toml file private int currentAbsNumber; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index f325cd4b3c..6890f9720f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -208,19 +208,20 @@ public void updateAccountFirstAndLast() { final Map txnAccountFirstAndLastMap = this. transactionProcessingMetadata.getTransactAccountFirstAndLastMap(); if (!txnAccountFirstAndLastMap.containsKey(oldState.address())) { + int dom = this.domSubStampsSubFragment.domStamp(); + int sub = this.domSubStampsSubFragment.subStamp(); TransactionProcessingMetadata.TransactAccountFirstAndLast txnFirstAndLast = - new TransactionProcessingMetadata.TransactAccountFirstAndLast(this, this, this.domSubStampsSubFragment.domStamp(), - this.domSubStampsSubFragment.subStamp()); + new TransactionProcessingMetadata.TransactAccountFirstAndLast(this, this, dom, sub, dom, sub); txnAccountFirstAndLastMap.put(oldState.address(), txnFirstAndLast); } else { TransactionProcessingMetadata.TransactAccountFirstAndLast txnFirstAndLast = txnAccountFirstAndLastMap.get(oldState.address()); // Replace condition - if (txnFirstAndLast.getDom() < this.domSubStampsSubFragment.domStamp() || - (txnFirstAndLast.getDom() == this.domSubStampsSubFragment.domStamp() && - txnFirstAndLast.getSub() > this.domSubStampsSubFragment.subStamp())) { + if (TransactionProcessingMetadata.TransactAccountFirstAndLast.strictlySmallerStamps( + txnFirstAndLast.getLastDom(), txnFirstAndLast.getLastSub(), + this.domSubStampsSubFragment.domStamp(), this.domSubStampsSubFragment.subStamp())) { txnFirstAndLast.setLast(this); - txnFirstAndLast.setDom(this.domSubStampsSubFragment.domStamp()); - txnFirstAndLast.setSub(this.domSubStampsSubFragment.subStamp()); + txnFirstAndLast.setLastDom(this.domSubStampsSubFragment.domStamp()); + txnFirstAndLast.setLastSub(this.domSubStampsSubFragment.subStamp()); txnAccountFirstAndLastMap.put(oldState.address(), txnFirstAndLast); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java index 298111a06d..2e794f62b0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java @@ -16,9 +16,16 @@ package net.consensys.linea.zktracer.module.hub.transients; import lombok.Getter; +import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import org.apache.commons.lang3.tuple.Pair; +import org.hyperledger.besu.datatypes.Address; + +import java.util.HashMap; +import java.util.Map; /** * This class stores data and provide information accessible through the {@link Hub} of various @@ -38,6 +45,24 @@ public class Transients { /** provides operation-related information */ final OperationAncillaries op; + + + @Getter + Map txnAccountFirstLastBlockMap = new HashMap<>(); + + public static class AddrBlockPair { + @Getter + private Address address; + @Getter + private int blockNumber; + + public AddrBlockPair(Address addr, int blockNumber) { + this.address = addr; + this.blockNumber = blockNumber; + } + } + + public TransactionProcessingMetadata tx() { return this.hub.txStack().current(); } 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 ea477810b5..7ea288747d 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 @@ -126,13 +126,20 @@ public class TransactionProcessingMetadata implements PostTransactionDefer { public static class TransactAccountFirstAndLast { AccountFragment first; AccountFragment last; - int dom; - int sub; - public TransactAccountFirstAndLast(AccountFragment first, AccountFragment last, int dom, int sub) { + int firstDom, firstSub; + int lastDom, lastSub; + public TransactAccountFirstAndLast(AccountFragment first, AccountFragment last, int firstDom, int firstSub, int lastDom, int lastSub) { this.first = first; this.last = last; - this.dom = dom; - this.sub = sub; + this.firstDom = firstDom; + this.firstSub = firstSub; + this.lastDom = lastDom; + this.lastSub = lastSub; + } + public static boolean strictlySmallerStamps(int firstDom, int firstSub, int lastDom, int lastSub) { + return firstDom < lastDom || + (firstDom == lastDom && + firstSub > lastSub); } } @Getter From 56b90f80687108e0b5618fbc48413a2104cb5f3c Mon Sep 17 00:00:00 2001 From: arijitdutta67 Date: Thu, 12 Sep 2024 13:22:11 +0530 Subject: [PATCH 04/74] fixing minor typos --- .../linea/zktracer/module/hub/Hub.java | 75 +++++++++---------- 1 file changed, 36 insertions(+), 39 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 2fa4c8230a..6d2016a850 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 @@ -1170,47 +1170,44 @@ public final boolean deploymentStatusOfAccountAddress() { public void updateBlockMap() { Map blockMap = transients.txnAccountFirstLastBlockMap(); List txn = txStack.getTxs(); - for (int i = 0; i < txn.size(); i++) { - TransactionProcessingMetadata metadata = txn.get(i); - if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) - { - int blockNumber = transients.block().blockNumber(); - Map localMap = metadata.getTransactAccountFirstAndLastMap(); - for (Address addr:localMap.keySet()) { - TransactionProcessingMetadata.TransactAccountFirstAndLast localInfo = localMap.get(addr); - Transients.AddrBlockPair pairAddrBlock = new Transients.AddrBlockPair(addr, blockNumber); - // localValue exists for sure because addr belongs to the keySet of the local map - TransactionProcessingMetadata.TransactAccountFirstAndLast localValue = localMap.get(addr); - if (!blockMap.containsKey(pairAddrBlock)) { - // the pair is not present in the map - blockMap.put(pairAddrBlock, localValue); - } else { - TransactionProcessingMetadata.TransactAccountFirstAndLast blockValue = blockMap.get(pairAddrBlock); - // update the first part of the blockValue - if (TransactionProcessingMetadata.TransactAccountFirstAndLast.strictlySmallerStamps( - localValue.getFirstDom(), localValue.getFirstSub(), blockValue.getFirstDom(), blockValue.getFirstSub())) { - // chronologically checks that localValue.First is before blockValue.First - // localValue comes chronologically before, and should be the first value of the map. - blockValue.setFirst(localValue.getFirst()); - blockValue.setFirstDom(localValue.getFirstDom()); - blockValue.setFirstSub(localValue.getFirstSub()); - - // update the last part of the blockValue - if (TransactionProcessingMetadata.TransactAccountFirstAndLast.strictlySmallerStamps( - blockValue.getLastDom(), blockValue.getLastSub(), localValue.getLastDom(), localValue.getLastSub())) { - // chronologically checks that blockValue.Last is before localValue.Last - // localValue comes chronologically after, and should be the final value of the map. - blockValue.setLast(localValue.getLast()); - blockValue.setLastDom(localValue.getLastDom()); - blockValue.setLastSub(localValue.getLastSub()); - } - blockMap.put(pairAddrBlock, blockValue); + for (TransactionProcessingMetadata metadata : txn) { + if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) { + int blockNumber = transients.block().blockNumber(); + Map localMap = metadata.getTransactAccountFirstAndLastMap(); + for (Address addr : localMap.keySet()) { + Transients.AddrBlockPair pairAddrBlock = new Transients.AddrBlockPair(addr, blockNumber); + // localValue exists for sure because addr belongs to the keySet of the local map + TransactionProcessingMetadata.TransactAccountFirstAndLast localValue = localMap.get(addr); + if (!blockMap.containsKey(pairAddrBlock)) { + // the pair is not present in the map + blockMap.put(pairAddrBlock, localValue); + } else { + TransactionProcessingMetadata.TransactAccountFirstAndLast blockValue = blockMap.get(pairAddrBlock); + // update the first part of the blockValue + if (TransactionProcessingMetadata.TransactAccountFirstAndLast.strictlySmallerStamps( + localValue.getFirstDom(), localValue.getFirstSub(), blockValue.getFirstDom(), blockValue.getFirstSub())) { + // chronologically checks that localValue.First is before blockValue.First + // localValue comes chronologically before, and should be the first value of the map. + blockValue.setFirst(localValue.getFirst()); + blockValue.setFirstDom(localValue.getFirstDom()); + blockValue.setFirstSub(localValue.getFirstSub()); + + // update the last part of the blockValue + if (TransactionProcessingMetadata.TransactAccountFirstAndLast.strictlySmallerStamps( + blockValue.getLastDom(), blockValue.getLastSub(), localValue.getLastDom(), localValue.getLastSub())) { + // chronologically checks that blockValue.Last is before localValue.Last + // localValue comes chronologically after, and should be the final value of the map. + blockValue.setLast(localValue.getLast()); + blockValue.setLastDom(localValue.getLastDom()); + blockValue.setLastSub(localValue.getLastSub()); + } + blockMap.put(pairAddrBlock, blockValue); + } + } + + } } - } - } - } - } } } From 0c8e16d1db083cd8c5b18892a01a4d119984c210 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 13 Sep 2024 14:02:14 +0200 Subject: [PATCH 05/74] remove update from post transaction defer. Co-Authored-By: Arijit Dutta <37040536+arijitdutta67@users.noreply.github.com> --- .../zktracer/module/hub/fragment/account/AccountFragment.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 6890f9720f..431b444a83 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -187,8 +187,6 @@ public void resolvePostTransaction( markedForSelfDestruct = false; markedForSelfDestructNew = false; } - updateAccountFirstAndLast(); - } @Override From 459005c9f4dcfe03d386538276d86b9d8a3e2bf2 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 13 Sep 2024 14:38:48 +0200 Subject: [PATCH 06/74] StateManagerMetadata class Co-Authored-By: Arijit Dutta <37040536+arijitdutta67@users.noreply.github.com> --- .../consensys/linea/zktracer/module/hub/Hub.java | 6 +++++- .../module/hub/transients/StateManagerMetadata.java | 13 +++++++++++++ .../zktracer/module/hub/transients/Transients.java | 3 +-- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java 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 6d2016a850..1ce0abc698 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 @@ -78,6 +78,7 @@ import net.consensys.linea.zktracer.module.hub.section.halt.StopSection; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.module.hub.signals.PlatformController; +import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; import net.consensys.linea.zktracer.module.hub.transients.Transients; import net.consensys.linea.zktracer.module.limits.Keccak; import net.consensys.linea.zktracer.module.limits.L2Block; @@ -158,6 +159,9 @@ public class Hub implements Module { /** provides phase-related volatile information */ @Getter Transients transients = new Transients(this); + /** Block and conflation-level metadata for computing columns relevant to the state manager.**/ + @Getter static StateManagerMetadata stateManagerMetadata = new StateManagerMetadata(); + /** * Long-lived states, not used in tracing per se but keeping track of data of the associated * lifetime @@ -1168,7 +1172,7 @@ public final boolean deploymentStatusOfAccountAddress() { public void updateBlockMap() { - Map blockMap = transients.txnAccountFirstLastBlockMap(); + Map blockMap = Hub.stateManagerMetadata().getTxnAccountFirstLastBlockMap();; List txn = txStack.getTxs(); for (TransactionProcessingMetadata metadata : txn) { if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java new file mode 100644 index 0000000000..1d42fa94d3 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java @@ -0,0 +1,13 @@ +package net.consensys.linea.zktracer.module.hub.transients; + +import lombok.Getter; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; + +import java.util.HashMap; +import java.util.Map; + +public class StateManagerMetadata +{ + @Getter + Map txnAccountFirstLastBlockMap = new HashMap<>(); +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java index 2e794f62b0..8998c6dc37 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java @@ -47,8 +47,7 @@ public class Transients { - @Getter - Map txnAccountFirstLastBlockMap = new HashMap<>(); + public static class AddrBlockPair { @Getter From 7e08c941146938f6f656535d683d08a0ab4793df Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 13 Sep 2024 14:45:44 +0200 Subject: [PATCH 07/74] TxMetadataInStorage Co-Authored-By: Arijit Dutta <37040536+arijitdutta67@users.noreply.github.com> --- .../module/hub/fragment/storage/StorageFragment.java | 3 +++ .../linea/zktracer/module/hub/section/SloadSection.java | 6 ++++-- .../linea/zktracer/module/hub/section/SstoreSection.java | 6 ++++-- .../module/hub/section/TxPreWarmingMacroSection.java | 3 ++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index 36e94b2d97..5d22c9b5e1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -28,6 +28,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; @RequiredArgsConstructor @Getter @@ -43,6 +44,8 @@ public final class StorageFragment implements TraceFragment { private final int blockNumber; private final StorageFragmentPurpose purpose; // for debugging purposes + final TransactionProcessingMetadata transactionProcessingMetadata; + public Trace trace(Trace trace) { final HashMap current = diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index 9671634cfd..d51aeedfdf 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -100,7 +100,8 @@ private StorageFragment doingSload(Hub hub) { true, DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0), hub.state.firstAndLastStorageSlotOccurrences.size(), - SLOAD_DOING); + SLOAD_DOING, + hub.txStack().current()); } @Override @@ -128,7 +129,8 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca incomingWarmth, undoingDomSubStamps, hub.state.firstAndLastStorageSlotOccurrences.size(), - SLOAD_UNDOING); + SLOAD_UNDOING, + hub.txStack().current()); this.addFragment(undoingSloadStorageFragment); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index acafc32918..3c998bd469 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -125,7 +125,8 @@ private StorageFragment doingSstore(Hub hub) { true, DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0), hub.state.firstAndLastStorageSlotOccurrences.size(), - SSTORE_DOING); + SSTORE_DOING, + hub.txStack().current()); } @Override @@ -146,7 +147,8 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca incomingWarmth, undoingDomSubStamps, hub.state.firstAndLastStorageSlotOccurrences.size(), - SSTORE_UNDOING); + SSTORE_UNDOING, + hub.txStack().current()); this.addFragment(undoingSstoreStorageFragment); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java index bf3a04293c..86ebc6d64d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java @@ -119,7 +119,8 @@ public TxPreWarmingMacroSection(WorldView world, Hub hub) { true, DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0), hub.state.firstAndLastStorageSlotOccurrences.size(), - PRE_WARMING); + PRE_WARMING, + hub.txStack().current()); new TxPrewarmingSection(hub, storageFragment); hub.state.updateOrInsertStorageSlotOccurrence( From b7373cd43b93ff46a7fa0cc8006b42d576c933e2 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 13 Sep 2024 15:02:31 +0200 Subject: [PATCH 08/74] Generic class for accounts and storage Co-Authored-By: Arijit Dutta <37040536+arijitdutta67@users.noreply.github.com> --- .../linea/zktracer/module/hub/Hub.java | 12 ++++++------ .../hub/fragment/account/AccountFragment.java | 10 +++++----- .../hub/transients/StateManagerMetadata.java | 3 ++- .../types/TransactionProcessingMetadata.java | 17 +++++++++++------ 4 files changed, 24 insertions(+), 18 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 1ce0abc698..fd06398437 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 @@ -1172,23 +1172,23 @@ public final boolean deploymentStatusOfAccountAddress() { public void updateBlockMap() { - Map blockMap = Hub.stateManagerMetadata().getTxnAccountFirstLastBlockMap();; + Map> blockMap = Hub.stateManagerMetadata().getTxnAccountFirstLastBlockMap();; List txn = txStack.getTxs(); for (TransactionProcessingMetadata metadata : txn) { if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) { int blockNumber = transients.block().blockNumber(); - Map localMap = metadata.getTransactAccountFirstAndLastMap(); + Map> localMap = metadata.getTransactAccountFirstAndLastMap(); for (Address addr : localMap.keySet()) { Transients.AddrBlockPair pairAddrBlock = new Transients.AddrBlockPair(addr, blockNumber); // localValue exists for sure because addr belongs to the keySet of the local map - TransactionProcessingMetadata.TransactAccountFirstAndLast localValue = localMap.get(addr); + TransactionProcessingMetadata.TransactFragmentFirstAndLast localValue = localMap.get(addr); if (!blockMap.containsKey(pairAddrBlock)) { // the pair is not present in the map blockMap.put(pairAddrBlock, localValue); } else { - TransactionProcessingMetadata.TransactAccountFirstAndLast blockValue = blockMap.get(pairAddrBlock); + TransactionProcessingMetadata.TransactFragmentFirstAndLast blockValue = blockMap.get(pairAddrBlock); // update the first part of the blockValue - if (TransactionProcessingMetadata.TransactAccountFirstAndLast.strictlySmallerStamps( + if (TransactionProcessingMetadata.TransactFragmentFirstAndLast.strictlySmallerStamps( localValue.getFirstDom(), localValue.getFirstSub(), blockValue.getFirstDom(), blockValue.getFirstSub())) { // chronologically checks that localValue.First is before blockValue.First // localValue comes chronologically before, and should be the first value of the map. @@ -1197,7 +1197,7 @@ public void updateBlockMap() { blockValue.setFirstSub(localValue.getFirstSub()); // update the last part of the blockValue - if (TransactionProcessingMetadata.TransactAccountFirstAndLast.strictlySmallerStamps( + if (TransactionProcessingMetadata.TransactFragmentFirstAndLast.strictlySmallerStamps( blockValue.getLastDom(), blockValue.getLastSub(), localValue.getLastDom(), localValue.getLastSub())) { // chronologically checks that blockValue.Last is before localValue.Last // localValue comes chronologically after, and should be the final value of the map. diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 431b444a83..358bba029b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -203,18 +203,18 @@ public void resolvePostConflation(Hub hub, WorldView world) { public void updateAccountFirstAndLast() { // Setting the post transaction first and last value // Initialise the Account First and Last map - final Map txnAccountFirstAndLastMap = + final Map> txnAccountFirstAndLastMap = this. transactionProcessingMetadata.getTransactAccountFirstAndLastMap(); if (!txnAccountFirstAndLastMap.containsKey(oldState.address())) { int dom = this.domSubStampsSubFragment.domStamp(); int sub = this.domSubStampsSubFragment.subStamp(); - TransactionProcessingMetadata.TransactAccountFirstAndLast txnFirstAndLast = - new TransactionProcessingMetadata.TransactAccountFirstAndLast(this, this, dom, sub, dom, sub); + TransactionProcessingMetadata.TransactFragmentFirstAndLast txnFirstAndLast = + new TransactionProcessingMetadata.TransactFragmentFirstAndLast<>(this, this, dom, sub, dom, sub); txnAccountFirstAndLastMap.put(oldState.address(), txnFirstAndLast); } else { - TransactionProcessingMetadata.TransactAccountFirstAndLast txnFirstAndLast = txnAccountFirstAndLastMap.get(oldState.address()); + TransactionProcessingMetadata.TransactFragmentFirstAndLast txnFirstAndLast = txnAccountFirstAndLastMap.get(oldState.address()); // Replace condition - if (TransactionProcessingMetadata.TransactAccountFirstAndLast.strictlySmallerStamps( + if (TransactionProcessingMetadata.TransactFragmentFirstAndLast.strictlySmallerStamps( txnFirstAndLast.getLastDom(), txnFirstAndLast.getLastSub(), this.domSubStampsSubFragment.domStamp(), this.domSubStampsSubFragment.subStamp())) { txnFirstAndLast.setLast(this); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java index 1d42fa94d3..921133e347 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java @@ -1,6 +1,7 @@ package net.consensys.linea.zktracer.module.hub.transients; import lombok.Getter; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import java.util.HashMap; @@ -9,5 +10,5 @@ public class StateManagerMetadata { @Getter - Map txnAccountFirstLastBlockMap = new HashMap<>(); + Map> txnAccountFirstLastBlockMap = new HashMap<>(); } 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 7ea288747d..132bcedfe7 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 @@ -33,7 +33,7 @@ import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; -import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.transients.Block; import net.consensys.linea.zktracer.module.hub.transients.StorageInitialValues; @@ -123,12 +123,12 @@ public class TransactionProcessingMetadata implements PostTransactionDefer { // Map for the first and last account occurance @Getter @Setter - public static class TransactAccountFirstAndLast { - AccountFragment first; - AccountFragment last; + public static class TransactFragmentFirstAndLast { + TraceFragment first; + TraceFragment last; int firstDom, firstSub; int lastDom, lastSub; - public TransactAccountFirstAndLast(AccountFragment first, AccountFragment last, int firstDom, int firstSub, int lastDom, int lastSub) { + public TransactFragmentFirstAndLast(TraceFragment first, TraceFragment last, int firstDom, int firstSub, int lastDom, int lastSub) { this.first = first; this.last = last; this.firstDom = firstDom; @@ -142,8 +142,13 @@ public static boolean strictlySmallerStamps(int firstDom, int firstSub, int last firstSub > lastSub); } } + + + + @Getter - Map transactAccountFirstAndLastMap = new HashMap<>(); + Map> transactAccountFirstAndLastMap = new HashMap<>(); + // Ephermeral accounts are both accounts that have been deployed on-chain // and accounts that live for a limited time From 4eb9b770d048a132b7f6bb40f834d3cdea096353 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 13 Sep 2024 15:06:30 +0200 Subject: [PATCH 09/74] refactor Co-Authored-By: Arijit Dutta <37040536+arijitdutta67@users.noreply.github.com> --- .../consensys/linea/zktracer/module/hub/Hub.java | 14 ++++++-------- .../hub/fragment/account/AccountFragment.java | 12 ++++++------ .../hub/transients/StateManagerMetadata.java | 2 +- .../types/TransactionProcessingMetadata.java | 16 ++++++++++------ 4 files changed, 23 insertions(+), 21 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 fd06398437..88daa12abd 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 @@ -30,7 +30,6 @@ import java.util.stream.Stream; import lombok.Getter; -import lombok.Setter; import lombok.experimental.Accessors; import lombok.extern.slf4j.Slf4j; import net.consensys.linea.zktracer.ColumnHeader; @@ -128,7 +127,6 @@ import net.consensys.linea.zktracer.types.Bytecode; import net.consensys.linea.zktracer.types.MemorySpan; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; -import org.apache.commons.lang3.tuple.Pair; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Transaction; @@ -1172,23 +1170,23 @@ public final boolean deploymentStatusOfAccountAddress() { public void updateBlockMap() { - Map> blockMap = Hub.stateManagerMetadata().getTxnAccountFirstLastBlockMap();; + Map> blockMap = Hub.stateManagerMetadata().getTxnAccountFirstLastBlockMap();; List txn = txStack.getTxs(); for (TransactionProcessingMetadata metadata : txn) { if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) { int blockNumber = transients.block().blockNumber(); - Map> localMap = metadata.getTransactAccountFirstAndLastMap(); + Map> localMap = metadata.getAccountFirstAndLastMap(); for (Address addr : localMap.keySet()) { Transients.AddrBlockPair pairAddrBlock = new Transients.AddrBlockPair(addr, blockNumber); // localValue exists for sure because addr belongs to the keySet of the local map - TransactionProcessingMetadata.TransactFragmentFirstAndLast localValue = localMap.get(addr); + TransactionProcessingMetadata.FragmentFirstAndLast localValue = localMap.get(addr); if (!blockMap.containsKey(pairAddrBlock)) { // the pair is not present in the map blockMap.put(pairAddrBlock, localValue); } else { - TransactionProcessingMetadata.TransactFragmentFirstAndLast blockValue = blockMap.get(pairAddrBlock); + TransactionProcessingMetadata.FragmentFirstAndLast blockValue = blockMap.get(pairAddrBlock); // update the first part of the blockValue - if (TransactionProcessingMetadata.TransactFragmentFirstAndLast.strictlySmallerStamps( + if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( localValue.getFirstDom(), localValue.getFirstSub(), blockValue.getFirstDom(), blockValue.getFirstSub())) { // chronologically checks that localValue.First is before blockValue.First // localValue comes chronologically before, and should be the first value of the map. @@ -1197,7 +1195,7 @@ public void updateBlockMap() { blockValue.setFirstSub(localValue.getFirstSub()); // update the last part of the blockValue - if (TransactionProcessingMetadata.TransactFragmentFirstAndLast.strictlySmallerStamps( + if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( blockValue.getLastDom(), blockValue.getLastSub(), localValue.getLastDom(), localValue.getLastSub())) { // chronologically checks that blockValue.Last is before localValue.Last // localValue comes chronologically after, and should be the final value of the map. diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 358bba029b..b88becbb67 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -203,18 +203,18 @@ public void resolvePostConflation(Hub hub, WorldView world) { public void updateAccountFirstAndLast() { // Setting the post transaction first and last value // Initialise the Account First and Last map - final Map> txnAccountFirstAndLastMap = - this. transactionProcessingMetadata.getTransactAccountFirstAndLastMap(); + final Map> txnAccountFirstAndLastMap = + this. transactionProcessingMetadata.getAccountFirstAndLastMap(); if (!txnAccountFirstAndLastMap.containsKey(oldState.address())) { int dom = this.domSubStampsSubFragment.domStamp(); int sub = this.domSubStampsSubFragment.subStamp(); - TransactionProcessingMetadata.TransactFragmentFirstAndLast txnFirstAndLast = - new TransactionProcessingMetadata.TransactFragmentFirstAndLast<>(this, this, dom, sub, dom, sub); + TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = + new TransactionProcessingMetadata.FragmentFirstAndLast<>(this, this, dom, sub, dom, sub); txnAccountFirstAndLastMap.put(oldState.address(), txnFirstAndLast); } else { - TransactionProcessingMetadata.TransactFragmentFirstAndLast txnFirstAndLast = txnAccountFirstAndLastMap.get(oldState.address()); + TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = txnAccountFirstAndLastMap.get(oldState.address()); // Replace condition - if (TransactionProcessingMetadata.TransactFragmentFirstAndLast.strictlySmallerStamps( + if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( txnFirstAndLast.getLastDom(), txnFirstAndLast.getLastSub(), this.domSubStampsSubFragment.domStamp(), this.domSubStampsSubFragment.subStamp())) { txnFirstAndLast.setLast(this); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java index 921133e347..b371ed38f0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java @@ -10,5 +10,5 @@ public class StateManagerMetadata { @Getter - Map> txnAccountFirstLastBlockMap = new HashMap<>(); + Map> txnAccountFirstLastBlockMap = new HashMap<>(); } 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 132bcedfe7..ad2e43e933 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 @@ -33,8 +33,8 @@ import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.transients.Block; import net.consensys.linea.zktracer.module.hub.transients.StorageInitialValues; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; @@ -121,14 +121,15 @@ public class TransactionProcessingMetadata implements PostTransactionDefer { @Getter Map effectiveSelfDestructMap = new HashMap<>(); - // Map for the first and last account occurance + /* FragmentFirstAndLast stores the first and last fragments relevant to the state manager in the + * current transaction segment (they will be either account fragments or storage fragments). */ @Getter @Setter - public static class TransactFragmentFirstAndLast { + public static class FragmentFirstAndLast { TraceFragment first; TraceFragment last; int firstDom, firstSub; int lastDom, lastSub; - public TransactFragmentFirstAndLast(TraceFragment first, TraceFragment last, int firstDom, int firstSub, int lastDom, int lastSub) { + public FragmentFirstAndLast(TraceFragment first, TraceFragment last, int firstDom, int firstSub, int lastDom, int lastSub) { this.first = first; this.last = last; this.firstDom = firstDom; @@ -145,9 +146,12 @@ public static boolean strictlySmallerStamps(int firstDom, int firstSub, int last - + // Map for the first and last account occurrence + @Getter + Map> accountFirstAndLastMap = new HashMap<>(); + // Map for the first and last storage occurrence @Getter - Map> transactAccountFirstAndLastMap = new HashMap<>(); + Map> storageFirstAndLastMap = new HashMap<>(); // Ephermeral accounts are both accounts that have been deployed on-chain From 850ddf8913e86d4447a6569250c7000269d4db12 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 13 Sep 2024 15:14:22 +0200 Subject: [PATCH 10/74] refactor Co-Authored-By: Arijit Dutta <37040536+arijitdutta67@users.noreply.github.com> --- .../hub/fragment/account/AccountFragment.java | 27 ++----------------- .../types/TransactionProcessingMetadata.java | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index b88becbb67..cc925daf14 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -57,6 +57,7 @@ public final class AccountFragment @Setter private boolean requiresRomlex; private int codeFragmentIndex; private final Optional addressToTrim; + @Getter private final DomSubStampsSubFragment domSubStampsSubFragment; @Setter private RlpAddrSubFragment rlpAddrSubFragment; private boolean markedForSelfDestruct; @@ -109,7 +110,7 @@ public AccountFragment( this.addressToTrim = addressToTrim; this.domSubStampsSubFragment = domSubStampsSubFragment; // Updating the map - updateAccountFirstAndLast(); + transactionProcessingMetadata.updateAccountFirstAndLast(this); // This allows us to properly fill EXISTS_INFTY, DEPLOYMENT_NUMBER_INFTY and CODE_FRAGMENT_INDEX hub.defers().scheduleForPostConflation(this); @@ -200,31 +201,7 @@ public void resolvePostConflation(Hub hub, WorldView world) { ContractMetadata.make(oldState.address(), deploymentNumber, isDeployment)) : 0; } - public void updateAccountFirstAndLast() { - // Setting the post transaction first and last value - // Initialise the Account First and Last map - final Map> txnAccountFirstAndLastMap = - this. transactionProcessingMetadata.getAccountFirstAndLastMap(); - if (!txnAccountFirstAndLastMap.containsKey(oldState.address())) { - int dom = this.domSubStampsSubFragment.domStamp(); - int sub = this.domSubStampsSubFragment.subStamp(); - TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = - new TransactionProcessingMetadata.FragmentFirstAndLast<>(this, this, dom, sub, dom, sub); - txnAccountFirstAndLastMap.put(oldState.address(), txnFirstAndLast); - } else { - TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = txnAccountFirstAndLastMap.get(oldState.address()); - // Replace condition - if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( - txnFirstAndLast.getLastDom(), txnFirstAndLast.getLastSub(), - this.domSubStampsSubFragment.domStamp(), this.domSubStampsSubFragment.subStamp())) { - txnFirstAndLast.setLast(this); - txnFirstAndLast.setLastDom(this.domSubStampsSubFragment.domStamp()); - txnFirstAndLast.setLastSub(this.domSubStampsSubFragment.subStamp()); - txnAccountFirstAndLastMap.put(oldState.address(), txnFirstAndLast); - } - } - } } 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 ad2e43e933..98e3e24c0c 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 @@ -142,6 +142,7 @@ public static boolean strictlySmallerStamps(int firstDom, int firstSub, int last (firstDom == lastDom && firstSub > lastSub); } + } @@ -153,6 +154,32 @@ public static boolean strictlySmallerStamps(int firstDom, int firstSub, int last @Getter Map> storageFirstAndLastMap = new HashMap<>(); + public void updateAccountFirstAndLast(AccountFragment fragment) { + // Setting the post transaction first and last value + // Initialise the Account First and Last map + final Map> txnAccountFirstAndLastMap = + getAccountFirstAndLastMap(); + if (!txnAccountFirstAndLastMap.containsKey(fragment.oldState().address())) { + int dom = fragment.domSubStampsSubFragment().domStamp(); + int sub = fragment.domSubStampsSubFragment().subStamp(); + TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = + new FragmentFirstAndLast(fragment, fragment, dom, sub, dom, sub); + txnAccountFirstAndLastMap.put(fragment.oldState().address(), txnFirstAndLast); + } else { + TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = txnAccountFirstAndLastMap.get(fragment.oldState().address()); + // Replace condition + if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( + txnFirstAndLast.getLastDom(), txnFirstAndLast.getLastSub(), + fragment.domSubStampsSubFragment().domStamp(), fragment.domSubStampsSubFragment().subStamp())) { + txnFirstAndLast.setLast(fragment); + txnFirstAndLast.setLastDom(fragment.domSubStampsSubFragment().domStamp()); + txnFirstAndLast.setLastSub(fragment.domSubStampsSubFragment().subStamp()); + txnAccountFirstAndLastMap.put(fragment.oldState().address(), txnFirstAndLast); + } + } + + } + // Ephermeral accounts are both accounts that have been deployed on-chain // and accounts that live for a limited time From d556f4ac651e317dc496331ab0140c366742fd5f Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 13 Sep 2024 15:22:15 +0200 Subject: [PATCH 11/74] refactor and (addr, storage) pair Co-Authored-By: Arijit Dutta <37040536+arijitdutta67@users.noreply.github.com> --- .../consensys/linea/zktracer/module/hub/Hub.java | 4 ++-- .../hub/transients/StateManagerMetadata.java | 14 +++++++++++++- .../module/hub/transients/Transients.java | 16 ---------------- .../types/TransactionProcessingMetadata.java | 14 +++++++++++++- 4 files changed, 28 insertions(+), 20 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 88daa12abd..ac3281ba13 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 @@ -1170,14 +1170,14 @@ public final boolean deploymentStatusOfAccountAddress() { public void updateBlockMap() { - Map> blockMap = Hub.stateManagerMetadata().getTxnAccountFirstLastBlockMap();; + Map> blockMap = Hub.stateManagerMetadata().getTxnAccountFirstLastBlockMap();; List txn = txStack.getTxs(); for (TransactionProcessingMetadata metadata : txn) { if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) { int blockNumber = transients.block().blockNumber(); Map> localMap = metadata.getAccountFirstAndLastMap(); for (Address addr : localMap.keySet()) { - Transients.AddrBlockPair pairAddrBlock = new Transients.AddrBlockPair(addr, blockNumber); + StateManagerMetadata.AddrBlockPair pairAddrBlock = new StateManagerMetadata.AddrBlockPair(addr, blockNumber); // localValue exists for sure because addr belongs to the keySet of the local map TransactionProcessingMetadata.FragmentFirstAndLast localValue = localMap.get(addr); if (!blockMap.containsKey(pairAddrBlock)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java index b371ed38f0..7d03b06503 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java @@ -3,12 +3,24 @@ import lombok.Getter; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import org.hyperledger.besu.datatypes.Address; import java.util.HashMap; import java.util.Map; public class StateManagerMetadata { + public static class AddrBlockPair { + @Getter + private Address address; + @Getter + private int blockNumber; + + public AddrBlockPair(Address addr, int blockNumber) { + this.address = addr; + this.blockNumber = blockNumber; + } + } @Getter - Map> txnAccountFirstLastBlockMap = new HashMap<>(); + Map> txnAccountFirstLastBlockMap = new HashMap<>(); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java index 8998c6dc37..11ee7a0157 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java @@ -46,22 +46,6 @@ public class Transients { final OperationAncillaries op; - - - - public static class AddrBlockPair { - @Getter - private Address address; - @Getter - private int blockNumber; - - public AddrBlockPair(Address addr, int blockNumber) { - this.address = addr; - this.blockNumber = blockNumber; - } - } - - public TransactionProcessingMetadata tx() { return this.hub.txStack().current(); } 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 98e3e24c0c..db9bb87336 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 @@ -145,6 +145,17 @@ public static boolean strictlySmallerStamps(int firstDom, int firstSub, int last } + public static class AddrStorageKeyPair { + @Getter + private Address address; + @Getter + private EWord storageKey; + + public AddrStorageKeyPair(Address addr, EWord storageKey) { + this.address = addr; + this.storageKey = storageKey; + } + } // Map for the first and last account occurrence @@ -152,7 +163,7 @@ public static boolean strictlySmallerStamps(int firstDom, int firstSub, int last Map> accountFirstAndLastMap = new HashMap<>(); // Map for the first and last storage occurrence @Getter - Map> storageFirstAndLastMap = new HashMap<>(); + Map> storageFirstAndLastMap = new HashMap<>(); public void updateAccountFirstAndLast(AccountFragment fragment) { // Setting the post transaction first and last value @@ -181,6 +192,7 @@ public void updateAccountFirstAndLast(AccountFragment fragment) { } + // Ephermeral accounts are both accounts that have been deployed on-chain // and accounts that live for a limited time public record EphemeralAccount(Address address, int deploymentNumber) {} From da23d1d7cd09faadb3b1197d66c5562af4e7fa77 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 13 Sep 2024 16:40:50 +0200 Subject: [PATCH 12/74] update for storage Co-Authored-By: Arijit Dutta <37040536+arijitdutta67@users.noreply.github.com> --- .../hub/fragment/storage/StorageFragment.java | 1 + .../types/TransactionProcessingMetadata.java | 51 +++++++++++++++---- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index 5d22c9b5e1..a97597fe83 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -40,6 +40,7 @@ public final class StorageFragment implements TraceFragment { private final EWord valueNext; private final boolean incomingWarmth; private final boolean outgoingWarmth; + @Getter private final DomSubStampsSubFragment domSubStampsSubFragment; private final int blockNumber; private final StorageFragmentPurpose purpose; // for debugging purposes 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 db9bb87336..ba3c10c5b5 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 @@ -168,29 +168,58 @@ public AddrStorageKeyPair(Address addr, EWord storageKey) { public void updateAccountFirstAndLast(AccountFragment fragment) { // Setting the post transaction first and last value // Initialise the Account First and Last map - final Map> txnAccountFirstAndLastMap = + int dom = fragment.domSubStampsSubFragment().domStamp(); + int sub = fragment.domSubStampsSubFragment().subStamp(); + + Address key = fragment.oldState().address(); + + + final Map> txnAccountFirstAndLastMap = getAccountFirstAndLastMap(); - if (!txnAccountFirstAndLastMap.containsKey(fragment.oldState().address())) { - int dom = fragment.domSubStampsSubFragment().domStamp(); - int sub = fragment.domSubStampsSubFragment().subStamp(); + if (!txnAccountFirstAndLastMap.containsKey(key)) { TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = new FragmentFirstAndLast(fragment, fragment, dom, sub, dom, sub); - txnAccountFirstAndLastMap.put(fragment.oldState().address(), txnFirstAndLast); + txnAccountFirstAndLastMap.put(key, txnFirstAndLast); } else { - TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = txnAccountFirstAndLastMap.get(fragment.oldState().address()); + TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = txnAccountFirstAndLastMap.get(key); // Replace condition if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( txnFirstAndLast.getLastDom(), txnFirstAndLast.getLastSub(), - fragment.domSubStampsSubFragment().domStamp(), fragment.domSubStampsSubFragment().subStamp())) { + dom, sub)) { txnFirstAndLast.setLast(fragment); - txnFirstAndLast.setLastDom(fragment.domSubStampsSubFragment().domStamp()); - txnFirstAndLast.setLastSub(fragment.domSubStampsSubFragment().subStamp()); - txnAccountFirstAndLastMap.put(fragment.oldState().address(), txnFirstAndLast); + txnFirstAndLast.setLastDom(dom); + txnFirstAndLast.setLastSub(sub); + txnAccountFirstAndLastMap.put(key, txnFirstAndLast); } } - } + public void updateStorageFirstAndLast(StorageFragment fragment, AddrStorageKeyPair key) { + // Setting the post transaction first and last value + // Initialise the Account First and Last map + int dom = fragment.getDomSubStampsSubFragment().domStamp(); + int sub = fragment.getDomSubStampsSubFragment().subStamp(); + + + final Map> txnStorageFirstAndLastMap = + getStorageFirstAndLastMap(); + if (!txnStorageFirstAndLastMap.containsKey(key)) { + TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = + new FragmentFirstAndLast(fragment, fragment, dom, sub, dom, sub); + txnStorageFirstAndLastMap.put(key, txnFirstAndLast); + } else { + TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = txnStorageFirstAndLastMap.get(key); + // Replace condition + if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( + txnFirstAndLast.getLastDom(), txnFirstAndLast.getLastSub(), + dom, sub)) { + txnFirstAndLast.setLast(fragment); + txnFirstAndLast.setLastDom(dom); + txnFirstAndLast.setLastSub(sub); + txnStorageFirstAndLastMap.put(key, txnFirstAndLast); + } + } + } // Ephermeral accounts are both accounts that have been deployed on-chain From 8f5351031b2ea49f4c56cc3ffd1d8ff56603e141 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 13 Sep 2024 16:59:08 +0200 Subject: [PATCH 13/74] map update for storage fragments Co-Authored-By: Arijit Dutta <37040536+arijitdutta67@users.noreply.github.com> --- .../module/hub/section/SloadSection.java | 15 ++++++++++++--- .../module/hub/section/SstoreSection.java | 16 ++++++++++++---- .../hub/section/TxPreWarmingMacroSection.java | 9 +++++++-- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index d51aeedfdf..10857993de 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -28,6 +28,7 @@ import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; import org.hyperledger.besu.datatypes.Address; @@ -89,7 +90,8 @@ public SloadSection(Hub hub, WorldView worldView) { private StorageFragment doingSload(Hub hub) { - return new StorageFragment( + TransactionProcessingMetadata txnMetadata = hub.txStack().current(); + StorageFragment newFragment = new StorageFragment( hub.state, new State.StorageSlotIdentifier( accountAddress, accountAddressDeploymentNumber, EWord.of(storageKey)), @@ -101,7 +103,11 @@ private StorageFragment doingSload(Hub hub) { DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0), hub.state.firstAndLastStorageSlotOccurrences.size(), SLOAD_DOING, - hub.txStack().current()); + txnMetadata); + TransactionProcessingMetadata.AddrStorageKeyPair mapKey = new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); + txnMetadata.updateStorageFirstAndLast(newFragment, mapKey); + return newFragment; + } @Override @@ -117,6 +123,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca DomSubStampsSubFragment.revertWithCurrentDomSubStamps( this.hubStamp(), hub.callStack().current().revertStamp(), 0); + TransactionProcessingMetadata txnMetadata = hub.txStack().current(); final StorageFragment undoingSloadStorageFragment = new StorageFragment( hub.state, @@ -130,9 +137,11 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca undoingDomSubStamps, hub.state.firstAndLastStorageSlotOccurrences.size(), SLOAD_UNDOING, - hub.txStack().current()); + txnMetadata); this.addFragment(undoingSloadStorageFragment); + TransactionProcessingMetadata.AddrStorageKeyPair mapKey = new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); + txnMetadata.updateStorageFirstAndLast(undoingSloadStorageFragment, mapKey); } private boolean undoingRequired() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index 3c998bd469..6d87264b07 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -31,6 +31,7 @@ import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.runtime.callstack.CallFrame; import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; import org.hyperledger.besu.datatypes.Address; @@ -114,7 +115,8 @@ public SstoreSection(Hub hub, WorldView worldView) { private StorageFragment doingSstore(Hub hub) { - return new StorageFragment( + TransactionProcessingMetadata txnMetadata = hub.txStack().current(); + StorageFragment newFragment = new StorageFragment( hub.state, new State.StorageSlotIdentifier( accountAddress, accountAddressDeploymentNumber, EWord.of(storageKey)), @@ -126,7 +128,10 @@ private StorageFragment doingSstore(Hub hub) { DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0), hub.state.firstAndLastStorageSlotOccurrences.size(), SSTORE_DOING, - hub.txStack().current()); + txnMetadata); + TransactionProcessingMetadata.AddrStorageKeyPair mapKey = new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); + txnMetadata.updateStorageFirstAndLast(newFragment, mapKey); + return newFragment; } @Override @@ -135,6 +140,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca DomSubStampsSubFragment.revertWithCurrentDomSubStamps( this.hubStamp(), hub.callStack().current().revertStamp(), 0); + TransactionProcessingMetadata txnMetadata = hub.txStack().current(); final StorageFragment undoingSstoreStorageFragment = new StorageFragment( hub.state, @@ -148,11 +154,13 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca undoingDomSubStamps, hub.state.firstAndLastStorageSlotOccurrences.size(), SSTORE_UNDOING, - hub.txStack().current()); + txnMetadata); this.addFragment(undoingSstoreStorageFragment); - // undo the refund commonValues.refundDelta(0); + // update storage txn map values for the state manager + TransactionProcessingMetadata.AddrStorageKeyPair mapKey = new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); + txnMetadata.updateStorageFirstAndLast(undoingSstoreStorageFragment, mapKey); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java index 86ebc6d64d..1c32373ab1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java @@ -107,6 +107,7 @@ public TxPreWarmingMacroSection(WorldView world, Hub hub) { new State.StorageSlotIdentifier( address, deploymentInfo.deploymentNumber(address), EWord.of(k)); + TransactionProcessingMetadata txnMetadata = hub.txStack().current(); final StorageFragment storageFragment = new StorageFragment( hub.state, @@ -120,13 +121,17 @@ public TxPreWarmingMacroSection(WorldView world, Hub hub) { DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0), hub.state.firstAndLastStorageSlotOccurrences.size(), PRE_WARMING, - hub.txStack().current()); + txnMetadata); new TxPrewarmingSection(hub, storageFragment); hub.state.updateOrInsertStorageSlotOccurrence( storageSlotIdentifier, storageFragment); - seenKeys.get(address).add(key); + + TransactionProcessingMetadata.AddrStorageKeyPair mapKey = new TransactionProcessingMetadata.AddrStorageKeyPair(address, EWord.of(key)); + txnMetadata.updateStorageFirstAndLast(storageFragment, mapKey); + + } } From 808611e9378dfaadf0d3cad702b061051b35c954 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 13 Sep 2024 17:08:29 +0200 Subject: [PATCH 14/74] adding deployment numbers in StorageFragment Co-Authored-By: Arijit Dutta <37040536+arijitdutta67@users.noreply.github.com> --- .../zktracer/module/hub/fragment/storage/StorageFragment.java | 2 ++ .../linea/zktracer/module/hub/section/SloadSection.java | 2 ++ .../linea/zktracer/module/hub/section/SstoreSection.java | 2 ++ .../zktracer/module/hub/section/TxPreWarmingMacroSection.java | 1 + 4 files changed, 7 insertions(+) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index a97597fe83..431f3db41f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -45,6 +45,8 @@ public final class StorageFragment implements TraceFragment { private final int blockNumber; private final StorageFragmentPurpose purpose; // for debugging purposes + private final int deploymentNumber; + final TransactionProcessingMetadata transactionProcessingMetadata; public Trace trace(Trace trace) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index 10857993de..32f8759415 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -103,6 +103,7 @@ private StorageFragment doingSload(Hub hub) { DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0), hub.state.firstAndLastStorageSlotOccurrences.size(), SLOAD_DOING, + accountAddressDeploymentNumber, // Arijit — check that it is computed properly beforehand. txnMetadata); TransactionProcessingMetadata.AddrStorageKeyPair mapKey = new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); txnMetadata.updateStorageFirstAndLast(newFragment, mapKey); @@ -137,6 +138,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca undoingDomSubStamps, hub.state.firstAndLastStorageSlotOccurrences.size(), SLOAD_UNDOING, + accountAddressDeploymentNumber, // Arijit — check that it is computed properly beforehand. txnMetadata); this.addFragment(undoingSloadStorageFragment); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index 6d87264b07..7f4f7d8707 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -128,6 +128,7 @@ private StorageFragment doingSstore(Hub hub) { DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0), hub.state.firstAndLastStorageSlotOccurrences.size(), SSTORE_DOING, + accountAddressDeploymentNumber, // Arijit — check that it is computed properly beforehand. txnMetadata); TransactionProcessingMetadata.AddrStorageKeyPair mapKey = new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); txnMetadata.updateStorageFirstAndLast(newFragment, mapKey); @@ -154,6 +155,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca undoingDomSubStamps, hub.state.firstAndLastStorageSlotOccurrences.size(), SSTORE_UNDOING, + accountAddressDeploymentNumber, // Arijit — check that it is computed properly beforehand. txnMetadata); this.addFragment(undoingSstoreStorageFragment); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java index 1c32373ab1..40cfc413a6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java @@ -121,6 +121,7 @@ public TxPreWarmingMacroSection(WorldView world, Hub hub) { DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0), hub.state.firstAndLastStorageSlotOccurrences.size(), PRE_WARMING, + deploymentNumber, // Arijit — check that it is computed properly beforehand. txnMetadata); new TxPrewarmingSection(hub, storageFragment); From 06773a482f16c0d0272b1d8f2c7b1796f9044026 Mon Sep 17 00:00:00 2001 From: arijitdutta67 Date: Mon, 16 Sep 2024 17:14:44 +0530 Subject: [PATCH 15/74] adding comments --- .../linea/zktracer/module/hub/section/SloadSection.java | 2 ++ .../linea/zktracer/module/hub/section/SstoreSection.java | 3 ++- .../module/hub/section/TxPreWarmingMacroSection.java | 2 +- .../module/hub/transients/StateManagerMetadata.java | 3 +++ .../zktracer/types/TransactionProcessingMetadata.java | 7 +++---- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index 32f8759415..4c76bcb0c6 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -105,6 +105,7 @@ private StorageFragment doingSload(Hub hub) { SLOAD_DOING, accountAddressDeploymentNumber, // Arijit — check that it is computed properly beforehand. txnMetadata); + // update storage txn map values for the state manager as new storage fragment is created TransactionProcessingMetadata.AddrStorageKeyPair mapKey = new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); txnMetadata.updateStorageFirstAndLast(newFragment, mapKey); return newFragment; @@ -142,6 +143,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca txnMetadata); this.addFragment(undoingSloadStorageFragment); + // update storage txn map values for the state manager as new storage fragment is created TransactionProcessingMetadata.AddrStorageKeyPair mapKey = new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); txnMetadata.updateStorageFirstAndLast(undoingSloadStorageFragment, mapKey); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index 7f4f7d8707..41a65d2ba9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -131,6 +131,7 @@ private StorageFragment doingSstore(Hub hub) { accountAddressDeploymentNumber, // Arijit — check that it is computed properly beforehand. txnMetadata); TransactionProcessingMetadata.AddrStorageKeyPair mapKey = new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); + // update storage txn map values for the state manager as new storage fragment is created txnMetadata.updateStorageFirstAndLast(newFragment, mapKey); return newFragment; } @@ -161,7 +162,7 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca this.addFragment(undoingSstoreStorageFragment); // undo the refund commonValues.refundDelta(0); - // update storage txn map values for the state manager + // update storage txn map values for the state manager as new storage fragment is created TransactionProcessingMetadata.AddrStorageKeyPair mapKey = new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); txnMetadata.updateStorageFirstAndLast(undoingSstoreStorageFragment, mapKey); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java index 40cfc413a6..5d5e86d252 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java @@ -128,7 +128,7 @@ public TxPreWarmingMacroSection(WorldView world, Hub hub) { hub.state.updateOrInsertStorageSlotOccurrence( storageSlotIdentifier, storageFragment); seenKeys.get(address).add(key); - + // update storage txn map values for the state manager as new storage fragment is created TransactionProcessingMetadata.AddrStorageKeyPair mapKey = new TransactionProcessingMetadata.AddrStorageKeyPair(address, EWord.of(key)); txnMetadata.updateStorageFirstAndLast(storageFragment, mapKey); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java index 7d03b06503..3d5c42a8d7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java @@ -23,4 +23,7 @@ public AddrBlockPair(Address addr, int blockNumber) { } @Getter Map> txnAccountFirstLastBlockMap = new HashMap<>(); + + @Getter + Map> txnAccountFirstLastConflationMap = new HashMap<>(); } 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 ba3c10c5b5..85d7841c90 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 @@ -164,16 +164,15 @@ public AddrStorageKeyPair(Address addr, EWord storageKey) { // Map for the first and last storage occurrence @Getter Map> storageFirstAndLastMap = new HashMap<>(); - + // Todo: Create a generic method which can handle AccountFragment and StorageFragment public void updateAccountFirstAndLast(AccountFragment fragment) { // Setting the post transaction first and last value - // Initialise the Account First and Last map int dom = fragment.domSubStampsSubFragment().domStamp(); int sub = fragment.domSubStampsSubFragment().subStamp(); Address key = fragment.oldState().address(); - + // Initialise the Account First and Last map final Map> txnAccountFirstAndLastMap = getAccountFirstAndLastMap(); if (!txnAccountFirstAndLastMap.containsKey(key)) { @@ -195,11 +194,11 @@ public void updateAccountFirstAndLast(AccountFragment fragment) { } public void updateStorageFirstAndLast(StorageFragment fragment, AddrStorageKeyPair key) { // Setting the post transaction first and last value - // Initialise the Account First and Last map int dom = fragment.getDomSubStampsSubFragment().domStamp(); int sub = fragment.getDomSubStampsSubFragment().subStamp(); + // Initialise the Storage First and Last map final Map> txnStorageFirstAndLastMap = getStorageFirstAndLastMap(); if (!txnStorageFirstAndLastMap.containsKey(key)) { From 9bbcfaa0583a9d9b907fe4150235f90edb2a82a1 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Wed, 18 Sep 2024 02:50:41 +0200 Subject: [PATCH 16/74] Min/Max DeplNo maps --- .../hub/fragment/account/AccountFragment.java | 4 ++++ .../hub/transients/StateManagerMetadata.java | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index cc925daf14..f308080a75 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -111,6 +111,10 @@ public AccountFragment( this.domSubStampsSubFragment = domSubStampsSubFragment; // Updating the map transactionProcessingMetadata.updateAccountFirstAndLast(this); + // update the minDeplMoBlock and maxDeplNoBlock maps + Hub.stateManagerMetadata().updateDeplNoBlockMaps(oldState.address(), + transactionProcessingMetadata.getRelativeBlockNumber(), + deploymentNumber); // This allows us to properly fill EXISTS_INFTY, DEPLOYMENT_NUMBER_INFTY and CODE_FRAGMENT_INDEX hub.defers().scheduleForPostConflation(this); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java index 3d5c42a8d7..bb3469fd11 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java @@ -26,4 +26,22 @@ public AddrBlockPair(Address addr, int blockNumber) { @Getter Map> txnAccountFirstLastConflationMap = new HashMap<>(); + + @Getter + Map minDeplNoBlock = new HashMap<>(); + @Getter + Map maxDeplNoBlock = new HashMap<>(); + public void updateDeplNoBlockMaps(Address address, int blockNumber, int currentDeplNo) { + AddrBlockPair addrBlockPair = new AddrBlockPair(address, blockNumber); + if (minDeplNoBlock.containsKey(addrBlockPair)) { + // the maps already contain deployment info for this address, and this is not the first one in the block + // since it is not the first, we do not update the minDeplNoBlock + // but we update the maxDeplNoBlock + maxDeplNoBlock.put(addrBlockPair, currentDeplNo); + } else { + // this is the first time we have a deployment at this address in the block + minDeplNoBlock.put(addrBlockPair, currentDeplNo); + maxDeplNoBlock.put(addrBlockPair, currentDeplNo); + } + } } From 6045a65c45b0ff7bf46279e44ec51d5ad7a28c18 Mon Sep 17 00:00:00 2001 From: arijitdutta67 Date: Wed, 18 Sep 2024 12:49:21 +0530 Subject: [PATCH 17/74] adding conflation level map for account --- .../linea/zktracer/module/hub/Hub.java | 52 ++++++++++++++++++- .../hub/transients/StateManagerMetadata.java | 4 ++ 2 files changed, 54 insertions(+), 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 ac3281ba13..943f8ddcd9 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 @@ -466,6 +466,8 @@ public void traceEndConflation(final WorldView world) { romLex.determineCodeFragmentIndex(); txStack.setCodeFragmentIndex(this); defers.resolvePostConflation(this, world); + // update the conflation level map for the state manager + updateConflationMap(); for (Module m : modules) { m.traceEndConflation(world); @@ -487,6 +489,7 @@ public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBo for (Module m : modules) { m.traceEndBlock(blockHeader, blockBody); } + // update the block level map for the state manager updateBlockMap(); } @@ -1170,12 +1173,14 @@ public final boolean deploymentStatusOfAccountAddress() { public void updateBlockMap() { - Map> blockMap = Hub.stateManagerMetadata().getTxnAccountFirstLastBlockMap();; + Map> blockMap + = Hub.stateManagerMetadata().getTxnAccountFirstLastBlockMap(); List txn = txStack.getTxs(); for (TransactionProcessingMetadata metadata : txn) { if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) { int blockNumber = transients.block().blockNumber(); - Map> localMap = metadata.getAccountFirstAndLastMap(); + Map> localMap + = metadata.getAccountFirstAndLastMap(); for (Address addr : localMap.keySet()) { StateManagerMetadata.AddrBlockPair pairAddrBlock = new StateManagerMetadata.AddrBlockPair(addr, blockNumber); // localValue exists for sure because addr belongs to the keySet of the local map @@ -1212,6 +1217,49 @@ public void updateBlockMap() { } } + + +// Update the conflation level map for the state manager +public void updateConflationMap() { + Map> conflationMap + = Hub.stateManagerMetadata().getTxnAccountFirstLastConflationMap(); + List txn = txStack.getTxs(); + Map> blockMap + = Hub.stateManagerMetadata().getTxnAccountFirstLastBlockMap(); + for (TransactionProcessingMetadata metadata : txn) { + Map> txnMap = metadata.getAccountFirstAndLastMap(); + for (Address addr : txnMap.keySet()) { + // Update the first value of the conflation map + // We update the value of the conflation map with the earliest value of the block map + for (int i = 0; i < transients.block().blockNumber(); i++) { + StateManagerMetadata.AddrBlockPair pairAddrBlock = new StateManagerMetadata.AddrBlockPair(addr, i); + if (blockMap.containsKey(pairAddrBlock)) { + TransactionProcessingMetadata.FragmentFirstAndLast blockValue = blockMap.get(pairAddrBlock); + TransactionProcessingMetadata.FragmentFirstAndLast conflationValue = + new TransactionProcessingMetadata.FragmentFirstAndLast + (blockValue.getFirst(), null, blockValue.getFirstDom(), blockValue.getFirstSub(), 0, 0); + conflationMap.put(addr, conflationValue); + break; + } + } + // Update the last value of the conflation map + // We update the last value for the conflation map with the latest blockMap's last values, + // if some address is not present in the last block, we ignore the corresponding account + StateManagerMetadata.AddrBlockPair pairAddrBlockLast = new StateManagerMetadata.AddrBlockPair(addr, transients.block().blockNumber()); + if (blockMap.containsKey(pairAddrBlockLast)) { + TransactionProcessingMetadata.FragmentFirstAndLast blockValueLast = blockMap.get(pairAddrBlockLast); + TransactionProcessingMetadata.FragmentFirstAndLast conflationValueLast = + new TransactionProcessingMetadata.FragmentFirstAndLast + (null, blockValueLast.getLast(), 0, 0, blockValueLast.getLastDom(), blockValueLast.getLastSub()); + } + } + } + + } + + + } + diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java index bb3469fd11..0403bb05d5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java @@ -2,6 +2,7 @@ import lombok.Getter; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.hyperledger.besu.datatypes.Address; @@ -24,6 +25,9 @@ public AddrBlockPair(Address addr, int blockNumber) { @Getter Map> txnAccountFirstLastBlockMap = new HashMap<>(); + @Getter + Map> txnStorageFirstLastBlockMap = new HashMap<>(); + @Getter Map> txnAccountFirstLastConflationMap = new HashMap<>(); From 8e3da28478fb6c75e39068206960e1e03e32c731 Mon Sep 17 00:00:00 2001 From: arijitdutta67 Date: Wed, 18 Sep 2024 18:37:29 +0530 Subject: [PATCH 18/74] adding the remaining maps for the storage --- .../linea/zktracer/module/hub/Hub.java | 156 ++++++++++++++---- .../hub/transients/StateManagerMetadata.java | 21 ++- 2 files changed, 143 insertions(+), 34 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 943f8ddcd9..1298e394ae 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 @@ -48,6 +48,7 @@ import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.StackFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.section.AccountSection; import net.consensys.linea.zktracer.module.hub.section.CallDataLoadSection; import net.consensys.linea.zktracer.module.hub.section.ContextSection; @@ -1173,46 +1174,95 @@ public final boolean deploymentStatusOfAccountAddress() { public void updateBlockMap() { - Map> blockMap - = Hub.stateManagerMetadata().getTxnAccountFirstLastBlockMap(); + Map> blockMapAccount + = Hub.stateManagerMetadata().getAccountFirstLastBlockMap(); + + Map> blockMapStorage + = Hub.stateManagerMetadata().getStorageFirstLastBlockMap(); + List txn = txStack.getTxs(); - for (TransactionProcessingMetadata metadata : txn) { + + for (TransactionProcessingMetadata metadata : txn) { if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) { int blockNumber = transients.block().blockNumber(); - Map> localMap + Map> localMapAccount = metadata.getAccountFirstAndLastMap(); - for (Address addr : localMap.keySet()) { + + Map> + localMapStorage = metadata.getStorageFirstAndLastMap(); + + // Update the block map for the account + for (Address addr : localMapAccount.keySet()) { StateManagerMetadata.AddrBlockPair pairAddrBlock = new StateManagerMetadata.AddrBlockPair(addr, blockNumber); - // localValue exists for sure because addr belongs to the keySet of the local map - TransactionProcessingMetadata.FragmentFirstAndLast localValue = localMap.get(addr); - if (!blockMap.containsKey(pairAddrBlock)) { + + // localValue exists for sure because addr belongs to the keySet of the local map + TransactionProcessingMetadata.FragmentFirstAndLast localValueAccount = localMapAccount.get(addr); + if (!blockMapAccount.containsKey(pairAddrBlock)) { // the pair is not present in the map - blockMap.put(pairAddrBlock, localValue); + blockMapAccount.put(pairAddrBlock, localValueAccount); } else { - TransactionProcessingMetadata.FragmentFirstAndLast blockValue = blockMap.get(pairAddrBlock); + TransactionProcessingMetadata.FragmentFirstAndLast blockValue = blockMapAccount.get(pairAddrBlock); // update the first part of the blockValue + // Todo: Refactor and remove code duplication if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( - localValue.getFirstDom(), localValue.getFirstSub(), blockValue.getFirstDom(), blockValue.getFirstSub())) { + localValueAccount.getFirstDom(), localValueAccount.getFirstSub(), blockValue.getFirstDom(), blockValue.getFirstSub())) { // chronologically checks that localValue.First is before blockValue.First // localValue comes chronologically before, and should be the first value of the map. - blockValue.setFirst(localValue.getFirst()); - blockValue.setFirstDom(localValue.getFirstDom()); - blockValue.setFirstSub(localValue.getFirstSub()); + blockValue.setFirst(localValueAccount.getFirst()); + blockValue.setFirstDom(localValueAccount.getFirstDom()); + blockValue.setFirstSub(localValueAccount.getFirstSub()); // update the last part of the blockValue if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( - blockValue.getLastDom(), blockValue.getLastSub(), localValue.getLastDom(), localValue.getLastSub())) { + blockValue.getLastDom(), blockValue.getLastSub(), localValueAccount.getLastDom(), localValueAccount.getLastSub())) { // chronologically checks that blockValue.Last is before localValue.Last // localValue comes chronologically after, and should be the final value of the map. - blockValue.setLast(localValue.getLast()); - blockValue.setLastDom(localValue.getLastDom()); - blockValue.setLastSub(localValue.getLastSub()); + blockValue.setLast(localValueAccount.getLast()); + blockValue.setLastDom(localValueAccount.getLastDom()); + blockValue.setLastSub(localValueAccount.getLastSub()); } - blockMap.put(pairAddrBlock, blockValue); + blockMapAccount.put(pairAddrBlock, blockValue); } } } + // Update the block map for storage + for (TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair : localMapStorage.keySet()) { + + StateManagerMetadata.AddrStorageKeyBlockNumTuple addrStorageBlockTuple = + new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, blockNumber); + + // localValue exists for sure because addr belongs to the keySet of the local map + TransactionProcessingMetadata.FragmentFirstAndLast localValueStorage = + localMapStorage.get(addrStorageKeyPair); + + if (!blockMapStorage.containsKey(addrStorageBlockTuple)) { + // the pair is not present in the map + blockMapStorage.put(addrStorageBlockTuple, localValueStorage); + } else { + TransactionProcessingMetadata.FragmentFirstAndLast blockValueStorage = blockMapStorage.get(addrStorageBlockTuple); + // update the first part of the blockValue + if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( + localValueStorage.getFirstDom(), localValueStorage.getFirstSub(), blockValueStorage.getFirstDom(), blockValueStorage.getFirstSub())) { + // chronologically checks that localValue.First is before blockValue.First + // localValue comes chronologically before, and should be the first value of the map. + blockValueStorage.setFirst(localValueStorage.getFirst()); + blockValueStorage.setFirstDom(localValueStorage.getFirstDom()); + blockValueStorage.setFirstSub(localValueStorage.getFirstSub()); + + // update the last part of the blockValue + if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( + blockValueStorage.getLastDom(), blockValueStorage.getLastSub(), localValueStorage.getLastDom(), localValueStorage.getLastSub())) { + // chronologically checks that blockValue.Last is before localValue.Last + // localValue comes chronologically after, and should be the final value of the map. + blockValueStorage.setLast(localValueStorage.getLast()); + blockValueStorage.setLastDom(localValueStorage.getLastDom()); + blockValueStorage.setLastSub(localValueStorage.getLastSub()); + } + blockMapStorage.put(addrStorageBlockTuple, blockValueStorage); + } + } + } } } @@ -1221,24 +1271,37 @@ public void updateBlockMap() { // Update the conflation level map for the state manager public void updateConflationMap() { - Map> conflationMap - = Hub.stateManagerMetadata().getTxnAccountFirstLastConflationMap(); + Map> + conflationMapAccount = Hub.stateManagerMetadata().getAccountFirstLastConflationMap(); + + Map> + conflationMapStorage = Hub.stateManagerMetadata().getStorageFirstLastConflationMap(); + List txn = txStack.getTxs(); - Map> blockMap - = Hub.stateManagerMetadata().getTxnAccountFirstLastBlockMap(); + + Map> + blockMapAccount = Hub.stateManagerMetadata().getAccountFirstLastBlockMap(); + + Map> + blockMapStorage = Hub.stateManagerMetadata().getStorageFirstLastBlockMap(); + for (TransactionProcessingMetadata metadata : txn) { - Map> txnMap = metadata.getAccountFirstAndLastMap(); - for (Address addr : txnMap.keySet()) { - // Update the first value of the conflation map + + Map> txnMapAccount = metadata.getAccountFirstAndLastMap(); + + Map> + txnMapStorage = metadata.getStorageFirstAndLastMap(); + for (Address addr : txnMapAccount.keySet()) { + // Update the first value of the conflation map for Account // We update the value of the conflation map with the earliest value of the block map for (int i = 0; i < transients.block().blockNumber(); i++) { StateManagerMetadata.AddrBlockPair pairAddrBlock = new StateManagerMetadata.AddrBlockPair(addr, i); - if (blockMap.containsKey(pairAddrBlock)) { - TransactionProcessingMetadata.FragmentFirstAndLast blockValue = blockMap.get(pairAddrBlock); + if (blockMapAccount.containsKey(pairAddrBlock)) { + TransactionProcessingMetadata.FragmentFirstAndLast blockValue = blockMapAccount.get(pairAddrBlock); TransactionProcessingMetadata.FragmentFirstAndLast conflationValue = new TransactionProcessingMetadata.FragmentFirstAndLast (blockValue.getFirst(), null, blockValue.getFirstDom(), blockValue.getFirstSub(), 0, 0); - conflationMap.put(addr, conflationValue); + conflationMapAccount.put(addr, conflationValue); break; } } @@ -1246,13 +1309,44 @@ public void updateConflationMap() { // We update the last value for the conflation map with the latest blockMap's last values, // if some address is not present in the last block, we ignore the corresponding account StateManagerMetadata.AddrBlockPair pairAddrBlockLast = new StateManagerMetadata.AddrBlockPair(addr, transients.block().blockNumber()); - if (blockMap.containsKey(pairAddrBlockLast)) { - TransactionProcessingMetadata.FragmentFirstAndLast blockValueLast = blockMap.get(pairAddrBlockLast); + if (blockMapAccount.containsKey(pairAddrBlockLast)) { + TransactionProcessingMetadata.FragmentFirstAndLast blockValueLast = blockMapAccount.get(pairAddrBlockLast); TransactionProcessingMetadata.FragmentFirstAndLast conflationValueLast = new TransactionProcessingMetadata.FragmentFirstAndLast (null, blockValueLast.getLast(), 0, 0, blockValueLast.getLastDom(), blockValueLast.getLastSub()); + conflationMapAccount.put(addr, conflationValueLast); + } + } + // Doing similar update for the storage map + for (TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair : txnMapStorage.keySet()) { + // Update the first value of the conflation map for Account + // We update the value of the conflation map with the earliest value of the block map + for (int i = 0; i < transients.block().blockNumber(); i++) { + StateManagerMetadata. AddrStorageKeyBlockNumTuple addrStorageBlockTuple = + new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, i); + + if (blockMapStorage.containsKey(addrStorageBlockTuple)) { + TransactionProcessingMetadata.FragmentFirstAndLast blockValueStorage = blockMapStorage.get(addrStorageBlockTuple); + TransactionProcessingMetadata.FragmentFirstAndLast conflationValueStorage = + new TransactionProcessingMetadata.FragmentFirstAndLast + (blockValueStorage.getFirst(), null, blockValueStorage.getFirstDom(), blockValueStorage.getFirstSub(), 0, 0); + conflationMapStorage.put(addrStorageKeyPair, conflationValueStorage); + break; + } + } + // Update the last value of the conflation map for storage + // We update the last value for the conflation map with the latest blockMap's last values, + // if some address is not present in the last block, we ignore the corresponding account + StateManagerMetadata.AddrStorageKeyBlockNumTuple addrStorageBlockTupleLast = new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, transients.block().blockNumber()); + if (blockMapStorage.containsKey(addrStorageBlockTupleLast)) { + TransactionProcessingMetadata.FragmentFirstAndLast blockValueStorageLast = blockMapStorage.get(addrStorageBlockTupleLast); + TransactionProcessingMetadata.FragmentFirstAndLast conflationValueLast = + new TransactionProcessingMetadata.FragmentFirstAndLast + (null, blockValueStorageLast.getLast(), 0, 0, blockValueStorageLast.getLastDom(), blockValueStorageLast.getLastSub()); + conflationMapStorage.put(addrStorageKeyPair, conflationValueLast); } } + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java index 0403bb05d5..9d5ed35cb0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java @@ -22,14 +22,29 @@ public AddrBlockPair(Address addr, int blockNumber) { this.blockNumber = blockNumber; } } + public static class AddrStorageKeyBlockNumTuple { + @Getter + private TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair; + @Getter + private int blockNumber; + + public AddrStorageKeyBlockNumTuple(TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair, int blockNumber) { + this.addrStorageKeyPair = addrStorageKeyPair; + this.blockNumber = blockNumber; + } + } + @Getter + Map> accountFirstLastBlockMap = new HashMap<>(); + @Getter - Map> txnAccountFirstLastBlockMap = new HashMap<>(); + Map> storageFirstLastBlockMap = new HashMap<>(); @Getter - Map> txnStorageFirstLastBlockMap = new HashMap<>(); + Map> accountFirstLastConflationMap = new HashMap<>(); @Getter - Map> txnAccountFirstLastConflationMap = new HashMap<>(); + Map> + storageFirstLastConflationMap = new HashMap<>(); @Getter Map minDeplNoBlock = new HashMap<>(); From d111681bfd966d2d0b77afe647f5d1eef74210de Mon Sep 17 00:00:00 2001 From: arijitdutta67 Date: Thu, 19 Sep 2024 11:35:11 +0530 Subject: [PATCH 19/74] fixing import --- .../main/java/net/consensys/linea/zktracer/module/hub/Hub.java | 1 + 1 file changed, 1 insertion(+) 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 3616e5bf12..793fca0c4d 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 @@ -48,6 +48,7 @@ import net.consensys.linea.zktracer.module.hub.defer.DeferRegistry; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.StackFragment; +import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.section.AccountSection; From 7ce5ad039cc9fa31db51fff1269486415f91ca68 Mon Sep 17 00:00:00 2001 From: arijitdutta67 Date: Thu, 19 Sep 2024 15:28:47 +0530 Subject: [PATCH 20/74] fixing gradlew formatting --- .../linea/zktracer/module/hub/Hub.java | 373 ++++++++++-------- .../zktracer/module/hub/TransactionStack.java | 2 +- .../hub/fragment/account/AccountFragment.java | 13 +- .../hub/fragment/storage/StorageFragment.java | 3 +- .../module/hub/section/SloadSection.java | 40 +- .../module/hub/section/SstoreSection.java | 39 +- .../hub/section/TxPreWarmingMacroSection.java | 14 +- .../hub/transients/StateManagerMetadata.java | 116 +++--- .../module/hub/transients/Transients.java | 8 - .../types/TransactionProcessingMetadata.java | 148 +++---- 10 files changed, 415 insertions(+), 341 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 dd850f8983..3a815f8423 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 @@ -161,7 +161,7 @@ public class Hub implements Module { /** provides phase-related volatile information */ @Getter Transients transients = new Transients(this); - /** Block and conflation-level metadata for computing columns relevant to the state manager.**/ + /** Block and conflation-level metadata for computing columns relevant to the state manager.* */ @Getter static StateManagerMetadata stateManagerMetadata = new StateManagerMetadata(); /** @@ -1192,189 +1192,238 @@ public final boolean deploymentStatusOfAccountAddress() { return deploymentStatusOf(this.accountAddress()); } - - public void updateBlockMap() { - Map> blockMapAccount - = Hub.stateManagerMetadata().getAccountFirstLastBlockMap(); + Map< + StateManagerMetadata.AddrBlockPair, + TransactionProcessingMetadata.FragmentFirstAndLast> + blockMapAccount = Hub.stateManagerMetadata().getAccountFirstLastBlockMap(); - Map> blockMapStorage - = Hub.stateManagerMetadata().getStorageFirstLastBlockMap(); + Map< + StateManagerMetadata.AddrStorageKeyBlockNumTuple, + TransactionProcessingMetadata.FragmentFirstAndLast> + blockMapStorage = Hub.stateManagerMetadata().getStorageFirstLastBlockMap(); List txn = txStack.getTxs(); for (TransactionProcessingMetadata metadata : txn) { - if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) { - int blockNumber = transients.block().blockNumber(); - Map> localMapAccount - = metadata.getAccountFirstAndLastMap(); - - Map> - localMapStorage = metadata.getStorageFirstAndLastMap(); - - // Update the block map for the account - for (Address addr : localMapAccount.keySet()) { - StateManagerMetadata.AddrBlockPair pairAddrBlock = new StateManagerMetadata.AddrBlockPair(addr, blockNumber); - - // localValue exists for sure because addr belongs to the keySet of the local map - TransactionProcessingMetadata.FragmentFirstAndLast localValueAccount = localMapAccount.get(addr); - if (!blockMapAccount.containsKey(pairAddrBlock)) { - // the pair is not present in the map - blockMapAccount.put(pairAddrBlock, localValueAccount); - } else { - TransactionProcessingMetadata.FragmentFirstAndLast blockValue = blockMapAccount.get(pairAddrBlock); - // update the first part of the blockValue - // Todo: Refactor and remove code duplication - if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( - localValueAccount.getFirstDom(), localValueAccount.getFirstSub(), blockValue.getFirstDom(), blockValue.getFirstSub())) { - // chronologically checks that localValue.First is before blockValue.First - // localValue comes chronologically before, and should be the first value of the map. - blockValue.setFirst(localValueAccount.getFirst()); - blockValue.setFirstDom(localValueAccount.getFirstDom()); - blockValue.setFirstSub(localValueAccount.getFirstSub()); - - // update the last part of the blockValue - if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( - blockValue.getLastDom(), blockValue.getLastSub(), localValueAccount.getLastDom(), localValueAccount.getLastSub())) { - // chronologically checks that blockValue.Last is before localValue.Last - // localValue comes chronologically after, and should be the final value of the map. - blockValue.setLast(localValueAccount.getLast()); - blockValue.setLastDom(localValueAccount.getLastDom()); - blockValue.setLastSub(localValueAccount.getLastSub()); - } - blockMapAccount.put(pairAddrBlock, blockValue); - } - } - + if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) { + int blockNumber = transients.block().blockNumber(); + Map> + localMapAccount = metadata.getAccountFirstAndLastMap(); + + Map< + TransactionProcessingMetadata.AddrStorageKeyPair, + TransactionProcessingMetadata.FragmentFirstAndLast> + localMapStorage = metadata.getStorageFirstAndLastMap(); + + // Update the block map for the account + for (Address addr : localMapAccount.keySet()) { + StateManagerMetadata.AddrBlockPair pairAddrBlock = + new StateManagerMetadata.AddrBlockPair(addr, blockNumber); + + // localValue exists for sure because addr belongs to the keySet of the local map + TransactionProcessingMetadata.FragmentFirstAndLast localValueAccount = + localMapAccount.get(addr); + if (!blockMapAccount.containsKey(pairAddrBlock)) { + // the pair is not present in the map + blockMapAccount.put(pairAddrBlock, localValueAccount); + } else { + TransactionProcessingMetadata.FragmentFirstAndLast blockValue = + blockMapAccount.get(pairAddrBlock); + // update the first part of the blockValue + // Todo: Refactor and remove code duplication + if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( + localValueAccount.getFirstDom(), + localValueAccount.getFirstSub(), + blockValue.getFirstDom(), + blockValue.getFirstSub())) { + // chronologically checks that localValue.First is before blockValue.First + // localValue comes chronologically before, and should be the first value of the map. + blockValue.setFirst(localValueAccount.getFirst()); + blockValue.setFirstDom(localValueAccount.getFirstDom()); + blockValue.setFirstSub(localValueAccount.getFirstSub()); + + // update the last part of the blockValue + if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( + blockValue.getLastDom(), + blockValue.getLastSub(), + localValueAccount.getLastDom(), + localValueAccount.getLastSub())) { + // chronologically checks that blockValue.Last is before localValue.Last + // localValue comes chronologically after, and should be the final value of the map. + blockValue.setLast(localValueAccount.getLast()); + blockValue.setLastDom(localValueAccount.getLastDom()); + blockValue.setLastSub(localValueAccount.getLastSub()); } - // Update the block map for storage - for (TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair : localMapStorage.keySet()) { - - StateManagerMetadata.AddrStorageKeyBlockNumTuple addrStorageBlockTuple = - new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, blockNumber); - - // localValue exists for sure because addr belongs to the keySet of the local map - TransactionProcessingMetadata.FragmentFirstAndLast localValueStorage = - localMapStorage.get(addrStorageKeyPair); - - if (!blockMapStorage.containsKey(addrStorageBlockTuple)) { - // the pair is not present in the map - blockMapStorage.put(addrStorageBlockTuple, localValueStorage); - } else { - TransactionProcessingMetadata.FragmentFirstAndLast blockValueStorage = blockMapStorage.get(addrStorageBlockTuple); - // update the first part of the blockValue - if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( - localValueStorage.getFirstDom(), localValueStorage.getFirstSub(), blockValueStorage.getFirstDom(), blockValueStorage.getFirstSub())) { - // chronologically checks that localValue.First is before blockValue.First - // localValue comes chronologically before, and should be the first value of the map. - blockValueStorage.setFirst(localValueStorage.getFirst()); - blockValueStorage.setFirstDom(localValueStorage.getFirstDom()); - blockValueStorage.setFirstSub(localValueStorage.getFirstSub()); - - // update the last part of the blockValue - if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( - blockValueStorage.getLastDom(), blockValueStorage.getLastSub(), localValueStorage.getLastDom(), localValueStorage.getLastSub())) { - // chronologically checks that blockValue.Last is before localValue.Last - // localValue comes chronologically after, and should be the final value of the map. - blockValueStorage.setLast(localValueStorage.getLast()); - blockValueStorage.setLastDom(localValueStorage.getLastDom()); - blockValueStorage.setLastSub(localValueStorage.getLastSub()); - } - blockMapStorage.put(addrStorageBlockTuple, blockValueStorage); - } + blockMapAccount.put(pairAddrBlock, blockValue); + } + } + } + // Update the block map for storage + for (TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair : + localMapStorage.keySet()) { + + StateManagerMetadata.AddrStorageKeyBlockNumTuple addrStorageBlockTuple = + new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, blockNumber); + + // localValue exists for sure because addr belongs to the keySet of the local map + TransactionProcessingMetadata.FragmentFirstAndLast localValueStorage = + localMapStorage.get(addrStorageKeyPair); + + if (!blockMapStorage.containsKey(addrStorageBlockTuple)) { + // the pair is not present in the map + blockMapStorage.put(addrStorageBlockTuple, localValueStorage); + } else { + TransactionProcessingMetadata.FragmentFirstAndLast blockValueStorage = + blockMapStorage.get(addrStorageBlockTuple); + // update the first part of the blockValue + if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( + localValueStorage.getFirstDom(), + localValueStorage.getFirstSub(), + blockValueStorage.getFirstDom(), + blockValueStorage.getFirstSub())) { + // chronologically checks that localValue.First is before blockValue.First + // localValue comes chronologically before, and should be the first value of the map. + blockValueStorage.setFirst(localValueStorage.getFirst()); + blockValueStorage.setFirstDom(localValueStorage.getFirstDom()); + blockValueStorage.setFirstSub(localValueStorage.getFirstSub()); + + // update the last part of the blockValue + if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( + blockValueStorage.getLastDom(), + blockValueStorage.getLastSub(), + localValueStorage.getLastDom(), + localValueStorage.getLastSub())) { + // chronologically checks that blockValue.Last is before localValue.Last + // localValue comes chronologically after, and should be the final value of the map. + blockValueStorage.setLast(localValueStorage.getLast()); + blockValueStorage.setLastDom(localValueStorage.getLastDom()); + blockValueStorage.setLastSub(localValueStorage.getLastSub()); } + blockMapStorage.put(addrStorageBlockTuple, blockValueStorage); } } + } } + } + } -} - - -// Update the conflation level map for the state manager -public void updateConflationMap() { - Map> - conflationMapAccount = Hub.stateManagerMetadata().getAccountFirstLastConflationMap(); - - Map> - conflationMapStorage = Hub.stateManagerMetadata().getStorageFirstLastConflationMap(); + // Update the conflation level map for the state manager + public void updateConflationMap() { + Map> + conflationMapAccount = Hub.stateManagerMetadata().getAccountFirstLastConflationMap(); - List txn = txStack.getTxs(); + Map< + TransactionProcessingMetadata.AddrStorageKeyPair, + TransactionProcessingMetadata.FragmentFirstAndLast> + conflationMapStorage = Hub.stateManagerMetadata().getStorageFirstLastConflationMap(); - Map> - blockMapAccount = Hub.stateManagerMetadata().getAccountFirstLastBlockMap(); + List txn = txStack.getTxs(); - Map> - blockMapStorage = Hub.stateManagerMetadata().getStorageFirstLastBlockMap(); + Map< + StateManagerMetadata.AddrBlockPair, + TransactionProcessingMetadata.FragmentFirstAndLast> + blockMapAccount = Hub.stateManagerMetadata().getAccountFirstLastBlockMap(); - for (TransactionProcessingMetadata metadata : txn) { + Map< + StateManagerMetadata.AddrStorageKeyBlockNumTuple, + TransactionProcessingMetadata.FragmentFirstAndLast> + blockMapStorage = Hub.stateManagerMetadata().getStorageFirstLastBlockMap(); - Map> txnMapAccount = metadata.getAccountFirstAndLastMap(); + for (TransactionProcessingMetadata metadata : txn) { - Map> - txnMapStorage = metadata.getStorageFirstAndLastMap(); - for (Address addr : txnMapAccount.keySet()) { - // Update the first value of the conflation map for Account - // We update the value of the conflation map with the earliest value of the block map - for (int i = 0; i < transients.block().blockNumber(); i++) { - StateManagerMetadata.AddrBlockPair pairAddrBlock = new StateManagerMetadata.AddrBlockPair(addr, i); - if (blockMapAccount.containsKey(pairAddrBlock)) { - TransactionProcessingMetadata.FragmentFirstAndLast blockValue = blockMapAccount.get(pairAddrBlock); - TransactionProcessingMetadata.FragmentFirstAndLast conflationValue = - new TransactionProcessingMetadata.FragmentFirstAndLast - (blockValue.getFirst(), null, blockValue.getFirstDom(), blockValue.getFirstSub(), 0, 0); - conflationMapAccount.put(addr, conflationValue); - break; + Map> + txnMapAccount = metadata.getAccountFirstAndLastMap(); + + Map< + TransactionProcessingMetadata.AddrStorageKeyPair, + TransactionProcessingMetadata.FragmentFirstAndLast> + txnMapStorage = metadata.getStorageFirstAndLastMap(); + for (Address addr : txnMapAccount.keySet()) { + // Update the first value of the conflation map for Account + // We update the value of the conflation map with the earliest value of the block map + for (int i = 0; i < transients.block().blockNumber(); i++) { + StateManagerMetadata.AddrBlockPair pairAddrBlock = + new StateManagerMetadata.AddrBlockPair(addr, i); + if (blockMapAccount.containsKey(pairAddrBlock)) { + TransactionProcessingMetadata.FragmentFirstAndLast blockValue = + blockMapAccount.get(pairAddrBlock); + TransactionProcessingMetadata.FragmentFirstAndLast conflationValue = + new TransactionProcessingMetadata.FragmentFirstAndLast( + blockValue.getFirst(), + null, + blockValue.getFirstDom(), + blockValue.getFirstSub(), + 0, + 0); + conflationMapAccount.put(addr, conflationValue); + break; + } } - } - // Update the last value of the conflation map - // We update the last value for the conflation map with the latest blockMap's last values, - // if some address is not present in the last block, we ignore the corresponding account - StateManagerMetadata.AddrBlockPair pairAddrBlockLast = new StateManagerMetadata.AddrBlockPair(addr, transients.block().blockNumber()); - if (blockMapAccount.containsKey(pairAddrBlockLast)) { - TransactionProcessingMetadata.FragmentFirstAndLast blockValueLast = blockMapAccount.get(pairAddrBlockLast); - TransactionProcessingMetadata.FragmentFirstAndLast conflationValueLast = - new TransactionProcessingMetadata.FragmentFirstAndLast - (null, blockValueLast.getLast(), 0, 0, blockValueLast.getLastDom(), blockValueLast.getLastSub()); - conflationMapAccount.put(addr, conflationValueLast); - } - } - // Doing similar update for the storage map - for (TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair : txnMapStorage.keySet()) { - // Update the first value of the conflation map for Account - // We update the value of the conflation map with the earliest value of the block map - for (int i = 0; i < transients.block().blockNumber(); i++) { - StateManagerMetadata. AddrStorageKeyBlockNumTuple addrStorageBlockTuple = - new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, i); - - if (blockMapStorage.containsKey(addrStorageBlockTuple)) { - TransactionProcessingMetadata.FragmentFirstAndLast blockValueStorage = blockMapStorage.get(addrStorageBlockTuple); - TransactionProcessingMetadata.FragmentFirstAndLast conflationValueStorage = - new TransactionProcessingMetadata.FragmentFirstAndLast - (blockValueStorage.getFirst(), null, blockValueStorage.getFirstDom(), blockValueStorage.getFirstSub(), 0, 0); - conflationMapStorage.put(addrStorageKeyPair, conflationValueStorage); - break; + // Update the last value of the conflation map + // We update the last value for the conflation map with the latest blockMap's last values, + // if some address is not present in the last block, we ignore the corresponding account + StateManagerMetadata.AddrBlockPair pairAddrBlockLast = + new StateManagerMetadata.AddrBlockPair(addr, transients.block().blockNumber()); + if (blockMapAccount.containsKey(pairAddrBlockLast)) { + TransactionProcessingMetadata.FragmentFirstAndLast blockValueLast = + blockMapAccount.get(pairAddrBlockLast); + TransactionProcessingMetadata.FragmentFirstAndLast conflationValueLast = + new TransactionProcessingMetadata.FragmentFirstAndLast( + null, + blockValueLast.getLast(), + 0, + 0, + blockValueLast.getLastDom(), + blockValueLast.getLastSub()); + conflationMapAccount.put(addr, conflationValueLast); } } - // Update the last value of the conflation map for storage - // We update the last value for the conflation map with the latest blockMap's last values, - // if some address is not present in the last block, we ignore the corresponding account - StateManagerMetadata.AddrStorageKeyBlockNumTuple addrStorageBlockTupleLast = new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, transients.block().blockNumber()); - if (blockMapStorage.containsKey(addrStorageBlockTupleLast)) { - TransactionProcessingMetadata.FragmentFirstAndLast blockValueStorageLast = blockMapStorage.get(addrStorageBlockTupleLast); - TransactionProcessingMetadata.FragmentFirstAndLast conflationValueLast = - new TransactionProcessingMetadata.FragmentFirstAndLast - (null, blockValueStorageLast.getLast(), 0, 0, blockValueStorageLast.getLastDom(), blockValueStorageLast.getLastSub()); - conflationMapStorage.put(addrStorageKeyPair, conflationValueLast); + // Doing similar update for the storage map + for (TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair : + txnMapStorage.keySet()) { + // Update the first value of the conflation map for Account + // We update the value of the conflation map with the earliest value of the block map + for (int i = 0; i < transients.block().blockNumber(); i++) { + StateManagerMetadata.AddrStorageKeyBlockNumTuple addrStorageBlockTuple = + new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, i); + + if (blockMapStorage.containsKey(addrStorageBlockTuple)) { + TransactionProcessingMetadata.FragmentFirstAndLast blockValueStorage = + blockMapStorage.get(addrStorageBlockTuple); + TransactionProcessingMetadata.FragmentFirstAndLast + conflationValueStorage = + new TransactionProcessingMetadata.FragmentFirstAndLast( + blockValueStorage.getFirst(), + null, + blockValueStorage.getFirstDom(), + blockValueStorage.getFirstSub(), + 0, + 0); + conflationMapStorage.put(addrStorageKeyPair, conflationValueStorage); + break; + } + } + // Update the last value of the conflation map for storage + // We update the last value for the conflation map with the latest blockMap's last values, + // if some address is not present in the last block, we ignore the corresponding account + StateManagerMetadata.AddrStorageKeyBlockNumTuple addrStorageBlockTupleLast = + new StateManagerMetadata.AddrStorageKeyBlockNumTuple( + addrStorageKeyPair, transients.block().blockNumber()); + if (blockMapStorage.containsKey(addrStorageBlockTupleLast)) { + TransactionProcessingMetadata.FragmentFirstAndLast + blockValueStorageLast = blockMapStorage.get(addrStorageBlockTupleLast); + TransactionProcessingMetadata.FragmentFirstAndLast conflationValueLast = + new TransactionProcessingMetadata.FragmentFirstAndLast( + null, + blockValueStorageLast.getLast(), + 0, + 0, + blockValueStorageLast.getLastDom(), + blockValueStorageLast.getLastSub()); + conflationMapStorage.put(addrStorageKeyPair, conflationValueLast); + } } } - } - - } - - - } - - - 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 673af31b4f..3ba6bf8ede 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 @@ -19,7 +19,6 @@ import java.util.List; import lombok.Getter; -import lombok.Setter; import net.consensys.linea.zktracer.container.StackedContainer; import net.consensys.linea.zktracer.module.hub.transients.Block; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; @@ -31,6 +30,7 @@ public class TransactionStack implements StackedContainer { @Getter private final List txs = new ArrayList<>(200); // TODO: write the allocated memory from .toml file + private int currentAbsNumber; private int relativeTransactionNumber; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index f308080a75..b35fc1cb7d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -39,7 +39,6 @@ import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.worldstate.WorldView; @@ -57,8 +56,7 @@ public final class AccountFragment @Setter private boolean requiresRomlex; private int codeFragmentIndex; private final Optional addressToTrim; - @Getter - private final DomSubStampsSubFragment domSubStampsSubFragment; + @Getter private final DomSubStampsSubFragment domSubStampsSubFragment; @Setter private RlpAddrSubFragment rlpAddrSubFragment; private boolean markedForSelfDestruct; private boolean markedForSelfDestructNew; @@ -112,7 +110,9 @@ public AccountFragment( // Updating the map transactionProcessingMetadata.updateAccountFirstAndLast(this); // update the minDeplMoBlock and maxDeplNoBlock maps - Hub.stateManagerMetadata().updateDeplNoBlockMaps(oldState.address(), + Hub.stateManagerMetadata() + .updateDeplNoBlockMaps( + oldState.address(), transactionProcessingMetadata.getRelativeBlockNumber(), deploymentNumber); @@ -178,7 +178,7 @@ public Trace trace(Trace trace) { @Override public void resolvePostTransaction( - Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { + Hub hub, WorldView state, Transaction tx, boolean isSuccessful) { final Map effectiveSelfDestructMap = transactionProcessingMetadata.getEffectiveSelfDestructMap(); final TransactionProcessingMetadata.EphemeralAccount ephemeralAccount = @@ -205,7 +205,4 @@ public void resolvePostConflation(Hub hub, WorldView world) { ContractMetadata.make(oldState.address(), deploymentNumber, isDeployment)) : 0; } - } - - diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index 431f3db41f..d90d87ce4b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -40,8 +40,7 @@ public final class StorageFragment implements TraceFragment { private final EWord valueNext; private final boolean incomingWarmth; private final boolean outgoingWarmth; - @Getter - private final DomSubStampsSubFragment domSubStampsSubFragment; + @Getter private final DomSubStampsSubFragment domSubStampsSubFragment; private final int blockNumber; private final StorageFragmentPurpose purpose; // for debugging purposes diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java index 58905a5df6..eed4dd934f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SloadSection.java @@ -91,25 +91,27 @@ public SloadSection(Hub hub, WorldView worldView) { private StorageFragment doingSload(Hub hub) { TransactionProcessingMetadata txnMetadata = hub.txStack().current(); - StorageFragment newFragment = new StorageFragment( - hub.state, - new State.StorageSlotIdentifier( - accountAddress, accountAddressDeploymentNumber, EWord.of(storageKey)), - valueOriginal, - valueCurrent, - valueCurrent, - incomingWarmth, - true, - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0), - hub.state.firstAndLastStorageSlotOccurrences.size(), - SLOAD_DOING, - accountAddressDeploymentNumber, // Arijit — check that it is computed properly beforehand. + StorageFragment newFragment = + new StorageFragment( + hub.state, + new State.StorageSlotIdentifier( + accountAddress, accountAddressDeploymentNumber, EWord.of(storageKey)), + valueOriginal, + valueCurrent, + valueCurrent, + incomingWarmth, + true, + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0), + hub.state.firstAndLastStorageSlotOccurrences.size(), + SLOAD_DOING, + accountAddressDeploymentNumber, // Arijit — check that it is computed properly + // beforehand. txnMetadata); // update storage txn map values for the state manager as new storage fragment is created - TransactionProcessingMetadata.AddrStorageKeyPair mapKey = new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); + TransactionProcessingMetadata.AddrStorageKeyPair mapKey = + new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); txnMetadata.updateStorageFirstAndLast(newFragment, mapKey); return newFragment; - } @Override @@ -139,12 +141,14 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca undoingDomSubStamps, hub.state.firstAndLastStorageSlotOccurrences.size(), SLOAD_UNDOING, - accountAddressDeploymentNumber, // Arijit — check that it is computed properly beforehand. - txnMetadata); + accountAddressDeploymentNumber, // Arijit — check that it is computed properly + // beforehand. + txnMetadata); this.addFragment(undoingSloadStorageFragment); // update storage txn map values for the state manager as new storage fragment is created - TransactionProcessingMetadata.AddrStorageKeyPair mapKey = new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); + TransactionProcessingMetadata.AddrStorageKeyPair mapKey = + new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); txnMetadata.updateStorageFirstAndLast(undoingSloadStorageFragment, mapKey); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java index 2e49abafe8..695a156423 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/SstoreSection.java @@ -116,21 +116,24 @@ public SstoreSection(Hub hub, WorldView worldView) { private StorageFragment doingSstore(Hub hub) { TransactionProcessingMetadata txnMetadata = hub.txStack().current(); - StorageFragment newFragment = new StorageFragment( - hub.state, - new State.StorageSlotIdentifier( - accountAddress, accountAddressDeploymentNumber, EWord.of(storageKey)), - valueOriginal, - valueCurrent, - valueNext, - incomingWarmth, - true, - DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0), - hub.state.firstAndLastStorageSlotOccurrences.size(), - SSTORE_DOING, - accountAddressDeploymentNumber, // Arijit — check that it is computed properly beforehand. + StorageFragment newFragment = + new StorageFragment( + hub.state, + new State.StorageSlotIdentifier( + accountAddress, accountAddressDeploymentNumber, EWord.of(storageKey)), + valueOriginal, + valueCurrent, + valueNext, + incomingWarmth, + true, + DomSubStampsSubFragment.standardDomSubStamps(this.hubStamp(), 0), + hub.state.firstAndLastStorageSlotOccurrences.size(), + SSTORE_DOING, + accountAddressDeploymentNumber, // Arijit — check that it is computed properly + // beforehand. txnMetadata); - TransactionProcessingMetadata.AddrStorageKeyPair mapKey = new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); + TransactionProcessingMetadata.AddrStorageKeyPair mapKey = + new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); // update storage txn map values for the state manager as new storage fragment is created txnMetadata.updateStorageFirstAndLast(newFragment, mapKey); return newFragment; @@ -156,14 +159,16 @@ public void resolvePostRollback(Hub hub, MessageFrame messageFrame, CallFrame ca undoingDomSubStamps, hub.state.firstAndLastStorageSlotOccurrences.size(), SSTORE_UNDOING, - accountAddressDeploymentNumber, // Arijit — check that it is computed properly beforehand. - txnMetadata); + accountAddressDeploymentNumber, // Arijit — check that it is computed properly + // beforehand. + txnMetadata); this.addFragment(undoingSstoreStorageFragment); // undo the refund commonValues.refundDelta(0); // update storage txn map values for the state manager as new storage fragment is created - TransactionProcessingMetadata.AddrStorageKeyPair mapKey = new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); + TransactionProcessingMetadata.AddrStorageKeyPair mapKey = + new TransactionProcessingMetadata.AddrStorageKeyPair(accountAddress, EWord.of(storageKey)); txnMetadata.updateStorageFirstAndLast(undoingSstoreStorageFragment, mapKey); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java index 5d5e86d252..63367401fc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TxPreWarmingMacroSection.java @@ -121,18 +121,20 @@ public TxPreWarmingMacroSection(WorldView world, Hub hub) { DomSubStampsSubFragment.standardDomSubStamps(hub.stamp(), 0), hub.state.firstAndLastStorageSlotOccurrences.size(), PRE_WARMING, - deploymentNumber, // Arijit — check that it is computed properly beforehand. - txnMetadata); + deploymentNumber, // Arijit — check that it is computed properly + // beforehand. + txnMetadata); new TxPrewarmingSection(hub, storageFragment); hub.state.updateOrInsertStorageSlotOccurrence( storageSlotIdentifier, storageFragment); seenKeys.get(address).add(key); - // update storage txn map values for the state manager as new storage fragment is created - TransactionProcessingMetadata.AddrStorageKeyPair mapKey = new TransactionProcessingMetadata.AddrStorageKeyPair(address, EWord.of(key)); + // update storage txn map values for the state manager as new storage fragment + // is created + TransactionProcessingMetadata.AddrStorageKeyPair mapKey = + new TransactionProcessingMetadata.AddrStorageKeyPair( + address, EWord.of(key)); txnMetadata.updateStorageFirstAndLast(storageFragment, mapKey); - - } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java index 9d5ed35cb0..36c174b4d5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java @@ -1,66 +1,86 @@ +/* + * Copyright Consensys Software 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.transients; +import java.util.HashMap; +import java.util.Map; + import lombok.Getter; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.hyperledger.besu.datatypes.Address; -import java.util.HashMap; -import java.util.Map; - -public class StateManagerMetadata -{ - public static class AddrBlockPair { - @Getter - private Address address; - @Getter - private int blockNumber; +public class StateManagerMetadata { + public static class AddrBlockPair { + @Getter private Address address; + @Getter private int blockNumber; - public AddrBlockPair(Address addr, int blockNumber) { - this.address = addr; - this.blockNumber = blockNumber; - } + public AddrBlockPair(Address addr, int blockNumber) { + this.address = addr; + this.blockNumber = blockNumber; } - public static class AddrStorageKeyBlockNumTuple { - @Getter - private TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair; - @Getter - private int blockNumber; + } + + public static class AddrStorageKeyBlockNumTuple { + @Getter private TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair; + @Getter private int blockNumber; - public AddrStorageKeyBlockNumTuple(TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair, int blockNumber) { - this.addrStorageKeyPair = addrStorageKeyPair; - this.blockNumber = blockNumber; - } + public AddrStorageKeyBlockNumTuple( + TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair, int blockNumber) { + this.addrStorageKeyPair = addrStorageKeyPair; + this.blockNumber = blockNumber; } - @Getter - Map> accountFirstLastBlockMap = new HashMap<>(); + } + + @Getter + Map> + accountFirstLastBlockMap = new HashMap<>(); + + @Getter + Map< + AddrStorageKeyBlockNumTuple, + TransactionProcessingMetadata.FragmentFirstAndLast> + storageFirstLastBlockMap = new HashMap<>(); - @Getter - Map> storageFirstLastBlockMap = new HashMap<>(); + @Getter + Map> + accountFirstLastConflationMap = new HashMap<>(); - @Getter - Map> accountFirstLastConflationMap = new HashMap<>(); + @Getter + Map< + TransactionProcessingMetadata.AddrStorageKeyPair, + TransactionProcessingMetadata.FragmentFirstAndLast> + storageFirstLastConflationMap = new HashMap<>(); - @Getter - Map> - storageFirstLastConflationMap = new HashMap<>(); + @Getter Map minDeplNoBlock = new HashMap<>(); + @Getter Map maxDeplNoBlock = new HashMap<>(); - @Getter - Map minDeplNoBlock = new HashMap<>(); - @Getter - Map maxDeplNoBlock = new HashMap<>(); - public void updateDeplNoBlockMaps(Address address, int blockNumber, int currentDeplNo) { - AddrBlockPair addrBlockPair = new AddrBlockPair(address, blockNumber); - if (minDeplNoBlock.containsKey(addrBlockPair)) { - // the maps already contain deployment info for this address, and this is not the first one in the block - // since it is not the first, we do not update the minDeplNoBlock - // but we update the maxDeplNoBlock - maxDeplNoBlock.put(addrBlockPair, currentDeplNo); - } else { - // this is the first time we have a deployment at this address in the block - minDeplNoBlock.put(addrBlockPair, currentDeplNo); - maxDeplNoBlock.put(addrBlockPair, currentDeplNo); - } + public void updateDeplNoBlockMaps(Address address, int blockNumber, int currentDeplNo) { + AddrBlockPair addrBlockPair = new AddrBlockPair(address, blockNumber); + if (minDeplNoBlock.containsKey(addrBlockPair)) { + // the maps already contain deployment info for this address, and this is not the first one in + // the block + // since it is not the first, we do not update the minDeplNoBlock + // but we update the maxDeplNoBlock + maxDeplNoBlock.put(addrBlockPair, currentDeplNo); + } else { + // this is the first time we have a deployment at this address in the block + minDeplNoBlock.put(addrBlockPair, currentDeplNo); + maxDeplNoBlock.put(addrBlockPair, currentDeplNo); } + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java index 11ee7a0157..298111a06d 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/Transients.java @@ -16,16 +16,9 @@ package net.consensys.linea.zktracer.module.hub.transients; import lombok.Getter; -import lombok.Setter; import lombok.experimental.Accessors; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; -import org.apache.commons.lang3.tuple.Pair; -import org.hyperledger.besu.datatypes.Address; - -import java.util.HashMap; -import java.util.Map; /** * This class stores data and provide information accessible through the {@link Hub} of various @@ -45,7 +38,6 @@ public class Transients { /** provides operation-related information */ final OperationAncillaries op; - public TransactionProcessingMetadata tx() { return this.hub.txStack().current(); } 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 85d7841c90..30408d4ce9 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 @@ -121,15 +121,23 @@ public class TransactionProcessingMetadata implements PostTransactionDefer { @Getter Map effectiveSelfDestructMap = new HashMap<>(); - /* FragmentFirstAndLast stores the first and last fragments relevant to the state manager in the - * current transaction segment (they will be either account fragments or storage fragments). */ - @Getter @Setter + /* FragmentFirstAndLast stores the first and last fragments relevant to the state manager in the + * current transaction segment (they will be either account fragments or storage fragments). */ + @Getter + @Setter public static class FragmentFirstAndLast { TraceFragment first; TraceFragment last; int firstDom, firstSub; int lastDom, lastSub; - public FragmentFirstAndLast(TraceFragment first, TraceFragment last, int firstDom, int firstSub, int lastDom, int lastSub) { + + public FragmentFirstAndLast( + TraceFragment first, + TraceFragment last, + int firstDom, + int firstSub, + int lastDom, + int lastSub) { this.first = first; this.last = last; this.firstDom = firstDom; @@ -137,89 +145,87 @@ public FragmentFirstAndLast(TraceFragment first, TraceFragment last, int firstDo this.lastDom = lastDom; this.lastSub = lastSub; } - public static boolean strictlySmallerStamps(int firstDom, int firstSub, int lastDom, int lastSub) { - return firstDom < lastDom || - (firstDom == lastDom && - firstSub > lastSub); - } + public static boolean strictlySmallerStamps( + int firstDom, int firstSub, int lastDom, int lastSub) { + return firstDom < lastDom || (firstDom == lastDom && firstSub > lastSub); + } } - public static class AddrStorageKeyPair { - @Getter - private Address address; - @Getter - private EWord storageKey; + public static class AddrStorageKeyPair { + @Getter private Address address; + @Getter private EWord storageKey; - public AddrStorageKeyPair(Address addr, EWord storageKey) { - this.address = addr; - this.storageKey = storageKey; - } + public AddrStorageKeyPair(Address addr, EWord storageKey) { + this.address = addr; + this.storageKey = storageKey; } - + } // Map for the first and last account occurrence @Getter Map> accountFirstAndLastMap = new HashMap<>(); + // Map for the first and last storage occurrence @Getter - Map> storageFirstAndLastMap = new HashMap<>(); + Map> storageFirstAndLastMap = + new HashMap<>(); + // Todo: Create a generic method which can handle AccountFragment and StorageFragment public void updateAccountFirstAndLast(AccountFragment fragment) { - // Setting the post transaction first and last value - int dom = fragment.domSubStampsSubFragment().domStamp(); - int sub = fragment.domSubStampsSubFragment().subStamp(); - - Address key = fragment.oldState().address(); - - // Initialise the Account First and Last map - final Map> txnAccountFirstAndLastMap = - getAccountFirstAndLastMap(); - if (!txnAccountFirstAndLastMap.containsKey(key)) { - TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = - new FragmentFirstAndLast(fragment, fragment, dom, sub, dom, sub); - txnAccountFirstAndLastMap.put(key, txnFirstAndLast); - } else { - TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = txnAccountFirstAndLastMap.get(key); - // Replace condition - if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( - txnFirstAndLast.getLastDom(), txnFirstAndLast.getLastSub(), - dom, sub)) { - txnFirstAndLast.setLast(fragment); - txnFirstAndLast.setLastDom(dom); - txnFirstAndLast.setLastSub(sub); - txnAccountFirstAndLastMap.put(key, txnFirstAndLast); - } - } + // Setting the post transaction first and last value + int dom = fragment.domSubStampsSubFragment().domStamp(); + int sub = fragment.domSubStampsSubFragment().subStamp(); + + Address key = fragment.oldState().address(); + + // Initialise the Account First and Last map + final Map> + txnAccountFirstAndLastMap = getAccountFirstAndLastMap(); + if (!txnAccountFirstAndLastMap.containsKey(key)) { + TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = + new FragmentFirstAndLast(fragment, fragment, dom, sub, dom, sub); + txnAccountFirstAndLastMap.put(key, txnFirstAndLast); + } else { + TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = + txnAccountFirstAndLastMap.get(key); + // Replace condition + if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( + txnFirstAndLast.getLastDom(), txnFirstAndLast.getLastSub(), dom, sub)) { + txnFirstAndLast.setLast(fragment); + txnFirstAndLast.setLastDom(dom); + txnFirstAndLast.setLastSub(sub); + txnAccountFirstAndLastMap.put(key, txnFirstAndLast); + } } - public void updateStorageFirstAndLast(StorageFragment fragment, AddrStorageKeyPair key) { - // Setting the post transaction first and last value - int dom = fragment.getDomSubStampsSubFragment().domStamp(); - int sub = fragment.getDomSubStampsSubFragment().subStamp(); - - - // Initialise the Storage First and Last map - final Map> txnStorageFirstAndLastMap = - getStorageFirstAndLastMap(); - if (!txnStorageFirstAndLastMap.containsKey(key)) { - TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = - new FragmentFirstAndLast(fragment, fragment, dom, sub, dom, sub); - txnStorageFirstAndLastMap.put(key, txnFirstAndLast); - } else { - TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = txnStorageFirstAndLastMap.get(key); - // Replace condition - if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( - txnFirstAndLast.getLastDom(), txnFirstAndLast.getLastSub(), - dom, sub)) { - txnFirstAndLast.setLast(fragment); - txnFirstAndLast.setLastDom(dom); - txnFirstAndLast.setLastSub(sub); - txnStorageFirstAndLastMap.put(key, txnFirstAndLast); - } - } + } + public void updateStorageFirstAndLast(StorageFragment fragment, AddrStorageKeyPair key) { + // Setting the post transaction first and last value + int dom = fragment.getDomSubStampsSubFragment().domStamp(); + int sub = fragment.getDomSubStampsSubFragment().subStamp(); + + // Initialise the Storage First and Last map + final Map< + AddrStorageKeyPair, TransactionProcessingMetadata.FragmentFirstAndLast> + txnStorageFirstAndLastMap = getStorageFirstAndLastMap(); + if (!txnStorageFirstAndLastMap.containsKey(key)) { + TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = + new FragmentFirstAndLast(fragment, fragment, dom, sub, dom, sub); + txnStorageFirstAndLastMap.put(key, txnFirstAndLast); + } else { + TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = + txnStorageFirstAndLastMap.get(key); + // Replace condition + if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( + txnFirstAndLast.getLastDom(), txnFirstAndLast.getLastSub(), dom, sub)) { + txnFirstAndLast.setLast(fragment); + txnFirstAndLast.setLastDom(dom); + txnFirstAndLast.setLastSub(sub); + txnStorageFirstAndLastMap.put(key, txnFirstAndLast); + } } - + } // Ephermeral accounts are both accounts that have been deployed on-chain // and accounts that live for a limited time From 5d1d8ffe426044e5d9272555e69613dd292a476e Mon Sep 17 00:00:00 2001 From: Gaurav Ahuja Date: Mon, 23 Sep 2024 13:23:53 +0530 Subject: [PATCH 21/74] Fix multi block tests --- .../zktracer}/ExampleMultiBlockTest.java | 6 +- .../linea/zktracer}/ExampleTxTest.java | 6 +- .../MultiBlockExecutionEnvironment.java | 103 +++++++++++++++++- 3 files changed, 110 insertions(+), 5 deletions(-) rename {testing/src/test/java/net/consensys/linea/testing => arithmetization/src/test/java/net/consensys/linea/zktracer}/ExampleMultiBlockTest.java (96%) rename {testing/src/test/java/net/consensys/linea/testing => arithmetization/src/test/java/net/consensys/linea/zktracer}/ExampleTxTest.java (89%) diff --git a/testing/src/test/java/net/consensys/linea/testing/ExampleMultiBlockTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java similarity index 96% rename from testing/src/test/java/net/consensys/linea/testing/ExampleMultiBlockTest.java rename to arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java index 0dc94328a4..8cfbfff9e9 100644 --- a/testing/src/test/java/net/consensys/linea/testing/ExampleMultiBlockTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java @@ -13,10 +13,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.testing; +package net.consensys.linea.zktracer; import java.util.List; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.MultiBlockExecutionEnvironment; +import net.consensys.linea.testing.ToyAccount; +import net.consensys.linea.testing.ToyTransaction; import net.consensys.linea.zktracer.opcode.OpCode; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.crypto.KeyPair; diff --git a/testing/src/test/java/net/consensys/linea/testing/ExampleTxTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleTxTest.java similarity index 89% rename from testing/src/test/java/net/consensys/linea/testing/ExampleTxTest.java rename to arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleTxTest.java index 9d67361098..3a84887d4d 100644 --- a/testing/src/test/java/net/consensys/linea/testing/ExampleTxTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleTxTest.java @@ -13,10 +13,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.testing; +package net.consensys.linea.zktracer; import java.util.List; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.ToyAccount; +import net.consensys.linea.testing.ToyExecutionEnvironmentV2; +import net.consensys.linea.testing.ToyTransaction; import net.consensys.linea.zktracer.opcode.OpCode; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.SECP256K1; diff --git a/testing/src/main/java/net/consensys/linea/testing/MultiBlockExecutionEnvironment.java b/testing/src/main/java/net/consensys/linea/testing/MultiBlockExecutionEnvironment.java index 650a3e645b..2c165bb73f 100644 --- a/testing/src/main/java/net/consensys/linea/testing/MultiBlockExecutionEnvironment.java +++ b/testing/src/main/java/net/consensys/linea/testing/MultiBlockExecutionEnvironment.java @@ -15,8 +15,10 @@ package net.consensys.linea.testing; +import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Optional; @@ -24,16 +26,36 @@ import lombok.Singular; import lombok.extern.slf4j.Slf4j; import net.consensys.linea.blockcapture.snapshots.*; +import net.consensys.linea.corset.CorsetValidator; +import net.consensys.linea.zktracer.ConflationAwareOperationTracer; +import net.consensys.linea.zktracer.ZkTracer; +import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.units.bigints.UInt256; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.*; +import org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor; +import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; +import org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState; +import org.hyperledger.besu.evm.account.MutableAccount; +import org.hyperledger.besu.evm.internal.EvmConfiguration; +import org.hyperledger.besu.evm.internal.Words; +import org.hyperledger.besu.evm.operation.BlockHashOperation; +import org.hyperledger.besu.evm.tracing.OperationTracer; +import org.hyperledger.besu.evm.worldstate.WorldUpdater; @Builder @Slf4j public class MultiBlockExecutionEnvironment { + private static final CorsetValidator CORSET_VALIDATOR = new CorsetValidator(); + @Singular("addAccount") private final List accounts; private final List blocks; + private final ZkTracer tracer = new ZkTracer(); + public static class MultiBlockExecutionEnvironmentBuilder { private List blocks = new ArrayList<>(); @@ -53,9 +75,8 @@ public MultiBlockExecutionEnvironmentBuilder addBlock(List transact } public void run() { - ReplayExecutionEnvironment.builder() - .build() - .replay(ToyExecutionEnvironmentV2.CHAIN_ID, this.buildConflationSnapshot()); + this.executeFrom(ToyExecutionEnvironmentV2.CHAIN_ID, this.buildConflationSnapshot()); + ExecutionEnvironment.checkTracer(tracer, CORSET_VALIDATOR, Optional.of(log)); } private ConflationSnapshot buildConflationSnapshot() { @@ -95,4 +116,80 @@ private ConflationSnapshot buildConflationSnapshot() { return new ConflationSnapshot( this.blocks, accountSnapshots, storageSnapshots, blockHashSnapshots); } + + private void executeFrom(final BigInteger chainId, final ConflationSnapshot conflation) { + BlockHashOperation.BlockHashLookup blockHashLookup = conflation.toBlockHashLookup(); + ReferenceTestWorldState world = + ReferenceTestWorldState.create(new HashMap<>(), EvmConfiguration.DEFAULT); + // Initialise world state from conflation + initWorld(world.updater(), conflation); + // Construct the transaction processor + final MainnetTransactionProcessor transactionProcessor = + ExecutionEnvironment.getProtocolSpec(chainId).getTransactionProcessor(); + // Begin + tracer.traceStartConflation(conflation.blocks().size()); + // + for (BlockSnapshot blockSnapshot : conflation.blocks()) { + final BlockHeader header = blockSnapshot.header().toBlockHeader(); + + final BlockBody body = + new BlockBody( + blockSnapshot.txs().stream().map(TransactionSnapshot::toTransaction).toList(), + new ArrayList<>()); + tracer.traceStartBlock(header, body); + + for (TransactionSnapshot txs : blockSnapshot.txs()) { + final Transaction tx = txs.toTransaction(); + final WorldUpdater updater = world.updater(); + // Process transaction leading to expected outcome + final TransactionProcessingResult outcome = + transactionProcessor.processTransaction( + updater, + header, + tx, + header.getCoinbase(), + buildOperationTracer(tx, txs.getOutcome()), + blockHashLookup, + false, + Wei.ZERO); + // Commit transaction + updater.commit(); + } + tracer.traceEndBlock(header, body); + } + tracer.traceEndConflation(world.updater()); + } + + private OperationTracer buildOperationTracer(Transaction tx, TransactionResultSnapshot txs) { + if (txs == null) { + String hash = tx.getHash().toHexString(); + log.info("tx `{}` outcome not checked (missing)", hash); + return tracer; + } else { + return ConflationAwareOperationTracer.sequence(txs.check(), tracer); + } + } + + private static void initWorld(WorldUpdater world, final ConflationSnapshot conflation) { + WorldUpdater updater = world.updater(); + + for (AccountSnapshot account : conflation.accounts()) { + // Construct contract address + Address addr = Address.fromHexString(account.address()); + // Create account + MutableAccount acc = + world.createAccount( + Words.toAddress(addr), account.nonce(), Wei.fromHexString(account.balance())); + // Update code + acc.setCode(Bytes.fromHexString(account.code())); + } + // Initialise storage + for (StorageSnapshot s : conflation.storage()) { + world + .getAccount(Words.toAddress(Bytes.fromHexString(s.address()))) + .setStorageValue(UInt256.fromHexString(s.key()), UInt256.fromHexString(s.value())); + } + // + world.commit(); + } } From 77ffad9c588a08b255fd87ce0e5f9929707a5d68 Mon Sep 17 00:00:00 2001 From: arijitdutta67 Date: Tue, 24 Sep 2024 18:35:18 +0530 Subject: [PATCH 22/74] Adding simple multiblock account test --- .../linea/zktracer/module/hub/Hub.java | 62 ++++++++ .../module/hub/StateManagerAccountTest.java | 138 ++++++++++++++++++ 2 files changed, 200 insertions(+) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StateManagerAccountTest.java 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 d6366950fd..51ace91803 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 @@ -484,6 +484,8 @@ public void traceEndConflation(final WorldView world) { for (Module m : modules) { m.traceEndConflation(world); } + // Print all the account maps + printAccountMaps(); } @Override @@ -1430,4 +1432,64 @@ public void updateConflationMap() { } } } + + // Print all the account maps + public void printAccountMaps() { + // Print txnMaps + List txn = txStack.getTxs(); + for (var metadata : txn) { + Map> + txnMapAccount = metadata.getAccountFirstAndLastMap(); + for (Address addr : txnMapAccount.keySet()) { + var txnValue = txnMapAccount.get(addr); + System.out.println( + "txn level map: addr: " + + addr + + ": first dom: " + + txnValue.getFirstDom() + + ", first sub: " + + txnValue.getFirstSub() + + ": last dom: " + + txnValue.getLastDom() + + ", last sub: " + + txnValue.getLastSub()); + } + } + + // Print blockMaps + var blockMapAccount = Hub.stateManagerMetadata().getAccountFirstLastBlockMap(); + for (var addrBlockPair : blockMapAccount.keySet()) { + var blockValue = blockMapAccount.get(addrBlockPair); + System.out.println( + "block level map: addr: " + + addrBlockPair.getAddress() + + ": block: " + + addrBlockPair.getBlockNumber() + + ": first dom: " + + blockValue.getFirstDom() + + ", first sub: " + + blockValue.getFirstSub() + + ": last dom: " + + blockValue.getLastDom() + + ", last sub: " + + blockValue.getLastSub()); + } + + // Print conflationMaps + var conflationMapAccount = Hub.stateManagerMetadata().getAccountFirstLastConflationMap(); + for (var addr : conflationMapAccount.keySet()) { + var conflationValue = conflationMapAccount.get(addr); + System.out.println( + "conflation level map: addr: " + + addr + + ": first dom: " + + conflationValue.getFirstDom() + + ", first sub: " + + conflationValue.getFirstSub() + + ": last dom: " + + conflationValue.getLastDom() + + ", last sub: " + + conflationValue.getLastSub()); + } + } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StateManagerAccountTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StateManagerAccountTest.java new file mode 100644 index 0000000000..525edb1137 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StateManagerAccountTest.java @@ -0,0 +1,138 @@ +/* + * 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; + +import java.util.List; + +import net.consensys.linea.testing.MultiBlockExecutionEnvironment; +import net.consensys.linea.testing.ToyAccount; +import net.consensys.linea.testing.ToyTransaction; +import org.hyperledger.besu.crypto.KeyPair; +import org.hyperledger.besu.crypto.SECP256K1; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.core.Transaction; +import org.junit.jupiter.api.Test; + +public class StateManagerAccountTest { + + @Test + void test() { + final ToyAccount receiverAccount = + ToyAccount.builder() + .balance(Wei.fromEth(1)) + .nonce(116) + .address(Address.fromHexString("0xdead000000000000000000000000000beef")) + .build(); + + final KeyPair senderKeyPair1 = new SECP256K1().generateKeyPair(); + final Address senderAddress1 = + Address.extract(Hash.hash(senderKeyPair1.getPublicKey().getEncodedBytes())); + System.out.println("Sender address1: " + senderAddress1); + final ToyAccount senderAccount1 = + ToyAccount.builder().balance(Wei.fromEth(123)).nonce(5).address(senderAddress1).build(); + + final KeyPair senderKeyPair2 = new SECP256K1().generateKeyPair(); + final Address senderAddress2 = + Address.extract(Hash.hash(senderKeyPair2.getPublicKey().getEncodedBytes())); + System.out.println("Sender address2: " + senderAddress2); + final ToyAccount senderAccount2 = + ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress2).build(); + + final KeyPair senderKeyPair3 = new SECP256K1().generateKeyPair(); + final Address senderAddress3 = + Address.extract(Hash.hash(senderKeyPair3.getPublicKey().getEncodedBytes())); + System.out.println("Sender address3: " + senderAddress3); + final ToyAccount senderAccount3 = + ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress3).build(); + + final KeyPair senderKeyPair4 = new SECP256K1().generateKeyPair(); + final Address senderAddress4 = + Address.extract(Hash.hash(senderKeyPair4.getPublicKey().getEncodedBytes())); + System.out.println("Sender address4: " + senderAddress4); + final ToyAccount senderAccount4 = + ToyAccount.builder().balance(Wei.fromEth(11)).nonce(115).address(senderAddress4).build(); + + final KeyPair senderKeyPair5 = new SECP256K1().generateKeyPair(); + final Address senderAddress5 = + Address.extract(Hash.hash(senderKeyPair5.getPublicKey().getEncodedBytes())); + System.out.println("Sender address5: " + senderAddress5); + final ToyAccount senderAccount5 = + ToyAccount.builder().balance(Wei.fromEth(12)).nonce(0).address(senderAddress5).build(); + + final KeyPair senderKeyPair6 = new SECP256K1().generateKeyPair(); + final Address senderAddress6 = + Address.extract(Hash.hash(senderKeyPair6.getPublicKey().getEncodedBytes())); + System.out.println("Sender address6: " + senderAddress6); + final ToyAccount senderAccount6 = + ToyAccount.builder().balance(Wei.fromEth(12)).nonce(6).address(senderAddress6).build(); + + final KeyPair senderKeyPair7 = new SECP256K1().generateKeyPair(); + final Address senderAddress7 = + Address.extract(Hash.hash(senderKeyPair7.getPublicKey().getEncodedBytes())); + System.out.println("Sender address7: " + senderAddress7); + final ToyAccount senderAccount7 = + ToyAccount.builder().balance(Wei.fromEth(231)).nonce(21).address(senderAddress7).build(); + + final Transaction pureTransferSender1 = + ToyTransaction.builder() + .sender(senderAccount1) + .to(receiverAccount) + .keyPair(senderKeyPair1) + .value(Wei.of(123)) + .build(); + final Transaction pureTransferSender2 = + ToyTransaction.builder() + .sender(senderAccount2) + .to(receiverAccount) + .keyPair(senderKeyPair2) + .value(Wei.of(120)) + .build(); + final Transaction pureTransferSender3 = + ToyTransaction.builder() + .sender(senderAccount3) + .to(receiverAccount) + .keyPair(senderKeyPair3) + .value(Wei.of(110)) + .build(); + final Transaction pureTransferSender4 = + ToyTransaction.builder() + .sender(senderAccount4) + .to(receiverAccount) + .keyPair(senderKeyPair4) + .value(Wei.of(10)) + .build(); + + MultiBlockExecutionEnvironment.MultiBlockExecutionEnvironmentBuilder builder = + MultiBlockExecutionEnvironment.builder(); + builder + .accounts( + List.of( + senderAccount1, + senderAccount2, + senderAccount3, + senderAccount4, + senderAccount5, + senderAccount6, + senderAccount7, + receiverAccount)) + .addBlock(List.of(pureTransferSender1, pureTransferSender2)) + .addBlock(List.of(pureTransferSender3, pureTransferSender4)) + .build() + .run(); + } +} From 765ff278b38fa1f6980779944ace7ed6926fffb5 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 27 Sep 2024 12:28:10 +0200 Subject: [PATCH 23/74] Fixing conflation-level account maps Co-Authored-By: Arijit Dutta <37040536+arijitdutta67@users.noreply.github.com> --- .../linea/zktracer/module/hub/Hub.java | 100 +++++++++++------- .../hub/transients/StateManagerMetadata.java | 2 + 2 files changed, 61 insertions(+), 41 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 938ea7b5b7..b16ef3fbe1 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 @@ -1266,6 +1266,64 @@ public void updateConflationMap() { Map> conflationMapAccount = Hub.stateManagerMetadata().getAccountFirstLastConflationMap(); + List txn = txStack.getTxs(); + HashSet
allAccounts = new HashSet
(); + + Map< + StateManagerMetadata.AddrBlockPair, + TransactionProcessingMetadata.FragmentFirstAndLast> + blockMapAccount = Hub.stateManagerMetadata().getAccountFirstLastBlockMap(); + + for (TransactionProcessingMetadata metadata : txn) { + + Map> + txnMapAccount = metadata.getAccountFirstAndLastMap(); + + allAccounts.addAll(txnMapAccount.keySet()); + } + + for (Address addr : allAccounts) { + TransactionProcessingMetadata.FragmentFirstAndLast firstValue = null; + // Update the first value of the conflation map for Account + // We update the value of the conflation map with the earliest value of the block map + for (int i = 1; i <= transients.block().blockNumber(); i++) { + StateManagerMetadata.AddrBlockPair pairAddrBlock = + new StateManagerMetadata.AddrBlockPair(addr, i); + if (blockMapAccount.containsKey(pairAddrBlock)) { + firstValue = blockMapAccount.get(pairAddrBlock); + conflationMapAccount.put(addr, firstValue); + break; + } + } + // Update the last value of the conflation map + // We update the last value for the conflation map with the latest blockMap's last values, + // if some address is not present in the last block, we ignore the corresponding account + for (int i = transients.block().blockNumber(); i >= 1; i--) { + StateManagerMetadata.AddrBlockPair pairAddrBlock = + new StateManagerMetadata.AddrBlockPair(addr, i); + if (blockMapAccount.containsKey(pairAddrBlock)) { + TransactionProcessingMetadata.FragmentFirstAndLast blockValue = + blockMapAccount.get(pairAddrBlock); + + TransactionProcessingMetadata.FragmentFirstAndLast updatedValue = + new TransactionProcessingMetadata.FragmentFirstAndLast( + firstValue.getFirst(), + blockValue.getLast(), + firstValue.getFirstDom(), + firstValue.getFirstSub(), + blockValue.getLastDom(), + blockValue.getLastSub()); + conflationMapAccount.put(addr, updatedValue); + break; + } + } + } + } + + public void updateConflationMapStorage() { + Map> + conflationMapAccount = Hub.stateManagerMetadata().getAccountFirstLastConflationMap(); + Map< TransactionProcessingMetadata.AddrStorageKeyPair, TransactionProcessingMetadata.FragmentFirstAndLast> @@ -1292,46 +1350,6 @@ public void updateConflationMap() { TransactionProcessingMetadata.AddrStorageKeyPair, TransactionProcessingMetadata.FragmentFirstAndLast> txnMapStorage = metadata.getStorageFirstAndLastMap(); - for (Address addr : txnMapAccount.keySet()) { - // Update the first value of the conflation map for Account - // We update the value of the conflation map with the earliest value of the block map - for (int i = 0; i < transients.block().blockNumber(); i++) { - StateManagerMetadata.AddrBlockPair pairAddrBlock = - new StateManagerMetadata.AddrBlockPair(addr, i); - if (blockMapAccount.containsKey(pairAddrBlock)) { - TransactionProcessingMetadata.FragmentFirstAndLast blockValue = - blockMapAccount.get(pairAddrBlock); - TransactionProcessingMetadata.FragmentFirstAndLast conflationValue = - new TransactionProcessingMetadata.FragmentFirstAndLast( - blockValue.getFirst(), - null, - blockValue.getFirstDom(), - blockValue.getFirstSub(), - 0, - 0); - conflationMapAccount.put(addr, conflationValue); - break; - } - } - // Update the last value of the conflation map - // We update the last value for the conflation map with the latest blockMap's last values, - // if some address is not present in the last block, we ignore the corresponding account - StateManagerMetadata.AddrBlockPair pairAddrBlockLast = - new StateManagerMetadata.AddrBlockPair(addr, transients.block().blockNumber()); - if (blockMapAccount.containsKey(pairAddrBlockLast)) { - TransactionProcessingMetadata.FragmentFirstAndLast blockValueLast = - blockMapAccount.get(pairAddrBlockLast); - TransactionProcessingMetadata.FragmentFirstAndLast conflationValueLast = - new TransactionProcessingMetadata.FragmentFirstAndLast( - null, - blockValueLast.getLast(), - 0, - 0, - blockValueLast.getLastDom(), - blockValueLast.getLastSub()); - conflationMapAccount.put(addr, conflationValueLast); - } - } // Doing similar update for the storage map for (TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair : txnMapStorage.keySet()) { @@ -1424,7 +1442,7 @@ public void printAccountMaps() { // Print conflationMaps var conflationMapAccount = Hub.stateManagerMetadata().getAccountFirstLastConflationMap(); - for (var addr : conflationMapAccount.keySet()) { + for (Address addr : conflationMapAccount.keySet()) { var conflationValue = conflationMapAccount.get(addr); System.out.println( "conflation level map: addr: " diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java index 36c174b4d5..36c186a7c0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java @@ -18,6 +18,7 @@ import java.util.HashMap; import java.util.Map; +import lombok.EqualsAndHashCode; import lombok.Getter; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; @@ -25,6 +26,7 @@ import org.hyperledger.besu.datatypes.Address; public class StateManagerMetadata { + @EqualsAndHashCode public static class AddrBlockPair { @Getter private Address address; @Getter private int blockNumber; From deaffdce37afa4377209eb146b74208856e20ba8 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 27 Sep 2024 12:32:02 +0200 Subject: [PATCH 24/74] annotations Co-Authored-By: Arijit Dutta <37040536+arijitdutta67@users.noreply.github.com> --- .../zktracer/module/hub/transients/StateManagerMetadata.java | 1 + .../linea/zktracer/types/TransactionProcessingMetadata.java | 2 ++ 2 files changed, 3 insertions(+) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java index 36c186a7c0..bb9a8440a1 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java @@ -37,6 +37,7 @@ public AddrBlockPair(Address addr, int blockNumber) { } } + @EqualsAndHashCode public static class AddrStorageKeyBlockNumTuple { @Getter private TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair; @Getter private int blockNumber; 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 30408d4ce9..d78f778664 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 @@ -26,6 +26,7 @@ import java.util.Optional; import java.util.Set; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; @@ -152,6 +153,7 @@ public static boolean strictlySmallerStamps( } } + @EqualsAndHashCode public static class AddrStorageKeyPair { @Getter private Address address; @Getter private EWord storageKey; From 659dff2c4fcdc71a3e9129f0edec6a3c74b628f1 Mon Sep 17 00:00:00 2001 From: arijitdutta67 Date: Fri, 27 Sep 2024 19:26:50 +0530 Subject: [PATCH 25/74] Adding simple multiblock storage test --- .../linea/zktracer/module/hub/Hub.java | 170 ++++++++++++------ .../module/hub/StateManagerStorageTest.java | 162 +++++++++++++++++ 2 files changed, 274 insertions(+), 58 deletions(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StateManagerStorageTest.java 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 b16ef3fbe1..5d30a13430 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 @@ -479,13 +479,16 @@ public void traceEndConflation(final WorldView world) { txStack.setCodeFragmentIndex(this); defers.resolvePostConflation(this, world); // update the conflation level map for the state manager - updateConflationMap(); + updateConflationMapAccount(); + updateConflationMapStorage(); for (Module m : modules) { m.traceEndConflation(world); } // Print all the account maps printAccountMaps(); + // Print all the storage map + printStorageMaps(); } @Override @@ -1262,7 +1265,7 @@ public void updateBlockMap() { } // Update the conflation level map for the state manager - public void updateConflationMap() { + public void updateConflationMapAccount() { Map> conflationMapAccount = Hub.stateManagerMetadata().getAccountFirstLastConflationMap(); @@ -1321,78 +1324,61 @@ public void updateConflationMap() { } public void updateConflationMapStorage() { - Map> - conflationMapAccount = Hub.stateManagerMetadata().getAccountFirstLastConflationMap(); - Map< TransactionProcessingMetadata.AddrStorageKeyPair, TransactionProcessingMetadata.FragmentFirstAndLast> conflationMapStorage = Hub.stateManagerMetadata().getStorageFirstLastConflationMap(); List txn = txStack.getTxs(); - - Map< - StateManagerMetadata.AddrBlockPair, - TransactionProcessingMetadata.FragmentFirstAndLast> - blockMapAccount = Hub.stateManagerMetadata().getAccountFirstLastBlockMap(); - + HashSet allStorage = + new HashSet(); Map< StateManagerMetadata.AddrStorageKeyBlockNumTuple, TransactionProcessingMetadata.FragmentFirstAndLast> blockMapStorage = Hub.stateManagerMetadata().getStorageFirstLastBlockMap(); - for (TransactionProcessingMetadata metadata : txn) { - Map> - txnMapAccount = metadata.getAccountFirstAndLastMap(); - Map< TransactionProcessingMetadata.AddrStorageKeyPair, TransactionProcessingMetadata.FragmentFirstAndLast> txnMapStorage = metadata.getStorageFirstAndLastMap(); - // Doing similar update for the storage map - for (TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair : - txnMapStorage.keySet()) { - // Update the first value of the conflation map for Account - // We update the value of the conflation map with the earliest value of the block map - for (int i = 0; i < transients.block().blockNumber(); i++) { - StateManagerMetadata.AddrStorageKeyBlockNumTuple addrStorageBlockTuple = - new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, i); - if (blockMapStorage.containsKey(addrStorageBlockTuple)) { - TransactionProcessingMetadata.FragmentFirstAndLast blockValueStorage = - blockMapStorage.get(addrStorageBlockTuple); - TransactionProcessingMetadata.FragmentFirstAndLast - conflationValueStorage = - new TransactionProcessingMetadata.FragmentFirstAndLast( - blockValueStorage.getFirst(), - null, - blockValueStorage.getFirstDom(), - blockValueStorage.getFirstSub(), - 0, - 0); - conflationMapStorage.put(addrStorageKeyPair, conflationValueStorage); - break; - } + allStorage.addAll(txnMapStorage.keySet()); + } + + for (TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair : allStorage) { + TransactionProcessingMetadata.FragmentFirstAndLast firstValue = null; + // Update the first value of the conflation map for Storage + // We update the value of the conflation map with the earliest value of the block map + for (int i = 1; i <= transients.block().blockNumber(); i++) { + StateManagerMetadata.AddrStorageKeyBlockNumTuple addrStorageBlockTuple = + new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, i); + if (blockMapStorage.containsKey(addrStorageBlockTuple)) { + firstValue = blockMapStorage.get(addrStorageBlockTuple); + conflationMapStorage.put(addrStorageKeyPair, firstValue); + break; } - // Update the last value of the conflation map for storage - // We update the last value for the conflation map with the latest blockMap's last values, - // if some address is not present in the last block, we ignore the corresponding account - StateManagerMetadata.AddrStorageKeyBlockNumTuple addrStorageBlockTupleLast = - new StateManagerMetadata.AddrStorageKeyBlockNumTuple( - addrStorageKeyPair, transients.block().blockNumber()); - if (blockMapStorage.containsKey(addrStorageBlockTupleLast)) { - TransactionProcessingMetadata.FragmentFirstAndLast - blockValueStorageLast = blockMapStorage.get(addrStorageBlockTupleLast); - TransactionProcessingMetadata.FragmentFirstAndLast conflationValueLast = + } + // Update the last value of the conflation map + // We update the last value for the conflation map with the latest blockMap's last values, + // if some address is not present in the last block, we ignore the corresponding account + for (int i = transients.block().blockNumber(); i >= 1; i--) { + StateManagerMetadata.AddrStorageKeyBlockNumTuple addrStorageBlockTuple = + new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, i); + if (blockMapStorage.containsKey(addrStorageBlockTuple)) { + TransactionProcessingMetadata.FragmentFirstAndLast blockValue = + blockMapStorage.get(addrStorageBlockTuple); + + TransactionProcessingMetadata.FragmentFirstAndLast updatedValue = new TransactionProcessingMetadata.FragmentFirstAndLast( - null, - blockValueStorageLast.getLast(), - 0, - 0, - blockValueStorageLast.getLastDom(), - blockValueStorageLast.getLastSub()); - conflationMapStorage.put(addrStorageKeyPair, conflationValueLast); + firstValue.getFirst(), + blockValue.getLast(), + firstValue.getFirstDom(), + firstValue.getFirstSub(), + blockValue.getLastDom(), + blockValue.getLastSub()); + conflationMapStorage.put(addrStorageKeyPair, updatedValue); + break; } } } @@ -1408,7 +1394,7 @@ public void printAccountMaps() { for (Address addr : txnMapAccount.keySet()) { var txnValue = txnMapAccount.get(addr); System.out.println( - "txn level map: addr: " + "Account: txn level map: addr: " + addr + ": first dom: " + txnValue.getFirstDom() @@ -1426,7 +1412,7 @@ public void printAccountMaps() { for (var addrBlockPair : blockMapAccount.keySet()) { var blockValue = blockMapAccount.get(addrBlockPair); System.out.println( - "block level map: addr: " + "Account: block level map: addr: " + addrBlockPair.getAddress() + ": block: " + addrBlockPair.getBlockNumber() @@ -1445,7 +1431,7 @@ public void printAccountMaps() { for (Address addr : conflationMapAccount.keySet()) { var conflationValue = conflationMapAccount.get(addr); System.out.println( - "conflation level map: addr: " + "Account: conflation level map: addr: " + addr + ": first dom: " + conflationValue.getFirstDom() @@ -1457,4 +1443,72 @@ public void printAccountMaps() { + conflationValue.getLastSub()); } } + + // Print all the storage maps + public void printStorageMaps() { + // Print txnMaps + List txn = txStack.getTxs(); + for (var metadata : txn) { + Map< + TransactionProcessingMetadata.AddrStorageKeyPair, + TransactionProcessingMetadata.FragmentFirstAndLast> + txnMapStorage = metadata.getStorageFirstAndLastMap(); + for (TransactionProcessingMetadata.AddrStorageKeyPair addrKeyPair : txnMapStorage.keySet()) { + var txnValue = txnMapStorage.get(addrKeyPair); + System.out.println( + "Storage: txn level map: addr: " + + addrKeyPair.getAddress() + + ": storage key: " + + addrKeyPair.getStorageKey() + + ": first dom: " + + txnValue.getFirstDom() + + ", first sub: " + + txnValue.getFirstSub() + + ": last dom: " + + txnValue.getLastDom() + + ", last sub: " + + txnValue.getLastSub()); + } + } + + // Print blockMaps + var blockMapStorage = Hub.stateManagerMetadata().getStorageFirstLastBlockMap(); + for (var addrKeyBlockTuple : blockMapStorage.keySet()) { + var blockValue = blockMapStorage.get(addrKeyBlockTuple); + System.out.println( + "Storage: block level map: addr: " + + addrKeyBlockTuple.getAddrStorageKeyPair().getAddress() + + ": key: " + + addrKeyBlockTuple.getAddrStorageKeyPair().getStorageKey() + + ": block: " + + addrKeyBlockTuple.getBlockNumber() + + ": first dom: " + + blockValue.getFirstDom() + + ", first sub: " + + blockValue.getFirstSub() + + ": last dom: " + + blockValue.getLastDom() + + ", last sub: " + + blockValue.getLastSub()); + } + + // Print conflationMaps + var conflationMapStorage = Hub.stateManagerMetadata().getStorageFirstLastConflationMap(); + for (var addrKeyPair : conflationMapStorage.keySet()) { + var conflationValue = conflationMapStorage.get(addrKeyPair); + System.out.println( + "Storage: conflation level map: addr: " + + addrKeyPair.getAddress() + + ": storage key: " + + addrKeyPair.getStorageKey() + + ": first dom: " + + conflationValue.getFirstDom() + + ", first sub: " + + conflationValue.getFirstSub() + + ": last dom: " + + conflationValue.getLastDom() + + ", last sub: " + + conflationValue.getLastSub()); + } + } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StateManagerStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StateManagerStorageTest.java new file mode 100644 index 0000000000..cd249afd0c --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StateManagerStorageTest.java @@ -0,0 +1,162 @@ +/* + * 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; + +import java.util.List; + +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.MultiBlockExecutionEnvironment; +import net.consensys.linea.testing.ToyAccount; +import net.consensys.linea.testing.ToyTransaction; +import net.consensys.linea.zktracer.opcode.OpCode; +import org.apache.tuweni.bytes.Bytes32; +import org.hyperledger.besu.crypto.KeyPair; +import org.hyperledger.besu.crypto.SECP256K1; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.core.Transaction; +import org.junit.jupiter.api.Test; + +public class StateManagerStorageTest { + private final String keyString = + "0x00010203040060708090A0B0C0DE0F10101112131415161718191A1B1C1D1E1F"; + private final Bytes32 key = Bytes32.fromHexString(keyString); + private final Bytes32 value1 = Bytes32.repeat((byte) 1); + private final Bytes32 value2 = Bytes32.repeat((byte) 2); + private final Address receiverAddress = + Address.fromHexString("0x00000bad0000000000000000000000000000b077"); + final ToyAccount receiverAccount = + ToyAccount.builder() + .balance(Wei.fromEth(1)) + .address(receiverAddress) + .code( + BytecodeCompiler.newProgram() + // SLOAD initial value + .push(key) + .op(OpCode.SLOAD) + .op(OpCode.POP) + // SSTORE value 1 + .push(value1) + .push(key) + .op(OpCode.SSTORE) + // SSTORE value 2 + .push(value2) + .push(key) + .op(OpCode.SSTORE) + .compile()) + .nonce(116) + .build(); + + @Test + void test() { + + final KeyPair senderKeyPair1 = new SECP256K1().generateKeyPair(); + final Address senderAddress1 = + Address.extract(Hash.hash(senderKeyPair1.getPublicKey().getEncodedBytes())); + System.out.println("Sender address1: " + senderAddress1); + final ToyAccount senderAccount1 = + ToyAccount.builder().balance(Wei.fromEth(123)).nonce(5).address(senderAddress1).build(); + + final KeyPair senderKeyPair2 = new SECP256K1().generateKeyPair(); + final Address senderAddress2 = + Address.extract(Hash.hash(senderKeyPair2.getPublicKey().getEncodedBytes())); + System.out.println("Sender address2: " + senderAddress2); + final ToyAccount senderAccount2 = + ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress2).build(); + + final KeyPair senderKeyPair3 = new SECP256K1().generateKeyPair(); + final Address senderAddress3 = + Address.extract(Hash.hash(senderKeyPair3.getPublicKey().getEncodedBytes())); + System.out.println("Sender address3: " + senderAddress3); + final ToyAccount senderAccount3 = + ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress3).build(); + + final KeyPair senderKeyPair4 = new SECP256K1().generateKeyPair(); + final Address senderAddress4 = + Address.extract(Hash.hash(senderKeyPair4.getPublicKey().getEncodedBytes())); + System.out.println("Sender address4: " + senderAddress4); + final ToyAccount senderAccount4 = + ToyAccount.builder().balance(Wei.fromEth(11)).nonce(115).address(senderAddress4).build(); + + final KeyPair senderKeyPair5 = new SECP256K1().generateKeyPair(); + final Address senderAddress5 = + Address.extract(Hash.hash(senderKeyPair5.getPublicKey().getEncodedBytes())); + System.out.println("Sender address5: " + senderAddress5); + final ToyAccount senderAccount5 = + ToyAccount.builder().balance(Wei.fromEth(12)).nonce(0).address(senderAddress5).build(); + + final KeyPair senderKeyPair6 = new SECP256K1().generateKeyPair(); + final Address senderAddress6 = + Address.extract(Hash.hash(senderKeyPair6.getPublicKey().getEncodedBytes())); + System.out.println("Sender address6: " + senderAddress6); + final ToyAccount senderAccount6 = + ToyAccount.builder().balance(Wei.fromEth(12)).nonce(6).address(senderAddress6).build(); + + final KeyPair senderKeyPair7 = new SECP256K1().generateKeyPair(); + final Address senderAddress7 = + Address.extract(Hash.hash(senderKeyPair7.getPublicKey().getEncodedBytes())); + System.out.println("Sender address7: " + senderAddress7); + final ToyAccount senderAccount7 = + ToyAccount.builder().balance(Wei.fromEth(231)).nonce(21).address(senderAddress7).build(); + + final Transaction pureTransferSender1 = + ToyTransaction.builder() + .sender(senderAccount1) + .to(receiverAccount) + .keyPair(senderKeyPair1) + .value(Wei.of(123)) + .build(); + final Transaction pureTransferSender2 = + ToyTransaction.builder() + .sender(senderAccount2) + .to(receiverAccount) + .keyPair(senderKeyPair2) + .value(Wei.of(120)) + .build(); + final Transaction pureTransferSender3 = + ToyTransaction.builder() + .sender(senderAccount3) + .to(receiverAccount) + .keyPair(senderKeyPair3) + .value(Wei.of(110)) + .build(); + final Transaction pureTransferSender4 = + ToyTransaction.builder() + .sender(senderAccount4) + .to(receiverAccount) + .keyPair(senderKeyPair4) + .value(Wei.of(10)) + .build(); + + MultiBlockExecutionEnvironment.MultiBlockExecutionEnvironmentBuilder builder = + MultiBlockExecutionEnvironment.builder(); + builder + .accounts( + List.of( + senderAccount1, + senderAccount2, + senderAccount3, + senderAccount4, + senderAccount5, + senderAccount6, + senderAccount7, + receiverAccount)) + .addBlock(List.of(pureTransferSender1, pureTransferSender2)) + .addBlock(List.of(pureTransferSender3, pureTransferSender4)) + .build() + .run(); + } +} From bf596c05bdf95ada070199a1d6189745aeadbcbe Mon Sep 17 00:00:00 2001 From: arijitdutta67 Date: Tue, 1 Oct 2024 13:17:27 +0530 Subject: [PATCH 26/74] Adding storage test with warming of accounts --- .../module/hub/StateManagerStorageTest.java | 166 +++++++++++++----- 1 file changed, 120 insertions(+), 46 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StateManagerStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StateManagerStorageTest.java index cd249afd0c..e3728804eb 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StateManagerStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/StateManagerStorageTest.java @@ -24,18 +24,59 @@ import org.apache.tuweni.bytes.Bytes32; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.SECP256K1; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.datatypes.*; import org.hyperledger.besu.ethereum.core.Transaction; import org.junit.jupiter.api.Test; public class StateManagerStorageTest { + + final KeyPair senderKeyPair1 = new SECP256K1().generateKeyPair(); + final Address senderAddress1 = + Address.extract(Hash.hash(senderKeyPair1.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount1 = + ToyAccount.builder().balance(Wei.fromEth(123)).nonce(5).address(senderAddress1).build(); + + final KeyPair senderKeyPair2 = new SECP256K1().generateKeyPair(); + final Address senderAddress2 = + Address.extract(Hash.hash(senderKeyPair2.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount2 = + ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress2).build(); + + final KeyPair senderKeyPair3 = new SECP256K1().generateKeyPair(); + final Address senderAddress3 = + Address.extract(Hash.hash(senderKeyPair3.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount3 = + ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress3).build(); + + final KeyPair senderKeyPair4 = new SECP256K1().generateKeyPair(); + final Address senderAddress4 = + Address.extract(Hash.hash(senderKeyPair4.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount4 = + ToyAccount.builder().balance(Wei.fromEth(11)).nonce(115).address(senderAddress4).build(); + + final KeyPair senderKeyPair5 = new SECP256K1().generateKeyPair(); + final Address senderAddress5 = + Address.extract(Hash.hash(senderKeyPair5.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount5 = + ToyAccount.builder().balance(Wei.fromEth(12)).nonce(0).address(senderAddress5).build(); + + final KeyPair senderKeyPair6 = new SECP256K1().generateKeyPair(); + final Address senderAddress6 = + Address.extract(Hash.hash(senderKeyPair6.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount6 = + ToyAccount.builder().balance(Wei.fromEth(12)).nonce(6).address(senderAddress6).build(); + + final KeyPair senderKeyPair7 = new SECP256K1().generateKeyPair(); + final Address senderAddress7 = + Address.extract(Hash.hash(senderKeyPair7.getPublicKey().getEncodedBytes())); + final ToyAccount senderAccount7 = + ToyAccount.builder().balance(Wei.fromEth(231)).nonce(21).address(senderAddress7).build(); private final String keyString = "0x00010203040060708090A0B0C0DE0F10101112131415161718191A1B1C1D1E1F"; private final Bytes32 key = Bytes32.fromHexString(keyString); private final Bytes32 value1 = Bytes32.repeat((byte) 1); private final Bytes32 value2 = Bytes32.repeat((byte) 2); + private final Address receiverAddress = Address.fromHexString("0x00000bad0000000000000000000000000000b077"); final ToyAccount receiverAccount = @@ -59,59 +100,32 @@ public class StateManagerStorageTest { .compile()) .nonce(116) .build(); + final List simpleKey = List.of(keyString); + final List duplicateKey = List.of(keyString, keyString); + final List simpleKeyAndTrash = + List.of(keyString, "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); + + final List warmOnlyReceiver = + List.of(AccessListEntry.createAccessListEntry(receiverAddress, simpleKey)); + + final List stupidWarmer = + List.of( + AccessListEntry.createAccessListEntry(receiverAddress, duplicateKey), + AccessListEntry.createAccessListEntry(senderAddress4, simpleKeyAndTrash), + AccessListEntry.createAccessListEntry(senderAddress1, simpleKeyAndTrash), + AccessListEntry.createAccessListEntry(senderAddress3, simpleKey), + AccessListEntry.createAccessListEntry(senderAddress7, duplicateKey)); @Test - void test() { + void test_simple() { - final KeyPair senderKeyPair1 = new SECP256K1().generateKeyPair(); - final Address senderAddress1 = - Address.extract(Hash.hash(senderKeyPair1.getPublicKey().getEncodedBytes())); System.out.println("Sender address1: " + senderAddress1); - final ToyAccount senderAccount1 = - ToyAccount.builder().balance(Wei.fromEth(123)).nonce(5).address(senderAddress1).build(); - - final KeyPair senderKeyPair2 = new SECP256K1().generateKeyPair(); - final Address senderAddress2 = - Address.extract(Hash.hash(senderKeyPair2.getPublicKey().getEncodedBytes())); System.out.println("Sender address2: " + senderAddress2); - final ToyAccount senderAccount2 = - ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress2).build(); - - final KeyPair senderKeyPair3 = new SECP256K1().generateKeyPair(); - final Address senderAddress3 = - Address.extract(Hash.hash(senderKeyPair3.getPublicKey().getEncodedBytes())); System.out.println("Sender address3: " + senderAddress3); - final ToyAccount senderAccount3 = - ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress3).build(); - - final KeyPair senderKeyPair4 = new SECP256K1().generateKeyPair(); - final Address senderAddress4 = - Address.extract(Hash.hash(senderKeyPair4.getPublicKey().getEncodedBytes())); System.out.println("Sender address4: " + senderAddress4); - final ToyAccount senderAccount4 = - ToyAccount.builder().balance(Wei.fromEth(11)).nonce(115).address(senderAddress4).build(); - - final KeyPair senderKeyPair5 = new SECP256K1().generateKeyPair(); - final Address senderAddress5 = - Address.extract(Hash.hash(senderKeyPair5.getPublicKey().getEncodedBytes())); System.out.println("Sender address5: " + senderAddress5); - final ToyAccount senderAccount5 = - ToyAccount.builder().balance(Wei.fromEth(12)).nonce(0).address(senderAddress5).build(); - - final KeyPair senderKeyPair6 = new SECP256K1().generateKeyPair(); - final Address senderAddress6 = - Address.extract(Hash.hash(senderKeyPair6.getPublicKey().getEncodedBytes())); System.out.println("Sender address6: " + senderAddress6); - final ToyAccount senderAccount6 = - ToyAccount.builder().balance(Wei.fromEth(12)).nonce(6).address(senderAddress6).build(); - - final KeyPair senderKeyPair7 = new SECP256K1().generateKeyPair(); - final Address senderAddress7 = - Address.extract(Hash.hash(senderKeyPair7.getPublicKey().getEncodedBytes())); System.out.println("Sender address7: " + senderAddress7); - final ToyAccount senderAccount7 = - ToyAccount.builder().balance(Wei.fromEth(231)).nonce(21).address(senderAddress7).build(); - final Transaction pureTransferSender1 = ToyTransaction.builder() .sender(senderAccount1) @@ -159,4 +173,64 @@ void test() { .build() .run(); } + + @Test + void test_warming() { + System.out.println("Sender address1: " + senderAddress1); + System.out.println("Sender address2: " + senderAddress2); + System.out.println("Sender address3: " + senderAddress3); + System.out.println("Sender address4: " + senderAddress4); + System.out.println("Sender address5: " + senderAddress5); + System.out.println("Sender address6: " + senderAddress6); + System.out.println("Sender address7: " + senderAddress7); + final Transaction simpleWarm = + ToyTransaction.builder() + .sender(senderAccount1) + .to(receiverAccount) + .keyPair(senderKeyPair1) + .gasLimit(1000000L) + .transactionType(TransactionType.ACCESS_LIST) + .accessList(warmOnlyReceiver) + .value(Wei.of(50000)) + .build(); + + final Transaction stupidWarm = + ToyTransaction.builder() + .sender(senderAccount2) + .to(receiverAccount) + .keyPair(senderKeyPair2) + .gasLimit(1000000L) + .transactionType(TransactionType.ACCESS_LIST) + .accessList(stupidWarmer) + .value(Wei.of(50000)) + .build(); + + final Transaction noWarm = + ToyTransaction.builder() + .sender(senderAccount3) + .to(receiverAccount) + .keyPair(senderKeyPair3) + .gasLimit(1000000L) + .transactionType(TransactionType.ACCESS_LIST) + .accessList(List.of()) + .value(Wei.of(50000)) + .build(); + MultiBlockExecutionEnvironment.MultiBlockExecutionEnvironmentBuilder builder = + MultiBlockExecutionEnvironment.builder(); + builder + .accounts( + List.of( + senderAccount1, + senderAccount2, + senderAccount3, + senderAccount4, + senderAccount5, + senderAccount6, + senderAccount7, + receiverAccount)) + .addBlock(List.of(simpleWarm, noWarm)) + .addBlock(List.of(stupidWarm)) + .build() + .run(); + } } From a9382b50c4fafbde8c8ac2650a246b3cd8737f42 Mon Sep 17 00:00:00 2001 From: arijitdutta67 Date: Fri, 4 Oct 2024 16:57:14 +0530 Subject: [PATCH 27/74] Bug fix --- .../net/consensys/linea/zktracer/module/hub/Hub.java | 11 +++++------ .../linea/zktracer/module/hub/TransactionStack.java | 1 - .../zktracer/types/TransactionProcessingMetadata.java | 2 -- 3 files changed, 5 insertions(+), 9 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 ba82221e59..589f778bec 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 @@ -50,7 +50,6 @@ import net.consensys.linea.zktracer.module.hub.defer.DeferRegistry; import net.consensys.linea.zktracer.module.hub.fragment.ContextFragment; import net.consensys.linea.zktracer.module.hub.fragment.StackFragment; -import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.section.AccountSection; @@ -1158,7 +1157,7 @@ public void updateBlockMap() { TransactionProcessingMetadata.FragmentFirstAndLast> blockMapStorage = Hub.stateManagerMetadata().getStorageFirstLastBlockMap(); - List txn = txStack.getTxs(); + List txn = txStack.getTransactions(); for (TransactionProcessingMetadata metadata : txn) { if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) { @@ -1268,7 +1267,7 @@ public void updateConflationMapAccount() { Map> conflationMapAccount = Hub.stateManagerMetadata().getAccountFirstLastConflationMap(); - List txn = txStack.getTxs(); + List txn = txStack.getTransactions(); HashSet
allAccounts = new HashSet
(); Map< @@ -1328,7 +1327,7 @@ public void updateConflationMapStorage() { TransactionProcessingMetadata.FragmentFirstAndLast> conflationMapStorage = Hub.stateManagerMetadata().getStorageFirstLastConflationMap(); - List txn = txStack.getTxs(); + List txn = txStack.getTransactions(); HashSet allStorage = new HashSet(); Map< @@ -1386,7 +1385,7 @@ public void updateConflationMapStorage() { // Print all the account maps public void printAccountMaps() { // Print txnMaps - List txn = txStack.getTxs(); + List txn = txStack.getTransactions(); for (var metadata : txn) { Map> txnMapAccount = metadata.getAccountFirstAndLastMap(); @@ -1446,7 +1445,7 @@ public void printAccountMaps() { // Print all the storage maps public void printStorageMaps() { // Print txnMaps - List txn = txStack.getTxs(); + List txn = txStack.getTransactions(); for (var metadata : txn) { Map< TransactionProcessingMetadata.AddrStorageKeyPair, 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 437c267161..55b75c5d48 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 @@ -28,7 +28,6 @@ @Getter public class TransactionStack implements StackedContainer { @Getter - private final List txs = private final List transactions = new ArrayList<>(200); // TODO: write the allocated memory from .toml file 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 e8cc2df732..8418b7c0e0 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 @@ -33,7 +33,6 @@ import net.consensys.linea.zktracer.ZkTracer; import net.consensys.linea.zktracer.module.hub.AccountSnapshot; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.defer.PostTransactionDefer; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.section.halt.AttemptedSelfDestruct; @@ -233,7 +232,6 @@ public void updateStorageFirstAndLast(StorageFragment fragment, AddrStorageKeyPa } } - public TransactionProcessingMetadata( final WorldView world, final Transaction transaction, From 261fdc6dbb435530e3482a513df40c3d974710eb Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 11 Oct 2024 02:59:30 +0200 Subject: [PATCH 28/74] new multi-block test with solidity integration --- .../linea/zktracer/ExampleMultiBlockTest.java | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java index 8cfbfff9e9..fd8d65a513 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java @@ -32,6 +32,29 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; import org.junit.jupiter.api.Test; +import net.consensys.linea.testing.SolidityUtils; +import net.consensys.linea.testing.generated.FrameworkEntrypoint; +import net.consensys.linea.testing.generated.TestSnippet_Events; +import net.consensys.linea.testing.generated.TestStorage; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import java.math.BigInteger; +import java.util.Collections; +import java.util.List; +import java.util.function.Consumer; + +import org.web3j.abi.EventEncoder; +import org.web3j.abi.FunctionEncoder; +import org.web3j.abi.datatypes.DynamicArray; +import org.web3j.abi.datatypes.Function; +import org.web3j.abi.datatypes.generated.Uint256; + +import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; +import org.hyperledger.besu.evm.log.Log; class ExampleMultiBlockTest { @@ -193,4 +216,125 @@ void test2() { .build() .run(); } + + @Test + void testWithFrameworkEntrypoint() { + KeyPair keyPair = new SECP256K1().generateKeyPair(); + Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); + + ToyAccount senderAccount = + ToyAccount.builder().balance(Wei.fromEth(1000)).nonce(5).address(senderAddress).build(); + + ToyAccount frameworkEntrypointAccount = + ToyAccount.builder() + .address(Address.fromHexString("0x22222")) + .balance(Wei.of(1000)) + .nonce(6) + .code(SolidityUtils.getContractByteCode(FrameworkEntrypoint.class)) + .build(); + + ToyAccount snippetAccount = + ToyAccount.builder() + .address(Address.fromHexString("0x11111")) + .balance(Wei.of(1000)) + .nonce(7) + .code(SolidityUtils.getContractByteCode(TestSnippet_Events.class)) + .build(); + + Function snippetFunction = + new Function( + TestSnippet_Events.FUNC_EMITDATANOINDEXES, + List.of(new Uint256(BigInteger.valueOf(123456))), + Collections.emptyList()); + + Function snippetFunction2 = + new Function( + TestSnippet_Events.FUNC_EMITDATANOINDEXES, + List.of(new Uint256(BigInteger.valueOf(123456))), + Collections.emptyList()); + + + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ snippetAccount.getAddress().toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(FunctionEncoder.encode(snippetFunction)) + .toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ZERO); + + FrameworkEntrypoint.ContractCall snippetContractCall2 = + new FrameworkEntrypoint.ContractCall( + /*Address*/ snippetAccount.getAddress().toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(FunctionEncoder.encode(snippetFunction2)) + .toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ZERO); + + List contractCalls = List.of(snippetContractCall); + List contractCalls2 = List.of(snippetContractCall2); + + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Function frameworkEntryPointFunction2 = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls2)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + Transaction tx = + ToyTransaction.builder() + .sender(senderAccount) + .to(frameworkEntrypointAccount) + .payload(txPayload) + .keyPair(keyPair) + .build(); + + Bytes txPayload2 = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction2)); + + Transaction tx2 = + ToyTransaction.builder() + .sender(senderAccount) + .to(frameworkEntrypointAccount) + .payload(txPayload2) + .keyPair(keyPair) + .build(); + + Consumer resultValidator = + (TransactionProcessingResult result) -> { + // One event from the snippet + // One event from the framework entrypoint about contract call + assertEquals(result.getLogs().size(), 2); + for (Log log : result.getLogs()) { + String logTopic = log.getTopics().getFirst().toHexString(); + if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { + TestSnippet_Events.DataNoIndexesEventResponse response = + TestSnippet_Events.getDataNoIndexesEventFromLog(SolidityUtils.fromBesuLog(log)); + assertEquals(response.singleInt, BigInteger.valueOf(123456)); + } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) + .equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(SolidityUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + assertEquals(response.destination, snippetAccount.getAddress().toHexString()); + } else { + fail(); + } + } + }; + + MultiBlockExecutionEnvironment.builder() + .accounts(List.of(senderAccount, frameworkEntrypointAccount, snippetAccount)) + .addBlock(List.of(tx)) + .addBlock(List.of(tx2)) + .build() + .run(); + } } From 741d473d6db06ff6ff828f6ba16eff2990cc1104 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Mon, 14 Oct 2024 16:33:28 +0200 Subject: [PATCH 29/74] .yul functions and events, and calls from java --- .../linea/zktracer/ExampleSolidityTest.java | 193 +++++++++++++++++- testing/src/main/solidity/TestingBase.sol | 55 +++-- testing/src/main/solidity/YulContract.yul | 144 +++++++++++++ 3 files changed, 367 insertions(+), 25 deletions(-) create mode 100644 testing/src/main/solidity/YulContract.yul diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java index 301ad0fe37..ab6d7485fb 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java @@ -15,11 +15,8 @@ package net.consensys.linea.zktracer; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - import java.math.BigInteger; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.function.Consumer; @@ -43,10 +40,13 @@ import org.junit.jupiter.api.Test; import org.web3j.abi.EventEncoder; import org.web3j.abi.FunctionEncoder; +import org.web3j.abi.TypeReference; import org.web3j.abi.datatypes.DynamicArray; import org.web3j.abi.datatypes.Function; import org.web3j.abi.datatypes.generated.Uint256; +import static org.junit.jupiter.api.Assertions.*; + public class ExampleSolidityTest { @Test @@ -224,4 +224,189 @@ void testContractNotRelatedToTestingFramework() { .build() .run(); } + + @Test + void testYul() { + KeyPair senderkeyPair = new SECP256K1().generateKeyPair(); + Address senderAddress = + Address.extract(Hash.hash(senderkeyPair.getPublicKey().getEncodedBytes())); + + ToyAccount senderAccount = + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + + ToyAccount frameworkEntrypointAccount = + ToyAccount.builder() + .address(Address.fromHexString("0x22222")) + .balance(Wei.ONE) + .nonce(5) + .code(SolidityUtils.getContractByteCode(FrameworkEntrypoint.class)) + .build(); + + String dynamicBytecodeYul = + "6005605f565b63a770741d8114601e576397deb47b8114602857600080fd5b60246039565b6034565b60005460005260206000f35b506088565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b"; + + ToyAccount yulAccount = + ToyAccount.builder() + .address(Address.fromHexString("0x11111")) + .balance(Wei.ONE) + .nonce(6) + .code(Bytes.fromHexStringLenient(dynamicBytecodeYul)) + .build(); + + Function yulFunction = new Function("Write", Collections.emptyList(), Collections.emptyList()); + + String encodedContractCall = FunctionEncoder.encode(yulFunction); + + FrameworkEntrypoint.ContractCall yulContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ yulAccount.getAddress().toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encodedContractCall).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ZERO); + + List contractCalls = List.of(yulContractCall); + + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + Consumer resultValidator = + (TransactionProcessingResult result) -> { + assertFalse(result.getLogs().isEmpty()); + }; + + Transaction tx = + ToyTransaction.builder() + .sender(senderAccount) + .to(frameworkEntrypointAccount) + .payload(txPayload) + .keyPair(senderkeyPair) + .gasLimit(500000L) + .build(); + + ToyExecutionEnvironmentV2.builder() + .accounts(List.of(senderAccount, yulAccount)) + .transaction(tx) + .testValidator(resultValidator) + .build() + .run(); + } + + @Test + void testYulModifiedWrite() { + KeyPair keyPair = new SECP256K1().generateKeyPair(); + Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); + + ToyAccount senderAccount = + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + + ToyAccount frameworkEntrypointAccount = + ToyAccount.builder() + .address(Address.fromHexString("0x22222")) + .balance(Wei.ONE) + .nonce(5) + .code(SolidityUtils.getContractByteCode(FrameworkEntrypoint.class)) + .build(); + + String dynamicBytecodeYul = "0x610007610143565b63a770741d8114610038576397deb47b811461004557630dd2602c81146100515763d40e607a811461007257600080fd5b610040610091565b61008b565b60005460005260206000f35b6004356024356100618183610131565b61006b81836100b7565b505061008b565b60043561007e81610138565b61008881836100f4565b50505b5061016c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b8181555050565b600081549050919050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b"; + + ToyAccount yulAccount = + ToyAccount.builder() + .address(Address.fromHexString("0x11111")) + .balance(Wei.ONE) + .nonce(6) + .code(Bytes.fromHexStringLenient(dynamicBytecodeYul)) + .build(); + + + //org.web3j.abi.datatypes.Type + // ArrayList inputParams = new ArrayList<>(); + // var inputParams = List.of(new Uint256(BigInteger.valueOf(123456))); + + + List inputParams = new ArrayList<>(); + inputParams.addLast(new Uint256(BigInteger.valueOf(1))); + inputParams.addLast(new Uint256(BigInteger.valueOf(123456))); + Function yulFunction = new Function("writeToStorage", Collections.unmodifiableList(inputParams), Collections.emptyList()); + + //"0x0dd2602c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" + var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ yulAccount.getAddress().toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ZERO); + + List inputParams2 = new ArrayList<>(); + List> outputParams2 = new ArrayList<>(); + inputParams2.addLast(new Uint256(BigInteger.valueOf(1))); + Function yulFunction2 = new Function("readFromStorage", Collections.unmodifiableList(inputParams2), outputParams2); + + + var encoding2 = FunctionEncoder.encode(yulFunction2); + FrameworkEntrypoint.ContractCall snippetContractCall2 = + new FrameworkEntrypoint.ContractCall( + /*Address*/ yulAccount.getAddress().toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding2).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ZERO); + + List contractCalls = List.of(snippetContractCall, snippetContractCall2); + + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + Transaction tx = + ToyTransaction.builder() + .sender(senderAccount) + .to(frameworkEntrypointAccount) + .payload(txPayload) + .keyPair(keyPair) + .gasLimit(500000L) + .build(); + + Consumer resultValidator = + (TransactionProcessingResult result) -> { + // One event from the snippet + // One event from the framework entrypoint about contract call + //assertEquals(result.getLogs().size(), 1); + System.out.println("Number of logs: "+result.getLogs().size()); + var noTopics = result.getLogs().size(); + for (Log log : result.getLogs()) { + String logTopic = log.getTopics().getFirst().toHexString(); + String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); + String writeEventSignature = EventEncoder.encode(FrameworkEntrypoint.WRITE_EVENT); + String readEventSignature = EventEncoder.encode(FrameworkEntrypoint.READ_EVENT); + if (callEventSignature.equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(SolidityUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + assertEquals(response.destination, yulAccount.getAddress().toHexString()); + } else { + //fail(); + } + } + }; + + ToyExecutionEnvironmentV2.builder() + .accounts(List.of(senderAccount, frameworkEntrypointAccount, yulAccount)) + .transaction(tx) + .testValidator(resultValidator) + .build() + .run(); + System.out.println("Done"); + } } diff --git a/testing/src/main/solidity/TestingBase.sol b/testing/src/main/solidity/TestingBase.sol index 7068a45c57..6b3f60050c 100644 --- a/testing/src/main/solidity/TestingBase.sol +++ b/testing/src/main/solidity/TestingBase.sol @@ -24,6 +24,19 @@ abstract contract TestingBase { /// @param contractAddress The contract address. event ContractDestroyed(address contractAddress); + /// @dev The event for writing storage; + /// @param contractAddress is the contract addresss, x is the storage key and y is the storage value. + /// Event signature: 33d8dc4a860afa0606947f2b214f16e21e7eac41e3eb6642e859d9626d002ef6 + event Write(address contractAddress, uint256 x, uint256 y); + + /// @dev The event for reading storage; + /// @param contractAddress is the contract addresss, x is the storage key and y is the storage value. + /// the event will be generated after y is read as the value stored at x. + /// Event signature: c2db4694c1ec690e784f771a7fe3533681e081da4baa4aa1ad7dd5c33da95925 + event Read(address contractAddress, uint256 x, uint256 y); + + event EventReadFromStorage(address contractAddress, uint256 x); + /// @dev The Call types for external calls. /// @dev Default is delegate call (value==0), so be aware. enum CallType { @@ -106,11 +119,11 @@ abstract contract TestingBase { function getCallFunction( CallType _callType ) - internal - pure - returns ( - function(address, bytes memory, uint256, uint256) returns (bool) - ) + internal + pure + returns ( + function(address, bytes memory, uint256, uint256) returns (bool) + ) { if (_callType == CallType.DELEGATE_CALL) { return doDelegateCall; @@ -198,28 +211,28 @@ abstract contract TestingBase { /// @solidity memory-safe-assembly assembly { let n := mload(_data) // Let `l` be `n + 1`. +1 as we prefix a STOP opcode. - /** - * ---------------------------------------------------+ - * Opcode | Mnemonic | Stack | Memory | - * ---------------------------------------------------| - * 61 l | PUSH2 l | l | | - * 80 | DUP1 | l l | | - * 60 0xa | PUSH1 0xa | 0xa l l | | - * 3D | RETURNDATASIZE | 0 0xa l l | | - * 39 | CODECOPY | l | [0..l): code | - * 3D | RETURNDATASIZE | 0 l | [0..l): code | - * F3 | RETURN | | [0..l): code | - * 00 | STOP | | | - * ---------------------------------------------------+ - * @dev Prefix the bytecode with a STOP opcode to ensure it cannot be called. + /** + * ---------------------------------------------------+ + * Opcode | Mnemonic | Stack | Memory | + * ---------------------------------------------------| + * 61 l | PUSH2 l | l | | + * 80 | DUP1 | l l | | + * 60 0xa | PUSH1 0xa | 0xa l l | | + * 3D | RETURNDATASIZE | 0 0xa l l | | + * 39 | CODECOPY | l | [0..l): code | + * 3D | RETURNDATASIZE | 0 l | [0..l): code | + * F3 | RETURN | | [0..l): code | + * 00 | STOP | | | + * ---------------------------------------------------+ + * @dev Prefix the bytecode with a STOP opcode to ensure it cannot be called. * Also PUSH2 is used since max contract size cap is 24,576 bytes which is less than 2 ** 16. */ - // Do a out-of-gas revert if `n + 1` is more than 2 bytes. + // Do a out-of-gas revert if `n + 1` is more than 2 bytes. mstore( add(_data, gt(n, 0xfffe)), add(0xfe61000180600a3d393df300, shl(0x40, n)) ) - // Deploy a new contract with the generated creation code. + // Deploy a new contract with the generated creation code. pointer := create(0, add(_data, 0x15), add(n, 0xb)) if iszero(pointer) { mstore(0x00, 0x30116425) // `DeploymentFailed()`. diff --git a/testing/src/main/solidity/YulContract.yul b/testing/src/main/solidity/YulContract.yul new file mode 100644 index 0000000000..20113ae7ca --- /dev/null +++ b/testing/src/main/solidity/YulContract.yul @@ -0,0 +1,144 @@ +object "YulContract" { + code { + // return the bytecode of the contract + datacopy(0x00, dataoffset("runtime"), datasize("runtime")) + return(0x00, datasize("runtime")) + } + + object "runtime" { + code { + switch selector() + case 0xa770741d // Write() + { + write() + } + + case 0x97deb47b // Read() + { + // store the ID to memory at 0x00 + mstore(0x00, sload(0x00)) + + return (0x00,0x20) + } + + case 0x0dd2602c // writeToStorage() + { + // Load the first argument (x) from calldata + let x := calldataload(0x04) + + // Load the second argument (y) from calldata + let y := calldataload(0x24) + + // call the writeToStorage function + writeToStorage(x, y) + + // log the call + logValuesWrite(x, y) + } + + case 0xd40e607a // readFromStorage() + { + // Load the first argument (x) from calldata + let x := calldataload(0x04) + + // call the readFromStorage function + let y := readFromStorage(x) + + // log the call + logValuesRead(x, y) + } + + default { + // if the function signature sent does not match any + // of the contract functions, revert + revert(0, 0) + } + + function write() { + // take no inputs, push the 1234...EF 32 byte integer onto the stack + // add 0 as the slot key to the stack + // store the key/value + verbatim_0i_0o(hex"7f0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF600055") + } + + // Function to log two uint256 values for the write storage operation, along with the contract address + function logValuesWrite(x, y) { + // Define an event signature to generate logs for storage operations + let eventSignature := "Write(address,uint256,uint256)" //Hex for "Write(address,uint256,uint256)", signature length is 30 characters (thus 30 bytes) + + let memStart := mload(0x40) // get the free memory pointer + mstore(memStart, eventSignature) + + let eventSignatureHash := keccak256(memStart, 30) // expected 33d8dc4a860afa0606947f2b214f16e21e7eac41e3eb6642e859d9626d002ef6 + + // in the case of a delegate call, this will be the original that called the .Yul snippet. + // For a regular call, it will be the address of the .Yul contract. + let contractAddress := address() + + // call the inbuilt logging function + log4(0x20, 0x60, eventSignatureHash, contractAddress, x, y) + } + // Function to log two uint256 values for the read storage operation, along with the contract address + function logValuesRead(x, y) { + // Define an event signature to generate logs for storage operations + let eventSignatureHex := 0x5265616428616464726573732c75696e743235362c75696e7432353629202020 + // Above is the hex for "Read(address,uint256,uint256)", exact length is 29 characters, padded with 3 spaces (20 in hex) + // if we do not pad at the end, the hex is stored in the wrong manner. The spaces will be disregarded when we hash. + + let memStart := mload(0x40) // get the free memory pointer + mstore(memStart, eventSignatureHex) + + let eventSignatureHash := keccak256(memStart, 29) // 29 bytes is the string length, expected output c2db4694c1ec690e784f771a7fe3533681e081da4baa4aa1ad7dd5c33da95925 + + // in the case of a delegate call, this will be the original that called the .Yul snippet. + // For a regular call, it will be the address of the .Yul contract. + let contractAddress := address() + + // call the inbuilt logging function + log4(0x20, 0x60, eventSignatureHash, contractAddress, x, y) + } + + // 0x0dd2602cce131b717885742cf4e9a79978d80b588950101dc8619106202b5fd5 + // function signature: first 4 bytes 0x0dd2602c + // example of call: [["Addr",0x0dd2602c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001,0,0,0]] + // writeToStorage(uint256,uint256) is the unhashed function signature + function writeToStorage(x, y) { + // Use verbatim to include raw bytecode for storing y at storage key x + // 55 corresponds to SSTORE + verbatim_2i_0o(hex"55", x, y) + } + + // d40e607a2e462b02b78a86a129a210a71054c4774d1e5b71932b4e61bbd12df6 + // function signature: first 4 bytes 0xd40e607a + // example of call: [["Addr",0xd40e607a0000000000000000000000000000000000000000000000000000000000000001,0,0,0]] + // readFromStorage(uint256) is the unhashed function signature + function readFromStorage(x) -> y{ + // Use verbatim to include raw bytecode for reading the value stored at x + // 54 corresponds to SLOAD + y := verbatim_1i_1o(hex"54", x) + } + + // Return the function selector: the first 4 bytes of the call data + function selector() -> s { + s := div(calldataload(0), 0x100000000000000000000000000000000000000000000000000000000) + } + + // Implementation of the require statement from Solidity + function require(condition) { + if iszero(condition) { revert(0, 0) } + } + + // Check if the calldata has the correct number of params + function checkParamLength(len) { + require(eq(calldatasize(), add(4, mul(32, len)))) + } + + // Transfer ether to the caller address + function transfer(amount) { + if iszero(call(gas(), caller(), amount, 0, 0, 0, 0)) { + revert(0,0) + } + } + } + } +} \ No newline at end of file From 646e7186d18e0ac05a335daff9e9701034f3a5cf Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Tue, 15 Oct 2024 01:30:35 +0200 Subject: [PATCH 30/74] =?UTF-8?q?refactoring=E2=80=94prepping=20for=20test?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../linea/zktracer/ExampleSolidityTest.java | 100 +++++++++++------- 1 file changed, 62 insertions(+), 38 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java index ab6d7485fb..15bb29e68b 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java @@ -21,6 +21,8 @@ import java.util.List; import java.util.function.Consumer; +import lombok.Getter; +import lombok.NoArgsConstructor; import net.consensys.linea.testing.SolidityUtils; import net.consensys.linea.testing.ToyAccount; import net.consensys.linea.testing.ToyExecutionEnvironmentV2; @@ -297,37 +299,51 @@ void testYul() { .run(); } + @NoArgsConstructor + class TestContext { + static final int numberOfAccounts = 3; + @Getter + ToyAccount frameworkEntryPointAccount, yulSnippetsAccount; + ToyAccount[] initialAccounts; + KeyPair[] initialKeyPairs; + public void initializeTestContext() { + // initialize vectors + initialAccounts = new ToyAccount[numberOfAccounts]; + initialKeyPairs = new KeyPair[numberOfAccounts]; + // initialize the testing framework entry point account + frameworkEntryPointAccount = + ToyAccount.builder() + .address(Address.fromHexString("0x22222")) + .balance(Wei.ONE) + .nonce(5) + .code(SolidityUtils.getContractByteCode(FrameworkEntrypoint.class)) + .build(); + // initialize the .yul snippets account + // load the .yul bytecode + String dynamicBytecodeYul = "0x610007610143565b63a770741d8114610038576397deb47b811461004557630dd2602c81146100515763d40e607a811461007257600080fd5b610040610091565b61008b565b60005460005260206000f35b6004356024356100618183610131565b61006b81836100b7565b505061008b565b60043561007e81610138565b61008881836100f4565b50505b5061016c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b8181555050565b600081549050919050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b"; + yulSnippetsAccount = + ToyAccount.builder() + .address(Address.fromHexString("0x11111")) + .balance(Wei.ONE) + .nonce(6) + .code(Bytes.fromHexStringLenient(dynamicBytecodeYul)) + .build(); + // generate extra accounts + KeyPair keyPair = new SECP256K1().generateKeyPair(); + Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); + ToyAccount senderAccount = + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + // add to arrays + initialAccounts[0] = senderAccount; + initialKeyPairs[0] = keyPair; + } + } + @Test void testYulModifiedWrite() { - KeyPair keyPair = new SECP256K1().generateKeyPair(); - Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); - - ToyAccount senderAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); - - ToyAccount frameworkEntrypointAccount = - ToyAccount.builder() - .address(Address.fromHexString("0x22222")) - .balance(Wei.ONE) - .nonce(5) - .code(SolidityUtils.getContractByteCode(FrameworkEntrypoint.class)) - .build(); - - String dynamicBytecodeYul = "0x610007610143565b63a770741d8114610038576397deb47b811461004557630dd2602c81146100515763d40e607a811461007257600080fd5b610040610091565b61008b565b60005460005260206000f35b6004356024356100618183610131565b61006b81836100b7565b505061008b565b60043561007e81610138565b61008881836100f4565b50505b5061016c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b8181555050565b600081549050919050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b"; - - ToyAccount yulAccount = - ToyAccount.builder() - .address(Address.fromHexString("0x11111")) - .balance(Wei.ONE) - .nonce(6) - .code(Bytes.fromHexStringLenient(dynamicBytecodeYul)) - .build(); - - - //org.web3j.abi.datatypes.Type - // ArrayList inputParams = new ArrayList<>(); - // var inputParams = List.of(new Uint256(BigInteger.valueOf(123456))); - + // initialize the test context + TestContext context = new TestContext(); + context.initializeTestContext(); List inputParams = new ArrayList<>(); inputParams.addLast(new Uint256(BigInteger.valueOf(1))); @@ -338,7 +354,7 @@ void testYulModifiedWrite() { var encoding = FunctionEncoder.encode(yulFunction); FrameworkEntrypoint.ContractCall snippetContractCall = new FrameworkEntrypoint.ContractCall( - /*Address*/ yulAccount.getAddress().toHexString(), + /*Address*/ context.getYulSnippetsAccount().getAddress().toHexString(), /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), /*gasLimit*/ BigInteger.ZERO, /*value*/ BigInteger.ZERO, @@ -353,7 +369,7 @@ void testYulModifiedWrite() { var encoding2 = FunctionEncoder.encode(yulFunction2); FrameworkEntrypoint.ContractCall snippetContractCall2 = new FrameworkEntrypoint.ContractCall( - /*Address*/ yulAccount.getAddress().toHexString(), + /*Address*/ context.getYulSnippetsAccount().getAddress().toHexString(), /*calldata*/ Bytes.fromHexStringLenient(encoding2).toArray(), /*gasLimit*/ BigInteger.ZERO, /*value*/ BigInteger.ZERO, @@ -371,10 +387,10 @@ void testYulModifiedWrite() { Transaction tx = ToyTransaction.builder() - .sender(senderAccount) - .to(frameworkEntrypointAccount) + .sender(context.initialAccounts[0]) + .to(context.frameworkEntryPointAccount) .payload(txPayload) - .keyPair(keyPair) + .keyPair(context.initialKeyPairs[0]) .gasLimit(500000L) .build(); @@ -394,15 +410,23 @@ void testYulModifiedWrite() { FrameworkEntrypoint.CallExecutedEventResponse response = FrameworkEntrypoint.getCallExecutedEventFromLog(SolidityUtils.fromBesuLog(log)); assertTrue(response.isSuccess); - assertEquals(response.destination, yulAccount.getAddress().toHexString()); - } else { - //fail(); + assertEquals(response.destination, context.yulSnippetsAccount.getAddress().toHexString()); + continue; + } + if (writeEventSignature.equals(logTopic)) { + // write event + continue; + } + if (readEventSignature.equals(logTopic)) { + // read event + continue; } + fail(); } }; ToyExecutionEnvironmentV2.builder() - .accounts(List.of(senderAccount, frameworkEntrypointAccount, yulAccount)) + .accounts(List.of(context.initialAccounts[0], context.frameworkEntryPointAccount, context.yulSnippetsAccount)) .transaction(tx) .testValidator(resultValidator) .build() From 63158373f1d6a02f42b834543d7d7e4e54c739d7 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Tue, 15 Oct 2024 23:10:10 +0200 Subject: [PATCH 31/74] refactoring --- .../linea/zktracer/ExampleSolidityTest.java | 95 ++++++++++++------- 1 file changed, 60 insertions(+), 35 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java index 15bb29e68b..a6b9895c86 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java @@ -21,8 +21,10 @@ import java.util.List; import java.util.function.Consumer; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Singular; import net.consensys.linea.testing.SolidityUtils; import net.consensys.linea.testing.ToyAccount; import net.consensys.linea.testing.ToyExecutionEnvironmentV2; @@ -46,10 +48,12 @@ import org.web3j.abi.datatypes.DynamicArray; import org.web3j.abi.datatypes.Function; import org.web3j.abi.datatypes.generated.Uint256; +import org.web3j.tx.Contract; import static org.junit.jupiter.api.Assertions.*; public class ExampleSolidityTest { + TestContext testContext; @Test void testWithFrameworkEntrypoint() { @@ -299,8 +303,46 @@ void testYul() { .run(); } + + org. hyperledger. besu. ethereum. core. Transaction writeToStorage(ToyAccount sender, ToyAccount destination, Long key, Long value) { + List inputParams = new ArrayList<>(); + inputParams.addLast(new Uint256(BigInteger.valueOf(key))); + inputParams.addLast(new Uint256(BigInteger.valueOf(value))); + Function yulFunction = new Function("writeToStorage", Collections.unmodifiableList(inputParams), Collections.emptyList()); + + var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ this.testContext.getYulSnippetsAccount().getAddress().toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ZERO); + + List contractCalls = List.of(snippetContractCall); + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + Transaction tx = + ToyTransaction.builder() + .sender(this.testContext.initialAccounts[0]) + .to(this.testContext.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(this.testContext.initialKeyPairs[0]) + .gasLimit(TestContext.gasLimit) + .build(); + return tx; + } + + @NoArgsConstructor class TestContext { + static final Long gasLimit = 500000L; static final int numberOfAccounts = 3; @Getter ToyAccount frameworkEntryPointAccount, yulSnippetsAccount; @@ -339,26 +381,16 @@ public void initializeTestContext() { } } + + @Test void testYulModifiedWrite() { // initialize the test context - TestContext context = new TestContext(); - context.initializeTestContext(); + this.testContext = new TestContext(); + this.testContext.initializeTestContext(); + - List inputParams = new ArrayList<>(); - inputParams.addLast(new Uint256(BigInteger.valueOf(1))); - inputParams.addLast(new Uint256(BigInteger.valueOf(123456))); - Function yulFunction = new Function("writeToStorage", Collections.unmodifiableList(inputParams), Collections.emptyList()); - //"0x0dd2602c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" - var encoding = FunctionEncoder.encode(yulFunction); - FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ context.getYulSnippetsAccount().getAddress().toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ BigInteger.ZERO); List inputParams2 = new ArrayList<>(); List> outputParams2 = new ArrayList<>(); @@ -369,30 +401,22 @@ void testYulModifiedWrite() { var encoding2 = FunctionEncoder.encode(yulFunction2); FrameworkEntrypoint.ContractCall snippetContractCall2 = new FrameworkEntrypoint.ContractCall( - /*Address*/ context.getYulSnippetsAccount().getAddress().toHexString(), + /*Address*/ this.testContext.getYulSnippetsAccount().getAddress().toHexString(), /*calldata*/ Bytes.fromHexStringLenient(encoding2).toArray(), /*gasLimit*/ BigInteger.ZERO, /*value*/ BigInteger.ZERO, /*callType*/ BigInteger.ZERO); - List contractCalls = List.of(snippetContractCall, snippetContractCall2); + /* + ContractCalls contractCalls = ContractCalls.builder() + .call(snippetContractCall) + .call(snippetContractCall2) + .build(); + */ + List contractCalls = List.of(snippetContractCall2); + - Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); - Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - Transaction tx = - ToyTransaction.builder() - .sender(context.initialAccounts[0]) - .to(context.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(context.initialKeyPairs[0]) - .gasLimit(500000L) - .build(); Consumer resultValidator = (TransactionProcessingResult result) -> { @@ -410,7 +434,7 @@ void testYulModifiedWrite() { FrameworkEntrypoint.CallExecutedEventResponse response = FrameworkEntrypoint.getCallExecutedEventFromLog(SolidityUtils.fromBesuLog(log)); assertTrue(response.isSuccess); - assertEquals(response.destination, context.yulSnippetsAccount.getAddress().toHexString()); + assertEquals(response.destination, this.testContext.yulSnippetsAccount.getAddress().toHexString()); continue; } if (writeEventSignature.equals(logTopic)) { @@ -426,11 +450,12 @@ void testYulModifiedWrite() { }; ToyExecutionEnvironmentV2.builder() - .accounts(List.of(context.initialAccounts[0], context.frameworkEntryPointAccount, context.yulSnippetsAccount)) - .transaction(tx) + .accounts(List.of(this.testContext.initialAccounts[0], this.testContext.frameworkEntryPointAccount, this.testContext.yulSnippetsAccount)) + .transaction(writeToStorage(testContext.initialAccounts[0], testContext.initialAccounts[1], 123L, 1L)) .testValidator(resultValidator) .build() .run(); System.out.println("Done"); } } + From 690ba099d51a5c02788ed61dec6634a3280041f9 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Wed, 16 Oct 2024 00:58:10 +0200 Subject: [PATCH 32/74] refactor after merging from main --- .../linea/zktracer/ExampleMultiBlockTest.java | 14 +- .../linea/zktracer/ExampleSolidityTest.java | 341 +++++++++--------- .../zktracer/StateManagerSolidityTest.java | 205 +++++++++++ 3 files changed, 380 insertions(+), 180 deletions(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java index fd8d65a513..a786011186 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java @@ -17,10 +17,7 @@ import java.util.List; -import net.consensys.linea.testing.BytecodeCompiler; -import net.consensys.linea.testing.MultiBlockExecutionEnvironment; -import net.consensys.linea.testing.ToyAccount; -import net.consensys.linea.testing.ToyTransaction; +import net.consensys.linea.testing.*; import net.consensys.linea.zktracer.opcode.OpCode; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.crypto.KeyPair; @@ -32,7 +29,6 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; import org.junit.jupiter.api.Test; -import net.consensys.linea.testing.SolidityUtils; import net.consensys.linea.testing.generated.FrameworkEntrypoint; import net.consensys.linea.testing.generated.TestSnippet_Events; import net.consensys.linea.testing.generated.TestStorage; @@ -230,7 +226,7 @@ void testWithFrameworkEntrypoint() { .address(Address.fromHexString("0x22222")) .balance(Wei.of(1000)) .nonce(6) - .code(SolidityUtils.getContractByteCode(FrameworkEntrypoint.class)) + .code(SmartContractUtils.getSolidityContractByteCode(FrameworkEntrypoint.class)) .build(); ToyAccount snippetAccount = @@ -238,7 +234,7 @@ void testWithFrameworkEntrypoint() { .address(Address.fromHexString("0x11111")) .balance(Wei.of(1000)) .nonce(7) - .code(SolidityUtils.getContractByteCode(TestSnippet_Events.class)) + .code(SmartContractUtils.getSolidityContractByteCode(TestSnippet_Events.class)) .build(); Function snippetFunction = @@ -316,12 +312,12 @@ void testWithFrameworkEntrypoint() { String logTopic = log.getTopics().getFirst().toHexString(); if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { TestSnippet_Events.DataNoIndexesEventResponse response = - TestSnippet_Events.getDataNoIndexesEventFromLog(SolidityUtils.fromBesuLog(log)); + TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); assertEquals(response.singleInt, BigInteger.valueOf(123456)); } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) .equals(logTopic)) { FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(SolidityUtils.fromBesuLog(log)); + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); assertTrue(response.isSuccess); assertEquals(response.destination, snippetAccount.getAddress().toHexString()); } else { diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java index bf1b31a394..405c4c6945 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java @@ -15,11 +15,15 @@ package net.consensys.linea.zktracer; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + import java.math.BigInteger; -import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.function.Consumer; + import net.consensys.linea.testing.SmartContractUtils; import net.consensys.linea.testing.ToyAccount; import net.consensys.linea.testing.ToyExecutionEnvironmentV2; @@ -40,16 +44,11 @@ import org.junit.jupiter.api.Test; import org.web3j.abi.EventEncoder; import org.web3j.abi.FunctionEncoder; -import org.web3j.abi.TypeReference; import org.web3j.abi.datatypes.DynamicArray; import org.web3j.abi.datatypes.Function; import org.web3j.abi.datatypes.generated.Uint256; -import org.web3j.tx.Contract; - -import static org.junit.jupiter.api.Assertions.*; public class ExampleSolidityTest { - TestContext testContext; @Test void testWithFrameworkEntrypoint() { @@ -57,86 +56,86 @@ void testWithFrameworkEntrypoint() { Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); ToyAccount senderAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); ToyAccount frameworkEntrypointAccount = - ToyAccount.builder() - .address(Address.fromHexString("0x22222")) - .balance(Wei.ONE) - .nonce(5) - .code(SmartContractUtils.getSolidityContractByteCode(FrameworkEntrypoint.class)) - .build(); + ToyAccount.builder() + .address(Address.fromHexString("0x22222")) + .balance(Wei.ONE) + .nonce(5) + .code(SmartContractUtils.getSolidityContractByteCode(FrameworkEntrypoint.class)) + .build(); ToyAccount snippetAccount = - ToyAccount.builder() - .address(Address.fromHexString("0x11111")) - .balance(Wei.ONE) - .nonce(6) - .code(SmartContractUtils.getSolidityContractByteCode(TestSnippet_Events.class)) - .build(); + ToyAccount.builder() + .address(Address.fromHexString("0x11111")) + .balance(Wei.ONE) + .nonce(6) + .code(SmartContractUtils.getSolidityContractByteCode(TestSnippet_Events.class)) + .build(); Function snippetFunction = - new Function( - TestSnippet_Events.FUNC_EMITDATANOINDEXES, - List.of(new Uint256(BigInteger.valueOf(123456))), - Collections.emptyList()); + new Function( + TestSnippet_Events.FUNC_EMITDATANOINDEXES, + List.of(new Uint256(BigInteger.valueOf(123456))), + Collections.emptyList()); FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ snippetAccount.getAddress().toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(FunctionEncoder.encode(snippetFunction)) - .toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ BigInteger.ZERO); + new FrameworkEntrypoint.ContractCall( + /*Address*/ snippetAccount.getAddress().toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(FunctionEncoder.encode(snippetFunction)) + .toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ZERO); List contractCalls = List.of(snippetContractCall); Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); Transaction tx = - ToyTransaction.builder() - .sender(senderAccount) - .to(frameworkEntrypointAccount) - .payload(txPayload) - .keyPair(keyPair) - .build(); + ToyTransaction.builder() + .sender(senderAccount) + .to(frameworkEntrypointAccount) + .payload(txPayload) + .keyPair(keyPair) + .build(); Consumer resultValidator = - (TransactionProcessingResult result) -> { - // One event from the snippet - // One event from the framework entrypoint about contract call - assertEquals(result.getLogs().size(), 2); - for (Log log : result.getLogs()) { - String logTopic = log.getTopics().getFirst().toHexString(); - if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { - TestSnippet_Events.DataNoIndexesEventResponse response = - TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); - assertEquals(response.singleInt, BigInteger.valueOf(123456)); - } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) - .equals(logTopic)) { - FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - assertTrue(response.isSuccess); - assertEquals(response.destination, snippetAccount.getAddress().toHexString()); - } else { - fail(); - } - } - }; + (TransactionProcessingResult result) -> { + // One event from the snippet + // One event from the framework entrypoint about contract call + assertEquals(result.getLogs().size(), 2); + for (Log log : result.getLogs()) { + String logTopic = log.getTopics().getFirst().toHexString(); + if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { + TestSnippet_Events.DataNoIndexesEventResponse response = + TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); + assertEquals(response.singleInt, BigInteger.valueOf(123456)); + } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) + .equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + assertEquals(response.destination, snippetAccount.getAddress().toHexString()); + } else { + fail(); + } + } + }; ToyExecutionEnvironmentV2.builder() - .accounts(List.of(senderAccount, frameworkEntrypointAccount, snippetAccount)) - .transaction(tx) - .testValidator(resultValidator) - .build() - .run(); + .accounts(List.of(senderAccount, frameworkEntrypointAccount, snippetAccount)) + .transaction(tx) + .testValidator(resultValidator) + .build() + .run(); } @Test @@ -145,165 +144,165 @@ void testSnippetIndependently() { Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); ToyAccount senderAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); ToyAccount contractAccount = - ToyAccount.builder() - .address(Address.fromHexString("0x11111")) - .balance(Wei.ONE) - .nonce(6) - .code(SmartContractUtils.getSolidityContractByteCode(TestSnippet_Events.class)) - .build(); + ToyAccount.builder() + .address(Address.fromHexString("0x11111")) + .balance(Wei.ONE) + .nonce(6) + .code(SmartContractUtils.getSolidityContractByteCode(TestSnippet_Events.class)) + .build(); Function function = - new Function( - TestSnippet_Events.FUNC_EMITDATANOINDEXES, - List.of(new Uint256(BigInteger.valueOf(123456))), - Collections.emptyList()); + new Function( + TestSnippet_Events.FUNC_EMITDATANOINDEXES, + List.of(new Uint256(BigInteger.valueOf(123456))), + Collections.emptyList()); String encodedFunction = FunctionEncoder.encode(function); Bytes txPayload = Bytes.fromHexStringLenient(encodedFunction); Transaction tx = - ToyTransaction.builder() - .sender(senderAccount) - .to(contractAccount) - .payload(txPayload) - .keyPair(keyPair) - .build(); + ToyTransaction.builder() + .sender(senderAccount) + .to(contractAccount) + .payload(txPayload) + .keyPair(keyPair) + .build(); Consumer resultValidator = - (TransactionProcessingResult result) -> { - assertEquals(result.getLogs().size(), 1); - TestSnippet_Events.DataNoIndexesEventResponse response = - TestSnippet_Events.getDataNoIndexesEventFromLog( - Web3jUtils.fromBesuLog(result.getLogs().getFirst())); - assertEquals(response.singleInt, BigInteger.valueOf(123456)); - }; + (TransactionProcessingResult result) -> { + assertEquals(result.getLogs().size(), 1); + TestSnippet_Events.DataNoIndexesEventResponse response = + TestSnippet_Events.getDataNoIndexesEventFromLog( + Web3jUtils.fromBesuLog(result.getLogs().getFirst())); + assertEquals(response.singleInt, BigInteger.valueOf(123456)); + }; ToyExecutionEnvironmentV2.builder() - .accounts(List.of(senderAccount, contractAccount)) - .transaction(tx) - .testValidator(resultValidator) - .build() - .run(); + .accounts(List.of(senderAccount, contractAccount)) + .transaction(tx) + .testValidator(resultValidator) + .build() + .run(); } @Test void testContractNotRelatedToTestingFramework() { KeyPair senderkeyPair = new SECP256K1().generateKeyPair(); Address senderAddress = - Address.extract(Hash.hash(senderkeyPair.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderkeyPair.getPublicKey().getEncodedBytes())); ToyAccount senderAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); ToyAccount contractAccount = - ToyAccount.builder() - .address(Address.fromHexString("0x11111")) - .balance(Wei.ONE) - .nonce(6) - .code(SmartContractUtils.getSolidityContractByteCode(TestStorage.class)) - .build(); + ToyAccount.builder() + .address(Address.fromHexString("0x11111")) + .balance(Wei.ONE) + .nonce(6) + .code(SmartContractUtils.getSolidityContractByteCode(TestStorage.class)) + .build(); Function function = - new Function( - TestStorage.FUNC_STORE, - List.of(new Uint256(BigInteger.valueOf(3))), - Collections.emptyList()); + new Function( + TestStorage.FUNC_STORE, + List.of(new Uint256(BigInteger.valueOf(3))), + Collections.emptyList()); String encodedFunction = FunctionEncoder.encode(function); Bytes txPayload = Bytes.fromHexStringLenient(encodedFunction); Transaction tx = - ToyTransaction.builder() - .sender(senderAccount) - .to(contractAccount) - .payload(txPayload) - .keyPair(senderkeyPair) - .build(); + ToyTransaction.builder() + .sender(senderAccount) + .to(contractAccount) + .payload(txPayload) + .keyPair(senderkeyPair) + .build(); ToyExecutionEnvironmentV2.builder() - .accounts(List.of(senderAccount, contractAccount)) - .transaction(tx) - .build() - .run(); + .accounts(List.of(senderAccount, contractAccount)) + .transaction(tx) + .build() + .run(); } @Test void testYul() { KeyPair senderkeyPair = new SECP256K1().generateKeyPair(); Address senderAddress = - Address.extract(Hash.hash(senderkeyPair.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderkeyPair.getPublicKey().getEncodedBytes())); ToyAccount senderAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); ToyAccount frameworkEntrypointAccount = - ToyAccount.builder() - .address(Address.fromHexString("0x22222")) - .balance(Wei.ONE) - .nonce(5) - .code(SmartContractUtils.getSolidityContractByteCode(FrameworkEntrypoint.class)) - .build(); + ToyAccount.builder() + .address(Address.fromHexString("0x22222")) + .balance(Wei.ONE) + .nonce(5) + .code(SmartContractUtils.getSolidityContractByteCode(FrameworkEntrypoint.class)) + .build(); + ToyAccount yulAccount = - ToyAccount.builder() - .address(Address.fromHexString("0x11111")) - .balance(Wei.ONE) - .nonce(6) - .code(SmartContractUtils.getYulContractByteCode("DynamicBytecode.yul")) - .build(); + ToyAccount.builder() + .address(Address.fromHexString("0x11111")) + .balance(Wei.ONE) + .nonce(6) + .code(SmartContractUtils.getYulContractByteCode("DynamicBytecode.yul")) + .build(); Function yulFunction = new Function("Write", Collections.emptyList(), Collections.emptyList()); String encodedContractCall = FunctionEncoder.encode(yulFunction); FrameworkEntrypoint.ContractCall yulContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ yulAccount.getAddress().toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encodedContractCall).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ BigInteger.ZERO); + new FrameworkEntrypoint.ContractCall( + /*Address*/ yulAccount.getAddress().toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encodedContractCall).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ZERO); List contractCalls = List.of(yulContractCall); Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); Consumer resultValidator = - (TransactionProcessingResult result) -> { - assertEquals(result.getLogs().size(), 1); - for (Log log : result.getLogs()) { - String logTopic = log.getTopics().getFirst().toHexString(); - if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT).equals(logTopic)) { - FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - assertTrue(response.isSuccess); - assertEquals(response.destination, yulAccount.getAddress().toHexString()); - } else { - fail(); - } - } - }; + (TransactionProcessingResult result) -> { + assertEquals(result.getLogs().size(), 1); + for (Log log : result.getLogs()) { + String logTopic = log.getTopics().getFirst().toHexString(); + if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT).equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + assertEquals(response.destination, yulAccount.getAddress().toHexString()); + } else { + fail(); + } + } + }; Transaction tx = - ToyTransaction.builder() - .sender(senderAccount) - .to(frameworkEntrypointAccount) - .payload(txPayload) - .keyPair(senderkeyPair) - .gasLimit(500000L) - .build(); + ToyTransaction.builder() + .sender(senderAccount) + .to(frameworkEntrypointAccount) + .payload(txPayload) + .keyPair(senderkeyPair) + .gasLimit(500000L) + .build(); ToyExecutionEnvironmentV2.builder() - .accounts(List.of(senderAccount, yulAccount, frameworkEntrypointAccount)) - .transaction(tx) - .testValidator(resultValidator) - .build() - .run(); + .accounts(List.of(senderAccount, yulAccount, frameworkEntrypointAccount)) + .transaction(tx) + .testValidator(resultValidator) + .build() + .run(); } -} - +} \ No newline at end of file diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java new file mode 100644 index 0000000000..53a3acc511 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -0,0 +1,205 @@ +/* + * Copyright Consensys Software 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; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import net.consensys.linea.testing.*; +import net.consensys.linea.testing.generated.FrameworkEntrypoint; +import net.consensys.linea.testing.generated.TestSnippet_Events; +import net.consensys.linea.testing.generated.TestStorage; +import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.crypto.KeyPair; +import org.hyperledger.besu.crypto.SECP256K1; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; +import org.hyperledger.besu.evm.log.Log; +import org.junit.jupiter.api.Test; +import org.web3j.abi.EventEncoder; +import org.web3j.abi.FunctionEncoder; +import org.web3j.abi.TypeReference; +import org.web3j.abi.datatypes.DynamicArray; +import org.web3j.abi.datatypes.Function; +import org.web3j.abi.datatypes.generated.Uint256; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.function.Consumer; + +import static org.junit.jupiter.api.Assertions.*; + +public class StateManagerSolidityTest { + TestContext testContext; + Transaction writeToStorage(ToyAccount sender, ToyAccount destination, Long key, Long value) { + List inputParams = new ArrayList<>(); + inputParams.addLast(new Uint256(BigInteger.valueOf(key))); + inputParams.addLast(new Uint256(BigInteger.valueOf(value))); + Function yulFunction = new Function("writeToStorage", Collections.unmodifiableList(inputParams), Collections.emptyList()); + + var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ this.testContext.getYulSnippetsAccount().getAddress().toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ZERO); + + List contractCalls = List.of(snippetContractCall); + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + Transaction tx = + ToyTransaction.builder() + .sender(this.testContext.initialAccounts[0]) + .to(this.testContext.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(this.testContext.initialKeyPairs[0]) + .gasLimit(TestContext.gasLimit) + .build(); + return tx; + } + + + @NoArgsConstructor + class TestContext { + static final Long gasLimit = 500000L; + static final int numberOfAccounts = 3; + @Getter + ToyAccount frameworkEntryPointAccount, yulSnippetsAccount; + ToyAccount[] initialAccounts; + KeyPair[] initialKeyPairs; + public void initializeTestContext() { + // initialize vectors + initialAccounts = new ToyAccount[numberOfAccounts]; + initialKeyPairs = new KeyPair[numberOfAccounts]; + // initialize the testing framework entry point account + frameworkEntryPointAccount = + ToyAccount.builder() + .address(Address.fromHexString("0x22222")) + .balance(Wei.ONE) + .nonce(5) + .code(SmartContractUtils.getSolidityContractByteCode(FrameworkEntrypoint.class)) + .build(); + // initialize the .yul snippets account + // load the .yul bytecode + String dynamicBytecodeYul = "0x610007610143565b63a770741d8114610038576397deb47b811461004557630dd2602c81146100515763d40e607a811461007257600080fd5b610040610091565b61008b565b60005460005260206000f35b6004356024356100618183610131565b61006b81836100b7565b505061008b565b60043561007e81610138565b61008881836100f4565b50505b5061016c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b8181555050565b600081549050919050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b"; + yulSnippetsAccount = + ToyAccount.builder() + .address(Address.fromHexString("0x11111")) + .balance(Wei.ONE) + .nonce(6) + .code(Bytes.fromHexStringLenient(dynamicBytecodeYul)) + .build(); + // generate extra accounts + KeyPair keyPair = new SECP256K1().generateKeyPair(); + Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); + ToyAccount senderAccount = + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + // add to arrays + initialAccounts[0] = senderAccount; + initialKeyPairs[0] = keyPair; + } + } + + + + @Test + void testYulModifiedWrite() { + // initialize the test context + this.testContext = new TestContext(); + this.testContext.initializeTestContext(); + + + + + List inputParams2 = new ArrayList<>(); + List> outputParams2 = new ArrayList<>(); + inputParams2.addLast(new Uint256(BigInteger.valueOf(1))); + Function yulFunction2 = new Function("readFromStorage", Collections.unmodifiableList(inputParams2), outputParams2); + + + var encoding2 = FunctionEncoder.encode(yulFunction2); + FrameworkEntrypoint.ContractCall snippetContractCall2 = + new FrameworkEntrypoint.ContractCall( + /*Address*/ this.testContext.getYulSnippetsAccount().getAddress().toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding2).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ZERO); + + /* + ContractCalls contractCalls = ContractCalls.builder() + .call(snippetContractCall) + .call(snippetContractCall2) + .build(); + */ + List contractCalls = List.of(snippetContractCall2); + + + + + Consumer resultValidator = + (TransactionProcessingResult result) -> { + // One event from the snippet + // One event from the framework entrypoint about contract call + //assertEquals(result.getLogs().size(), 1); + System.out.println("Number of logs: "+result.getLogs().size()); + var noTopics = result.getLogs().size(); + for (Log log : result.getLogs()) { + String logTopic = log.getTopics().getFirst().toHexString(); + String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); + String writeEventSignature = EventEncoder.encode(FrameworkEntrypoint.WRITE_EVENT); + String readEventSignature = EventEncoder.encode(FrameworkEntrypoint.READ_EVENT); + if (callEventSignature.equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + assertEquals(response.destination, this.testContext.yulSnippetsAccount.getAddress().toHexString()); + continue; + } + if (writeEventSignature.equals(logTopic)) { + // write event + continue; + } + if (readEventSignature.equals(logTopic)) { + // read event + continue; + } + fail(); + } + }; + + ToyExecutionEnvironmentV2.builder() + .accounts(List.of(this.testContext.initialAccounts[0], this.testContext.frameworkEntryPointAccount, this.testContext.yulSnippetsAccount)) + .transaction(writeToStorage(testContext.initialAccounts[0], testContext.initialAccounts[1], 123L, 1L)) + .testValidator(resultValidator) + .build() + .run(); + System.out.println("Done"); + } +} + From cd34771e149d202255348d1049e666125305e42e Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Wed, 16 Oct 2024 01:38:43 +0200 Subject: [PATCH 33/74] refactor to use plugin-generated .yul --- .../zktracer/StateManagerSolidityTest.java | 92 ++++++++++--------- .../main/{solidity => yul}/YulContract.yul | 0 2 files changed, 51 insertions(+), 41 deletions(-) rename testing/src/main/{solidity => yul}/YulContract.yul (100%) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index 53a3acc511..91c7f8bd10 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -19,8 +19,6 @@ import lombok.NoArgsConstructor; import net.consensys.linea.testing.*; import net.consensys.linea.testing.generated.FrameworkEntrypoint; -import net.consensys.linea.testing.generated.TestSnippet_Events; -import net.consensys.linea.testing.generated.TestStorage; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.SECP256K1; @@ -48,7 +46,8 @@ public class StateManagerSolidityTest { TestContext testContext; - Transaction writeToStorage(ToyAccount sender, ToyAccount destination, Long key, Long value) { + // destination must be our .yul smart contract + Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, Long key, Long value) { List inputParams = new ArrayList<>(); inputParams.addLast(new Uint256(BigInteger.valueOf(key))); inputParams.addLast(new Uint256(BigInteger.valueOf(value))); @@ -57,7 +56,7 @@ Transaction writeToStorage(ToyAccount sender, ToyAccount destination, Long key, var encoding = FunctionEncoder.encode(yulFunction); FrameworkEntrypoint.ContractCall snippetContractCall = new FrameworkEntrypoint.ContractCall( - /*Address*/ this.testContext.getYulSnippetsAccount().getAddress().toHexString(), + /*Address*/ destination.getAddress().toHexString(), /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), /*gasLimit*/ BigInteger.ZERO, /*value*/ BigInteger.ZERO, @@ -74,10 +73,47 @@ Transaction writeToStorage(ToyAccount sender, ToyAccount destination, Long key, Transaction tx = ToyTransaction.builder() - .sender(this.testContext.initialAccounts[0]) + .sender(sender) .to(this.testContext.frameworkEntryPointAccount) .payload(txPayload) - .keyPair(this.testContext.initialKeyPairs[0]) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit) + .build(); + return tx; + } + + // destination must be our .yul smart contract + Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, Long key) { + List inputParams2 = new ArrayList<>(); + List> outputParams2 = new ArrayList<>(); + inputParams2.addLast(new Uint256(BigInteger.valueOf(1))); + Function yulFunction2 = new Function("readFromStorage", Collections.unmodifiableList(inputParams2), outputParams2); + + + var encoding2 = FunctionEncoder.encode(yulFunction2); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.getAddress().toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding2).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ZERO); + + List contractCalls = List.of(snippetContractCall); + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + Transaction tx = + ToyTransaction.builder() + .sender(sender) + .to(this.testContext.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) .gasLimit(TestContext.gasLimit) .build(); return tx; @@ -89,7 +125,7 @@ class TestContext { static final Long gasLimit = 500000L; static final int numberOfAccounts = 3; @Getter - ToyAccount frameworkEntryPointAccount, yulSnippetsAccount; + ToyAccount frameworkEntryPointAccount; ToyAccount[] initialAccounts; KeyPair[] initialKeyPairs; public void initializeTestContext() { @@ -106,13 +142,12 @@ public void initializeTestContext() { .build(); // initialize the .yul snippets account // load the .yul bytecode - String dynamicBytecodeYul = "0x610007610143565b63a770741d8114610038576397deb47b811461004557630dd2602c81146100515763d40e607a811461007257600080fd5b610040610091565b61008b565b60005460005260206000f35b6004356024356100618183610131565b61006b81836100b7565b505061008b565b60043561007e81610138565b61008881836100f4565b50505b5061016c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b8181555050565b600081549050919050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b"; - yulSnippetsAccount = + initialAccounts[0] = ToyAccount.builder() .address(Address.fromHexString("0x11111")) .balance(Wei.ONE) .nonce(6) - .code(Bytes.fromHexStringLenient(dynamicBytecodeYul)) + .code(SmartContractUtils.getYulContractByteCode("YulContract.yul")) .build(); // generate extra accounts KeyPair keyPair = new SECP256K1().generateKeyPair(); @@ -120,8 +155,8 @@ public void initializeTestContext() { ToyAccount senderAccount = ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); // add to arrays - initialAccounts[0] = senderAccount; - initialKeyPairs[0] = keyPair; + initialAccounts[1] = senderAccount; + initialKeyPairs[1] = keyPair; } } @@ -136,32 +171,6 @@ void testYulModifiedWrite() { - List inputParams2 = new ArrayList<>(); - List> outputParams2 = new ArrayList<>(); - inputParams2.addLast(new Uint256(BigInteger.valueOf(1))); - Function yulFunction2 = new Function("readFromStorage", Collections.unmodifiableList(inputParams2), outputParams2); - - - var encoding2 = FunctionEncoder.encode(yulFunction2); - FrameworkEntrypoint.ContractCall snippetContractCall2 = - new FrameworkEntrypoint.ContractCall( - /*Address*/ this.testContext.getYulSnippetsAccount().getAddress().toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding2).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ BigInteger.ZERO); - - /* - ContractCalls contractCalls = ContractCalls.builder() - .call(snippetContractCall) - .call(snippetContractCall2) - .build(); - */ - List contractCalls = List.of(snippetContractCall2); - - - - Consumer resultValidator = (TransactionProcessingResult result) -> { // One event from the snippet @@ -178,7 +187,7 @@ void testYulModifiedWrite() { FrameworkEntrypoint.CallExecutedEventResponse response = FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); assertTrue(response.isSuccess); - assertEquals(response.destination, this.testContext.yulSnippetsAccount.getAddress().toHexString()); + assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); continue; } if (writeEventSignature.equals(logTopic)) { @@ -194,8 +203,9 @@ void testYulModifiedWrite() { }; ToyExecutionEnvironmentV2.builder() - .accounts(List.of(this.testContext.initialAccounts[0], this.testContext.frameworkEntryPointAccount, this.testContext.yulSnippetsAccount)) - .transaction(writeToStorage(testContext.initialAccounts[0], testContext.initialAccounts[1], 123L, 1L)) + .accounts(List.of(this.testContext.initialAccounts[0], this.testContext.initialAccounts[1], this.testContext.frameworkEntryPointAccount)) + .transaction(writeToStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, 1L)) + // .transaction(readFromStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L)) .testValidator(resultValidator) .build() .run(); diff --git a/testing/src/main/solidity/YulContract.yul b/testing/src/main/yul/YulContract.yul similarity index 100% rename from testing/src/main/solidity/YulContract.yul rename to testing/src/main/yul/YulContract.yul From 6f3030aa756934d53e6f5ef63d888e534f552b11 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Wed, 16 Oct 2024 14:47:57 +0200 Subject: [PATCH 34/74] seld destruct --- testing/src/main/yul/YulContract.yul | 41 +++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/testing/src/main/yul/YulContract.yul b/testing/src/main/yul/YulContract.yul index 20113ae7ca..52d9ee76ba 100644 --- a/testing/src/main/yul/YulContract.yul +++ b/testing/src/main/yul/YulContract.yul @@ -48,6 +48,18 @@ object "YulContract" { logValuesRead(x, y) } + case 0x3f5a0bdd // selfDestruct + { + // Load the first argument (recipient) from calldata + let recipient := calldataload(0x04) + + // log the call before self destructing + logSelfDestruct(recipient) + + // call the self-destruct function + selfDestruct(recipient) + } + default { // if the function signature sent does not match any // of the contract functions, revert @@ -64,7 +76,7 @@ object "YulContract" { // Function to log two uint256 values for the write storage operation, along with the contract address function logValuesWrite(x, y) { // Define an event signature to generate logs for storage operations - let eventSignature := "Write(address,uint256,uint256)" //Hex for "Write(address,uint256,uint256)", signature length is 30 characters (thus 30 bytes) + let eventSignature := "Write(address,uint256,uint256)" // The signature is "Write(address,uint256,uint256)", signature length is 30 characters (thus 30 bytes) let memStart := mload(0x40) // get the free memory pointer mstore(memStart, eventSignature) @@ -98,6 +110,20 @@ object "YulContract" { log4(0x20, 0x60, eventSignatureHash, contractAddress, x, y) } + // Function to log the self destruction of the contract + function logSelfDestruct(recipient) { + // Define an event signature to generate logs for storage operations + let eventSignature := "ContractDestroyed(address)" + + let memStart := mload(0x40) // get the free memory pointer + mstore(memStart, eventSignature) + + let eventSignatureHash := keccak256(memStart, 26) // 26 bytes is the string length, expected output 3ab1d7915d663a46c292b8f01ac13567c748cff5213cb3652695882b5f9b2e0f + + // call the inbuilt logging function + log2(0x20, 0x60, eventSignatureHash, recipient) + } + // 0x0dd2602cce131b717885742cf4e9a79978d80b588950101dc8619106202b5fd5 // function signature: first 4 bytes 0x0dd2602c // example of call: [["Addr",0x0dd2602c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001,0,0,0]] @@ -118,6 +144,19 @@ object "YulContract" { y := verbatim_1i_1o(hex"54", x) } + /** + * @notice Selfdestructs and sends remaining ETH to a payable address. + * @dev Keep in mind you need to compile and target London EVM version - this doesn't work for repeat addresses on Cancun etc. + * @param _fundAddress The deploying contract's address. + * example of call: [["Addr",0x3f5a0bdd0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4,0,0,0]] + * (replace the argument 5b38da6a701c568545dcfcb03fcb875f56beddc4 with the intended recipient, as needed) + **/ + function selfDestruct(recipient) { + // There is a weird bug with selfdestruct(recipient), so we replace that with verbatim + // Use verbatim to include the selfdestruct opcode (0xff) + verbatim_1i_0o(hex"ff", recipient) + } + // Return the function selector: the first 4 bytes of the call data function selector() -> s { s := div(calldataload(0), 0x100000000000000000000000000000000000000000000000000000000) From b162f42e65c67d05eec011a48622686fc7ed79cb Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Wed, 16 Oct 2024 15:29:30 +0200 Subject: [PATCH 35/74] self-destruct calls, to be tested more --- .../zktracer/StateManagerSolidityTest.java | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index 91c7f8bd10..abb62c6730 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -119,6 +119,44 @@ Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount return tx; } + // destination must be our .yul smart contract + Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, ToyAccount recipient) { + List inputParams = new ArrayList<>(); + List> outputParams = new ArrayList<>(); + String recipientAddressString = recipient.getAddress().toHexString(); + inputParams.addLast(new org.web3j.abi.datatypes.Address(recipientAddressString)); + Function yulFunction = new Function("selfDestruct", Collections.unmodifiableList(inputParams), outputParams); + + + var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.getAddress().toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ONE); // Normal call, not a delegate call as it is the default + + List contractCalls = List.of(snippetContractCall); + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + Transaction tx = + ToyTransaction.builder() + .sender(sender) + .to(this.testContext.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit) + .build(); + return tx; + } + @NoArgsConstructor class TestContext { @@ -183,6 +221,7 @@ void testYulModifiedWrite() { String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); String writeEventSignature = EventEncoder.encode(FrameworkEntrypoint.WRITE_EVENT); String readEventSignature = EventEncoder.encode(FrameworkEntrypoint.READ_EVENT); + String destructEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); if (callEventSignature.equals(logTopic)) { FrameworkEntrypoint.CallExecutedEventResponse response = FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); @@ -198,15 +237,20 @@ void testYulModifiedWrite() { // read event continue; } + if (destructEventSignature.equals(logTopic)) { + // self destruct + continue; + } fail(); } }; ToyExecutionEnvironmentV2.builder() .accounts(List.of(this.testContext.initialAccounts[0], this.testContext.initialAccounts[1], this.testContext.frameworkEntryPointAccount)) - .transaction(writeToStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, 1L)) + //.transaction(writeToStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, 1L)) // .transaction(readFromStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L)) - .testValidator(resultValidator) + .transaction(selfDestruct(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], testContext.frameworkEntryPointAccount)) + .testValidator(resultValidator) .build() .run(); System.out.println("Done"); From 18ac0b6f354e4a1d06c6657a6f6213ee64a63335 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Thu, 24 Oct 2024 01:12:28 +0200 Subject: [PATCH 36/74] updating with latest .yul and latest arith-dev --- .../linea/zktracer/module/hub/Hub.java | 79 ++--- .../zktracer/StateManagerSolidityTest.java | 315 ++++++++++++----- .../MultiBlockExecutionEnvironment.java | 173 +++------- testing/src/main/yul/StateManagerSnippets.yul | 316 ++++++++++++++++++ testing/src/main/yul/YulContract.yul | 183 ---------- 5 files changed, 620 insertions(+), 446 deletions(-) create mode 100644 testing/src/main/yul/StateManagerSnippets.yul delete mode 100644 testing/src/main/yul/YulContract.yul 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 8675014d27..4b21e5dc6d 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 @@ -1484,22 +1484,22 @@ public void printStorageMaps() { Map< TransactionProcessingMetadata.AddrStorageKeyPair, TransactionProcessingMetadata.FragmentFirstAndLast> - txnMapStorage = metadata.getStorageFirstAndLastMap(); + txnMapStorage = metadata.getStorageFirstAndLastMap(); for (TransactionProcessingMetadata.AddrStorageKeyPair addrKeyPair : txnMapStorage.keySet()) { var txnValue = txnMapStorage.get(addrKeyPair); System.out.println( - "Storage: txn level map: addr: " - + addrKeyPair.getAddress() - + ": storage key: " - + addrKeyPair.getStorageKey() - + ": first dom: " - + txnValue.getFirstDom() - + ", first sub: " - + txnValue.getFirstSub() - + ": last dom: " - + txnValue.getLastDom() - + ", last sub: " - + txnValue.getLastSub()); + "Storage: txn level map: addr: " + + addrKeyPair.getAddress() + + ": storage key: " + + addrKeyPair.getStorageKey() + + ": first dom: " + + txnValue.getFirstDom() + + ", first sub: " + + txnValue.getFirstSub() + + ": last dom: " + + txnValue.getLastDom() + + ", last sub: " + + txnValue.getLastSub()); } } @@ -1508,20 +1508,20 @@ public void printStorageMaps() { for (var addrKeyBlockTuple : blockMapStorage.keySet()) { var blockValue = blockMapStorage.get(addrKeyBlockTuple); System.out.println( - "Storage: block level map: addr: " - + addrKeyBlockTuple.getAddrStorageKeyPair().getAddress() - + ": key: " - + addrKeyBlockTuple.getAddrStorageKeyPair().getStorageKey() - + ": block: " - + addrKeyBlockTuple.getBlockNumber() - + ": first dom: " - + blockValue.getFirstDom() - + ", first sub: " - + blockValue.getFirstSub() - + ": last dom: " - + blockValue.getLastDom() - + ", last sub: " - + blockValue.getLastSub()); + "Storage: block level map: addr: " + + addrKeyBlockTuple.getAddrStorageKeyPair().getAddress() + + ": key: " + + addrKeyBlockTuple.getAddrStorageKeyPair().getStorageKey() + + ": block: " + + addrKeyBlockTuple.getBlockNumber() + + ": first dom: " + + blockValue.getFirstDom() + + ", first sub: " + + blockValue.getFirstSub() + + ": last dom: " + + blockValue.getLastDom() + + ", last sub: " + + blockValue.getLastSub()); } // Print conflationMaps @@ -1529,19 +1529,20 @@ public void printStorageMaps() { for (var addrKeyPair : conflationMapStorage.keySet()) { var conflationValue = conflationMapStorage.get(addrKeyPair); System.out.println( - "Storage: conflation level map: addr: " - + addrKeyPair.getAddress() - + ": storage key: " - + addrKeyPair.getStorageKey() - + ": first dom: " - + conflationValue.getFirstDom() - + ", first sub: " - + conflationValue.getFirstSub() - + ": last dom: " - + conflationValue.getLastDom() - + ", last sub: " - + conflationValue.getLastSub()); + "Storage: conflation level map: addr: " + + addrKeyPair.getAddress() + + ": storage key: " + + addrKeyPair.getStorageKey() + + ": first dom: " + + conflationValue.getFirstDom() + + ", first sub: " + + conflationValue.getFirstSub() + + ": last dom: " + + conflationValue.getLastDom() + + ", last sub: " + + conflationValue.getLastSub()); } + } public final boolean returnFromMessageCall(MessageFrame frame) { return opCode() == RETURN && frame.getType() == MESSAGE_CALL; } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index abb62c6730..f770975668 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -19,6 +19,9 @@ import lombok.NoArgsConstructor; import net.consensys.linea.testing.*; import net.consensys.linea.testing.generated.FrameworkEntrypoint; +import net.consensys.linea.testing.generated.StateManagerEvents; +import net.consensys.linea.testing.generated.TestSnippet_Events; +import net.consensys.linea.testing.generated.TestingBase; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.SECP256K1; @@ -33,25 +36,44 @@ import org.web3j.abi.FunctionEncoder; import org.web3j.abi.TypeReference; import org.web3j.abi.datatypes.DynamicArray; +import org.web3j.abi.datatypes.DynamicBytes; import org.web3j.abi.datatypes.Function; +import org.web3j.abi.datatypes.Type; +import org.web3j.abi.datatypes.generated.Bytes32; import org.web3j.abi.datatypes.generated.Uint256; import java.math.BigInteger; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.function.Consumer; +import static org.assertj.core.api.Fail.fail; import static org.junit.jupiter.api.Assertions.*; public class StateManagerSolidityTest { TestContext testContext; + enum RevertFlag { + DISABLED, + ENABLED + } + String boolToHexString(boolean x) { + if (x) { + return "0x0000000000000000000000000000000000000000000000000000000000000001"; + } + else { + return "0x0000000000000000000000000000000000000000000000000000000000000000"; + } + } + + + // destination must be our .yul smart contract - Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, Long key, Long value) { - List inputParams = new ArrayList<>(); - inputParams.addLast(new Uint256(BigInteger.valueOf(key))); - inputParams.addLast(new Uint256(BigInteger.valueOf(value))); - Function yulFunction = new Function("writeToStorage", Collections.unmodifiableList(inputParams), Collections.emptyList()); + Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, Long key, Long value, boolean revertFlag) { + Function yulFunction = new Function("writeToStorage", + Arrays.asList(new Uint256(BigInteger.valueOf(key)), new Uint256(BigInteger.valueOf(value)), new org.web3j.abi.datatypes.Bool(revertFlag)), + Collections.emptyList()); var encoding = FunctionEncoder.encode(yulFunction); FrameworkEntrypoint.ContractCall snippetContractCall = @@ -71,30 +93,37 @@ Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount Bytes txPayload = Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - Transaction tx = - ToyTransaction.builder() - .sender(sender) - .to(this.testContext.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit) - .build(); + + ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() + .sender(sender) + .to(this.testContext.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit); + + if (TestContext.txNonce != null) { + tempTx = tempTx.nonce(++TestContext.txNonce); + } + Transaction tx = tempTx.build(); + if (TestContext.txNonce == null) { + TestContext.txNonce = tx.getNonce(); + } return tx; } + // destination must be our .yul smart contract - Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, Long key) { - List inputParams2 = new ArrayList<>(); - List> outputParams2 = new ArrayList<>(); - inputParams2.addLast(new Uint256(BigInteger.valueOf(1))); - Function yulFunction2 = new Function("readFromStorage", Collections.unmodifiableList(inputParams2), outputParams2); + Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, Long key, boolean revertFlag) { + Function yulFunction = new Function("readFromStorage", + Arrays.asList(new Uint256(BigInteger.valueOf(key)), new org.web3j.abi.datatypes.Bool(revertFlag)), + Collections.emptyList()); - var encoding2 = FunctionEncoder.encode(yulFunction2); + var encoding = FunctionEncoder.encode(yulFunction); FrameworkEntrypoint.ContractCall snippetContractCall = new FrameworkEntrypoint.ContractCall( /*Address*/ destination.getAddress().toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding2).toArray(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), /*gasLimit*/ BigInteger.ZERO, /*value*/ BigInteger.ZERO, /*callType*/ BigInteger.ZERO); @@ -108,27 +137,81 @@ Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount Bytes txPayload = Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - Transaction tx = - ToyTransaction.builder() - .sender(sender) - .to(this.testContext.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit) - .build(); + ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() + .sender(sender) + .to(this.testContext.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit); + + if (TestContext.txNonce != null) { + tempTx = tempTx.nonce(++TestContext.txNonce); + } + Transaction tx = tempTx.build(); + if (TestContext.txNonce == null) { + TestContext.txNonce = tx.getNonce(); + } return tx; } // destination must be our .yul smart contract - Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, ToyAccount recipient) { - List inputParams = new ArrayList<>(); - List> outputParams = new ArrayList<>(); + Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, ToyAccount recipient, boolean revertFlag) { String recipientAddressString = recipient.getAddress().toHexString(); - inputParams.addLast(new org.web3j.abi.datatypes.Address(recipientAddressString)); - Function yulFunction = new Function("selfDestruct", Collections.unmodifiableList(inputParams), outputParams); + Function yulFunction = new Function("selfDestruct", + Arrays.asList(new org.web3j.abi.datatypes.Address(recipientAddressString), new org.web3j.abi.datatypes.Bool(revertFlag)), + Collections.emptyList()); var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.getAddress().toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ONE); // Normal call, not a delegate call as would be the default + + List contractCalls = List.of(snippetContractCall); + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() + .sender(sender) + .to(this.testContext.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit); + + if (TestContext.txNonce != null) { + tempTx = tempTx.nonce(++TestContext.txNonce); + } + Transaction tx = tempTx.build(); + if (TestContext.txNonce == null) { + TestContext.txNonce = tx.getNonce(); + } + return tx; + } + + // destination must be our .yul smart contract + Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, String saltString) { + Bytes salt = Bytes.fromHexStringLenient(saltString); + // the following are the bytecode of the .yul contract + Bytes yulContractBytes = Bytes.fromHexStringLenient("61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); + // prepare the Create2 function + Function create2Function = + new Function( + FrameworkEntrypoint.FUNC_DEPLOYWITHCREATE2, + Arrays.asList(new org.web3j.abi.datatypes.generated.Bytes32(salt.toArray()), + new org.web3j.abi.datatypes.DynamicBytes(yulContractBytes.toArray())), + Collections.emptyList()); + + String encoding = FunctionEncoder.encode(create2Function); + FrameworkEntrypoint.ContractCall snippetContractCall = new FrameworkEntrypoint.ContractCall( /*Address*/ destination.getAddress().toHexString(), @@ -137,30 +220,39 @@ Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, ToyAccount de /*value*/ BigInteger.ZERO, /*callType*/ BigInteger.ONE); // Normal call, not a delegate call as it is the default + List contractCalls = List.of(snippetContractCall); Function frameworkEntryPointFunction = new Function( FrameworkEntrypoint.FUNC_EXECUTECALLS, List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), Collections.emptyList()); + Bytes txPayload = Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - Transaction tx = - ToyTransaction.builder() - .sender(sender) - .to(this.testContext.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit) - .build(); + ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() + .sender(sender) + .to(this.testContext.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit); + + if (TestContext.txNonce != null) { + tempTx = tempTx.nonce(++TestContext.txNonce); + } + Transaction tx = tempTx.build(); + if (TestContext.txNonce == null) { + TestContext.txNonce = tx.getNonce(); + } return tx; } @NoArgsConstructor class TestContext { - static final Long gasLimit = 500000L; + static Long txNonce = null; + static final Long gasLimit = 5000000L; static final int numberOfAccounts = 3; @Getter ToyAccount frameworkEntryPointAccount; @@ -185,7 +277,7 @@ public void initializeTestContext() { .address(Address.fromHexString("0x11111")) .balance(Wei.ONE) .nonce(6) - .code(SmartContractUtils.getYulContractByteCode("YulContract.yul")) + .code(SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul")) .build(); // generate extra accounts KeyPair keyPair = new SECP256K1().generateKeyPair(); @@ -195,6 +287,14 @@ public void initializeTestContext() { // add to arrays initialAccounts[1] = senderAccount; initialKeyPairs[1] = keyPair; + // an account with revert + initialAccounts[2] = + ToyAccount.builder() + .address(Address.fromHexString("0x44444")) + .balance(Wei.ONE) + .nonce(8) + .code(SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul")) + .build(); } } @@ -208,52 +308,89 @@ void testYulModifiedWrite() { + TransactionProcessingResultValidator resultValidator = + (Transaction transaction, TransactionProcessingResult result) -> { + TransactionProcessingResultValidator.DEFAULT_VALIDATOR.accept(transaction, result); + // One event from the snippet + // One event from the framework entrypoint about contract call + System.out.println("Number of logs: "+result.getLogs().size()); + //assertEquals(result.getLogs().size(), 2); + for (Log log : result.getLogs()) { + String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); + String writeEventSignature = EventEncoder.encode(StateManagerEvents.WRITE_EVENT); + String readEventSignature = EventEncoder.encode(StateManagerEvents.READ_EVENT); + String destroyedEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); + String createdEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTCREATED_EVENT); + String logTopic = log.getTopics().getFirst().toHexString(); + if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { + TestSnippet_Events.DataNoIndexesEventResponse response = + TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); + //assertEquals(response.singleInt, BigInteger.valueOf(123456)); + } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) + .equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + if (logTopic.equals(createdEventSignature)) { + assertEquals(response.destination, this.testContext.frameworkEntryPointAccount.getAddress().toHexString()); + } else { + //assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); + } + } else { + if (!(logTopic.equals(callEventSignature) || logTopic.equals(writeEventSignature) || logTopic.equals(readEventSignature) || logTopic.equals(destroyedEventSignature) || logTopic.equals(createdEventSignature))) { + fail(); + } + } + } + }; + + /* + TransactionProcessingResultValidator resultValidator = + (Transaction transaction, TransactionProcessingResult result) -> { + // One event from the snippet + // One event from the framework entrypoint about contract call + //assertEquals(result.getLogs().size(), 1); + System.out.println("Number of logs: "+result.getLogs().size()); + var noTopics = result.getLogs().size(); + for (Log log : result.getLogs()) { + String logTopic = log.getTopics().getFirst().toHexString(); + String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); + String writeEventSignature = EventEncoder.encode(FrameworkEntrypoint.WRITE_EVENT); + String readEventSignature = EventEncoder.encode(FrameworkEntrypoint.READ_EVENT); + String destructEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); + if (callEventSignature.equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); + continue; + } + if (writeEventSignature.equals(logTopic)) { + // write event + continue; + } + if (readEventSignature.equals(logTopic)) { + // read event + continue; + } + if (destructEventSignature.equals(logTopic)) { + // self destruct + continue; + } + fail(); + } + }; - Consumer resultValidator = - (TransactionProcessingResult result) -> { - // One event from the snippet - // One event from the framework entrypoint about contract call - //assertEquals(result.getLogs().size(), 1); - System.out.println("Number of logs: "+result.getLogs().size()); - var noTopics = result.getLogs().size(); - for (Log log : result.getLogs()) { - String logTopic = log.getTopics().getFirst().toHexString(); - String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); - String writeEventSignature = EventEncoder.encode(FrameworkEntrypoint.WRITE_EVENT); - String readEventSignature = EventEncoder.encode(FrameworkEntrypoint.READ_EVENT); - String destructEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); - if (callEventSignature.equals(logTopic)) { - FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - assertTrue(response.isSuccess); - assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); - continue; - } - if (writeEventSignature.equals(logTopic)) { - // write event - continue; - } - if (readEventSignature.equals(logTopic)) { - // read event - continue; - } - if (destructEventSignature.equals(logTopic)) { - // self destruct - continue; - } - fail(); - } - }; - - ToyExecutionEnvironmentV2.builder() - .accounts(List.of(this.testContext.initialAccounts[0], this.testContext.initialAccounts[1], this.testContext.frameworkEntryPointAccount)) - //.transaction(writeToStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, 1L)) - // .transaction(readFromStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L)) - .transaction(selfDestruct(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], testContext.frameworkEntryPointAccount)) - .testValidator(resultValidator) - .build() - .run(); + */ + MultiBlockExecutionEnvironment.builder() + .accounts(List.of(this.testContext.initialAccounts[0], this.testContext.initialAccounts[1], this.testContext.frameworkEntryPointAccount)) + .addBlock(List.of(writeToStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, 1L, false))) + .addBlock(List.of(readFromStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, false))) + .addBlock(List.of(selfDestruct(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], testContext.frameworkEntryPointAccount, false))) + .addBlock(List.of(deployWithCreate2(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.frameworkEntryPointAccount, "0x0000000000000000000000000000000000000000000000000000000000000002"))) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); System.out.println("Done"); } -} - +} \ No newline at end of file diff --git a/testing/src/main/java/net/consensys/linea/testing/MultiBlockExecutionEnvironment.java b/testing/src/main/java/net/consensys/linea/testing/MultiBlockExecutionEnvironment.java index c3d19d3108..f3e653c437 100644 --- a/testing/src/main/java/net/consensys/linea/testing/MultiBlockExecutionEnvironment.java +++ b/testing/src/main/java/net/consensys/linea/testing/MultiBlockExecutionEnvironment.java @@ -15,10 +15,8 @@ package net.consensys.linea.testing; -import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Optional; @@ -26,29 +24,11 @@ import lombok.Singular; import lombok.extern.slf4j.Slf4j; import net.consensys.linea.blockcapture.snapshots.*; -import net.consensys.linea.corset.CorsetValidator; -import net.consensys.linea.zktracer.ConflationAwareOperationTracer; -import net.consensys.linea.zktracer.ZkTracer; -import org.apache.tuweni.bytes.Bytes; -import org.apache.tuweni.units.bigints.UInt256; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.*; -import org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor; -import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; -import org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState; -import org.hyperledger.besu.evm.account.MutableAccount; -import org.hyperledger.besu.evm.internal.EvmConfiguration; -import org.hyperledger.besu.evm.internal.Words; -import org.hyperledger.besu.evm.operation.BlockHashOperation; -import org.hyperledger.besu.evm.tracing.OperationTracer; -import org.hyperledger.besu.evm.worldstate.WorldUpdater; @Builder @Slf4j public class MultiBlockExecutionEnvironment { - private static final CorsetValidator CORSET_VALIDATOR = new CorsetValidator(); - @Singular("addAccount") private final List accounts; @@ -60,8 +40,7 @@ public class MultiBlockExecutionEnvironment { */ @Builder.Default private final TransactionProcessingResultValidator transactionProcessingResultValidator = - TransactionProcessingResultValidator.DEFAULT_VALIDATOR; - + TransactionProcessingResultValidator.DEFAULT_VALIDATOR; public static class MultiBlockExecutionEnvironmentBuilder { @@ -69,10 +48,10 @@ public static class MultiBlockExecutionEnvironmentBuilder { public MultiBlockExecutionEnvironmentBuilder addBlock(List transactions) { BlockHeaderBuilder blockHeaderBuilder = - this.blocks.isEmpty() - ? ExecutionEnvironment.getLineaBlockHeaderBuilder(Optional.empty()) - : ExecutionEnvironment.getLineaBlockHeaderBuilder( - Optional.of(this.blocks.getLast().header().toBlockHeader())); + this.blocks.isEmpty() + ? ExecutionEnvironment.getLineaBlockHeaderBuilder(Optional.empty()) + : ExecutionEnvironment.getLineaBlockHeaderBuilder( + Optional.of(this.blocks.getLast().header().toBlockHeader())); blockHeaderBuilder.coinbase(ToyExecutionEnvironmentV2.DEFAULT_COINBASE_ADDRESS); BlockBody blockBody = new BlockBody(transactions, Collections.emptyList()); this.blocks.add(BlockSnapshot.of(blockHeaderBuilder.buildBlockHeader(), blockBody)); @@ -83,123 +62,47 @@ public MultiBlockExecutionEnvironmentBuilder addBlock(List transact public void run() { ReplayExecutionEnvironment.builder() - .useCoinbaseAddressFromBlockHeader(true) - .transactionProcessingResultValidator(this.transactionProcessingResultValidator) - .build() - .replay(ToyExecutionEnvironmentV2.CHAIN_ID, this.buildConflationSnapshot()); + .useCoinbaseAddressFromBlockHeader(true) + .transactionProcessingResultValidator(this.transactionProcessingResultValidator) + .build() + .replay(ToyExecutionEnvironmentV2.CHAIN_ID, this.buildConflationSnapshot()); } private ConflationSnapshot buildConflationSnapshot() { List accountSnapshots = - accounts.stream() - .map( - toyAccount -> - new AccountSnapshot( - toyAccount.getAddress().toHexString(), - toyAccount.getNonce(), - toyAccount.getBalance().toHexString(), - toyAccount.getCode().toHexString())) - .toList(); + accounts.stream() + .map( + toyAccount -> + new AccountSnapshot( + toyAccount.getAddress().toHexString(), + toyAccount.getNonce(), + toyAccount.getBalance().toHexString(), + toyAccount.getCode().toHexString())) + .toList(); List storageSnapshots = - accounts.stream() - .flatMap( - account -> - account.storage.entrySet().stream() - .map( - storageEntry -> - new StorageSnapshot( - account.getAddress().toHexString(), - storageEntry.getKey().toHexString(), - storageEntry.getValue().toHexString()))) - .toList(); + accounts.stream() + .flatMap( + account -> + account.storage.entrySet().stream() + .map( + storageEntry -> + new StorageSnapshot( + account.getAddress().toHexString(), + storageEntry.getKey().toHexString(), + storageEntry.getValue().toHexString()))) + .toList(); List blockHashSnapshots = - blocks.stream() - .map( - blockSnapshot -> { - BlockHeader blockHeader = blockSnapshot.header().toBlockHeader(); - return BlockHashSnapshot.of(blockHeader.getNumber(), blockHeader.getBlockHash()); - }) - .toList(); + blocks.stream() + .map( + blockSnapshot -> { + BlockHeader blockHeader = blockSnapshot.header().toBlockHeader(); + return BlockHashSnapshot.of(blockHeader.getNumber(), blockHeader.getBlockHash()); + }) + .toList(); return new ConflationSnapshot( - this.blocks, accountSnapshots, storageSnapshots, blockHashSnapshots); - } - - private void executeFrom(final BigInteger chainId, final ConflationSnapshot conflation) { - BlockHashOperation.BlockHashLookup blockHashLookup = conflation.toBlockHashLookup(); - ReferenceTestWorldState world = - ReferenceTestWorldState.create(new HashMap<>(), EvmConfiguration.DEFAULT); - // Initialise world state from conflation - initWorld(world.updater(), conflation); - // Construct the transaction processor - final MainnetTransactionProcessor transactionProcessor = - ExecutionEnvironment.getProtocolSpec(chainId).getTransactionProcessor(); - // Begin - tracer.traceStartConflation(conflation.blocks().size()); - // - for (BlockSnapshot blockSnapshot : conflation.blocks()) { - final BlockHeader header = blockSnapshot.header().toBlockHeader(); - - final BlockBody body = - new BlockBody( - blockSnapshot.txs().stream().map(TransactionSnapshot::toTransaction).toList(), - new ArrayList<>()); - tracer.traceStartBlock(header, body); - - for (TransactionSnapshot txs : blockSnapshot.txs()) { - final Transaction tx = txs.toTransaction(); - final WorldUpdater updater = world.updater(); - // Process transaction leading to expected outcome - final TransactionProcessingResult outcome = - transactionProcessor.processTransaction( - updater, - header, - tx, - header.getCoinbase(), - buildOperationTracer(tx, txs.getOutcome()), - blockHashLookup, - false, - Wei.ZERO); - // Commit transaction - updater.commit(); - } - tracer.traceEndBlock(header, body); - } - tracer.traceEndConflation(world.updater()); - } - - private OperationTracer buildOperationTracer(Transaction tx, TransactionResultSnapshot txs) { - if (txs == null) { - String hash = tx.getHash().toHexString(); - log.info("tx `{}` outcome not checked (missing)", hash); - return tracer; - } else { - return ConflationAwareOperationTracer.sequence(txs.check(), tracer); - } - } - - private static void initWorld(WorldUpdater world, final ConflationSnapshot conflation) { - WorldUpdater updater = world.updater(); - - for (AccountSnapshot account : conflation.accounts()) { - // Construct contract address - Address addr = Address.fromHexString(account.address()); - // Create account - MutableAccount acc = - world.createAccount( - Words.toAddress(addr), account.nonce(), Wei.fromHexString(account.balance())); - // Update code - acc.setCode(Bytes.fromHexString(account.code())); - } - // Initialise storage - for (StorageSnapshot s : conflation.storage()) { - world - .getAccount(Words.toAddress(Bytes.fromHexString(s.address()))) - .setStorageValue(UInt256.fromHexString(s.key()), UInt256.fromHexString(s.value())); - } - // - world.commit(); + this.blocks, accountSnapshots, storageSnapshots, blockHashSnapshots); } -} +} \ No newline at end of file diff --git a/testing/src/main/yul/StateManagerSnippets.yul b/testing/src/main/yul/StateManagerSnippets.yul new file mode 100644 index 0000000000..1a96300e65 --- /dev/null +++ b/testing/src/main/yul/StateManagerSnippets.yul @@ -0,0 +1,316 @@ +object "StateManagerSnippets" { + code { + // return the bytecode of the contract + datacopy(0x00, dataoffset("runtime"), datasize("runtime")) + return(0x00, datasize("runtime")) + } + + object "runtime" { + code { + switch selector() + case 0xa770741d // Write() + { + write() + } + + case 0x97deb47b // Read() + { + // store the ID to memory at 0x00 + mstore(0x00, sload(0x00)) + + return (0x00,0x20) + } + + case 0xacf07154 // writeToStorage() + { + // Load the first argument (x) from calldata + let x := calldataload(0x04) + + // Load the second argument (y) from calldata, 0x20 is 32 bytes + let y := calldataload(0x24) + + // get the revertFlag + let revertFlag := calldataload(0x44) + + // call the writeToStorage function + writeToStorage(x, y, revertFlag) + + // log the call + logValuesWrite(x, y) + + // check the revert flag, and if true, perform a revert + if eq(revertFlag, 0x0000000000000000000000000000000000000000000000000000000000000001) { + revertWithError() + } + } + + case 0x2d97bf10 // readFromStorage() + { + // Load the first argument (x) from calldata + let x := calldataload(0x04) + + // get the revertFlag + let revertFlag := calldataload(0x24) + + // call the readFromStorage function + let y := readFromStorage(x, revertFlag) + + // log the call + logValuesRead(x, y) + + // check the revert flag, and if true, perform a revert + if eq(revertFlag, 0x0000000000000000000000000000000000000000000000000000000000000001) { + revertWithError() + } + } + + case 0xeba7ff7f // selfDestruct() + { + // Load the first argument (recipient) from calldata + let recipient := calldataload(0x04) + + // get the revertFlag + let revertFlag := calldataload(0x24) + + // log the call before self destructing + logSelfDestruct(recipient) + + // call the self-destruct function if the revert is not present + // not the best way to revert, but the self destruct does not allow for a revert afterwards + // unless the revert flag is pushed outside, after the end of the contract call + if eq(revertFlag, 0x0000000000000000000000000000000000000000000000000000000000000000) { + selfDestruct(recipient, revertFlag) + } + + // check the revert flag, and if true, perform a revert + if eq(revertFlag, 0x0000000000000000000000000000000000000000000000000000000000000001) { + revertWithError() + } + } + + case 0x2b261e94 // transferTo(), transfer to a specific address + { + // Load the recipient address from calldata + let recipient := calldataload(0x04) + + // get the amount + let amount := calldataload(0x24) + + // get the revertFlag + let revertFlag := calldataload(0x44) + + // address of the sender contract + let senderAddress := address() + + // perform the transfer + transferTo(recipient, amount, revertFlag) + + // log the call + logTransfer(senderAddress, recipient, amount) + + // check the revert flag, and if true, perform a revert + if eq(revertFlag, 0x0000000000000000000000000000000000000000000000000000000000000001) { + revertWithError() + } + } + + case 0x3ecfd51e { + // I will use 0xf1f1f1f1 as hardcoded calldata for the call opcode in case of a transfer + logReceive() + receiveETH() + } + + case 0xffffffff { + // I will use 0xf1f1f1f1 as hardcoded calldata for the call opcode in case of a transfer + } + + default { + // if the function signature sent does not match any + // of the contract functions, revert + revert(0, 0) + } + + function write() { + // take no inputs, push the 1234...EF 32 byte integer onto the stack + // add 0 as the slot key to the stack + // store the key/value + verbatim_0i_0o(hex"7f0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF600055") + } + + // Function to log two uint256 values for the write storage operation, along with the contract address + function logValuesWrite(x, y) { + // Define an event signature to generate logs for storage operations + let eventSignature := "Write(address,uint256,uint256)" // The signature is "Write(address,uint256,uint256)", signature length is 30 characters (thus 30 bytes) + + let memStart := mload(0x40) // get the free memory pointer + mstore(memStart, eventSignature) + + let eventSignatureHash := keccak256(memStart, 30) // expected 33d8dc4a860afa0606947f2b214f16e21e7eac41e3eb6642e859d9626d002ef6 + + // in the case of a delegate call, this will be the original that called the .Yul snippet. + // For a regular call, it will be the address of the .Yul contract. + let contractAddress := address() + + // call the inbuilt logging function + log4(0x20, 0x60, eventSignatureHash, contractAddress, x, y) + } + // Function to log two uint256 values for the read storage operation, along with the contract address + function logValuesRead(x, y) { + // Define an event signature to generate logs for storage operations + let eventSignatureHex := 0x5265616428616464726573732c75696e743235362c75696e7432353629202020 + // Above is the hex for "Read(address,uint256,uint256)", exact length is 29 characters, padded with 3 spaces (20 in hex) + // if we do not pad at the end, the hex is stored in the wrong manner. The spaces will be disregarded when we hash. + + let memStart := mload(0x40) // get the free memory pointer + mstore(memStart, eventSignatureHex) + + let eventSignatureHash := keccak256(memStart, 29) // 29 bytes is the string length, expected output c2db4694c1ec690e784f771a7fe3533681e081da4baa4aa1ad7dd5c33da95925 + + // in the case of a delegate call, this will be the original that called the .Yul snippet. + // For a regular call, it will be the address of the .Yul contract. + let contractAddress := address() + + // call the inbuilt logging function + log4(0x20, 0x60, eventSignatureHash, contractAddress, x, y) + } + + // Function to log a transfer + function logTransfer(sender, recipient, amount) { + // Define an event signature to generate logs for storage operations + let eventSignature := "PayETH(address,address,uint256)" + + let memStart := mload(0x40) // get the free memory pointer + mstore(memStart, eventSignature) + + let eventSignatureHash := keccak256(memStart, 31) // 31 bytes is the string length, expected output 86486637435fcc400fa51609bdb9068db32be14298e016223d7b7ffdae7998ff + + + // call the inbuilt logging function + log4(0x20, 0x60, eventSignatureHash, sender, recipient, amount) + } + + // Function to log the self destruction of the contract + function logSelfDestruct(recipient) { + // Define an event signature to generate logs for storage operations + let eventSignature := "ContractDestroyed(address)" + + let memStart := mload(0x40) // get the free memory pointer + mstore(memStart, eventSignature) + + let eventSignatureHash := keccak256(memStart, 26) // 26 bytes is the string length, expected output 3ab1d7915d663a46c292b8f01ac13567c748cff5213cb3652695882b5f9b2e0f + + // call the inbuilt logging function + log2(0x20, 0x60, eventSignatureHash, recipient) + } + + function logReceive() { + // Define an event signature to generate a log when the .yul contract receives ETH + let eventSignature := "RecETH(address,uint256)" + + let memStart := mload(0x40) // get the free memory pointer + mstore(memStart, eventSignature) + + let eventSignatureHash := keccak256(memStart, 23) // 23 bytes is the string length, expected output e1b5c1e280a4d97847c2d5c3006bd406609f68889f3d868ed3250aa10a8629aa + + let currentAddress := address() + let amount := callvalue() + // call the inbuilt logging function + log3(0x20, 0x60, eventSignatureHash, currentAddress, amount) + } + + // 0xacf071542e5c4e6701a11ffbc7a8f8e63ef5fdc6871e5d1ee4e7bc956a8d23ac + // function signature: first 4 bytes 0xacf07154 + // example of call: [["Addr",0xacf07154000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001,0,0,0]] + // writeToStorage(uint256,uint256,bool) is the unhashed function signature + function writeToStorage(x, y, revertFlag) { + // Use verbatim to include raw bytecode for storing y at storage key x + // 55 corresponds to SSTORE + verbatim_2i_0o(hex"55", x, y) + } + + // 0x2d97bf1001ed6a98a40186556bfeee30afccf7c13d4d24f6eb6e48b668210fc8 + // function signature: first 4 bytes 0x2d97bf10 + // example of call: [["Addr",0x2d97bf1000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001,0,0,0]] + // readFromStorage(uint256,bool) is the unhashed function signature + function readFromStorage(x, revertFlag) -> y{ + // Use verbatim to include raw bytecode for reading the value stored at x + // 54 corresponds to SLOAD + y := verbatim_1i_1o(hex"54", x) + } + + + // @notice Selfdestructs and sends remaining ETH to a payable address. + // @dev Keep in mind you need to compile and target London EVM version - this doesn't work for repeat addresses on Cancun etc. + // example of call: [["Addr",0xeba7ff7f0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc40000000000000000000000000000000000000000000000000000000000000001,0,0,0]] + // (replace the argument 5b38da6a701c568545dcfcb03fcb875f56beddc4 with the intended recipient, as needed) + // function signature selfDestruct(address,bool)—eba7ff7f626dacfd4408d6e720f444f37df3477e2719d8610a3837a6f8b9400e + function selfDestruct(recipient, revertFlag) { + // There is a weird bug with selfdestruct(recipient), so we replace that with verbatim + // Use verbatim to include the selfdestruct opcode (0xff) + verbatim_1i_0o(hex"ff", recipient) + } + + // Return the function selector: the first 4 bytes of the call data + function selector() -> s { + s := div(calldataload(0), 0x100000000000000000000000000000000000000000000000000000000) + } + + // Implementation of the require statement from Solidity + function require(condition) { + if iszero(condition) { revert(0, 0) } + } + + // Check if the calldata has the correct number of params + function checkParamLength(len) { + require(eq(calldatasize(), add(4, mul(32, len)))) + } + + // Transfer ether to the caller address + function transfer(amount) { + if iszero(call(gas(), caller(), amount, 0, 0, 0, 0)) { + revert(0,0) + } + } + + // Transfer ether to the recipient address + // function signature transferTo(address,uint256,bool)—hash 0x2b261e94b0c8d2a13b0379d0e6facd43b4bd12e1d1b944f2ee6288c0a278d838 + // function selector 0x2b261e94 + // call example, snippet address—function selector, recipient address, wei amount and revert flag + // call example: [["addr",0x2b261e94000000000000000000000000746FfB8C87c9142519a144caB812495d2960a24b00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000,0,0,1]] + function transferTo(recipient, amount, revertFlag) { + // hardcoding f1f1f1f1 as custom calldata in case of a transfer + let formedCallData := mload(0x40) + let functionSelector := 0x3ecfd51e00000000000000000000000000000000000000000000000000000000 + mstore(formedCallData, functionSelector) + let success := call(gas(), recipient, amount, formedCallData, 0x20, 0, 0) + // Check if the transfer was successful + if iszero(success) { + // Revert the transaction if the transfer failed + revert(0, 0) + } + } + + // Function to revert with an error message + function revertWithError() { + // Define the error message in hexadecimal + let errorMessage := "Reverting" + + // Allocate memory for the error message + let errorMessageSize := 0x20 // 32 bytes + let errorMessageOffset := mload(0x40) // Load the free memory pointer + mstore(errorMessageOffset, errorMessage) + + // Revert with the error message + revert(errorMessageOffset, errorMessageSize) + } + + // 3ecfd51e90ed5312cd5bc47447919dde093173d93c6a98ab52ecf0cfc491e099 + // function selector 0x3ecfd51e + // we need this empty function in order for the contract to be sucessfully deployed + // using the java wrappers + function receiveETH() { + + } + } + } +} \ No newline at end of file diff --git a/testing/src/main/yul/YulContract.yul b/testing/src/main/yul/YulContract.yul deleted file mode 100644 index 52d9ee76ba..0000000000 --- a/testing/src/main/yul/YulContract.yul +++ /dev/null @@ -1,183 +0,0 @@ -object "YulContract" { - code { - // return the bytecode of the contract - datacopy(0x00, dataoffset("runtime"), datasize("runtime")) - return(0x00, datasize("runtime")) - } - - object "runtime" { - code { - switch selector() - case 0xa770741d // Write() - { - write() - } - - case 0x97deb47b // Read() - { - // store the ID to memory at 0x00 - mstore(0x00, sload(0x00)) - - return (0x00,0x20) - } - - case 0x0dd2602c // writeToStorage() - { - // Load the first argument (x) from calldata - let x := calldataload(0x04) - - // Load the second argument (y) from calldata - let y := calldataload(0x24) - - // call the writeToStorage function - writeToStorage(x, y) - - // log the call - logValuesWrite(x, y) - } - - case 0xd40e607a // readFromStorage() - { - // Load the first argument (x) from calldata - let x := calldataload(0x04) - - // call the readFromStorage function - let y := readFromStorage(x) - - // log the call - logValuesRead(x, y) - } - - case 0x3f5a0bdd // selfDestruct - { - // Load the first argument (recipient) from calldata - let recipient := calldataload(0x04) - - // log the call before self destructing - logSelfDestruct(recipient) - - // call the self-destruct function - selfDestruct(recipient) - } - - default { - // if the function signature sent does not match any - // of the contract functions, revert - revert(0, 0) - } - - function write() { - // take no inputs, push the 1234...EF 32 byte integer onto the stack - // add 0 as the slot key to the stack - // store the key/value - verbatim_0i_0o(hex"7f0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF600055") - } - - // Function to log two uint256 values for the write storage operation, along with the contract address - function logValuesWrite(x, y) { - // Define an event signature to generate logs for storage operations - let eventSignature := "Write(address,uint256,uint256)" // The signature is "Write(address,uint256,uint256)", signature length is 30 characters (thus 30 bytes) - - let memStart := mload(0x40) // get the free memory pointer - mstore(memStart, eventSignature) - - let eventSignatureHash := keccak256(memStart, 30) // expected 33d8dc4a860afa0606947f2b214f16e21e7eac41e3eb6642e859d9626d002ef6 - - // in the case of a delegate call, this will be the original that called the .Yul snippet. - // For a regular call, it will be the address of the .Yul contract. - let contractAddress := address() - - // call the inbuilt logging function - log4(0x20, 0x60, eventSignatureHash, contractAddress, x, y) - } - // Function to log two uint256 values for the read storage operation, along with the contract address - function logValuesRead(x, y) { - // Define an event signature to generate logs for storage operations - let eventSignatureHex := 0x5265616428616464726573732c75696e743235362c75696e7432353629202020 - // Above is the hex for "Read(address,uint256,uint256)", exact length is 29 characters, padded with 3 spaces (20 in hex) - // if we do not pad at the end, the hex is stored in the wrong manner. The spaces will be disregarded when we hash. - - let memStart := mload(0x40) // get the free memory pointer - mstore(memStart, eventSignatureHex) - - let eventSignatureHash := keccak256(memStart, 29) // 29 bytes is the string length, expected output c2db4694c1ec690e784f771a7fe3533681e081da4baa4aa1ad7dd5c33da95925 - - // in the case of a delegate call, this will be the original that called the .Yul snippet. - // For a regular call, it will be the address of the .Yul contract. - let contractAddress := address() - - // call the inbuilt logging function - log4(0x20, 0x60, eventSignatureHash, contractAddress, x, y) - } - - // Function to log the self destruction of the contract - function logSelfDestruct(recipient) { - // Define an event signature to generate logs for storage operations - let eventSignature := "ContractDestroyed(address)" - - let memStart := mload(0x40) // get the free memory pointer - mstore(memStart, eventSignature) - - let eventSignatureHash := keccak256(memStart, 26) // 26 bytes is the string length, expected output 3ab1d7915d663a46c292b8f01ac13567c748cff5213cb3652695882b5f9b2e0f - - // call the inbuilt logging function - log2(0x20, 0x60, eventSignatureHash, recipient) - } - - // 0x0dd2602cce131b717885742cf4e9a79978d80b588950101dc8619106202b5fd5 - // function signature: first 4 bytes 0x0dd2602c - // example of call: [["Addr",0x0dd2602c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001,0,0,0]] - // writeToStorage(uint256,uint256) is the unhashed function signature - function writeToStorage(x, y) { - // Use verbatim to include raw bytecode for storing y at storage key x - // 55 corresponds to SSTORE - verbatim_2i_0o(hex"55", x, y) - } - - // d40e607a2e462b02b78a86a129a210a71054c4774d1e5b71932b4e61bbd12df6 - // function signature: first 4 bytes 0xd40e607a - // example of call: [["Addr",0xd40e607a0000000000000000000000000000000000000000000000000000000000000001,0,0,0]] - // readFromStorage(uint256) is the unhashed function signature - function readFromStorage(x) -> y{ - // Use verbatim to include raw bytecode for reading the value stored at x - // 54 corresponds to SLOAD - y := verbatim_1i_1o(hex"54", x) - } - - /** - * @notice Selfdestructs and sends remaining ETH to a payable address. - * @dev Keep in mind you need to compile and target London EVM version - this doesn't work for repeat addresses on Cancun etc. - * @param _fundAddress The deploying contract's address. - * example of call: [["Addr",0x3f5a0bdd0000000000000000000000005b38da6a701c568545dcfcb03fcb875f56beddc4,0,0,0]] - * (replace the argument 5b38da6a701c568545dcfcb03fcb875f56beddc4 with the intended recipient, as needed) - **/ - function selfDestruct(recipient) { - // There is a weird bug with selfdestruct(recipient), so we replace that with verbatim - // Use verbatim to include the selfdestruct opcode (0xff) - verbatim_1i_0o(hex"ff", recipient) - } - - // Return the function selector: the first 4 bytes of the call data - function selector() -> s { - s := div(calldataload(0), 0x100000000000000000000000000000000000000000000000000000000) - } - - // Implementation of the require statement from Solidity - function require(condition) { - if iszero(condition) { revert(0, 0) } - } - - // Check if the calldata has the correct number of params - function checkParamLength(len) { - require(eq(calldatasize(), add(4, mul(32, len)))) - } - - // Transfer ether to the caller address - function transfer(amount) { - if iszero(call(gas(), caller(), amount, 0, 0, 0, 0)) { - revert(0,0) - } - } - } - } -} \ No newline at end of file From ec3bd1548cad48b2e9bdf5f3d86c284a8129569b Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Thu, 24 Oct 2024 01:26:02 +0200 Subject: [PATCH 37/74] Create StateManagerEvents.sol --- .../src/main/solidity/StateManagerEvents.sol | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 testing/src/main/solidity/StateManagerEvents.sol diff --git a/testing/src/main/solidity/StateManagerEvents.sol b/testing/src/main/solidity/StateManagerEvents.sol new file mode 100644 index 0000000000..b97975e1b0 --- /dev/null +++ b/testing/src/main/solidity/StateManagerEvents.sol @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: MIT +pragma solidity 0.8.26; + +/** + * @notice Shared contract containing framework events. + */ +abstract contract StateManagerEvents { + /// @dev The event for writing storage; + /// @param contractAddress is the contract addresss, x is the storage key and y is the storage value. + /// Event signature: 33d8dc4a860afa0606947f2b214f16e21e7eac41e3eb6642e859d9626d002ef6 + event Write(address contractAddress, uint256 x, uint256 y); + + /// @dev The event for reading storage; + /// @param contractAddress is the contract addresss, x is the storage key and y is the storage value. + /// the event will be generated after y is read as the value stored at x. + /// Event signature: c2db4694c1ec690e784f771a7fe3533681e081da4baa4aa1ad7dd5c33da95925 + event Read(address contractAddress, uint256 x, uint256 y); + + // Unhashed signature PayETH(address,address,uint256) + // Event signature: 86486637435fcc400fa51609bdb9068db32be14298e016223d7b7ffdae7998ff + event PayETH(address,address,uint256); + + // Received ETH event + // Unhashed signature RecETH(address,uint256) + // Event signature: e1b5c1e280a4d97847c2d5c3006bd406609f68889f3d868ed3250aa10a8629aa + event RecETH(address,uint256); +} From 9f9ace8a89b01f20c5b66322b3863e7766e6b59c Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Thu, 24 Oct 2024 02:47:38 +0200 Subject: [PATCH 38/74] first basic storage test --- .../zktracer/StateManagerSolidityTest.java | 143 ++++++++++++++++-- 1 file changed, 127 insertions(+), 16 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index f770975668..936f30ca2e 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -22,6 +22,12 @@ import net.consensys.linea.testing.generated.StateManagerEvents; import net.consensys.linea.testing.generated.TestSnippet_Events; import net.consensys.linea.testing.generated.TestingBase; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; +import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; +import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.SECP256K1; @@ -43,10 +49,7 @@ import org.web3j.abi.datatypes.generated.Uint256; import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.util.*; import java.util.function.Consumer; import static org.assertj.core.api.Fail.fail; @@ -70,7 +73,7 @@ String boolToHexString(boolean x) { // destination must be our .yul smart contract - Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, Long key, Long value, boolean revertFlag) { + Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, Long key, Long value, boolean revertFlag, BigInteger callType) { Function yulFunction = new Function("writeToStorage", Arrays.asList(new Uint256(BigInteger.valueOf(key)), new Uint256(BigInteger.valueOf(value)), new org.web3j.abi.datatypes.Bool(revertFlag)), Collections.emptyList()); @@ -82,7 +85,7 @@ Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), /*gasLimit*/ BigInteger.ZERO, /*value*/ BigInteger.ZERO, - /*callType*/ BigInteger.ZERO); + /*callType*/ callType); List contractCalls = List.of(snippetContractCall); Function frameworkEntryPointFunction = @@ -113,7 +116,7 @@ Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount // destination must be our .yul smart contract - Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, Long key, boolean revertFlag) { + Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, Long key, boolean revertFlag, BigInteger callType) { Function yulFunction = new Function("readFromStorage", Arrays.asList(new Uint256(BigInteger.valueOf(key)), new org.web3j.abi.datatypes.Bool(revertFlag)), Collections.emptyList()); @@ -126,7 +129,7 @@ Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), /*gasLimit*/ BigInteger.ZERO, /*value*/ BigInteger.ZERO, - /*callType*/ BigInteger.ZERO); + /*callType*/ callType); List contractCalls = List.of(snippetContractCall); Function frameworkEntryPointFunction = @@ -155,7 +158,7 @@ Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount } // destination must be our .yul smart contract - Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, ToyAccount recipient, boolean revertFlag) { + Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, ToyAccount recipient, boolean revertFlag, BigInteger callType) { String recipientAddressString = recipient.getAddress().toHexString(); Function yulFunction = new Function("selfDestruct", Arrays.asList(new org.web3j.abi.datatypes.Address(recipientAddressString), new org.web3j.abi.datatypes.Bool(revertFlag)), @@ -169,7 +172,7 @@ Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, ToyAccount de /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), /*gasLimit*/ BigInteger.ZERO, /*value*/ BigInteger.ZERO, - /*callType*/ BigInteger.ONE); // Normal call, not a delegate call as would be the default + /*callType*/ callType); // Normal call, not a delegate call as would be the default List contractCalls = List.of(snippetContractCall); Function frameworkEntryPointFunction = @@ -301,13 +304,101 @@ public void initializeTestContext() { @Test - void testYulModifiedWrite() { + void testBuildingBlockOperations() { // initialize the test context this.testContext = new TestContext(); this.testContext.initializeTestContext(); + TransactionProcessingResultValidator resultValidator = + (Transaction transaction, TransactionProcessingResult result) -> { + TransactionProcessingResultValidator.DEFAULT_VALIDATOR.accept(transaction, result); + // One event from the snippet + // One event from the framework entrypoint about contract call + System.out.println("Number of logs: "+result.getLogs().size()); + //assertEquals(result.getLogs().size(), 2); + for (Log log : result.getLogs()) { + String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); + String writeEventSignature = EventEncoder.encode(StateManagerEvents.WRITE_EVENT); + String readEventSignature = EventEncoder.encode(StateManagerEvents.READ_EVENT); + String destroyedEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); + String createdEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTCREATED_EVENT); + String logTopic = log.getTopics().getFirst().toHexString(); + if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { + TestSnippet_Events.DataNoIndexesEventResponse response = + TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); + //assertEquals(response.singleInt, BigInteger.valueOf(123456)); + } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) + .equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + if (logTopic.equals(createdEventSignature)) { + assertEquals(response.destination, this.testContext.frameworkEntryPointAccount.getAddress().toHexString()); + } else { + //assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); + } + } else { + if (!(logTopic.equals(callEventSignature) || logTopic.equals(writeEventSignature) || logTopic.equals(readEventSignature) || logTopic.equals(destroyedEventSignature) || logTopic.equals(createdEventSignature))) { + fail(); + } + } + } + }; + /* + TransactionProcessingResultValidator resultValidator = + (Transaction transaction, TransactionProcessingResult result) -> { + // One event from the snippet + // One event from the framework entrypoint about contract call + //assertEquals(result.getLogs().size(), 1); + System.out.println("Number of logs: "+result.getLogs().size()); + var noTopics = result.getLogs().size(); + for (Log log : result.getLogs()) { + String logTopic = log.getTopics().getFirst().toHexString(); + String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); + String writeEventSignature = EventEncoder.encode(FrameworkEntrypoint.WRITE_EVENT); + String readEventSignature = EventEncoder.encode(FrameworkEntrypoint.READ_EVENT); + String destructEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); + if (callEventSignature.equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); + continue; + } + if (writeEventSignature.equals(logTopic)) { + // write event + continue; + } + if (readEventSignature.equals(logTopic)) { + // read event + continue; + } + if (destructEventSignature.equals(logTopic)) { + // self destruct + continue; + } + fail(); + } + }; + */ + MultiBlockExecutionEnvironment.builder() + .accounts(List.of(this.testContext.initialAccounts[0], this.testContext.initialAccounts[1], this.testContext.frameworkEntryPointAccount)) + .addBlock(List.of(writeToStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, 1L, false, BigInteger.ZERO))) + .addBlock(List.of(readFromStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, false, BigInteger.ZERO))) + .addBlock(List.of(selfDestruct(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], testContext.frameworkEntryPointAccount, false, BigInteger.ZERO))) + .addBlock(List.of(deployWithCreate2(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.frameworkEntryPointAccount, "0x0000000000000000000000000000000000000000000000000000000000000002"))) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); + System.out.println("Done"); + } + @Test + void testConflationMap() { + // initialize the test context + this.testContext = new TestContext(); + this.testContext.initializeTestContext(); TransactionProcessingResultValidator resultValidator = (Transaction transaction, TransactionProcessingResult result) -> { TransactionProcessingResultValidator.DEFAULT_VALIDATOR.accept(transaction, result); @@ -380,17 +471,37 @@ void testYulModifiedWrite() { fail(); } }; - */ + + StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); + MultiBlockExecutionEnvironment.builder() .accounts(List.of(this.testContext.initialAccounts[0], this.testContext.initialAccounts[1], this.testContext.frameworkEntryPointAccount)) - .addBlock(List.of(writeToStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, 1L, false))) - .addBlock(List.of(readFromStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, false))) - .addBlock(List.of(selfDestruct(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], testContext.frameworkEntryPointAccount, false))) - .addBlock(List.of(deployWithCreate2(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.frameworkEntryPointAccount, "0x0000000000000000000000000000000000000000000000000000000000000002"))) + .addBlock(List.of(writeToStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, 8L, false, BigInteger.ONE))) + .addBlock(List.of(readFromStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, false, BigInteger.ONE))) + .addBlock(List.of(writeToStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, 10L, false, BigInteger.ONE))) + .addBlock(List.of(readFromStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, false, BigInteger.ONE))) + .addBlock(List.of(writeToStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, 15L, false, BigInteger.ONE))) .transactionProcessingResultValidator(resultValidator) .build() .run(); + + Map> + conflationMap = stateManagerMetadata.getAccountFirstLastConflationMap(); + Map> + conflationStorage = stateManagerMetadata.getStorageFirstLastConflationMap(); + + + TransactionProcessingMetadata.AddrStorageKeyPair key = new TransactionProcessingMetadata.AddrStorageKeyPair(testContext.initialAccounts[0].getAddress(), EWord.of(123L)); + TransactionProcessingMetadata. FragmentFirstAndLast storageData = conflationStorage.get(key); + + + assertEquals(storageData.getFirst().getValueNext(), EWord.of(8L)); + assertEquals(storageData.getLast().getValueNext(), EWord.of(15L)); + + System.out.println("Done"); } + + } \ No newline at end of file From c38f025b339a58f542ac3963142f311938787be3 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Thu, 24 Oct 2024 03:18:48 +0200 Subject: [PATCH 39/74] predict create2 address function wip --- .../zktracer/StateManagerSolidityTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index 936f30ca2e..dd965a7257 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -70,6 +70,33 @@ String boolToHexString(boolean x) { } } + + public static String calculateCreate2Address(byte[] senderAddress, byte[] salt, byte[] initCode) { + + // Calculate keccak256(init_code) + org.apache.tuweni.bytes.Bytes32 initCodeHash = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(initCode)); + + // Concatenate 0xff, sender_address, salt, and keccak256(init_code) + byte[] data = new byte[1 + senderAddress.length + salt.length + initCodeHash.size()]; + data[0] = (byte) 0xff; + System.arraycopy(senderAddress, 0, data, 1, senderAddress.length); + System.arraycopy(salt, 0, data, 1 + senderAddress.length, salt.length); + System.arraycopy(initCodeHash, 0, data, 1 + senderAddress.length + salt.length, initCodeHash.size()); + + // Calculate keccak256(data) + org.apache.tuweni.bytes.Bytes32 addressBytes = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(data)); + + // Take the last 20 bytes of the hash result + byte[] resultAddressBytes = new byte[20]; + System.arraycopy(addressBytes, 12, resultAddressBytes, 0, 20); + + // Convert the result to a hex string + return "0x" + resultAddressBytes.toString(); + } + + + + // destination must be our .yul smart contract From 0d4ad1f3a1157fa2e5a1a3ae4d1a23ba3df6ca21 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Thu, 24 Oct 2024 17:45:39 +0200 Subject: [PATCH 40/74] testing writes after creates --- .../zktracer/StateManagerSolidityTest.java | 106 ++++++++++-------- 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index dd965a7257..4b1c431869 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -21,11 +21,11 @@ import net.consensys.linea.testing.generated.FrameworkEntrypoint; import net.consensys.linea.testing.generated.StateManagerEvents; import net.consensys.linea.testing.generated.TestSnippet_Events; -import net.consensys.linea.testing.generated.TestingBase; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; +import net.consensys.linea.zktracer.types.AddressUtils; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; @@ -40,23 +40,18 @@ import org.junit.jupiter.api.Test; import org.web3j.abi.EventEncoder; import org.web3j.abi.FunctionEncoder; -import org.web3j.abi.TypeReference; import org.web3j.abi.datatypes.DynamicArray; -import org.web3j.abi.datatypes.DynamicBytes; import org.web3j.abi.datatypes.Function; -import org.web3j.abi.datatypes.Type; -import org.web3j.abi.datatypes.generated.Bytes32; import org.web3j.abi.datatypes.generated.Uint256; import java.math.BigInteger; import java.util.*; -import java.util.function.Consumer; import static org.assertj.core.api.Fail.fail; import static org.junit.jupiter.api.Assertions.*; public class StateManagerSolidityTest { - TestContext testContext; + TestContext ctxt; enum RevertFlag { DISABLED, ENABLED @@ -70,7 +65,7 @@ String boolToHexString(boolean x) { } } - + public static String calculateCreate2Address(byte[] senderAddress, byte[] salt, byte[] initCode) { // Calculate keccak256(init_code) @@ -100,7 +95,7 @@ public static String calculateCreate2Address(byte[] senderAddress, byte[] salt, // destination must be our .yul smart contract - Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, Long key, Long value, boolean revertFlag, BigInteger callType) { + Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, Address destination, Long key, Long value, boolean revertFlag, BigInteger callType) { Function yulFunction = new Function("writeToStorage", Arrays.asList(new Uint256(BigInteger.valueOf(key)), new Uint256(BigInteger.valueOf(value)), new org.web3j.abi.datatypes.Bool(revertFlag)), Collections.emptyList()); @@ -108,7 +103,7 @@ Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount var encoding = FunctionEncoder.encode(yulFunction); FrameworkEntrypoint.ContractCall snippetContractCall = new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.getAddress().toHexString(), + /*Address*/ destination.toHexString(), /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), /*gasLimit*/ BigInteger.ZERO, /*value*/ BigInteger.ZERO, @@ -126,7 +121,7 @@ Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() .sender(sender) - .to(this.testContext.frameworkEntryPointAccount) + .to(this.ctxt.frameworkEntryPointAccount) .payload(txPayload) .keyPair(senderKeyPair) .gasLimit(TestContext.gasLimit); @@ -143,7 +138,7 @@ Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount // destination must be our .yul smart contract - Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, Long key, boolean revertFlag, BigInteger callType) { + Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, Address destination, Long key, boolean revertFlag, BigInteger callType) { Function yulFunction = new Function("readFromStorage", Arrays.asList(new Uint256(BigInteger.valueOf(key)), new org.web3j.abi.datatypes.Bool(revertFlag)), Collections.emptyList()); @@ -152,7 +147,7 @@ Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount var encoding = FunctionEncoder.encode(yulFunction); FrameworkEntrypoint.ContractCall snippetContractCall = new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.getAddress().toHexString(), + /*Address*/ destination.toHexString(), /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), /*gasLimit*/ BigInteger.ZERO, /*value*/ BigInteger.ZERO, @@ -169,7 +164,7 @@ Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() .sender(sender) - .to(this.testContext.frameworkEntryPointAccount) + .to(this.ctxt.frameworkEntryPointAccount) .payload(txPayload) .keyPair(senderKeyPair) .gasLimit(TestContext.gasLimit); @@ -185,7 +180,7 @@ Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, ToyAccount } // destination must be our .yul smart contract - Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, ToyAccount recipient, boolean revertFlag, BigInteger callType) { + Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, Address destination, ToyAccount recipient, boolean revertFlag, BigInteger callType) { String recipientAddressString = recipient.getAddress().toHexString(); Function yulFunction = new Function("selfDestruct", Arrays.asList(new org.web3j.abi.datatypes.Address(recipientAddressString), new org.web3j.abi.datatypes.Bool(revertFlag)), @@ -195,7 +190,7 @@ Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, ToyAccount de var encoding = FunctionEncoder.encode(yulFunction); FrameworkEntrypoint.ContractCall snippetContractCall = new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.getAddress().toHexString(), + /*Address*/ destination.toHexString(), /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), /*gasLimit*/ BigInteger.ZERO, /*value*/ BigInteger.ZERO, @@ -212,7 +207,7 @@ Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, ToyAccount de ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() .sender(sender) - .to(this.testContext.frameworkEntryPointAccount) + .to(this.ctxt.frameworkEntryPointAccount) .payload(txPayload) .keyPair(senderKeyPair) .gasLimit(TestContext.gasLimit); @@ -228,7 +223,7 @@ Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, ToyAccount de } // destination must be our .yul smart contract - Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, ToyAccount destination, String saltString) { + Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, Address destination, String saltString) { Bytes salt = Bytes.fromHexStringLenient(saltString); // the following are the bytecode of the .yul contract Bytes yulContractBytes = Bytes.fromHexStringLenient("61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); @@ -244,7 +239,7 @@ Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, ToyAccou FrameworkEntrypoint.ContractCall snippetContractCall = new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.getAddress().toHexString(), + /*Address*/ destination.toHexString(), /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), /*gasLimit*/ BigInteger.ZERO, /*value*/ BigInteger.ZERO, @@ -263,7 +258,7 @@ Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, ToyAccou ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() .sender(sender) - .to(this.testContext.frameworkEntryPointAccount) + .to(this.ctxt.frameworkEntryPointAccount) .payload(txPayload) .keyPair(senderKeyPair) .gasLimit(TestContext.gasLimit); @@ -283,15 +278,19 @@ Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, ToyAccou class TestContext { static Long txNonce = null; static final Long gasLimit = 5000000L; - static final int numberOfAccounts = 3; + static final int numberOfAccounts = 4; + static final Bytes snippetsCode = SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul"); @Getter ToyAccount frameworkEntryPointAccount; + Address frameworkEntryPointAddress; ToyAccount[] initialAccounts; + Address[] addresses; KeyPair[] initialKeyPairs; public void initializeTestContext() { // initialize vectors initialAccounts = new ToyAccount[numberOfAccounts]; initialKeyPairs = new KeyPair[numberOfAccounts]; + addresses = new Address[numberOfAccounts]; // initialize the testing framework entry point account frameworkEntryPointAccount = ToyAccount.builder() @@ -300,6 +299,7 @@ public void initializeTestContext() { .nonce(5) .code(SmartContractUtils.getSolidityContractByteCode(FrameworkEntrypoint.class)) .build(); + frameworkEntryPointAddress = frameworkEntryPointAccount.getAddress(); // initialize the .yul snippets account // load the .yul bytecode initialAccounts[0] = @@ -309,6 +309,7 @@ public void initializeTestContext() { .nonce(6) .code(SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul")) .build(); + addresses[0] = initialAccounts[0].getAddress(); // generate extra accounts KeyPair keyPair = new SECP256K1().generateKeyPair(); Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); @@ -317,6 +318,7 @@ public void initializeTestContext() { // add to arrays initialAccounts[1] = senderAccount; initialKeyPairs[1] = keyPair; + addresses[1] = initialAccounts[1].getAddress(); // an account with revert initialAccounts[2] = ToyAccount.builder() @@ -325,6 +327,7 @@ public void initializeTestContext() { .nonce(8) .code(SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul")) .build(); + addresses[2] = initialAccounts[2].getAddress(); } } @@ -333,8 +336,8 @@ public void initializeTestContext() { @Test void testBuildingBlockOperations() { // initialize the test context - this.testContext = new TestContext(); - this.testContext.initializeTestContext(); + this.ctxt = new TestContext(); + this.ctxt.initializeTestContext(); TransactionProcessingResultValidator resultValidator = (Transaction transaction, TransactionProcessingResult result) -> { TransactionProcessingResultValidator.DEFAULT_VALIDATOR.accept(transaction, result); @@ -359,7 +362,7 @@ void testBuildingBlockOperations() { FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); assertTrue(response.isSuccess); if (logTopic.equals(createdEventSignature)) { - assertEquals(response.destination, this.testContext.frameworkEntryPointAccount.getAddress().toHexString()); + assertEquals(response.destination, this.ctxt.frameworkEntryPointAccount.getAddress().toHexString()); } else { //assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); } @@ -410,11 +413,11 @@ void testBuildingBlockOperations() { */ MultiBlockExecutionEnvironment.builder() - .accounts(List.of(this.testContext.initialAccounts[0], this.testContext.initialAccounts[1], this.testContext.frameworkEntryPointAccount)) - .addBlock(List.of(writeToStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, 1L, false, BigInteger.ZERO))) - .addBlock(List.of(readFromStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, false, BigInteger.ZERO))) - .addBlock(List.of(selfDestruct(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], testContext.frameworkEntryPointAccount, false, BigInteger.ZERO))) - .addBlock(List.of(deployWithCreate2(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.frameworkEntryPointAccount, "0x0000000000000000000000000000000000000000000000000000000000000002"))) + .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 1L, false, BigInteger.ZERO))) + .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ZERO))) + .addBlock(List.of(selfDestruct(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.frameworkEntryPointAccount, false, BigInteger.ZERO))) + .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002"))) .transactionProcessingResultValidator(resultValidator) .build() .run(); @@ -424,8 +427,8 @@ void testBuildingBlockOperations() { @Test void testConflationMap() { // initialize the test context - this.testContext = new TestContext(); - this.testContext.initializeTestContext(); + this.ctxt = new TestContext(); + this.ctxt.initializeTestContext(); TransactionProcessingResultValidator resultValidator = (Transaction transaction, TransactionProcessingResult result) -> { TransactionProcessingResultValidator.DEFAULT_VALIDATOR.accept(transaction, result); @@ -450,7 +453,7 @@ void testConflationMap() { FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); assertTrue(response.isSuccess); if (logTopic.equals(createdEventSignature)) { - assertEquals(response.destination, this.testContext.frameworkEntryPointAccount.getAddress().toHexString()); + assertEquals(response.destination, this.ctxt.frameworkEntryPointAccount.getAddress().toHexString()); } else { //assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); } @@ -501,14 +504,23 @@ void testConflationMap() { */ StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); + org.apache.tuweni.bytes.Bytes32 initCodeHash = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(TestContext.snippetsCode)); + org.apache.tuweni.bytes.Bytes32 targetAddress = AddressUtils.getCreate2RawAddress(ctxt.frameworkEntryPointAccount.getAddress(), + org.apache.tuweni.bytes.Bytes32.wrap(Bytes.fromHexStringLenient("0x0000000000000000000000000000000000000000000000000000000000000002").toArray()), + initCodeHash); + ctxt.addresses[3] = Address.extract(targetAddress); MultiBlockExecutionEnvironment.builder() - .accounts(List.of(this.testContext.initialAccounts[0], this.testContext.initialAccounts[1], this.testContext.frameworkEntryPointAccount)) - .addBlock(List.of(writeToStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, 8L, false, BigInteger.ONE))) - .addBlock(List.of(readFromStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, false, BigInteger.ONE))) - .addBlock(List.of(writeToStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, 10L, false, BigInteger.ONE))) - .addBlock(List.of(readFromStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, false, BigInteger.ONE))) - .addBlock(List.of(writeToStorage(testContext.initialAccounts[1], testContext.initialKeyPairs[1], testContext.initialAccounts[0], 123L, 15L, false, BigInteger.ONE))) + .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 8L, false, BigInteger.ONE))) + .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ONE))) + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 10L, false, BigInteger.ONE))) + .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ONE))) + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 15L, false, BigInteger.ONE))) + .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002"))) + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, 20L, false, BigInteger.ONE))) + .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, false, BigInteger.ONE))) + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, 40L, false, BigInteger.ONE))) .transactionProcessingResultValidator(resultValidator) .build() .run(); @@ -518,15 +530,17 @@ void testConflationMap() { Map> conflationStorage = stateManagerMetadata.getStorageFirstLastConflationMap(); + EWord[] expectedFirst = {EWord.of(8L), EWord.of(20L)}; + EWord[] expectedLast = {EWord.of(15L), EWord.of(40L)}; + TransactionProcessingMetadata.AddrStorageKeyPair[] keys = {new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.initialAccounts[0].getAddress(), EWord.of(123L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.addresses[3], EWord.of(345L)) + }; - TransactionProcessingMetadata.AddrStorageKeyPair key = new TransactionProcessingMetadata.AddrStorageKeyPair(testContext.initialAccounts[0].getAddress(), EWord.of(123L)); - TransactionProcessingMetadata. FragmentFirstAndLast storageData = conflationStorage.get(key); - - - assertEquals(storageData.getFirst().getValueNext(), EWord.of(8L)); - assertEquals(storageData.getLast().getValueNext(), EWord.of(15L)); - - + for (int i = 0; i < keys.length; i++) { + TransactionProcessingMetadata. FragmentFirstAndLast storageData = conflationStorage.get(keys[i]); + assertEquals(storageData.getFirst().getValueNext(), expectedFirst[i]); + assertEquals(storageData.getLast().getValueNext(), expectedLast[i]); + } System.out.println("Done"); } From 94a08a50d6f4d7c8075ca186ac64cfc3ebb96044 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Thu, 24 Oct 2024 18:33:29 +0200 Subject: [PATCH 41/74] debugging create2 --- .../zktracer/StateManagerSolidityTest.java | 200 ++++++------------ 1 file changed, 70 insertions(+), 130 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index 4b1c431869..c36a71a032 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -21,6 +21,7 @@ import net.consensys.linea.testing.generated.FrameworkEntrypoint; import net.consensys.linea.testing.generated.StateManagerEvents; import net.consensys.linea.testing.generated.TestSnippet_Events; +import net.consensys.linea.testing.generated.TestingBase; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; @@ -223,16 +224,16 @@ Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, Address desti } // destination must be our .yul smart contract - Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, Address destination, String saltString) { + Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, Address destination, String saltString, Bytes contractBytes) { Bytes salt = Bytes.fromHexStringLenient(saltString); - // the following are the bytecode of the .yul contract - Bytes yulContractBytes = Bytes.fromHexStringLenient("61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); + // the following is the bytecode of the .yul contract + // Bytes yulContractBytes = Bytes.fromHexStringLenient("61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); // prepare the Create2 function Function create2Function = new Function( FrameworkEntrypoint.FUNC_DEPLOYWITHCREATE2, Arrays.asList(new org.web3j.abi.datatypes.generated.Bytes32(salt.toArray()), - new org.web3j.abi.datatypes.DynamicBytes(yulContractBytes.toArray())), + new org.web3j.abi.datatypes.DynamicBytes(contractBytes.toArray())), Collections.emptyList()); String encoding = FunctionEncoder.encode(create2Function); @@ -331,13 +332,7 @@ public void initializeTestContext() { } } - - - @Test - void testBuildingBlockOperations() { - // initialize the test context - this.ctxt = new TestContext(); - this.ctxt.initializeTestContext(); + TransactionProcessingResultValidator getValidator() { TransactionProcessingResultValidator resultValidator = (Transaction transaction, TransactionProcessingResult result) -> { TransactionProcessingResultValidator.DEFAULT_VALIDATOR.accept(transaction, result); @@ -373,99 +368,88 @@ void testBuildingBlockOperations() { } } }; + return resultValidator; + } - /* - TransactionProcessingResultValidator resultValidator = - (Transaction transaction, TransactionProcessingResult result) -> { - // One event from the snippet - // One event from the framework entrypoint about contract call - //assertEquals(result.getLogs().size(), 1); - System.out.println("Number of logs: "+result.getLogs().size()); - var noTopics = result.getLogs().size(); - for (Log log : result.getLogs()) { - String logTopic = log.getTopics().getFirst().toHexString(); - String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); - String writeEventSignature = EventEncoder.encode(FrameworkEntrypoint.WRITE_EVENT); - String readEventSignature = EventEncoder.encode(FrameworkEntrypoint.READ_EVENT); - String destructEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); - if (callEventSignature.equals(logTopic)) { - FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - assertTrue(response.isSuccess); - assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); - continue; - } - if (writeEventSignature.equals(logTopic)) { - // write event - continue; - } - if (readEventSignature.equals(logTopic)) { - // read event - continue; - } - if (destructEventSignature.equals(logTopic)) { - // self destruct - continue; - } - fail(); - } - }; - */ + @Test + void testBuildingBlockOperations() { + // initialize the test context + this.ctxt = new TestContext(); + this.ctxt.initializeTestContext(); + TransactionProcessingResultValidator resultValidator = getValidator(); MultiBlockExecutionEnvironment.builder() .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 1L, false, BigInteger.ZERO))) .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ZERO))) .addBlock(List.of(selfDestruct(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.frameworkEntryPointAccount, false, BigInteger.ZERO))) - .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002"))) + .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCode))) .transactionProcessingResultValidator(resultValidator) .build() .run(); System.out.println("Done"); } + + @Test void testConflationMap() { // initialize the test context this.ctxt = new TestContext(); this.ctxt.initializeTestContext(); - TransactionProcessingResultValidator resultValidator = - (Transaction transaction, TransactionProcessingResult result) -> { - TransactionProcessingResultValidator.DEFAULT_VALIDATOR.accept(transaction, result); - // One event from the snippet - // One event from the framework entrypoint about contract call - System.out.println("Number of logs: "+result.getLogs().size()); - //assertEquals(result.getLogs().size(), 2); - for (Log log : result.getLogs()) { - String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); - String writeEventSignature = EventEncoder.encode(StateManagerEvents.WRITE_EVENT); - String readEventSignature = EventEncoder.encode(StateManagerEvents.READ_EVENT); - String destroyedEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); - String createdEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTCREATED_EVENT); - String logTopic = log.getTopics().getFirst().toHexString(); - if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { - TestSnippet_Events.DataNoIndexesEventResponse response = - TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); - //assertEquals(response.singleInt, BigInteger.valueOf(123456)); - } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) - .equals(logTopic)) { - FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - assertTrue(response.isSuccess); - if (logTopic.equals(createdEventSignature)) { - assertEquals(response.destination, this.ctxt.frameworkEntryPointAccount.getAddress().toHexString()); - } else { - //assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); - } - } else { - if (!(logTopic.equals(callEventSignature) || logTopic.equals(writeEventSignature) || logTopic.equals(readEventSignature) || logTopic.equals(destroyedEventSignature) || logTopic.equals(createdEventSignature))) { - fail(); - } - } - } - }; + TransactionProcessingResultValidator resultValidator = getValidator(); + + + + + StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); + org.apache.tuweni.bytes.Bytes32 initCodeHash = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(TestContext.snippetsCode)); + org.apache.tuweni.bytes.Bytes32 targetAddress = AddressUtils.getCreate2RawAddress(ctxt.frameworkEntryPointAccount.getAddress(), + org.apache.tuweni.bytes.Bytes32.wrap(Bytes.fromHexStringLenient("0x0000000000000000000000000000000000000000000000000000000000000002").toArray()), + initCodeHash); + ctxt.addresses[3] = Address.extract(targetAddress); + + MultiBlockExecutionEnvironment.builder() + .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) + //.addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 8L, false, BigInteger.ONE))) + /*.addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ONE))) + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 10L, false, BigInteger.ONE))) + .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ONE))) + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 15L, false, BigInteger.ONE))) + */ + .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCode))) + //.addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCode))) + //.addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, 20L, false, BigInteger.ONE))) + //.addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, false, BigInteger.ONE))) + //.addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, 40L, false, BigInteger.ONE))) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); + + Map> + conflationMap = stateManagerMetadata.getAccountFirstLastConflationMap(); + Map> + conflationStorage = stateManagerMetadata.getStorageFirstLastConflationMap(); + + EWord[] expectedFirst = {EWord.of(8L), EWord.of(20L)}; + EWord[] expectedLast = {EWord.of(15L), EWord.of(40L)}; + TransactionProcessingMetadata.AddrStorageKeyPair[] keys = {new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.initialAccounts[0].getAddress(), EWord.of(123L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.addresses[3], EWord.of(345L)) + }; + + for (int i = 0; i < keys.length-1; i++) { + TransactionProcessingMetadata. FragmentFirstAndLast storageData = conflationStorage.get(keys[i]); + //assertEquals(storageData.getFirst().getValueNext(), expectedFirst[i]); + //assertEquals(storageData.getLast().getValueNext(), expectedLast[i]); + } + System.out.println("Done"); + } - /* + +} + + +/* TransactionProcessingResultValidator resultValidator = (Transaction transaction, TransactionProcessingResult result) -> { // One event from the snippet @@ -501,48 +485,4 @@ void testConflationMap() { fail(); } }; - */ - - StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); - org.apache.tuweni.bytes.Bytes32 initCodeHash = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(TestContext.snippetsCode)); - org.apache.tuweni.bytes.Bytes32 targetAddress = AddressUtils.getCreate2RawAddress(ctxt.frameworkEntryPointAccount.getAddress(), - org.apache.tuweni.bytes.Bytes32.wrap(Bytes.fromHexStringLenient("0x0000000000000000000000000000000000000000000000000000000000000002").toArray()), - initCodeHash); - ctxt.addresses[3] = Address.extract(targetAddress); - - MultiBlockExecutionEnvironment.builder() - .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 8L, false, BigInteger.ONE))) - .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ONE))) - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 10L, false, BigInteger.ONE))) - .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ONE))) - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 15L, false, BigInteger.ONE))) - .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002"))) - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, 20L, false, BigInteger.ONE))) - .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, false, BigInteger.ONE))) - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, 40L, false, BigInteger.ONE))) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); - - Map> - conflationMap = stateManagerMetadata.getAccountFirstLastConflationMap(); - Map> - conflationStorage = stateManagerMetadata.getStorageFirstLastConflationMap(); - - EWord[] expectedFirst = {EWord.of(8L), EWord.of(20L)}; - EWord[] expectedLast = {EWord.of(15L), EWord.of(40L)}; - TransactionProcessingMetadata.AddrStorageKeyPair[] keys = {new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.initialAccounts[0].getAddress(), EWord.of(123L)), - new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.addresses[3], EWord.of(345L)) - }; - - for (int i = 0; i < keys.length; i++) { - TransactionProcessingMetadata. FragmentFirstAndLast storageData = conflationStorage.get(keys[i]); - assertEquals(storageData.getFirst().getValueNext(), expectedFirst[i]); - assertEquals(storageData.getLast().getValueNext(), expectedLast[i]); - } - System.out.println("Done"); - } - - -} \ No newline at end of file + */ \ No newline at end of file From 669c3607bc09a734e98c05e296114416496bd446 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Thu, 24 Oct 2024 19:01:04 +0200 Subject: [PATCH 42/74] testing create2 storage --- .../zktracer/StateManagerSolidityTest.java | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index c36a71a032..2efa90d22f 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -281,6 +281,7 @@ class TestContext { static final Long gasLimit = 5000000L; static final int numberOfAccounts = 4; static final Bytes snippetsCode = SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul"); + static final Bytes snippetsCodeForCreate2 = Bytes.fromHexStringLenient("0x61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); @Getter ToyAccount frameworkEntryPointAccount; Address frameworkEntryPointAddress; @@ -383,7 +384,24 @@ void testBuildingBlockOperations() { .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 1L, false, BigInteger.ZERO))) .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ZERO))) .addBlock(List.of(selfDestruct(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.frameworkEntryPointAccount, false, BigInteger.ZERO))) - .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCode))) + .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); + System.out.println("Done"); + } + + // Create 2 has a weird behavior and does not seem to work with the + // bytecode output by the function SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul") + @Test + void testCreate2Snippets() { +// initialize the test context + this.ctxt = new TestContext(); + this.ctxt.initializeTestContext(); + TransactionProcessingResultValidator resultValidator = getValidator(); + MultiBlockExecutionEnvironment.builder() + .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) + .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) .transactionProcessingResultValidator(resultValidator) .build() .run(); @@ -403,7 +421,7 @@ void testConflationMap() { StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); - org.apache.tuweni.bytes.Bytes32 initCodeHash = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(TestContext.snippetsCode)); + org.apache.tuweni.bytes.Bytes32 initCodeHash = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(TestContext.snippetsCodeForCreate2)); org.apache.tuweni.bytes.Bytes32 targetAddress = AddressUtils.getCreate2RawAddress(ctxt.frameworkEntryPointAccount.getAddress(), org.apache.tuweni.bytes.Bytes32.wrap(Bytes.fromHexStringLenient("0x0000000000000000000000000000000000000000000000000000000000000002").toArray()), initCodeHash); @@ -411,17 +429,15 @@ void testConflationMap() { MultiBlockExecutionEnvironment.builder() .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) - //.addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 8L, false, BigInteger.ONE))) - /*.addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ONE))) + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 8L, false, BigInteger.ONE))) + .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ONE))) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 10L, false, BigInteger.ONE))) .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ONE))) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 15L, false, BigInteger.ONE))) - */ - .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCode))) - //.addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCode))) - //.addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, 20L, false, BigInteger.ONE))) - //.addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, false, BigInteger.ONE))) - //.addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, 40L, false, BigInteger.ONE))) + .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, 20L, false, BigInteger.ONE))) + .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, false, BigInteger.ONE))) + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, 40L, false, BigInteger.ONE))) .transactionProcessingResultValidator(resultValidator) .build() .run(); @@ -437,18 +453,20 @@ void testConflationMap() { new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.addresses[3], EWord.of(345L)) }; - for (int i = 0; i < keys.length-1; i++) { + for (int i = 0; i < keys.length; i++) { TransactionProcessingMetadata. FragmentFirstAndLast storageData = conflationStorage.get(keys[i]); - //assertEquals(storageData.getFirst().getValueNext(), expectedFirst[i]); - //assertEquals(storageData.getLast().getValueNext(), expectedLast[i]); + assertEquals(storageData.getFirst().getValueNext(), expectedFirst[i]); + assertEquals(storageData.getLast().getValueNext(), expectedLast[i]); } System.out.println("Done"); } -} + +} + /* TransactionProcessingResultValidator resultValidator = (Transaction transaction, TransactionProcessingResult result) -> { From 4c33994910ac96690a50cb89cc288d305d304e8a Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 25 Oct 2024 00:47:13 +0200 Subject: [PATCH 43/74] refactor --- .../zktracer/StateManagerSolidityTest.java | 30 +------------------ 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index 2efa90d22f..e89dc7188a 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -67,34 +67,6 @@ String boolToHexString(boolean x) { } - public static String calculateCreate2Address(byte[] senderAddress, byte[] salt, byte[] initCode) { - - // Calculate keccak256(init_code) - org.apache.tuweni.bytes.Bytes32 initCodeHash = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(initCode)); - - // Concatenate 0xff, sender_address, salt, and keccak256(init_code) - byte[] data = new byte[1 + senderAddress.length + salt.length + initCodeHash.size()]; - data[0] = (byte) 0xff; - System.arraycopy(senderAddress, 0, data, 1, senderAddress.length); - System.arraycopy(salt, 0, data, 1 + senderAddress.length, salt.length); - System.arraycopy(initCodeHash, 0, data, 1 + senderAddress.length + salt.length, initCodeHash.size()); - - // Calculate keccak256(data) - org.apache.tuweni.bytes.Bytes32 addressBytes = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(data)); - - // Take the last 20 bytes of the hash result - byte[] resultAddressBytes = new byte[20]; - System.arraycopy(addressBytes, 12, resultAddressBytes, 0, 20); - - // Convert the result to a hex string - return "0x" + resultAddressBytes.toString(); - } - - - - - - // destination must be our .yul smart contract Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, Address destination, Long key, Long value, boolean revertFlag, BigInteger callType) { Function yulFunction = new Function("writeToStorage", @@ -309,7 +281,7 @@ public void initializeTestContext() { .address(Address.fromHexString("0x11111")) .balance(Wei.ONE) .nonce(6) - .code(SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul")) + .code(TestContext.snippetsCode) .build(); addresses[0] = initialAccounts[0].getAddress(); // generate extra accounts From 6e29c452a33bbe9865e52429434adf96b8a41d59 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 25 Oct 2024 00:54:58 +0200 Subject: [PATCH 44/74] bug in bytecode --- .../consensys/linea/zktracer/StateManagerSolidityTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index e89dc7188a..98cc76ca9a 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -373,7 +373,12 @@ void testCreate2Snippets() { TransactionProcessingResultValidator resultValidator = getValidator(); MultiBlockExecutionEnvironment.builder() .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) - .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of( + deployWithCreate2(ctxt.initialAccounts[1], + ctxt.initialKeyPairs[1], + ctxt.frameworkEntryPointAddress, + "0x0000000000000000000000000000000000000000000000000000000000000002", + TestContext.snippetsCode))) .transactionProcessingResultValidator(resultValidator) .build() .run(); From 3612c888ee35adff7f9cfc370dd44bb6c30376ec Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 25 Oct 2024 00:56:44 +0200 Subject: [PATCH 45/74] bug in bytecode --- .../net/consensys/linea/zktracer/StateManagerSolidityTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index 98cc76ca9a..c9941be02b 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -378,7 +378,7 @@ void testCreate2Snippets() { ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", - TestContext.snippetsCode))) + SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul")))) .transactionProcessingResultValidator(resultValidator) .build() .run(); From b643a5d9cd428d797499749c0f1361f9f801fe83 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 25 Oct 2024 01:22:10 +0200 Subject: [PATCH 46/74] self destructs --- .../zktracer/StateManagerSolidityTest.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index c9941be02b..f67f161123 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -153,8 +153,8 @@ Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, Address de } // destination must be our .yul smart contract - Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, Address destination, ToyAccount recipient, boolean revertFlag, BigInteger callType) { - String recipientAddressString = recipient.getAddress().toHexString(); + Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, Address destination, Address recipient, boolean revertFlag, BigInteger callType) { + String recipientAddressString = recipient.toHexString(); Function yulFunction = new Function("selfDestruct", Arrays.asList(new org.web3j.abi.datatypes.Address(recipientAddressString), new org.web3j.abi.datatypes.Bool(revertFlag)), Collections.emptyList()); @@ -251,7 +251,7 @@ Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, Address class TestContext { static Long txNonce = null; static final Long gasLimit = 5000000L; - static final int numberOfAccounts = 4; + static final int numberOfAccounts = 5; static final Bytes snippetsCode = SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul"); static final Bytes snippetsCodeForCreate2 = Bytes.fromHexStringLenient("0x61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); @Getter @@ -355,7 +355,7 @@ void testBuildingBlockOperations() { .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 1L, false, BigInteger.ZERO))) .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ZERO))) - .addBlock(List.of(selfDestruct(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.frameworkEntryPointAccount, false, BigInteger.ZERO))) + .addBlock(List.of(selfDestruct(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.frameworkEntryPointAddress, false, BigInteger.ZERO))) .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) .transactionProcessingResultValidator(resultValidator) .build() @@ -404,6 +404,11 @@ void testConflationMap() { initCodeHash); ctxt.addresses[3] = Address.extract(targetAddress); + org.apache.tuweni.bytes.Bytes32 targetAddress2 = AddressUtils.getCreate2RawAddress(ctxt.frameworkEntryPointAccount.getAddress(), + org.apache.tuweni.bytes.Bytes32.wrap(Bytes.fromHexStringLenient("0x0000000000000000000000000000000000000000000000000000000000000003").toArray()), + initCodeHash); + ctxt.addresses[4] = Address.extract(targetAddress); + MultiBlockExecutionEnvironment.builder() .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 8L, false, BigInteger.ONE))) @@ -415,6 +420,11 @@ void testConflationMap() { .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, 20L, false, BigInteger.ONE))) .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, false, BigInteger.ONE))) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, 40L, false, BigInteger.ONE))) + .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, 12L, false, BigInteger.ONE))) + .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, false, BigInteger.ONE))) + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, 13L, false, BigInteger.ONE))) + .addBlock(List.of(selfDestruct(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, ctxt.addresses[4], false, BigInteger.ONE))) .transactionProcessingResultValidator(resultValidator) .build() .run(); @@ -424,10 +434,12 @@ void testConflationMap() { Map> conflationStorage = stateManagerMetadata.getStorageFirstLastConflationMap(); - EWord[] expectedFirst = {EWord.of(8L), EWord.of(20L)}; - EWord[] expectedLast = {EWord.of(15L), EWord.of(40L)}; - TransactionProcessingMetadata.AddrStorageKeyPair[] keys = {new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.initialAccounts[0].getAddress(), EWord.of(123L)), - new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.addresses[3], EWord.of(345L)) + EWord[] expectedFirst = {EWord.of(8L), EWord.of(20L), EWord.of(12L)}; + EWord[] expectedLast = {EWord.of(15L), EWord.of(40L), EWord.of(13L)}; + TransactionProcessingMetadata.AddrStorageKeyPair[] keys = { + new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.initialAccounts[0].getAddress(), EWord.of(123L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.addresses[3], EWord.of(345L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.addresses[4], EWord.of(400L)) }; for (int i = 0; i < keys.length; i++) { From 97287485961ae944c49caeb6becd726f9a77bd42 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 25 Oct 2024 01:23:44 +0200 Subject: [PATCH 47/74] typo --- .../net/consensys/linea/zktracer/StateManagerSolidityTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index f67f161123..d5ba5f026e 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -407,7 +407,7 @@ void testConflationMap() { org.apache.tuweni.bytes.Bytes32 targetAddress2 = AddressUtils.getCreate2RawAddress(ctxt.frameworkEntryPointAccount.getAddress(), org.apache.tuweni.bytes.Bytes32.wrap(Bytes.fromHexStringLenient("0x0000000000000000000000000000000000000000000000000000000000000003").toArray()), initCodeHash); - ctxt.addresses[4] = Address.extract(targetAddress); + ctxt.addresses[4] = Address.extract(targetAddress2); MultiBlockExecutionEnvironment.builder() .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) From 15f9036162fd1ff1ed74116c3d54e718abd8002f Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 25 Oct 2024 01:37:50 +0200 Subject: [PATCH 48/74] adding some reverts --- .../zktracer/StateManagerSolidityTest.java | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index d5ba5f026e..23a77230ee 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -22,6 +22,7 @@ import net.consensys.linea.testing.generated.StateManagerEvents; import net.consensys.linea.testing.generated.TestSnippet_Events; import net.consensys.linea.testing.generated.TestingBase; +import net.consensys.linea.zktracer.module.add.Add; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; @@ -251,9 +252,10 @@ Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, Address class TestContext { static Long txNonce = null; static final Long gasLimit = 5000000L; - static final int numberOfAccounts = 5; + static final int numberOfAccounts = 6; static final Bytes snippetsCode = SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul"); static final Bytes snippetsCodeForCreate2 = Bytes.fromHexStringLenient("0x61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); + static final org.apache.tuweni.bytes.Bytes32 initCodeHashSnippet = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(TestContext.snippetsCodeForCreate2)); @Getter ToyAccount frameworkEntryPointAccount; Address frameworkEntryPointAddress; @@ -344,6 +346,14 @@ TransactionProcessingResultValidator getValidator() { return resultValidator; } + Address getCreate2AddressForSnippet(String salt) { + org.apache.tuweni.bytes.Bytes32 initCodeHash = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(TestContext.snippetsCodeForCreate2)); + org.apache.tuweni.bytes.Bytes32 targetAddress = AddressUtils.getCreate2RawAddress(ctxt.frameworkEntryPointAccount.getAddress(), + org.apache.tuweni.bytes.Bytes32.wrap(Bytes.fromHexStringLenient(salt).toArray()), + initCodeHash); + return Address.extract(targetAddress); + } + @Test void testBuildingBlockOperations() { // initialize the test context @@ -393,21 +403,11 @@ void testConflationMap() { this.ctxt = new TestContext(); this.ctxt.initializeTestContext(); TransactionProcessingResultValidator resultValidator = getValidator(); - - - - StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); - org.apache.tuweni.bytes.Bytes32 initCodeHash = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(TestContext.snippetsCodeForCreate2)); - org.apache.tuweni.bytes.Bytes32 targetAddress = AddressUtils.getCreate2RawAddress(ctxt.frameworkEntryPointAccount.getAddress(), - org.apache.tuweni.bytes.Bytes32.wrap(Bytes.fromHexStringLenient("0x0000000000000000000000000000000000000000000000000000000000000002").toArray()), - initCodeHash); - ctxt.addresses[3] = Address.extract(targetAddress); - org.apache.tuweni.bytes.Bytes32 targetAddress2 = AddressUtils.getCreate2RawAddress(ctxt.frameworkEntryPointAccount.getAddress(), - org.apache.tuweni.bytes.Bytes32.wrap(Bytes.fromHexStringLenient("0x0000000000000000000000000000000000000000000000000000000000000003").toArray()), - initCodeHash); - ctxt.addresses[4] = Address.extract(targetAddress2); + ctxt.addresses[3] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); + ctxt.addresses[4] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); + ctxt.addresses[5] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); MultiBlockExecutionEnvironment.builder() .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) @@ -425,6 +425,10 @@ void testConflationMap() { .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, false, BigInteger.ONE))) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, 13L, false, BigInteger.ONE))) .addBlock(List.of(selfDestruct(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, ctxt.addresses[4], false, BigInteger.ONE))) + .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000004", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 500L, 23L, false, BigInteger.ONE))) + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 500L, 53L, true, BigInteger.ONE))) // revert flag on + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 500L, 63L, true, BigInteger.ONE))) // revert flag on .transactionProcessingResultValidator(resultValidator) .build() .run(); @@ -434,12 +438,13 @@ void testConflationMap() { Map> conflationStorage = stateManagerMetadata.getStorageFirstLastConflationMap(); - EWord[] expectedFirst = {EWord.of(8L), EWord.of(20L), EWord.of(12L)}; - EWord[] expectedLast = {EWord.of(15L), EWord.of(40L), EWord.of(13L)}; + EWord[] expectedFirst = {EWord.of(8L), EWord.of(20L), EWord.of(12L), EWord.of(23L)}; + EWord[] expectedLast = {EWord.of(15L), EWord.of(40L), EWord.of(13L), EWord.of(23L)}; TransactionProcessingMetadata.AddrStorageKeyPair[] keys = { new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.initialAccounts[0].getAddress(), EWord.of(123L)), new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.addresses[3], EWord.of(345L)), - new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.addresses[4], EWord.of(400L)) + new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.addresses[4], EWord.of(400L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.addresses[5], EWord.of(500L)) }; for (int i = 0; i < keys.length; i++) { From 0c532809381d798ca3c3633c8a1baea6fdbe81f3 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 25 Oct 2024 01:48:35 +0200 Subject: [PATCH 49/74] explanations --- .../zktracer/StateManagerSolidityTest.java | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index 23a77230ee..a64bb8a5c3 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -402,29 +402,40 @@ void testConflationMap() { // initialize the test context this.ctxt = new TestContext(); this.ctxt.initializeTestContext(); + // prepare the transaction validator TransactionProcessingResultValidator resultValidator = getValidator(); + // fetch the Hub metadata for the state manager maps StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); - + // compute the addresses for several accounts that will be deployed later ctxt.addresses[3] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); ctxt.addresses[4] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); ctxt.addresses[5] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); + // prepare a multi-block execution of transactions MultiBlockExecutionEnvironment.builder() + // initialize accounts .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) + // test storage operations for an account prexisting in the state .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 8L, false, BigInteger.ONE))) .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ONE))) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 10L, false, BigInteger.ONE))) .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ONE))) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 15L, false, BigInteger.ONE))) + // deploy another account and perform storage operations on it .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, 20L, false, BigInteger.ONE))) .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, false, BigInteger.ONE))) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, 40L, false, BigInteger.ONE))) + // deploy another account and self destruct it at the end, redeploy it and change the storage again + // the salt will be the same twice in a row, which will be on purpose .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, 12L, false, BigInteger.ONE))) .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, false, BigInteger.ONE))) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, 13L, false, BigInteger.ONE))) .addBlock(List.of(selfDestruct(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, ctxt.addresses[4], false, BigInteger.ONE))) + .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, 99L, false, BigInteger.ONE))) + // deploy a new account and check revert operations on it .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000004", TestContext.snippetsCodeForCreate2))) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 500L, 23L, false, BigInteger.ONE))) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 500L, 53L, true, BigInteger.ONE))) // revert flag on @@ -438,8 +449,22 @@ void testConflationMap() { Map> conflationStorage = stateManagerMetadata.getStorageFirstLastConflationMap(); - EWord[] expectedFirst = {EWord.of(8L), EWord.of(20L), EWord.of(12L), EWord.of(23L)}; - EWord[] expectedLast = {EWord.of(15L), EWord.of(40L), EWord.of(13L), EWord.of(23L)}; + // prepare data for asserts + // expected first values for the keys we are testing + EWord[] expectedFirst = { + EWord.of(8L), + EWord.of(20L), + EWord.of(12L), + EWord.of(23L) + }; + // expected last values for the keys we are testing + EWord[] expectedLast = { + EWord.of(15L), + EWord.of(40L), + EWord.of(99L), + EWord.of(23L) + }; + // prepare the key pairs TransactionProcessingMetadata.AddrStorageKeyPair[] keys = { new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.initialAccounts[0].getAddress(), EWord.of(123L)), new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.addresses[3], EWord.of(345L)), @@ -448,7 +473,9 @@ void testConflationMap() { }; for (int i = 0; i < keys.length; i++) { - TransactionProcessingMetadata. FragmentFirstAndLast storageData = conflationStorage.get(keys[i]); + TransactionProcessingMetadata. FragmentFirstAndLast + storageData = conflationStorage.get(keys[i]); + // asserts for the first and last storage values in conflation assertEquals(storageData.getFirst().getValueNext(), expectedFirst[i]); assertEquals(storageData.getLast().getValueNext(), expectedLast[i]); } From 5202005875322e0cdf9b7ff820abe80d0f897f0c Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 25 Oct 2024 03:09:40 +0200 Subject: [PATCH 50/74] reverts, but the validator is wip --- .../consensys/linea/zktracer/StateManagerSolidityTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index a64bb8a5c3..48bdf48d5b 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -437,9 +437,11 @@ void testConflationMap() { .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, 99L, false, BigInteger.ONE))) // deploy a new account and check revert operations on it .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000004", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 500L, 23L, false, BigInteger.ONE))) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 500L, 53L, true, BigInteger.ONE))) // revert flag on .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 500L, 63L, true, BigInteger.ONE))) // revert flag on + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[5], 500L, 23L, false, BigInteger.ONE))) + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[5], 500L, 53L, true, BigInteger.ONE))) // revert flag on + .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[5], 500L, 63L, true, BigInteger.ONE))) // revert flag on .transactionProcessingResultValidator(resultValidator) .build() .run(); From f8476ba60ec7d57ec87102ca4a959015c78576a6 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Fri, 25 Oct 2024 14:27:50 +0200 Subject: [PATCH 51/74] transfer tests wip --- .../zktracer/StateManagerSolidityTest.java | 82 +++++++++++++++++-- 1 file changed, 75 insertions(+), 7 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index 48bdf48d5b..d53f703bfb 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -196,6 +196,49 @@ Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, Address desti return tx; } + // destination must be our .yul smart contract + Transaction transferTo(ToyAccount sender, KeyPair senderKeyPair, Address destination, Address recipient, long amount, boolean revertFlag, BigInteger callType) { + String recipientAddressString = recipient.toHexString(); + Function yulFunction = new Function("transferTo", + Arrays.asList(new org.web3j.abi.datatypes.Address(recipientAddressString), new Uint256(amount), new org.web3j.abi.datatypes.Bool(revertFlag)), + Collections.emptyList()); + + + var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); // Normal call, not a delegate call as would be the default + + List contractCalls = List.of(snippetContractCall); + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() + .sender(sender) + .to(this.ctxt.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit); + + if (TestContext.txNonce != null) { + tempTx = tempTx.nonce(++TestContext.txNonce); + } + Transaction tx = tempTx.build(); + if (TestContext.txNonce == null) { + TestContext.txNonce = tx.getNonce(); + } + return tx; + } + // destination must be our .yul smart contract Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, Address destination, String saltString, Bytes contractBytes) { Bytes salt = Bytes.fromHexStringLenient(saltString); @@ -252,6 +295,7 @@ Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, Address class TestContext { static Long txNonce = null; static final Long gasLimit = 5000000L; + static final Wei defaultBalance = Wei.fromEth(3); static final int numberOfAccounts = 6; static final Bytes snippetsCode = SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul"); static final Bytes snippetsCodeForCreate2 = Bytes.fromHexStringLenient("0x61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); @@ -271,7 +315,7 @@ public void initializeTestContext() { frameworkEntryPointAccount = ToyAccount.builder() .address(Address.fromHexString("0x22222")) - .balance(Wei.ONE) + .balance(defaultBalance) .nonce(5) .code(SmartContractUtils.getSolidityContractByteCode(FrameworkEntrypoint.class)) .build(); @@ -281,7 +325,7 @@ public void initializeTestContext() { initialAccounts[0] = ToyAccount.builder() .address(Address.fromHexString("0x11111")) - .balance(Wei.ONE) + .balance(defaultBalance) .nonce(6) .code(TestContext.snippetsCode) .build(); @@ -299,7 +343,7 @@ public void initializeTestContext() { initialAccounts[2] = ToyAccount.builder() .address(Address.fromHexString("0x44444")) - .balance(Wei.ONE) + .balance(defaultBalance) .nonce(8) .code(SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul")) .build(); @@ -330,7 +374,7 @@ TransactionProcessingResultValidator getValidator() { .equals(logTopic)) { FrameworkEntrypoint.CallExecutedEventResponse response = FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - assertTrue(response.isSuccess); + //assertTrue(response.isSuccess); if (logTopic.equals(createdEventSignature)) { assertEquals(response.destination, this.ctxt.frameworkEntryPointAccount.getAddress().toHexString()); } else { @@ -388,7 +432,7 @@ void testCreate2Snippets() { ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", - SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul")))) + TestContext.snippetsCodeForCreate2))) .transactionProcessingResultValidator(resultValidator) .build() .run(); @@ -437,8 +481,6 @@ void testConflationMap() { .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, 99L, false, BigInteger.ONE))) // deploy a new account and check revert operations on it .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000004", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 500L, 53L, true, BigInteger.ONE))) // revert flag on - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 500L, 63L, true, BigInteger.ONE))) // revert flag on .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[5], 500L, 23L, false, BigInteger.ONE))) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[5], 500L, 53L, true, BigInteger.ONE))) // revert flag on .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[5], 500L, 63L, true, BigInteger.ONE))) // revert flag on @@ -485,6 +527,32 @@ void testConflationMap() { } + @Test + void testConflationMapTransfers() { + // initialize the test context + this.ctxt = new TestContext(); + this.ctxt.initializeTestContext(); + // prepare the transaction validator + TransactionProcessingResultValidator resultValidator = getValidator(); + // fetch the Hub metadata for the state manager maps + StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); + // compute the addresses for several accounts that will be deployed later + ctxt.addresses[3] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); + ctxt.addresses[4] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); + ctxt.addresses[5] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); + + // prepare a multi-block execution of transactions + MultiBlockExecutionEnvironment.builder() + // initialize accounts + .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) + // test storage operations for an account prexisting in the state + .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[2], 8L, false, BigInteger.ONE))) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); + + System.out.println("Done"); + } From bc9808abd45edf9b278e85958454d31362a4c323 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Mon, 28 Oct 2024 23:12:16 +0100 Subject: [PATCH 52/74] testing Gaurav's bytecode utilities PR --- .../linea/zktracer/ExampleMultiBlockTest.java | 339 +++++++++--------- .../linea/zktracer/ExampleSolidityTest.java | 132 ++++--- .../zktracer/StateManagerSolidityTest.java | 11 +- .../linea/testing/SmartContractUtils.java | 78 +++- .../templates/compiler_yul.json.template | 3 +- 5 files changed, 302 insertions(+), 261 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java index 2ffd650162..cc89411e9d 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java @@ -23,7 +23,6 @@ import java.util.Collections; import java.util.List; - import net.consensys.linea.testing.BytecodeCompiler; import net.consensys.linea.testing.MultiBlockExecutionEnvironment; import net.consensys.linea.testing.SmartContractUtils; @@ -33,7 +32,6 @@ import net.consensys.linea.testing.Web3jUtils; import net.consensys.linea.testing.generated.FrameworkEntrypoint; import net.consensys.linea.testing.generated.TestSnippet_Events; - import net.consensys.linea.zktracer.opcode.OpCode; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.crypto.KeyPair; @@ -47,142 +45,140 @@ import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; import org.hyperledger.besu.evm.log.Log; import org.junit.jupiter.api.Test; - import org.web3j.abi.EventEncoder; import org.web3j.abi.FunctionEncoder; import org.web3j.abi.datatypes.DynamicArray; import org.web3j.abi.datatypes.Function; import org.web3j.abi.datatypes.generated.Uint256; - class ExampleMultiBlockTest { @Test void test() { final ToyAccount receiverAccount = - ToyAccount.builder() - .balance(Wei.fromEth(1)) - .nonce(116) - .address(Address.fromHexString("0xdead000000000000000000000000000beef")) - .build(); + ToyAccount.builder() + .balance(Wei.fromEth(1)) + .nonce(116) + .address(Address.fromHexString("0xdead000000000000000000000000000beef")) + .build(); final KeyPair senderKeyPair1 = new SECP256K1().generateKeyPair(); final Address senderAddress1 = - Address.extract(Hash.hash(senderKeyPair1.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderKeyPair1.getPublicKey().getEncodedBytes())); final ToyAccount senderAccount1 = - ToyAccount.builder().balance(Wei.fromEth(123)).nonce(5).address(senderAddress1).build(); + ToyAccount.builder().balance(Wei.fromEth(123)).nonce(5).address(senderAddress1).build(); final KeyPair senderKeyPair2 = new SECP256K1().generateKeyPair(); final Address senderAddress2 = - Address.extract(Hash.hash(senderKeyPair2.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderKeyPair2.getPublicKey().getEncodedBytes())); final ToyAccount senderAccount2 = - ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress2).build(); + ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress2).build(); final KeyPair senderKeyPair3 = new SECP256K1().generateKeyPair(); final Address senderAddress3 = - Address.extract(Hash.hash(senderKeyPair3.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderKeyPair3.getPublicKey().getEncodedBytes())); final ToyAccount senderAccount3 = - ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress3).build(); + ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress3).build(); final KeyPair senderKeyPair4 = new SECP256K1().generateKeyPair(); final Address senderAddress4 = - Address.extract(Hash.hash(senderKeyPair4.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderKeyPair4.getPublicKey().getEncodedBytes())); final ToyAccount senderAccount4 = - ToyAccount.builder().balance(Wei.fromEth(11)).nonce(115).address(senderAddress4).build(); + ToyAccount.builder().balance(Wei.fromEth(11)).nonce(115).address(senderAddress4).build(); final KeyPair senderKeyPair5 = new SECP256K1().generateKeyPair(); final Address senderAddress5 = - Address.extract(Hash.hash(senderKeyPair5.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderKeyPair5.getPublicKey().getEncodedBytes())); final ToyAccount senderAccount5 = - ToyAccount.builder().balance(Wei.fromEth(12)).nonce(0).address(senderAddress5).build(); + ToyAccount.builder().balance(Wei.fromEth(12)).nonce(0).address(senderAddress5).build(); final KeyPair senderKeyPair6 = new SECP256K1().generateKeyPair(); final Address senderAddress6 = - Address.extract(Hash.hash(senderKeyPair6.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderKeyPair6.getPublicKey().getEncodedBytes())); final ToyAccount senderAccount6 = - ToyAccount.builder().balance(Wei.fromEth(12)).nonce(6).address(senderAddress6).build(); + ToyAccount.builder().balance(Wei.fromEth(12)).nonce(6).address(senderAddress6).build(); final KeyPair senderKeyPair7 = new SECP256K1().generateKeyPair(); final Address senderAddress7 = - Address.extract(Hash.hash(senderKeyPair7.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderKeyPair7.getPublicKey().getEncodedBytes())); final ToyAccount senderAccount7 = - ToyAccount.builder().balance(Wei.fromEth(231)).nonce(21).address(senderAddress7).build(); + ToyAccount.builder().balance(Wei.fromEth(231)).nonce(21).address(senderAddress7).build(); final Transaction pureTransfer = - ToyTransaction.builder() - .sender(senderAccount1) - .to(receiverAccount) - .keyPair(senderKeyPair1) - .value(Wei.of(123)) - .build(); + ToyTransaction.builder() + .sender(senderAccount1) + .to(receiverAccount) + .keyPair(senderKeyPair1) + .value(Wei.of(123)) + .build(); final Transaction pureTransferWoValue = - ToyTransaction.builder() - .sender(senderAccount2) - .to(receiverAccount) - .keyPair(senderKeyPair2) - .value(Wei.of(0)) - .build(); + ToyTransaction.builder() + .sender(senderAccount2) + .to(receiverAccount) + .keyPair(senderKeyPair2) + .value(Wei.of(0)) + .build(); final List listOfKeys = - List.of("0x0123", "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); + List.of("0x0123", "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); final List accessList = - List.of( - AccessListEntry.createAccessListEntry( - Address.fromHexString("0x1234567890"), listOfKeys)); + List.of( + AccessListEntry.createAccessListEntry( + Address.fromHexString("0x1234567890"), listOfKeys)); final Transaction pureTransferWithUselessAccessList = - ToyTransaction.builder() - .sender(senderAccount3) - .to(receiverAccount) - .keyPair(senderKeyPair3) - .gasLimit(100000L) - .transactionType(TransactionType.ACCESS_LIST) - .accessList(accessList) - .value(Wei.of(546)) - .build(); + ToyTransaction.builder() + .sender(senderAccount3) + .to(receiverAccount) + .keyPair(senderKeyPair3) + .gasLimit(100000L) + .transactionType(TransactionType.ACCESS_LIST) + .accessList(accessList) + .value(Wei.of(546)) + .build(); final Transaction pureTransferWithUselessCalldata = - ToyTransaction.builder() - .sender(senderAccount4) - .to(receiverAccount) - .keyPair(senderKeyPair4) - .gasLimit(1000001L) - .value(Wei.of(546)) - .payload(Bytes.minimalBytes(0xdeadbeefL)) - .build(); + ToyTransaction.builder() + .sender(senderAccount4) + .to(receiverAccount) + .keyPair(senderKeyPair4) + .gasLimit(1000001L) + .value(Wei.of(546)) + .payload(Bytes.minimalBytes(0xdeadbeefL)) + .build(); final Transaction pureTransferWithUselessCalldataAndAccessList = - ToyTransaction.builder() - .sender(senderAccount5) - .to(receiverAccount) - .gasLimit(1000020L) - .transactionType(TransactionType.EIP1559) - .keyPair(senderKeyPair5) - .value(Wei.of(546)) - .accessList(accessList) - .payload(Bytes.minimalBytes(0xdeadbeefL)) - .build(); + ToyTransaction.builder() + .sender(senderAccount5) + .to(receiverAccount) + .gasLimit(1000020L) + .transactionType(TransactionType.EIP1559) + .keyPair(senderKeyPair5) + .value(Wei.of(546)) + .accessList(accessList) + .payload(Bytes.minimalBytes(0xdeadbeefL)) + .build(); MultiBlockExecutionEnvironment.MultiBlockExecutionEnvironmentBuilder builder = - MultiBlockExecutionEnvironment.builder(); + MultiBlockExecutionEnvironment.builder(); builder - .accounts( - List.of( - senderAccount1, - senderAccount2, - senderAccount3, - senderAccount4, - senderAccount5, - senderAccount6, - senderAccount7, - receiverAccount)) - .addBlock(List.of(pureTransfer)) - .addBlock(List.of(pureTransferWoValue, pureTransferWithUselessAccessList)) - .addBlock( - List.of(pureTransferWithUselessCalldata, pureTransferWithUselessCalldataAndAccessList)) - .build() - .run(); + .accounts( + List.of( + senderAccount1, + senderAccount2, + senderAccount3, + senderAccount4, + senderAccount5, + senderAccount6, + senderAccount7, + receiverAccount)) + .addBlock(List.of(pureTransfer)) + .addBlock(List.of(pureTransferWoValue, pureTransferWithUselessAccessList)) + .addBlock( + List.of(pureTransferWithUselessCalldata, pureTransferWithUselessCalldataAndAccessList)) + .build() + .run(); } @Test @@ -191,29 +187,29 @@ void test2() { Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); ToyAccount senderAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); ToyAccount receiverAccount = - ToyAccount.builder() - .balance(Wei.ONE) - .nonce(6) - .address(Address.fromHexString("0x111111")) - .code( - BytecodeCompiler.newProgram() - .push(32, 0xbeef) - .push(32, 0xdead) - .op(OpCode.ADD) - .compile()) - .build(); + ToyAccount.builder() + .balance(Wei.ONE) + .nonce(6) + .address(Address.fromHexString("0x111111")) + .code( + BytecodeCompiler.newProgram() + .push(32, 0xbeef) + .push(32, 0xdead) + .op(OpCode.ADD) + .compile()) + .build(); Transaction tx = - ToyTransaction.builder().sender(senderAccount).to(receiverAccount).keyPair(keyPair).build(); + ToyTransaction.builder().sender(senderAccount).to(receiverAccount).keyPair(keyPair).build(); MultiBlockExecutionEnvironment.builder() - .accounts(List.of(senderAccount, receiverAccount)) - .addBlock(List.of(tx)) - .build() - .run(); + .accounts(List.of(senderAccount, receiverAccount)) + .addBlock(List.of(tx)) + .build() + .run(); } @Test @@ -221,96 +217,97 @@ void testWithFrameworkEntrypoint() { KeyPair keyPair = new SECP256K1().generateKeyPair(); Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); - ToyAccount senderAccount = ToyAccount.builder().balance(Wei.fromEth(1000)).nonce(5).address(senderAddress).build(); + ToyAccount senderAccount = + ToyAccount.builder().balance(Wei.fromEth(1000)).nonce(5).address(senderAddress).build(); ToyAccount frameworkEntrypointAccount = - ToyAccount.builder() - .address(Address.fromHexString("0x22222")) - .balance(Wei.of(1000)) - .nonce(6) - .code(SmartContractUtils.getSolidityContractByteCode(FrameworkEntrypoint.class)) - .build(); + ToyAccount.builder() + .address(Address.fromHexString("0x22222")) + .balance(Wei.of(1000)) + .nonce(6) + .code(SmartContractUtils.getSolidityContractRuntimeByteCode(FrameworkEntrypoint.class)) + .build(); ToyAccount snippetAccount = - ToyAccount.builder() - .address(Address.fromHexString("0x11111")) - .balance(Wei.of(1000)) - .nonce(7) - .code(SmartContractUtils.getSolidityContractByteCode(TestSnippet_Events.class)) - .build(); + ToyAccount.builder() + .address(Address.fromHexString("0x11111")) + .balance(Wei.of(1000)) + .nonce(7) + .code(SmartContractUtils.getSolidityContractRuntimeByteCode(TestSnippet_Events.class)) + .build(); Function snippetFunction = - new Function( - TestSnippet_Events.FUNC_EMITDATANOINDEXES, - List.of(new Uint256(BigInteger.valueOf(123456))), - Collections.emptyList()); + new Function( + TestSnippet_Events.FUNC_EMITDATANOINDEXES, + List.of(new Uint256(BigInteger.valueOf(123456))), + Collections.emptyList()); FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ snippetAccount.getAddress().toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(FunctionEncoder.encode(snippetFunction)) - .toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ BigInteger.ZERO); + new FrameworkEntrypoint.ContractCall( + /*Address*/ snippetAccount.getAddress().toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(FunctionEncoder.encode(snippetFunction)) + .toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ZERO); List contractCalls = List.of(snippetContractCall); Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); Transaction tx = - ToyTransaction.builder() - .sender(senderAccount) - .to(frameworkEntrypointAccount) - .payload(txPayload) - .keyPair(keyPair) - .build(); + ToyTransaction.builder() + .sender(senderAccount) + .to(frameworkEntrypointAccount) + .payload(txPayload) + .keyPair(keyPair) + .build(); Transaction tx2 = - ToyTransaction.builder() - .sender(senderAccount) - .to(frameworkEntrypointAccount) - .payload(txPayload) - .keyPair(keyPair) - .nonce(tx.getNonce() + 1) - .build(); + ToyTransaction.builder() + .sender(senderAccount) + .to(frameworkEntrypointAccount) + .payload(txPayload) + .keyPair(keyPair) + .nonce(tx.getNonce() + 1) + .build(); TransactionProcessingResultValidator resultValidator = - (Transaction transaction, TransactionProcessingResult result) -> { - TransactionProcessingResultValidator.DEFAULT_VALIDATOR.accept(transaction, result); - // One event from the snippet - // One event from the framework entrypoint about contract call - assertEquals(result.getLogs().size(), 2); - for (Log log : result.getLogs()) { - String logTopic = log.getTopics().getFirst().toHexString(); - if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { - TestSnippet_Events.DataNoIndexesEventResponse response = - TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); - assertEquals(response.singleInt, BigInteger.valueOf(123456)); - } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) - .equals(logTopic)) { - FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - assertTrue(response.isSuccess); - assertEquals(response.destination, snippetAccount.getAddress().toHexString()); - } else { - fail(); - } - } - }; + (Transaction transaction, TransactionProcessingResult result) -> { + TransactionProcessingResultValidator.DEFAULT_VALIDATOR.accept(transaction, result); + // One event from the snippet + // One event from the framework entrypoint about contract call + assertEquals(result.getLogs().size(), 2); + for (Log log : result.getLogs()) { + String logTopic = log.getTopics().getFirst().toHexString(); + if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { + TestSnippet_Events.DataNoIndexesEventResponse response = + TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); + assertEquals(response.singleInt, BigInteger.valueOf(123456)); + } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) + .equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + assertEquals(response.destination, snippetAccount.getAddress().toHexString()); + } else { + fail(); + } + } + }; MultiBlockExecutionEnvironment.builder() - .accounts(List.of(senderAccount, frameworkEntrypointAccount, snippetAccount)) - .addBlock(List.of(tx)) - .addBlock(List.of(tx2)) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); + .accounts(List.of(senderAccount, frameworkEntrypointAccount, snippetAccount)) + .addBlock(List.of(tx)) + .addBlock(List.of(tx2)) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); } -} +} \ No newline at end of file diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java index fafc5c09ef..8283c5f09a 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java @@ -63,7 +63,7 @@ void testWithFrameworkEntrypoint() { .address(Address.fromHexString("0x22222")) .balance(Wei.ONE) .nonce(5) - .code(SmartContractUtils.getSolidityContractByteCode(FrameworkEntrypoint.class)) + .code(SmartContractUtils.getSolidityContractRuntimeByteCode(FrameworkEntrypoint.class)) .build(); ToyAccount snippetAccount = @@ -71,7 +71,7 @@ void testWithFrameworkEntrypoint() { .address(Address.fromHexString("0x11111")) .balance(Wei.ONE) .nonce(6) - .code(SmartContractUtils.getSolidityContractByteCode(TestSnippet_Events.class)) + .code(SmartContractUtils.getSolidityContractRuntimeByteCode(TestSnippet_Events.class)) .build(); Function snippetFunction = @@ -107,37 +107,35 @@ void testWithFrameworkEntrypoint() { .keyPair(keyPair) .build(); - TransactionProcessingResultValidator resultValidator = - (Transaction transaction, TransactionProcessingResult result) -> { - // One event from the snippet - // One event from the framework entrypoint about contract call - assertEquals(result.getLogs().size(), 2); - for (Log log : result.getLogs()) { - String logTopic = log.getTopics().getFirst().toHexString(); - if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { - TestSnippet_Events.DataNoIndexesEventResponse response = - TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); - assertEquals(response.singleInt, BigInteger.valueOf(123456)); - } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) - .equals(logTopic)) { - FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - assertTrue(response.isSuccess); - assertEquals(response.destination, snippetAccount.getAddress().toHexString()); - } else { - fail(); - } - } - }; + (Transaction transaction, TransactionProcessingResult result) -> { + // One event from the snippet + // One event from the framework entrypoint about contract call + assertEquals(result.getLogs().size(), 2); + for (Log log : result.getLogs()) { + String logTopic = log.getTopics().getFirst().toHexString(); + if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { + TestSnippet_Events.DataNoIndexesEventResponse response = + TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); + assertEquals(response.singleInt, BigInteger.valueOf(123456)); + } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) + .equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + assertEquals(response.destination, snippetAccount.getAddress().toHexString()); + } else { + fail(); + } + } + }; ToyExecutionEnvironmentV2.builder() - .accounts(List.of(senderAccount, frameworkEntrypointAccount, snippetAccount)) - .transaction(tx) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); - + .accounts(List.of(senderAccount, frameworkEntrypointAccount, snippetAccount)) + .transaction(tx) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); } @Test @@ -153,7 +151,7 @@ void testSnippetIndependently() { .address(Address.fromHexString("0x11111")) .balance(Wei.ONE) .nonce(6) - .code(SmartContractUtils.getSolidityContractByteCode(TestSnippet_Events.class)) + .code(SmartContractUtils.getSolidityContractRuntimeByteCode(TestSnippet_Events.class)) .build(); Function function = @@ -172,22 +170,21 @@ void testSnippetIndependently() { .keyPair(keyPair) .build(); - TransactionProcessingResultValidator resultValidator = - (Transaction transaction, TransactionProcessingResult result) -> { - assertEquals(result.getLogs().size(), 1); - TestSnippet_Events.DataNoIndexesEventResponse response = - TestSnippet_Events.getDataNoIndexesEventFromLog( - Web3jUtils.fromBesuLog(result.getLogs().getFirst())); - assertEquals(response.singleInt, BigInteger.valueOf(123456)); - }; + (Transaction transaction, TransactionProcessingResult result) -> { + assertEquals(result.getLogs().size(), 1); + TestSnippet_Events.DataNoIndexesEventResponse response = + TestSnippet_Events.getDataNoIndexesEventFromLog( + Web3jUtils.fromBesuLog(result.getLogs().getFirst())); + assertEquals(response.singleInt, BigInteger.valueOf(123456)); + }; ToyExecutionEnvironmentV2.builder() - .accounts(List.of(senderAccount, contractAccount)) - .transaction(tx) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); + .accounts(List.of(senderAccount, contractAccount)) + .transaction(tx) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); } @Test @@ -204,7 +201,7 @@ void testContractNotRelatedToTestingFramework() { .address(Address.fromHexString("0x11111")) .balance(Wei.ONE) .nonce(6) - .code(SmartContractUtils.getSolidityContractByteCode(TestStorage.class)) + .code(SmartContractUtils.getSolidityContractRuntimeByteCode(TestStorage.class)) .build(); Function function = @@ -243,7 +240,7 @@ void testYul() { .address(Address.fromHexString("0x22222")) .balance(Wei.ONE) .nonce(5) - .code(SmartContractUtils.getSolidityContractByteCode(FrameworkEntrypoint.class)) + .code(SmartContractUtils.getSolidityContractRuntimeByteCode(FrameworkEntrypoint.class)) .build(); ToyAccount yulAccount = @@ -251,7 +248,7 @@ void testYul() { .address(Address.fromHexString("0x11111")) .balance(Wei.ONE) .nonce(6) - .code(SmartContractUtils.getYulContractByteCode("DynamicBytecode.yul")) + .code(SmartContractUtils.getYulContractRuntimeByteCode("DynamicBytecode.yul")) .build(); Function yulFunction = new Function("Write", Collections.emptyList(), Collections.emptyList()); @@ -276,23 +273,21 @@ void testYul() { Bytes txPayload = Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - TransactionProcessingResultValidator resultValidator = - (Transaction transaction, TransactionProcessingResult result) -> { - assertEquals(result.getLogs().size(), 1); - for (Log log : result.getLogs()) { - String logTopic = log.getTopics().getFirst().toHexString(); - if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT).equals(logTopic)) { - FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - assertTrue(response.isSuccess); - assertEquals(response.destination, yulAccount.getAddress().toHexString()); - } else { - fail(); - } - } - }; - + (Transaction transaction, TransactionProcessingResult result) -> { + assertEquals(result.getLogs().size(), 1); + for (Log log : result.getLogs()) { + String logTopic = log.getTopics().getFirst().toHexString(); + if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT).equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + assertEquals(response.destination, yulAccount.getAddress().toHexString()); + } else { + fail(); + } + } + }; Transaction tx = ToyTransaction.builder() @@ -304,11 +299,10 @@ void testYul() { .build(); ToyExecutionEnvironmentV2.builder() - - .accounts(List.of(senderAccount, yulAccount, frameworkEntrypointAccount)) - .transaction(tx) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); + .accounts(List.of(senderAccount, yulAccount, frameworkEntrypointAccount)) + .transaction(tx) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); } } \ No newline at end of file diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index d53f703bfb..98a086fe9b 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -297,8 +297,8 @@ class TestContext { static final Long gasLimit = 5000000L; static final Wei defaultBalance = Wei.fromEth(3); static final int numberOfAccounts = 6; - static final Bytes snippetsCode = SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul"); - static final Bytes snippetsCodeForCreate2 = Bytes.fromHexStringLenient("0x61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); + static final Bytes snippetsCode = SmartContractUtils.getYulContractRuntimeByteCode("StateManagerSnippets.yul"); + static final Bytes snippetsCodeForCreate2 = SmartContractUtils.getYulContractCompiledByteCode("StateManagerSnippets.yul"); static final org.apache.tuweni.bytes.Bytes32 initCodeHashSnippet = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(TestContext.snippetsCodeForCreate2)); @Getter ToyAccount frameworkEntryPointAccount; @@ -317,7 +317,7 @@ public void initializeTestContext() { .address(Address.fromHexString("0x22222")) .balance(defaultBalance) .nonce(5) - .code(SmartContractUtils.getSolidityContractByteCode(FrameworkEntrypoint.class)) + .code(SmartContractUtils.getSolidityContractRuntimeByteCode(FrameworkEntrypoint.class)) .build(); frameworkEntryPointAddress = frameworkEntryPointAccount.getAddress(); // initialize the .yul snippets account @@ -345,7 +345,7 @@ public void initializeTestContext() { .address(Address.fromHexString("0x44444")) .balance(defaultBalance) .nonce(8) - .code(SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul")) + .code(SmartContractUtils.getYulContractRuntimeByteCode("StateManagerSnippets.yul")) .build(); addresses[2] = initialAccounts[2].getAddress(); } @@ -365,6 +365,7 @@ TransactionProcessingResultValidator getValidator() { String readEventSignature = EventEncoder.encode(StateManagerEvents.READ_EVENT); String destroyedEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); String createdEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTCREATED_EVENT); + String sentETHEventSignature = EventEncoder.encode(StateManagerEvents.PAYETH_EVENT); String logTopic = log.getTopics().getFirst().toHexString(); if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { TestSnippet_Events.DataNoIndexesEventResponse response = @@ -381,7 +382,7 @@ TransactionProcessingResultValidator getValidator() { //assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); } } else { - if (!(logTopic.equals(callEventSignature) || logTopic.equals(writeEventSignature) || logTopic.equals(readEventSignature) || logTopic.equals(destroyedEventSignature) || logTopic.equals(createdEventSignature))) { + if (!(logTopic.equals(callEventSignature) || logTopic.equals(writeEventSignature) || logTopic.equals(readEventSignature) || logTopic.equals(destroyedEventSignature) || logTopic.equals(createdEventSignature) || logTopic.equals(sentETHEventSignature))) { fail(); } } diff --git a/testing/src/main/java/net/consensys/linea/testing/SmartContractUtils.java b/testing/src/main/java/net/consensys/linea/testing/SmartContractUtils.java index 52dfec6a3c..229b35fbe8 100644 --- a/testing/src/main/java/net/consensys/linea/testing/SmartContractUtils.java +++ b/testing/src/main/java/net/consensys/linea/testing/SmartContractUtils.java @@ -36,9 +36,9 @@ public class SmartContractUtils { * runtime bytecode for solidity contract. * * @param contractClass: The web3j wrapper class that is autogenerated from the solidity contract - * @return The depolyed or runtime bytecode for the solidity contract + * @return The deployed or runtime bytecode for the solidity contract */ - public static Bytes getSolidityContractByteCode(Class contractClass) { + public static Bytes getSolidityContractRuntimeByteCode(Class contractClass) { String contractResourcePath = "solidity/%s.json".formatted(contractClass.getSimpleName()); URL contractResourceURL = classLoader.getResource(contractResourcePath); try { @@ -56,15 +56,37 @@ public static Bytes getSolidityContractByteCode(Class contra throw new RuntimeException("Could not find contract bytecode"); } + /** + * @param contractClass: The web3j wrapper class that is autogenerated from the solidity contract + * @return The compiled bytecode for the solidity contract + */ + public static Bytes getSolidityContractCompiledByteCode(Class contractClass) { + String contractResourcePath = "solidity/%s.json".formatted(contractClass.getSimpleName()); + URL contractResourceURL = classLoader.getResource(contractResourcePath); + try { + JsonNode jsonRoot = objectMapper.readTree(contractResourceURL); + Iterator> contracts = jsonRoot.get("contracts").fields(); + while (contracts.hasNext()) { + Map.Entry contract = contracts.next(); + if (contract.getKey().contains(contractClass.getSimpleName())) { + return Bytes.fromHexStringLenient(contract.getValue().get("bin").asText()); + } + } + } catch (Exception e) { + throw new RuntimeException(e); + } + throw new RuntimeException("Could not find contract bytecode"); + } + /** * The yul contracts under testing/src/main/yul are compiled using the solidity compiler via the * yul plugin This method reads the output of the solidity compiler output file and returns the * deployed or runtime bytecode for yul contract. * * @param yulFileName: The yul contract filename along with .yul suffix - * @return The depolyed or runtime bytecode for the yul contract + * @return The deployed or runtime bytecode for the yul contract */ - public static Bytes getYulContractByteCode(final String yulFileName) { + public static Bytes getYulContractRuntimeByteCode(final String yulFileName) { if (!yulFileName.contains(".yul")) { throw new IllegalArgumentException("Yul file name should contain the suffix: .yul"); } @@ -74,17 +96,45 @@ public static Bytes getYulContractByteCode(final String yulFileName) { try { JsonNode jsonRoot = objectMapper.readTree(contractResourceURL); String byteCode = - jsonRoot - .get("contracts") - .get(yulFileName) - .get(yulFileNameWithoutSuffix) - .get("evm") - .get("deployedBytecode") - .get("object") - .asText(); + jsonRoot + .get("contracts") + .get(yulFileName) + .get(yulFileNameWithoutSuffix) + .get("evm") + .get("deployedBytecode") + .get("object") + .asText(); return Bytes.fromHexStringLenient(byteCode); } catch (Exception e) { - throw new RuntimeException(e); + throw new RuntimeException("Could not find contract bytecode", e); + } + } + + /** + * @param yulFileName: The yul contract filename along with .yul suffix + * @return The compiled bytecode for the yul contract + */ + public static Bytes getYulContractCompiledByteCode(final String yulFileName) { + if (!yulFileName.contains(".yul")) { + throw new IllegalArgumentException("Yul file name should contain the suffix: .yul"); + } + String yulFileNameWithoutSuffix = yulFileName.replace(".yul", ""); + String contractResourcePath = "yul/%s.json".formatted(yulFileNameWithoutSuffix); + URL contractResourceURL = classLoader.getResource(contractResourcePath); + try { + JsonNode jsonRoot = objectMapper.readTree(contractResourceURL); + String byteCode = + jsonRoot + .get("contracts") + .get(yulFileName) + .get(yulFileNameWithoutSuffix) + .get("evm") + .get("bytecode") + .get("object") + .asText(); + return Bytes.fromHexStringLenient(byteCode); + } catch (Exception e) { + throw new RuntimeException("Could not find contract bytecode", e); } } -} +} \ No newline at end of file diff --git a/testing/src/main/resources/templates/compiler_yul.json.template b/testing/src/main/resources/templates/compiler_yul.json.template index 11c1bab0c1..4e7cc62b2f 100644 --- a/testing/src/main/resources/templates/compiler_yul.json.template +++ b/testing/src/main/resources/templates/compiler_yul.json.template @@ -7,7 +7,7 @@ }, "settings": { "evmVersion": "london", - "optimizer": { "enabled": true, "details": { "yul": true } }, + "optimizer": { "enabled": false, "details": { "yul": true } }, "outputSelection": { "*": { "": ["ast"], @@ -16,4 +16,3 @@ } } } - From 3ef5435c286e27df2b87970cca796d580c2f0216 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Mon, 28 Oct 2024 23:23:45 +0100 Subject: [PATCH 53/74] fixed nonce bug when running tests all the once --- .../zktracer/StateManagerSolidityTest.java | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index 98a086fe9b..b76763f6ff 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -100,12 +100,12 @@ Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, Address des .keyPair(senderKeyPair) .gasLimit(TestContext.gasLimit); - if (TestContext.txNonce != null) { - tempTx = tempTx.nonce(++TestContext.txNonce); + if (this.ctxt.txNonce != null) { + tempTx = tempTx.nonce(++this.ctxt.txNonce); } Transaction tx = tempTx.build(); - if (TestContext.txNonce == null) { - TestContext.txNonce = tx.getNonce(); + if (this.ctxt.txNonce == null) { + this.ctxt.txNonce = tx.getNonce(); } return tx; } @@ -143,12 +143,12 @@ Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, Address de .keyPair(senderKeyPair) .gasLimit(TestContext.gasLimit); - if (TestContext.txNonce != null) { - tempTx = tempTx.nonce(++TestContext.txNonce); + if (this.ctxt.txNonce != null) { + tempTx = tempTx.nonce(++this.ctxt.txNonce); } Transaction tx = tempTx.build(); - if (TestContext.txNonce == null) { - TestContext.txNonce = tx.getNonce(); + if (this.ctxt.txNonce == null) { + this.ctxt.txNonce = tx.getNonce(); } return tx; } @@ -186,12 +186,12 @@ Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, Address desti .keyPair(senderKeyPair) .gasLimit(TestContext.gasLimit); - if (TestContext.txNonce != null) { - tempTx = tempTx.nonce(++TestContext.txNonce); + if (this.ctxt.txNonce != null) { + tempTx = tempTx.nonce(++this.ctxt.txNonce); } Transaction tx = tempTx.build(); - if (TestContext.txNonce == null) { - TestContext.txNonce = tx.getNonce(); + if (this.ctxt.txNonce == null) { + this.ctxt.txNonce = tx.getNonce(); } return tx; } @@ -229,12 +229,12 @@ Transaction transferTo(ToyAccount sender, KeyPair senderKeyPair, Address destina .keyPair(senderKeyPair) .gasLimit(TestContext.gasLimit); - if (TestContext.txNonce != null) { - tempTx = tempTx.nonce(++TestContext.txNonce); + if (this.ctxt.txNonce != null) { + tempTx = tempTx.nonce(++this.ctxt.txNonce); } Transaction tx = tempTx.build(); - if (TestContext.txNonce == null) { - TestContext.txNonce = tx.getNonce(); + if (this.ctxt.txNonce == null) { + this.ctxt.txNonce = tx.getNonce(); } return tx; } @@ -280,12 +280,12 @@ Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, Address .keyPair(senderKeyPair) .gasLimit(TestContext.gasLimit); - if (TestContext.txNonce != null) { - tempTx = tempTx.nonce(++TestContext.txNonce); + if (this.ctxt.txNonce != null) { + tempTx = tempTx.nonce(++this.ctxt.txNonce); } Transaction tx = tempTx.build(); - if (TestContext.txNonce == null) { - TestContext.txNonce = tx.getNonce(); + if (this.ctxt.txNonce == null) { + this.ctxt.txNonce = tx.getNonce(); } return tx; } @@ -293,7 +293,7 @@ Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, Address @NoArgsConstructor class TestContext { - static Long txNonce = null; + Long txNonce = null; static final Long gasLimit = 5000000L; static final Wei defaultBalance = Wei.fromEth(3); static final int numberOfAccounts = 6; From 72dc1b5620d2c506254502797eacdc64b1d27317 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Tue, 29 Oct 2024 00:44:04 +0100 Subject: [PATCH 54/74] found a bug --- .../zktracer/StateManagerSolidityTest.java | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index b76763f6ff..e3fc10cc1a 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -443,7 +443,7 @@ void testCreate2Snippets() { @Test - void testConflationMap() { + void testConflationMapStorage() { // initialize the test context this.ctxt = new TestContext(); this.ctxt.initializeTestContext(); @@ -529,7 +529,7 @@ void testConflationMap() { @Test - void testConflationMapTransfers() { + void testConflationMapAccount() { // initialize the test context this.ctxt = new TestContext(); this.ctxt.initializeTestContext(); @@ -537,10 +537,6 @@ void testConflationMapTransfers() { TransactionProcessingResultValidator resultValidator = getValidator(); // fetch the Hub metadata for the state manager maps StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); - // compute the addresses for several accounts that will be deployed later - ctxt.addresses[3] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); - ctxt.addresses[4] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); - ctxt.addresses[5] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); // prepare a multi-block execution of transactions MultiBlockExecutionEnvironment.builder() @@ -548,10 +544,43 @@ void testConflationMapTransfers() { .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) // test storage operations for an account prexisting in the state .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[2], 8L, false, BigInteger.ONE))) + //.addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[2], ctxt.addresses[0], 20L, false, BigInteger.ONE))) + //.addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[2], 50L, true, BigInteger.ONE))) + //.addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[2], 10L, false, BigInteger.ONE))) .transactionProcessingResultValidator(resultValidator) .build() .run(); + Map> + conflationMap = stateManagerMetadata.getAccountFirstLastConflationMap(); + + // prepare data for asserts + // expected first values for the keys we are testing + Wei[] expectedFirst = { + TestContext.defaultBalance, + TestContext.defaultBalance, + }; + // expected last values for the keys we are testing + Wei[] expectedLast = { + TestContext.defaultBalance.subtract(8L), + TestContext.defaultBalance.add(8L), + }; + + // prepare the key pairs + Address[] keys = { + ctxt.initialAccounts[0].getAddress(), + ctxt.initialAccounts[2].getAddress(), + }; + + for (int i = 1; i < keys.length; i++) { + TransactionProcessingMetadata. FragmentFirstAndLast + accountData = conflationMap.get(keys[i]); + // asserts for the first and last storage values in conflation + assertEquals(accountData.getFirst().oldState().balance(), expectedFirst[i]); + assertEquals(accountData.getLast().newState().balance(), expectedLast[i]); + } + + System.out.println("Done"); } From 300ce6f129fa6ecb282efecabd265f0f39b1080f Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Tue, 29 Oct 2024 00:55:42 +0100 Subject: [PATCH 55/74] account map --- .../zktracer/StateManagerSolidityTest.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index e3fc10cc1a..855a286d85 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -366,6 +366,7 @@ TransactionProcessingResultValidator getValidator() { String destroyedEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); String createdEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTCREATED_EVENT); String sentETHEventSignature = EventEncoder.encode(StateManagerEvents.PAYETH_EVENT); + String recETHEventSignature = EventEncoder.encode(StateManagerEvents.RECETH_EVENT); String logTopic = log.getTopics().getFirst().toHexString(); if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { TestSnippet_Events.DataNoIndexesEventResponse response = @@ -382,7 +383,7 @@ TransactionProcessingResultValidator getValidator() { //assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); } } else { - if (!(logTopic.equals(callEventSignature) || logTopic.equals(writeEventSignature) || logTopic.equals(readEventSignature) || logTopic.equals(destroyedEventSignature) || logTopic.equals(createdEventSignature) || logTopic.equals(sentETHEventSignature))) { + if (!(logTopic.equals(callEventSignature) || logTopic.equals(writeEventSignature) || logTopic.equals(readEventSignature) || logTopic.equals(destroyedEventSignature) || logTopic.equals(createdEventSignature) || logTopic.equals(sentETHEventSignature) || logTopic.equals(recETHEventSignature))) { fail(); } } @@ -459,7 +460,7 @@ void testConflationMapStorage() { // prepare a multi-block execution of transactions MultiBlockExecutionEnvironment.builder() // initialize accounts - .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) + .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.initialAccounts[2], ctxt.frameworkEntryPointAccount)) // test storage operations for an account prexisting in the state .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 8L, false, BigInteger.ONE))) .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ONE))) @@ -541,12 +542,12 @@ void testConflationMapAccount() { // prepare a multi-block execution of transactions MultiBlockExecutionEnvironment.builder() // initialize accounts - .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) + .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.initialAccounts[2], ctxt.frameworkEntryPointAccount)) // test storage operations for an account prexisting in the state .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[2], 8L, false, BigInteger.ONE))) - //.addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[2], ctxt.addresses[0], 20L, false, BigInteger.ONE))) - //.addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[2], 50L, true, BigInteger.ONE))) - //.addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[2], 10L, false, BigInteger.ONE))) + .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[2], ctxt.addresses[0], 20L, false, BigInteger.ONE))) + .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[2], 50L, true, BigInteger.ONE))) // this action is reverted + .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[2], 10L, false, BigInteger.ONE))) .transactionProcessingResultValidator(resultValidator) .build() .run(); @@ -562,8 +563,8 @@ void testConflationMapAccount() { }; // expected last values for the keys we are testing Wei[] expectedLast = { - TestContext.defaultBalance.subtract(8L), - TestContext.defaultBalance.add(8L), + TestContext.defaultBalance.subtract(8L).add(20L).subtract(10L), + TestContext.defaultBalance.add(8L).subtract(20L).add(10L), }; // prepare the key pairs @@ -572,7 +573,7 @@ void testConflationMapAccount() { ctxt.initialAccounts[2].getAddress(), }; - for (int i = 1; i < keys.length; i++) { + for (int i = 0; i < keys.length; i++) { TransactionProcessingMetadata. FragmentFirstAndLast accountData = conflationMap.get(keys[i]); // asserts for the first and last storage values in conflation From ff547ed47f24910eba8230abffc20da916f355c1 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Tue, 29 Oct 2024 02:13:39 +0100 Subject: [PATCH 56/74] account maps --- .../zktracer/StateManagerSolidityTest.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index 855a286d85..4e471aa218 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -35,6 +35,7 @@ import org.hyperledger.besu.crypto.SECP256K1; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.Quantity; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; @@ -539,15 +540,25 @@ void testConflationMapAccount() { // fetch the Hub metadata for the state manager maps StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); + // compute the addresses for several accounts that will be deployed later + ctxt.addresses[3] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); + ctxt.addresses[4] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); + ctxt.addresses[5] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); + // prepare a multi-block execution of transactions MultiBlockExecutionEnvironment.builder() // initialize accounts .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.initialAccounts[2], ctxt.frameworkEntryPointAccount)) - // test storage operations for an account prexisting in the state + // test account operations for an account prexisting in the state .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[2], 8L, false, BigInteger.ONE))) .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[2], ctxt.addresses[0], 20L, false, BigInteger.ONE))) .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[2], 50L, true, BigInteger.ONE))) // this action is reverted .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[2], 10L, false, BigInteger.ONE))) + // deploy another account ctxt.addresses[3] and perform account operations on it + .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[3], 49L, false, BigInteger.ONE))) + .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], ctxt.addresses[0], 27L, false, BigInteger.ONE))) + .transactionProcessingResultValidator(resultValidator) .build() .run(); @@ -560,17 +571,21 @@ void testConflationMapAccount() { Wei[] expectedFirst = { TestContext.defaultBalance, TestContext.defaultBalance, + Wei.of(0L), }; // expected last values for the keys we are testing Wei[] expectedLast = { - TestContext.defaultBalance.subtract(8L).add(20L).subtract(10L), + TestContext.defaultBalance.subtract(8L).add(20L). + subtract(10L).subtract(49L).add(27L), TestContext.defaultBalance.add(8L).subtract(20L).add(10L), + Wei.of(0L).add(49L).subtract(27L) }; // prepare the key pairs Address[] keys = { ctxt.initialAccounts[0].getAddress(), ctxt.initialAccounts[2].getAddress(), + ctxt.addresses[3], }; for (int i = 0; i < keys.length; i++) { From 9a8dd043fb0351e1276a9a4f4be610b07844405f Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Tue, 29 Oct 2024 02:31:43 +0100 Subject: [PATCH 57/74] account operations --- .../zktracer/StateManagerSolidityTest.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index 4e471aa218..d397163fc4 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -558,7 +558,15 @@ void testConflationMapAccount() { .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[3], 49L, false, BigInteger.ONE))) .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], ctxt.addresses[0], 27L, false, BigInteger.ONE))) - + // deploy another account and self destruct it at the end, redeploy it and change its balance again + .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[4], 98L, false, BigInteger.ONE))) + .addBlock(List.of(selfDestruct(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], ctxt.addresses[2], false, BigInteger.ONE))) + .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[4], 123L, false, BigInteger.ONE))) + // deploy a new account and check revert operations on it + .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000004", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[2], ctxt.addresses[5], 1L, true, BigInteger.ONE))) .transactionProcessingResultValidator(resultValidator) .build() .run(); @@ -572,13 +580,17 @@ void testConflationMapAccount() { TestContext.defaultBalance, TestContext.defaultBalance, Wei.of(0L), + Wei.of(0L) }; // expected last values for the keys we are testing Wei[] expectedLast = { TestContext.defaultBalance.subtract(8L).add(20L). - subtract(10L).subtract(49L).add(27L), - TestContext.defaultBalance.add(8L).subtract(20L).add(10L), - Wei.of(0L).add(49L).subtract(27L) + subtract(10L).subtract(49L).add(27L) + .subtract(98L).subtract(123L), + TestContext.defaultBalance.add(8L).subtract(20L).add(10L) + .add(98L), // 98L obtained from the self destruct of the account at ctxt.addresses[4] + Wei.of(0L).add(49L).subtract(27L), + Wei.of(123L) }; // prepare the key pairs @@ -586,6 +598,7 @@ void testConflationMapAccount() { ctxt.initialAccounts[0].getAddress(), ctxt.initialAccounts[2].getAddress(), ctxt.addresses[3], + ctxt.addresses[4] }; for (int i = 0; i < keys.length; i++) { From 50a76600c47fd470bcf1cd0ef038bebd8b44ae47 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Tue, 29 Oct 2024 02:35:56 +0100 Subject: [PATCH 58/74] bug fix --- .../net/consensys/linea/zktracer/StateManagerSolidityTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index d397163fc4..0699f7ec55 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -479,7 +479,7 @@ void testConflationMapStorage() { .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, 12L, false, BigInteger.ONE))) .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, false, BigInteger.ONE))) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, 13L, false, BigInteger.ONE))) - .addBlock(List.of(selfDestruct(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, ctxt.addresses[4], false, BigInteger.ONE))) + .addBlock(List.of(selfDestruct(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], ctxt.frameworkEntryPointAddress, false, BigInteger.ONE))) .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, 99L, false, BigInteger.ONE))) // deploy a new account and check revert operations on it From ae5efd25e1993cdcbafcfd7d1f9712fdb5aaa73a Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Tue, 29 Oct 2024 13:59:54 +0100 Subject: [PATCH 59/74] better transaction validator --- .../zktracer/StateManagerSolidityTest.java | 81 ++++++++----------- .../zktracer/StateManagerTestValidator.java | 73 +++++++++++++++++ 2 files changed, 107 insertions(+), 47 deletions(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerTestValidator.java diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index 0699f7ec55..62524ebfc2 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -300,7 +300,6 @@ class TestContext { static final int numberOfAccounts = 6; static final Bytes snippetsCode = SmartContractUtils.getYulContractRuntimeByteCode("StateManagerSnippets.yul"); static final Bytes snippetsCodeForCreate2 = SmartContractUtils.getYulContractCompiledByteCode("StateManagerSnippets.yul"); - static final org.apache.tuweni.bytes.Bytes32 initCodeHashSnippet = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(TestContext.snippetsCodeForCreate2)); @Getter ToyAccount frameworkEntryPointAccount; Address frameworkEntryPointAddress; @@ -352,46 +351,7 @@ public void initializeTestContext() { } } - TransactionProcessingResultValidator getValidator() { - TransactionProcessingResultValidator resultValidator = - (Transaction transaction, TransactionProcessingResult result) -> { - TransactionProcessingResultValidator.DEFAULT_VALIDATOR.accept(transaction, result); - // One event from the snippet - // One event from the framework entrypoint about contract call - System.out.println("Number of logs: "+result.getLogs().size()); - //assertEquals(result.getLogs().size(), 2); - for (Log log : result.getLogs()) { - String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); - String writeEventSignature = EventEncoder.encode(StateManagerEvents.WRITE_EVENT); - String readEventSignature = EventEncoder.encode(StateManagerEvents.READ_EVENT); - String destroyedEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); - String createdEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTCREATED_EVENT); - String sentETHEventSignature = EventEncoder.encode(StateManagerEvents.PAYETH_EVENT); - String recETHEventSignature = EventEncoder.encode(StateManagerEvents.RECETH_EVENT); - String logTopic = log.getTopics().getFirst().toHexString(); - if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { - TestSnippet_Events.DataNoIndexesEventResponse response = - TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); - //assertEquals(response.singleInt, BigInteger.valueOf(123456)); - } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) - .equals(logTopic)) { - FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - //assertTrue(response.isSuccess); - if (logTopic.equals(createdEventSignature)) { - assertEquals(response.destination, this.ctxt.frameworkEntryPointAccount.getAddress().toHexString()); - } else { - //assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); - } - } else { - if (!(logTopic.equals(callEventSignature) || logTopic.equals(writeEventSignature) || logTopic.equals(readEventSignature) || logTopic.equals(destroyedEventSignature) || logTopic.equals(createdEventSignature) || logTopic.equals(sentETHEventSignature) || logTopic.equals(recETHEventSignature))) { - fail(); - } - } - } - }; - return resultValidator; - } + Address getCreate2AddressForSnippet(String salt) { org.apache.tuweni.bytes.Bytes32 initCodeHash = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(TestContext.snippetsCodeForCreate2)); @@ -406,13 +366,20 @@ void testBuildingBlockOperations() { // initialize the test context this.ctxt = new TestContext(); this.ctxt.initializeTestContext(); - TransactionProcessingResultValidator resultValidator = getValidator(); + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + ctxt.frameworkEntryPointAccount, + // Creates and self-destructs generate 2 logs, + // Transfers generate 3 logs, the 1s are for reverted operations + List.of(2, 2, 3, 2, 2) + ); MultiBlockExecutionEnvironment.builder() - .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) + .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.initialAccounts[2], ctxt.frameworkEntryPointAccount)) .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 1L, false, BigInteger.ZERO))) .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ZERO))) - .addBlock(List.of(selfDestruct(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.frameworkEntryPointAddress, false, BigInteger.ZERO))) + .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[2], 8L, false, BigInteger.ONE))) + // test operations above, before self-destructing a snippet in the next line + .addBlock(List.of(selfDestruct(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.frameworkEntryPointAddress, false, BigInteger.ONE))) // use BigInteger.ONE, otherwise the framework entry point gets destroyed .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) .transactionProcessingResultValidator(resultValidator) .build() @@ -427,7 +394,10 @@ void testCreate2Snippets() { // initialize the test context this.ctxt = new TestContext(); this.ctxt.initializeTestContext(); - TransactionProcessingResultValidator resultValidator = getValidator(); + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + ctxt.frameworkEntryPointAccount, + List.of(2) + ); MultiBlockExecutionEnvironment.builder() .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) .addBlock(List.of( @@ -450,7 +420,15 @@ void testConflationMapStorage() { this.ctxt = new TestContext(); this.ctxt.initializeTestContext(); // prepare the transaction validator - TransactionProcessingResultValidator resultValidator = getValidator(); + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + ctxt.frameworkEntryPointAccount, + // Creates, writes, reads and self-destructs generate 2 logs, + // Reverted operations only have 1 log + List.of(2, 2, 2, 2, 2, + 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, + 2, 2, 1, 1) + ); // fetch the Hub metadata for the state manager maps StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); // compute the addresses for several accounts that will be deployed later @@ -536,7 +514,15 @@ void testConflationMapAccount() { this.ctxt = new TestContext(); this.ctxt.initializeTestContext(); // prepare the transaction validator - TransactionProcessingResultValidator resultValidator = getValidator(); + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + ctxt.frameworkEntryPointAccount, + // Creates and self-destructs generate 2 logs, + // Transfers generate 3 logs, the 1s are for reverted operations + List.of(3, 3, 1, 3, + 2, 3, 3, + 2, 3, 2, 2, 3, + 2, 1) + ); // fetch the Hub metadata for the state manager maps StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); @@ -602,6 +588,7 @@ void testConflationMapAccount() { }; for (int i = 0; i < keys.length; i++) { + System.out.println("Index is "+i); TransactionProcessingMetadata. FragmentFirstAndLast accountData = conflationMap.get(keys[i]); // asserts for the first and last storage values in conflation diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerTestValidator.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerTestValidator.java new file mode 100644 index 0000000000..8bb2a346d2 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerTestValidator.java @@ -0,0 +1,73 @@ +package net.consensys.linea.zktracer; + +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import net.consensys.linea.testing.ToyAccount; +import net.consensys.linea.testing.TransactionProcessingResultValidator; +import net.consensys.linea.testing.Web3jUtils; +import net.consensys.linea.testing.generated.FrameworkEntrypoint; +import net.consensys.linea.testing.generated.StateManagerEvents; +import net.consensys.linea.testing.generated.TestSnippet_Events; +import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; +import org.hyperledger.besu.evm.log.Log; +import org.web3j.abi.EventEncoder; + +import java.util.List; + +import static org.assertj.core.api.Fail.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@RequiredArgsConstructor +public class StateManagerTestValidator implements TransactionProcessingResultValidator { + @NonNull + ToyAccount frameworkEntryPointAccount; + @NonNull + List expectedNoLogs; + int txCounter = 0; + @Override + public void accept(Transaction transaction, TransactionProcessingResult result) { + TransactionProcessingResultValidator.DEFAULT_VALIDATOR.accept(transaction, result); + // One event from the snippet + // One event from the framework entrypoint about contract call + System.out.println("Number of logs: "+result.getLogs().size()); + assertEquals(result.getLogs().size(), expectedNoLogs.get(txCounter)); + for (Log log : result.getLogs()) { + String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); + String writeEventSignature = EventEncoder.encode(StateManagerEvents.WRITE_EVENT); + String readEventSignature = EventEncoder.encode(StateManagerEvents.READ_EVENT); + String destroyedEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); + String createdEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTCREATED_EVENT); + String sentETHEventSignature = EventEncoder.encode(StateManagerEvents.PAYETH_EVENT); + String recETHEventSignature = EventEncoder.encode(StateManagerEvents.RECETH_EVENT); + String logTopic = log.getTopics().getFirst().toHexString(); + if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { + TestSnippet_Events.DataNoIndexesEventResponse response = + TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); + //assertEquals(response.singleInt, BigInteger.valueOf(123456)); + } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) + .equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + if (result.getLogs().size() != 1) { + // when the number of logs is 1, in our tests we will have an operation + // with the revert flag set to true. + assertTrue(response.isSuccess); + } + if (logTopic.equals(createdEventSignature)) { + assertEquals(response.destination, frameworkEntryPointAccount.getAddress().toHexString()); + } else { + //assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); + } + } else { + if (!(logTopic.equals(callEventSignature) || logTopic.equals(writeEventSignature) || logTopic.equals(readEventSignature) || logTopic.equals(destroyedEventSignature) || logTopic.equals(createdEventSignature) || logTopic.equals(sentETHEventSignature) || logTopic.equals(recETHEventSignature))) { + fail(); + } + } + } + txCounter++; + } +} From b93f02c9cc426b9a061a1b78d1cb4d8b76797468 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Tue, 29 Oct 2024 17:37:02 +0100 Subject: [PATCH 60/74] refactor --- .../zktracer/StateManagerSolidityTest.java | 466 +++--------------- .../consensys/linea/zktracer/TestContext.java | 322 ++++++++++++ 2 files changed, 395 insertions(+), 393 deletions(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/TestContext.java diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java index 62524ebfc2..aacfba45d7 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java @@ -19,15 +19,10 @@ import lombok.NoArgsConstructor; import net.consensys.linea.testing.*; import net.consensys.linea.testing.generated.FrameworkEntrypoint; -import net.consensys.linea.testing.generated.StateManagerEvents; -import net.consensys.linea.testing.generated.TestSnippet_Events; -import net.consensys.linea.testing.generated.TestingBase; -import net.consensys.linea.zktracer.module.add.Add; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; -import net.consensys.linea.zktracer.types.AddressUtils; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; @@ -35,17 +30,8 @@ import org.hyperledger.besu.crypto.SECP256K1; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.datatypes.Quantity; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.Transaction; -import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; -import org.hyperledger.besu.evm.log.Log; import org.junit.jupiter.api.Test; -import org.web3j.abi.EventEncoder; -import org.web3j.abi.FunctionEncoder; -import org.web3j.abi.datatypes.DynamicArray; -import org.web3j.abi.datatypes.Function; -import org.web3j.abi.datatypes.generated.Uint256; import java.math.BigInteger; import java.util.*; @@ -54,333 +40,27 @@ import static org.junit.jupiter.api.Assertions.*; public class StateManagerSolidityTest { - TestContext ctxt; - enum RevertFlag { - DISABLED, - ENABLED - } - String boolToHexString(boolean x) { - if (x) { - return "0x0000000000000000000000000000000000000000000000000000000000000001"; - } - else { - return "0x0000000000000000000000000000000000000000000000000000000000000000"; - } - } - - - // destination must be our .yul smart contract - Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, Address destination, Long key, Long value, boolean revertFlag, BigInteger callType) { - Function yulFunction = new Function("writeToStorage", - Arrays.asList(new Uint256(BigInteger.valueOf(key)), new Uint256(BigInteger.valueOf(value)), new org.web3j.abi.datatypes.Bool(revertFlag)), - Collections.emptyList()); - - var encoding = FunctionEncoder.encode(yulFunction); - FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ callType); - - List contractCalls = List.of(snippetContractCall); - Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); - Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - - - ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() - .sender(sender) - .to(this.ctxt.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit); - - if (this.ctxt.txNonce != null) { - tempTx = tempTx.nonce(++this.ctxt.txNonce); - } - Transaction tx = tempTx.build(); - if (this.ctxt.txNonce == null) { - this.ctxt.txNonce = tx.getNonce(); - } - return tx; - } - - - // destination must be our .yul smart contract - Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, Address destination, Long key, boolean revertFlag, BigInteger callType) { - Function yulFunction = new Function("readFromStorage", - Arrays.asList(new Uint256(BigInteger.valueOf(key)), new org.web3j.abi.datatypes.Bool(revertFlag)), - Collections.emptyList()); - - - var encoding = FunctionEncoder.encode(yulFunction); - FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ callType); - - List contractCalls = List.of(snippetContractCall); - Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); - Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - - ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() - .sender(sender) - .to(this.ctxt.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit); - - if (this.ctxt.txNonce != null) { - tempTx = tempTx.nonce(++this.ctxt.txNonce); - } - Transaction tx = tempTx.build(); - if (this.ctxt.txNonce == null) { - this.ctxt.txNonce = tx.getNonce(); - } - return tx; - } - - // destination must be our .yul smart contract - Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, Address destination, Address recipient, boolean revertFlag, BigInteger callType) { - String recipientAddressString = recipient.toHexString(); - Function yulFunction = new Function("selfDestruct", - Arrays.asList(new org.web3j.abi.datatypes.Address(recipientAddressString), new org.web3j.abi.datatypes.Bool(revertFlag)), - Collections.emptyList()); - - - var encoding = FunctionEncoder.encode(yulFunction); - FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ callType); // Normal call, not a delegate call as would be the default - - List contractCalls = List.of(snippetContractCall); - Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); - Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - - ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() - .sender(sender) - .to(this.ctxt.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit); - - if (this.ctxt.txNonce != null) { - tempTx = tempTx.nonce(++this.ctxt.txNonce); - } - Transaction tx = tempTx.build(); - if (this.ctxt.txNonce == null) { - this.ctxt.txNonce = tx.getNonce(); - } - return tx; - } - - // destination must be our .yul smart contract - Transaction transferTo(ToyAccount sender, KeyPair senderKeyPair, Address destination, Address recipient, long amount, boolean revertFlag, BigInteger callType) { - String recipientAddressString = recipient.toHexString(); - Function yulFunction = new Function("transferTo", - Arrays.asList(new org.web3j.abi.datatypes.Address(recipientAddressString), new Uint256(amount), new org.web3j.abi.datatypes.Bool(revertFlag)), - Collections.emptyList()); - - - var encoding = FunctionEncoder.encode(yulFunction); - FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ callType); // Normal call, not a delegate call as would be the default - - List contractCalls = List.of(snippetContractCall); - Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); - Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - - ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() - .sender(sender) - .to(this.ctxt.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit); - - if (this.ctxt.txNonce != null) { - tempTx = tempTx.nonce(++this.ctxt.txNonce); - } - Transaction tx = tempTx.build(); - if (this.ctxt.txNonce == null) { - this.ctxt.txNonce = tx.getNonce(); - } - return tx; - } - - // destination must be our .yul smart contract - Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, Address destination, String saltString, Bytes contractBytes) { - Bytes salt = Bytes.fromHexStringLenient(saltString); - // the following is the bytecode of the .yul contract - // Bytes yulContractBytes = Bytes.fromHexStringLenient("61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); - // prepare the Create2 function - Function create2Function = - new Function( - FrameworkEntrypoint.FUNC_DEPLOYWITHCREATE2, - Arrays.asList(new org.web3j.abi.datatypes.generated.Bytes32(salt.toArray()), - new org.web3j.abi.datatypes.DynamicBytes(contractBytes.toArray())), - Collections.emptyList()); - - String encoding = FunctionEncoder.encode(create2Function); - - FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ BigInteger.ONE); // Normal call, not a delegate call as it is the default - - - List contractCalls = List.of(snippetContractCall); - Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); - - Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - - ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() - .sender(sender) - .to(this.ctxt.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit); - - if (this.ctxt.txNonce != null) { - tempTx = tempTx.nonce(++this.ctxt.txNonce); - } - Transaction tx = tempTx.build(); - if (this.ctxt.txNonce == null) { - this.ctxt.txNonce = tx.getNonce(); - } - return tx; - } - - - @NoArgsConstructor - class TestContext { - Long txNonce = null; - static final Long gasLimit = 5000000L; - static final Wei defaultBalance = Wei.fromEth(3); - static final int numberOfAccounts = 6; - static final Bytes snippetsCode = SmartContractUtils.getYulContractRuntimeByteCode("StateManagerSnippets.yul"); - static final Bytes snippetsCodeForCreate2 = SmartContractUtils.getYulContractCompiledByteCode("StateManagerSnippets.yul"); - @Getter - ToyAccount frameworkEntryPointAccount; - Address frameworkEntryPointAddress; - ToyAccount[] initialAccounts; - Address[] addresses; - KeyPair[] initialKeyPairs; - public void initializeTestContext() { - // initialize vectors - initialAccounts = new ToyAccount[numberOfAccounts]; - initialKeyPairs = new KeyPair[numberOfAccounts]; - addresses = new Address[numberOfAccounts]; - // initialize the testing framework entry point account - frameworkEntryPointAccount = - ToyAccount.builder() - .address(Address.fromHexString("0x22222")) - .balance(defaultBalance) - .nonce(5) - .code(SmartContractUtils.getSolidityContractRuntimeByteCode(FrameworkEntrypoint.class)) - .build(); - frameworkEntryPointAddress = frameworkEntryPointAccount.getAddress(); - // initialize the .yul snippets account - // load the .yul bytecode - initialAccounts[0] = - ToyAccount.builder() - .address(Address.fromHexString("0x11111")) - .balance(defaultBalance) - .nonce(6) - .code(TestContext.snippetsCode) - .build(); - addresses[0] = initialAccounts[0].getAddress(); - // generate extra accounts - KeyPair keyPair = new SECP256K1().generateKeyPair(); - Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); - ToyAccount senderAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); - // add to arrays - initialAccounts[1] = senderAccount; - initialKeyPairs[1] = keyPair; - addresses[1] = initialAccounts[1].getAddress(); - // an account with revert - initialAccounts[2] = - ToyAccount.builder() - .address(Address.fromHexString("0x44444")) - .balance(defaultBalance) - .nonce(8) - .code(SmartContractUtils.getYulContractRuntimeByteCode("StateManagerSnippets.yul")) - .build(); - addresses[2] = initialAccounts[2].getAddress(); - } - } - - - - Address getCreate2AddressForSnippet(String salt) { - org.apache.tuweni.bytes.Bytes32 initCodeHash = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(TestContext.snippetsCodeForCreate2)); - org.apache.tuweni.bytes.Bytes32 targetAddress = AddressUtils.getCreate2RawAddress(ctxt.frameworkEntryPointAccount.getAddress(), - org.apache.tuweni.bytes.Bytes32.wrap(Bytes.fromHexStringLenient(salt).toArray()), - initCodeHash); - return Address.extract(targetAddress); - } - + TestContext tc; @Test void testBuildingBlockOperations() { // initialize the test context - this.ctxt = new TestContext(); - this.ctxt.initializeTestContext(); + this.tc = new TestContext(); + this.tc.initializeTestContext(); TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( - ctxt.frameworkEntryPointAccount, + tc.frameworkEntryPointAccount, // Creates and self-destructs generate 2 logs, // Transfers generate 3 logs, the 1s are for reverted operations List.of(2, 2, 3, 2, 2) ); MultiBlockExecutionEnvironment.builder() - .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.initialAccounts[2], ctxt.frameworkEntryPointAccount)) - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 1L, false, BigInteger.ZERO))) - .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ZERO))) - .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[2], 8L, false, BigInteger.ONE))) + .accounts(List.of(tc.initialAccounts[0], tc.initialAccounts[1], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) + .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], 123L, 1L, false, BigInteger.ZERO))) + .addBlock(List.of(tc.readFromStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], 123L, false, BigInteger.ZERO))) + .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], tc.addresses[2], 8L, false, BigInteger.ONE))) // test operations above, before self-destructing a snippet in the next line - .addBlock(List.of(selfDestruct(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.frameworkEntryPointAddress, false, BigInteger.ONE))) // use BigInteger.ONE, otherwise the framework entry point gets destroyed - .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(tc.selfDestruct(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], tc.frameworkEntryPointAddress, false, BigInteger.ONE))) // use BigInteger.ONE, otherwise the framework entry point gets destroyed + .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) .transactionProcessingResultValidator(resultValidator) .build() .run(); @@ -392,18 +72,18 @@ void testBuildingBlockOperations() { @Test void testCreate2Snippets() { // initialize the test context - this.ctxt = new TestContext(); - this.ctxt.initializeTestContext(); + this.tc = new TestContext(); + this.tc.initializeTestContext(); TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( - ctxt.frameworkEntryPointAccount, + tc.frameworkEntryPointAccount, List.of(2) ); MultiBlockExecutionEnvironment.builder() - .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.frameworkEntryPointAccount)) + .accounts(List.of(tc.initialAccounts[0], tc.initialAccounts[1], tc.frameworkEntryPointAccount)) .addBlock(List.of( - deployWithCreate2(ctxt.initialAccounts[1], - ctxt.initialKeyPairs[1], - ctxt.frameworkEntryPointAddress, + tc.deployWithCreate2(tc.initialAccounts[1], + tc.initialKeyPairs[1], + tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) .transactionProcessingResultValidator(resultValidator) @@ -417,11 +97,11 @@ void testCreate2Snippets() { @Test void testConflationMapStorage() { // initialize the test context - this.ctxt = new TestContext(); - this.ctxt.initializeTestContext(); + this.tc = new TestContext(); + this.tc.initializeTestContext(); // prepare the transaction validator TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( - ctxt.frameworkEntryPointAccount, + tc.frameworkEntryPointAccount, // Creates, writes, reads and self-destructs generate 2 logs, // Reverted operations only have 1 log List.of(2, 2, 2, 2, 2, @@ -432,39 +112,39 @@ void testConflationMapStorage() { // fetch the Hub metadata for the state manager maps StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); // compute the addresses for several accounts that will be deployed later - ctxt.addresses[3] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); - ctxt.addresses[4] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); - ctxt.addresses[5] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); + tc.addresses[3] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); + tc.addresses[4] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); + tc.addresses[5] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); // prepare a multi-block execution of transactions MultiBlockExecutionEnvironment.builder() // initialize accounts - .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.initialAccounts[2], ctxt.frameworkEntryPointAccount)) + .accounts(List.of(tc.initialAccounts[0], tc.initialAccounts[1], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) // test storage operations for an account prexisting in the state - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 8L, false, BigInteger.ONE))) - .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ONE))) - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 10L, false, BigInteger.ONE))) - .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, false, BigInteger.ONE))) - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], 123L, 15L, false, BigInteger.ONE))) + .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], 123L, 8L, false, BigInteger.ONE))) + .addBlock(List.of(tc.readFromStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], 123L, false, BigInteger.ONE))) + .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], 123L, 10L, false, BigInteger.ONE))) + .addBlock(List.of(tc.readFromStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], 123L, false, BigInteger.ONE))) + .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], 123L, 15L, false, BigInteger.ONE))) // deploy another account and perform storage operations on it - .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, 20L, false, BigInteger.ONE))) - .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, false, BigInteger.ONE))) - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], 345L, 40L, false, BigInteger.ONE))) + .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[3], 345L, 20L, false, BigInteger.ONE))) + .addBlock(List.of(tc.readFromStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[3], 345L, false, BigInteger.ONE))) + .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[3], 345L, 40L, false, BigInteger.ONE))) // deploy another account and self destruct it at the end, redeploy it and change the storage again // the salt will be the same twice in a row, which will be on purpose - .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, 12L, false, BigInteger.ONE))) - .addBlock(List.of(readFromStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, false, BigInteger.ONE))) - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, 13L, false, BigInteger.ONE))) - .addBlock(List.of(selfDestruct(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], ctxt.frameworkEntryPointAddress, false, BigInteger.ONE))) - .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], 400L, 99L, false, BigInteger.ONE))) + .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[4], 400L, 12L, false, BigInteger.ONE))) + .addBlock(List.of(tc.readFromStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[4], 400L, false, BigInteger.ONE))) + .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[4], 400L, 13L, false, BigInteger.ONE))) + .addBlock(List.of(tc.selfDestruct(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[4], tc.frameworkEntryPointAddress, false, BigInteger.ONE))) + .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[4], 400L, 99L, false, BigInteger.ONE))) // deploy a new account and check revert operations on it - .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000004", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[5], 500L, 23L, false, BigInteger.ONE))) - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[5], 500L, 53L, true, BigInteger.ONE))) // revert flag on - .addBlock(List.of(writeToStorage(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[5], 500L, 63L, true, BigInteger.ONE))) // revert flag on + .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000004", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[5], 500L, 23L, false, BigInteger.ONE))) + .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[5], 500L, 53L, true, BigInteger.ONE))) // revert flag on + .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[5], 500L, 63L, true, BigInteger.ONE))) // revert flag on .transactionProcessingResultValidator(resultValidator) .build() .run(); @@ -491,10 +171,10 @@ void testConflationMapStorage() { }; // prepare the key pairs TransactionProcessingMetadata.AddrStorageKeyPair[] keys = { - new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.initialAccounts[0].getAddress(), EWord.of(123L)), - new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.addresses[3], EWord.of(345L)), - new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.addresses[4], EWord.of(400L)), - new TransactionProcessingMetadata.AddrStorageKeyPair(ctxt.addresses[5], EWord.of(500L)) + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.initialAccounts[0].getAddress(), EWord.of(123L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.addresses[3], EWord.of(345L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.addresses[4], EWord.of(400L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.addresses[5], EWord.of(500L)) }; for (int i = 0; i < keys.length; i++) { @@ -511,11 +191,11 @@ void testConflationMapStorage() { @Test void testConflationMapAccount() { // initialize the test context - this.ctxt = new TestContext(); - this.ctxt.initializeTestContext(); + this.tc = new TestContext(); + this.tc.initializeTestContext(); // prepare the transaction validator TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( - ctxt.frameworkEntryPointAccount, + tc.frameworkEntryPointAccount, // Creates and self-destructs generate 2 logs, // Transfers generate 3 logs, the 1s are for reverted operations List.of(3, 3, 1, 3, @@ -527,32 +207,32 @@ void testConflationMapAccount() { StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); // compute the addresses for several accounts that will be deployed later - ctxt.addresses[3] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); - ctxt.addresses[4] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); - ctxt.addresses[5] = getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); + tc.addresses[3] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); + tc.addresses[4] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); + tc.addresses[5] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); // prepare a multi-block execution of transactions MultiBlockExecutionEnvironment.builder() // initialize accounts - .accounts(List.of(ctxt.initialAccounts[0], ctxt.initialAccounts[1], ctxt.initialAccounts[2], ctxt.frameworkEntryPointAccount)) + .accounts(List.of(tc.initialAccounts[0], tc.initialAccounts[1], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) // test account operations for an account prexisting in the state - .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[2], 8L, false, BigInteger.ONE))) - .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[2], ctxt.addresses[0], 20L, false, BigInteger.ONE))) - .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[2], 50L, true, BigInteger.ONE))) // this action is reverted - .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[2], 10L, false, BigInteger.ONE))) + .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], tc.addresses[2], 8L, false, BigInteger.ONE))) + .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[2], tc.addresses[0], 20L, false, BigInteger.ONE))) + .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], tc.addresses[2], 50L, true, BigInteger.ONE))) // this action is reverted + .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], tc.addresses[2], 10L, false, BigInteger.ONE))) // deploy another account ctxt.addresses[3] and perform account operations on it - .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[3], 49L, false, BigInteger.ONE))) - .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[3], ctxt.addresses[0], 27L, false, BigInteger.ONE))) + .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], tc.addresses[3], 49L, false, BigInteger.ONE))) + .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[3], tc.addresses[0], 27L, false, BigInteger.ONE))) // deploy another account and self destruct it at the end, redeploy it and change its balance again - .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[4], 98L, false, BigInteger.ONE))) - .addBlock(List.of(selfDestruct(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[4], ctxt.addresses[2], false, BigInteger.ONE))) - .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[0], ctxt.addresses[4], 123L, false, BigInteger.ONE))) + .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], tc.addresses[4], 98L, false, BigInteger.ONE))) + .addBlock(List.of(tc.selfDestruct(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[4], tc.addresses[2], false, BigInteger.ONE))) + .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], tc.addresses[4], 123L, false, BigInteger.ONE))) // deploy a new account and check revert operations on it - .addBlock(List.of(deployWithCreate2(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000004", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(transferTo(ctxt.initialAccounts[1], ctxt.initialKeyPairs[1], ctxt.addresses[2], ctxt.addresses[5], 1L, true, BigInteger.ONE))) + .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000004", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[2], tc.addresses[5], 1L, true, BigInteger.ONE))) .transactionProcessingResultValidator(resultValidator) .build() .run(); @@ -581,10 +261,10 @@ void testConflationMapAccount() { // prepare the key pairs Address[] keys = { - ctxt.initialAccounts[0].getAddress(), - ctxt.initialAccounts[2].getAddress(), - ctxt.addresses[3], - ctxt.addresses[4] + tc.initialAccounts[0].getAddress(), + tc.initialAccounts[2].getAddress(), + tc.addresses[3], + tc.addresses[4] }; for (int i = 0; i < keys.length; i++) { diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/TestContext.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/TestContext.java new file mode 100644 index 0000000000..30f4edad7e --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/TestContext.java @@ -0,0 +1,322 @@ +package net.consensys.linea.zktracer; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import net.consensys.linea.testing.*; +import net.consensys.linea.testing.generated.FrameworkEntrypoint; +import net.consensys.linea.testing.generated.StateManagerEvents; +import net.consensys.linea.testing.generated.TestSnippet_Events; +import net.consensys.linea.zktracer.types.AddressUtils; +import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.crypto.KeyPair; +import org.hyperledger.besu.crypto.SECP256K1; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; +import org.hyperledger.besu.evm.log.Log; +import org.web3j.abi.EventEncoder; +import org.web3j.abi.FunctionEncoder; +import org.web3j.abi.datatypes.DynamicArray; +import org.web3j.abi.datatypes.Function; +import org.web3j.abi.datatypes.generated.Uint256; + +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.assertj.core.api.Fail.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +@NoArgsConstructor +public class TestContext { + Long txNonce = null; + static final Long gasLimit = 5000000L; + static final Wei defaultBalance = Wei.fromEth(3); + static final int numberOfAccounts = 6; + static final Bytes snippetsCode = SmartContractUtils.getYulContractRuntimeByteCode("StateManagerSnippets.yul"); + static final Bytes snippetsCodeForCreate2 = SmartContractUtils.getYulContractCompiledByteCode("StateManagerSnippets.yul"); + @Getter + ToyAccount frameworkEntryPointAccount; + Address frameworkEntryPointAddress; + ToyAccount[] initialAccounts; + Address[] addresses; + KeyPair[] initialKeyPairs; + public void initializeTestContext() { + // initialize vectors + initialAccounts = new ToyAccount[numberOfAccounts]; + initialKeyPairs = new KeyPair[numberOfAccounts]; + addresses = new Address[numberOfAccounts]; + // initialize the testing framework entry point account + frameworkEntryPointAccount = + ToyAccount.builder() + .address(Address.fromHexString("0x22222")) + .balance(defaultBalance) + .nonce(5) + .code(SmartContractUtils.getSolidityContractRuntimeByteCode(FrameworkEntrypoint.class)) + .build(); + frameworkEntryPointAddress = frameworkEntryPointAccount.getAddress(); + // initialize the .yul snippets account + // load the .yul bytecode + initialAccounts[0] = + ToyAccount.builder() + .address(Address.fromHexString("0x11111")) + .balance(defaultBalance) + .nonce(6) + .code(TestContext.snippetsCode) + .build(); + addresses[0] = initialAccounts[0].getAddress(); + // generate extra accounts + KeyPair keyPair = new SECP256K1().generateKeyPair(); + Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); + ToyAccount senderAccount = + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + // add to arrays + initialAccounts[1] = senderAccount; + initialKeyPairs[1] = keyPair; + addresses[1] = initialAccounts[1].getAddress(); + // an account with revert + initialAccounts[2] = + ToyAccount.builder() + .address(Address.fromHexString("0x44444")) + .balance(defaultBalance) + .nonce(8) + .code(SmartContractUtils.getYulContractRuntimeByteCode("StateManagerSnippets.yul")) + .build(); + addresses[2] = initialAccounts[2].getAddress(); + } + + // destination must be our .yul smart contract + Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, Address destination, Long key, Long value, boolean revertFlag, BigInteger callType) { + Function yulFunction = new Function("writeToStorage", + Arrays.asList(new Uint256(BigInteger.valueOf(key)), new Uint256(BigInteger.valueOf(value)), new org.web3j.abi.datatypes.Bool(revertFlag)), + Collections.emptyList()); + + var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); + + List contractCalls = List.of(snippetContractCall); + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + + ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() + .sender(sender) + .to(this.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit); + + if (this.txNonce != null) { + tempTx = tempTx.nonce(++this.txNonce); + } + Transaction tx = tempTx.build(); + if (this.txNonce == null) { + this.txNonce = tx.getNonce(); + } + return tx; + } + + + // destination must be our .yul smart contract + Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, Address destination, Long key, boolean revertFlag, BigInteger callType) { + Function yulFunction = new Function("readFromStorage", + Arrays.asList(new Uint256(BigInteger.valueOf(key)), new org.web3j.abi.datatypes.Bool(revertFlag)), + Collections.emptyList()); + + + var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); + + List contractCalls = List.of(snippetContractCall); + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() + .sender(sender) + .to(this.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit); + + if (this.txNonce != null) { + tempTx = tempTx.nonce(++this.txNonce); + } + Transaction tx = tempTx.build(); + if (this.txNonce == null) { + this.txNonce = tx.getNonce(); + } + return tx; + } + + // destination must be our .yul smart contract + Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, Address destination, Address recipient, boolean revertFlag, BigInteger callType) { + String recipientAddressString = recipient.toHexString(); + Function yulFunction = new Function("selfDestruct", + Arrays.asList(new org.web3j.abi.datatypes.Address(recipientAddressString), new org.web3j.abi.datatypes.Bool(revertFlag)), + Collections.emptyList()); + + + var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); // Normal call, not a delegate call as would be the default + + List contractCalls = List.of(snippetContractCall); + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() + .sender(sender) + .to(this.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit); + + if (this.txNonce != null) { + tempTx = tempTx.nonce(++this.txNonce); + } + Transaction tx = tempTx.build(); + if (this.txNonce == null) { + this.txNonce = tx.getNonce(); + } + return tx; + } + + // destination must be our .yul smart contract + Transaction transferTo(ToyAccount sender, KeyPair senderKeyPair, Address destination, Address recipient, long amount, boolean revertFlag, BigInteger callType) { + String recipientAddressString = recipient.toHexString(); + Function yulFunction = new Function("transferTo", + Arrays.asList(new org.web3j.abi.datatypes.Address(recipientAddressString), new Uint256(amount), new org.web3j.abi.datatypes.Bool(revertFlag)), + Collections.emptyList()); + + + var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); // Normal call, not a delegate call as would be the default + + List contractCalls = List.of(snippetContractCall); + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() + .sender(sender) + .to(this.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit); + + if (this.txNonce != null) { + tempTx = tempTx.nonce(++this.txNonce); + } + Transaction tx = tempTx.build(); + if (this.txNonce == null) { + this.txNonce = tx.getNonce(); + } + return tx; + } + + // destination must be our .yul smart contract + Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, Address destination, String saltString, Bytes contractBytes) { + Bytes salt = Bytes.fromHexStringLenient(saltString); + // the following is the bytecode of the .yul contract + // Bytes yulContractBytes = Bytes.fromHexStringLenient("61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); + // prepare the Create2 function + Function create2Function = + new Function( + FrameworkEntrypoint.FUNC_DEPLOYWITHCREATE2, + Arrays.asList(new org.web3j.abi.datatypes.generated.Bytes32(salt.toArray()), + new org.web3j.abi.datatypes.DynamicBytes(contractBytes.toArray())), + Collections.emptyList()); + + String encoding = FunctionEncoder.encode(create2Function); + + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ONE); // Normal call, not a delegate call as it is the default + + + List contractCalls = List.of(snippetContractCall); + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() + .sender(sender) + .to(this.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit); + + if (this.txNonce != null) { + tempTx = tempTx.nonce(++this.txNonce); + } + Transaction tx = tempTx.build(); + if (this.txNonce == null) { + this.txNonce = tx.getNonce(); + } + return tx; + } + + public Address getCreate2AddressForSnippet(String salt) { + org.apache.tuweni.bytes.Bytes32 initCodeHash = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(TestContext.snippetsCodeForCreate2)); + org.apache.tuweni.bytes.Bytes32 targetAddress = AddressUtils.getCreate2RawAddress(frameworkEntryPointAccount.getAddress(), + org.apache.tuweni.bytes.Bytes32.wrap(Bytes.fromHexStringLenient(salt).toArray()), + initCodeHash); + return Address.extract(targetAddress); + } +} From cc62290a0994fc2c4ece6d22e534a2b7baddb55e Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Tue, 29 Oct 2024 18:47:55 +0100 Subject: [PATCH 61/74] refactor to avoid batched testing bug --- .../zktracer/StateManagerSolidityTest.java | 323 ------------------ .../statemanager/ConflationAccountTest.java | 133 ++++++++ .../statemanager/ConflationStorageTest.java | 169 +++++++++ .../{ => statemanager}/TestContext.java | 68 ++-- .../zktracer/statemanager/UtilitiesTest.java | 90 +++++ 5 files changed, 422 insertions(+), 361 deletions(-) delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationAccountTest.java create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java rename arithmetization/src/test/java/net/consensys/linea/zktracer/{ => statemanager}/TestContext.java (89%) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/UtilitiesTest.java diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java deleted file mode 100644 index aacfba45d7..0000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerSolidityTest.java +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Copyright Consensys Software 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; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import net.consensys.linea.testing.*; -import net.consensys.linea.testing.generated.FrameworkEntrypoint; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; -import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; -import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; -import net.consensys.linea.zktracer.types.EWord; -import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.crypto.KeyPair; -import org.hyperledger.besu.crypto.SECP256K1; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Hash; -import org.hyperledger.besu.datatypes.Wei; -import org.junit.jupiter.api.Test; - -import java.math.BigInteger; -import java.util.*; - -import static org.assertj.core.api.Fail.fail; -import static org.junit.jupiter.api.Assertions.*; - -public class StateManagerSolidityTest { - TestContext tc; - @Test - void testBuildingBlockOperations() { - // initialize the test context - this.tc = new TestContext(); - this.tc.initializeTestContext(); - TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( - tc.frameworkEntryPointAccount, - // Creates and self-destructs generate 2 logs, - // Transfers generate 3 logs, the 1s are for reverted operations - List.of(2, 2, 3, 2, 2) - ); - - MultiBlockExecutionEnvironment.builder() - .accounts(List.of(tc.initialAccounts[0], tc.initialAccounts[1], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) - .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], 123L, 1L, false, BigInteger.ZERO))) - .addBlock(List.of(tc.readFromStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], 123L, false, BigInteger.ZERO))) - .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], tc.addresses[2], 8L, false, BigInteger.ONE))) - // test operations above, before self-destructing a snippet in the next line - .addBlock(List.of(tc.selfDestruct(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], tc.frameworkEntryPointAddress, false, BigInteger.ONE))) // use BigInteger.ONE, otherwise the framework entry point gets destroyed - .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); - System.out.println("Done"); - } - - // Create 2 has a weird behavior and does not seem to work with the - // bytecode output by the function SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul") - @Test - void testCreate2Snippets() { -// initialize the test context - this.tc = new TestContext(); - this.tc.initializeTestContext(); - TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( - tc.frameworkEntryPointAccount, - List.of(2) - ); - MultiBlockExecutionEnvironment.builder() - .accounts(List.of(tc.initialAccounts[0], tc.initialAccounts[1], tc.frameworkEntryPointAccount)) - .addBlock(List.of( - tc.deployWithCreate2(tc.initialAccounts[1], - tc.initialKeyPairs[1], - tc.frameworkEntryPointAddress, - "0x0000000000000000000000000000000000000000000000000000000000000002", - TestContext.snippetsCodeForCreate2))) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); - System.out.println("Done"); - } - - - - @Test - void testConflationMapStorage() { - // initialize the test context - this.tc = new TestContext(); - this.tc.initializeTestContext(); - // prepare the transaction validator - TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( - tc.frameworkEntryPointAccount, - // Creates, writes, reads and self-destructs generate 2 logs, - // Reverted operations only have 1 log - List.of(2, 2, 2, 2, 2, - 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, - 2, 2, 1, 1) - ); - // fetch the Hub metadata for the state manager maps - StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); - // compute the addresses for several accounts that will be deployed later - tc.addresses[3] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); - tc.addresses[4] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); - tc.addresses[5] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); - - // prepare a multi-block execution of transactions - MultiBlockExecutionEnvironment.builder() - // initialize accounts - .accounts(List.of(tc.initialAccounts[0], tc.initialAccounts[1], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) - // test storage operations for an account prexisting in the state - .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], 123L, 8L, false, BigInteger.ONE))) - .addBlock(List.of(tc.readFromStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], 123L, false, BigInteger.ONE))) - .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], 123L, 10L, false, BigInteger.ONE))) - .addBlock(List.of(tc.readFromStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], 123L, false, BigInteger.ONE))) - .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], 123L, 15L, false, BigInteger.ONE))) - // deploy another account and perform storage operations on it - .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[3], 345L, 20L, false, BigInteger.ONE))) - .addBlock(List.of(tc.readFromStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[3], 345L, false, BigInteger.ONE))) - .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[3], 345L, 40L, false, BigInteger.ONE))) - // deploy another account and self destruct it at the end, redeploy it and change the storage again - // the salt will be the same twice in a row, which will be on purpose - .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[4], 400L, 12L, false, BigInteger.ONE))) - .addBlock(List.of(tc.readFromStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[4], 400L, false, BigInteger.ONE))) - .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[4], 400L, 13L, false, BigInteger.ONE))) - .addBlock(List.of(tc.selfDestruct(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[4], tc.frameworkEntryPointAddress, false, BigInteger.ONE))) - .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[4], 400L, 99L, false, BigInteger.ONE))) - // deploy a new account and check revert operations on it - .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000004", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[5], 500L, 23L, false, BigInteger.ONE))) - .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[5], 500L, 53L, true, BigInteger.ONE))) // revert flag on - .addBlock(List.of(tc.writeToStorage(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[5], 500L, 63L, true, BigInteger.ONE))) // revert flag on - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); - - Map> - conflationMap = stateManagerMetadata.getAccountFirstLastConflationMap(); - Map> - conflationStorage = stateManagerMetadata.getStorageFirstLastConflationMap(); - - // prepare data for asserts - // expected first values for the keys we are testing - EWord[] expectedFirst = { - EWord.of(8L), - EWord.of(20L), - EWord.of(12L), - EWord.of(23L) - }; - // expected last values for the keys we are testing - EWord[] expectedLast = { - EWord.of(15L), - EWord.of(40L), - EWord.of(99L), - EWord.of(23L) - }; - // prepare the key pairs - TransactionProcessingMetadata.AddrStorageKeyPair[] keys = { - new TransactionProcessingMetadata.AddrStorageKeyPair(tc.initialAccounts[0].getAddress(), EWord.of(123L)), - new TransactionProcessingMetadata.AddrStorageKeyPair(tc.addresses[3], EWord.of(345L)), - new TransactionProcessingMetadata.AddrStorageKeyPair(tc.addresses[4], EWord.of(400L)), - new TransactionProcessingMetadata.AddrStorageKeyPair(tc.addresses[5], EWord.of(500L)) - }; - - for (int i = 0; i < keys.length; i++) { - TransactionProcessingMetadata. FragmentFirstAndLast - storageData = conflationStorage.get(keys[i]); - // asserts for the first and last storage values in conflation - assertEquals(storageData.getFirst().getValueNext(), expectedFirst[i]); - assertEquals(storageData.getLast().getValueNext(), expectedLast[i]); - } - System.out.println("Done"); - } - - - @Test - void testConflationMapAccount() { - // initialize the test context - this.tc = new TestContext(); - this.tc.initializeTestContext(); - // prepare the transaction validator - TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( - tc.frameworkEntryPointAccount, - // Creates and self-destructs generate 2 logs, - // Transfers generate 3 logs, the 1s are for reverted operations - List.of(3, 3, 1, 3, - 2, 3, 3, - 2, 3, 2, 2, 3, - 2, 1) - ); - // fetch the Hub metadata for the state manager maps - StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); - - // compute the addresses for several accounts that will be deployed later - tc.addresses[3] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); - tc.addresses[4] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); - tc.addresses[5] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); - - // prepare a multi-block execution of transactions - MultiBlockExecutionEnvironment.builder() - // initialize accounts - .accounts(List.of(tc.initialAccounts[0], tc.initialAccounts[1], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) - // test account operations for an account prexisting in the state - .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], tc.addresses[2], 8L, false, BigInteger.ONE))) - .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[2], tc.addresses[0], 20L, false, BigInteger.ONE))) - .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], tc.addresses[2], 50L, true, BigInteger.ONE))) // this action is reverted - .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], tc.addresses[2], 10L, false, BigInteger.ONE))) - // deploy another account ctxt.addresses[3] and perform account operations on it - .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], tc.addresses[3], 49L, false, BigInteger.ONE))) - .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[3], tc.addresses[0], 27L, false, BigInteger.ONE))) - // deploy another account and self destruct it at the end, redeploy it and change its balance again - .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], tc.addresses[4], 98L, false, BigInteger.ONE))) - .addBlock(List.of(tc.selfDestruct(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[4], tc.addresses[2], false, BigInteger.ONE))) - .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[0], tc.addresses[4], 123L, false, BigInteger.ONE))) - // deploy a new account and check revert operations on it - .addBlock(List.of(tc.deployWithCreate2(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000004", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(tc.transferTo(tc.initialAccounts[1], tc.initialKeyPairs[1], tc.addresses[2], tc.addresses[5], 1L, true, BigInteger.ONE))) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); - - Map> - conflationMap = stateManagerMetadata.getAccountFirstLastConflationMap(); - - // prepare data for asserts - // expected first values for the keys we are testing - Wei[] expectedFirst = { - TestContext.defaultBalance, - TestContext.defaultBalance, - Wei.of(0L), - Wei.of(0L) - }; - // expected last values for the keys we are testing - Wei[] expectedLast = { - TestContext.defaultBalance.subtract(8L).add(20L). - subtract(10L).subtract(49L).add(27L) - .subtract(98L).subtract(123L), - TestContext.defaultBalance.add(8L).subtract(20L).add(10L) - .add(98L), // 98L obtained from the self destruct of the account at ctxt.addresses[4] - Wei.of(0L).add(49L).subtract(27L), - Wei.of(123L) - }; - - // prepare the key pairs - Address[] keys = { - tc.initialAccounts[0].getAddress(), - tc.initialAccounts[2].getAddress(), - tc.addresses[3], - tc.addresses[4] - }; - - for (int i = 0; i < keys.length; i++) { - System.out.println("Index is "+i); - TransactionProcessingMetadata. FragmentFirstAndLast - accountData = conflationMap.get(keys[i]); - // asserts for the first and last storage values in conflation - assertEquals(accountData.getFirst().oldState().balance(), expectedFirst[i]); - assertEquals(accountData.getLast().newState().balance(), expectedLast[i]); - } - - - System.out.println("Done"); - } - - - -} - -/* - TransactionProcessingResultValidator resultValidator = - (Transaction transaction, TransactionProcessingResult result) -> { - // One event from the snippet - // One event from the framework entrypoint about contract call - //assertEquals(result.getLogs().size(), 1); - System.out.println("Number of logs: "+result.getLogs().size()); - var noTopics = result.getLogs().size(); - for (Log log : result.getLogs()) { - String logTopic = log.getTopics().getFirst().toHexString(); - String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); - String writeEventSignature = EventEncoder.encode(FrameworkEntrypoint.WRITE_EVENT); - String readEventSignature = EventEncoder.encode(FrameworkEntrypoint.READ_EVENT); - String destructEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); - if (callEventSignature.equals(logTopic)) { - FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - assertTrue(response.isSuccess); - assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); - continue; - } - if (writeEventSignature.equals(logTopic)) { - // write event - continue; - } - if (readEventSignature.equals(logTopic)) { - // read event - continue; - } - if (destructEventSignature.equals(logTopic)) { - // self destruct - continue; - } - fail(); - } - }; - */ \ No newline at end of file diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationAccountTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationAccountTest.java new file mode 100644 index 0000000000..ce94e8a4ca --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationAccountTest.java @@ -0,0 +1,133 @@ +/* + * Copyright Consensys Software 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.statemanager; + +import net.consensys.linea.testing.MultiBlockExecutionEnvironment; +import net.consensys.linea.testing.TransactionProcessingResultValidator; +import net.consensys.linea.zktracer.StateManagerTestValidator; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; +import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; +import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Wei; +import org.junit.jupiter.api.Test; + +import java.math.BigInteger; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ConflationAccountTest { + TestContext tc; + @Test + void testConflationMapAccount() { + // initialize the test context + this.tc = new TestContext(); + this.tc.initializeTestContext(); + // prepare the transaction validator + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + tc.frameworkEntryPointAccount, + // Creates and self-destructs generate 2 logs, + // Transfers generate 3 logs, the 1s are for reverted operations + List.of(3, 3, 1, 3, + 2, 3, 3, + 2, 3, 2, 2, 3, + 2, 1) + ); + // fetch the Hub metadata for the state manager maps + StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); + + // compute the addresses for several accounts that will be deployed later + tc.newAddresses[0] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); + tc.newAddresses[1] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); + tc.newAddresses[2] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); + + // prepare a multi-block execution of transactions + MultiBlockExecutionEnvironment.builder() + // initialize accounts + .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) + // test account operations for an account prexisting in the state + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 8L, false, BigInteger.ONE))) + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[2], tc.addresses[0], 20L, false, BigInteger.ONE))) + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 50L, true, BigInteger.ONE))) // this action is reverted + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 10L, false, BigInteger.ONE))) + // deploy another account ctxt.addresses[3] and perform account operations on it + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.newAddresses[0], 49L, false, BigInteger.ONE))) + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[0], tc.addresses[0], 27L, false, BigInteger.ONE))) + // deploy another account and self destruct it at the end, redeploy it and change its balance again + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.newAddresses[1], 98L, false, BigInteger.ONE))) + .addBlock(List.of(tc.selfDestruct(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], tc.addresses[2], false, BigInteger.ONE))) + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.newAddresses[1], 123L, false, BigInteger.ONE))) + // deploy a new account and check revert operations on it + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000004", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[2], tc.newAddresses[2], 1L, true, BigInteger.ONE))) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); + + Map> + conflationMap = stateManagerMetadata.getAccountFirstLastConflationMap(); + + // prepare data for asserts + // expected first values for the keys we are testing + Wei[] expectedFirst = { + TestContext.defaultBalance, + TestContext.defaultBalance, + Wei.of(0L), + Wei.of(0L), + Wei.of(0L) + }; + // expected last values for the keys we are testing + Wei[] expectedLast = { + TestContext.defaultBalance.subtract(8L).add(20L). + subtract(10L).subtract(49L).add(27L) + .subtract(98L).subtract(123L), + TestContext.defaultBalance.add(8L).subtract(20L).add(10L) + .add(98L), // 98L obtained from the self destruct of the account at ctxt.addresses[4] + Wei.of(0L).add(49L).subtract(27L), + Wei.of(123L), + Wei.of(0L) + }; + + // prepare the key pairs + Address[] keys = { + tc.initialAccounts[0].getAddress(), + tc.initialAccounts[2].getAddress(), + tc.newAddresses[0], + tc.newAddresses[1], + tc.newAddresses[2] + }; + + for (int i = 0; i < keys.length; i++) { + System.out.println("Index is "+i); + TransactionProcessingMetadata. FragmentFirstAndLast + accountData = conflationMap.get(keys[i]); + // asserts for the first and last storage values in conflation + assertEquals(accountData.getFirst().oldState().balance(), expectedFirst[i]); + assertEquals(accountData.getLast().newState().balance(), expectedLast[i]); + } + + + System.out.println("Done"); + } +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java new file mode 100644 index 0000000000..d95a3a00b6 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java @@ -0,0 +1,169 @@ +/* + * Copyright Consensys Software 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.statemanager; + +import net.consensys.linea.testing.*; +import net.consensys.linea.zktracer.StateManagerTestValidator; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; +import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; +import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Wei; +import org.junit.jupiter.api.Test; + +import java.math.BigInteger; +import java.util.*; + +import static org.assertj.core.api.Fail.fail; +import static org.junit.jupiter.api.Assertions.*; + +public class ConflationStorageTest { + TestContext tc; + + @Test + void testConflationMapStorage() { + // initialize the test context + this.tc = new TestContext(); + this.tc.initializeTestContext(); + // prepare the transaction validator + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + tc.frameworkEntryPointAccount, + // Creates, writes, reads and self-destructs generate 2 logs, + // Reverted operations only have 1 log + List.of(2, 2, 2, 2, 2, + 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, + 2, 2, 1, 1) + ); + // fetch the Hub metadata for the state manager maps + StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); + // compute the addresses for several accounts that will be deployed later + tc.newAddresses[0] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); + tc.newAddresses[1] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); + tc.newAddresses[2] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); + + // prepare a multi-block execution of transactions + MultiBlockExecutionEnvironment.builder() + // initialize accounts + .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) + // test storage operations for an account prexisting in the state + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, 8L, false, BigInteger.ONE))) + .addBlock(List.of(tc.readFromStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, false, BigInteger.ONE))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, 10L, false, BigInteger.ONE))) + .addBlock(List.of(tc.readFromStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, false, BigInteger.ONE))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, 15L, false, BigInteger.ONE))) + // deploy another account and perform storage operations on it + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[0], 345L, 20L, false, BigInteger.ONE))) + .addBlock(List.of(tc.readFromStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[0], 345L, false, BigInteger.ONE))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[0], 345L, 40L, false, BigInteger.ONE))) + // deploy another account and self destruct it at the end, redeploy it and change the storage again + // the salt will be the same twice in a row, which will be on purpose + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], 400L, 12L, false, BigInteger.ONE))) + .addBlock(List.of(tc.readFromStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], 400L, false, BigInteger.ONE))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], 400L, 13L, false, BigInteger.ONE))) + .addBlock(List.of(tc.selfDestruct(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], tc.frameworkEntryPointAddress, false, BigInteger.ONE))) + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], 400L, 99L, false, BigInteger.ONE))) + // deploy a new account and check revert operations on it + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000004", TestContext.snippetsCodeForCreate2))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[2], 500L, 23L, false, BigInteger.ONE))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[2], 500L, 53L, true, BigInteger.ONE))) // revert flag on + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[2], 500L, 63L, true, BigInteger.ONE))) // revert flag on + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); + + Map> + conflationMap = stateManagerMetadata.getAccountFirstLastConflationMap(); + Map> + conflationStorage = stateManagerMetadata.getStorageFirstLastConflationMap(); + + // prepare data for asserts + // expected first values for the keys we are testing + EWord[] expectedFirst = { + EWord.of(8L), + EWord.of(20L), + EWord.of(12L), + EWord.of(23L) + }; + // expected last values for the keys we are testing + EWord[] expectedLast = { + EWord.of(15L), + EWord.of(40L), + EWord.of(99L), + EWord.of(23L) + }; + // prepare the key pairs + TransactionProcessingMetadata.AddrStorageKeyPair[] keys = { + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.initialAccounts[0].getAddress(), EWord.of(123L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.newAddresses[0], EWord.of(345L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.newAddresses[1], EWord.of(400L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.newAddresses[2], EWord.of(500L)) + }; + + for (int i = 0; i < keys.length; i++) { + TransactionProcessingMetadata. FragmentFirstAndLast + storageData = conflationStorage.get(keys[i]); + // asserts for the first and last storage values in conflation + assertEquals(storageData.getFirst().getValueNext(), expectedFirst[i]); + assertEquals(storageData.getLast().getValueNext(), expectedLast[i]); + } + System.out.println("Done"); + } +} + +/* + TransactionProcessingResultValidator resultValidator = + (Transaction transaction, TransactionProcessingResult result) -> { + // One event from the snippet + // One event from the framework entrypoint about contract call + //assertEquals(result.getLogs().size(), 1); + System.out.println("Number of logs: "+result.getLogs().size()); + var noTopics = result.getLogs().size(); + for (Log log : result.getLogs()) { + String logTopic = log.getTopics().getFirst().toHexString(); + String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); + String writeEventSignature = EventEncoder.encode(FrameworkEntrypoint.WRITE_EVENT); + String readEventSignature = EventEncoder.encode(FrameworkEntrypoint.READ_EVENT); + String destructEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); + if (callEventSignature.equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); + continue; + } + if (writeEventSignature.equals(logTopic)) { + // write event + continue; + } + if (readEventSignature.equals(logTopic)) { + // read event + continue; + } + if (destructEventSignature.equals(logTopic)) { + // self destruct + continue; + } + fail(); + } + }; + */ \ No newline at end of file diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/TestContext.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java similarity index 89% rename from arithmetization/src/test/java/net/consensys/linea/zktracer/TestContext.java rename to arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java index 30f4edad7e..ef068cd21a 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/TestContext.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java @@ -1,13 +1,9 @@ -package net.consensys.linea.zktracer; +package net.consensys.linea.zktracer.statemanager; import lombok.Getter; import lombok.NoArgsConstructor; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; import net.consensys.linea.testing.*; import net.consensys.linea.testing.generated.FrameworkEntrypoint; -import net.consensys.linea.testing.generated.StateManagerEvents; -import net.consensys.linea.testing.generated.TestSnippet_Events; import net.consensys.linea.zktracer.types.AddressUtils; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.crypto.KeyPair; @@ -16,9 +12,6 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; -import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; -import org.hyperledger.besu.evm.log.Log; -import org.web3j.abi.EventEncoder; import org.web3j.abi.FunctionEncoder; import org.web3j.abi.datatypes.DynamicArray; import org.web3j.abi.datatypes.Function; @@ -37,57 +30,56 @@ public class TestContext { Long txNonce = null; static final Long gasLimit = 5000000L; static final Wei defaultBalance = Wei.fromEth(3); - static final int numberOfAccounts = 6; + static final int numberOfAccounts = 10; + static final int numberOfNewAccounts = 10; + static final int numberOfEOA = 1; static final Bytes snippetsCode = SmartContractUtils.getYulContractRuntimeByteCode("StateManagerSnippets.yul"); static final Bytes snippetsCodeForCreate2 = SmartContractUtils.getYulContractCompiledByteCode("StateManagerSnippets.yul"); @Getter ToyAccount frameworkEntryPointAccount; Address frameworkEntryPointAddress; ToyAccount[] initialAccounts; + ToyAccount[] externallyOwnedAccounts; + KeyPair[] keyPairs; Address[] addresses; - KeyPair[] initialKeyPairs; + Address[] newAddresses; public void initializeTestContext() { // initialize vectors initialAccounts = new ToyAccount[numberOfAccounts]; - initialKeyPairs = new KeyPair[numberOfAccounts]; addresses = new Address[numberOfAccounts]; + externallyOwnedAccounts = new ToyAccount[numberOfEOA]; + keyPairs = new KeyPair[numberOfEOA]; + newAddresses = new Address[numberOfNewAccounts]; + // generate externally owned accounts + for (int i = 0; i < numberOfEOA; i++) { + KeyPair keyPair = new SECP256K1().generateKeyPair(); + Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); + externallyOwnedAccounts[i] = + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + keyPairs[i] = keyPair; + } // initialize the testing framework entry point account frameworkEntryPointAccount = ToyAccount.builder() - .address(Address.fromHexString("0x22222")) + .address(Address.fromHexString("0x123456")) .balance(defaultBalance) .nonce(5) .code(SmartContractUtils.getSolidityContractRuntimeByteCode(FrameworkEntrypoint.class)) .build(); frameworkEntryPointAddress = frameworkEntryPointAccount.getAddress(); + // add to arrays // initialize the .yul snippets account // load the .yul bytecode - initialAccounts[0] = - ToyAccount.builder() - .address(Address.fromHexString("0x11111")) - .balance(defaultBalance) - .nonce(6) - .code(TestContext.snippetsCode) - .build(); - addresses[0] = initialAccounts[0].getAddress(); - // generate extra accounts - KeyPair keyPair = new SECP256K1().generateKeyPair(); - Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); - ToyAccount senderAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); - // add to arrays - initialAccounts[1] = senderAccount; - initialKeyPairs[1] = keyPair; - addresses[1] = initialAccounts[1].getAddress(); - // an account with revert - initialAccounts[2] = - ToyAccount.builder() - .address(Address.fromHexString("0x44444")) - .balance(defaultBalance) - .nonce(8) - .code(SmartContractUtils.getYulContractRuntimeByteCode("StateManagerSnippets.yul")) - .build(); - addresses[2] = initialAccounts[2].getAddress(); + for (int i = 0; i < numberOfAccounts; i++) { + + initialAccounts[i] = + ToyAccount.builder() + .address(Address.fromHexString("0x" + i + i + i + i + i)) + .balance(defaultBalance) + .nonce(6) + .code(TestContext.snippetsCode) + .build(); + addresses[i] = initialAccounts[i].getAddress(); } } // destination must be our .yul smart contract diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/UtilitiesTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/UtilitiesTest.java new file mode 100644 index 0000000000..28fbd6a534 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/UtilitiesTest.java @@ -0,0 +1,90 @@ +/* + * Copyright Consensys Software 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.statemanager; + +import net.consensys.linea.testing.MultiBlockExecutionEnvironment; +import net.consensys.linea.testing.TransactionProcessingResultValidator; +import net.consensys.linea.zktracer.StateManagerTestValidator; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; +import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; +import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Wei; +import org.junit.jupiter.api.Test; + +import java.math.BigInteger; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class UtilitiesTest { + TestContext tc; + + @Test + void testBuildingBlockOperations() { + // initialize the test context + this.tc = new TestContext(); + this.tc.initializeTestContext(); + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + tc.frameworkEntryPointAccount, + // Creates and self-destructs generate 2 logs, + // Transfers generate 3 logs, the 1s are for reverted operations + List.of(2, 2, 3, 2, 2) + ); + + MultiBlockExecutionEnvironment.builder() + .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, 1L, false, BigInteger.ZERO))) + .addBlock(List.of(tc.readFromStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, false, BigInteger.ZERO))) + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 8L, false, BigInteger.ONE))) + // test operations above, before self-destructing a snippet in the next line + .addBlock(List.of(tc.selfDestruct(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.frameworkEntryPointAddress, false, BigInteger.ONE))) // use BigInteger.ONE, otherwise the framework entry point gets destroyed + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); + System.out.println("Done"); + } + + // Create 2 has a weird behavior and does not seem to work with the + // bytecode output by the function SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul") + @Test + void testCreate2Snippets() { +// initialize the test context + this.tc = new TestContext(); + this.tc.initializeTestContext(); + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + tc.frameworkEntryPointAccount, + List.of(2) + ); + MultiBlockExecutionEnvironment.builder() + .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.frameworkEntryPointAccount)) + .addBlock(List.of( + tc.deployWithCreate2(tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.frameworkEntryPointAddress, + "0x0000000000000000000000000000000000000000000000000000000000004312", + TestContext.snippetsCodeForCreate2))) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); + System.out.println("Done"); + } +} \ No newline at end of file From 53107633bd9ff005d0dd6d8f9a6e375ba7507b76 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Tue, 29 Oct 2024 23:11:11 +0100 Subject: [PATCH 62/74] bug fix + debugging blockwise storage --- .../statemanager/BlockwiseStorageTest.java | 139 ++++++++++++++++++ .../statemanager/ConflationStorageTest.java | 10 +- 2 files changed, 144 insertions(+), 5 deletions(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseStorageTest.java diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseStorageTest.java new file mode 100644 index 0000000000..94fb7447ba --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseStorageTest.java @@ -0,0 +1,139 @@ +/* + * Copyright Consensys Software 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.statemanager; + +import net.consensys.linea.testing.MultiBlockExecutionEnvironment; +import net.consensys.linea.testing.TransactionProcessingResultValidator; +import net.consensys.linea.zktracer.StateManagerTestValidator; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; +import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; +import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import org.hyperledger.besu.datatypes.Address; +import org.junit.jupiter.api.Test; + +import java.math.BigInteger; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class BlockwiseStorageTest { + TestContext tc; + + @Test + void testBlockwiseMapStorage() { + // initialize the test context + this.tc = new TestContext(); + this.tc.initializeTestContext(); + // prepare the transaction validator + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + tc.frameworkEntryPointAccount, + // Creates, writes, reads and self-destructs generate 2 logs, + // Reverted operations only have 1 log + List.of(2, 2, 2, + 2, 2, 2, + 2, 2, 2) + ); + // fetch the Hub metadata for the state manager maps + StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); + // compute the addresses for several accounts that will be deployed later + tc.newAddresses[0] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); + tc.newAddresses[1] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); + tc.newAddresses[2] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); + + // prepare a multi-block execution of transactions + MultiBlockExecutionEnvironment.builder() + // initialize accounts + .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) + // Block 1 + .addBlock(List.of( + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 1L, false, BigInteger.ONE), + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 2L, false, BigInteger.ONE), + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 3L, false, BigInteger.ONE) + )) + .addBlock(List.of( + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 4L, false, BigInteger.ONE), + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 5L, false, BigInteger.ONE), + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 6L, false, BigInteger.ONE) + )) + .addBlock(List.of( + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 7L, false, BigInteger.ONE), + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 8L, false, BigInteger.ONE), + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 9L, false, BigInteger.ONE) + )) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); + + + Map> + blockMap = stateManagerMetadata.getStorageFirstLastBlockMap(); + + // prepare data for asserts + // expected first values for the keys we are testing + int noBlocks = 3; + EWord[][] expectedFirst = { + { + EWord.of(0L), + }, + { + EWord.of(3L), + }, + { + EWord.of(6L), + }, + }; + // expected last values for the keys we are testing + EWord[][] expectedLast = { + { + EWord.of(3L), + }, + { + EWord.of(6L), + }, + { + EWord.of(9L), + }, + + }; + // prepare the key pairs + TransactionProcessingMetadata.AddrStorageKeyPair[] rawKeys = { + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.initialAccounts[0].getAddress(), EWord.of(3L)), + }; + + + // blocks are numbered starting from 1 + for (int block = 1; block <= noBlocks; block++) { + for (int i = 0; i < rawKeys.length; i++) { + StateManagerMetadata.AddrStorageKeyBlockNumTuple key = + new StateManagerMetadata.AddrStorageKeyBlockNumTuple( + rawKeys[i], + block); + TransactionProcessingMetadata. FragmentFirstAndLast + storageData = blockMap.get(key); + // asserts for the first and last storage values in conflation + // -1 due to block numbering + assertEquals(storageData.getFirst().getValueCurrent(), expectedFirst[block-1][i]); + assertEquals(storageData.getLast().getValueNext(), expectedLast[block-1][i]); + } + } + + System.out.println("Done"); + } +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java index d95a3a00b6..e88c123392 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java @@ -99,10 +99,10 @@ void testConflationMapStorage() { // prepare data for asserts // expected first values for the keys we are testing EWord[] expectedFirst = { - EWord.of(8L), - EWord.of(20L), - EWord.of(12L), - EWord.of(23L) + EWord.of(0L), + EWord.of(0), + EWord.of(0), + EWord.of(0) }; // expected last values for the keys we are testing EWord[] expectedLast = { @@ -123,7 +123,7 @@ void testConflationMapStorage() { TransactionProcessingMetadata. FragmentFirstAndLast storageData = conflationStorage.get(keys[i]); // asserts for the first and last storage values in conflation - assertEquals(storageData.getFirst().getValueNext(), expectedFirst[i]); + assertEquals(storageData.getFirst().getValueCurrent(), expectedFirst[i]); assertEquals(storageData.getLast().getValueNext(), expectedLast[i]); } System.out.println("Done"); From ac67471fc270109c0556d7aed0c293d818f62fea Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Wed, 30 Oct 2024 00:23:03 +0100 Subject: [PATCH 63/74] transaction map storage testing --- .../linea/zktracer/module/hub/Hub.java | 1 + .../hub/transients/StateManagerMetadata.java | 8 +- .../zktracer/statemanager/TestContext.java | 48 ++++++++ .../statemanager/TransactionStorageTest.java | 109 ++++++++++++++++++ 4 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java 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 4b21e5dc6d..760a800347 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 @@ -454,6 +454,7 @@ public Hub( blockdata /* WARN: must be called AFTER txnData */), precompileLimitModules().stream()) .toList(); + stateManagerMetadata.setHub(this); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java index bb9a8440a1..e181672e93 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java @@ -18,14 +18,18 @@ import java.util.HashMap; import java.util.Map; -import lombok.EqualsAndHashCode; -import lombok.Getter; +import lombok.*; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.TransactionStack; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.hyperledger.besu.datatypes.Address; public class StateManagerMetadata { + @Setter @Getter + Hub hub; + @EqualsAndHashCode public static class AddrBlockPair { @Getter private Address address; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java index ef068cd21a..2266816d3c 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java @@ -82,6 +82,54 @@ public void initializeTestContext() { addresses[i] = initialAccounts[i].getAddress(); } } + + // destination must be our .yul smart contract + FrameworkEntrypoint.ContractCall writeToStorageCall(Address destination, Long key, Long value, boolean revertFlag, BigInteger callType) { + Function yulFunction = new Function("writeToStorage", + Arrays.asList(new Uint256(BigInteger.valueOf(key)), new Uint256(BigInteger.valueOf(value)), new org.web3j.abi.datatypes.Bool(revertFlag)), + Collections.emptyList()); + + var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); + return snippetContractCall; + } + + // destination must be our .yul smart contract + Transaction wrapWrite(ToyAccount sender, KeyPair senderKeyPair, FrameworkEntrypoint.ContractCall[] contractCalls) { + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + + ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() + .sender(sender) + .to(this.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit); + + if (this.txNonce != null) { + tempTx = tempTx.nonce(++this.txNonce); + } + Transaction tx = tempTx.build(); + if (this.txNonce == null) { + this.txNonce = tx.getNonce(); + } + return tx; + } + + + // destination must be our .yul smart contract Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, Address destination, Long key, Long value, boolean revertFlag, BigInteger callType) { Function yulFunction = new Function("writeToStorage", diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java new file mode 100644 index 0000000000..41ddbec6cd --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java @@ -0,0 +1,109 @@ +/* + * Copyright Consensys Software 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.statemanager; + +import net.consensys.linea.testing.MultiBlockExecutionEnvironment; +import net.consensys.linea.testing.TransactionProcessingResultValidator; +import net.consensys.linea.testing.generated.FrameworkEntrypoint; +import net.consensys.linea.zktracer.StateManagerTestValidator; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; +import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; +import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import org.junit.jupiter.api.Test; + +import java.math.BigInteger; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TransactionStorageTest { + TestContext tc; + + @Test + void testTransactionMapStorage() { + // initialize the test context + this.tc = new TestContext(); + this.tc.initializeTestContext(); + // prepare the transaction validator + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + tc.frameworkEntryPointAccount, + // Creates, writes, reads and self-destructs generate 2 logs, + // Reverted operations only have 1 log + List.of(6) + ); + // fetch the Hub metadata for the state manager maps + StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); + + // prepare a multi-block execution of transactions + MultiBlockExecutionEnvironment.builder() + // initialize accounts + .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) + // Block 1 + .addBlock(List.of( + tc.wrapWrite(tc.externallyOwnedAccounts[0], tc.keyPairs[0], new FrameworkEntrypoint.ContractCall[] + { + tc.writeToStorageCall(tc.addresses[0], 3L, 1L, false, BigInteger.ONE), + tc.writeToStorageCall(tc.addresses[0], 3L, 2L, false, BigInteger.ONE), + tc.writeToStorageCall(tc.addresses[0], 3L, 3L, false, BigInteger.ONE), + }))) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); + + + List txn = Hub.stateManagerMetadata().getHub().txStack().getTransactions();; + + Map> + storageMap = txn.get(0).getStorageFirstAndLastMap(); + + // prepare data for asserts + // expected first values for the keys we are testing + int noBlocks = 3; + EWord[][] expectedFirst = { + { + EWord.of(0L), + }, + }; + // expected last values for the keys we are testing + EWord[][] expectedLast = { + { + EWord.of(3L), + }, + }; + // prepare the key pairs + TransactionProcessingMetadata.AddrStorageKeyPair[] keys = { + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.initialAccounts[0].getAddress(), EWord.of(3L)), + }; + + + // blocks are numbered starting from 1 + for (int txCounter = 1; txCounter <= txn.size(); txCounter++) { + for (int i = 0; i < keys.length; i++) { + TransactionProcessingMetadata. FragmentFirstAndLast + storageData = storageMap.get(keys[i]); + // asserts for the first and last storage values in conflation + // -1 due to block numbering + assertEquals(storageData.getFirst().getValueCurrent(), expectedFirst[txCounter-1][i]); + assertEquals(storageData.getLast().getValueNext(), expectedLast[txCounter-1][i]); + } + } + + System.out.println("Done"); + } +} From bb1977f14a8ef511f46dadd3c1c2c5b8a49b80ec Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Wed, 30 Oct 2024 00:32:24 +0100 Subject: [PATCH 64/74] two tx testing in the txMap --- .../statemanager/TransactionStorageTest.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java index 41ddbec6cd..6b8cb0af7d 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java @@ -45,7 +45,7 @@ void testTransactionMapStorage() { tc.frameworkEntryPointAccount, // Creates, writes, reads and self-destructs generate 2 logs, // Reverted operations only have 1 log - List.of(6) + List.of(6, 6) ); // fetch the Hub metadata for the state manager maps StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); @@ -61,7 +61,15 @@ void testTransactionMapStorage() { tc.writeToStorageCall(tc.addresses[0], 3L, 1L, false, BigInteger.ONE), tc.writeToStorageCall(tc.addresses[0], 3L, 2L, false, BigInteger.ONE), tc.writeToStorageCall(tc.addresses[0], 3L, 3L, false, BigInteger.ONE), - }))) + }), + tc.wrapWrite(tc.externallyOwnedAccounts[0], tc.keyPairs[0], new FrameworkEntrypoint.ContractCall[] + { + tc.writeToStorageCall(tc.addresses[0], 3L, 4L, false, BigInteger.ONE), + tc.writeToStorageCall(tc.addresses[0], 3L, 5L, false, BigInteger.ONE), + tc.writeToStorageCall(tc.addresses[0], 3L, 6L, false, BigInteger.ONE), + }) + + )) .transactionProcessingResultValidator(resultValidator) .build() .run(); @@ -69,21 +77,26 @@ void testTransactionMapStorage() { List txn = Hub.stateManagerMetadata().getHub().txStack().getTransactions();; - Map> - storageMap = txn.get(0).getStorageFirstAndLastMap(); + // prepare data for asserts // expected first values for the keys we are testing int noBlocks = 3; EWord[][] expectedFirst = { { - EWord.of(0L), + EWord.of(0L), + }, + { + EWord.of(3L), }, }; // expected last values for the keys we are testing EWord[][] expectedLast = { { - EWord.of(3L), + EWord.of(3L), + }, + { + EWord.of(6L), }, }; // prepare the key pairs @@ -94,6 +107,8 @@ void testTransactionMapStorage() { // blocks are numbered starting from 1 for (int txCounter = 1; txCounter <= txn.size(); txCounter++) { + Map> + storageMap = txn.get(txCounter-1).getStorageFirstAndLastMap(); for (int i = 0; i < keys.length; i++) { TransactionProcessingMetadata. FragmentFirstAndLast storageData = storageMap.get(keys[i]); From ff93b7e6c52a53befcfada6b8f4634d85d153e91 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Wed, 30 Oct 2024 10:47:54 +0100 Subject: [PATCH 65/74] refactor asserts --- .../linea/zktracer/statemanager/BlockwiseStorageTest.java | 4 ++-- .../linea/zktracer/statemanager/ConflationAccountTest.java | 4 ++-- .../linea/zktracer/statemanager/ConflationStorageTest.java | 4 ++-- .../linea/zktracer/statemanager/TransactionStorageTest.java | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseStorageTest.java index 94fb7447ba..8e7b9a4113 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseStorageTest.java @@ -129,8 +129,8 @@ void testBlockwiseMapStorage() { storageData = blockMap.get(key); // asserts for the first and last storage values in conflation // -1 due to block numbering - assertEquals(storageData.getFirst().getValueCurrent(), expectedFirst[block-1][i]); - assertEquals(storageData.getLast().getValueNext(), expectedLast[block-1][i]); + assertEquals(expectedFirst[block-1][i], storageData.getFirst().getValueCurrent()); + assertEquals(expectedLast[block-1][i], storageData.getLast().getValueNext()); } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationAccountTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationAccountTest.java index ce94e8a4ca..882354d12c 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationAccountTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationAccountTest.java @@ -123,8 +123,8 @@ void testConflationMapAccount() { TransactionProcessingMetadata. FragmentFirstAndLast accountData = conflationMap.get(keys[i]); // asserts for the first and last storage values in conflation - assertEquals(accountData.getFirst().oldState().balance(), expectedFirst[i]); - assertEquals(accountData.getLast().newState().balance(), expectedLast[i]); + assertEquals(expectedFirst[i], accountData.getFirst().oldState().balance()); + assertEquals(expectedLast[i], accountData.getLast().newState().balance()); } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java index e88c123392..92aea7b732 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java @@ -123,8 +123,8 @@ void testConflationMapStorage() { TransactionProcessingMetadata. FragmentFirstAndLast storageData = conflationStorage.get(keys[i]); // asserts for the first and last storage values in conflation - assertEquals(storageData.getFirst().getValueCurrent(), expectedFirst[i]); - assertEquals(storageData.getLast().getValueNext(), expectedLast[i]); + assertEquals(expectedFirst[i], storageData.getFirst().getValueCurrent()); + assertEquals(expectedLast[i], storageData.getLast().getValueNext()); } System.out.println("Done"); } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java index 6b8cb0af7d..3bc16d0bcd 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java @@ -114,8 +114,8 @@ void testTransactionMapStorage() { storageData = storageMap.get(keys[i]); // asserts for the first and last storage values in conflation // -1 due to block numbering - assertEquals(storageData.getFirst().getValueCurrent(), expectedFirst[txCounter-1][i]); - assertEquals(storageData.getLast().getValueNext(), expectedLast[txCounter-1][i]); + assertEquals(expectedFirst[txCounter-1][i], storageData.getFirst().getValueCurrent()); + assertEquals(expectedLast[txCounter-1][i], storageData.getLast().getValueNext()); } } From 045487a337b17aa57c0bbf5f06a004f90540c3b5 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Wed, 30 Oct 2024 11:23:08 +0100 Subject: [PATCH 66/74] refactor --- .../linea/zktracer/module/hub/Hub.java | 85 ++++++++++++------- 1 file changed, 52 insertions(+), 33 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 760a800347..fe87c2622c 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 @@ -1180,17 +1180,11 @@ public final boolean deploymentStatusOfAccountAddress() { return deploymentStatusOf(this.accountAddress()); } - - public void updateBlockMap() { + public void updateBlockMapAccount() { Map< StateManagerMetadata.AddrBlockPair, TransactionProcessingMetadata.FragmentFirstAndLast> - blockMapAccount = Hub.stateManagerMetadata().getAccountFirstLastBlockMap(); - - Map< - StateManagerMetadata.AddrStorageKeyBlockNumTuple, - TransactionProcessingMetadata.FragmentFirstAndLast> - blockMapStorage = Hub.stateManagerMetadata().getStorageFirstLastBlockMap(); + blockMapAccount = Hub.stateManagerMetadata().getAccountFirstLastBlockMap(); List txn = txStack.getTransactions(); @@ -1198,34 +1192,34 @@ public void updateBlockMap() { if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) { int blockNumber = transients.block().blockNumber(); Map> - localMapAccount = metadata.getAccountFirstAndLastMap(); + localMapAccount = metadata.getAccountFirstAndLastMap(); Map< TransactionProcessingMetadata.AddrStorageKeyPair, TransactionProcessingMetadata.FragmentFirstAndLast> - localMapStorage = metadata.getStorageFirstAndLastMap(); + localMapStorage = metadata.getStorageFirstAndLastMap(); // Update the block map for the account for (Address addr : localMapAccount.keySet()) { StateManagerMetadata.AddrBlockPair pairAddrBlock = - new StateManagerMetadata.AddrBlockPair(addr, blockNumber); + new StateManagerMetadata.AddrBlockPair(addr, blockNumber); // localValue exists for sure because addr belongs to the keySet of the local map TransactionProcessingMetadata.FragmentFirstAndLast localValueAccount = - localMapAccount.get(addr); + localMapAccount.get(addr); if (!blockMapAccount.containsKey(pairAddrBlock)) { // the pair is not present in the map blockMapAccount.put(pairAddrBlock, localValueAccount); } else { TransactionProcessingMetadata.FragmentFirstAndLast blockValue = - blockMapAccount.get(pairAddrBlock); + blockMapAccount.get(pairAddrBlock); // update the first part of the blockValue // Todo: Refactor and remove code duplication if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( - localValueAccount.getFirstDom(), - localValueAccount.getFirstSub(), - blockValue.getFirstDom(), - blockValue.getFirstSub())) { + localValueAccount.getFirstDom(), + localValueAccount.getFirstSub(), + blockValue.getFirstDom(), + blockValue.getFirstSub())) { // chronologically checks that localValue.First is before blockValue.First // localValue comes chronologically before, and should be the first value of the map. blockValue.setFirst(localValueAccount.getFirst()); @@ -1234,10 +1228,10 @@ public void updateBlockMap() { // update the last part of the blockValue if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( - blockValue.getLastDom(), - blockValue.getLastSub(), - localValueAccount.getLastDom(), - localValueAccount.getLastSub())) { + blockValue.getLastDom(), + blockValue.getLastSub(), + localValueAccount.getLastDom(), + localValueAccount.getLastSub())) { // chronologically checks that blockValue.Last is before localValue.Last // localValue comes chronologically after, and should be the final value of the map. blockValue.setLast(localValueAccount.getLast()); @@ -1247,30 +1241,50 @@ public void updateBlockMap() { blockMapAccount.put(pairAddrBlock, blockValue); } } + } + } + } + } + + public void updateBlockMapStorage() { + Map< + StateManagerMetadata.AddrStorageKeyBlockNumTuple, + TransactionProcessingMetadata.FragmentFirstAndLast> + blockMapStorage = Hub.stateManagerMetadata().getStorageFirstLastBlockMap(); + + List txn = txStack.getTransactions(); + + for (TransactionProcessingMetadata metadata : txn) { + if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) { + int blockNumber = transients.block().blockNumber(); + Map< + TransactionProcessingMetadata.AddrStorageKeyPair, + TransactionProcessingMetadata.FragmentFirstAndLast> + localMapStorage = metadata.getStorageFirstAndLastMap(); // Update the block map for storage for (TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair : - localMapStorage.keySet()) { + localMapStorage.keySet()) { StateManagerMetadata.AddrStorageKeyBlockNumTuple addrStorageBlockTuple = - new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, blockNumber); + new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, blockNumber); // localValue exists for sure because addr belongs to the keySet of the local map TransactionProcessingMetadata.FragmentFirstAndLast localValueStorage = - localMapStorage.get(addrStorageKeyPair); + localMapStorage.get(addrStorageKeyPair); if (!blockMapStorage.containsKey(addrStorageBlockTuple)) { // the pair is not present in the map blockMapStorage.put(addrStorageBlockTuple, localValueStorage); } else { TransactionProcessingMetadata.FragmentFirstAndLast blockValueStorage = - blockMapStorage.get(addrStorageBlockTuple); + blockMapStorage.get(addrStorageBlockTuple); // update the first part of the blockValue if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( - localValueStorage.getFirstDom(), - localValueStorage.getFirstSub(), - blockValueStorage.getFirstDom(), - blockValueStorage.getFirstSub())) { + localValueStorage.getFirstDom(), + localValueStorage.getFirstSub(), + blockValueStorage.getFirstDom(), + blockValueStorage.getFirstSub())) { // chronologically checks that localValue.First is before blockValue.First // localValue comes chronologically before, and should be the first value of the map. blockValueStorage.setFirst(localValueStorage.getFirst()); @@ -1279,10 +1293,10 @@ public void updateBlockMap() { // update the last part of the blockValue if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( - blockValueStorage.getLastDom(), - blockValueStorage.getLastSub(), - localValueStorage.getLastDom(), - localValueStorage.getLastSub())) { + blockValueStorage.getLastDom(), + blockValueStorage.getLastSub(), + localValueStorage.getLastDom(), + localValueStorage.getLastSub())) { // chronologically checks that blockValue.Last is before localValue.Last // localValue comes chronologically after, and should be the final value of the map. blockValueStorage.setLast(localValueStorage.getLast()); @@ -1297,6 +1311,11 @@ public void updateBlockMap() { } } + public void updateBlockMap() { + updateBlockMapAccount(); + updateBlockMapStorage(); + } + // Update the conflation level map for the state manager public void updateConflationMapAccount() { Map> From 405ff2cb3ea0e6d0ca44c6336666a76373778b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 30 Oct 2024 13:48:02 +0100 Subject: [PATCH 67/74] fix: added tracing for FIRST/AGAIN/FINAL in the account perspective --- .../hub/fragment/account/AccountFragment.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 2561001377..21c081d39a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -36,10 +36,12 @@ import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; import net.consensys.linea.zktracer.module.hub.section.halt.EphemeralAccount; +import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; import net.consensys.linea.zktracer.module.romlex.ContractMetadata; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.apache.tuweni.bytes.Bytes; +import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Transaction; import org.hyperledger.besu.evm.worldstate.WorldView; @@ -136,6 +138,19 @@ public Trace trace(Trace trace) { rlpAddrSubFragment.trace(trace); } + Map> transactionAccountMap = transactionProcessingMetadata.getAccountFirstAndLastMap(); + StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); + + Map> accountFirstLastBlockMap = + stateManagerMetadata.getAccountFirstLastBlockMap(); + StateManagerMetadata.AddrBlockPair current = new StateManagerMetadata.AddrBlockPair(oldState.address(), transactionProcessingMetadata.getRelativeBlockNumber()); + + Map> accountFirstLastConflationMap = + stateManagerMetadata.getAccountFirstLastConflationMap(); + + long minDeploymentNumberInBlock = stateManagerMetadata.getMinDeplNoBlock().get(current); + long maxDeploymentNumberInBlock = stateManagerMetadata.getMaxDeplNoBlock().get(current); + return trace .peekAtAccount(true) .pAccountAddressHi(highPart(oldState.address())) @@ -174,7 +189,19 @@ public Trace trace(Trace trace) { .pAccountDeploymentStatusInfty(existsInfinity) .pAccountTrmFlag(addressToTrim.isPresent()) .pAccountTrmRawAddressHi(addressToTrim.map(a -> EWord.of(a).hi()).orElse(Bytes.EMPTY)) - .pAccountIsPrecompile(isPrecompile(oldState.address())); + .pAccountIsPrecompile(isPrecompile(oldState.address())) + .pAccountFirstInTxn(this == transactionAccountMap.get(oldState.address()).getFirst()) + .pAccountAgainInTxn(this != transactionAccountMap.get(oldState.address()).getFirst()) + .pAccountFinalInTxn(this == transactionAccountMap.get(oldState.address()).getLast()) + .pAccountFirstInBlk(this == accountFirstLastBlockMap.get(current).getFirst()) + .pAccountAgainInBlk(this != accountFirstLastBlockMap.get(current).getFirst()) + .pAccountFinalInBlk(this == accountFirstLastBlockMap.get(current).getLast()) + .pAccountFirstInCnf(this == accountFirstLastConflationMap.get(oldState.address()).getFirst()) + .pAccountAgainInCnf(this != accountFirstLastConflationMap.get(oldState.address()).getFirst()) + .pAccountFinalInCnf(this == accountFirstLastConflationMap.get(oldState.address()).getLast()) + .pAccountDeploymentNumberFirstInBlock(minDeploymentNumberInBlock) + .pAccountDeploymentNumberFinalInBlock(maxDeploymentNumberInBlock) + ; } @Override From 096942bfa802d3b134c45433a67d954e2ff5edf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 30 Oct 2024 13:48:23 +0100 Subject: [PATCH 68/74] fix: added tracing for FIRST/AGAIN/FINAL in the storage perspective --- .../hub/fragment/storage/StorageFragment.java | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index d90d87ce4b..8f3cb60ee4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -20,13 +20,17 @@ import static net.consensys.linea.zktracer.types.AddressUtils.lowPart; import java.util.HashMap; +import java.util.Map; import lombok.Getter; import lombok.RequiredArgsConstructor; +import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.State; import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; @@ -70,6 +74,22 @@ public Trace trace(Trace trace) { // tracing domSubStampsSubFragment.trace(trace); + Map> + storageFirstAndLastMap = transactionProcessingMetadata.getStorageFirstAndLastMap(); + TransactionProcessingMetadata.AddrStorageKeyPair currentAddressKeyPair = new TransactionProcessingMetadata.AddrStorageKeyPair(storageSlotIdentifier.getAddress(), storageSlotIdentifier.getStorageKey()); + + StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); + Map> + storageFirstLastBlockMap = stateManagerMetadata.getStorageFirstLastBlockMap(); + StateManagerMetadata.AddrStorageKeyBlockNumTuple storageKeyBlockNumTuple = new StateManagerMetadata.AddrStorageKeyBlockNumTuple(currentAddressKeyPair, this.blockNumber); + + TransactionProcessingMetadata.FragmentFirstAndLast storageFirstLastConflationPair = stateManagerMetadata.getStorageFirstLastConflationMap().get(currentAddressKeyPair); + + StateManagerMetadata.AddrBlockPair addressBlockPair = new StateManagerMetadata.AddrBlockPair(storageSlotIdentifier.getAddress(), transactionProcessingMetadata.getRelativeBlockNumber()); + long minDeploymentNumberInBlock = stateManagerMetadata.getMinDeplNoBlock().get(addressBlockPair); + long maxDeploymentNumberInBlock = stateManagerMetadata.getMaxDeplNoBlock().get(addressBlockPair); + return trace .peekAtStorage(true) .pStorageAddressHi(highPart(storageSlotIdentifier.getAddress())) @@ -92,6 +112,18 @@ public Trace trace(Trace trace) { .pStorageValueNextIsZero(valueNext.isZero()) .pStorageValueNextIsOrig(valueNext.equals(valueOriginal)) .pStorageUnconstrainedFirst(isFirstOccurrence) - .pStorageUnconstrainedFinal(isFinalOccurrence); + .pStorageUnconstrainedFinal(isFinalOccurrence) + .pStorageFirstInTxn(this == storageFirstAndLastMap.get(currentAddressKeyPair).getFirst()) + .pStorageAgainInTxn(this != storageFirstAndLastMap.get(currentAddressKeyPair).getFirst()) + .pStorageFinalInTxn(this == storageFirstAndLastMap.get(currentAddressKeyPair).getLast()) + .pStorageFirstInBlk(this == storageFirstLastBlockMap.get(storageKeyBlockNumTuple).getFirst()) + .pStorageAgainInBlk(this != storageFirstLastBlockMap.get(storageKeyBlockNumTuple).getFirst()) + .pStorageFinalInBlk(this == storageFirstLastBlockMap.get(storageKeyBlockNumTuple).getLast()) + .pStorageFirstInCnf(this == storageFirstLastConflationPair.getFirst()) + .pStorageAgainInCnf(this != storageFirstLastConflationPair.getFirst()) + .pStorageFinalInCnf(this == storageFirstLastConflationPair.getLast()) + .pStorageDeploymentNumberFirstInBlock(minDeploymentNumberInBlock) + .pStorageDeploymentNumberFinalInBlock(maxDeploymentNumberInBlock) + ; } } From aa2012494a48e73c9461046ac03760c4c77b16fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20B=C3=A9gassat?= Date: Wed, 30 Oct 2024 13:49:27 +0100 Subject: [PATCH 69/74] spotless --- .../linea/zktracer/module/hub/Hub.java | 136 +- .../linea/zktracer/module/hub/Trace.java | 2434 ++++++++++------- .../hub/fragment/account/AccountFragment.java | 26 +- .../hub/fragment/storage/StorageFragment.java | 46 +- .../hub/transients/StateManagerMetadata.java | 4 +- .../linea/zktracer/ExampleMultiBlockTest.java | 311 ++- .../linea/zktracer/ExampleSolidityTest.java | 259 +- .../zktracer/StateManagerTestValidator.java | 110 +- .../statemanager/BlockwiseStorageTest.java | 204 +- .../statemanager/ConflationAccountTest.java | 256 +- .../statemanager/ConflationStorageTest.java | 375 ++- .../zktracer/statemanager/TestContext.java | 718 ++--- .../statemanager/TransactionStorageTest.java | 119 +- .../zktracer/statemanager/UtilitiesTest.java | 130 +- linea-constraints | 2 +- .../MultiBlockExecutionEnvironment.java | 76 +- .../linea/testing/SmartContractUtils.java | 18 +- 17 files changed, 3060 insertions(+), 2164 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 fe87c2622c..7157149ba8 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 @@ -1184,7 +1184,7 @@ public void updateBlockMapAccount() { Map< StateManagerMetadata.AddrBlockPair, TransactionProcessingMetadata.FragmentFirstAndLast> - blockMapAccount = Hub.stateManagerMetadata().getAccountFirstLastBlockMap(); + blockMapAccount = Hub.stateManagerMetadata().getAccountFirstLastBlockMap(); List txn = txStack.getTransactions(); @@ -1192,34 +1192,34 @@ public void updateBlockMapAccount() { if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) { int blockNumber = transients.block().blockNumber(); Map> - localMapAccount = metadata.getAccountFirstAndLastMap(); + localMapAccount = metadata.getAccountFirstAndLastMap(); Map< TransactionProcessingMetadata.AddrStorageKeyPair, TransactionProcessingMetadata.FragmentFirstAndLast> - localMapStorage = metadata.getStorageFirstAndLastMap(); + localMapStorage = metadata.getStorageFirstAndLastMap(); // Update the block map for the account for (Address addr : localMapAccount.keySet()) { StateManagerMetadata.AddrBlockPair pairAddrBlock = - new StateManagerMetadata.AddrBlockPair(addr, blockNumber); + new StateManagerMetadata.AddrBlockPair(addr, blockNumber); // localValue exists for sure because addr belongs to the keySet of the local map TransactionProcessingMetadata.FragmentFirstAndLast localValueAccount = - localMapAccount.get(addr); + localMapAccount.get(addr); if (!blockMapAccount.containsKey(pairAddrBlock)) { // the pair is not present in the map blockMapAccount.put(pairAddrBlock, localValueAccount); } else { TransactionProcessingMetadata.FragmentFirstAndLast blockValue = - blockMapAccount.get(pairAddrBlock); + blockMapAccount.get(pairAddrBlock); // update the first part of the blockValue // Todo: Refactor and remove code duplication if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( - localValueAccount.getFirstDom(), - localValueAccount.getFirstSub(), - blockValue.getFirstDom(), - blockValue.getFirstSub())) { + localValueAccount.getFirstDom(), + localValueAccount.getFirstSub(), + blockValue.getFirstDom(), + blockValue.getFirstSub())) { // chronologically checks that localValue.First is before blockValue.First // localValue comes chronologically before, and should be the first value of the map. blockValue.setFirst(localValueAccount.getFirst()); @@ -1228,10 +1228,10 @@ public void updateBlockMapAccount() { // update the last part of the blockValue if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( - blockValue.getLastDom(), - blockValue.getLastSub(), - localValueAccount.getLastDom(), - localValueAccount.getLastSub())) { + blockValue.getLastDom(), + blockValue.getLastSub(), + localValueAccount.getLastDom(), + localValueAccount.getLastSub())) { // chronologically checks that blockValue.Last is before localValue.Last // localValue comes chronologically after, and should be the final value of the map. blockValue.setLast(localValueAccount.getLast()); @@ -1241,7 +1241,6 @@ public void updateBlockMapAccount() { blockMapAccount.put(pairAddrBlock, blockValue); } } - } } } @@ -1251,7 +1250,7 @@ public void updateBlockMapStorage() { Map< StateManagerMetadata.AddrStorageKeyBlockNumTuple, TransactionProcessingMetadata.FragmentFirstAndLast> - blockMapStorage = Hub.stateManagerMetadata().getStorageFirstLastBlockMap(); + blockMapStorage = Hub.stateManagerMetadata().getStorageFirstLastBlockMap(); List txn = txStack.getTransactions(); @@ -1261,30 +1260,30 @@ public void updateBlockMapStorage() { Map< TransactionProcessingMetadata.AddrStorageKeyPair, TransactionProcessingMetadata.FragmentFirstAndLast> - localMapStorage = metadata.getStorageFirstAndLastMap(); + localMapStorage = metadata.getStorageFirstAndLastMap(); // Update the block map for storage for (TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair : - localMapStorage.keySet()) { + localMapStorage.keySet()) { StateManagerMetadata.AddrStorageKeyBlockNumTuple addrStorageBlockTuple = - new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, blockNumber); + new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, blockNumber); // localValue exists for sure because addr belongs to the keySet of the local map TransactionProcessingMetadata.FragmentFirstAndLast localValueStorage = - localMapStorage.get(addrStorageKeyPair); + localMapStorage.get(addrStorageKeyPair); if (!blockMapStorage.containsKey(addrStorageBlockTuple)) { // the pair is not present in the map blockMapStorage.put(addrStorageBlockTuple, localValueStorage); } else { TransactionProcessingMetadata.FragmentFirstAndLast blockValueStorage = - blockMapStorage.get(addrStorageBlockTuple); + blockMapStorage.get(addrStorageBlockTuple); // update the first part of the blockValue if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( - localValueStorage.getFirstDom(), - localValueStorage.getFirstSub(), - blockValueStorage.getFirstDom(), - blockValueStorage.getFirstSub())) { + localValueStorage.getFirstDom(), + localValueStorage.getFirstSub(), + blockValueStorage.getFirstDom(), + blockValueStorage.getFirstSub())) { // chronologically checks that localValue.First is before blockValue.First // localValue comes chronologically before, and should be the first value of the map. blockValueStorage.setFirst(localValueStorage.getFirst()); @@ -1293,10 +1292,10 @@ public void updateBlockMapStorage() { // update the last part of the blockValue if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( - blockValueStorage.getLastDom(), - blockValueStorage.getLastSub(), - localValueStorage.getLastDom(), - localValueStorage.getLastSub())) { + blockValueStorage.getLastDom(), + blockValueStorage.getLastSub(), + localValueStorage.getLastDom(), + localValueStorage.getLastSub())) { // chronologically checks that blockValue.Last is before localValue.Last // localValue comes chronologically after, and should be the final value of the map. blockValueStorage.setLast(localValueStorage.getLast()); @@ -1504,22 +1503,22 @@ public void printStorageMaps() { Map< TransactionProcessingMetadata.AddrStorageKeyPair, TransactionProcessingMetadata.FragmentFirstAndLast> - txnMapStorage = metadata.getStorageFirstAndLastMap(); + txnMapStorage = metadata.getStorageFirstAndLastMap(); for (TransactionProcessingMetadata.AddrStorageKeyPair addrKeyPair : txnMapStorage.keySet()) { var txnValue = txnMapStorage.get(addrKeyPair); System.out.println( - "Storage: txn level map: addr: " - + addrKeyPair.getAddress() - + ": storage key: " - + addrKeyPair.getStorageKey() - + ": first dom: " - + txnValue.getFirstDom() - + ", first sub: " - + txnValue.getFirstSub() - + ": last dom: " - + txnValue.getLastDom() - + ", last sub: " - + txnValue.getLastSub()); + "Storage: txn level map: addr: " + + addrKeyPair.getAddress() + + ": storage key: " + + addrKeyPair.getStorageKey() + + ": first dom: " + + txnValue.getFirstDom() + + ", first sub: " + + txnValue.getFirstSub() + + ": last dom: " + + txnValue.getLastDom() + + ", last sub: " + + txnValue.getLastSub()); } } @@ -1528,20 +1527,20 @@ public void printStorageMaps() { for (var addrKeyBlockTuple : blockMapStorage.keySet()) { var blockValue = blockMapStorage.get(addrKeyBlockTuple); System.out.println( - "Storage: block level map: addr: " - + addrKeyBlockTuple.getAddrStorageKeyPair().getAddress() - + ": key: " - + addrKeyBlockTuple.getAddrStorageKeyPair().getStorageKey() - + ": block: " - + addrKeyBlockTuple.getBlockNumber() - + ": first dom: " - + blockValue.getFirstDom() - + ", first sub: " - + blockValue.getFirstSub() - + ": last dom: " - + blockValue.getLastDom() - + ", last sub: " - + blockValue.getLastSub()); + "Storage: block level map: addr: " + + addrKeyBlockTuple.getAddrStorageKeyPair().getAddress() + + ": key: " + + addrKeyBlockTuple.getAddrStorageKeyPair().getStorageKey() + + ": block: " + + addrKeyBlockTuple.getBlockNumber() + + ": first dom: " + + blockValue.getFirstDom() + + ", first sub: " + + blockValue.getFirstSub() + + ": last dom: " + + blockValue.getLastDom() + + ", last sub: " + + blockValue.getLastSub()); } // Print conflationMaps @@ -1549,20 +1548,21 @@ public void printStorageMaps() { for (var addrKeyPair : conflationMapStorage.keySet()) { var conflationValue = conflationMapStorage.get(addrKeyPair); System.out.println( - "Storage: conflation level map: addr: " - + addrKeyPair.getAddress() - + ": storage key: " - + addrKeyPair.getStorageKey() - + ": first dom: " - + conflationValue.getFirstDom() - + ", first sub: " - + conflationValue.getFirstSub() - + ": last dom: " - + conflationValue.getLastDom() - + ", last sub: " - + conflationValue.getLastSub()); + "Storage: conflation level map: addr: " + + addrKeyPair.getAddress() + + ": storage key: " + + addrKeyPair.getStorageKey() + + ": first dom: " + + conflationValue.getFirstDom() + + ", first sub: " + + conflationValue.getFirstSub() + + ": last dom: " + + conflationValue.getLastDom() + + ", last sub: " + + conflationValue.getLastSub()); } } + public final boolean returnFromMessageCall(MessageFrame frame) { return opCode() == RETURN && frame.getType() == MESSAGE_CALL; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java index 97db5e2f84..f9714477bd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java @@ -44,6 +44,12 @@ public class Trace { addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize; private final MappedByteBuffer addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo; + private final MappedByteBuffer + againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd; + private final MappedByteBuffer + againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment; + private final MappedByteBuffer + againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2; private final MappedByteBuffer alpha; private final MappedByteBuffer balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance; @@ -75,15 +81,9 @@ public class Trace { private final MappedByteBuffer contextWillRevert; private final MappedByteBuffer counterNsr; private final MappedByteBuffer counterTli; - private final MappedByteBuffer createExceptionXorHashInfoFlag; - private final MappedByteBuffer createFailureConditionWillRevertXorIcpx; - private final MappedByteBuffer createFailureConditionWontRevertXorInvalidFlag; - private final MappedByteBuffer createNonemptyInitCodeFailureWillRevertXorJumpx; - private final MappedByteBuffer - createNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequired; - private final MappedByteBuffer createNonemptyInitCodeSuccessWillRevertXorJumpFlag; - private final MappedByteBuffer createNonemptyInitCodeSuccessWontRevertXorKecFlag; private final MappedByteBuffer delta; + private final MappedByteBuffer deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock; + private final MappedByteBuffer deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock; private final MappedByteBuffer deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao; private final MappedByteBuffer @@ -91,38 +91,49 @@ public class Trace { private final MappedByteBuffer deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi; private final MappedByteBuffer - deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment; + deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode; private final MappedByteBuffer - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2; + deploymentStatusNewXorMxpFlagXorCallPrcFailureXorConFlagXorFinalInTxn; private final MappedByteBuffer - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd; + deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution; private final MappedByteBuffer domStamp; private final MappedByteBuffer exceptionAhoy; private final MappedByteBuffer - existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode; + existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf; + private final MappedByteBuffer + existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk; + private final MappedByteBuffer + finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn; + private final MappedByteBuffer + finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorUnconstrainedFinal; + private final MappedByteBuffer + finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorUnconstrainedFirst; private final MappedByteBuffer - existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution; + firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrChanges; + private final MappedByteBuffer firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueCurrIsOrig; + private final MappedByteBuffer + firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueCurrIsZero; private final MappedByteBuffer gasActual; private final MappedByteBuffer gasCost; private final MappedByteBuffer gasExpected; private final MappedByteBuffer gasLimit; private final MappedByteBuffer gasNext; private final MappedByteBuffer gasPrice; + private final MappedByteBuffer hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueNextIsOrig; private final MappedByteBuffer - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig; - private final MappedByteBuffer hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr; + hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsCurr; private final MappedByteBuffer height; private final MappedByteBuffer heightNew; private final MappedByteBuffer hubStamp; private final MappedByteBuffer hubStampTransactionEnd; private final MappedByteBuffer instruction; private final MappedByteBuffer - isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero; + isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorValueNextIsZero; private final MappedByteBuffer logInfoStamp; private final MappedByteBuffer - markedForSelfdestructNewXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth; + markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpxXorWarmth; private final MappedByteBuffer - markedForSelfdestructXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero; + markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorValueOrigIsZero; private final MappedByteBuffer mmuStamp; private final MappedByteBuffer mxpOffset2Hi; private final MappedByteBuffer mxpOffset2Lo; @@ -154,8 +165,6 @@ public class Trace { private final MappedByteBuffer peekAtStack; private final MappedByteBuffer peekAtStorage; private final MappedByteBuffer peekAtTransaction; - private final MappedByteBuffer prcBlake2FXorLogFlag; - private final MappedByteBuffer prcEcaddXorLogInfoFlag; private final MappedByteBuffer prcEcmulXorMachineStateFlag; private final MappedByteBuffer prcEcpairingXorMaxcsx; private final MappedByteBuffer prcEcrecoverXorModFlag; @@ -191,13 +200,13 @@ public class Trace { private final MappedByteBuffer rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi; private final MappedByteBuffer - rlpaddrFlagXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew; + rlpaddrFlagXorCreateNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequiredXorWarmthNew; private final MappedByteBuffer rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo; private final MappedByteBuffer rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2; private final MappedByteBuffer rlpaddrRecipe; private final MappedByteBuffer rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3; private final MappedByteBuffer rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4; - private final MappedByteBuffer romlexFlagXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4; + private final MappedByteBuffer romlexFlagXorCreateNonemptyInitCodeSuccessWillRevertXorJumpFlag; private final MappedByteBuffer selfdestructExceptionXorStaticx; private final MappedByteBuffer selfdestructWillRevertXorStaticFlag; private final MappedByteBuffer selfdestructWontRevertAlreadyMarkedXorStoFlag; @@ -216,7 +225,7 @@ public class Trace { private final MappedByteBuffer stpValueLo; private final MappedByteBuffer subStamp; private final MappedByteBuffer swapFlag; - private final MappedByteBuffer trmFlagXorStpFlagXorCreateAbortXorDupFlag; + private final MappedByteBuffer trmFlagXorCreateNonemptyInitCodeSuccessWontRevertXorKecFlag; private final MappedByteBuffer trmRawAddressHiXorMxpOffset1Lo; private final MappedByteBuffer twoLineInstruction; private final MappedByteBuffer txExec; @@ -225,8 +234,8 @@ public class Trace { private final MappedByteBuffer txSkip; private final MappedByteBuffer txWarm; private final MappedByteBuffer txnFlag; - private final MappedByteBuffer warmthNewXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlag; - private final MappedByteBuffer warmthXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlag; + private final MappedByteBuffer warmthNewXorPrcEcaddXorLogInfoFlag; + private final MappedByteBuffer warmthXorPrcBlake2FXorLogFlag; private final MappedByteBuffer wcpFlag; static List headers(int length) { @@ -242,6 +251,21 @@ static List headers(int length) { "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO", 16, length)); + headers.add( + new ColumnHeader( + "hub.AGAIN_IN_BLK_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_WILL_REVERT_xor_ACC_FLAG_xor_AGAIN_IN_BLK_xor_COPY_TXCD", + 1, + length)); + headers.add( + new ColumnHeader( + "hub.AGAIN_IN_CNF_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_ABORT_WONT_REVERT_xor_ADD_FLAG_xor_AGAIN_IN_CNF_xor_IS_DEPLOYMENT", + 1, + length)); + headers.add( + new ColumnHeader( + "hub.AGAIN_IN_TXN_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_BIN_FLAG_xor_AGAIN_IN_TXN_xor_IS_TYPE2", + 1, + length)); headers.add(new ColumnHeader("hub.ALPHA", 1, length)); headers.add( new ColumnHeader( @@ -303,24 +327,17 @@ static List headers(int length) { headers.add(new ColumnHeader("hub.CONTEXT_WILL_REVERT", 1, length)); headers.add(new ColumnHeader("hub.COUNTER_NSR", 1, length)); headers.add(new ColumnHeader("hub.COUNTER_TLI", 1, length)); - headers.add(new ColumnHeader("hub.CREATE_EXCEPTION_xor_HASH_INFO_FLAG", 1, length)); - headers.add(new ColumnHeader("hub.CREATE_FAILURE_CONDITION_WILL_REVERT_xor_ICPX", 1, length)); - headers.add( - new ColumnHeader("hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_INVALID_FLAG", 1, length)); - headers.add( - new ColumnHeader("hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_JUMPX", 1, length)); + headers.add(new ColumnHeader("hub.DELTA", 1, length)); headers.add( new ColumnHeader( - "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED", - 1, + "hub.DEPLOYMENT_NUMBER_FINAL_IN_BLOCK_xor_DEPLOYMENT_NUMBER_FINAL_IN_BLOCK", + 2, length)); headers.add( new ColumnHeader( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_FLAG", 1, length)); - headers.add( - new ColumnHeader( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_KEC_FLAG", 1, length)); - headers.add(new ColumnHeader("hub.DELTA", 1, length)); + "hub.DEPLOYMENT_NUMBER_FIRST_IN_BLOCK_xor_DEPLOYMENT_NUMBER_FIRST_IN_BLOCK", + 2, + length)); headers.add( new ColumnHeader( "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO", @@ -338,29 +355,59 @@ static List headers(int length) { length)); headers.add( new ColumnHeader( - "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_ABORT_WONT_REVERT_xor_ADD_FLAG_xor_UNCONSTRAINED_FIRST_xor_IS_DEPLOYMENT", + "hub.DEPLOYMENT_STATUS_INFTY_xor_MXP_DEPLOYS_xor_CALL_EXCEPTION_xor_CALL_FLAG_xor_FINAL_IN_CNF_xor_STATUS_CODE", 1, length)); headers.add( new ColumnHeader( - "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_CHANGES_xor_IS_TYPE2", + "hub.DEPLOYMENT_STATUS_NEW_xor_MXP_FLAG_xor_CALL_PRC_FAILURE_xor_CON_FLAG_xor_FINAL_IN_TXN", 1, length)); headers.add( new ColumnHeader( - "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_WILL_REVERT_xor_ACC_FLAG_xor_UNCONSTRAINED_FINAL_xor_COPY_TXCD", + "hub.DEPLOYMENT_STATUS_xor_MMU_SUCCESS_BIT_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BTC_FLAG_xor_FINAL_IN_BLK_xor_REQUIRES_EVM_EXECUTION", 1, length)); headers.add(new ColumnHeader("hub.DOM_STAMP", 4, length)); headers.add(new ColumnHeader("hub.EXCEPTION_AHOY", 1, length)); headers.add( new ColumnHeader( - "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_EXCEPTION_xor_CALL_FLAG_xor_VALUE_CURR_IS_ZERO_xor_STATUS_CODE", + "hub.EXISTS_NEW_xor_MXP_MXPX_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_CREATE_FLAG_xor_FIRST_IN_CNF", + 1, + length)); + headers.add( + new ColumnHeader( + "hub.EXISTS_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_COPY_FLAG_xor_FIRST_IN_BLK", + 1, + length)); + headers.add( + new ColumnHeader( + "hub.FINAL_IN_BLK_xor_MXP_SIZE_1_NONZERO_NO_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_DEC_FLAG_1_xor_FIRST_IN_TXN", + 1, + length)); + headers.add( + new ColumnHeader( + "hub.FINAL_IN_CNF_xor_MXP_SIZE_2_NONZERO_NO_MXPX_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_2_xor_UNCONSTRAINED_FINAL", + 1, + length)); + headers.add( + new ColumnHeader( + "hub.FINAL_IN_TXN_xor_OOB_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_3_xor_UNCONSTRAINED_FIRST", + 1, + length)); + headers.add( + new ColumnHeader( + "hub.FIRST_IN_BLK_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_4_xor_VALUE_CURR_CHANGES", + 1, + length)); + headers.add( + new ColumnHeader( + "hub.FIRST_IN_CNF_xor_STP_FLAG_xor_CREATE_ABORT_xor_DUP_FLAG_xor_VALUE_CURR_IS_ORIG", 1, length)); headers.add( new ColumnHeader( - "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BTC_FLAG_xor_VALUE_CURR_IS_ORIG_xor_REQUIRES_EVM_EXECUTION", + "hub.FIRST_IN_TXN_xor_STP_OOGX_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_EXT_FLAG_xor_VALUE_CURR_IS_ZERO", 1, length)); headers.add(new ColumnHeader("hub.GAS_ACTUAL", 8, length)); @@ -371,12 +418,12 @@ static List headers(int length) { headers.add(new ColumnHeader("hub.GAS_PRICE", 8, length)); headers.add( new ColumnHeader( - "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_COPY_FLAG_xor_VALUE_NEXT_IS_ORIG", + "hub.HAS_CODE_NEW_xor_CREATE_EXCEPTION_xor_HASH_INFO_FLAG_xor_VALUE_NEXT_IS_ORIG", 1, length)); headers.add( new ColumnHeader( - "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_FAILURE_xor_CON_FLAG_xor_VALUE_NEXT_IS_CURR", + "hub.HAS_CODE_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_HALT_FLAG_xor_VALUE_NEXT_IS_CURR", 1, length)); headers.add(new ColumnHeader("hub.HEIGHT", 2, length)); @@ -386,18 +433,18 @@ static List headers(int length) { headers.add(new ColumnHeader("hub.INSTRUCTION", 32, length)); headers.add( new ColumnHeader( - "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_CREATE_FLAG_xor_VALUE_NEXT_IS_ZERO", + "hub.IS_PRECOMPILE_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_ICPX_xor_VALUE_NEXT_IS_ZERO", 1, length)); headers.add(new ColumnHeader("hub.LOG_INFO_STAMP", 4, length)); headers.add( new ColumnHeader( - "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_MXP_SIZE_2_NONZERO_NO_MXPX_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_2_xor_WARMTH", + "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_JUMPX_xor_WARMTH", 1, length)); headers.add( new ColumnHeader( - "hub.MARKED_FOR_SELFDESTRUCT_xor_MXP_SIZE_1_NONZERO_NO_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_DEC_FLAG_1_xor_VALUE_ORIG_IS_ZERO", + "hub.MARKED_FOR_SELFDESTRUCT_xor_CREATE_FAILURE_CONDITION_WONT_REVERT_xor_INVALID_FLAG_xor_VALUE_ORIG_IS_ZERO", 1, length)); headers.add(new ColumnHeader("hub.MMU_STAMP", 4, length)); @@ -433,8 +480,6 @@ static List headers(int length) { headers.add(new ColumnHeader("hub.PEEK_AT_STACK", 1, length)); headers.add(new ColumnHeader("hub.PEEK_AT_STORAGE", 1, length)); headers.add(new ColumnHeader("hub.PEEK_AT_TRANSACTION", 1, length)); - headers.add(new ColumnHeader("hub.PRC_BLAKE2f_xor_LOG_FLAG", 1, length)); - headers.add(new ColumnHeader("hub.PRC_ECADD_xor_LOG_INFO_FLAG", 1, length)); headers.add(new ColumnHeader("hub.PRC_ECMUL_xor_MACHINE_STATE_FLAG", 1, length)); headers.add(new ColumnHeader("hub.PRC_ECPAIRING_xor_MAXCSX", 1, length)); headers.add(new ColumnHeader("hub.PRC_ECRECOVER_xor_MOD_FLAG", 1, length)); @@ -492,7 +537,7 @@ static List headers(int length) { length)); headers.add( new ColumnHeader( - "hub.RLPADDR_FLAG_xor_OOB_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_3_xor_WARMTH_NEW", + "hub.RLPADDR_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED_xor_WARMTH_NEW", 1, length)); headers.add( @@ -512,7 +557,7 @@ static List headers(int length) { "hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI_xor_STACK_ITEM_VALUE_LO_4", 16, length)); headers.add( new ColumnHeader( - "hub.ROMLEX_FLAG_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_4", + "hub.ROMLEX_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_FLAG", 1, length)); headers.add(new ColumnHeader("hub.SELFDESTRUCT_EXCEPTION_xor_STATICX", 1, length)); @@ -535,7 +580,10 @@ static List headers(int length) { headers.add(new ColumnHeader("hub.SUB_STAMP", 4, length)); headers.add(new ColumnHeader("hub.SWAP_FLAG", 1, length)); headers.add( - new ColumnHeader("hub.TRM_FLAG_xor_STP_FLAG_xor_CREATE_ABORT_xor_DUP_FLAG", 1, length)); + new ColumnHeader( + "hub.TRM_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_KEC_FLAG", + 1, + length)); headers.add(new ColumnHeader("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO", 16, length)); headers.add(new ColumnHeader("hub.TWO_LINE_INSTRUCTION", 1, length)); headers.add(new ColumnHeader("hub.TX_EXEC", 1, length)); @@ -544,16 +592,8 @@ static List headers(int length) { headers.add(new ColumnHeader("hub.TX_SKIP", 1, length)); headers.add(new ColumnHeader("hub.TX_WARM", 1, length)); headers.add(new ColumnHeader("hub.TXN_FLAG", 1, length)); - headers.add( - new ColumnHeader( - "hub.WARMTH_NEW_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_HALT_FLAG", - 1, - length)); - headers.add( - new ColumnHeader( - "hub.WARMTH_xor_STP_OOGX_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_EXT_FLAG", - 1, - length)); + headers.add(new ColumnHeader("hub.WARMTH_NEW_xor_PRC_ECADD_xor_LOG_INFO_FLAG", 1, length)); + headers.add(new ColumnHeader("hub.WARMTH_xor_PRC_BLAKE2f_xor_LOG_FLAG", 1, length)); headers.add(new ColumnHeader("hub.WCP_FLAG", 1, length)); return headers; } @@ -566,193 +606,201 @@ public Trace(List buffers) { this .addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo = buffers.get(2); - this.alpha = buffers.get(3); - this.balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance = + this.againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd = + buffers.get(3); + this + .againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment = buffers.get(4); - this.balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo = + this + .againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2 = buffers.get(5); - this.callDataOffsetXorMmuSize = buffers.get(6); - this.callDataSizeXorMmuSrcId = buffers.get(7); - this.callStackDepthXorStackItemHeight1 = buffers.get(8); - this.callerContextNumber = buffers.get(9); - this.codeFragmentIndex = buffers.get(10); + this.alpha = buffers.get(6); + this.balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance = + buffers.get(7); + this.balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo = + buffers.get(8); + this.callDataOffsetXorMmuSize = buffers.get(9); + this.callDataSizeXorMmuSrcId = buffers.get(10); + this.callStackDepthXorStackItemHeight1 = buffers.get(11); + this.callerContextNumber = buffers.get(12); + this.codeFragmentIndex = buffers.get(13); this .codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi = - buffers.get(11); - this.codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue = buffers.get(12); + buffers.get(14); + this.codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue = buffers.get(15); this.codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo = - buffers.get(13); - this.codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo = buffers.get(14); - this.codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi = buffers.get(15); - this.codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize = buffers.get(16); + this.codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo = buffers.get(17); + this.codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi = buffers.get(18); + this.codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize = + buffers.get(19); this.codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi = - buffers.get(17); - this.contextGetsReverted = buffers.get(18); - this.contextMayChange = buffers.get(19); - this.contextNumber = buffers.get(20); - this.contextNumberNew = buffers.get(21); - this.contextNumberXorMmuTgtId = buffers.get(22); - this.contextRevertStamp = buffers.get(23); - this.contextSelfReverts = buffers.get(24); - this.contextWillRevert = buffers.get(25); - this.counterNsr = buffers.get(26); - this.counterTli = buffers.get(27); - this.createExceptionXorHashInfoFlag = buffers.get(28); - this.createFailureConditionWillRevertXorIcpx = buffers.get(29); - this.createFailureConditionWontRevertXorInvalidFlag = buffers.get(30); - this.createNonemptyInitCodeFailureWillRevertXorJumpx = buffers.get(31); - this.createNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequired = buffers.get(32); - this.createNonemptyInitCodeSuccessWillRevertXorJumpFlag = buffers.get(33); - this.createNonemptyInitCodeSuccessWontRevertXorKecFlag = buffers.get(34); - this.delta = buffers.get(35); - this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao = buffers.get(36); - this.deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas = buffers.get(37); + buffers.get(20); + this.contextGetsReverted = buffers.get(21); + this.contextMayChange = buffers.get(22); + this.contextNumber = buffers.get(23); + this.contextNumberNew = buffers.get(24); + this.contextNumberXorMmuTgtId = buffers.get(25); + this.contextRevertStamp = buffers.get(26); + this.contextSelfReverts = buffers.get(27); + this.contextWillRevert = buffers.get(28); + this.counterNsr = buffers.get(29); + this.counterTli = buffers.get(30); + this.delta = buffers.get(31); + this.deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock = buffers.get(32); + this.deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock = buffers.get(33); + this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao = buffers.get(34); + this.deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas = buffers.get(35); this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi = - buffers.get(38); + buffers.get(36); + this.deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode = + buffers.get(37); + this.deploymentStatusNewXorMxpFlagXorCallPrcFailureXorConFlagXorFinalInTxn = buffers.get(38); this - .deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment = + .deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution = buffers.get(39); + this.domStamp = buffers.get(40); + this.exceptionAhoy = buffers.get(41); + this.existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf = + buffers.get(42); + this.existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk = + buffers.get(43); this - .deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 = - buffers.get(40); - this - .deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd = - buffers.get(41); - this.domStamp = buffers.get(42); - this.exceptionAhoy = buffers.get(43); - this.existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode = + .finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn = buffers.get(44); this - .existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution = + .finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorUnconstrainedFinal = buffers.get(45); - this.gasActual = buffers.get(46); - this.gasCost = buffers.get(47); - this.gasExpected = buffers.get(48); - this.gasLimit = buffers.get(49); - this.gasNext = buffers.get(50); - this.gasPrice = buffers.get(51); - this.hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig = - buffers.get(52); - this.hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr = buffers.get(53); - this.height = buffers.get(54); - this.heightNew = buffers.get(55); - this.hubStamp = buffers.get(56); - this.hubStampTransactionEnd = buffers.get(57); - this.instruction = buffers.get(58); - this.isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero = - buffers.get(59); - this.logInfoStamp = buffers.get(60); - this - .markedForSelfdestructNewXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth = - buffers.get(61); + this.finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorUnconstrainedFirst = + buffers.get(46); + this.firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrChanges = + buffers.get(47); + this.firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueCurrIsOrig = buffers.get(48); + this.firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueCurrIsZero = + buffers.get(49); + this.gasActual = buffers.get(50); + this.gasCost = buffers.get(51); + this.gasExpected = buffers.get(52); + this.gasLimit = buffers.get(53); + this.gasNext = buffers.get(54); + this.gasPrice = buffers.get(55); + this.hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueNextIsOrig = buffers.get(56); + this.hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsCurr = + buffers.get(57); + this.height = buffers.get(58); + this.heightNew = buffers.get(59); + this.hubStamp = buffers.get(60); + this.hubStampTransactionEnd = buffers.get(61); + this.instruction = buffers.get(62); + this.isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorValueNextIsZero = buffers.get(63); + this.logInfoStamp = buffers.get(64); + this.markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpxXorWarmth = + buffers.get(65); + this.markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorValueOrigIsZero = + buffers.get(66); + this.mmuStamp = buffers.get(67); + this.mxpOffset2Hi = buffers.get(68); + this.mxpOffset2Lo = buffers.get(69); + this.mxpSize1Hi = buffers.get(70); + this.mxpSize1Lo = buffers.get(71); + this.mxpSize2Hi = buffers.get(72); + this.mxpSize2Lo = buffers.get(73); + this.mxpStamp = buffers.get(74); + this.mxpWords = buffers.get(75); + this.nbAdded = buffers.get(76); + this.nbRemoved = buffers.get(77); + this.nonStackRows = buffers.get(78); + this.nonce = buffers.get(79); + this.nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable = buffers.get(80); + this.nonceXorStpGasMxpXorBasefee = buffers.get(81); + this.oobData1 = buffers.get(82); + this.oobData2 = buffers.get(83); + this.oobData3 = buffers.get(84); + this.oobData4 = buffers.get(85); + this.oobData5 = buffers.get(86); + this.oobData6 = buffers.get(87); + this.oobData7 = buffers.get(88); + this.oobData8 = buffers.get(89); + this.oobData9 = buffers.get(90); + this.peekAtAccount = buffers.get(91); + this.peekAtContext = buffers.get(92); + this.peekAtMiscellaneous = buffers.get(93); + this.peekAtScenario = buffers.get(94); + this.peekAtStack = buffers.get(95); + this.peekAtStorage = buffers.get(96); + this.peekAtTransaction = buffers.get(97); + this.prcEcmulXorMachineStateFlag = buffers.get(98); + this.prcEcpairingXorMaxcsx = buffers.get(99); + this.prcEcrecoverXorModFlag = buffers.get(100); + this.prcFailureKnownToHubXorMulFlag = buffers.get(101); + this.prcFailureKnownToRamXorMxpx = buffers.get(102); + this.prcIdentityXorMxpFlag = buffers.get(103); + this.prcModexpXorOogx = buffers.get(104); + this.prcRipemd160XorOpcx = buffers.get(105); + this.prcSha2256XorPushpopFlag = buffers.get(106); + this.prcSuccessCallerWillRevertXorRdcx = buffers.get(107); + this.prcSuccessCallerWontRevertXorShfFlag = buffers.get(108); + this.priorityFeePerGas = buffers.get(109); + this.programCounter = buffers.get(110); + this.programCounterNew = buffers.get(111); + this.refundCounter = buffers.get(112); + this.refundCounterInfinity = buffers.get(113); + this.refundCounterNew = buffers.get(114); + this.refundEffective = buffers.get(115); + this.relativeBlockNumber = buffers.get(116); + this.returnAtCapacityXorMxpInst = buffers.get(117); + this.returnAtOffsetXorOobInst = buffers.get(118); + this.returnDataContextNumberXorStpGasStipend = buffers.get(119); + this.returnDataOffsetXorStpInstruction = buffers.get(120); + this.returnDataSize = buffers.get(121); + this.returnExceptionXorSox = buffers.get(122); + this.returnFromDeploymentEmptyCodeWillRevertXorSstorex = buffers.get(123); + this.returnFromDeploymentEmptyCodeWontRevertXorStackramFlag = buffers.get(124); + this.returnFromDeploymentNonemptyCodeWillRevertXorStackItemPop1 = buffers.get(125); + this.returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop2 = buffers.get(126); + this.returnFromMessageCallWillTouchRamXorStackItemPop3 = buffers.get(127); + this.returnFromMessageCallWontTouchRamXorStackItemPop4 = buffers.get(128); + this.rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize = buffers.get(129); + this.rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi = buffers.get(130); this - .markedForSelfdestructXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero = - buffers.get(62); - this.mmuStamp = buffers.get(63); - this.mxpOffset2Hi = buffers.get(64); - this.mxpOffset2Lo = buffers.get(65); - this.mxpSize1Hi = buffers.get(66); - this.mxpSize1Lo = buffers.get(67); - this.mxpSize2Hi = buffers.get(68); - this.mxpSize2Lo = buffers.get(69); - this.mxpStamp = buffers.get(70); - this.mxpWords = buffers.get(71); - this.nbAdded = buffers.get(72); - this.nbRemoved = buffers.get(73); - this.nonStackRows = buffers.get(74); - this.nonce = buffers.get(75); - this.nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable = buffers.get(76); - this.nonceXorStpGasMxpXorBasefee = buffers.get(77); - this.oobData1 = buffers.get(78); - this.oobData2 = buffers.get(79); - this.oobData3 = buffers.get(80); - this.oobData4 = buffers.get(81); - this.oobData5 = buffers.get(82); - this.oobData6 = buffers.get(83); - this.oobData7 = buffers.get(84); - this.oobData8 = buffers.get(85); - this.oobData9 = buffers.get(86); - this.peekAtAccount = buffers.get(87); - this.peekAtContext = buffers.get(88); - this.peekAtMiscellaneous = buffers.get(89); - this.peekAtScenario = buffers.get(90); - this.peekAtStack = buffers.get(91); - this.peekAtStorage = buffers.get(92); - this.peekAtTransaction = buffers.get(93); - this.prcBlake2FXorLogFlag = buffers.get(94); - this.prcEcaddXorLogInfoFlag = buffers.get(95); - this.prcEcmulXorMachineStateFlag = buffers.get(96); - this.prcEcpairingXorMaxcsx = buffers.get(97); - this.prcEcrecoverXorModFlag = buffers.get(98); - this.prcFailureKnownToHubXorMulFlag = buffers.get(99); - this.prcFailureKnownToRamXorMxpx = buffers.get(100); - this.prcIdentityXorMxpFlag = buffers.get(101); - this.prcModexpXorOogx = buffers.get(102); - this.prcRipemd160XorOpcx = buffers.get(103); - this.prcSha2256XorPushpopFlag = buffers.get(104); - this.prcSuccessCallerWillRevertXorRdcx = buffers.get(105); - this.prcSuccessCallerWontRevertXorShfFlag = buffers.get(106); - this.priorityFeePerGas = buffers.get(107); - this.programCounter = buffers.get(108); - this.programCounterNew = buffers.get(109); - this.refundCounter = buffers.get(110); - this.refundCounterInfinity = buffers.get(111); - this.refundCounterNew = buffers.get(112); - this.refundEffective = buffers.get(113); - this.relativeBlockNumber = buffers.get(114); - this.returnAtCapacityXorMxpInst = buffers.get(115); - this.returnAtOffsetXorOobInst = buffers.get(116); - this.returnDataContextNumberXorStpGasStipend = buffers.get(117); - this.returnDataOffsetXorStpInstruction = buffers.get(118); - this.returnDataSize = buffers.get(119); - this.returnExceptionXorSox = buffers.get(120); - this.returnFromDeploymentEmptyCodeWillRevertXorSstorex = buffers.get(121); - this.returnFromDeploymentEmptyCodeWontRevertXorStackramFlag = buffers.get(122); - this.returnFromDeploymentNonemptyCodeWillRevertXorStackItemPop1 = buffers.get(123); - this.returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop2 = buffers.get(124); - this.returnFromMessageCallWillTouchRamXorStackItemPop3 = buffers.get(125); - this.returnFromMessageCallWontTouchRamXorStackItemPop4 = buffers.get(126); - this.rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize = buffers.get(127); - this.rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi = buffers.get(128); - this.rlpaddrFlagXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew = - buffers.get(129); - this.rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo = buffers.get(130); - this.rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2 = buffers.get(131); - this.rlpaddrRecipe = buffers.get(132); - this.rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3 = buffers.get(133); - this.rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4 = buffers.get(134); - this.romlexFlagXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4 = buffers.get(135); - this.selfdestructExceptionXorStaticx = buffers.get(136); - this.selfdestructWillRevertXorStaticFlag = buffers.get(137); - this.selfdestructWontRevertAlreadyMarkedXorStoFlag = buffers.get(138); - this.selfdestructWontRevertNotYetMarkedXorSux = buffers.get(139); - this.stackItemHeight2 = buffers.get(140); - this.stackItemHeight3 = buffers.get(141); - this.stackItemHeight4 = buffers.get(142); - this.stackItemStamp1 = buffers.get(143); - this.stackItemStamp2 = buffers.get(144); - this.stackItemStamp3 = buffers.get(145); - this.stackItemStamp4 = buffers.get(146); - this.stpGasHi = buffers.get(147); - this.stpGasLo = buffers.get(148); - this.stpGasUpfrontGasCostXorGasLeftover = buffers.get(149); - this.stpValueHi = buffers.get(150); - this.stpValueLo = buffers.get(151); - this.subStamp = buffers.get(152); - this.swapFlag = buffers.get(153); - this.trmFlagXorStpFlagXorCreateAbortXorDupFlag = buffers.get(154); - this.trmRawAddressHiXorMxpOffset1Lo = buffers.get(155); - this.twoLineInstruction = buffers.get(156); - this.txExec = buffers.get(157); - this.txFinl = buffers.get(158); - this.txInit = buffers.get(159); - this.txSkip = buffers.get(160); - this.txWarm = buffers.get(161); - this.txnFlag = buffers.get(162); - this.warmthNewXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlag = buffers.get(163); - this.warmthXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlag = buffers.get(164); - this.wcpFlag = buffers.get(165); + .rlpaddrFlagXorCreateNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequiredXorWarmthNew = + buffers.get(131); + this.rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo = buffers.get(132); + this.rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2 = buffers.get(133); + this.rlpaddrRecipe = buffers.get(134); + this.rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3 = buffers.get(135); + this.rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4 = buffers.get(136); + this.romlexFlagXorCreateNonemptyInitCodeSuccessWillRevertXorJumpFlag = buffers.get(137); + this.selfdestructExceptionXorStaticx = buffers.get(138); + this.selfdestructWillRevertXorStaticFlag = buffers.get(139); + this.selfdestructWontRevertAlreadyMarkedXorStoFlag = buffers.get(140); + this.selfdestructWontRevertNotYetMarkedXorSux = buffers.get(141); + this.stackItemHeight2 = buffers.get(142); + this.stackItemHeight3 = buffers.get(143); + this.stackItemHeight4 = buffers.get(144); + this.stackItemStamp1 = buffers.get(145); + this.stackItemStamp2 = buffers.get(146); + this.stackItemStamp3 = buffers.get(147); + this.stackItemStamp4 = buffers.get(148); + this.stpGasHi = buffers.get(149); + this.stpGasLo = buffers.get(150); + this.stpGasUpfrontGasCostXorGasLeftover = buffers.get(151); + this.stpValueHi = buffers.get(152); + this.stpValueLo = buffers.get(153); + this.subStamp = buffers.get(154); + this.swapFlag = buffers.get(155); + this.trmFlagXorCreateNonemptyInitCodeSuccessWontRevertXorKecFlag = buffers.get(156); + this.trmRawAddressHiXorMxpOffset1Lo = buffers.get(157); + this.twoLineInstruction = buffers.get(158); + this.txExec = buffers.get(159); + this.txFinl = buffers.get(160); + this.txInit = buffers.get(161); + this.txSkip = buffers.get(162); + this.txWarm = buffers.get(163); + this.txnFlag = buffers.get(164); + this.warmthNewXorPrcEcaddXorLogInfoFlag = buffers.get(165); + this.warmthXorPrcBlake2FXorLogFlag = buffers.get(166); + this.wcpFlag = buffers.get(167); } public int size() { @@ -1214,10 +1262,10 @@ public Trace nonStackRows(final long b) { } public Trace pAccountAddressHi(final long b) { - if (filled.get(103)) { + if (filled.get(105)) { throw new IllegalStateException("hub.account/ADDRESS_HI already set"); } else { - filled.set(103); + filled.set(105); } if (b >= 4294967296L) { @@ -1239,10 +1287,10 @@ public Trace pAccountAddressHi(final long b) { } public Trace pAccountAddressLo(final Bytes b) { - if (filled.get(132)) { + if (filled.get(134)) { throw new IllegalStateException("hub.account/ADDRESS_LO already set"); } else { - filled.set(132); + filled.set(134); } // Trim array to size @@ -1268,11 +1316,50 @@ public Trace pAccountAddressLo(final Bytes b) { return this; } + public Trace pAccountAgainInBlk(final Boolean b) { + if (filled.get(45)) { + throw new IllegalStateException("hub.account/AGAIN_IN_BLK already set"); + } else { + filled.set(45); + } + + againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd.put( + (byte) (b ? 1 : 0)); + + return this; + } + + public Trace pAccountAgainInCnf(final Boolean b) { + if (filled.get(46)) { + throw new IllegalStateException("hub.account/AGAIN_IN_CNF already set"); + } else { + filled.set(46); + } + + againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment.put( + (byte) (b ? 1 : 0)); + + return this; + } + + public Trace pAccountAgainInTxn(final Boolean b) { + if (filled.get(47)) { + throw new IllegalStateException("hub.account/AGAIN_IN_TXN already set"); + } else { + filled.set(47); + } + + againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2 + .put((byte) (b ? 1 : 0)); + + return this; + } + public Trace pAccountBalance(final Bytes b) { - if (filled.get(133)) { + if (filled.get(135)) { throw new IllegalStateException("hub.account/BALANCE already set"); } else { - filled.set(133); + filled.set(135); } // Trim array to size @@ -1299,10 +1386,10 @@ public Trace pAccountBalance(final Bytes b) { } public Trace pAccountBalanceNew(final Bytes b) { - if (filled.get(134)) { + if (filled.get(136)) { throw new IllegalStateException("hub.account/BALANCE_NEW already set"); } else { - filled.set(134); + filled.set(136); } // Trim array to size @@ -1329,10 +1416,10 @@ public Trace pAccountBalanceNew(final Bytes b) { } public Trace pAccountCodeFragmentIndex(final long b) { - if (filled.get(104)) { + if (filled.get(106)) { throw new IllegalStateException("hub.account/CODE_FRAGMENT_INDEX already set"); } else { - filled.set(104); + filled.set(106); } if (b >= 4294967296L) { @@ -1354,10 +1441,10 @@ public Trace pAccountCodeFragmentIndex(final long b) { } public Trace pAccountCodeHashHi(final Bytes b) { - if (filled.get(135)) { + if (filled.get(137)) { throw new IllegalStateException("hub.account/CODE_HASH_HI already set"); } else { - filled.set(135); + filled.set(137); } // Trim array to size @@ -1382,10 +1469,10 @@ public Trace pAccountCodeHashHi(final Bytes b) { } public Trace pAccountCodeHashHiNew(final Bytes b) { - if (filled.get(136)) { + if (filled.get(138)) { throw new IllegalStateException("hub.account/CODE_HASH_HI_NEW already set"); } else { - filled.set(136); + filled.set(138); } // Trim array to size @@ -1410,10 +1497,10 @@ public Trace pAccountCodeHashHiNew(final Bytes b) { } public Trace pAccountCodeHashLo(final Bytes b) { - if (filled.get(137)) { + if (filled.get(139)) { throw new IllegalStateException("hub.account/CODE_HASH_LO already set"); } else { - filled.set(137); + filled.set(139); } // Trim array to size @@ -1438,10 +1525,10 @@ public Trace pAccountCodeHashLo(final Bytes b) { } public Trace pAccountCodeHashLoNew(final Bytes b) { - if (filled.get(138)) { + if (filled.get(140)) { throw new IllegalStateException("hub.account/CODE_HASH_LO_NEW already set"); } else { - filled.set(138); + filled.set(140); } // Trim array to size @@ -1466,10 +1553,10 @@ public Trace pAccountCodeHashLoNew(final Bytes b) { } public Trace pAccountCodeSize(final long b) { - if (filled.get(105)) { + if (filled.get(107)) { throw new IllegalStateException("hub.account/CODE_SIZE already set"); } else { - filled.set(105); + filled.set(107); } if (b >= 4294967296L) { @@ -1491,10 +1578,10 @@ public Trace pAccountCodeSize(final long b) { } public Trace pAccountCodeSizeNew(final long b) { - if (filled.get(106)) { + if (filled.get(108)) { throw new IllegalStateException("hub.account/CODE_SIZE_NEW already set"); } else { - filled.set(106); + filled.set(108); } if (b >= 4294967296L) { @@ -1515,10 +1602,10 @@ public Trace pAccountCodeSizeNew(final long b) { } public Trace pAccountDeploymentNumber(final long b) { - if (filled.get(107)) { + if (filled.get(109)) { throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER already set"); } else { - filled.set(107); + filled.set(109); } if (b >= 4294967296L) { @@ -1538,11 +1625,49 @@ public Trace pAccountDeploymentNumber(final long b) { return this; } + public Trace pAccountDeploymentNumberFinalInBlock(final long b) { + if (filled.get(103)) { + throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER_FINAL_IN_BLOCK already set"); + } else { + filled.set(103); + } + + if (b >= 65536L) { + throw new IllegalArgumentException( + "deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock has invalid value (" + + b + + ")"); + } + deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock.put((byte) (b >> 8)); + deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock.put((byte) b); + + return this; + } + + public Trace pAccountDeploymentNumberFirstInBlock(final long b) { + if (filled.get(104)) { + throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER_FIRST_IN_BLOCK already set"); + } else { + filled.set(104); + } + + if (b >= 65536L) { + throw new IllegalArgumentException( + "deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock has invalid value (" + + b + + ")"); + } + deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock.put((byte) (b >> 8)); + deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock.put((byte) b); + + return this; + } + public Trace pAccountDeploymentNumberInfty(final long b) { - if (filled.get(108)) { + if (filled.get(110)) { throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER_INFTY already set"); } else { - filled.set(108); + filled.set(110); } if (b >= 4294967296L) { @@ -1560,10 +1685,10 @@ public Trace pAccountDeploymentNumberInfty(final long b) { } public Trace pAccountDeploymentNumberNew(final long b) { - if (filled.get(109)) { + if (filled.get(111)) { throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER_NEW already set"); } else { - filled.set(109); + filled.set(111); } if (b >= 4294967296L) { @@ -1581,142 +1706,218 @@ public Trace pAccountDeploymentNumberNew(final long b) { } public Trace pAccountDeploymentStatus(final Boolean b) { - if (filled.get(45)) { + if (filled.get(48)) { throw new IllegalStateException("hub.account/DEPLOYMENT_STATUS already set"); } else { - filled.set(45); + filled.set(48); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd + deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution .put((byte) (b ? 1 : 0)); return this; } public Trace pAccountDeploymentStatusInfty(final Boolean b) { - if (filled.get(46)) { + if (filled.get(49)) { throw new IllegalStateException("hub.account/DEPLOYMENT_STATUS_INFTY already set"); } else { - filled.set(46); + filled.set(49); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment - .put((byte) (b ? 1 : 0)); + deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode.put( + (byte) (b ? 1 : 0)); return this; } public Trace pAccountDeploymentStatusNew(final Boolean b) { - if (filled.get(47)) { + if (filled.get(50)) { throw new IllegalStateException("hub.account/DEPLOYMENT_STATUS_NEW already set"); } else { - filled.set(47); + filled.set(50); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 - .put((byte) (b ? 1 : 0)); + deploymentStatusNewXorMxpFlagXorCallPrcFailureXorConFlagXorFinalInTxn.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountExists(final Boolean b) { - if (filled.get(48)) { + if (filled.get(51)) { throw new IllegalStateException("hub.account/EXISTS already set"); } else { - filled.set(48); + filled.set(51); } - existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution - .put((byte) (b ? 1 : 0)); + existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.put( + (byte) (b ? 1 : 0)); return this; } public Trace pAccountExistsNew(final Boolean b) { - if (filled.get(49)) { + if (filled.get(52)) { throw new IllegalStateException("hub.account/EXISTS_NEW already set"); } else { - filled.set(49); + filled.set(52); } - existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.put( (byte) (b ? 1 : 0)); return this; } - public Trace pAccountHasCode(final Boolean b) { - if (filled.get(50)) { - throw new IllegalStateException("hub.account/HAS_CODE already set"); + public Trace pAccountFinalInBlk(final Boolean b) { + if (filled.get(53)) { + throw new IllegalStateException("hub.account/FINAL_IN_BLK already set"); } else { - filled.set(50); + filled.set(53); } - hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); + finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn.put( + (byte) (b ? 1 : 0)); return this; } - public Trace pAccountHasCodeNew(final Boolean b) { - if (filled.get(51)) { - throw new IllegalStateException("hub.account/HAS_CODE_NEW already set"); + public Trace pAccountFinalInCnf(final Boolean b) { + if (filled.get(54)) { + throw new IllegalStateException("hub.account/FINAL_IN_CNF already set"); } else { - filled.set(51); + filled.set(54); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig.put( - (byte) (b ? 1 : 0)); + finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorUnconstrainedFinal + .put((byte) (b ? 1 : 0)); return this; } - public Trace pAccountIsPrecompile(final Boolean b) { - if (filled.get(52)) { - throw new IllegalStateException("hub.account/IS_PRECOMPILE already set"); + public Trace pAccountFinalInTxn(final Boolean b) { + if (filled.get(55)) { + throw new IllegalStateException("hub.account/FINAL_IN_TXN already set"); } else { - filled.set(52); + filled.set(55); } - isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero.put( + finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorUnconstrainedFirst.put( (byte) (b ? 1 : 0)); return this; } - public Trace pAccountMarkedForSelfdestruct(final Boolean b) { - if (filled.get(53)) { - throw new IllegalStateException("hub.account/MARKED_FOR_SELFDESTRUCT already set"); + public Trace pAccountFirstInBlk(final Boolean b) { + if (filled.get(56)) { + throw new IllegalStateException("hub.account/FIRST_IN_BLK already set"); } else { - filled.set(53); + filled.set(56); } - markedForSelfdestructXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero - .put((byte) (b ? 1 : 0)); + firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrChanges.put( + (byte) (b ? 1 : 0)); return this; } - public Trace pAccountMarkedForSelfdestructNew(final Boolean b) { - if (filled.get(54)) { - throw new IllegalStateException("hub.account/MARKED_FOR_SELFDESTRUCT_NEW already set"); + public Trace pAccountFirstInCnf(final Boolean b) { + if (filled.get(57)) { + throw new IllegalStateException("hub.account/FIRST_IN_CNF already set"); } else { - filled.set(54); + filled.set(57); } - markedForSelfdestructNewXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth - .put((byte) (b ? 1 : 0)); + firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueCurrIsOrig.put((byte) (b ? 1 : 0)); return this; } - public Trace pAccountNonce(final Bytes b) { - if (filled.get(123)) { - throw new IllegalStateException("hub.account/NONCE already set"); + public Trace pAccountFirstInTxn(final Boolean b) { + if (filled.get(58)) { + throw new IllegalStateException("hub.account/FIRST_IN_TXN already set"); } else { - filled.set(123); + filled.set(58); } - // Trim array to size + firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueCurrIsZero.put( + (byte) (b ? 1 : 0)); + + return this; + } + + public Trace pAccountHasCode(final Boolean b) { + if (filled.get(59)) { + throw new IllegalStateException("hub.account/HAS_CODE already set"); + } else { + filled.set(59); + } + + hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsCurr.put( + (byte) (b ? 1 : 0)); + + return this; + } + + public Trace pAccountHasCodeNew(final Boolean b) { + if (filled.get(60)) { + throw new IllegalStateException("hub.account/HAS_CODE_NEW already set"); + } else { + filled.set(60); + } + + hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueNextIsOrig.put((byte) (b ? 1 : 0)); + + return this; + } + + public Trace pAccountIsPrecompile(final Boolean b) { + if (filled.get(61)) { + throw new IllegalStateException("hub.account/IS_PRECOMPILE already set"); + } else { + filled.set(61); + } + + isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); + + return this; + } + + public Trace pAccountMarkedForSelfdestruct(final Boolean b) { + if (filled.get(62)) { + throw new IllegalStateException("hub.account/MARKED_FOR_SELFDESTRUCT already set"); + } else { + filled.set(62); + } + + markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorValueOrigIsZero.put( + (byte) (b ? 1 : 0)); + + return this; + } + + public Trace pAccountMarkedForSelfdestructNew(final Boolean b) { + if (filled.get(63)) { + throw new IllegalStateException("hub.account/MARKED_FOR_SELFDESTRUCT_NEW already set"); + } else { + filled.set(63); + } + + markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpxXorWarmth.put( + (byte) (b ? 1 : 0)); + + return this; + } + + public Trace pAccountNonce(final Bytes b) { + if (filled.get(125)) { + throw new IllegalStateException("hub.account/NONCE already set"); + } else { + filled.set(125); + } + + // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width if (bs.bitLength() > 64) { @@ -1736,10 +1937,10 @@ public Trace pAccountNonce(final Bytes b) { } public Trace pAccountNonceNew(final Bytes b) { - if (filled.get(124)) { + if (filled.get(126)) { throw new IllegalStateException("hub.account/NONCE_NEW already set"); } else { - filled.set(124); + filled.set(126); } // Trim array to size @@ -1764,10 +1965,10 @@ public Trace pAccountNonceNew(final Bytes b) { } public Trace pAccountRlpaddrDepAddrHi(final long b) { - if (filled.get(110)) { + if (filled.get(112)) { throw new IllegalStateException("hub.account/RLPADDR_DEP_ADDR_HI already set"); } else { - filled.set(110); + filled.set(112); } if (b >= 4294967296L) { @@ -1783,10 +1984,10 @@ public Trace pAccountRlpaddrDepAddrHi(final long b) { } public Trace pAccountRlpaddrDepAddrLo(final Bytes b) { - if (filled.get(139)) { + if (filled.get(141)) { throw new IllegalStateException("hub.account/RLPADDR_DEP_ADDR_LO already set"); } else { - filled.set(139); + filled.set(141); } // Trim array to size @@ -1811,23 +2012,23 @@ public Trace pAccountRlpaddrDepAddrLo(final Bytes b) { } public Trace pAccountRlpaddrFlag(final Boolean b) { - if (filled.get(55)) { + if (filled.get(64)) { throw new IllegalStateException("hub.account/RLPADDR_FLAG already set"); } else { - filled.set(55); + filled.set(64); } - rlpaddrFlagXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew.put( - (byte) (b ? 1 : 0)); + rlpaddrFlagXorCreateNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequiredXorWarmthNew + .put((byte) (b ? 1 : 0)); return this; } public Trace pAccountRlpaddrKecHi(final Bytes b) { - if (filled.get(140)) { + if (filled.get(142)) { throw new IllegalStateException("hub.account/RLPADDR_KEC_HI already set"); } else { - filled.set(140); + filled.set(142); } // Trim array to size @@ -1852,10 +2053,10 @@ public Trace pAccountRlpaddrKecHi(final Bytes b) { } public Trace pAccountRlpaddrKecLo(final Bytes b) { - if (filled.get(141)) { + if (filled.get(143)) { throw new IllegalStateException("hub.account/RLPADDR_KEC_LO already set"); } else { - filled.set(141); + filled.set(143); } // Trim array to size @@ -1895,10 +2096,10 @@ public Trace pAccountRlpaddrRecipe(final long b) { } public Trace pAccountRlpaddrSaltHi(final Bytes b) { - if (filled.get(142)) { + if (filled.get(144)) { throw new IllegalStateException("hub.account/RLPADDR_SALT_HI already set"); } else { - filled.set(142); + filled.set(144); } // Trim array to size @@ -1923,10 +2124,10 @@ public Trace pAccountRlpaddrSaltHi(final Bytes b) { } public Trace pAccountRlpaddrSaltLo(final Bytes b) { - if (filled.get(143)) { + if (filled.get(145)) { throw new IllegalStateException("hub.account/RLPADDR_SALT_LO already set"); } else { - filled.set(143); + filled.set(145); } // Trim array to size @@ -1951,34 +2152,34 @@ public Trace pAccountRlpaddrSaltLo(final Bytes b) { } public Trace pAccountRomlexFlag(final Boolean b) { - if (filled.get(56)) { + if (filled.get(65)) { throw new IllegalStateException("hub.account/ROMLEX_FLAG already set"); } else { - filled.set(56); + filled.set(65); } - romlexFlagXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4.put((byte) (b ? 1 : 0)); + romlexFlagXorCreateNonemptyInitCodeSuccessWillRevertXorJumpFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountTrmFlag(final Boolean b) { - if (filled.get(57)) { + if (filled.get(66)) { throw new IllegalStateException("hub.account/TRM_FLAG already set"); } else { - filled.set(57); + filled.set(66); } - trmFlagXorStpFlagXorCreateAbortXorDupFlag.put((byte) (b ? 1 : 0)); + trmFlagXorCreateNonemptyInitCodeSuccessWontRevertXorKecFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountTrmRawAddressHi(final Bytes b) { - if (filled.get(144)) { + if (filled.get(146)) { throw new IllegalStateException("hub.account/TRM_RAW_ADDRESS_HI already set"); } else { - filled.set(144); + filled.set(146); } // Trim array to size @@ -2001,34 +2202,34 @@ public Trace pAccountTrmRawAddressHi(final Bytes b) { } public Trace pAccountWarmth(final Boolean b) { - if (filled.get(58)) { + if (filled.get(67)) { throw new IllegalStateException("hub.account/WARMTH already set"); } else { - filled.set(58); + filled.set(67); } - warmthXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlag.put((byte) (b ? 1 : 0)); + warmthXorPrcBlake2FXorLogFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountWarmthNew(final Boolean b) { - if (filled.get(59)) { + if (filled.get(68)) { throw new IllegalStateException("hub.account/WARMTH_NEW already set"); } else { - filled.set(59); + filled.set(68); } - warmthNewXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlag.put((byte) (b ? 1 : 0)); + warmthNewXorPrcEcaddXorLogInfoFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pContextAccountAddressHi(final long b) { - if (filled.get(103)) { + if (filled.get(105)) { throw new IllegalStateException("hub.context/ACCOUNT_ADDRESS_HI already set"); } else { - filled.set(103); + filled.set(105); } if (b >= 4294967296L) { @@ -2050,10 +2251,10 @@ public Trace pContextAccountAddressHi(final long b) { } public Trace pContextAccountAddressLo(final Bytes b) { - if (filled.get(132)) { + if (filled.get(134)) { throw new IllegalStateException("hub.context/ACCOUNT_ADDRESS_LO already set"); } else { - filled.set(132); + filled.set(134); } // Trim array to size @@ -2080,10 +2281,10 @@ public Trace pContextAccountAddressLo(final Bytes b) { } public Trace pContextAccountDeploymentNumber(final long b) { - if (filled.get(104)) { + if (filled.get(106)) { throw new IllegalStateException("hub.context/ACCOUNT_DEPLOYMENT_NUMBER already set"); } else { - filled.set(104); + filled.set(106); } if (b >= 4294967296L) { @@ -2105,10 +2306,10 @@ public Trace pContextAccountDeploymentNumber(final long b) { } public Trace pContextByteCodeAddressHi(final long b) { - if (filled.get(105)) { + if (filled.get(107)) { throw new IllegalStateException("hub.context/BYTE_CODE_ADDRESS_HI already set"); } else { - filled.set(105); + filled.set(107); } if (b >= 4294967296L) { @@ -2130,10 +2331,10 @@ public Trace pContextByteCodeAddressHi(final long b) { } public Trace pContextByteCodeAddressLo(final Bytes b) { - if (filled.get(133)) { + if (filled.get(135)) { throw new IllegalStateException("hub.context/BYTE_CODE_ADDRESS_LO already set"); } else { - filled.set(133); + filled.set(135); } // Trim array to size @@ -2160,10 +2361,10 @@ public Trace pContextByteCodeAddressLo(final Bytes b) { } public Trace pContextByteCodeCodeFragmentIndex(final long b) { - if (filled.get(106)) { + if (filled.get(108)) { throw new IllegalStateException("hub.context/BYTE_CODE_CODE_FRAGMENT_INDEX already set"); } else { - filled.set(106); + filled.set(108); } if (b >= 4294967296L) { @@ -2184,10 +2385,10 @@ public Trace pContextByteCodeCodeFragmentIndex(final long b) { } public Trace pContextByteCodeDeploymentNumber(final long b) { - if (filled.get(107)) { + if (filled.get(109)) { throw new IllegalStateException("hub.context/BYTE_CODE_DEPLOYMENT_NUMBER already set"); } else { - filled.set(107); + filled.set(109); } if (b >= 4294967296L) { @@ -2208,10 +2409,10 @@ public Trace pContextByteCodeDeploymentNumber(final long b) { } public Trace pContextByteCodeDeploymentStatus(final long b) { - if (filled.get(108)) { + if (filled.get(110)) { throw new IllegalStateException("hub.context/BYTE_CODE_DEPLOYMENT_STATUS already set"); } else { - filled.set(108); + filled.set(110); } if (b >= 4294967296L) { @@ -2229,10 +2430,10 @@ public Trace pContextByteCodeDeploymentStatus(final long b) { } public Trace pContextCallDataContextNumber(final long b) { - if (filled.get(110)) { + if (filled.get(112)) { throw new IllegalStateException("hub.context/CALL_DATA_CONTEXT_NUMBER already set"); } else { - filled.set(110); + filled.set(112); } if (b >= 4294967296L) { @@ -2248,10 +2449,10 @@ public Trace pContextCallDataContextNumber(final long b) { } public Trace pContextCallDataOffset(final long b) { - if (filled.get(111)) { + if (filled.get(113)) { throw new IllegalStateException("hub.context/CALL_DATA_OFFSET already set"); } else { - filled.set(111); + filled.set(113); } if (b >= 4294967296L) { @@ -2266,10 +2467,10 @@ public Trace pContextCallDataOffset(final long b) { } public Trace pContextCallDataSize(final long b) { - if (filled.get(112)) { + if (filled.get(114)) { throw new IllegalStateException("hub.context/CALL_DATA_SIZE already set"); } else { - filled.set(112); + filled.set(114); } if (b >= 4294967296L) { @@ -2301,10 +2502,10 @@ public Trace pContextCallStackDepth(final long b) { } public Trace pContextCallValue(final Bytes b) { - if (filled.get(135)) { + if (filled.get(137)) { throw new IllegalStateException("hub.context/CALL_VALUE already set"); } else { - filled.set(135); + filled.set(137); } // Trim array to size @@ -2329,10 +2530,10 @@ public Trace pContextCallValue(final Bytes b) { } public Trace pContextCallerAddressHi(final long b) { - if (filled.get(109)) { + if (filled.get(111)) { throw new IllegalStateException("hub.context/CALLER_ADDRESS_HI already set"); } else { - filled.set(109); + filled.set(111); } if (b >= 4294967296L) { @@ -2350,10 +2551,10 @@ public Trace pContextCallerAddressHi(final long b) { } public Trace pContextCallerAddressLo(final Bytes b) { - if (filled.get(134)) { + if (filled.get(136)) { throw new IllegalStateException("hub.context/CALLER_ADDRESS_LO already set"); } else { - filled.set(134); + filled.set(136); } // Trim array to size @@ -2380,10 +2581,10 @@ public Trace pContextCallerAddressLo(final Bytes b) { } public Trace pContextContextNumber(final long b) { - if (filled.get(113)) { + if (filled.get(115)) { throw new IllegalStateException("hub.context/CONTEXT_NUMBER already set"); } else { - filled.set(113); + filled.set(115); } if (b >= 4294967296L) { @@ -2404,8 +2605,8 @@ public Trace pContextIsRoot(final Boolean b) { filled.set(45); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd - .put((byte) (b ? 1 : 0)); + againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -2417,17 +2618,17 @@ public Trace pContextIsStatic(final Boolean b) { filled.set(46); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment - .put((byte) (b ? 1 : 0)); + againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment.put( + (byte) (b ? 1 : 0)); return this; } public Trace pContextReturnAtCapacity(final long b) { - if (filled.get(114)) { + if (filled.get(116)) { throw new IllegalStateException("hub.context/RETURN_AT_CAPACITY already set"); } else { - filled.set(114); + filled.set(116); } if (b >= 4294967296L) { @@ -2443,10 +2644,10 @@ public Trace pContextReturnAtCapacity(final long b) { } public Trace pContextReturnAtOffset(final long b) { - if (filled.get(115)) { + if (filled.get(117)) { throw new IllegalStateException("hub.context/RETURN_AT_OFFSET already set"); } else { - filled.set(115); + filled.set(117); } if (b >= 4294967296L) { @@ -2461,10 +2662,10 @@ public Trace pContextReturnAtOffset(final long b) { } public Trace pContextReturnDataContextNumber(final long b) { - if (filled.get(116)) { + if (filled.get(118)) { throw new IllegalStateException("hub.context/RETURN_DATA_CONTEXT_NUMBER already set"); } else { - filled.set(116); + filled.set(118); } if (b >= 4294967296L) { @@ -2480,10 +2681,10 @@ public Trace pContextReturnDataContextNumber(final long b) { } public Trace pContextReturnDataOffset(final long b) { - if (filled.get(117)) { + if (filled.get(119)) { throw new IllegalStateException("hub.context/RETURN_DATA_OFFSET already set"); } else { - filled.set(117); + filled.set(119); } if (b >= 4294967296L) { @@ -2499,10 +2700,10 @@ public Trace pContextReturnDataOffset(final long b) { } public Trace pContextReturnDataSize(final long b) { - if (filled.get(118)) { + if (filled.get(120)) { throw new IllegalStateException("hub.context/RETURN_DATA_SIZE already set"); } else { - filled.set(118); + filled.set(120); } if (b >= 4294967296L) { @@ -2523,17 +2724,17 @@ public Trace pContextUpdate(final Boolean b) { filled.set(47); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 + againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2 .put((byte) (b ? 1 : 0)); return this; } public Trace pMiscCcrsStamp(final long b) { - if (filled.get(103)) { + if (filled.get(105)) { throw new IllegalStateException("hub.misc/CCRS_STAMP already set"); } else { - filled.set(103); + filled.set(105); } if (b >= 4294967296L) { @@ -2561,17 +2762,17 @@ public Trace pMiscCcsrFlag(final Boolean b) { filled.set(45); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd - .put((byte) (b ? 1 : 0)); + againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } public Trace pMiscExpData1(final Bytes b) { - if (filled.get(132)) { + if (filled.get(134)) { throw new IllegalStateException("hub.misc/EXP_DATA_1 already set"); } else { - filled.set(132); + filled.set(134); } // Trim array to size @@ -2598,10 +2799,10 @@ public Trace pMiscExpData1(final Bytes b) { } public Trace pMiscExpData2(final Bytes b) { - if (filled.get(133)) { + if (filled.get(135)) { throw new IllegalStateException("hub.misc/EXP_DATA_2 already set"); } else { - filled.set(133); + filled.set(135); } // Trim array to size @@ -2628,10 +2829,10 @@ public Trace pMiscExpData2(final Bytes b) { } public Trace pMiscExpData3(final Bytes b) { - if (filled.get(134)) { + if (filled.get(136)) { throw new IllegalStateException("hub.misc/EXP_DATA_3 already set"); } else { - filled.set(134); + filled.set(136); } // Trim array to size @@ -2658,10 +2859,10 @@ public Trace pMiscExpData3(final Bytes b) { } public Trace pMiscExpData4(final Bytes b) { - if (filled.get(135)) { + if (filled.get(137)) { throw new IllegalStateException("hub.misc/EXP_DATA_4 already set"); } else { - filled.set(135); + filled.set(137); } // Trim array to size @@ -2686,10 +2887,10 @@ public Trace pMiscExpData4(final Bytes b) { } public Trace pMiscExpData5(final Bytes b) { - if (filled.get(136)) { + if (filled.get(138)) { throw new IllegalStateException("hub.misc/EXP_DATA_5 already set"); } else { - filled.set(136); + filled.set(138); } // Trim array to size @@ -2720,17 +2921,17 @@ public Trace pMiscExpFlag(final Boolean b) { filled.set(46); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment - .put((byte) (b ? 1 : 0)); + againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment.put( + (byte) (b ? 1 : 0)); return this; } public Trace pMiscExpInst(final long b) { - if (filled.get(104)) { + if (filled.get(106)) { throw new IllegalStateException("hub.misc/EXP_INST already set"); } else { - filled.set(104); + filled.set(106); } if (b >= 4294967296L) { @@ -2752,10 +2953,10 @@ public Trace pMiscExpInst(final long b) { } public Trace pMiscMmuAuxId(final long b) { - if (filled.get(105)) { + if (filled.get(107)) { throw new IllegalStateException("hub.misc/MMU_AUX_ID already set"); } else { - filled.set(105); + filled.set(107); } if (b >= 4294967296L) { @@ -2777,10 +2978,10 @@ public Trace pMiscMmuAuxId(final long b) { } public Trace pMiscMmuExoSum(final long b) { - if (filled.get(106)) { + if (filled.get(108)) { throw new IllegalStateException("hub.misc/MMU_EXO_SUM already set"); } else { - filled.set(106); + filled.set(108); } if (b >= 4294967296L) { @@ -2807,17 +3008,17 @@ public Trace pMiscMmuFlag(final Boolean b) { filled.set(47); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 + againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2 .put((byte) (b ? 1 : 0)); return this; } public Trace pMiscMmuInst(final long b) { - if (filled.get(107)) { + if (filled.get(109)) { throw new IllegalStateException("hub.misc/MMU_INST already set"); } else { - filled.set(107); + filled.set(109); } if (b >= 4294967296L) { @@ -2838,10 +3039,10 @@ public Trace pMiscMmuInst(final long b) { } public Trace pMiscMmuLimb1(final Bytes b) { - if (filled.get(137)) { + if (filled.get(139)) { throw new IllegalStateException("hub.misc/MMU_LIMB_1 already set"); } else { - filled.set(137); + filled.set(139); } // Trim array to size @@ -2866,10 +3067,10 @@ public Trace pMiscMmuLimb1(final Bytes b) { } public Trace pMiscMmuLimb2(final Bytes b) { - if (filled.get(138)) { + if (filled.get(140)) { throw new IllegalStateException("hub.misc/MMU_LIMB_2 already set"); } else { - filled.set(138); + filled.set(140); } // Trim array to size @@ -2894,10 +3095,10 @@ public Trace pMiscMmuLimb2(final Bytes b) { } public Trace pMiscMmuPhase(final long b) { - if (filled.get(108)) { + if (filled.get(110)) { throw new IllegalStateException("hub.misc/MMU_PHASE already set"); } else { - filled.set(108); + filled.set(110); } if (b >= 4294967296L) { @@ -2915,10 +3116,10 @@ public Trace pMiscMmuPhase(final long b) { } public Trace pMiscMmuRefOffset(final long b) { - if (filled.get(109)) { + if (filled.get(111)) { throw new IllegalStateException("hub.misc/MMU_REF_OFFSET already set"); } else { - filled.set(109); + filled.set(111); } if (b >= 4294967296L) { @@ -2936,10 +3137,10 @@ public Trace pMiscMmuRefOffset(final long b) { } public Trace pMiscMmuRefSize(final long b) { - if (filled.get(110)) { + if (filled.get(112)) { throw new IllegalStateException("hub.misc/MMU_REF_SIZE already set"); } else { - filled.set(110); + filled.set(112); } if (b >= 4294967296L) { @@ -2955,10 +3156,10 @@ public Trace pMiscMmuRefSize(final long b) { } public Trace pMiscMmuSize(final long b) { - if (filled.get(111)) { + if (filled.get(113)) { throw new IllegalStateException("hub.misc/MMU_SIZE already set"); } else { - filled.set(111); + filled.set(113); } if (b >= 4294967296L) { @@ -2973,10 +3174,10 @@ public Trace pMiscMmuSize(final long b) { } public Trace pMiscMmuSrcId(final long b) { - if (filled.get(112)) { + if (filled.get(114)) { throw new IllegalStateException("hub.misc/MMU_SRC_ID already set"); } else { - filled.set(112); + filled.set(114); } if (b >= 4294967296L) { @@ -2991,10 +3192,10 @@ public Trace pMiscMmuSrcId(final long b) { } public Trace pMiscMmuSrcOffsetHi(final Bytes b) { - if (filled.get(139)) { + if (filled.get(141)) { throw new IllegalStateException("hub.misc/MMU_SRC_OFFSET_HI already set"); } else { - filled.set(139); + filled.set(141); } // Trim array to size @@ -3019,10 +3220,10 @@ public Trace pMiscMmuSrcOffsetHi(final Bytes b) { } public Trace pMiscMmuSrcOffsetLo(final Bytes b) { - if (filled.get(140)) { + if (filled.get(142)) { throw new IllegalStateException("hub.misc/MMU_SRC_OFFSET_LO already set"); } else { - filled.set(140); + filled.set(142); } // Trim array to size @@ -3053,17 +3254,17 @@ public Trace pMiscMmuSuccessBit(final Boolean b) { filled.set(48); } - existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution + deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution .put((byte) (b ? 1 : 0)); return this; } public Trace pMiscMmuTgtId(final long b) { - if (filled.get(113)) { + if (filled.get(115)) { throw new IllegalStateException("hub.misc/MMU_TGT_ID already set"); } else { - filled.set(113); + filled.set(115); } if (b >= 4294967296L) { @@ -3078,10 +3279,10 @@ public Trace pMiscMmuTgtId(final long b) { } public Trace pMiscMmuTgtOffsetLo(final Bytes b) { - if (filled.get(141)) { + if (filled.get(143)) { throw new IllegalStateException("hub.misc/MMU_TGT_OFFSET_LO already set"); } else { - filled.set(141); + filled.set(143); } // Trim array to size @@ -3112,7 +3313,7 @@ public Trace pMiscMxpDeploys(final Boolean b) { filled.set(49); } - existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode.put( (byte) (b ? 1 : 0)); return this; @@ -3125,16 +3326,16 @@ public Trace pMiscMxpFlag(final Boolean b) { filled.set(50); } - hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorMxpFlagXorCallPrcFailureXorConFlagXorFinalInTxn.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscMxpGasMxp(final Bytes b) { - if (filled.get(142)) { + if (filled.get(144)) { throw new IllegalStateException("hub.misc/MXP_GAS_MXP already set"); } else { - filled.set(142); + filled.set(144); } // Trim array to size @@ -3159,10 +3360,10 @@ public Trace pMiscMxpGasMxp(final Bytes b) { } public Trace pMiscMxpInst(final long b) { - if (filled.get(114)) { + if (filled.get(116)) { throw new IllegalStateException("hub.misc/MXP_INST already set"); } else { - filled.set(114); + filled.set(116); } if (b >= 4294967296L) { @@ -3184,7 +3385,7 @@ public Trace pMiscMxpMtntop(final Boolean b) { filled.set(51); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig.put( + existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.put( (byte) (b ? 1 : 0)); return this; @@ -3197,17 +3398,17 @@ public Trace pMiscMxpMxpx(final Boolean b) { filled.set(52); } - isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero.put( + existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.put( (byte) (b ? 1 : 0)); return this; } public Trace pMiscMxpOffset1Hi(final Bytes b) { - if (filled.get(143)) { + if (filled.get(145)) { throw new IllegalStateException("hub.misc/MXP_OFFSET_1_HI already set"); } else { - filled.set(143); + filled.set(145); } // Trim array to size @@ -3232,10 +3433,10 @@ public Trace pMiscMxpOffset1Hi(final Bytes b) { } public Trace pMiscMxpOffset1Lo(final Bytes b) { - if (filled.get(144)) { + if (filled.get(146)) { throw new IllegalStateException("hub.misc/MXP_OFFSET_1_LO already set"); } else { - filled.set(144); + filled.set(146); } // Trim array to size @@ -3258,10 +3459,10 @@ public Trace pMiscMxpOffset1Lo(final Bytes b) { } public Trace pMiscMxpOffset2Hi(final Bytes b) { - if (filled.get(145)) { + if (filled.get(147)) { throw new IllegalStateException("hub.misc/MXP_OFFSET_2_HI already set"); } else { - filled.set(145); + filled.set(147); } // Trim array to size @@ -3284,10 +3485,10 @@ public Trace pMiscMxpOffset2Hi(final Bytes b) { } public Trace pMiscMxpOffset2Lo(final Bytes b) { - if (filled.get(146)) { + if (filled.get(148)) { throw new IllegalStateException("hub.misc/MXP_OFFSET_2_LO already set"); } else { - filled.set(146); + filled.set(148); } // Trim array to size @@ -3310,10 +3511,10 @@ public Trace pMiscMxpOffset2Lo(final Bytes b) { } public Trace pMiscMxpSize1Hi(final Bytes b) { - if (filled.get(147)) { + if (filled.get(149)) { throw new IllegalStateException("hub.misc/MXP_SIZE_1_HI already set"); } else { - filled.set(147); + filled.set(149); } // Trim array to size @@ -3336,10 +3537,10 @@ public Trace pMiscMxpSize1Hi(final Bytes b) { } public Trace pMiscMxpSize1Lo(final Bytes b) { - if (filled.get(148)) { + if (filled.get(150)) { throw new IllegalStateException("hub.misc/MXP_SIZE_1_LO already set"); } else { - filled.set(148); + filled.set(150); } // Trim array to size @@ -3368,17 +3569,17 @@ public Trace pMiscMxpSize1NonzeroNoMxpx(final Boolean b) { filled.set(53); } - markedForSelfdestructXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero - .put((byte) (b ? 1 : 0)); + finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn.put( + (byte) (b ? 1 : 0)); return this; } public Trace pMiscMxpSize2Hi(final Bytes b) { - if (filled.get(149)) { + if (filled.get(151)) { throw new IllegalStateException("hub.misc/MXP_SIZE_2_HI already set"); } else { - filled.set(149); + filled.set(151); } // Trim array to size @@ -3401,10 +3602,10 @@ public Trace pMiscMxpSize2Hi(final Bytes b) { } public Trace pMiscMxpSize2Lo(final Bytes b) { - if (filled.get(150)) { + if (filled.get(152)) { throw new IllegalStateException("hub.misc/MXP_SIZE_2_LO already set"); } else { - filled.set(150); + filled.set(152); } // Trim array to size @@ -3433,17 +3634,17 @@ public Trace pMiscMxpSize2NonzeroNoMxpx(final Boolean b) { filled.set(54); } - markedForSelfdestructNewXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth + finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorUnconstrainedFinal .put((byte) (b ? 1 : 0)); return this; } public Trace pMiscMxpWords(final Bytes b) { - if (filled.get(151)) { + if (filled.get(153)) { throw new IllegalStateException("hub.misc/MXP_WORDS already set"); } else { - filled.set(151); + filled.set(153); } // Trim array to size @@ -3465,10 +3666,10 @@ public Trace pMiscMxpWords(final Bytes b) { } public Trace pMiscOobData1(final Bytes b) { - if (filled.get(152)) { + if (filled.get(154)) { throw new IllegalStateException("hub.misc/OOB_DATA_1 already set"); } else { - filled.set(152); + filled.set(154); } // Trim array to size @@ -3490,10 +3691,10 @@ public Trace pMiscOobData1(final Bytes b) { } public Trace pMiscOobData2(final Bytes b) { - if (filled.get(153)) { + if (filled.get(155)) { throw new IllegalStateException("hub.misc/OOB_DATA_2 already set"); } else { - filled.set(153); + filled.set(155); } // Trim array to size @@ -3515,10 +3716,10 @@ public Trace pMiscOobData2(final Bytes b) { } public Trace pMiscOobData3(final Bytes b) { - if (filled.get(154)) { + if (filled.get(156)) { throw new IllegalStateException("hub.misc/OOB_DATA_3 already set"); } else { - filled.set(154); + filled.set(156); } // Trim array to size @@ -3540,10 +3741,10 @@ public Trace pMiscOobData3(final Bytes b) { } public Trace pMiscOobData4(final Bytes b) { - if (filled.get(155)) { + if (filled.get(157)) { throw new IllegalStateException("hub.misc/OOB_DATA_4 already set"); } else { - filled.set(155); + filled.set(157); } // Trim array to size @@ -3565,10 +3766,10 @@ public Trace pMiscOobData4(final Bytes b) { } public Trace pMiscOobData5(final Bytes b) { - if (filled.get(156)) { + if (filled.get(158)) { throw new IllegalStateException("hub.misc/OOB_DATA_5 already set"); } else { - filled.set(156); + filled.set(158); } // Trim array to size @@ -3590,10 +3791,10 @@ public Trace pMiscOobData5(final Bytes b) { } public Trace pMiscOobData6(final Bytes b) { - if (filled.get(157)) { + if (filled.get(159)) { throw new IllegalStateException("hub.misc/OOB_DATA_6 already set"); } else { - filled.set(157); + filled.set(159); } // Trim array to size @@ -3615,10 +3816,10 @@ public Trace pMiscOobData6(final Bytes b) { } public Trace pMiscOobData7(final Bytes b) { - if (filled.get(158)) { + if (filled.get(160)) { throw new IllegalStateException("hub.misc/OOB_DATA_7 already set"); } else { - filled.set(158); + filled.set(160); } // Trim array to size @@ -3640,10 +3841,10 @@ public Trace pMiscOobData7(final Bytes b) { } public Trace pMiscOobData8(final Bytes b) { - if (filled.get(159)) { + if (filled.get(161)) { throw new IllegalStateException("hub.misc/OOB_DATA_8 already set"); } else { - filled.set(159); + filled.set(161); } // Trim array to size @@ -3665,10 +3866,10 @@ public Trace pMiscOobData8(final Bytes b) { } public Trace pMiscOobData9(final Bytes b) { - if (filled.get(160)) { + if (filled.get(162)) { throw new IllegalStateException("hub.misc/OOB_DATA_9 already set"); } else { - filled.set(160); + filled.set(162); } // Trim array to size @@ -3696,17 +3897,17 @@ public Trace pMiscOobFlag(final Boolean b) { filled.set(55); } - rlpaddrFlagXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew.put( + finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorUnconstrainedFirst.put( (byte) (b ? 1 : 0)); return this; } public Trace pMiscOobInst(final long b) { - if (filled.get(115)) { + if (filled.get(117)) { throw new IllegalStateException("hub.misc/OOB_INST already set"); } else { - filled.set(115); + filled.set(117); } if (b >= 4294967296L) { @@ -3727,7 +3928,8 @@ public Trace pMiscStpExists(final Boolean b) { filled.set(56); } - romlexFlagXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4.put((byte) (b ? 1 : 0)); + firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrChanges.put( + (byte) (b ? 1 : 0)); return this; } @@ -3739,16 +3941,16 @@ public Trace pMiscStpFlag(final Boolean b) { filled.set(57); } - trmFlagXorStpFlagXorCreateAbortXorDupFlag.put((byte) (b ? 1 : 0)); + firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueCurrIsOrig.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscStpGasHi(final Bytes b) { - if (filled.get(161)) { + if (filled.get(163)) { throw new IllegalStateException("hub.misc/STP_GAS_HI already set"); } else { - filled.set(161); + filled.set(163); } // Trim array to size @@ -3770,10 +3972,10 @@ public Trace pMiscStpGasHi(final Bytes b) { } public Trace pMiscStpGasLo(final Bytes b) { - if (filled.get(162)) { + if (filled.get(164)) { throw new IllegalStateException("hub.misc/STP_GAS_LO already set"); } else { - filled.set(162); + filled.set(164); } // Trim array to size @@ -3795,10 +3997,10 @@ public Trace pMiscStpGasLo(final Bytes b) { } public Trace pMiscStpGasMxp(final Bytes b) { - if (filled.get(123)) { + if (filled.get(125)) { throw new IllegalStateException("hub.misc/STP_GAS_MXP already set"); } else { - filled.set(123); + filled.set(125); } // Trim array to size @@ -3821,10 +4023,10 @@ public Trace pMiscStpGasMxp(final Bytes b) { } public Trace pMiscStpGasPaidOutOfPocket(final Bytes b) { - if (filled.get(124)) { + if (filled.get(126)) { throw new IllegalStateException("hub.misc/STP_GAS_PAID_OUT_OF_POCKET already set"); } else { - filled.set(124); + filled.set(126); } // Trim array to size @@ -3849,10 +4051,10 @@ public Trace pMiscStpGasPaidOutOfPocket(final Bytes b) { } public Trace pMiscStpGasStipend(final long b) { - if (filled.get(116)) { + if (filled.get(118)) { throw new IllegalStateException("hub.misc/STP_GAS_STIPEND already set"); } else { - filled.set(116); + filled.set(118); } if (b >= 4294967296L) { @@ -3868,10 +4070,10 @@ public Trace pMiscStpGasStipend(final long b) { } public Trace pMiscStpGasUpfrontGasCost(final Bytes b) { - if (filled.get(125)) { + if (filled.get(127)) { throw new IllegalStateException("hub.misc/STP_GAS_UPFRONT_GAS_COST already set"); } else { - filled.set(125); + filled.set(127); } // Trim array to size @@ -3894,10 +4096,10 @@ public Trace pMiscStpGasUpfrontGasCost(final Bytes b) { } public Trace pMiscStpInstruction(final long b) { - if (filled.get(117)) { + if (filled.get(119)) { throw new IllegalStateException("hub.misc/STP_INSTRUCTION already set"); } else { - filled.set(117); + filled.set(119); } if (b >= 4294967296L) { @@ -3919,16 +4121,17 @@ public Trace pMiscStpOogx(final Boolean b) { filled.set(58); } - warmthXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlag.put((byte) (b ? 1 : 0)); + firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueCurrIsZero.put( + (byte) (b ? 1 : 0)); return this; } public Trace pMiscStpValueHi(final Bytes b) { - if (filled.get(163)) { + if (filled.get(165)) { throw new IllegalStateException("hub.misc/STP_VALUE_HI already set"); } else { - filled.set(163); + filled.set(165); } // Trim array to size @@ -3951,10 +4154,10 @@ public Trace pMiscStpValueHi(final Bytes b) { } public Trace pMiscStpValueLo(final Bytes b) { - if (filled.get(164)) { + if (filled.get(166)) { throw new IllegalStateException("hub.misc/STP_VALUE_LO already set"); } else { - filled.set(164); + filled.set(166); } // Trim array to size @@ -3983,7 +4186,8 @@ public Trace pMiscStpWarmth(final Boolean b) { filled.set(59); } - warmthNewXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlag.put((byte) (b ? 1 : 0)); + hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsCurr.put( + (byte) (b ? 1 : 0)); return this; } @@ -3995,8 +4199,8 @@ public Trace pScenarioCallAbortWillRevert(final Boolean b) { filled.set(45); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd - .put((byte) (b ? 1 : 0)); + againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -4008,8 +4212,8 @@ public Trace pScenarioCallAbortWontRevert(final Boolean b) { filled.set(46); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment - .put((byte) (b ? 1 : 0)); + againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment.put( + (byte) (b ? 1 : 0)); return this; } @@ -4022,7 +4226,7 @@ public Trace pScenarioCallEoaSuccessCallerWillRevert(final Boolean b) { filled.set(47); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 + againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2 .put((byte) (b ? 1 : 0)); return this; @@ -4036,7 +4240,7 @@ public Trace pScenarioCallEoaSuccessCallerWontRevert(final Boolean b) { filled.set(48); } - existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution + deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution .put((byte) (b ? 1 : 0)); return this; @@ -4049,7 +4253,7 @@ public Trace pScenarioCallException(final Boolean b) { filled.set(49); } - existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode.put( (byte) (b ? 1 : 0)); return this; @@ -4062,7 +4266,7 @@ public Trace pScenarioCallPrcFailure(final Boolean b) { filled.set(50); } - hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorMxpFlagXorCallPrcFailureXorConFlagXorFinalInTxn.put((byte) (b ? 1 : 0)); return this; } @@ -4075,7 +4279,7 @@ public Trace pScenarioCallPrcSuccessCallerWillRevert(final Boolean b) { filled.set(51); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig.put( + existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.put( (byte) (b ? 1 : 0)); return this; @@ -4089,7 +4293,7 @@ public Trace pScenarioCallPrcSuccessCallerWontRevert(final Boolean b) { filled.set(52); } - isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero.put( + existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.put( (byte) (b ? 1 : 0)); return this; @@ -4103,8 +4307,8 @@ public Trace pScenarioCallSmcFailureCallerWillRevert(final Boolean b) { filled.set(53); } - markedForSelfdestructXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero - .put((byte) (b ? 1 : 0)); + finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn.put( + (byte) (b ? 1 : 0)); return this; } @@ -4117,7 +4321,7 @@ public Trace pScenarioCallSmcFailureCallerWontRevert(final Boolean b) { filled.set(54); } - markedForSelfdestructNewXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth + finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorUnconstrainedFinal .put((byte) (b ? 1 : 0)); return this; @@ -4131,7 +4335,7 @@ public Trace pScenarioCallSmcSuccessCallerWillRevert(final Boolean b) { filled.set(55); } - rlpaddrFlagXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew.put( + finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorUnconstrainedFirst.put( (byte) (b ? 1 : 0)); return this; @@ -4145,7 +4349,8 @@ public Trace pScenarioCallSmcSuccessCallerWontRevert(final Boolean b) { filled.set(56); } - romlexFlagXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4.put((byte) (b ? 1 : 0)); + firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrChanges.put( + (byte) (b ? 1 : 0)); return this; } @@ -4157,7 +4362,7 @@ public Trace pScenarioCreateAbort(final Boolean b) { filled.set(57); } - trmFlagXorStpFlagXorCreateAbortXorDupFlag.put((byte) (b ? 1 : 0)); + firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueCurrIsOrig.put((byte) (b ? 1 : 0)); return this; } @@ -4170,7 +4375,8 @@ public Trace pScenarioCreateEmptyInitCodeWillRevert(final Boolean b) { filled.set(58); } - warmthXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlag.put((byte) (b ? 1 : 0)); + firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueCurrIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -4183,7 +4389,8 @@ public Trace pScenarioCreateEmptyInitCodeWontRevert(final Boolean b) { filled.set(59); } - warmthNewXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlag.put((byte) (b ? 1 : 0)); + hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsCurr.put( + (byte) (b ? 1 : 0)); return this; } @@ -4195,7 +4402,7 @@ public Trace pScenarioCreateException(final Boolean b) { filled.set(60); } - createExceptionXorHashInfoFlag.put((byte) (b ? 1 : 0)); + hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueNextIsOrig.put((byte) (b ? 1 : 0)); return this; } @@ -4208,7 +4415,8 @@ public Trace pScenarioCreateFailureConditionWillRevert(final Boolean b) { filled.set(61); } - createFailureConditionWillRevertXorIcpx.put((byte) (b ? 1 : 0)); + isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -4221,7 +4429,8 @@ public Trace pScenarioCreateFailureConditionWontRevert(final Boolean b) { filled.set(62); } - createFailureConditionWontRevertXorInvalidFlag.put((byte) (b ? 1 : 0)); + markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorValueOrigIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -4234,7 +4443,8 @@ public Trace pScenarioCreateNonemptyInitCodeFailureWillRevert(final Boolean b) { filled.set(63); } - createNonemptyInitCodeFailureWillRevertXorJumpx.put((byte) (b ? 1 : 0)); + markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpxXorWarmth.put( + (byte) (b ? 1 : 0)); return this; } @@ -4247,8 +4457,8 @@ public Trace pScenarioCreateNonemptyInitCodeFailureWontRevert(final Boolean b) { filled.set(64); } - createNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequired.put( - (byte) (b ? 1 : 0)); + rlpaddrFlagXorCreateNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequiredXorWarmthNew + .put((byte) (b ? 1 : 0)); return this; } @@ -4261,7 +4471,7 @@ public Trace pScenarioCreateNonemptyInitCodeSuccessWillRevert(final Boolean b) { filled.set(65); } - createNonemptyInitCodeSuccessWillRevertXorJumpFlag.put((byte) (b ? 1 : 0)); + romlexFlagXorCreateNonemptyInitCodeSuccessWillRevertXorJumpFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4274,7 +4484,7 @@ public Trace pScenarioCreateNonemptyInitCodeSuccessWontRevert(final Boolean b) { filled.set(66); } - createNonemptyInitCodeSuccessWontRevertXorKecFlag.put((byte) (b ? 1 : 0)); + trmFlagXorCreateNonemptyInitCodeSuccessWontRevertXorKecFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4286,16 +4496,16 @@ public Trace pScenarioPrcBlake2F(final Boolean b) { filled.set(67); } - prcBlake2FXorLogFlag.put((byte) (b ? 1 : 0)); + warmthXorPrcBlake2FXorLogFlag.put((byte) (b ? 1 : 0)); return this; } public Trace pScenarioPrcCalleeGas(final long b) { - if (filled.get(103)) { + if (filled.get(105)) { throw new IllegalStateException("hub.scenario/PRC_CALLEE_GAS already set"); } else { - filled.set(103); + filled.set(105); } if (b >= 4294967296L) { @@ -4317,10 +4527,10 @@ public Trace pScenarioPrcCalleeGas(final long b) { } public Trace pScenarioPrcCallerGas(final long b) { - if (filled.get(104)) { + if (filled.get(106)) { throw new IllegalStateException("hub.scenario/PRC_CALLER_GAS already set"); } else { - filled.set(104); + filled.set(106); } if (b >= 4294967296L) { @@ -4342,10 +4552,10 @@ public Trace pScenarioPrcCallerGas(final long b) { } public Trace pScenarioPrcCdo(final long b) { - if (filled.get(105)) { + if (filled.get(107)) { throw new IllegalStateException("hub.scenario/PRC_CDO already set"); } else { - filled.set(105); + filled.set(107); } if (b >= 4294967296L) { @@ -4367,10 +4577,10 @@ public Trace pScenarioPrcCdo(final long b) { } public Trace pScenarioPrcCds(final long b) { - if (filled.get(106)) { + if (filled.get(108)) { throw new IllegalStateException("hub.scenario/PRC_CDS already set"); } else { - filled.set(106); + filled.set(108); } if (b >= 4294967296L) { @@ -4397,7 +4607,7 @@ public Trace pScenarioPrcEcadd(final Boolean b) { filled.set(68); } - prcEcaddXorLogInfoFlag.put((byte) (b ? 1 : 0)); + warmthNewXorPrcEcaddXorLogInfoFlag.put((byte) (b ? 1 : 0)); return this; } @@ -4487,10 +4697,10 @@ public Trace pScenarioPrcModexp(final Boolean b) { } public Trace pScenarioPrcRac(final long b) { - if (filled.get(107)) { + if (filled.get(109)) { throw new IllegalStateException("hub.scenario/PRC_RAC already set"); } else { - filled.set(107); + filled.set(109); } if (b >= 4294967296L) { @@ -4511,10 +4721,10 @@ public Trace pScenarioPrcRac(final long b) { } public Trace pScenarioPrcRao(final long b) { - if (filled.get(108)) { + if (filled.get(110)) { throw new IllegalStateException("hub.scenario/PRC_RAO already set"); } else { - filled.set(108); + filled.set(110); } if (b >= 4294967296L) { @@ -4532,10 +4742,10 @@ public Trace pScenarioPrcRao(final long b) { } public Trace pScenarioPrcReturnGas(final long b) { - if (filled.get(109)) { + if (filled.get(111)) { throw new IllegalStateException("hub.scenario/PRC_RETURN_GAS already set"); } else { - filled.set(109); + filled.set(111); } if (b >= 4294967296L) { @@ -4747,8 +4957,8 @@ public Trace pStackAccFlag(final Boolean b) { filled.set(45); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd - .put((byte) (b ? 1 : 0)); + againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } @@ -4760,8 +4970,8 @@ public Trace pStackAddFlag(final Boolean b) { filled.set(46); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment - .put((byte) (b ? 1 : 0)); + againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment.put( + (byte) (b ? 1 : 0)); return this; } @@ -4785,7 +4995,7 @@ public Trace pStackBinFlag(final Boolean b) { filled.set(47); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 + againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2 .put((byte) (b ? 1 : 0)); return this; @@ -4798,7 +5008,7 @@ public Trace pStackBtcFlag(final Boolean b) { filled.set(48); } - existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution + deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution .put((byte) (b ? 1 : 0)); return this; @@ -4811,7 +5021,7 @@ public Trace pStackCallFlag(final Boolean b) { filled.set(49); } - existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode.put( (byte) (b ? 1 : 0)); return this; @@ -4824,7 +5034,7 @@ public Trace pStackConFlag(final Boolean b) { filled.set(50); } - hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); + deploymentStatusNewXorMxpFlagXorCallPrcFailureXorConFlagXorFinalInTxn.put((byte) (b ? 1 : 0)); return this; } @@ -4836,7 +5046,7 @@ public Trace pStackCopyFlag(final Boolean b) { filled.set(51); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig.put( + existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.put( (byte) (b ? 1 : 0)); return this; @@ -4849,7 +5059,7 @@ public Trace pStackCreateFlag(final Boolean b) { filled.set(52); } - isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero.put( + existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.put( (byte) (b ? 1 : 0)); return this; @@ -4862,8 +5072,8 @@ public Trace pStackDecFlag1(final Boolean b) { filled.set(53); } - markedForSelfdestructXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero - .put((byte) (b ? 1 : 0)); + finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn.put( + (byte) (b ? 1 : 0)); return this; } @@ -4875,7 +5085,7 @@ public Trace pStackDecFlag2(final Boolean b) { filled.set(54); } - markedForSelfdestructNewXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth + finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorUnconstrainedFinal .put((byte) (b ? 1 : 0)); return this; @@ -4888,7 +5098,7 @@ public Trace pStackDecFlag3(final Boolean b) { filled.set(55); } - rlpaddrFlagXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew.put( + finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorUnconstrainedFirst.put( (byte) (b ? 1 : 0)); return this; @@ -4901,7 +5111,8 @@ public Trace pStackDecFlag4(final Boolean b) { filled.set(56); } - romlexFlagXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4.put((byte) (b ? 1 : 0)); + firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrChanges.put( + (byte) (b ? 1 : 0)); return this; } @@ -4925,7 +5136,7 @@ public Trace pStackDupFlag(final Boolean b) { filled.set(57); } - trmFlagXorStpFlagXorCreateAbortXorDupFlag.put((byte) (b ? 1 : 0)); + firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueCurrIsOrig.put((byte) (b ? 1 : 0)); return this; } @@ -4937,7 +5148,8 @@ public Trace pStackExtFlag(final Boolean b) { filled.set(58); } - warmthXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlag.put((byte) (b ? 1 : 0)); + firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueCurrIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -4949,7 +5161,8 @@ public Trace pStackHaltFlag(final Boolean b) { filled.set(59); } - warmthNewXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlag.put((byte) (b ? 1 : 0)); + hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsCurr.put( + (byte) (b ? 1 : 0)); return this; } @@ -4961,16 +5174,16 @@ public Trace pStackHashInfoFlag(final Boolean b) { filled.set(60); } - createExceptionXorHashInfoFlag.put((byte) (b ? 1 : 0)); + hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueNextIsOrig.put((byte) (b ? 1 : 0)); return this; } public Trace pStackHashInfoKeccakHi(final Bytes b) { - if (filled.get(132)) { + if (filled.get(134)) { throw new IllegalStateException("hub.stack/HASH_INFO_KECCAK_HI already set"); } else { - filled.set(132); + filled.set(134); } // Trim array to size @@ -4997,10 +5210,10 @@ public Trace pStackHashInfoKeccakHi(final Bytes b) { } public Trace pStackHashInfoKeccakLo(final Bytes b) { - if (filled.get(133)) { + if (filled.get(135)) { throw new IllegalStateException("hub.stack/HASH_INFO_KECCAK_LO already set"); } else { - filled.set(133); + filled.set(135); } // Trim array to size @@ -5033,16 +5246,17 @@ public Trace pStackIcpx(final Boolean b) { filled.set(61); } - createFailureConditionWillRevertXorIcpx.put((byte) (b ? 1 : 0)); + isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorValueNextIsZero.put( + (byte) (b ? 1 : 0)); return this; } public Trace pStackInstruction(final Bytes b) { - if (filled.get(165)) { + if (filled.get(167)) { throw new IllegalStateException("hub.stack/INSTRUCTION already set"); } else { - filled.set(165); + filled.set(167); } // Trim array to size @@ -5071,7 +5285,8 @@ public Trace pStackInvalidFlag(final Boolean b) { filled.set(62); } - createFailureConditionWontRevertXorInvalidFlag.put((byte) (b ? 1 : 0)); + markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorValueOrigIsZero.put( + (byte) (b ? 1 : 0)); return this; } @@ -5083,8 +5298,8 @@ public Trace pStackJumpDestinationVettingRequired(final Boolean b) { filled.set(64); } - createNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequired.put( - (byte) (b ? 1 : 0)); + rlpaddrFlagXorCreateNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequiredXorWarmthNew + .put((byte) (b ? 1 : 0)); return this; } @@ -5096,7 +5311,7 @@ public Trace pStackJumpFlag(final Boolean b) { filled.set(65); } - createNonemptyInitCodeSuccessWillRevertXorJumpFlag.put((byte) (b ? 1 : 0)); + romlexFlagXorCreateNonemptyInitCodeSuccessWillRevertXorJumpFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5108,7 +5323,8 @@ public Trace pStackJumpx(final Boolean b) { filled.set(63); } - createNonemptyInitCodeFailureWillRevertXorJumpx.put((byte) (b ? 1 : 0)); + markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpxXorWarmth.put( + (byte) (b ? 1 : 0)); return this; } @@ -5120,7 +5336,7 @@ public Trace pStackKecFlag(final Boolean b) { filled.set(66); } - createNonemptyInitCodeSuccessWontRevertXorKecFlag.put((byte) (b ? 1 : 0)); + trmFlagXorCreateNonemptyInitCodeSuccessWontRevertXorKecFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5132,7 +5348,7 @@ public Trace pStackLogFlag(final Boolean b) { filled.set(67); } - prcBlake2FXorLogFlag.put((byte) (b ? 1 : 0)); + warmthXorPrcBlake2FXorLogFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5144,7 +5360,7 @@ public Trace pStackLogInfoFlag(final Boolean b) { filled.set(68); } - prcEcaddXorLogInfoFlag.put((byte) (b ? 1 : 0)); + warmthNewXorPrcEcaddXorLogInfoFlag.put((byte) (b ? 1 : 0)); return this; } @@ -5270,10 +5486,10 @@ public Trace pStackOpcx(final Boolean b) { } public Trace pStackPushValueHi(final Bytes b) { - if (filled.get(134)) { + if (filled.get(136)) { throw new IllegalStateException("hub.stack/PUSH_VALUE_HI already set"); } else { - filled.set(134); + filled.set(136); } // Trim array to size @@ -5300,10 +5516,10 @@ public Trace pStackPushValueHi(final Bytes b) { } public Trace pStackPushValueLo(final Bytes b) { - if (filled.get(135)) { + if (filled.get(137)) { throw new IllegalStateException("hub.stack/PUSH_VALUE_LO already set"); } else { - filled.set(135); + filled.set(137); } // Trim array to size @@ -5501,10 +5717,10 @@ public Trace pStackStackItemPop4(final Boolean b) { } public Trace pStackStackItemStamp1(final long b) { - if (filled.get(119)) { + if (filled.get(121)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_1 already set"); } else { - filled.set(119); + filled.set(121); } if (b >= 68719476736L) { @@ -5520,10 +5736,10 @@ public Trace pStackStackItemStamp1(final long b) { } public Trace pStackStackItemStamp2(final long b) { - if (filled.get(120)) { + if (filled.get(122)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_2 already set"); } else { - filled.set(120); + filled.set(122); } if (b >= 68719476736L) { @@ -5539,10 +5755,10 @@ public Trace pStackStackItemStamp2(final long b) { } public Trace pStackStackItemStamp3(final long b) { - if (filled.get(121)) { + if (filled.get(123)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_3 already set"); } else { - filled.set(121); + filled.set(123); } if (b >= 68719476736L) { @@ -5558,10 +5774,10 @@ public Trace pStackStackItemStamp3(final long b) { } public Trace pStackStackItemStamp4(final long b) { - if (filled.get(122)) { + if (filled.get(124)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_4 already set"); } else { - filled.set(122); + filled.set(124); } if (b >= 68719476736L) { @@ -5577,10 +5793,10 @@ public Trace pStackStackItemStamp4(final long b) { } public Trace pStackStackItemValueHi1(final Bytes b) { - if (filled.get(136)) { + if (filled.get(138)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_HI_1 already set"); } else { - filled.set(136); + filled.set(138); } // Trim array to size @@ -5605,10 +5821,10 @@ public Trace pStackStackItemValueHi1(final Bytes b) { } public Trace pStackStackItemValueHi2(final Bytes b) { - if (filled.get(137)) { + if (filled.get(139)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_HI_2 already set"); } else { - filled.set(137); + filled.set(139); } // Trim array to size @@ -5633,10 +5849,10 @@ public Trace pStackStackItemValueHi2(final Bytes b) { } public Trace pStackStackItemValueHi3(final Bytes b) { - if (filled.get(138)) { + if (filled.get(140)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_HI_3 already set"); } else { - filled.set(138); + filled.set(140); } // Trim array to size @@ -5661,10 +5877,10 @@ public Trace pStackStackItemValueHi3(final Bytes b) { } public Trace pStackStackItemValueHi4(final Bytes b) { - if (filled.get(139)) { + if (filled.get(141)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_HI_4 already set"); } else { - filled.set(139); + filled.set(141); } // Trim array to size @@ -5689,10 +5905,10 @@ public Trace pStackStackItemValueHi4(final Bytes b) { } public Trace pStackStackItemValueLo1(final Bytes b) { - if (filled.get(140)) { + if (filled.get(142)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_LO_1 already set"); } else { - filled.set(140); + filled.set(142); } // Trim array to size @@ -5717,10 +5933,10 @@ public Trace pStackStackItemValueLo1(final Bytes b) { } public Trace pStackStackItemValueLo2(final Bytes b) { - if (filled.get(141)) { + if (filled.get(143)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_LO_2 already set"); } else { - filled.set(141); + filled.set(143); } // Trim array to size @@ -5745,10 +5961,10 @@ public Trace pStackStackItemValueLo2(final Bytes b) { } public Trace pStackStackItemValueLo3(final Bytes b) { - if (filled.get(142)) { + if (filled.get(144)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_LO_3 already set"); } else { - filled.set(142); + filled.set(144); } // Trim array to size @@ -5773,10 +5989,10 @@ public Trace pStackStackItemValueLo3(final Bytes b) { } public Trace pStackStackItemValueLo4(final Bytes b) { - if (filled.get(143)) { + if (filled.get(145)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_LO_4 already set"); } else { - filled.set(143); + filled.set(145); } // Trim array to size @@ -5825,10 +6041,10 @@ public Trace pStackStaticFlag(final Boolean b) { } public Trace pStackStaticGas(final long b) { - if (filled.get(103)) { + if (filled.get(105)) { throw new IllegalStateException("hub.stack/STATIC_GAS already set"); } else { - filled.set(103); + filled.set(105); } if (b >= 4294967296L) { @@ -5922,10 +6138,10 @@ public Trace pStackWcpFlag(final Boolean b) { } public Trace pStorageAddressHi(final long b) { - if (filled.get(103)) { + if (filled.get(105)) { throw new IllegalStateException("hub.storage/ADDRESS_HI already set"); } else { - filled.set(103); + filled.set(105); } if (b >= 4294967296L) { @@ -5947,10 +6163,10 @@ public Trace pStorageAddressHi(final long b) { } public Trace pStorageAddressLo(final Bytes b) { - if (filled.get(132)) { + if (filled.get(134)) { throw new IllegalStateException("hub.storage/ADDRESS_LO already set"); } else { - filled.set(132); + filled.set(134); } // Trim array to size @@ -5976,11 +6192,50 @@ public Trace pStorageAddressLo(final Bytes b) { return this; } + public Trace pStorageAgainInBlk(final Boolean b) { + if (filled.get(45)) { + throw new IllegalStateException("hub.storage/AGAIN_IN_BLK already set"); + } else { + filled.set(45); + } + + againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd.put( + (byte) (b ? 1 : 0)); + + return this; + } + + public Trace pStorageAgainInCnf(final Boolean b) { + if (filled.get(46)) { + throw new IllegalStateException("hub.storage/AGAIN_IN_CNF already set"); + } else { + filled.set(46); + } + + againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment.put( + (byte) (b ? 1 : 0)); + + return this; + } + + public Trace pStorageAgainInTxn(final Boolean b) { + if (filled.get(47)) { + throw new IllegalStateException("hub.storage/AGAIN_IN_TXN already set"); + } else { + filled.set(47); + } + + againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2 + .put((byte) (b ? 1 : 0)); + + return this; + } + public Trace pStorageDeploymentNumber(final long b) { - if (filled.get(104)) { + if (filled.get(106)) { throw new IllegalStateException("hub.storage/DEPLOYMENT_NUMBER already set"); } else { - filled.set(104); + filled.set(106); } if (b >= 4294967296L) { @@ -6001,11 +6256,49 @@ public Trace pStorageDeploymentNumber(final long b) { return this; } + public Trace pStorageDeploymentNumberFinalInBlock(final long b) { + if (filled.get(103)) { + throw new IllegalStateException("hub.storage/DEPLOYMENT_NUMBER_FINAL_IN_BLOCK already set"); + } else { + filled.set(103); + } + + if (b >= 65536L) { + throw new IllegalArgumentException( + "deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock has invalid value (" + + b + + ")"); + } + deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock.put((byte) (b >> 8)); + deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock.put((byte) b); + + return this; + } + + public Trace pStorageDeploymentNumberFirstInBlock(final long b) { + if (filled.get(104)) { + throw new IllegalStateException("hub.storage/DEPLOYMENT_NUMBER_FIRST_IN_BLOCK already set"); + } else { + filled.set(104); + } + + if (b >= 65536L) { + throw new IllegalArgumentException( + "deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock has invalid value (" + + b + + ")"); + } + deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock.put((byte) (b >> 8)); + deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock.put((byte) b); + + return this; + } + public Trace pStorageDeploymentNumberInfty(final long b) { - if (filled.get(105)) { + if (filled.get(107)) { throw new IllegalStateException("hub.storage/DEPLOYMENT_NUMBER_INFTY already set"); } else { - filled.set(105); + filled.set(107); } if (b >= 4294967296L) { @@ -6026,11 +6319,88 @@ public Trace pStorageDeploymentNumberInfty(final long b) { return this; } + public Trace pStorageFinalInBlk(final Boolean b) { + if (filled.get(48)) { + throw new IllegalStateException("hub.storage/FINAL_IN_BLK already set"); + } else { + filled.set(48); + } + + deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution + .put((byte) (b ? 1 : 0)); + + return this; + } + + public Trace pStorageFinalInCnf(final Boolean b) { + if (filled.get(49)) { + throw new IllegalStateException("hub.storage/FINAL_IN_CNF already set"); + } else { + filled.set(49); + } + + deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode.put( + (byte) (b ? 1 : 0)); + + return this; + } + + public Trace pStorageFinalInTxn(final Boolean b) { + if (filled.get(50)) { + throw new IllegalStateException("hub.storage/FINAL_IN_TXN already set"); + } else { + filled.set(50); + } + + deploymentStatusNewXorMxpFlagXorCallPrcFailureXorConFlagXorFinalInTxn.put((byte) (b ? 1 : 0)); + + return this; + } + + public Trace pStorageFirstInBlk(final Boolean b) { + if (filled.get(51)) { + throw new IllegalStateException("hub.storage/FIRST_IN_BLK already set"); + } else { + filled.set(51); + } + + existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.put( + (byte) (b ? 1 : 0)); + + return this; + } + + public Trace pStorageFirstInCnf(final Boolean b) { + if (filled.get(52)) { + throw new IllegalStateException("hub.storage/FIRST_IN_CNF already set"); + } else { + filled.set(52); + } + + existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.put( + (byte) (b ? 1 : 0)); + + return this; + } + + public Trace pStorageFirstInTxn(final Boolean b) { + if (filled.get(53)) { + throw new IllegalStateException("hub.storage/FIRST_IN_TXN already set"); + } else { + filled.set(53); + } + + finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn.put( + (byte) (b ? 1 : 0)); + + return this; + } + public Trace pStorageStorageKeyHi(final Bytes b) { - if (filled.get(133)) { + if (filled.get(135)) { throw new IllegalStateException("hub.storage/STORAGE_KEY_HI already set"); } else { - filled.set(133); + filled.set(135); } // Trim array to size @@ -6057,10 +6427,10 @@ public Trace pStorageStorageKeyHi(final Bytes b) { } public Trace pStorageStorageKeyLo(final Bytes b) { - if (filled.get(134)) { + if (filled.get(136)) { throw new IllegalStateException("hub.storage/STORAGE_KEY_LO already set"); } else { - filled.set(134); + filled.set(136); } // Trim array to size @@ -6087,49 +6457,49 @@ public Trace pStorageStorageKeyLo(final Bytes b) { } public Trace pStorageUnconstrainedFinal(final Boolean b) { - if (filled.get(45)) { + if (filled.get(54)) { throw new IllegalStateException("hub.storage/UNCONSTRAINED_FINAL already set"); } else { - filled.set(45); + filled.set(54); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd + finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorUnconstrainedFinal .put((byte) (b ? 1 : 0)); return this; } public Trace pStorageUnconstrainedFirst(final Boolean b) { - if (filled.get(46)) { + if (filled.get(55)) { throw new IllegalStateException("hub.storage/UNCONSTRAINED_FIRST already set"); } else { - filled.set(46); + filled.set(55); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment - .put((byte) (b ? 1 : 0)); + finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorUnconstrainedFirst.put( + (byte) (b ? 1 : 0)); return this; } public Trace pStorageValueCurrChanges(final Boolean b) { - if (filled.get(47)) { + if (filled.get(56)) { throw new IllegalStateException("hub.storage/VALUE_CURR_CHANGES already set"); } else { - filled.set(47); + filled.set(56); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 - .put((byte) (b ? 1 : 0)); + firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrChanges.put( + (byte) (b ? 1 : 0)); return this; } public Trace pStorageValueCurrHi(final Bytes b) { - if (filled.get(135)) { + if (filled.get(137)) { throw new IllegalStateException("hub.storage/VALUE_CURR_HI already set"); } else { - filled.set(135); + filled.set(137); } // Trim array to size @@ -6154,36 +6524,35 @@ public Trace pStorageValueCurrHi(final Bytes b) { } public Trace pStorageValueCurrIsOrig(final Boolean b) { - if (filled.get(48)) { + if (filled.get(57)) { throw new IllegalStateException("hub.storage/VALUE_CURR_IS_ORIG already set"); } else { - filled.set(48); + filled.set(57); } - existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution - .put((byte) (b ? 1 : 0)); + firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueCurrIsOrig.put((byte) (b ? 1 : 0)); return this; } public Trace pStorageValueCurrIsZero(final Boolean b) { - if (filled.get(49)) { + if (filled.get(58)) { throw new IllegalStateException("hub.storage/VALUE_CURR_IS_ZERO already set"); } else { - filled.set(49); + filled.set(58); } - existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueCurrIsZero.put( (byte) (b ? 1 : 0)); return this; } public Trace pStorageValueCurrLo(final Bytes b) { - if (filled.get(136)) { + if (filled.get(138)) { throw new IllegalStateException("hub.storage/VALUE_CURR_LO already set"); } else { - filled.set(136); + filled.set(138); } // Trim array to size @@ -6208,10 +6577,10 @@ public Trace pStorageValueCurrLo(final Bytes b) { } public Trace pStorageValueNextHi(final Bytes b) { - if (filled.get(137)) { + if (filled.get(139)) { throw new IllegalStateException("hub.storage/VALUE_NEXT_HI already set"); } else { - filled.set(137); + filled.set(139); } // Trim array to size @@ -6236,48 +6605,48 @@ public Trace pStorageValueNextHi(final Bytes b) { } public Trace pStorageValueNextIsCurr(final Boolean b) { - if (filled.get(50)) { + if (filled.get(59)) { throw new IllegalStateException("hub.storage/VALUE_NEXT_IS_CURR already set"); } else { - filled.set(50); + filled.set(59); } - hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); + hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsCurr.put( + (byte) (b ? 1 : 0)); return this; } public Trace pStorageValueNextIsOrig(final Boolean b) { - if (filled.get(51)) { + if (filled.get(60)) { throw new IllegalStateException("hub.storage/VALUE_NEXT_IS_ORIG already set"); } else { - filled.set(51); + filled.set(60); } - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig.put( - (byte) (b ? 1 : 0)); + hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueNextIsOrig.put((byte) (b ? 1 : 0)); return this; } public Trace pStorageValueNextIsZero(final Boolean b) { - if (filled.get(52)) { + if (filled.get(61)) { throw new IllegalStateException("hub.storage/VALUE_NEXT_IS_ZERO already set"); } else { - filled.set(52); + filled.set(61); } - isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero.put( + isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorValueNextIsZero.put( (byte) (b ? 1 : 0)); return this; } public Trace pStorageValueNextLo(final Bytes b) { - if (filled.get(138)) { + if (filled.get(140)) { throw new IllegalStateException("hub.storage/VALUE_NEXT_LO already set"); } else { - filled.set(138); + filled.set(140); } // Trim array to size @@ -6302,10 +6671,10 @@ public Trace pStorageValueNextLo(final Bytes b) { } public Trace pStorageValueOrigHi(final Bytes b) { - if (filled.get(139)) { + if (filled.get(141)) { throw new IllegalStateException("hub.storage/VALUE_ORIG_HI already set"); } else { - filled.set(139); + filled.set(141); } // Trim array to size @@ -6330,23 +6699,23 @@ public Trace pStorageValueOrigHi(final Bytes b) { } public Trace pStorageValueOrigIsZero(final Boolean b) { - if (filled.get(53)) { + if (filled.get(62)) { throw new IllegalStateException("hub.storage/VALUE_ORIG_IS_ZERO already set"); } else { - filled.set(53); + filled.set(62); } - markedForSelfdestructXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero - .put((byte) (b ? 1 : 0)); + markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorValueOrigIsZero.put( + (byte) (b ? 1 : 0)); return this; } public Trace pStorageValueOrigLo(final Bytes b) { - if (filled.get(140)) { + if (filled.get(142)) { throw new IllegalStateException("hub.storage/VALUE_ORIG_LO already set"); } else { - filled.set(140); + filled.set(142); } // Trim array to size @@ -6371,36 +6740,36 @@ public Trace pStorageValueOrigLo(final Bytes b) { } public Trace pStorageWarmth(final Boolean b) { - if (filled.get(54)) { + if (filled.get(63)) { throw new IllegalStateException("hub.storage/WARMTH already set"); } else { - filled.set(54); + filled.set(63); } - markedForSelfdestructNewXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth - .put((byte) (b ? 1 : 0)); + markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpxXorWarmth.put( + (byte) (b ? 1 : 0)); return this; } public Trace pStorageWarmthNew(final Boolean b) { - if (filled.get(55)) { + if (filled.get(64)) { throw new IllegalStateException("hub.storage/WARMTH_NEW already set"); } else { - filled.set(55); + filled.set(64); } - rlpaddrFlagXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew.put( - (byte) (b ? 1 : 0)); + rlpaddrFlagXorCreateNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequiredXorWarmthNew + .put((byte) (b ? 1 : 0)); return this; } public Trace pTransactionBasefee(final Bytes b) { - if (filled.get(123)) { + if (filled.get(125)) { throw new IllegalStateException("hub.transaction/BASEFEE already set"); } else { - filled.set(123); + filled.set(125); } // Trim array to size @@ -6423,10 +6792,10 @@ public Trace pTransactionBasefee(final Bytes b) { } public Trace pTransactionCallDataSize(final long b) { - if (filled.get(103)) { + if (filled.get(105)) { throw new IllegalStateException("hub.transaction/CALL_DATA_SIZE already set"); } else { - filled.set(103); + filled.set(105); } if (b >= 4294967296L) { @@ -6448,10 +6817,10 @@ public Trace pTransactionCallDataSize(final long b) { } public Trace pTransactionCoinbaseAddressHi(final long b) { - if (filled.get(104)) { + if (filled.get(106)) { throw new IllegalStateException("hub.transaction/COINBASE_ADDRESS_HI already set"); } else { - filled.set(104); + filled.set(106); } if (b >= 4294967296L) { @@ -6473,10 +6842,10 @@ public Trace pTransactionCoinbaseAddressHi(final long b) { } public Trace pTransactionCoinbaseAddressLo(final Bytes b) { - if (filled.get(132)) { + if (filled.get(134)) { throw new IllegalStateException("hub.transaction/COINBASE_ADDRESS_LO already set"); } else { - filled.set(132); + filled.set(134); } // Trim array to size @@ -6509,17 +6878,17 @@ public Trace pTransactionCopyTxcd(final Boolean b) { filled.set(45); } - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd - .put((byte) (b ? 1 : 0)); + againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd.put( + (byte) (b ? 1 : 0)); return this; } public Trace pTransactionFromAddressHi(final long b) { - if (filled.get(105)) { + if (filled.get(107)) { throw new IllegalStateException("hub.transaction/FROM_ADDRESS_HI already set"); } else { - filled.set(105); + filled.set(107); } if (b >= 4294967296L) { @@ -6541,10 +6910,10 @@ public Trace pTransactionFromAddressHi(final long b) { } public Trace pTransactionFromAddressLo(final Bytes b) { - if (filled.get(133)) { + if (filled.get(135)) { throw new IllegalStateException("hub.transaction/FROM_ADDRESS_LO already set"); } else { - filled.set(133); + filled.set(135); } // Trim array to size @@ -6571,10 +6940,10 @@ public Trace pTransactionFromAddressLo(final Bytes b) { } public Trace pTransactionGasInitiallyAvailable(final Bytes b) { - if (filled.get(124)) { + if (filled.get(126)) { throw new IllegalStateException("hub.transaction/GAS_INITIALLY_AVAILABLE already set"); } else { - filled.set(124); + filled.set(126); } // Trim array to size @@ -6599,10 +6968,10 @@ public Trace pTransactionGasInitiallyAvailable(final Bytes b) { } public Trace pTransactionGasLeftover(final Bytes b) { - if (filled.get(125)) { + if (filled.get(127)) { throw new IllegalStateException("hub.transaction/GAS_LEFTOVER already set"); } else { - filled.set(125); + filled.set(127); } // Trim array to size @@ -6625,10 +6994,10 @@ public Trace pTransactionGasLeftover(final Bytes b) { } public Trace pTransactionGasLimit(final Bytes b) { - if (filled.get(126)) { + if (filled.get(128)) { throw new IllegalStateException("hub.transaction/GAS_LIMIT already set"); } else { - filled.set(126); + filled.set(128); } // Trim array to size @@ -6650,10 +7019,10 @@ public Trace pTransactionGasLimit(final Bytes b) { } public Trace pTransactionGasPrice(final Bytes b) { - if (filled.get(127)) { + if (filled.get(129)) { throw new IllegalStateException("hub.transaction/GAS_PRICE already set"); } else { - filled.set(127); + filled.set(129); } // Trim array to size @@ -6675,10 +7044,10 @@ public Trace pTransactionGasPrice(final Bytes b) { } public Trace pTransactionInitCodeSize(final long b) { - if (filled.get(106)) { + if (filled.get(108)) { throw new IllegalStateException("hub.transaction/INIT_CODE_SIZE already set"); } else { - filled.set(106); + filled.set(108); } if (b >= 4294967296L) { @@ -6699,10 +7068,10 @@ public Trace pTransactionInitCodeSize(final long b) { } public Trace pTransactionInitialBalance(final Bytes b) { - if (filled.get(134)) { + if (filled.get(136)) { throw new IllegalStateException("hub.transaction/INITIAL_BALANCE already set"); } else { - filled.set(134); + filled.set(136); } // Trim array to size @@ -6735,8 +7104,8 @@ public Trace pTransactionIsDeployment(final Boolean b) { filled.set(46); } - deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment - .put((byte) (b ? 1 : 0)); + againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment.put( + (byte) (b ? 1 : 0)); return this; } @@ -6748,17 +7117,17 @@ public Trace pTransactionIsType2(final Boolean b) { filled.set(47); } - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 + againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2 .put((byte) (b ? 1 : 0)); return this; } public Trace pTransactionNonce(final Bytes b) { - if (filled.get(128)) { + if (filled.get(130)) { throw new IllegalStateException("hub.transaction/NONCE already set"); } else { - filled.set(128); + filled.set(130); } // Trim array to size @@ -6780,10 +7149,10 @@ public Trace pTransactionNonce(final Bytes b) { } public Trace pTransactionPriorityFeePerGas(final Bytes b) { - if (filled.get(129)) { + if (filled.get(131)) { throw new IllegalStateException("hub.transaction/PRIORITY_FEE_PER_GAS already set"); } else { - filled.set(129); + filled.set(131); } // Trim array to size @@ -6806,10 +7175,10 @@ public Trace pTransactionPriorityFeePerGas(final Bytes b) { } public Trace pTransactionRefundCounterInfinity(final Bytes b) { - if (filled.get(130)) { + if (filled.get(132)) { throw new IllegalStateException("hub.transaction/REFUND_COUNTER_INFINITY already set"); } else { - filled.set(130); + filled.set(132); } // Trim array to size @@ -6832,10 +7201,10 @@ public Trace pTransactionRefundCounterInfinity(final Bytes b) { } public Trace pTransactionRefundEffective(final Bytes b) { - if (filled.get(131)) { + if (filled.get(133)) { throw new IllegalStateException("hub.transaction/REFUND_EFFECTIVE already set"); } else { - filled.set(131); + filled.set(133); } // Trim array to size @@ -6864,7 +7233,7 @@ public Trace pTransactionRequiresEvmExecution(final Boolean b) { filled.set(48); } - existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution + deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution .put((byte) (b ? 1 : 0)); return this; @@ -6877,17 +7246,17 @@ public Trace pTransactionStatusCode(final Boolean b) { filled.set(49); } - existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode.put( + deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode.put( (byte) (b ? 1 : 0)); return this; } public Trace pTransactionToAddressHi(final long b) { - if (filled.get(107)) { + if (filled.get(109)) { throw new IllegalStateException("hub.transaction/TO_ADDRESS_HI already set"); } else { - filled.set(107); + filled.set(109); } if (b >= 4294967296L) { @@ -6908,10 +7277,10 @@ public Trace pTransactionToAddressHi(final long b) { } public Trace pTransactionToAddressLo(final Bytes b) { - if (filled.get(135)) { + if (filled.get(137)) { throw new IllegalStateException("hub.transaction/TO_ADDRESS_LO already set"); } else { - filled.set(135); + filled.set(137); } // Trim array to size @@ -6936,10 +7305,10 @@ public Trace pTransactionToAddressLo(final Bytes b) { } public Trace pTransactionValue(final Bytes b) { - if (filled.get(136)) { + if (filled.get(138)) { throw new IllegalStateException("hub.transaction/VALUE already set"); } else { - filled.set(136); + filled.set(138); } // Trim array to size @@ -7230,35 +7599,50 @@ public Trace validateRow() { throw new IllegalStateException("hub.ABSOLUTE_TRANSACTION_NUMBER has not been filled"); } - if (!filled.get(103)) { + if (!filled.get(105)) { throw new IllegalStateException( "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_CALL_DATA_SIZE has not been filled"); } - if (!filled.get(132)) { + if (!filled.get(134)) { throw new IllegalStateException( "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO has not been filled"); } + if (!filled.get(45)) { + throw new IllegalStateException( + "hub.AGAIN_IN_BLK_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_WILL_REVERT_xor_ACC_FLAG_xor_AGAIN_IN_BLK_xor_COPY_TXCD has not been filled"); + } + + if (!filled.get(46)) { + throw new IllegalStateException( + "hub.AGAIN_IN_CNF_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_ABORT_WONT_REVERT_xor_ADD_FLAG_xor_AGAIN_IN_CNF_xor_IS_DEPLOYMENT has not been filled"); + } + + if (!filled.get(47)) { + throw new IllegalStateException( + "hub.AGAIN_IN_TXN_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_BIN_FLAG_xor_AGAIN_IN_TXN_xor_IS_TYPE2 has not been filled"); + } + if (!filled.get(94)) { throw new IllegalStateException("hub.ALPHA has not been filled"); } - if (!filled.get(134)) { + if (!filled.get(136)) { throw new IllegalStateException( "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE has not been filled"); } - if (!filled.get(133)) { + if (!filled.get(135)) { throw new IllegalStateException( "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO has not been filled"); } - if (!filled.get(111)) { + if (!filled.get(113)) { throw new IllegalStateException("hub.CALL_DATA_OFFSET_xor_MMU_SIZE has not been filled"); } - if (!filled.get(112)) { + if (!filled.get(114)) { throw new IllegalStateException("hub.CALL_DATA_SIZE_xor_MMU_SRC_ID has not been filled"); } @@ -7275,37 +7659,37 @@ public Trace validateRow() { throw new IllegalStateException("hub.CODE_FRAGMENT_INDEX has not been filled"); } - if (!filled.get(104)) { + if (!filled.get(106)) { throw new IllegalStateException( "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_COINBASE_ADDRESS_HI has not been filled"); } - if (!filled.get(136)) { + if (!filled.get(138)) { throw new IllegalStateException( "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_STACK_ITEM_VALUE_HI_1_xor_VALUE_CURR_LO_xor_VALUE has not been filled"); } - if (!filled.get(135)) { + if (!filled.get(137)) { throw new IllegalStateException( "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO has not been filled"); } - if (!filled.get(138)) { + if (!filled.get(140)) { throw new IllegalStateException( "hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_STACK_ITEM_VALUE_HI_3_xor_VALUE_NEXT_LO has not been filled"); } - if (!filled.get(137)) { + if (!filled.get(139)) { throw new IllegalStateException( "hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_STACK_ITEM_VALUE_HI_2_xor_VALUE_NEXT_HI has not been filled"); } - if (!filled.get(106)) { + if (!filled.get(108)) { throw new IllegalStateException( "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_INIT_CODE_SIZE has not been filled"); } - if (!filled.get(105)) { + if (!filled.get(107)) { throw new IllegalStateException( "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_FROM_ADDRESS_HI has not been filled"); } @@ -7326,7 +7710,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.CONTEXT_NUMBER_NEW has not been filled"); } - if (!filled.get(113)) { + if (!filled.get(115)) { throw new IllegalStateException("hub.CONTEXT_NUMBER_xor_MMU_TGT_ID has not been filled"); } @@ -7350,91 +7734,96 @@ public Trace validateRow() { throw new IllegalStateException("hub.COUNTER_TLI has not been filled"); } - if (!filled.get(60)) { - throw new IllegalStateException( - "hub.CREATE_EXCEPTION_xor_HASH_INFO_FLAG has not been filled"); + if (!filled.get(95)) { + throw new IllegalStateException("hub.DELTA has not been filled"); } - if (!filled.get(61)) { + if (!filled.get(103)) { throw new IllegalStateException( - "hub.CREATE_FAILURE_CONDITION_WILL_REVERT_xor_ICPX has not been filled"); + "hub.DEPLOYMENT_NUMBER_FINAL_IN_BLOCK_xor_DEPLOYMENT_NUMBER_FINAL_IN_BLOCK has not been filled"); } - if (!filled.get(62)) { + if (!filled.get(104)) { throw new IllegalStateException( - "hub.CREATE_FAILURE_CONDITION_WONT_REVERT_xor_INVALID_FLAG has not been filled"); + "hub.DEPLOYMENT_NUMBER_FIRST_IN_BLOCK_xor_DEPLOYMENT_NUMBER_FIRST_IN_BLOCK has not been filled"); } - if (!filled.get(63)) { + if (!filled.get(110)) { throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_JUMPX has not been filled"); + "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO has not been filled"); } - if (!filled.get(64)) { + if (!filled.get(111)) { throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED has not been filled"); + "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); } - if (!filled.get(65)) { + if (!filled.get(109)) { throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_FLAG has not been filled"); + "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_TO_ADDRESS_HI has not been filled"); } - if (!filled.get(66)) { + if (!filled.get(49)) { throw new IllegalStateException( - "hub.CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_KEC_FLAG has not been filled"); + "hub.DEPLOYMENT_STATUS_INFTY_xor_MXP_DEPLOYS_xor_CALL_EXCEPTION_xor_CALL_FLAG_xor_FINAL_IN_CNF_xor_STATUS_CODE has not been filled"); } - if (!filled.get(95)) { - throw new IllegalStateException("hub.DELTA has not been filled"); + if (!filled.get(50)) { + throw new IllegalStateException( + "hub.DEPLOYMENT_STATUS_NEW_xor_MXP_FLAG_xor_CALL_PRC_FAILURE_xor_CON_FLAG_xor_FINAL_IN_TXN has not been filled"); } - if (!filled.get(108)) { + if (!filled.get(48)) { throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO has not been filled"); + "hub.DEPLOYMENT_STATUS_xor_MMU_SUCCESS_BIT_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BTC_FLAG_xor_FINAL_IN_BLK_xor_REQUIRES_EVM_EXECUTION has not been filled"); } - if (!filled.get(109)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); + if (!filled.get(12)) { + throw new IllegalStateException("hub.DOM_STAMP has not been filled"); } - if (!filled.get(107)) { + if (!filled.get(13)) { + throw new IllegalStateException("hub.EXCEPTION_AHOY has not been filled"); + } + + if (!filled.get(52)) { throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_TO_ADDRESS_HI has not been filled"); + "hub.EXISTS_NEW_xor_MXP_MXPX_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_CREATE_FLAG_xor_FIRST_IN_CNF has not been filled"); } - if (!filled.get(46)) { + if (!filled.get(51)) { throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_INFTY_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_ABORT_WONT_REVERT_xor_ADD_FLAG_xor_UNCONSTRAINED_FIRST_xor_IS_DEPLOYMENT has not been filled"); + "hub.EXISTS_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_COPY_FLAG_xor_FIRST_IN_BLK has not been filled"); } - if (!filled.get(47)) { + if (!filled.get(53)) { throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_NEW_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_BIN_FLAG_xor_VALUE_CURR_CHANGES_xor_IS_TYPE2 has not been filled"); + "hub.FINAL_IN_BLK_xor_MXP_SIZE_1_NONZERO_NO_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_DEC_FLAG_1_xor_FIRST_IN_TXN has not been filled"); } - if (!filled.get(45)) { + if (!filled.get(54)) { throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_WILL_REVERT_xor_ACC_FLAG_xor_UNCONSTRAINED_FINAL_xor_COPY_TXCD has not been filled"); + "hub.FINAL_IN_CNF_xor_MXP_SIZE_2_NONZERO_NO_MXPX_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_2_xor_UNCONSTRAINED_FINAL has not been filled"); } - if (!filled.get(12)) { - throw new IllegalStateException("hub.DOM_STAMP has not been filled"); + if (!filled.get(55)) { + throw new IllegalStateException( + "hub.FINAL_IN_TXN_xor_OOB_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_3_xor_UNCONSTRAINED_FIRST has not been filled"); } - if (!filled.get(13)) { - throw new IllegalStateException("hub.EXCEPTION_AHOY has not been filled"); + if (!filled.get(56)) { + throw new IllegalStateException( + "hub.FIRST_IN_BLK_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_4_xor_VALUE_CURR_CHANGES has not been filled"); } - if (!filled.get(49)) { + if (!filled.get(57)) { throw new IllegalStateException( - "hub.EXISTS_NEW_xor_MXP_DEPLOYS_xor_CALL_EXCEPTION_xor_CALL_FLAG_xor_VALUE_CURR_IS_ZERO_xor_STATUS_CODE has not been filled"); + "hub.FIRST_IN_CNF_xor_STP_FLAG_xor_CREATE_ABORT_xor_DUP_FLAG_xor_VALUE_CURR_IS_ORIG has not been filled"); } - if (!filled.get(48)) { + if (!filled.get(58)) { throw new IllegalStateException( - "hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BTC_FLAG_xor_VALUE_CURR_IS_ORIG_xor_REQUIRES_EVM_EXECUTION has not been filled"); + "hub.FIRST_IN_TXN_xor_STP_OOGX_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_EXT_FLAG_xor_VALUE_CURR_IS_ZERO has not been filled"); } if (!filled.get(14)) { @@ -7449,7 +7838,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.GAS_EXPECTED has not been filled"); } - if (!filled.get(126)) { + if (!filled.get(128)) { throw new IllegalStateException("hub.GAS_LIMIT has not been filled"); } @@ -7457,18 +7846,18 @@ public Trace validateRow() { throw new IllegalStateException("hub.GAS_NEXT has not been filled"); } - if (!filled.get(127)) { + if (!filled.get(129)) { throw new IllegalStateException("hub.GAS_PRICE has not been filled"); } - if (!filled.get(51)) { + if (!filled.get(60)) { throw new IllegalStateException( - "hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_COPY_FLAG_xor_VALUE_NEXT_IS_ORIG has not been filled"); + "hub.HAS_CODE_NEW_xor_CREATE_EXCEPTION_xor_HASH_INFO_FLAG_xor_VALUE_NEXT_IS_ORIG has not been filled"); } - if (!filled.get(50)) { + if (!filled.get(59)) { throw new IllegalStateException( - "hub.HAS_CODE_xor_MXP_FLAG_xor_CALL_PRC_FAILURE_xor_CON_FLAG_xor_VALUE_NEXT_IS_CURR has not been filled"); + "hub.HAS_CODE_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_HALT_FLAG_xor_VALUE_NEXT_IS_CURR has not been filled"); } if (!filled.get(18)) { @@ -7487,54 +7876,54 @@ public Trace validateRow() { throw new IllegalStateException("hub.HUB_STAMP_TRANSACTION_END has not been filled"); } - if (!filled.get(165)) { + if (!filled.get(167)) { throw new IllegalStateException("hub.INSTRUCTION has not been filled"); } - if (!filled.get(52)) { + if (!filled.get(61)) { throw new IllegalStateException( - "hub.IS_PRECOMPILE_xor_MXP_MXPX_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_CREATE_FLAG_xor_VALUE_NEXT_IS_ZERO has not been filled"); + "hub.IS_PRECOMPILE_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_ICPX_xor_VALUE_NEXT_IS_ZERO has not been filled"); } if (!filled.get(22)) { throw new IllegalStateException("hub.LOG_INFO_STAMP has not been filled"); } - if (!filled.get(54)) { + if (!filled.get(63)) { throw new IllegalStateException( - "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_MXP_SIZE_2_NONZERO_NO_MXPX_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_2_xor_WARMTH has not been filled"); + "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_JUMPX_xor_WARMTH has not been filled"); } - if (!filled.get(53)) { + if (!filled.get(62)) { throw new IllegalStateException( - "hub.MARKED_FOR_SELFDESTRUCT_xor_MXP_SIZE_1_NONZERO_NO_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_DEC_FLAG_1_xor_VALUE_ORIG_IS_ZERO has not been filled"); + "hub.MARKED_FOR_SELFDESTRUCT_xor_CREATE_FAILURE_CONDITION_WONT_REVERT_xor_INVALID_FLAG_xor_VALUE_ORIG_IS_ZERO has not been filled"); } if (!filled.get(23)) { throw new IllegalStateException("hub.MMU_STAMP has not been filled"); } - if (!filled.get(145)) { + if (!filled.get(147)) { throw new IllegalStateException("hub.MXP_OFFSET_2_HI has not been filled"); } - if (!filled.get(146)) { + if (!filled.get(148)) { throw new IllegalStateException("hub.MXP_OFFSET_2_LO has not been filled"); } - if (!filled.get(147)) { + if (!filled.get(149)) { throw new IllegalStateException("hub.MXP_SIZE_1_HI has not been filled"); } - if (!filled.get(148)) { + if (!filled.get(150)) { throw new IllegalStateException("hub.MXP_SIZE_1_LO has not been filled"); } - if (!filled.get(149)) { + if (!filled.get(151)) { throw new IllegalStateException("hub.MXP_SIZE_2_HI has not been filled"); } - if (!filled.get(150)) { + if (!filled.get(152)) { throw new IllegalStateException("hub.MXP_SIZE_2_LO has not been filled"); } @@ -7542,7 +7931,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.MXP_STAMP has not been filled"); } - if (!filled.get(151)) { + if (!filled.get(153)) { throw new IllegalStateException("hub.MXP_WORDS has not been filled"); } @@ -7558,52 +7947,52 @@ public Trace validateRow() { throw new IllegalStateException("hub.NON_STACK_ROWS has not been filled"); } - if (!filled.get(128)) { + if (!filled.get(130)) { throw new IllegalStateException("hub.NONCE has not been filled"); } - if (!filled.get(124)) { + if (!filled.get(126)) { throw new IllegalStateException( "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE has not been filled"); } - if (!filled.get(123)) { + if (!filled.get(125)) { throw new IllegalStateException("hub.NONCE_xor_STP_GAS_MXP_xor_BASEFEE has not been filled"); } - if (!filled.get(152)) { + if (!filled.get(154)) { throw new IllegalStateException("hub.OOB_DATA_1 has not been filled"); } - if (!filled.get(153)) { + if (!filled.get(155)) { throw new IllegalStateException("hub.OOB_DATA_2 has not been filled"); } - if (!filled.get(154)) { + if (!filled.get(156)) { throw new IllegalStateException("hub.OOB_DATA_3 has not been filled"); } - if (!filled.get(155)) { + if (!filled.get(157)) { throw new IllegalStateException("hub.OOB_DATA_4 has not been filled"); } - if (!filled.get(156)) { + if (!filled.get(158)) { throw new IllegalStateException("hub.OOB_DATA_5 has not been filled"); } - if (!filled.get(157)) { + if (!filled.get(159)) { throw new IllegalStateException("hub.OOB_DATA_6 has not been filled"); } - if (!filled.get(158)) { + if (!filled.get(160)) { throw new IllegalStateException("hub.OOB_DATA_7 has not been filled"); } - if (!filled.get(159)) { + if (!filled.get(161)) { throw new IllegalStateException("hub.OOB_DATA_8 has not been filled"); } - if (!filled.get(160)) { + if (!filled.get(162)) { throw new IllegalStateException("hub.OOB_DATA_9 has not been filled"); } @@ -7635,14 +8024,6 @@ public Trace validateRow() { throw new IllegalStateException("hub.PEEK_AT_TRANSACTION has not been filled"); } - if (!filled.get(67)) { - throw new IllegalStateException("hub.PRC_BLAKE2f_xor_LOG_FLAG has not been filled"); - } - - if (!filled.get(68)) { - throw new IllegalStateException("hub.PRC_ECADD_xor_LOG_INFO_FLAG has not been filled"); - } - if (!filled.get(69)) { throw new IllegalStateException("hub.PRC_ECMUL_xor_MACHINE_STATE_FLAG has not been filled"); } @@ -7690,7 +8071,7 @@ public Trace validateRow() { "hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_SHF_FLAG has not been filled"); } - if (!filled.get(129)) { + if (!filled.get(131)) { throw new IllegalStateException("hub.PRIORITY_FEE_PER_GAS has not been filled"); } @@ -7706,7 +8087,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.REFUND_COUNTER has not been filled"); } - if (!filled.get(130)) { + if (!filled.get(132)) { throw new IllegalStateException("hub.REFUND_COUNTER_INFINITY has not been filled"); } @@ -7714,7 +8095,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.REFUND_COUNTER_NEW has not been filled"); } - if (!filled.get(131)) { + if (!filled.get(133)) { throw new IllegalStateException("hub.REFUND_EFFECTIVE has not been filled"); } @@ -7722,25 +8103,25 @@ public Trace validateRow() { throw new IllegalStateException("hub.RELATIVE_BLOCK_NUMBER has not been filled"); } - if (!filled.get(114)) { + if (!filled.get(116)) { throw new IllegalStateException("hub.RETURN_AT_CAPACITY_xor_MXP_INST has not been filled"); } - if (!filled.get(115)) { + if (!filled.get(117)) { throw new IllegalStateException("hub.RETURN_AT_OFFSET_xor_OOB_INST has not been filled"); } - if (!filled.get(116)) { + if (!filled.get(118)) { throw new IllegalStateException( "hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND has not been filled"); } - if (!filled.get(117)) { + if (!filled.get(119)) { throw new IllegalStateException( "hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION has not been filled"); } - if (!filled.get(118)) { + if (!filled.get(120)) { throw new IllegalStateException("hub.RETURN_DATA_SIZE has not been filled"); } @@ -7778,27 +8159,27 @@ public Trace validateRow() { "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_4 has not been filled"); } - if (!filled.get(110)) { + if (!filled.get(112)) { throw new IllegalStateException( "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE has not been filled"); } - if (!filled.get(139)) { + if (!filled.get(141)) { throw new IllegalStateException( "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_STACK_ITEM_VALUE_HI_4_xor_VALUE_ORIG_HI has not been filled"); } - if (!filled.get(55)) { + if (!filled.get(64)) { throw new IllegalStateException( - "hub.RLPADDR_FLAG_xor_OOB_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_3_xor_WARMTH_NEW has not been filled"); + "hub.RLPADDR_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED_xor_WARMTH_NEW has not been filled"); } - if (!filled.get(140)) { + if (!filled.get(142)) { throw new IllegalStateException( "hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_STACK_ITEM_VALUE_LO_1_xor_VALUE_ORIG_LO has not been filled"); } - if (!filled.get(141)) { + if (!filled.get(143)) { throw new IllegalStateException( "hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO_xor_STACK_ITEM_VALUE_LO_2 has not been filled"); } @@ -7807,19 +8188,19 @@ public Trace validateRow() { throw new IllegalStateException("hub.RLPADDR_RECIPE has not been filled"); } - if (!filled.get(142)) { + if (!filled.get(144)) { throw new IllegalStateException( "hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP_xor_STACK_ITEM_VALUE_LO_3 has not been filled"); } - if (!filled.get(143)) { + if (!filled.get(145)) { throw new IllegalStateException( "hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI_xor_STACK_ITEM_VALUE_LO_4 has not been filled"); } - if (!filled.get(56)) { + if (!filled.get(65)) { throw new IllegalStateException( - "hub.ROMLEX_FLAG_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_4 has not been filled"); + "hub.ROMLEX_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_FLAG has not been filled"); } if (!filled.get(87)) { @@ -7853,40 +8234,40 @@ public Trace validateRow() { throw new IllegalStateException("hub.STACK_ITEM_HEIGHT_4 has not been filled"); } - if (!filled.get(119)) { + if (!filled.get(121)) { throw new IllegalStateException("hub.STACK_ITEM_STAMP_1 has not been filled"); } - if (!filled.get(120)) { + if (!filled.get(122)) { throw new IllegalStateException("hub.STACK_ITEM_STAMP_2 has not been filled"); } - if (!filled.get(121)) { + if (!filled.get(123)) { throw new IllegalStateException("hub.STACK_ITEM_STAMP_3 has not been filled"); } - if (!filled.get(122)) { + if (!filled.get(124)) { throw new IllegalStateException("hub.STACK_ITEM_STAMP_4 has not been filled"); } - if (!filled.get(161)) { + if (!filled.get(163)) { throw new IllegalStateException("hub.STP_GAS_HI has not been filled"); } - if (!filled.get(162)) { + if (!filled.get(164)) { throw new IllegalStateException("hub.STP_GAS_LO has not been filled"); } - if (!filled.get(125)) { + if (!filled.get(127)) { throw new IllegalStateException( "hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER has not been filled"); } - if (!filled.get(163)) { + if (!filled.get(165)) { throw new IllegalStateException("hub.STP_VALUE_HI has not been filled"); } - if (!filled.get(164)) { + if (!filled.get(166)) { throw new IllegalStateException("hub.STP_VALUE_LO has not been filled"); } @@ -7898,12 +8279,12 @@ public Trace validateRow() { throw new IllegalStateException("hub.SWAP_FLAG has not been filled"); } - if (!filled.get(57)) { + if (!filled.get(66)) { throw new IllegalStateException( - "hub.TRM_FLAG_xor_STP_FLAG_xor_CREATE_ABORT_xor_DUP_FLAG has not been filled"); + "hub.TRM_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_KEC_FLAG has not been filled"); } - if (!filled.get(144)) { + if (!filled.get(146)) { throw new IllegalStateException( "hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO has not been filled"); } @@ -7936,14 +8317,14 @@ public Trace validateRow() { throw new IllegalStateException("hub.TXN_FLAG has not been filled"); } - if (!filled.get(59)) { + if (!filled.get(68)) { throw new IllegalStateException( - "hub.WARMTH_NEW_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_HALT_FLAG has not been filled"); + "hub.WARMTH_NEW_xor_PRC_ECADD_xor_LOG_INFO_FLAG has not been filled"); } - if (!filled.get(58)) { + if (!filled.get(67)) { throw new IllegalStateException( - "hub.WARMTH_xor_STP_OOGX_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_EXT_FLAG has not been filled"); + "hub.WARMTH_xor_PRC_BLAKE2f_xor_LOG_FLAG has not been filled"); } if (!filled.get(93)) { @@ -7961,7 +8342,7 @@ public Trace fillAndValidateRow() { absoluteTransactionNumber.position(absoluteTransactionNumber.position() + 2); } - if (!filled.get(103)) { + if (!filled.get(105)) { addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize .position( addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize @@ -7969,7 +8350,7 @@ public Trace fillAndValidateRow() { + 4); } - if (!filled.get(132)) { + if (!filled.get(134)) { addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo .position( addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo @@ -7977,11 +8358,35 @@ public Trace fillAndValidateRow() { + 16); } + if (!filled.get(45)) { + againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd + .position( + againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd + .position() + + 1); + } + + if (!filled.get(46)) { + againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment + .position( + againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment + .position() + + 1); + } + + if (!filled.get(47)) { + againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2 + .position( + againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2 + .position() + + 1); + } + if (!filled.get(94)) { alpha.position(alpha.position() + 1); } - if (!filled.get(134)) { + if (!filled.get(136)) { balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance .position( balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance @@ -7989,7 +8394,7 @@ public Trace fillAndValidateRow() { + 16); } - if (!filled.get(133)) { + if (!filled.get(135)) { balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo .position( balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo @@ -7997,11 +8402,11 @@ public Trace fillAndValidateRow() { + 16); } - if (!filled.get(111)) { + if (!filled.get(113)) { callDataOffsetXorMmuSize.position(callDataOffsetXorMmuSize.position() + 4); } - if (!filled.get(112)) { + if (!filled.get(114)) { callDataSizeXorMmuSrcId.position(callDataSizeXorMmuSrcId.position() + 4); } @@ -8017,7 +8422,7 @@ public Trace fillAndValidateRow() { codeFragmentIndex.position(codeFragmentIndex.position() + 4); } - if (!filled.get(104)) { + if (!filled.get(106)) { codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi .position( codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi @@ -8025,34 +8430,34 @@ public Trace fillAndValidateRow() { + 4); } - if (!filled.get(136)) { + if (!filled.get(138)) { codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.position( codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.position() + 16); } - if (!filled.get(135)) { + if (!filled.get(137)) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position( codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() + 16); } - if (!filled.get(138)) { + if (!filled.get(140)) { codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.position( codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.position() + 16); } - if (!filled.get(137)) { + if (!filled.get(139)) { codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.position( codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.position() + 16); } - if (!filled.get(106)) { + if (!filled.get(108)) { codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.position( codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.position() + 4); } - if (!filled.get(105)) { + if (!filled.get(107)) { codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi .position( codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi @@ -8076,7 +8481,7 @@ public Trace fillAndValidateRow() { contextNumberNew.position(contextNumberNew.position() + 4); } - if (!filled.get(113)) { + if (!filled.get(115)) { contextNumberXorMmuTgtId.position(contextNumberXorMmuTgtId.position() + 4); } @@ -8100,80 +8505,53 @@ public Trace fillAndValidateRow() { counterTli.position(counterTli.position() + 1); } - if (!filled.get(60)) { - createExceptionXorHashInfoFlag.position(createExceptionXorHashInfoFlag.position() + 1); - } - - if (!filled.get(61)) { - createFailureConditionWillRevertXorIcpx.position( - createFailureConditionWillRevertXorIcpx.position() + 1); - } - - if (!filled.get(62)) { - createFailureConditionWontRevertXorInvalidFlag.position( - createFailureConditionWontRevertXorInvalidFlag.position() + 1); - } - - if (!filled.get(63)) { - createNonemptyInitCodeFailureWillRevertXorJumpx.position( - createNonemptyInitCodeFailureWillRevertXorJumpx.position() + 1); - } - - if (!filled.get(64)) { - createNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequired.position( - createNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequired.position() + 1); - } - - if (!filled.get(65)) { - createNonemptyInitCodeSuccessWillRevertXorJumpFlag.position( - createNonemptyInitCodeSuccessWillRevertXorJumpFlag.position() + 1); + if (!filled.get(95)) { + delta.position(delta.position() + 1); } - if (!filled.get(66)) { - createNonemptyInitCodeSuccessWontRevertXorKecFlag.position( - createNonemptyInitCodeSuccessWontRevertXorKecFlag.position() + 1); + if (!filled.get(103)) { + deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock.position( + deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock.position() + 2); } - if (!filled.get(95)) { - delta.position(delta.position() + 1); + if (!filled.get(104)) { + deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock.position( + deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock.position() + 2); } - if (!filled.get(108)) { + if (!filled.get(110)) { deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.position( deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.position() + 4); } - if (!filled.get(109)) { + if (!filled.get(111)) { deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position( deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 4); } - if (!filled.get(107)) { + if (!filled.get(109)) { deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.position( deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.position() + 4); } - if (!filled.get(46)) { - deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + if (!filled.get(49)) { + deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode .position( - deploymentStatusInftyXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorUnconstrainedFirstXorIsDeployment + deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode .position() + 1); } - if (!filled.get(47)) { - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 - .position( - deploymentStatusNewXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorValueCurrChangesXorIsType2 - .position() - + 1); + if (!filled.get(50)) { + deploymentStatusNewXorMxpFlagXorCallPrcFailureXorConFlagXorFinalInTxn.position( + deploymentStatusNewXorMxpFlagXorCallPrcFailureXorConFlagXorFinalInTxn.position() + 1); } - if (!filled.get(45)) { - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd + if (!filled.get(48)) { + deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution .position( - deploymentStatusXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorUnconstrainedFinalXorCopyTxcd + deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution .position() + 1); } @@ -8186,21 +8564,62 @@ public Trace fillAndValidateRow() { exceptionAhoy.position(exceptionAhoy.position() + 1); } - if (!filled.get(49)) { - existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode.position( - existsNewXorMxpDeploysXorCallExceptionXorCallFlagXorValueCurrIsZeroXorStatusCode - .position() + if (!filled.get(52)) { + existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.position( + existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.position() + 1); } - if (!filled.get(48)) { - existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution + if (!filled.get(51)) { + existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.position( + existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.position() + + 1); + } + + if (!filled.get(53)) { + finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn + .position( + finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn + .position() + + 1); + } + + if (!filled.get(54)) { + finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorUnconstrainedFinal + .position( + finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorUnconstrainedFinal + .position() + + 1); + } + + if (!filled.get(55)) { + finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorUnconstrainedFirst + .position( + finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorUnconstrainedFirst + .position() + + 1); + } + + if (!filled.get(56)) { + firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrChanges .position( - existsXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorValueCurrIsOrigXorRequiresEvmExecution + firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrChanges .position() + 1); } + if (!filled.get(57)) { + firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueCurrIsOrig.position( + firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueCurrIsOrig.position() + 1); + } + + if (!filled.get(58)) { + firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueCurrIsZero.position( + firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueCurrIsZero + .position() + + 1); + } + if (!filled.get(14)) { gasActual.position(gasActual.position() + 8); } @@ -8213,7 +8632,7 @@ public Trace fillAndValidateRow() { gasExpected.position(gasExpected.position() + 8); } - if (!filled.get(126)) { + if (!filled.get(128)) { gasLimit.position(gasLimit.position() + 8); } @@ -8221,20 +8640,20 @@ public Trace fillAndValidateRow() { gasNext.position(gasNext.position() + 8); } - if (!filled.get(127)) { + if (!filled.get(129)) { gasPrice.position(gasPrice.position() + 8); } - if (!filled.get(51)) { - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig.position( - hasCodeNewXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorValueNextIsOrig - .position() - + 1); + if (!filled.get(60)) { + hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueNextIsOrig.position( + hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueNextIsOrig.position() + 1); } - if (!filled.get(50)) { - hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr.position( - hasCodeXorMxpFlagXorCallPrcFailureXorConFlagXorValueNextIsCurr.position() + 1); + if (!filled.get(59)) { + hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsCurr.position( + hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsCurr + .position() + + 1); } if (!filled.get(18)) { @@ -8253,34 +8672,30 @@ public Trace fillAndValidateRow() { hubStampTransactionEnd.position(hubStampTransactionEnd.position() + 4); } - if (!filled.get(165)) { + if (!filled.get(167)) { instruction.position(instruction.position() + 32); } - if (!filled.get(52)) { - isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero - .position( - isPrecompileXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorValueNextIsZero - .position() - + 1); + if (!filled.get(61)) { + isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorValueNextIsZero.position( + isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorValueNextIsZero.position() + 1); } if (!filled.get(22)) { logInfoStamp.position(logInfoStamp.position() + 4); } - if (!filled.get(54)) { - markedForSelfdestructNewXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth - .position( - markedForSelfdestructNewXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorWarmth - .position() - + 1); + if (!filled.get(63)) { + markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpxXorWarmth.position( + markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpxXorWarmth + .position() + + 1); } - if (!filled.get(53)) { - markedForSelfdestructXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero + if (!filled.get(62)) { + markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorValueOrigIsZero .position( - markedForSelfdestructXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorValueOrigIsZero + markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorValueOrigIsZero .position() + 1); } @@ -8289,27 +8704,27 @@ public Trace fillAndValidateRow() { mmuStamp.position(mmuStamp.position() + 4); } - if (!filled.get(145)) { + if (!filled.get(147)) { mxpOffset2Hi.position(mxpOffset2Hi.position() + 16); } - if (!filled.get(146)) { + if (!filled.get(148)) { mxpOffset2Lo.position(mxpOffset2Lo.position() + 16); } - if (!filled.get(147)) { + if (!filled.get(149)) { mxpSize1Hi.position(mxpSize1Hi.position() + 16); } - if (!filled.get(148)) { + if (!filled.get(150)) { mxpSize1Lo.position(mxpSize1Lo.position() + 16); } - if (!filled.get(149)) { + if (!filled.get(151)) { mxpSize2Hi.position(mxpSize2Hi.position() + 16); } - if (!filled.get(150)) { + if (!filled.get(152)) { mxpSize2Lo.position(mxpSize2Lo.position() + 16); } @@ -8317,7 +8732,7 @@ public Trace fillAndValidateRow() { mxpStamp.position(mxpStamp.position() + 4); } - if (!filled.get(151)) { + if (!filled.get(153)) { mxpWords.position(mxpWords.position() + 16); } @@ -8333,52 +8748,52 @@ public Trace fillAndValidateRow() { nonStackRows.position(nonStackRows.position() + 1); } - if (!filled.get(128)) { + if (!filled.get(130)) { nonce.position(nonce.position() + 8); } - if (!filled.get(124)) { + if (!filled.get(126)) { nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position( nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 8); } - if (!filled.get(123)) { + if (!filled.get(125)) { nonceXorStpGasMxpXorBasefee.position(nonceXorStpGasMxpXorBasefee.position() + 8); } - if (!filled.get(152)) { + if (!filled.get(154)) { oobData1.position(oobData1.position() + 16); } - if (!filled.get(153)) { + if (!filled.get(155)) { oobData2.position(oobData2.position() + 16); } - if (!filled.get(154)) { + if (!filled.get(156)) { oobData3.position(oobData3.position() + 16); } - if (!filled.get(155)) { + if (!filled.get(157)) { oobData4.position(oobData4.position() + 16); } - if (!filled.get(156)) { + if (!filled.get(158)) { oobData5.position(oobData5.position() + 16); } - if (!filled.get(157)) { + if (!filled.get(159)) { oobData6.position(oobData6.position() + 16); } - if (!filled.get(158)) { + if (!filled.get(160)) { oobData7.position(oobData7.position() + 16); } - if (!filled.get(159)) { + if (!filled.get(161)) { oobData8.position(oobData8.position() + 16); } - if (!filled.get(160)) { + if (!filled.get(162)) { oobData9.position(oobData9.position() + 16); } @@ -8410,14 +8825,6 @@ public Trace fillAndValidateRow() { peekAtTransaction.position(peekAtTransaction.position() + 1); } - if (!filled.get(67)) { - prcBlake2FXorLogFlag.position(prcBlake2FXorLogFlag.position() + 1); - } - - if (!filled.get(68)) { - prcEcaddXorLogInfoFlag.position(prcEcaddXorLogInfoFlag.position() + 1); - } - if (!filled.get(69)) { prcEcmulXorMachineStateFlag.position(prcEcmulXorMachineStateFlag.position() + 1); } @@ -8463,7 +8870,7 @@ public Trace fillAndValidateRow() { prcSuccessCallerWontRevertXorShfFlag.position() + 1); } - if (!filled.get(129)) { + if (!filled.get(131)) { priorityFeePerGas.position(priorityFeePerGas.position() + 8); } @@ -8479,7 +8886,7 @@ public Trace fillAndValidateRow() { refundCounter.position(refundCounter.position() + 4); } - if (!filled.get(130)) { + if (!filled.get(132)) { refundCounterInfinity.position(refundCounterInfinity.position() + 8); } @@ -8487,7 +8894,7 @@ public Trace fillAndValidateRow() { refundCounterNew.position(refundCounterNew.position() + 4); } - if (!filled.get(131)) { + if (!filled.get(133)) { refundEffective.position(refundEffective.position() + 8); } @@ -8495,24 +8902,24 @@ public Trace fillAndValidateRow() { relativeBlockNumber.position(relativeBlockNumber.position() + 2); } - if (!filled.get(114)) { + if (!filled.get(116)) { returnAtCapacityXorMxpInst.position(returnAtCapacityXorMxpInst.position() + 4); } - if (!filled.get(115)) { + if (!filled.get(117)) { returnAtOffsetXorOobInst.position(returnAtOffsetXorOobInst.position() + 4); } - if (!filled.get(116)) { + if (!filled.get(118)) { returnDataContextNumberXorStpGasStipend.position( returnDataContextNumberXorStpGasStipend.position() + 4); } - if (!filled.get(117)) { + if (!filled.get(119)) { returnDataOffsetXorStpInstruction.position(returnDataOffsetXorStpInstruction.position() + 4); } - if (!filled.get(118)) { + if (!filled.get(120)) { returnDataSize.position(returnDataSize.position() + 4); } @@ -8550,28 +8957,30 @@ public Trace fillAndValidateRow() { returnFromMessageCallWontTouchRamXorStackItemPop4.position() + 1); } - if (!filled.get(110)) { + if (!filled.get(112)) { rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position( rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 4); } - if (!filled.get(139)) { + if (!filled.get(141)) { rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.position( rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.position() + 16); } - if (!filled.get(55)) { - rlpaddrFlagXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew.position( - rlpaddrFlagXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorWarmthNew.position() - + 1); + if (!filled.get(64)) { + rlpaddrFlagXorCreateNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequiredXorWarmthNew + .position( + rlpaddrFlagXorCreateNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequiredXorWarmthNew + .position() + + 1); } - if (!filled.get(140)) { + if (!filled.get(142)) { rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.position( rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.position() + 16); } - if (!filled.get(141)) { + if (!filled.get(143)) { rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2.position( rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2.position() + 16); } @@ -8580,19 +8989,19 @@ public Trace fillAndValidateRow() { rlpaddrRecipe.position(rlpaddrRecipe.position() + 1); } - if (!filled.get(142)) { + if (!filled.get(144)) { rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3.position( rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3.position() + 16); } - if (!filled.get(143)) { + if (!filled.get(145)) { rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4.position( rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4.position() + 16); } - if (!filled.get(56)) { - romlexFlagXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4.position( - romlexFlagXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4.position() + 1); + if (!filled.get(65)) { + romlexFlagXorCreateNonemptyInitCodeSuccessWillRevertXorJumpFlag.position( + romlexFlagXorCreateNonemptyInitCodeSuccessWillRevertXorJumpFlag.position() + 1); } if (!filled.get(87)) { @@ -8626,40 +9035,40 @@ public Trace fillAndValidateRow() { stackItemHeight4.position(stackItemHeight4.position() + 2); } - if (!filled.get(119)) { + if (!filled.get(121)) { stackItemStamp1.position(stackItemStamp1.position() + 5); } - if (!filled.get(120)) { + if (!filled.get(122)) { stackItemStamp2.position(stackItemStamp2.position() + 5); } - if (!filled.get(121)) { + if (!filled.get(123)) { stackItemStamp3.position(stackItemStamp3.position() + 5); } - if (!filled.get(122)) { + if (!filled.get(124)) { stackItemStamp4.position(stackItemStamp4.position() + 5); } - if (!filled.get(161)) { + if (!filled.get(163)) { stpGasHi.position(stpGasHi.position() + 16); } - if (!filled.get(162)) { + if (!filled.get(164)) { stpGasLo.position(stpGasLo.position() + 16); } - if (!filled.get(125)) { + if (!filled.get(127)) { stpGasUpfrontGasCostXorGasLeftover.position( stpGasUpfrontGasCostXorGasLeftover.position() + 8); } - if (!filled.get(163)) { + if (!filled.get(165)) { stpValueHi.position(stpValueHi.position() + 16); } - if (!filled.get(164)) { + if (!filled.get(166)) { stpValueLo.position(stpValueLo.position() + 16); } @@ -8671,12 +9080,12 @@ public Trace fillAndValidateRow() { swapFlag.position(swapFlag.position() + 1); } - if (!filled.get(57)) { - trmFlagXorStpFlagXorCreateAbortXorDupFlag.position( - trmFlagXorStpFlagXorCreateAbortXorDupFlag.position() + 1); + if (!filled.get(66)) { + trmFlagXorCreateNonemptyInitCodeSuccessWontRevertXorKecFlag.position( + trmFlagXorCreateNonemptyInitCodeSuccessWontRevertXorKecFlag.position() + 1); } - if (!filled.get(144)) { + if (!filled.get(146)) { trmRawAddressHiXorMxpOffset1Lo.position(trmRawAddressHiXorMxpOffset1Lo.position() + 16); } @@ -8708,14 +9117,13 @@ public Trace fillAndValidateRow() { txnFlag.position(txnFlag.position() + 1); } - if (!filled.get(59)) { - warmthNewXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlag.position( - warmthNewXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlag.position() + 1); + if (!filled.get(68)) { + warmthNewXorPrcEcaddXorLogInfoFlag.position( + warmthNewXorPrcEcaddXorLogInfoFlag.position() + 1); } - if (!filled.get(58)) { - warmthXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlag.position( - warmthXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlag.position() + 1); + if (!filled.get(67)) { + warmthXorPrcBlake2FXorLogFlag.position(warmthXorPrcBlake2FXorLogFlag.position() + 1); } if (!filled.get(93)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java index 21c081d39a..d7601ec399 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/account/AccountFragment.java @@ -138,15 +138,20 @@ public Trace trace(Trace trace) { rlpAddrSubFragment.trace(trace); } - Map> transactionAccountMap = transactionProcessingMetadata.getAccountFirstAndLastMap(); + Map> + transactionAccountMap = transactionProcessingMetadata.getAccountFirstAndLastMap(); StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); - Map> accountFirstLastBlockMap = - stateManagerMetadata.getAccountFirstLastBlockMap(); - StateManagerMetadata.AddrBlockPair current = new StateManagerMetadata.AddrBlockPair(oldState.address(), transactionProcessingMetadata.getRelativeBlockNumber()); + Map< + StateManagerMetadata.AddrBlockPair, + TransactionProcessingMetadata.FragmentFirstAndLast> + accountFirstLastBlockMap = stateManagerMetadata.getAccountFirstLastBlockMap(); + StateManagerMetadata.AddrBlockPair current = + new StateManagerMetadata.AddrBlockPair( + oldState.address(), transactionProcessingMetadata.getRelativeBlockNumber()); - Map> accountFirstLastConflationMap = - stateManagerMetadata.getAccountFirstLastConflationMap(); + Map> + accountFirstLastConflationMap = stateManagerMetadata.getAccountFirstLastConflationMap(); long minDeploymentNumberInBlock = stateManagerMetadata.getMinDeplNoBlock().get(current); long maxDeploymentNumberInBlock = stateManagerMetadata.getMaxDeplNoBlock().get(current); @@ -196,12 +201,13 @@ public Trace trace(Trace trace) { .pAccountFirstInBlk(this == accountFirstLastBlockMap.get(current).getFirst()) .pAccountAgainInBlk(this != accountFirstLastBlockMap.get(current).getFirst()) .pAccountFinalInBlk(this == accountFirstLastBlockMap.get(current).getLast()) - .pAccountFirstInCnf(this == accountFirstLastConflationMap.get(oldState.address()).getFirst()) - .pAccountAgainInCnf(this != accountFirstLastConflationMap.get(oldState.address()).getFirst()) + .pAccountFirstInCnf( + this == accountFirstLastConflationMap.get(oldState.address()).getFirst()) + .pAccountAgainInCnf( + this != accountFirstLastConflationMap.get(oldState.address()).getFirst()) .pAccountFinalInCnf(this == accountFirstLastConflationMap.get(oldState.address()).getLast()) .pAccountDeploymentNumberFirstInBlock(minDeploymentNumberInBlock) - .pAccountDeploymentNumberFinalInBlock(maxDeploymentNumberInBlock) - ; + .pAccountDeploymentNumberFinalInBlock(maxDeploymentNumberInBlock); } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index 8f3cb60ee4..ae0a66ede4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -29,7 +29,6 @@ import net.consensys.linea.zktracer.module.hub.Trace; import net.consensys.linea.zktracer.module.hub.fragment.DomSubStampsSubFragment; import net.consensys.linea.zktracer.module.hub.fragment.TraceFragment; -import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; @@ -74,21 +73,35 @@ public Trace trace(Trace trace) { // tracing domSubStampsSubFragment.trace(trace); - Map> + Map< + TransactionProcessingMetadata.AddrStorageKeyPair, + TransactionProcessingMetadata.FragmentFirstAndLast> storageFirstAndLastMap = transactionProcessingMetadata.getStorageFirstAndLastMap(); - TransactionProcessingMetadata.AddrStorageKeyPair currentAddressKeyPair = new TransactionProcessingMetadata.AddrStorageKeyPair(storageSlotIdentifier.getAddress(), storageSlotIdentifier.getStorageKey()); + TransactionProcessingMetadata.AddrStorageKeyPair currentAddressKeyPair = + new TransactionProcessingMetadata.AddrStorageKeyPair( + storageSlotIdentifier.getAddress(), storageSlotIdentifier.getStorageKey()); StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); - Map> - storageFirstLastBlockMap = stateManagerMetadata.getStorageFirstLastBlockMap(); - StateManagerMetadata.AddrStorageKeyBlockNumTuple storageKeyBlockNumTuple = new StateManagerMetadata.AddrStorageKeyBlockNumTuple(currentAddressKeyPair, this.blockNumber); - - TransactionProcessingMetadata.FragmentFirstAndLast storageFirstLastConflationPair = stateManagerMetadata.getStorageFirstLastConflationMap().get(currentAddressKeyPair); - - StateManagerMetadata.AddrBlockPair addressBlockPair = new StateManagerMetadata.AddrBlockPair(storageSlotIdentifier.getAddress(), transactionProcessingMetadata.getRelativeBlockNumber()); - long minDeploymentNumberInBlock = stateManagerMetadata.getMinDeplNoBlock().get(addressBlockPair); - long maxDeploymentNumberInBlock = stateManagerMetadata.getMaxDeplNoBlock().get(addressBlockPair); + storageFirstLastBlockMap = stateManagerMetadata.getStorageFirstLastBlockMap(); + StateManagerMetadata.AddrStorageKeyBlockNumTuple storageKeyBlockNumTuple = + new StateManagerMetadata.AddrStorageKeyBlockNumTuple( + currentAddressKeyPair, this.blockNumber); + + TransactionProcessingMetadata.FragmentFirstAndLast + storageFirstLastConflationPair = + stateManagerMetadata.getStorageFirstLastConflationMap().get(currentAddressKeyPair); + + StateManagerMetadata.AddrBlockPair addressBlockPair = + new StateManagerMetadata.AddrBlockPair( + storageSlotIdentifier.getAddress(), + transactionProcessingMetadata.getRelativeBlockNumber()); + long minDeploymentNumberInBlock = + stateManagerMetadata.getMinDeplNoBlock().get(addressBlockPair); + long maxDeploymentNumberInBlock = + stateManagerMetadata.getMaxDeplNoBlock().get(addressBlockPair); return trace .peekAtStorage(true) @@ -116,14 +129,15 @@ public Trace trace(Trace trace) { .pStorageFirstInTxn(this == storageFirstAndLastMap.get(currentAddressKeyPair).getFirst()) .pStorageAgainInTxn(this != storageFirstAndLastMap.get(currentAddressKeyPair).getFirst()) .pStorageFinalInTxn(this == storageFirstAndLastMap.get(currentAddressKeyPair).getLast()) - .pStorageFirstInBlk(this == storageFirstLastBlockMap.get(storageKeyBlockNumTuple).getFirst()) - .pStorageAgainInBlk(this != storageFirstLastBlockMap.get(storageKeyBlockNumTuple).getFirst()) + .pStorageFirstInBlk( + this == storageFirstLastBlockMap.get(storageKeyBlockNumTuple).getFirst()) + .pStorageAgainInBlk( + this != storageFirstLastBlockMap.get(storageKeyBlockNumTuple).getFirst()) .pStorageFinalInBlk(this == storageFirstLastBlockMap.get(storageKeyBlockNumTuple).getLast()) .pStorageFirstInCnf(this == storageFirstLastConflationPair.getFirst()) .pStorageAgainInCnf(this != storageFirstLastConflationPair.getFirst()) .pStorageFinalInCnf(this == storageFirstLastConflationPair.getLast()) .pStorageDeploymentNumberFirstInBlock(minDeploymentNumberInBlock) - .pStorageDeploymentNumberFinalInBlock(maxDeploymentNumberInBlock) - ; + .pStorageDeploymentNumberFinalInBlock(maxDeploymentNumberInBlock); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java index e181672e93..c35b9be0f3 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/transients/StateManagerMetadata.java @@ -20,15 +20,13 @@ import lombok.*; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.TransactionStack; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.hyperledger.besu.datatypes.Address; public class StateManagerMetadata { - @Setter @Getter - Hub hub; + @Setter @Getter Hub hub; @EqualsAndHashCode public static class AddrBlockPair { diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java index c7cc9f5691..d65d426b09 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java @@ -56,129 +56,129 @@ class ExampleMultiBlockTest { @Test void test() { final ToyAccount receiverAccount = - ToyAccount.builder() - .balance(Wei.fromEth(1)) - .nonce(116) - .address(Address.fromHexString("0xdead000000000000000000000000000beef")) - .build(); + ToyAccount.builder() + .balance(Wei.fromEth(1)) + .nonce(116) + .address(Address.fromHexString("0xdead000000000000000000000000000beef")) + .build(); final KeyPair senderKeyPair1 = new SECP256K1().generateKeyPair(); final Address senderAddress1 = - Address.extract(Hash.hash(senderKeyPair1.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderKeyPair1.getPublicKey().getEncodedBytes())); final ToyAccount senderAccount1 = - ToyAccount.builder().balance(Wei.fromEth(123)).nonce(5).address(senderAddress1).build(); + ToyAccount.builder().balance(Wei.fromEth(123)).nonce(5).address(senderAddress1).build(); final KeyPair senderKeyPair2 = new SECP256K1().generateKeyPair(); final Address senderAddress2 = - Address.extract(Hash.hash(senderKeyPair2.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderKeyPair2.getPublicKey().getEncodedBytes())); final ToyAccount senderAccount2 = - ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress2).build(); + ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress2).build(); final KeyPair senderKeyPair3 = new SECP256K1().generateKeyPair(); final Address senderAddress3 = - Address.extract(Hash.hash(senderKeyPair3.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderKeyPair3.getPublicKey().getEncodedBytes())); final ToyAccount senderAccount3 = - ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress3).build(); + ToyAccount.builder().balance(Wei.fromEth(1231)).nonce(15).address(senderAddress3).build(); final KeyPair senderKeyPair4 = new SECP256K1().generateKeyPair(); final Address senderAddress4 = - Address.extract(Hash.hash(senderKeyPair4.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderKeyPair4.getPublicKey().getEncodedBytes())); final ToyAccount senderAccount4 = - ToyAccount.builder().balance(Wei.fromEth(11)).nonce(115).address(senderAddress4).build(); + ToyAccount.builder().balance(Wei.fromEth(11)).nonce(115).address(senderAddress4).build(); final KeyPair senderKeyPair5 = new SECP256K1().generateKeyPair(); final Address senderAddress5 = - Address.extract(Hash.hash(senderKeyPair5.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderKeyPair5.getPublicKey().getEncodedBytes())); final ToyAccount senderAccount5 = - ToyAccount.builder().balance(Wei.fromEth(12)).nonce(0).address(senderAddress5).build(); + ToyAccount.builder().balance(Wei.fromEth(12)).nonce(0).address(senderAddress5).build(); final KeyPair senderKeyPair6 = new SECP256K1().generateKeyPair(); final Address senderAddress6 = - Address.extract(Hash.hash(senderKeyPair6.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderKeyPair6.getPublicKey().getEncodedBytes())); final ToyAccount senderAccount6 = - ToyAccount.builder().balance(Wei.fromEth(12)).nonce(6).address(senderAddress6).build(); + ToyAccount.builder().balance(Wei.fromEth(12)).nonce(6).address(senderAddress6).build(); final KeyPair senderKeyPair7 = new SECP256K1().generateKeyPair(); final Address senderAddress7 = - Address.extract(Hash.hash(senderKeyPair7.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderKeyPair7.getPublicKey().getEncodedBytes())); final ToyAccount senderAccount7 = - ToyAccount.builder().balance(Wei.fromEth(231)).nonce(21).address(senderAddress7).build(); + ToyAccount.builder().balance(Wei.fromEth(231)).nonce(21).address(senderAddress7).build(); final Transaction pureTransfer = - ToyTransaction.builder() - .sender(senderAccount1) - .to(receiverAccount) - .keyPair(senderKeyPair1) - .value(Wei.of(123)) - .build(); + ToyTransaction.builder() + .sender(senderAccount1) + .to(receiverAccount) + .keyPair(senderKeyPair1) + .value(Wei.of(123)) + .build(); final Transaction pureTransferWoValue = - ToyTransaction.builder() - .sender(senderAccount2) - .to(receiverAccount) - .keyPair(senderKeyPair2) - .value(Wei.of(0)) - .build(); + ToyTransaction.builder() + .sender(senderAccount2) + .to(receiverAccount) + .keyPair(senderKeyPair2) + .value(Wei.of(0)) + .build(); final List listOfKeys = - List.of("0x0123", "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); + List.of("0x0123", "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"); final List accessList = - List.of( - AccessListEntry.createAccessListEntry( - Address.fromHexString("0x1234567890"), listOfKeys)); + List.of( + AccessListEntry.createAccessListEntry( + Address.fromHexString("0x1234567890"), listOfKeys)); final Transaction pureTransferWithUselessAccessList = - ToyTransaction.builder() - .sender(senderAccount3) - .to(receiverAccount) - .keyPair(senderKeyPair3) - .gasLimit(100000L) - .transactionType(TransactionType.ACCESS_LIST) - .accessList(accessList) - .value(Wei.of(546)) - .build(); + ToyTransaction.builder() + .sender(senderAccount3) + .to(receiverAccount) + .keyPair(senderKeyPair3) + .gasLimit(100000L) + .transactionType(TransactionType.ACCESS_LIST) + .accessList(accessList) + .value(Wei.of(546)) + .build(); final Transaction pureTransferWithUselessCalldata = - ToyTransaction.builder() - .sender(senderAccount4) - .to(receiverAccount) - .keyPair(senderKeyPair4) - .gasLimit(1000001L) - .value(Wei.of(546)) - .payload(Bytes.minimalBytes(0xdeadbeefL)) - .build(); + ToyTransaction.builder() + .sender(senderAccount4) + .to(receiverAccount) + .keyPair(senderKeyPair4) + .gasLimit(1000001L) + .value(Wei.of(546)) + .payload(Bytes.minimalBytes(0xdeadbeefL)) + .build(); final Transaction pureTransferWithUselessCalldataAndAccessList = - ToyTransaction.builder() - .sender(senderAccount5) - .to(receiverAccount) - .gasLimit(1000020L) - .transactionType(TransactionType.EIP1559) - .keyPair(senderKeyPair5) - .value(Wei.of(546)) - .accessList(accessList) - .payload(Bytes.minimalBytes(0xdeadbeefL)) - .build(); + ToyTransaction.builder() + .sender(senderAccount5) + .to(receiverAccount) + .gasLimit(1000020L) + .transactionType(TransactionType.EIP1559) + .keyPair(senderKeyPair5) + .value(Wei.of(546)) + .accessList(accessList) + .payload(Bytes.minimalBytes(0xdeadbeefL)) + .build(); MultiBlockExecutionEnvironment.MultiBlockExecutionEnvironmentBuilder builder = - MultiBlockExecutionEnvironment.builder(); + MultiBlockExecutionEnvironment.builder(); builder - .accounts( - List.of( - senderAccount1, - senderAccount2, - senderAccount3, - senderAccount4, - senderAccount5, - senderAccount6, - senderAccount7, - receiverAccount)) - .addBlock(List.of(pureTransfer)) - .addBlock(List.of(pureTransferWoValue, pureTransferWithUselessAccessList)) - .addBlock( - List.of(pureTransferWithUselessCalldata, pureTransferWithUselessCalldataAndAccessList)) - .build() - .run(); + .accounts( + List.of( + senderAccount1, + senderAccount2, + senderAccount3, + senderAccount4, + senderAccount5, + senderAccount6, + senderAccount7, + receiverAccount)) + .addBlock(List.of(pureTransfer)) + .addBlock(List.of(pureTransferWoValue, pureTransferWithUselessAccessList)) + .addBlock( + List.of(pureTransferWithUselessCalldata, pureTransferWithUselessCalldataAndAccessList)) + .build() + .run(); } @Test @@ -187,29 +187,29 @@ void test2() { Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); ToyAccount senderAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); ToyAccount receiverAccount = - ToyAccount.builder() - .balance(Wei.ONE) - .nonce(6) - .address(Address.fromHexString("0x111111")) - .code( - BytecodeCompiler.newProgram() - .push(32, 0xbeef) - .push(32, 0xdead) - .op(OpCode.ADD) - .compile()) - .build(); + ToyAccount.builder() + .balance(Wei.ONE) + .nonce(6) + .address(Address.fromHexString("0x111111")) + .code( + BytecodeCompiler.newProgram() + .push(32, 0xbeef) + .push(32, 0xdead) + .op(OpCode.ADD) + .compile()) + .build(); Transaction tx = - ToyTransaction.builder().sender(senderAccount).to(receiverAccount).keyPair(keyPair).build(); + ToyTransaction.builder().sender(senderAccount).to(receiverAccount).keyPair(keyPair).build(); MultiBlockExecutionEnvironment.builder() - .accounts(List.of(senderAccount, receiverAccount)) - .addBlock(List.of(tx)) - .build() - .run(); + .accounts(List.of(senderAccount, receiverAccount)) + .addBlock(List.of(tx)) + .build() + .run(); } @Test @@ -218,7 +218,7 @@ void testWithFrameworkEntrypoint() { Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); ToyAccount senderAccount = - ToyAccount.builder().balance(Wei.fromEth(1000)).nonce(5).address(senderAddress).build(); + ToyAccount.builder().balance(Wei.fromEth(1000)).nonce(5).address(senderAddress).build(); ToyAccount frameworkEntrypointAccount = ToyAccount.builder() @@ -236,79 +236,78 @@ void testWithFrameworkEntrypoint() { .code(SmartContractUtils.getSolidityContractRuntimeByteCode(TestSnippet_Events.class)) .build(); - Function snippetFunction = - new Function( - TestSnippet_Events.FUNC_EMITDATANOINDEXES, - List.of(new Uint256(BigInteger.valueOf(123456))), - Collections.emptyList()); + new Function( + TestSnippet_Events.FUNC_EMITDATANOINDEXES, + List.of(new Uint256(BigInteger.valueOf(123456))), + Collections.emptyList()); FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ snippetAccount.getAddress().toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(FunctionEncoder.encode(snippetFunction)) - .toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ BigInteger.ZERO); + new FrameworkEntrypoint.ContractCall( + /*Address*/ snippetAccount.getAddress().toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(FunctionEncoder.encode(snippetFunction)) + .toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ZERO); List contractCalls = List.of(snippetContractCall); Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); Transaction tx = - ToyTransaction.builder() - .sender(senderAccount) - .to(frameworkEntrypointAccount) - .payload(txPayload) - .keyPair(keyPair) - .build(); + ToyTransaction.builder() + .sender(senderAccount) + .to(frameworkEntrypointAccount) + .payload(txPayload) + .keyPair(keyPair) + .build(); Transaction tx2 = - ToyTransaction.builder() - .sender(senderAccount) - .to(frameworkEntrypointAccount) - .payload(txPayload) - .keyPair(keyPair) - .nonce(tx.getNonce() + 1) - .build(); + ToyTransaction.builder() + .sender(senderAccount) + .to(frameworkEntrypointAccount) + .payload(txPayload) + .keyPair(keyPair) + .nonce(tx.getNonce() + 1) + .build(); TransactionProcessingResultValidator resultValidator = - (Transaction transaction, TransactionProcessingResult result) -> { - TransactionProcessingResultValidator.DEFAULT_VALIDATOR.accept(transaction, result); - // One event from the snippet - // One event from the framework entrypoint about contract call - assertEquals(result.getLogs().size(), 2); - for (Log log : result.getLogs()) { - String logTopic = log.getTopics().getFirst().toHexString(); - if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { - TestSnippet_Events.DataNoIndexesEventResponse response = - TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); - assertEquals(response.singleInt, BigInteger.valueOf(123456)); - } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) - .equals(logTopic)) { - FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - assertTrue(response.isSuccess); - assertEquals(response.destination, snippetAccount.getAddress().toHexString()); - } else { - fail(); - } - } - }; + (Transaction transaction, TransactionProcessingResult result) -> { + TransactionProcessingResultValidator.DEFAULT_VALIDATOR.accept(transaction, result); + // One event from the snippet + // One event from the framework entrypoint about contract call + assertEquals(result.getLogs().size(), 2); + for (Log log : result.getLogs()) { + String logTopic = log.getTopics().getFirst().toHexString(); + if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { + TestSnippet_Events.DataNoIndexesEventResponse response = + TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); + assertEquals(response.singleInt, BigInteger.valueOf(123456)); + } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) + .equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + assertEquals(response.destination, snippetAccount.getAddress().toHexString()); + } else { + fail(); + } + } + }; MultiBlockExecutionEnvironment.builder() - .accounts(List.of(senderAccount, frameworkEntrypointAccount, snippetAccount)) - .addBlock(List.of(tx)) - .addBlock(List.of(tx2)) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); + .accounts(List.of(senderAccount, frameworkEntrypointAccount, snippetAccount)) + .addBlock(List.of(tx)) + .addBlock(List.of(tx2)) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); } -} \ No newline at end of file +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java index 46b1835e7e..5f5eedeba0 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleSolidityTest.java @@ -56,7 +56,7 @@ void testWithFrameworkEntrypoint() { Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); ToyAccount senderAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); ToyAccount frameworkEntrypointAccount = ToyAccount.builder() @@ -74,69 +74,68 @@ void testWithFrameworkEntrypoint() { .code(SmartContractUtils.getSolidityContractRuntimeByteCode(TestSnippet_Events.class)) .build(); - Function snippetFunction = - new Function( - TestSnippet_Events.FUNC_EMITDATANOINDEXES, - List.of(new Uint256(BigInteger.valueOf(123456))), - Collections.emptyList()); + new Function( + TestSnippet_Events.FUNC_EMITDATANOINDEXES, + List.of(new Uint256(BigInteger.valueOf(123456))), + Collections.emptyList()); FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ snippetAccount.getAddress().toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(FunctionEncoder.encode(snippetFunction)) - .toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ BigInteger.ZERO); + new FrameworkEntrypoint.ContractCall( + /*Address*/ snippetAccount.getAddress().toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(FunctionEncoder.encode(snippetFunction)) + .toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ZERO); List contractCalls = List.of(snippetContractCall); Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); Transaction tx = - ToyTransaction.builder() - .sender(senderAccount) - .to(frameworkEntrypointAccount) - .payload(txPayload) - .keyPair(keyPair) - .build(); + ToyTransaction.builder() + .sender(senderAccount) + .to(frameworkEntrypointAccount) + .payload(txPayload) + .keyPair(keyPair) + .build(); TransactionProcessingResultValidator resultValidator = - (Transaction transaction, TransactionProcessingResult result) -> { - // One event from the snippet - // One event from the framework entrypoint about contract call - assertEquals(result.getLogs().size(), 2); - for (Log log : result.getLogs()) { - String logTopic = log.getTopics().getFirst().toHexString(); - if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { - TestSnippet_Events.DataNoIndexesEventResponse response = - TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); - assertEquals(response.singleInt, BigInteger.valueOf(123456)); - } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) - .equals(logTopic)) { - FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - assertTrue(response.isSuccess); - assertEquals(response.destination, snippetAccount.getAddress().toHexString()); - } else { - fail(); - } - } - }; + (Transaction transaction, TransactionProcessingResult result) -> { + // One event from the snippet + // One event from the framework entrypoint about contract call + assertEquals(result.getLogs().size(), 2); + for (Log log : result.getLogs()) { + String logTopic = log.getTopics().getFirst().toHexString(); + if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { + TestSnippet_Events.DataNoIndexesEventResponse response = + TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); + assertEquals(response.singleInt, BigInteger.valueOf(123456)); + } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) + .equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + assertEquals(response.destination, snippetAccount.getAddress().toHexString()); + } else { + fail(); + } + } + }; ToyExecutionEnvironmentV2.builder() - .accounts(List.of(senderAccount, frameworkEntrypointAccount, snippetAccount)) - .transaction(tx) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); + .accounts(List.of(senderAccount, frameworkEntrypointAccount, snippetAccount)) + .transaction(tx) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); } @Test @@ -145,7 +144,7 @@ void testSnippetIndependently() { Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); ToyAccount senderAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); ToyAccount contractAccount = ToyAccount.builder() @@ -155,48 +154,47 @@ void testSnippetIndependently() { .code(SmartContractUtils.getSolidityContractRuntimeByteCode(TestSnippet_Events.class)) .build(); - Function function = - new Function( - TestSnippet_Events.FUNC_EMITDATANOINDEXES, - List.of(new Uint256(BigInteger.valueOf(123456))), - Collections.emptyList()); + new Function( + TestSnippet_Events.FUNC_EMITDATANOINDEXES, + List.of(new Uint256(BigInteger.valueOf(123456))), + Collections.emptyList()); String encodedFunction = FunctionEncoder.encode(function); Bytes txPayload = Bytes.fromHexStringLenient(encodedFunction); Transaction tx = - ToyTransaction.builder() - .sender(senderAccount) - .to(contractAccount) - .payload(txPayload) - .keyPair(keyPair) - .build(); + ToyTransaction.builder() + .sender(senderAccount) + .to(contractAccount) + .payload(txPayload) + .keyPair(keyPair) + .build(); TransactionProcessingResultValidator resultValidator = - (Transaction transaction, TransactionProcessingResult result) -> { - assertEquals(result.getLogs().size(), 1); - TestSnippet_Events.DataNoIndexesEventResponse response = - TestSnippet_Events.getDataNoIndexesEventFromLog( - Web3jUtils.fromBesuLog(result.getLogs().getFirst())); - assertEquals(response.singleInt, BigInteger.valueOf(123456)); - }; + (Transaction transaction, TransactionProcessingResult result) -> { + assertEquals(result.getLogs().size(), 1); + TestSnippet_Events.DataNoIndexesEventResponse response = + TestSnippet_Events.getDataNoIndexesEventFromLog( + Web3jUtils.fromBesuLog(result.getLogs().getFirst())); + assertEquals(response.singleInt, BigInteger.valueOf(123456)); + }; ToyExecutionEnvironmentV2.builder() - .accounts(List.of(senderAccount, contractAccount)) - .transaction(tx) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); + .accounts(List.of(senderAccount, contractAccount)) + .transaction(tx) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); } @Test void testContractNotRelatedToTestingFramework() { KeyPair senderkeyPair = new SECP256K1().generateKeyPair(); Address senderAddress = - Address.extract(Hash.hash(senderkeyPair.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderkeyPair.getPublicKey().getEncodedBytes())); ToyAccount senderAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); ToyAccount contractAccount = ToyAccount.builder() @@ -206,37 +204,36 @@ void testContractNotRelatedToTestingFramework() { .code(SmartContractUtils.getSolidityContractRuntimeByteCode(TestStorage.class)) .build(); - Function function = - new Function( - TestStorage.FUNC_STORE, - List.of(new Uint256(BigInteger.valueOf(3))), - Collections.emptyList()); + new Function( + TestStorage.FUNC_STORE, + List.of(new Uint256(BigInteger.valueOf(3))), + Collections.emptyList()); String encodedFunction = FunctionEncoder.encode(function); Bytes txPayload = Bytes.fromHexStringLenient(encodedFunction); Transaction tx = - ToyTransaction.builder() - .sender(senderAccount) - .to(contractAccount) - .payload(txPayload) - .keyPair(senderkeyPair) - .build(); + ToyTransaction.builder() + .sender(senderAccount) + .to(contractAccount) + .payload(txPayload) + .keyPair(senderkeyPair) + .build(); ToyExecutionEnvironmentV2.builder() - .accounts(List.of(senderAccount, contractAccount)) - .transaction(tx) - .build() - .run(); + .accounts(List.of(senderAccount, contractAccount)) + .transaction(tx) + .build() + .run(); } @Test void testYul() { KeyPair senderkeyPair = new SECP256K1().generateKeyPair(); Address senderAddress = - Address.extract(Hash.hash(senderkeyPair.getPublicKey().getEncodedBytes())); + Address.extract(Hash.hash(senderkeyPair.getPublicKey().getEncodedBytes())); ToyAccount senderAccount = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); ToyAccount frameworkEntrypointAccount = ToyAccount.builder() @@ -259,53 +256,53 @@ void testYul() { String encodedContractCall = FunctionEncoder.encode(yulFunction); FrameworkEntrypoint.ContractCall yulContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ yulAccount.getAddress().toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encodedContractCall).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ BigInteger.ZERO); + new FrameworkEntrypoint.ContractCall( + /*Address*/ yulAccount.getAddress().toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encodedContractCall).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ZERO); List contractCalls = List.of(yulContractCall); Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); TransactionProcessingResultValidator resultValidator = - (Transaction transaction, TransactionProcessingResult result) -> { - assertEquals(result.getLogs().size(), 1); - for (Log log : result.getLogs()) { - String logTopic = log.getTopics().getFirst().toHexString(); - if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT).equals(logTopic)) { - FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - assertTrue(response.isSuccess); - assertEquals(response.destination, yulAccount.getAddress().toHexString()); - } else { - fail(); - } - } - }; + (Transaction transaction, TransactionProcessingResult result) -> { + assertEquals(result.getLogs().size(), 1); + for (Log log : result.getLogs()) { + String logTopic = log.getTopics().getFirst().toHexString(); + if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT).equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + assertEquals(response.destination, yulAccount.getAddress().toHexString()); + } else { + fail(); + } + } + }; Transaction tx = - ToyTransaction.builder() - .sender(senderAccount) - .to(frameworkEntrypointAccount) - .payload(txPayload) - .keyPair(senderkeyPair) - .gasLimit(500000L) - .build(); + ToyTransaction.builder() + .sender(senderAccount) + .to(frameworkEntrypointAccount) + .payload(txPayload) + .keyPair(senderkeyPair) + .gasLimit(500000L) + .build(); ToyExecutionEnvironmentV2.builder() - .accounts(List.of(senderAccount, yulAccount, frameworkEntrypointAccount)) - .transaction(tx) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); + .accounts(List.of(senderAccount, yulAccount, frameworkEntrypointAccount)) + .transaction(tx) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); } -} \ No newline at end of file +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerTestValidator.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerTestValidator.java index 8bb2a346d2..34a531b094 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerTestValidator.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerTestValidator.java @@ -1,7 +1,11 @@ package net.consensys.linea.zktracer; -import jakarta.validation.constraints.NotNull; -import lombok.AllArgsConstructor; +import static org.assertj.core.api.Fail.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; + import lombok.NonNull; import lombok.RequiredArgsConstructor; import net.consensys.linea.testing.ToyAccount; @@ -15,59 +19,59 @@ import org.hyperledger.besu.evm.log.Log; import org.web3j.abi.EventEncoder; -import java.util.List; - -import static org.assertj.core.api.Fail.fail; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - @RequiredArgsConstructor public class StateManagerTestValidator implements TransactionProcessingResultValidator { - @NonNull - ToyAccount frameworkEntryPointAccount; - @NonNull - List expectedNoLogs; - int txCounter = 0; - @Override - public void accept(Transaction transaction, TransactionProcessingResult result) { - TransactionProcessingResultValidator.DEFAULT_VALIDATOR.accept(transaction, result); - // One event from the snippet - // One event from the framework entrypoint about contract call - System.out.println("Number of logs: "+result.getLogs().size()); - assertEquals(result.getLogs().size(), expectedNoLogs.get(txCounter)); - for (Log log : result.getLogs()) { - String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); - String writeEventSignature = EventEncoder.encode(StateManagerEvents.WRITE_EVENT); - String readEventSignature = EventEncoder.encode(StateManagerEvents.READ_EVENT); - String destroyedEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); - String createdEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTCREATED_EVENT); - String sentETHEventSignature = EventEncoder.encode(StateManagerEvents.PAYETH_EVENT); - String recETHEventSignature = EventEncoder.encode(StateManagerEvents.RECETH_EVENT); - String logTopic = log.getTopics().getFirst().toHexString(); - if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { - TestSnippet_Events.DataNoIndexesEventResponse response = - TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); - //assertEquals(response.singleInt, BigInteger.valueOf(123456)); - } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) - .equals(logTopic)) { - FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - if (result.getLogs().size() != 1) { - // when the number of logs is 1, in our tests we will have an operation - // with the revert flag set to true. - assertTrue(response.isSuccess); - } - if (logTopic.equals(createdEventSignature)) { - assertEquals(response.destination, frameworkEntryPointAccount.getAddress().toHexString()); - } else { - //assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); - } - } else { - if (!(logTopic.equals(callEventSignature) || logTopic.equals(writeEventSignature) || logTopic.equals(readEventSignature) || logTopic.equals(destroyedEventSignature) || logTopic.equals(createdEventSignature) || logTopic.equals(sentETHEventSignature) || logTopic.equals(recETHEventSignature))) { - fail(); - } - } + @NonNull ToyAccount frameworkEntryPointAccount; + @NonNull List expectedNoLogs; + int txCounter = 0; + + @Override + public void accept(Transaction transaction, TransactionProcessingResult result) { + TransactionProcessingResultValidator.DEFAULT_VALIDATOR.accept(transaction, result); + // One event from the snippet + // One event from the framework entrypoint about contract call + System.out.println("Number of logs: " + result.getLogs().size()); + assertEquals(result.getLogs().size(), expectedNoLogs.get(txCounter)); + for (Log log : result.getLogs()) { + String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); + String writeEventSignature = EventEncoder.encode(StateManagerEvents.WRITE_EVENT); + String readEventSignature = EventEncoder.encode(StateManagerEvents.READ_EVENT); + String destroyedEventSignature = + EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); + String createdEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTCREATED_EVENT); + String sentETHEventSignature = EventEncoder.encode(StateManagerEvents.PAYETH_EVENT); + String recETHEventSignature = EventEncoder.encode(StateManagerEvents.RECETH_EVENT); + String logTopic = log.getTopics().getFirst().toHexString(); + if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { + TestSnippet_Events.DataNoIndexesEventResponse response = + TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); + // assertEquals(response.singleInt, BigInteger.valueOf(123456)); + } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT).equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + if (result.getLogs().size() != 1) { + // when the number of logs is 1, in our tests we will have an operation + // with the revert flag set to true. + assertTrue(response.isSuccess); + } + if (logTopic.equals(createdEventSignature)) { + assertEquals(response.destination, frameworkEntryPointAccount.getAddress().toHexString()); + } else { + // assertEquals(response.destination, + // this.testContext.initialAccounts[0].getAddress().toHexString()); + } + } else { + if (!(logTopic.equals(callEventSignature) + || logTopic.equals(writeEventSignature) + || logTopic.equals(readEventSignature) + || logTopic.equals(destroyedEventSignature) + || logTopic.equals(createdEventSignature) + || logTopic.equals(sentETHEventSignature) + || logTopic.equals(recETHEventSignature))) { + fail(); } - txCounter++; + } } + txCounter++; + } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseStorageTest.java index 8e7b9a4113..4e5e5986a2 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseStorageTest.java @@ -15,24 +15,22 @@ package net.consensys.linea.zktracer.statemanager; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.math.BigInteger; +import java.util.List; +import java.util.Map; + import net.consensys.linea.testing.MultiBlockExecutionEnvironment; import net.consensys.linea.testing.TransactionProcessingResultValidator; import net.consensys.linea.zktracer.StateManagerTestValidator; import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; -import org.hyperledger.besu.datatypes.Address; import org.junit.jupiter.api.Test; -import java.math.BigInteger; -import java.util.List; -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertEquals; - public class BlockwiseStorageTest { TestContext tc; @@ -42,95 +40,165 @@ void testBlockwiseMapStorage() { this.tc = new TestContext(); this.tc.initializeTestContext(); // prepare the transaction validator - TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + TransactionProcessingResultValidator resultValidator = + new StateManagerTestValidator( tc.frameworkEntryPointAccount, // Creates, writes, reads and self-destructs generate 2 logs, // Reverted operations only have 1 log - List.of(2, 2, 2, - 2, 2, 2, - 2, 2, 2) - ); + List.of(2, 2, 2, 2, 2, 2, 2, 2, 2)); // fetch the Hub metadata for the state manager maps StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); // compute the addresses for several accounts that will be deployed later - tc.newAddresses[0] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); - tc.newAddresses[1] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); - tc.newAddresses[2] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); + tc.newAddresses[0] = + tc.getCreate2AddressForSnippet( + "0x0000000000000000000000000000000000000000000000000000000000000002"); + tc.newAddresses[1] = + tc.getCreate2AddressForSnippet( + "0x0000000000000000000000000000000000000000000000000000000000000003"); + tc.newAddresses[2] = + tc.getCreate2AddressForSnippet( + "0x0000000000000000000000000000000000000000000000000000000000000004"); // prepare a multi-block execution of transactions MultiBlockExecutionEnvironment.builder() - // initialize accounts - .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) - // Block 1 - .addBlock(List.of( - tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 1L, false, BigInteger.ONE), - tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 2L, false, BigInteger.ONE), - tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 3L, false, BigInteger.ONE) - )) - .addBlock(List.of( - tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 4L, false, BigInteger.ONE), - tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 5L, false, BigInteger.ONE), - tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 6L, false, BigInteger.ONE) - )) - .addBlock(List.of( - tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 7L, false, BigInteger.ONE), - tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 8L, false, BigInteger.ONE), - tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 9L, false, BigInteger.ONE) - )) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); + // initialize accounts + .accounts( + List.of( + tc.initialAccounts[0], + tc.externallyOwnedAccounts[0], + tc.initialAccounts[2], + tc.frameworkEntryPointAccount)) + // Block 1 + .addBlock( + List.of( + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + 3L, + 1L, + false, + BigInteger.ONE), + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + 3L, + 2L, + false, + BigInteger.ONE), + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + 3L, + 3L, + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + 3L, + 4L, + false, + BigInteger.ONE), + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + 3L, + 5L, + false, + BigInteger.ONE), + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + 3L, + 6L, + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + 3L, + 7L, + false, + BigInteger.ONE), + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + 3L, + 8L, + false, + BigInteger.ONE), + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + 3L, + 9L, + false, + BigInteger.ONE))) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); - - Map> - blockMap = stateManagerMetadata.getStorageFirstLastBlockMap(); + Map< + StateManagerMetadata.AddrStorageKeyBlockNumTuple, + TransactionProcessingMetadata.FragmentFirstAndLast> + blockMap = stateManagerMetadata.getStorageFirstLastBlockMap(); // prepare data for asserts // expected first values for the keys we are testing int noBlocks = 3; EWord[][] expectedFirst = { - { - EWord.of(0L), - }, - { - EWord.of(3L), - }, - { - EWord.of(6L), - }, + { + EWord.of(0L), + }, + { + EWord.of(3L), + }, + { + EWord.of(6L), + }, }; // expected last values for the keys we are testing EWord[][] expectedLast = { - { - EWord.of(3L), - }, - { - EWord.of(6L), - }, - { - EWord.of(9L), - }, - + { + EWord.of(3L), + }, + { + EWord.of(6L), + }, + { + EWord.of(9L), + }, }; // prepare the key pairs TransactionProcessingMetadata.AddrStorageKeyPair[] rawKeys = { - new TransactionProcessingMetadata.AddrStorageKeyPair(tc.initialAccounts[0].getAddress(), EWord.of(3L)), + new TransactionProcessingMetadata.AddrStorageKeyPair( + tc.initialAccounts[0].getAddress(), EWord.of(3L)), }; - // blocks are numbered starting from 1 for (int block = 1; block <= noBlocks; block++) { for (int i = 0; i < rawKeys.length; i++) { StateManagerMetadata.AddrStorageKeyBlockNumTuple key = - new StateManagerMetadata.AddrStorageKeyBlockNumTuple( - rawKeys[i], - block); - TransactionProcessingMetadata. FragmentFirstAndLast - storageData = blockMap.get(key); + new StateManagerMetadata.AddrStorageKeyBlockNumTuple(rawKeys[i], block); + TransactionProcessingMetadata.FragmentFirstAndLast storageData = + blockMap.get(key); // asserts for the first and last storage values in conflation // -1 due to block numbering - assertEquals(expectedFirst[block-1][i], storageData.getFirst().getValueCurrent()); - assertEquals(expectedLast[block-1][i], storageData.getLast().getValueNext()); + assertEquals(expectedFirst[block - 1][i], storageData.getFirst().getValueCurrent()); + assertEquals(expectedLast[block - 1][i], storageData.getLast().getValueNext()); } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationAccountTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationAccountTest.java index 882354d12c..e0016ad787 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationAccountTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationAccountTest.java @@ -15,119 +15,247 @@ package net.consensys.linea.zktracer.statemanager; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.math.BigInteger; +import java.util.List; +import java.util.Map; + import net.consensys.linea.testing.MultiBlockExecutionEnvironment; import net.consensys.linea.testing.TransactionProcessingResultValidator; import net.consensys.linea.zktracer.StateManagerTestValidator; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; -import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; -import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.junit.jupiter.api.Test; -import java.math.BigInteger; -import java.util.List; -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertEquals; - public class ConflationAccountTest { TestContext tc; + @Test void testConflationMapAccount() { // initialize the test context this.tc = new TestContext(); this.tc.initializeTestContext(); // prepare the transaction validator - TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + TransactionProcessingResultValidator resultValidator = + new StateManagerTestValidator( tc.frameworkEntryPointAccount, // Creates and self-destructs generate 2 logs, // Transfers generate 3 logs, the 1s are for reverted operations - List.of(3, 3, 1, 3, - 2, 3, 3, - 2, 3, 2, 2, 3, - 2, 1) - ); + List.of(3, 3, 1, 3, 2, 3, 3, 2, 3, 2, 2, 3, 2, 1)); // fetch the Hub metadata for the state manager maps StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); // compute the addresses for several accounts that will be deployed later - tc.newAddresses[0] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); - tc.newAddresses[1] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); - tc.newAddresses[2] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); + tc.newAddresses[0] = + tc.getCreate2AddressForSnippet( + "0x0000000000000000000000000000000000000000000000000000000000000002"); + tc.newAddresses[1] = + tc.getCreate2AddressForSnippet( + "0x0000000000000000000000000000000000000000000000000000000000000003"); + tc.newAddresses[2] = + tc.getCreate2AddressForSnippet( + "0x0000000000000000000000000000000000000000000000000000000000000004"); // prepare a multi-block execution of transactions MultiBlockExecutionEnvironment.builder() - // initialize accounts - .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) - // test account operations for an account prexisting in the state - .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 8L, false, BigInteger.ONE))) - .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[2], tc.addresses[0], 20L, false, BigInteger.ONE))) - .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 50L, true, BigInteger.ONE))) // this action is reverted - .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 10L, false, BigInteger.ONE))) - // deploy another account ctxt.addresses[3] and perform account operations on it - .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.newAddresses[0], 49L, false, BigInteger.ONE))) - .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[0], tc.addresses[0], 27L, false, BigInteger.ONE))) - // deploy another account and self destruct it at the end, redeploy it and change its balance again - .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.newAddresses[1], 98L, false, BigInteger.ONE))) - .addBlock(List.of(tc.selfDestruct(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], tc.addresses[2], false, BigInteger.ONE))) - .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.newAddresses[1], 123L, false, BigInteger.ONE))) - // deploy a new account and check revert operations on it - .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000004", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[2], tc.newAddresses[2], 1L, true, BigInteger.ONE))) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); + // initialize accounts + .accounts( + List.of( + tc.initialAccounts[0], + tc.externallyOwnedAccounts[0], + tc.initialAccounts[2], + tc.frameworkEntryPointAccount)) + // test account operations for an account prexisting in the state + .addBlock( + List.of( + tc.transferTo( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + tc.addresses[2], + 8L, + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.transferTo( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[2], + tc.addresses[0], + 20L, + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.transferTo( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + tc.addresses[2], + 50L, + true, + BigInteger.ONE))) // this action is reverted + .addBlock( + List.of( + tc.transferTo( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + tc.addresses[2], + 10L, + false, + BigInteger.ONE))) + // deploy another account ctxt.addresses[3] and perform account operations on it + .addBlock( + List.of( + tc.deployWithCreate2( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.frameworkEntryPointAddress, + "0x0000000000000000000000000000000000000000000000000000000000000002", + TestContext.snippetsCodeForCreate2))) + .addBlock( + List.of( + tc.transferTo( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + tc.newAddresses[0], + 49L, + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.transferTo( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.newAddresses[0], + tc.addresses[0], + 27L, + false, + BigInteger.ONE))) + // deploy another account and self destruct it at the end, redeploy it and change its + // balance again + .addBlock( + List.of( + tc.deployWithCreate2( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.frameworkEntryPointAddress, + "0x0000000000000000000000000000000000000000000000000000000000000003", + TestContext.snippetsCodeForCreate2))) + .addBlock( + List.of( + tc.transferTo( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + tc.newAddresses[1], + 98L, + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.selfDestruct( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.newAddresses[1], + tc.addresses[2], + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.deployWithCreate2( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.frameworkEntryPointAddress, + "0x0000000000000000000000000000000000000000000000000000000000000003", + TestContext.snippetsCodeForCreate2))) + .addBlock( + List.of( + tc.transferTo( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + tc.newAddresses[1], + 123L, + false, + BigInteger.ONE))) + // deploy a new account and check revert operations on it + .addBlock( + List.of( + tc.deployWithCreate2( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.frameworkEntryPointAddress, + "0x0000000000000000000000000000000000000000000000000000000000000004", + TestContext.snippetsCodeForCreate2))) + .addBlock( + List.of( + tc.transferTo( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[2], + tc.newAddresses[2], + 1L, + true, + BigInteger.ONE))) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); - Map> - conflationMap = stateManagerMetadata.getAccountFirstLastConflationMap(); + Map> + conflationMap = stateManagerMetadata.getAccountFirstLastConflationMap(); // prepare data for asserts // expected first values for the keys we are testing Wei[] expectedFirst = { - TestContext.defaultBalance, - TestContext.defaultBalance, - Wei.of(0L), - Wei.of(0L), - Wei.of(0L) + TestContext.defaultBalance, TestContext.defaultBalance, Wei.of(0L), Wei.of(0L), Wei.of(0L) }; // expected last values for the keys we are testing Wei[] expectedLast = { - TestContext.defaultBalance.subtract(8L).add(20L). - subtract(10L).subtract(49L).add(27L) - .subtract(98L).subtract(123L), - TestContext.defaultBalance.add(8L).subtract(20L).add(10L) - .add(98L), // 98L obtained from the self destruct of the account at ctxt.addresses[4] - Wei.of(0L).add(49L).subtract(27L), - Wei.of(123L), - Wei.of(0L) + TestContext.defaultBalance + .subtract(8L) + .add(20L) + .subtract(10L) + .subtract(49L) + .add(27L) + .subtract(98L) + .subtract(123L), + TestContext.defaultBalance + .add(8L) + .subtract(20L) + .add(10L) + .add(98L), // 98L obtained from the self destruct of the account at ctxt.addresses[4] + Wei.of(0L).add(49L).subtract(27L), + Wei.of(123L), + Wei.of(0L) }; // prepare the key pairs Address[] keys = { - tc.initialAccounts[0].getAddress(), - tc.initialAccounts[2].getAddress(), - tc.newAddresses[0], - tc.newAddresses[1], - tc.newAddresses[2] + tc.initialAccounts[0].getAddress(), + tc.initialAccounts[2].getAddress(), + tc.newAddresses[0], + tc.newAddresses[1], + tc.newAddresses[2] }; for (int i = 0; i < keys.length; i++) { - System.out.println("Index is "+i); - TransactionProcessingMetadata. FragmentFirstAndLast - accountData = conflationMap.get(keys[i]); + System.out.println("Index is " + i); + TransactionProcessingMetadata.FragmentFirstAndLast accountData = + conflationMap.get(keys[i]); // asserts for the first and last storage values in conflation assertEquals(expectedFirst[i], accountData.getFirst().oldState().balance()); assertEquals(expectedLast[i], accountData.getLast().newState().balance()); } - System.out.println("Done"); } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java index 92aea7b732..a1dc14a07e 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java @@ -15,6 +15,11 @@ package net.consensys.linea.zktracer.statemanager; +import static org.junit.jupiter.api.Assertions.*; + +import java.math.BigInteger; +import java.util.*; + import net.consensys.linea.testing.*; import net.consensys.linea.zktracer.StateManagerTestValidator; import net.consensys.linea.zktracer.module.hub.Hub; @@ -24,15 +29,8 @@ import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Wei; import org.junit.jupiter.api.Test; -import java.math.BigInteger; -import java.util.*; - -import static org.assertj.core.api.Fail.fail; -import static org.junit.jupiter.api.Assertions.*; - public class ConflationStorageTest { TestContext tc; @@ -42,86 +40,255 @@ void testConflationMapStorage() { this.tc = new TestContext(); this.tc.initializeTestContext(); // prepare the transaction validator - TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + TransactionProcessingResultValidator resultValidator = + new StateManagerTestValidator( tc.frameworkEntryPointAccount, // Creates, writes, reads and self-destructs generate 2 logs, // Reverted operations only have 1 log - List.of(2, 2, 2, 2, 2, - 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, - 2, 2, 1, 1) - ); + List.of(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1)); // fetch the Hub metadata for the state manager maps StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); // compute the addresses for several accounts that will be deployed later - tc.newAddresses[0] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); - tc.newAddresses[1] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); - tc.newAddresses[2] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); + tc.newAddresses[0] = + tc.getCreate2AddressForSnippet( + "0x0000000000000000000000000000000000000000000000000000000000000002"); + tc.newAddresses[1] = + tc.getCreate2AddressForSnippet( + "0x0000000000000000000000000000000000000000000000000000000000000003"); + tc.newAddresses[2] = + tc.getCreate2AddressForSnippet( + "0x0000000000000000000000000000000000000000000000000000000000000004"); // prepare a multi-block execution of transactions MultiBlockExecutionEnvironment.builder() - // initialize accounts - .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) - // test storage operations for an account prexisting in the state - .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, 8L, false, BigInteger.ONE))) - .addBlock(List.of(tc.readFromStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, false, BigInteger.ONE))) - .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, 10L, false, BigInteger.ONE))) - .addBlock(List.of(tc.readFromStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, false, BigInteger.ONE))) - .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, 15L, false, BigInteger.ONE))) - // deploy another account and perform storage operations on it - .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[0], 345L, 20L, false, BigInteger.ONE))) - .addBlock(List.of(tc.readFromStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[0], 345L, false, BigInteger.ONE))) - .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[0], 345L, 40L, false, BigInteger.ONE))) - // deploy another account and self destruct it at the end, redeploy it and change the storage again - // the salt will be the same twice in a row, which will be on purpose - .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], 400L, 12L, false, BigInteger.ONE))) - .addBlock(List.of(tc.readFromStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], 400L, false, BigInteger.ONE))) - .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], 400L, 13L, false, BigInteger.ONE))) - .addBlock(List.of(tc.selfDestruct(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], tc.frameworkEntryPointAddress, false, BigInteger.ONE))) - .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000003", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], 400L, 99L, false, BigInteger.ONE))) - // deploy a new account and check revert operations on it - .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000004", TestContext.snippetsCodeForCreate2))) - .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[2], 500L, 23L, false, BigInteger.ONE))) - .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[2], 500L, 53L, true, BigInteger.ONE))) // revert flag on - .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[2], 500L, 63L, true, BigInteger.ONE))) // revert flag on - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); + // initialize accounts + .accounts( + List.of( + tc.initialAccounts[0], + tc.externallyOwnedAccounts[0], + tc.initialAccounts[2], + tc.frameworkEntryPointAccount)) + // test storage operations for an account prexisting in the state + .addBlock( + List.of( + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + 123L, + 8L, + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.readFromStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + 123L, + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + 123L, + 10L, + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.readFromStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + 123L, + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + 123L, + 15L, + false, + BigInteger.ONE))) + // deploy another account and perform storage operations on it + .addBlock( + List.of( + tc.deployWithCreate2( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.frameworkEntryPointAddress, + "0x0000000000000000000000000000000000000000000000000000000000000002", + TestContext.snippetsCodeForCreate2))) + .addBlock( + List.of( + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.newAddresses[0], + 345L, + 20L, + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.readFromStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.newAddresses[0], + 345L, + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.newAddresses[0], + 345L, + 40L, + false, + BigInteger.ONE))) + // deploy another account and self destruct it at the end, redeploy it and change the + // storage again + // the salt will be the same twice in a row, which will be on purpose + .addBlock( + List.of( + tc.deployWithCreate2( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.frameworkEntryPointAddress, + "0x0000000000000000000000000000000000000000000000000000000000000003", + TestContext.snippetsCodeForCreate2))) + .addBlock( + List.of( + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.newAddresses[1], + 400L, + 12L, + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.readFromStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.newAddresses[1], + 400L, + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.newAddresses[1], + 400L, + 13L, + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.selfDestruct( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.newAddresses[1], + tc.frameworkEntryPointAddress, + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.deployWithCreate2( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.frameworkEntryPointAddress, + "0x0000000000000000000000000000000000000000000000000000000000000003", + TestContext.snippetsCodeForCreate2))) + .addBlock( + List.of( + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.newAddresses[1], + 400L, + 99L, + false, + BigInteger.ONE))) + // deploy a new account and check revert operations on it + .addBlock( + List.of( + tc.deployWithCreate2( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.frameworkEntryPointAddress, + "0x0000000000000000000000000000000000000000000000000000000000000004", + TestContext.snippetsCodeForCreate2))) + .addBlock( + List.of( + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.newAddresses[2], + 500L, + 23L, + false, + BigInteger.ONE))) + .addBlock( + List.of( + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.newAddresses[2], + 500L, + 53L, + true, + BigInteger.ONE))) // revert flag on + .addBlock( + List.of( + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.newAddresses[2], + 500L, + 63L, + true, + BigInteger.ONE))) // revert flag on + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); - Map> - conflationMap = stateManagerMetadata.getAccountFirstLastConflationMap(); - Map> - conflationStorage = stateManagerMetadata.getStorageFirstLastConflationMap(); + Map> + conflationMap = stateManagerMetadata.getAccountFirstLastConflationMap(); + Map< + TransactionProcessingMetadata.AddrStorageKeyPair, + TransactionProcessingMetadata.FragmentFirstAndLast> + conflationStorage = stateManagerMetadata.getStorageFirstLastConflationMap(); // prepare data for asserts // expected first values for the keys we are testing - EWord[] expectedFirst = { - EWord.of(0L), - EWord.of(0), - EWord.of(0), - EWord.of(0) - }; + EWord[] expectedFirst = {EWord.of(0L), EWord.of(0), EWord.of(0), EWord.of(0)}; // expected last values for the keys we are testing - EWord[] expectedLast = { - EWord.of(15L), - EWord.of(40L), - EWord.of(99L), - EWord.of(23L) - }; + EWord[] expectedLast = {EWord.of(15L), EWord.of(40L), EWord.of(99L), EWord.of(23L)}; // prepare the key pairs TransactionProcessingMetadata.AddrStorageKeyPair[] keys = { - new TransactionProcessingMetadata.AddrStorageKeyPair(tc.initialAccounts[0].getAddress(), EWord.of(123L)), - new TransactionProcessingMetadata.AddrStorageKeyPair(tc.newAddresses[0], EWord.of(345L)), - new TransactionProcessingMetadata.AddrStorageKeyPair(tc.newAddresses[1], EWord.of(400L)), - new TransactionProcessingMetadata.AddrStorageKeyPair(tc.newAddresses[2], EWord.of(500L)) + new TransactionProcessingMetadata.AddrStorageKeyPair( + tc.initialAccounts[0].getAddress(), EWord.of(123L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.newAddresses[0], EWord.of(345L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.newAddresses[1], EWord.of(400L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.newAddresses[2], EWord.of(500L)) }; for (int i = 0; i < keys.length; i++) { - TransactionProcessingMetadata. FragmentFirstAndLast - storageData = conflationStorage.get(keys[i]); + TransactionProcessingMetadata.FragmentFirstAndLast storageData = + conflationStorage.get(keys[i]); // asserts for the first and last storage values in conflation assertEquals(expectedFirst[i], storageData.getFirst().getValueCurrent()); assertEquals(expectedLast[i], storageData.getLast().getValueNext()); @@ -131,39 +298,39 @@ void testConflationMapStorage() { } /* - TransactionProcessingResultValidator resultValidator = - (Transaction transaction, TransactionProcessingResult result) -> { - // One event from the snippet - // One event from the framework entrypoint about contract call - //assertEquals(result.getLogs().size(), 1); - System.out.println("Number of logs: "+result.getLogs().size()); - var noTopics = result.getLogs().size(); - for (Log log : result.getLogs()) { - String logTopic = log.getTopics().getFirst().toHexString(); - String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); - String writeEventSignature = EventEncoder.encode(FrameworkEntrypoint.WRITE_EVENT); - String readEventSignature = EventEncoder.encode(FrameworkEntrypoint.READ_EVENT); - String destructEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); - if (callEventSignature.equals(logTopic)) { - FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - assertTrue(response.isSuccess); - assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); - continue; - } - if (writeEventSignature.equals(logTopic)) { - // write event - continue; - } - if (readEventSignature.equals(logTopic)) { - // read event - continue; - } - if (destructEventSignature.equals(logTopic)) { - // self destruct - continue; - } - fail(); - } - }; - */ \ No newline at end of file +TransactionProcessingResultValidator resultValidator = + (Transaction transaction, TransactionProcessingResult result) -> { + // One event from the snippet + // One event from the framework entrypoint about contract call + //assertEquals(result.getLogs().size(), 1); + System.out.println("Number of logs: "+result.getLogs().size()); + var noTopics = result.getLogs().size(); + for (Log log : result.getLogs()) { + String logTopic = log.getTopics().getFirst().toHexString(); + String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); + String writeEventSignature = EventEncoder.encode(FrameworkEntrypoint.WRITE_EVENT); + String readEventSignature = EventEncoder.encode(FrameworkEntrypoint.READ_EVENT); + String destructEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); + if (callEventSignature.equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); + continue; + } + if (writeEventSignature.equals(logTopic)) { + // write event + continue; + } + if (readEventSignature.equals(logTopic)) { + // read event + continue; + } + if (destructEventSignature.equals(logTopic)) { + // self destruct + continue; + } + fail(); + } + }; + */ diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java index 2266816d3c..b6e5a385cc 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java @@ -1,5 +1,10 @@ package net.consensys.linea.zktracer.statemanager; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + import lombok.Getter; import lombok.NoArgsConstructor; import net.consensys.linea.testing.*; @@ -17,346 +22,397 @@ import org.web3j.abi.datatypes.Function; import org.web3j.abi.datatypes.generated.Uint256; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import static org.assertj.core.api.Fail.fail; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; @NoArgsConstructor public class TestContext { - Long txNonce = null; - static final Long gasLimit = 5000000L; - static final Wei defaultBalance = Wei.fromEth(3); - static final int numberOfAccounts = 10; - static final int numberOfNewAccounts = 10; - static final int numberOfEOA = 1; - static final Bytes snippetsCode = SmartContractUtils.getYulContractRuntimeByteCode("StateManagerSnippets.yul"); - static final Bytes snippetsCodeForCreate2 = SmartContractUtils.getYulContractCompiledByteCode("StateManagerSnippets.yul"); - @Getter - ToyAccount frameworkEntryPointAccount; - Address frameworkEntryPointAddress; - ToyAccount[] initialAccounts; - ToyAccount[] externallyOwnedAccounts; - KeyPair[] keyPairs; - Address[] addresses; - Address[] newAddresses; - public void initializeTestContext() { - // initialize vectors - initialAccounts = new ToyAccount[numberOfAccounts]; - addresses = new Address[numberOfAccounts]; - externallyOwnedAccounts = new ToyAccount[numberOfEOA]; - keyPairs = new KeyPair[numberOfEOA]; - newAddresses = new Address[numberOfNewAccounts]; - // generate externally owned accounts - for (int i = 0; i < numberOfEOA; i++) { - KeyPair keyPair = new SECP256K1().generateKeyPair(); - Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); - externallyOwnedAccounts[i] = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); - keyPairs[i] = keyPair; - } - // initialize the testing framework entry point account - frameworkEntryPointAccount = - ToyAccount.builder() - .address(Address.fromHexString("0x123456")) - .balance(defaultBalance) - .nonce(5) - .code(SmartContractUtils.getSolidityContractRuntimeByteCode(FrameworkEntrypoint.class)) - .build(); - frameworkEntryPointAddress = frameworkEntryPointAccount.getAddress(); - // add to arrays - // initialize the .yul snippets account - // load the .yul bytecode - for (int i = 0; i < numberOfAccounts; i++) { - - initialAccounts[i] = - ToyAccount.builder() - .address(Address.fromHexString("0x" + i + i + i + i + i)) - .balance(defaultBalance) - .nonce(6) - .code(TestContext.snippetsCode) - .build(); - addresses[i] = initialAccounts[i].getAddress(); } + Long txNonce = null; + static final Long gasLimit = 5000000L; + static final Wei defaultBalance = Wei.fromEth(3); + static final int numberOfAccounts = 10; + static final int numberOfNewAccounts = 10; + static final int numberOfEOA = 1; + static final Bytes snippetsCode = + SmartContractUtils.getYulContractRuntimeByteCode("StateManagerSnippets.yul"); + static final Bytes snippetsCodeForCreate2 = + SmartContractUtils.getYulContractCompiledByteCode("StateManagerSnippets.yul"); + @Getter ToyAccount frameworkEntryPointAccount; + Address frameworkEntryPointAddress; + ToyAccount[] initialAccounts; + ToyAccount[] externallyOwnedAccounts; + KeyPair[] keyPairs; + Address[] addresses; + Address[] newAddresses; + + public void initializeTestContext() { + // initialize vectors + initialAccounts = new ToyAccount[numberOfAccounts]; + addresses = new Address[numberOfAccounts]; + externallyOwnedAccounts = new ToyAccount[numberOfEOA]; + keyPairs = new KeyPair[numberOfEOA]; + newAddresses = new Address[numberOfNewAccounts]; + // generate externally owned accounts + for (int i = 0; i < numberOfEOA; i++) { + KeyPair keyPair = new SECP256K1().generateKeyPair(); + Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); + externallyOwnedAccounts[i] = + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + keyPairs[i] = keyPair; } - - - // destination must be our .yul smart contract - FrameworkEntrypoint.ContractCall writeToStorageCall(Address destination, Long key, Long value, boolean revertFlag, BigInteger callType) { - Function yulFunction = new Function("writeToStorage", - Arrays.asList(new Uint256(BigInteger.valueOf(key)), new Uint256(BigInteger.valueOf(value)), new org.web3j.abi.datatypes.Bool(revertFlag)), - Collections.emptyList()); - - var encoding = FunctionEncoder.encode(yulFunction); - FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ callType); - return snippetContractCall; + // initialize the testing framework entry point account + frameworkEntryPointAccount = + ToyAccount.builder() + .address(Address.fromHexString("0x123456")) + .balance(defaultBalance) + .nonce(5) + .code(SmartContractUtils.getSolidityContractRuntimeByteCode(FrameworkEntrypoint.class)) + .build(); + frameworkEntryPointAddress = frameworkEntryPointAccount.getAddress(); + // add to arrays + // initialize the .yul snippets account + // load the .yul bytecode + for (int i = 0; i < numberOfAccounts; i++) { + + initialAccounts[i] = + ToyAccount.builder() + .address(Address.fromHexString("0x" + i + i + i + i + i)) + .balance(defaultBalance) + .nonce(6) + .code(TestContext.snippetsCode) + .build(); + addresses[i] = initialAccounts[i].getAddress(); } - - // destination must be our .yul smart contract - Transaction wrapWrite(ToyAccount sender, KeyPair senderKeyPair, FrameworkEntrypoint.ContractCall[] contractCalls) { - Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); - Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - - - ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() - .sender(sender) - .to(this.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit); - - if (this.txNonce != null) { - tempTx = tempTx.nonce(++this.txNonce); - } - Transaction tx = tempTx.build(); - if (this.txNonce == null) { - this.txNonce = tx.getNonce(); - } - return tx; + } + + // destination must be our .yul smart contract + FrameworkEntrypoint.ContractCall writeToStorageCall( + Address destination, Long key, Long value, boolean revertFlag, BigInteger callType) { + Function yulFunction = + new Function( + "writeToStorage", + Arrays.asList( + new Uint256(BigInteger.valueOf(key)), + new Uint256(BigInteger.valueOf(value)), + new org.web3j.abi.datatypes.Bool(revertFlag)), + Collections.emptyList()); + + var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); + return snippetContractCall; + } + + // destination must be our .yul smart contract + Transaction wrapWrite( + ToyAccount sender, KeyPair senderKeyPair, FrameworkEntrypoint.ContractCall[] contractCalls) { + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + ToyTransaction.ToyTransactionBuilder tempTx = + ToyTransaction.builder() + .sender(sender) + .to(this.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit); + + if (this.txNonce != null) { + tempTx = tempTx.nonce(++this.txNonce); } - - - - // destination must be our .yul smart contract - Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, Address destination, Long key, Long value, boolean revertFlag, BigInteger callType) { - Function yulFunction = new Function("writeToStorage", - Arrays.asList(new Uint256(BigInteger.valueOf(key)), new Uint256(BigInteger.valueOf(value)), new org.web3j.abi.datatypes.Bool(revertFlag)), - Collections.emptyList()); - - var encoding = FunctionEncoder.encode(yulFunction); - FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ callType); - - List contractCalls = List.of(snippetContractCall); - Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); - Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - - - ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() - .sender(sender) - .to(this.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit); - - if (this.txNonce != null) { - tempTx = tempTx.nonce(++this.txNonce); - } - Transaction tx = tempTx.build(); - if (this.txNonce == null) { - this.txNonce = tx.getNonce(); - } - return tx; + Transaction tx = tempTx.build(); + if (this.txNonce == null) { + this.txNonce = tx.getNonce(); } - - - // destination must be our .yul smart contract - Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, Address destination, Long key, boolean revertFlag, BigInteger callType) { - Function yulFunction = new Function("readFromStorage", - Arrays.asList(new Uint256(BigInteger.valueOf(key)), new org.web3j.abi.datatypes.Bool(revertFlag)), - Collections.emptyList()); - - - var encoding = FunctionEncoder.encode(yulFunction); - FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ callType); - - List contractCalls = List.of(snippetContractCall); - Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); - Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - - ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() - .sender(sender) - .to(this.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit); - - if (this.txNonce != null) { - tempTx = tempTx.nonce(++this.txNonce); - } - Transaction tx = tempTx.build(); - if (this.txNonce == null) { - this.txNonce = tx.getNonce(); - } - return tx; + return tx; + } + + // destination must be our .yul smart contract + Transaction writeToStorage( + ToyAccount sender, + KeyPair senderKeyPair, + Address destination, + Long key, + Long value, + boolean revertFlag, + BigInteger callType) { + Function yulFunction = + new Function( + "writeToStorage", + Arrays.asList( + new Uint256(BigInteger.valueOf(key)), + new Uint256(BigInteger.valueOf(value)), + new org.web3j.abi.datatypes.Bool(revertFlag)), + Collections.emptyList()); + + var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); + + List contractCalls = List.of(snippetContractCall); + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + ToyTransaction.ToyTransactionBuilder tempTx = + ToyTransaction.builder() + .sender(sender) + .to(this.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit); + + if (this.txNonce != null) { + tempTx = tempTx.nonce(++this.txNonce); } - - // destination must be our .yul smart contract - Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, Address destination, Address recipient, boolean revertFlag, BigInteger callType) { - String recipientAddressString = recipient.toHexString(); - Function yulFunction = new Function("selfDestruct", - Arrays.asList(new org.web3j.abi.datatypes.Address(recipientAddressString), new org.web3j.abi.datatypes.Bool(revertFlag)), - Collections.emptyList()); - - - var encoding = FunctionEncoder.encode(yulFunction); - FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ callType); // Normal call, not a delegate call as would be the default - - List contractCalls = List.of(snippetContractCall); - Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); - Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - - ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() - .sender(sender) - .to(this.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit); - - if (this.txNonce != null) { - tempTx = tempTx.nonce(++this.txNonce); - } - Transaction tx = tempTx.build(); - if (this.txNonce == null) { - this.txNonce = tx.getNonce(); - } - return tx; + Transaction tx = tempTx.build(); + if (this.txNonce == null) { + this.txNonce = tx.getNonce(); } - - // destination must be our .yul smart contract - Transaction transferTo(ToyAccount sender, KeyPair senderKeyPair, Address destination, Address recipient, long amount, boolean revertFlag, BigInteger callType) { - String recipientAddressString = recipient.toHexString(); - Function yulFunction = new Function("transferTo", - Arrays.asList(new org.web3j.abi.datatypes.Address(recipientAddressString), new Uint256(amount), new org.web3j.abi.datatypes.Bool(revertFlag)), - Collections.emptyList()); - - - var encoding = FunctionEncoder.encode(yulFunction); - FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ callType); // Normal call, not a delegate call as would be the default - - List contractCalls = List.of(snippetContractCall); - Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); - Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - - ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() - .sender(sender) - .to(this.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit); - - if (this.txNonce != null) { - tempTx = tempTx.nonce(++this.txNonce); - } - Transaction tx = tempTx.build(); - if (this.txNonce == null) { - this.txNonce = tx.getNonce(); - } - return tx; + return tx; + } + + // destination must be our .yul smart contract + Transaction readFromStorage( + ToyAccount sender, + KeyPair senderKeyPair, + Address destination, + Long key, + boolean revertFlag, + BigInteger callType) { + Function yulFunction = + new Function( + "readFromStorage", + Arrays.asList( + new Uint256(BigInteger.valueOf(key)), new org.web3j.abi.datatypes.Bool(revertFlag)), + Collections.emptyList()); + + var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); + + List contractCalls = List.of(snippetContractCall); + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + ToyTransaction.ToyTransactionBuilder tempTx = + ToyTransaction.builder() + .sender(sender) + .to(this.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit); + + if (this.txNonce != null) { + tempTx = tempTx.nonce(++this.txNonce); } - - // destination must be our .yul smart contract - Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, Address destination, String saltString, Bytes contractBytes) { - Bytes salt = Bytes.fromHexStringLenient(saltString); - // the following is the bytecode of the .yul contract - // Bytes yulContractBytes = Bytes.fromHexStringLenient("61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); - // prepare the Create2 function - Function create2Function = - new Function( - FrameworkEntrypoint.FUNC_DEPLOYWITHCREATE2, - Arrays.asList(new org.web3j.abi.datatypes.generated.Bytes32(salt.toArray()), - new org.web3j.abi.datatypes.DynamicBytes(contractBytes.toArray())), - Collections.emptyList()); - - String encoding = FunctionEncoder.encode(create2Function); - - FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ BigInteger.ONE); // Normal call, not a delegate call as it is the default - - - List contractCalls = List.of(snippetContractCall); - Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); - - Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - - ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() - .sender(sender) - .to(this.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit); - - if (this.txNonce != null) { - tempTx = tempTx.nonce(++this.txNonce); - } - Transaction tx = tempTx.build(); - if (this.txNonce == null) { - this.txNonce = tx.getNonce(); - } - return tx; + Transaction tx = tempTx.build(); + if (this.txNonce == null) { + this.txNonce = tx.getNonce(); } - - public Address getCreate2AddressForSnippet(String salt) { - org.apache.tuweni.bytes.Bytes32 initCodeHash = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(TestContext.snippetsCodeForCreate2)); - org.apache.tuweni.bytes.Bytes32 targetAddress = AddressUtils.getCreate2RawAddress(frameworkEntryPointAccount.getAddress(), - org.apache.tuweni.bytes.Bytes32.wrap(Bytes.fromHexStringLenient(salt).toArray()), - initCodeHash); - return Address.extract(targetAddress); + return tx; + } + + // destination must be our .yul smart contract + Transaction selfDestruct( + ToyAccount sender, + KeyPair senderKeyPair, + Address destination, + Address recipient, + boolean revertFlag, + BigInteger callType) { + String recipientAddressString = recipient.toHexString(); + Function yulFunction = + new Function( + "selfDestruct", + Arrays.asList( + new org.web3j.abi.datatypes.Address(recipientAddressString), + new org.web3j.abi.datatypes.Bool(revertFlag)), + Collections.emptyList()); + + var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); // Normal call, not a delegate call as would be the default + + List contractCalls = List.of(snippetContractCall); + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + ToyTransaction.ToyTransactionBuilder tempTx = + ToyTransaction.builder() + .sender(sender) + .to(this.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit); + + if (this.txNonce != null) { + tempTx = tempTx.nonce(++this.txNonce); + } + Transaction tx = tempTx.build(); + if (this.txNonce == null) { + this.txNonce = tx.getNonce(); + } + return tx; + } + + // destination must be our .yul smart contract + Transaction transferTo( + ToyAccount sender, + KeyPair senderKeyPair, + Address destination, + Address recipient, + long amount, + boolean revertFlag, + BigInteger callType) { + String recipientAddressString = recipient.toHexString(); + Function yulFunction = + new Function( + "transferTo", + Arrays.asList( + new org.web3j.abi.datatypes.Address(recipientAddressString), + new Uint256(amount), + new org.web3j.abi.datatypes.Bool(revertFlag)), + Collections.emptyList()); + + var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); // Normal call, not a delegate call as would be the default + + List contractCalls = List.of(snippetContractCall); + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + ToyTransaction.ToyTransactionBuilder tempTx = + ToyTransaction.builder() + .sender(sender) + .to(this.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit); + + if (this.txNonce != null) { + tempTx = tempTx.nonce(++this.txNonce); + } + Transaction tx = tempTx.build(); + if (this.txNonce == null) { + this.txNonce = tx.getNonce(); + } + return tx; + } + + // destination must be our .yul smart contract + Transaction deployWithCreate2( + ToyAccount sender, + KeyPair senderKeyPair, + Address destination, + String saltString, + Bytes contractBytes) { + Bytes salt = Bytes.fromHexStringLenient(saltString); + // the following is the bytecode of the .yul contract + // Bytes yulContractBytes = + // Bytes.fromHexStringLenient("61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); + // prepare the Create2 function + Function create2Function = + new Function( + FrameworkEntrypoint.FUNC_DEPLOYWITHCREATE2, + Arrays.asList( + new org.web3j.abi.datatypes.generated.Bytes32(salt.toArray()), + new org.web3j.abi.datatypes.DynamicBytes(contractBytes.toArray())), + Collections.emptyList()); + + String encoding = FunctionEncoder.encode(create2Function); + + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ONE); // Normal call, not a delegate call as it is the default + + List contractCalls = List.of(snippetContractCall); + Function frameworkEntryPointFunction = + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); + + Bytes txPayload = + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + + ToyTransaction.ToyTransactionBuilder tempTx = + ToyTransaction.builder() + .sender(sender) + .to(this.frameworkEntryPointAccount) + .payload(txPayload) + .keyPair(senderKeyPair) + .gasLimit(TestContext.gasLimit); + + if (this.txNonce != null) { + tempTx = tempTx.nonce(++this.txNonce); + } + Transaction tx = tempTx.build(); + if (this.txNonce == null) { + this.txNonce = tx.getNonce(); } + return tx; + } + + public Address getCreate2AddressForSnippet(String salt) { + org.apache.tuweni.bytes.Bytes32 initCodeHash = + org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(TestContext.snippetsCodeForCreate2)); + org.apache.tuweni.bytes.Bytes32 targetAddress = + AddressUtils.getCreate2RawAddress( + frameworkEntryPointAccount.getAddress(), + org.apache.tuweni.bytes.Bytes32.wrap(Bytes.fromHexStringLenient(salt).toArray()), + initCodeHash); + return Address.extract(targetAddress); + } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java index 3bc16d0bcd..e31b728e5f 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java @@ -15,6 +15,12 @@ package net.consensys.linea.zktracer.statemanager; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.math.BigInteger; +import java.util.List; +import java.util.Map; + import net.consensys.linea.testing.MultiBlockExecutionEnvironment; import net.consensys.linea.testing.TransactionProcessingResultValidator; import net.consensys.linea.testing.generated.FrameworkEntrypoint; @@ -26,12 +32,6 @@ import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.junit.jupiter.api.Test; -import java.math.BigInteger; -import java.util.List; -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertEquals; - public class TransactionStorageTest { TestContext tc; @@ -41,81 +41,90 @@ void testTransactionMapStorage() { this.tc = new TestContext(); this.tc.initializeTestContext(); // prepare the transaction validator - TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + TransactionProcessingResultValidator resultValidator = + new StateManagerTestValidator( tc.frameworkEntryPointAccount, // Creates, writes, reads and self-destructs generate 2 logs, // Reverted operations only have 1 log - List.of(6, 6) - ); + List.of(6, 6)); // fetch the Hub metadata for the state manager maps StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); // prepare a multi-block execution of transactions MultiBlockExecutionEnvironment.builder() - // initialize accounts - .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) - // Block 1 - .addBlock(List.of( - tc.wrapWrite(tc.externallyOwnedAccounts[0], tc.keyPairs[0], new FrameworkEntrypoint.ContractCall[] - { - tc.writeToStorageCall(tc.addresses[0], 3L, 1L, false, BigInteger.ONE), - tc.writeToStorageCall(tc.addresses[0], 3L, 2L, false, BigInteger.ONE), - tc.writeToStorageCall(tc.addresses[0], 3L, 3L, false, BigInteger.ONE), - }), - tc.wrapWrite(tc.externallyOwnedAccounts[0], tc.keyPairs[0], new FrameworkEntrypoint.ContractCall[] - { - tc.writeToStorageCall(tc.addresses[0], 3L, 4L, false, BigInteger.ONE), - tc.writeToStorageCall(tc.addresses[0], 3L, 5L, false, BigInteger.ONE), - tc.writeToStorageCall(tc.addresses[0], 3L, 6L, false, BigInteger.ONE), - }) - - )) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); - - - List txn = Hub.stateManagerMetadata().getHub().txStack().getTransactions();; - - + // initialize accounts + .accounts( + List.of( + tc.initialAccounts[0], + tc.externallyOwnedAccounts[0], + tc.initialAccounts[2], + tc.frameworkEntryPointAccount)) + // Block 1 + .addBlock( + List.of( + tc.wrapWrite( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + new FrameworkEntrypoint.ContractCall[] { + tc.writeToStorageCall(tc.addresses[0], 3L, 1L, false, BigInteger.ONE), + tc.writeToStorageCall(tc.addresses[0], 3L, 2L, false, BigInteger.ONE), + tc.writeToStorageCall(tc.addresses[0], 3L, 3L, false, BigInteger.ONE), + }), + tc.wrapWrite( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + new FrameworkEntrypoint.ContractCall[] { + tc.writeToStorageCall(tc.addresses[0], 3L, 4L, false, BigInteger.ONE), + tc.writeToStorageCall(tc.addresses[0], 3L, 5L, false, BigInteger.ONE), + tc.writeToStorageCall(tc.addresses[0], 3L, 6L, false, BigInteger.ONE), + }))) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); + + List txn = + Hub.stateManagerMetadata().getHub().txStack().getTransactions(); + ; // prepare data for asserts // expected first values for the keys we are testing int noBlocks = 3; EWord[][] expectedFirst = { - { - EWord.of(0L), - }, - { - EWord.of(3L), - }, + { + EWord.of(0L), + }, + { + EWord.of(3L), + }, }; // expected last values for the keys we are testing EWord[][] expectedLast = { - { - EWord.of(3L), - }, - { - EWord.of(6L), - }, + { + EWord.of(3L), + }, + { + EWord.of(6L), + }, }; // prepare the key pairs TransactionProcessingMetadata.AddrStorageKeyPair[] keys = { - new TransactionProcessingMetadata.AddrStorageKeyPair(tc.initialAccounts[0].getAddress(), EWord.of(3L)), + new TransactionProcessingMetadata.AddrStorageKeyPair( + tc.initialAccounts[0].getAddress(), EWord.of(3L)), }; - // blocks are numbered starting from 1 for (int txCounter = 1; txCounter <= txn.size(); txCounter++) { - Map> - storageMap = txn.get(txCounter-1).getStorageFirstAndLastMap(); + Map< + TransactionProcessingMetadata.AddrStorageKeyPair, + TransactionProcessingMetadata.FragmentFirstAndLast> + storageMap = txn.get(txCounter - 1).getStorageFirstAndLastMap(); for (int i = 0; i < keys.length; i++) { - TransactionProcessingMetadata. FragmentFirstAndLast - storageData = storageMap.get(keys[i]); + TransactionProcessingMetadata.FragmentFirstAndLast storageData = + storageMap.get(keys[i]); // asserts for the first and last storage values in conflation // -1 due to block numbering - assertEquals(expectedFirst[txCounter-1][i], storageData.getFirst().getValueCurrent()); - assertEquals(expectedLast[txCounter-1][i], storageData.getLast().getValueNext()); + assertEquals(expectedFirst[txCounter - 1][i], storageData.getFirst().getValueCurrent()); + assertEquals(expectedLast[txCounter - 1][i], storageData.getLast().getValueNext()); } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/UtilitiesTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/UtilitiesTest.java index 28fbd6a534..a1c912ff83 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/UtilitiesTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/UtilitiesTest.java @@ -15,25 +15,14 @@ package net.consensys.linea.zktracer.statemanager; +import java.math.BigInteger; +import java.util.List; + import net.consensys.linea.testing.MultiBlockExecutionEnvironment; import net.consensys.linea.testing.TransactionProcessingResultValidator; import net.consensys.linea.zktracer.StateManagerTestValidator; -import net.consensys.linea.zktracer.module.hub.Hub; -import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; -import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; -import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; -import net.consensys.linea.zktracer.types.EWord; -import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.datatypes.Wei; import org.junit.jupiter.api.Test; -import java.math.BigInteger; -import java.util.List; -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertEquals; - public class UtilitiesTest { TestContext tc; @@ -42,49 +31,102 @@ void testBuildingBlockOperations() { // initialize the test context this.tc = new TestContext(); this.tc.initializeTestContext(); - TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + TransactionProcessingResultValidator resultValidator = + new StateManagerTestValidator( tc.frameworkEntryPointAccount, // Creates and self-destructs generate 2 logs, // Transfers generate 3 logs, the 1s are for reverted operations - List.of(2, 2, 3, 2, 2) - ); + List.of(2, 2, 3, 2, 2)); MultiBlockExecutionEnvironment.builder() - .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) - .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, 1L, false, BigInteger.ZERO))) - .addBlock(List.of(tc.readFromStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, false, BigInteger.ZERO))) - .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 8L, false, BigInteger.ONE))) - // test operations above, before self-destructing a snippet in the next line - .addBlock(List.of(tc.selfDestruct(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.frameworkEntryPointAddress, false, BigInteger.ONE))) // use BigInteger.ONE, otherwise the framework entry point gets destroyed - .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2))) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); + .accounts( + List.of( + tc.initialAccounts[0], + tc.externallyOwnedAccounts[0], + tc.initialAccounts[2], + tc.frameworkEntryPointAccount)) + .addBlock( + List.of( + tc.writeToStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + 123L, + 1L, + false, + BigInteger.ZERO))) + .addBlock( + List.of( + tc.readFromStorage( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + 123L, + false, + BigInteger.ZERO))) + .addBlock( + List.of( + tc.transferTo( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + tc.addresses[2], + 8L, + false, + BigInteger.ONE))) + // test operations above, before self-destructing a snippet in the next line + .addBlock( + List.of( + tc.selfDestruct( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.addresses[0], + tc.frameworkEntryPointAddress, + false, + BigInteger + .ONE))) // use BigInteger.ONE, otherwise the framework entry point gets + // destroyed + .addBlock( + List.of( + tc.deployWithCreate2( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.frameworkEntryPointAddress, + "0x0000000000000000000000000000000000000000000000000000000000000002", + TestContext.snippetsCodeForCreate2))) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); System.out.println("Done"); } // Create 2 has a weird behavior and does not seem to work with the - // bytecode output by the function SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul") + // bytecode output by the function + // SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul") @Test void testCreate2Snippets() { -// initialize the test context + // initialize the test context this.tc = new TestContext(); this.tc.initializeTestContext(); - TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( - tc.frameworkEntryPointAccount, - List.of(2) - ); + TransactionProcessingResultValidator resultValidator = + new StateManagerTestValidator(tc.frameworkEntryPointAccount, List.of(2)); MultiBlockExecutionEnvironment.builder() - .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.frameworkEntryPointAccount)) - .addBlock(List.of( - tc.deployWithCreate2(tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.frameworkEntryPointAddress, - "0x0000000000000000000000000000000000000000000000000000000000004312", - TestContext.snippetsCodeForCreate2))) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); + .accounts( + List.of( + tc.initialAccounts[0], + tc.externallyOwnedAccounts[0], + tc.frameworkEntryPointAccount)) + .addBlock( + List.of( + tc.deployWithCreate2( + tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.frameworkEntryPointAddress, + "0x0000000000000000000000000000000000000000000000000000000000004312", + TestContext.snippetsCodeForCreate2))) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); System.out.println("Done"); } -} \ No newline at end of file +} diff --git a/linea-constraints b/linea-constraints index 6e1f6ead1f..d60e76258c 160000 --- a/linea-constraints +++ b/linea-constraints @@ -1 +1 @@ -Subproject commit 6e1f6ead1ffe4178fd7f5c29de4d79c189c19ab6 +Subproject commit d60e76258cd71d43bd59e2993dfc322c6f4ed1fd diff --git a/testing/src/main/java/net/consensys/linea/testing/MultiBlockExecutionEnvironment.java b/testing/src/main/java/net/consensys/linea/testing/MultiBlockExecutionEnvironment.java index f3e653c437..cbf2f2b2c5 100644 --- a/testing/src/main/java/net/consensys/linea/testing/MultiBlockExecutionEnvironment.java +++ b/testing/src/main/java/net/consensys/linea/testing/MultiBlockExecutionEnvironment.java @@ -40,7 +40,7 @@ public class MultiBlockExecutionEnvironment { */ @Builder.Default private final TransactionProcessingResultValidator transactionProcessingResultValidator = - TransactionProcessingResultValidator.DEFAULT_VALIDATOR; + TransactionProcessingResultValidator.DEFAULT_VALIDATOR; public static class MultiBlockExecutionEnvironmentBuilder { @@ -48,10 +48,10 @@ public static class MultiBlockExecutionEnvironmentBuilder { public MultiBlockExecutionEnvironmentBuilder addBlock(List transactions) { BlockHeaderBuilder blockHeaderBuilder = - this.blocks.isEmpty() - ? ExecutionEnvironment.getLineaBlockHeaderBuilder(Optional.empty()) - : ExecutionEnvironment.getLineaBlockHeaderBuilder( - Optional.of(this.blocks.getLast().header().toBlockHeader())); + this.blocks.isEmpty() + ? ExecutionEnvironment.getLineaBlockHeaderBuilder(Optional.empty()) + : ExecutionEnvironment.getLineaBlockHeaderBuilder( + Optional.of(this.blocks.getLast().header().toBlockHeader())); blockHeaderBuilder.coinbase(ToyExecutionEnvironmentV2.DEFAULT_COINBASE_ADDRESS); BlockBody blockBody = new BlockBody(transactions, Collections.emptyList()); this.blocks.add(BlockSnapshot.of(blockHeaderBuilder.buildBlockHeader(), blockBody)); @@ -62,47 +62,47 @@ public MultiBlockExecutionEnvironmentBuilder addBlock(List transact public void run() { ReplayExecutionEnvironment.builder() - .useCoinbaseAddressFromBlockHeader(true) - .transactionProcessingResultValidator(this.transactionProcessingResultValidator) - .build() - .replay(ToyExecutionEnvironmentV2.CHAIN_ID, this.buildConflationSnapshot()); + .useCoinbaseAddressFromBlockHeader(true) + .transactionProcessingResultValidator(this.transactionProcessingResultValidator) + .build() + .replay(ToyExecutionEnvironmentV2.CHAIN_ID, this.buildConflationSnapshot()); } private ConflationSnapshot buildConflationSnapshot() { List accountSnapshots = - accounts.stream() - .map( - toyAccount -> - new AccountSnapshot( - toyAccount.getAddress().toHexString(), - toyAccount.getNonce(), - toyAccount.getBalance().toHexString(), - toyAccount.getCode().toHexString())) - .toList(); + accounts.stream() + .map( + toyAccount -> + new AccountSnapshot( + toyAccount.getAddress().toHexString(), + toyAccount.getNonce(), + toyAccount.getBalance().toHexString(), + toyAccount.getCode().toHexString())) + .toList(); List storageSnapshots = - accounts.stream() - .flatMap( - account -> - account.storage.entrySet().stream() - .map( - storageEntry -> - new StorageSnapshot( - account.getAddress().toHexString(), - storageEntry.getKey().toHexString(), - storageEntry.getValue().toHexString()))) - .toList(); + accounts.stream() + .flatMap( + account -> + account.storage.entrySet().stream() + .map( + storageEntry -> + new StorageSnapshot( + account.getAddress().toHexString(), + storageEntry.getKey().toHexString(), + storageEntry.getValue().toHexString()))) + .toList(); List blockHashSnapshots = - blocks.stream() - .map( - blockSnapshot -> { - BlockHeader blockHeader = blockSnapshot.header().toBlockHeader(); - return BlockHashSnapshot.of(blockHeader.getNumber(), blockHeader.getBlockHash()); - }) - .toList(); + blocks.stream() + .map( + blockSnapshot -> { + BlockHeader blockHeader = blockSnapshot.header().toBlockHeader(); + return BlockHashSnapshot.of(blockHeader.getNumber(), blockHeader.getBlockHash()); + }) + .toList(); return new ConflationSnapshot( - this.blocks, accountSnapshots, storageSnapshots, blockHashSnapshots); + this.blocks, accountSnapshots, storageSnapshots, blockHashSnapshots); } -} \ No newline at end of file +} diff --git a/testing/src/main/java/net/consensys/linea/testing/SmartContractUtils.java b/testing/src/main/java/net/consensys/linea/testing/SmartContractUtils.java index 88b909fe17..20367da4e8 100644 --- a/testing/src/main/java/net/consensys/linea/testing/SmartContractUtils.java +++ b/testing/src/main/java/net/consensys/linea/testing/SmartContractUtils.java @@ -96,14 +96,14 @@ public static Bytes getYulContractRuntimeByteCode(final String yulFileName) { try { JsonNode jsonRoot = objectMapper.readTree(contractResourceURL); String byteCode = - jsonRoot - .get("contracts") - .get(yulFileName) - .get(yulFileNameWithoutSuffix) - .get("evm") - .get("deployedBytecode") - .get("object") - .asText(); + jsonRoot + .get("contracts") + .get(yulFileName) + .get(yulFileNameWithoutSuffix) + .get("evm") + .get("deployedBytecode") + .get("object") + .asText(); return Bytes.fromHexStringLenient(byteCode); } catch (Exception e) { throw new RuntimeException("Could not find contract bytecode", e); @@ -137,4 +137,4 @@ public static Bytes getYulContractCompiledByteCode(final String yulFileName) { throw new RuntimeException("Could not find contract bytecode", e); } } -} \ No newline at end of file +} From 11a9127ca0c51d032095f02a90d349a5f998fcbb Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Thu, 31 Oct 2024 01:23:33 +0100 Subject: [PATCH 70/74] fixing bugs --- .../types/TransactionProcessingMetadata.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 f0e56ee8e4..447b8296b3 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 @@ -154,6 +154,17 @@ public static boolean strictlySmallerStamps( int firstDom, int firstSub, int lastDom, int lastSub) { return firstDom < lastDom || (firstDom == lastDom && firstSub > lastSub); } + + public FragmentFirstAndLast copy() { + return new FragmentFirstAndLast( + this.first, + this.last, + this.firstDom, + this.firstSub, + this.lastDom, + this.lastSub + ); + } } @EqualsAndHashCode @@ -219,6 +230,7 @@ public void updateStorageFirstAndLast(StorageFragment fragment, AddrStorageKeyPa new FragmentFirstAndLast(fragment, fragment, dom, sub, dom, sub); txnStorageFirstAndLastMap.put(key, txnFirstAndLast); } else { + // the storage key has already been acessed for this account TransactionProcessingMetadata.FragmentFirstAndLast txnFirstAndLast = txnStorageFirstAndLastMap.get(key); // Replace condition From ce70bfb99c7dca808d232dfa040bf23bbce0116b Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Mon, 25 Nov 2024 14:47:13 +0100 Subject: [PATCH 71/74] fixing compiler errors --- .../linea/zktracer/module/hub/Hub.java | 277 + .../linea/zktracer/module/hub/Trace.java | 4777 ++++++----------- .../hub/fragment/storage/StorageFragment.java | 2 +- 3 files changed, 1962 insertions(+), 3094 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 961167fa7d..468ff99130 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 @@ -15,6 +15,11 @@ package net.consensys.linea.zktracer.module.hub; +import java.util.*; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; +import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; + import static com.google.common.base.Preconditions.*; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_EXEC; import static net.consensys.linea.zktracer.module.hub.HubProcessingPhase.TX_FINL; @@ -145,6 +150,9 @@ public class Hub implements Module { /** provides phase-related volatile information */ @Getter Transients transients = new Transients(this); + /** Block and conflation-level metadata for computing columns relevant to the state manager.* */ + @Getter static StateManagerMetadata stateManagerMetadata = new StateManagerMetadata(); + /** * Long-lived states, not used in tracing per se but keeping track of data of the associated * lifetime @@ -432,6 +440,7 @@ public Hub( blockdata /* WARN: must be called AFTER txnData */), precompileLimitModules().stream()) .toList(); + stateManagerMetadata.setHub(this); } @Override @@ -473,6 +482,10 @@ public void traceEndConflation(final WorldView world) { for (Module m : modules) { m.traceEndConflation(world); } + + // update the conflation level map for the state manager + updateConflationMapAccount(); + updateConflationMapStorage(); } @Override @@ -490,6 +503,8 @@ public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBo for (Module m : modules) { m.traceEndBlock(blockHeader, blockBody); } + // update the block level map for the state manager + updateBlockMap(); } public void traceStartTransaction(final WorldView world, final Transaction tx) { @@ -1164,4 +1179,266 @@ public final boolean returnFromMessageCall(MessageFrame frame) { public final boolean returnFromDeployment(MessageFrame frame) { return opCode() == RETURN && frame.getType() == CONTRACT_CREATION; } + + + public void updateBlockMapAccount() { + Map< + StateManagerMetadata.AddrBlockPair, + TransactionProcessingMetadata.FragmentFirstAndLast> + blockMapAccount = Hub.stateManagerMetadata().getAccountFirstLastBlockMap(); + + List txn = txStack.getTransactions(); + + for (TransactionProcessingMetadata metadata : txn) { + if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) { + int blockNumber = transients.block().blockNumber(); + Map> + localMapAccount = metadata.getAccountFirstAndLastMap(); + + // Update the block map for the account + for (Address addr : localMapAccount.keySet()) { + StateManagerMetadata.AddrBlockPair pairAddrBlock = + new StateManagerMetadata.AddrBlockPair(addr, blockNumber); + + // localValue exists for sure because addr belongs to the keySet of the local map + TransactionProcessingMetadata.FragmentFirstAndLast localValueAccount = + localMapAccount.get(addr); + if (!blockMapAccount.containsKey(pairAddrBlock)) { + // the pair is not present in the map + blockMapAccount.put(pairAddrBlock, localValueAccount); + } else { + TransactionProcessingMetadata.FragmentFirstAndLast fetchedValue = + blockMapAccount.get(pairAddrBlock); + // we make a copy that will be modified to not change the values already present in the + // transaction maps + TransactionProcessingMetadata.FragmentFirstAndLast blockValue = + fetchedValue.copy(); + // update the first part of the blockValue + // Todo: Refactor and remove code duplication + if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( + localValueAccount.getFirstDom(), + localValueAccount.getFirstSub(), + blockValue.getFirstDom(), + blockValue.getFirstSub())) { + // chronologically checks that localValue.First is before blockValue.First + // localValue comes chronologically before, and should be the first value of the map. + blockValue.setFirst(localValueAccount.getFirst()); + blockValue.setFirstDom(localValueAccount.getFirstDom()); + blockValue.setFirstSub(localValueAccount.getFirstSub()); + } + + // update the last part of the blockValue + if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( + blockValue.getLastDom(), + blockValue.getLastSub(), + localValueAccount.getLastDom(), + localValueAccount.getLastSub())) { + // chronologically checks that blockValue.Last is before localValue.Last + // localValue comes chronologically after, and should be the final value of the map. + blockValue.setLast(localValueAccount.getLast()); + blockValue.setLastDom(localValueAccount.getLastDom()); + blockValue.setLastSub(localValueAccount.getLastSub()); + } + blockMapAccount.put(pairAddrBlock, blockValue); + + } + + } + } + } + } + + public void updateBlockMapStorage() { + Map< + StateManagerMetadata.AddrStorageKeyBlockNumTuple, + TransactionProcessingMetadata.FragmentFirstAndLast> + blockMapStorage = Hub.stateManagerMetadata().getStorageFirstLastBlockMap(); + + List txn = txStack.getTransactions(); + + for (TransactionProcessingMetadata metadata : txn) { + if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) { + int blockNumber = transients.block().blockNumber(); + Map< + TransactionProcessingMetadata.AddrStorageKeyPair, + TransactionProcessingMetadata.FragmentFirstAndLast> + localMapStorage = metadata.getStorageFirstAndLastMap(); + // Update the block map for storage + for (TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair : + localMapStorage.keySet()) { + + StateManagerMetadata.AddrStorageKeyBlockNumTuple addrStorageBlockTuple = + new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, blockNumber); + + // localValue exists for sure because addr belongs to the keySet of the local map + TransactionProcessingMetadata.FragmentFirstAndLast localValueStorage = + localMapStorage.get(addrStorageKeyPair); + + if (!blockMapStorage.containsKey(addrStorageBlockTuple)) { + // the pair is not present in the map + blockMapStorage.put(addrStorageBlockTuple, localValueStorage); + } else { + TransactionProcessingMetadata.FragmentFirstAndLast fetched = + blockMapStorage.get(addrStorageBlockTuple); + // we make a copy that will be modified to not change the values already present in the + // transaction maps + TransactionProcessingMetadata.FragmentFirstAndLast blockValueStorage = + fetched.copy(); + // update the first part of the blockValue + if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( + localValueStorage.getFirstDom(), + localValueStorage.getFirstSub(), + blockValueStorage.getFirstDom(), + blockValueStorage.getFirstSub())) { + // chronologically checks that localValue.First is before blockValue.First + // localValue comes chronologically before, and should be the first value of the map. + blockValueStorage.setFirst(localValueStorage.getFirst()); + blockValueStorage.setFirstDom(localValueStorage.getFirstDom()); + blockValueStorage.setFirstSub(localValueStorage.getFirstSub()); + } + // update the last part of the blockValue + if (TransactionProcessingMetadata.FragmentFirstAndLast.strictlySmallerStamps( + blockValueStorage.getLastDom(), + blockValueStorage.getLastSub(), + localValueStorage.getLastDom(), + localValueStorage.getLastSub())) { + // chronologically checks that blockValue.Last is before localValue.Last + // localValue comes chronologically after, and should be the final value of the map. + blockValueStorage.setLast(localValueStorage.getLast()); + blockValueStorage.setLastDom(localValueStorage.getLastDom()); + blockValueStorage.setLastSub(localValueStorage.getLastSub()); + } + + blockMapStorage.put(addrStorageBlockTuple, blockValueStorage); + + } + } + } + } + } + + public void updateBlockMap() { + updateBlockMapAccount(); + updateBlockMapStorage(); + } + + // Update the conflation level map for the state manager + public void updateConflationMapAccount() { + Map> + conflationMapAccount = Hub.stateManagerMetadata().getAccountFirstLastConflationMap(); + + List txn = txStack.getTransactions(); + HashSet
allAccounts = new HashSet
(); + + Map< + StateManagerMetadata.AddrBlockPair, + TransactionProcessingMetadata.FragmentFirstAndLast> + blockMapAccount = Hub.stateManagerMetadata().getAccountFirstLastBlockMap(); + + for (TransactionProcessingMetadata metadata : txn) { + + Map> + txnMapAccount = metadata.getAccountFirstAndLastMap(); + + allAccounts.addAll(txnMapAccount.keySet()); + } + + for (Address addr : allAccounts) { + TransactionProcessingMetadata.FragmentFirstAndLast firstValue = null; + // Update the first value of the conflation map for Account + // We update the value of the conflation map with the earliest value of the block map + for (int i = 1; i <= transients.block().blockNumber(); i++) { + StateManagerMetadata.AddrBlockPair pairAddrBlock = + new StateManagerMetadata.AddrBlockPair(addr, i); + if (blockMapAccount.containsKey(pairAddrBlock)) { + firstValue = blockMapAccount.get(pairAddrBlock); + conflationMapAccount.put(addr, firstValue); + break; + } + } + // Update the last value of the conflation map + // We update the last value for the conflation map with the latest blockMap's last values, + // if some address is not present in the last block, we ignore the corresponding account + for (int i = transients.block().blockNumber(); i >= 1; i--) { + StateManagerMetadata.AddrBlockPair pairAddrBlock = + new StateManagerMetadata.AddrBlockPair(addr, i); + if (blockMapAccount.containsKey(pairAddrBlock)) { + TransactionProcessingMetadata.FragmentFirstAndLast blockValue = + blockMapAccount.get(pairAddrBlock); + + TransactionProcessingMetadata.FragmentFirstAndLast updatedValue = + new TransactionProcessingMetadata.FragmentFirstAndLast( + firstValue.getFirst(), + blockValue.getLast(), + firstValue.getFirstDom(), + firstValue.getFirstSub(), + blockValue.getLastDom(), + blockValue.getLastSub()); + conflationMapAccount.put(addr, updatedValue); + break; + } + } + } + } + + public void updateConflationMapStorage() { + Map< + TransactionProcessingMetadata.AddrStorageKeyPair, + TransactionProcessingMetadata.FragmentFirstAndLast> + conflationMapStorage = Hub.stateManagerMetadata().getStorageFirstLastConflationMap(); + + List txn = txStack.getTransactions(); + HashSet allStorage = + new HashSet(); + Map< + StateManagerMetadata.AddrStorageKeyBlockNumTuple, + TransactionProcessingMetadata.FragmentFirstAndLast> + blockMapStorage = Hub.stateManagerMetadata().getStorageFirstLastBlockMap(); + for (TransactionProcessingMetadata metadata : txn) { + + Map< + TransactionProcessingMetadata.AddrStorageKeyPair, + TransactionProcessingMetadata.FragmentFirstAndLast> + txnMapStorage = metadata.getStorageFirstAndLastMap(); + + allStorage.addAll(txnMapStorage.keySet()); + } + + for (TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair : allStorage) { + TransactionProcessingMetadata.FragmentFirstAndLast firstValue = null; + // Update the first value of the conflation map for Storage + // We update the value of the conflation map with the earliest value of the block map + for (int i = 1; i <= transients.block().blockNumber(); i++) { + StateManagerMetadata.AddrStorageKeyBlockNumTuple addrStorageBlockTuple = + new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, i); + if (blockMapStorage.containsKey(addrStorageBlockTuple)) { + firstValue = blockMapStorage.get(addrStorageBlockTuple); + conflationMapStorage.put(addrStorageKeyPair, firstValue); + break; + } + } + // Update the last value of the conflation map + // We update the last value for the conflation map with the latest blockMap's last values, + // if some address is not present in the last block, we ignore the corresponding account + for (int i = transients.block().blockNumber(); i >= 1; i--) { + StateManagerMetadata.AddrStorageKeyBlockNumTuple addrStorageBlockTuple = + new StateManagerMetadata.AddrStorageKeyBlockNumTuple(addrStorageKeyPair, i); + if (blockMapStorage.containsKey(addrStorageBlockTuple)) { + TransactionProcessingMetadata.FragmentFirstAndLast blockValue = + blockMapStorage.get(addrStorageBlockTuple); + + TransactionProcessingMetadata.FragmentFirstAndLast updatedValue = + new TransactionProcessingMetadata.FragmentFirstAndLast( + firstValue.getFirst(), + blockValue.getLast(), + firstValue.getFirstDom(), + firstValue.getFirstSub(), + blockValue.getLastDom(), + blockValue.getLastSub()); + conflationMapStorage.put(addrStorageKeyPair, updatedValue); + break; + } + } + } + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java index 83e6037fb0..567a58e81c 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Trace.java @@ -15,6 +15,7 @@ package net.consensys.linea.zktracer.module.hub; +import java.math.BigInteger; import java.nio.MappedByteBuffer; import java.util.ArrayList; import java.util.BitSet; @@ -34,43 +35,33 @@ public class Trace { public static final int DOM_SUB_STAMP_OFFSET___REVERT = 0x6; public static final int DOM_SUB_STAMP_OFFSET___SELFDESTRUCT = 0x7; public static final int MULTIPLIER___DOM_SUB_STAMPS = 0x8; + public static final int MULTIPLIER___STACK_HEIGHT = 0x8; public static final int MULTIPLIER___STACK_STAMP = 0x8; private final BitSet filled = new BitSet(); private int currentLine = 0; private final MappedByteBuffer absoluteTransactionNumber; - private final MappedByteBuffer - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize; - private final MappedByteBuffer - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo; - private final MappedByteBuffer - againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd; - private final MappedByteBuffer - againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment; - private final MappedByteBuffer - againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2; + private final MappedByteBuffer addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize; + private final MappedByteBuffer addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo; + private final MappedByteBuffer againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd; + private final MappedByteBuffer againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment; + private final MappedByteBuffer againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2; private final MappedByteBuffer alpha; - private final MappedByteBuffer - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance; - private final MappedByteBuffer - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo; + private final MappedByteBuffer balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance; + private final MappedByteBuffer balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo; private final MappedByteBuffer callDataOffsetXorMmuSize; private final MappedByteBuffer callDataSizeXorMmuSrcId; private final MappedByteBuffer callStackDepthXorStackItemHeight1; private final MappedByteBuffer callerContextNumber; private final MappedByteBuffer codeFragmentIndex; - private final MappedByteBuffer - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi; + private final MappedByteBuffer codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi; private final MappedByteBuffer codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue; - private final MappedByteBuffer - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo; + private final MappedByteBuffer codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo; private final MappedByteBuffer codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo; private final MappedByteBuffer codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi; - private final MappedByteBuffer - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize; - private final MappedByteBuffer - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi; + private final MappedByteBuffer codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize; + private final MappedByteBuffer codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi; private final MappedByteBuffer contextGetsReverted; private final MappedByteBuffer contextMayChange; private final MappedByteBuffer contextNumber; @@ -84,55 +75,39 @@ public class Trace { private final MappedByteBuffer delta; private final MappedByteBuffer deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock; private final MappedByteBuffer deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock; - private final MappedByteBuffer - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao; - private final MappedByteBuffer - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas; - private final MappedByteBuffer - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi; - private final MappedByteBuffer - deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode; - private final MappedByteBuffer - deploymentStatusNewXorMxpFlagXorCallPrcFailureXorConFlagXorFinalInTxn; - private final MappedByteBuffer - deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution; + private final MappedByteBuffer deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao; + private final MappedByteBuffer deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas; + private final MappedByteBuffer deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi; + private final MappedByteBuffer deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode; + private final MappedByteBuffer deploymentStatusNewXorMxpFlagXorCallPrcFailureXorConFlagXorFinalInTxn; + private final MappedByteBuffer deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution; private final MappedByteBuffer domStamp; private final MappedByteBuffer exceptionAhoy; - private final MappedByteBuffer - existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf; - private final MappedByteBuffer - existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk; - private final MappedByteBuffer - finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn; - private final MappedByteBuffer - finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorValueCurrChanges; - private final MappedByteBuffer - finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorValueCurrIsOrig; - private final MappedByteBuffer - firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrIsZero; - private final MappedByteBuffer firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueNextIsCurr; - private final MappedByteBuffer - firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueNextIsOrig; + private final MappedByteBuffer existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf; + private final MappedByteBuffer existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk; + private final MappedByteBuffer finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn; + private final MappedByteBuffer finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorUnconstrainedFinal; + private final MappedByteBuffer finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorUnconstrainedFirst; + private final MappedByteBuffer firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrChanges; + private final MappedByteBuffer firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueCurrIsOrig; + private final MappedByteBuffer firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueCurrIsZero; private final MappedByteBuffer gasActual; private final MappedByteBuffer gasCost; private final MappedByteBuffer gasExpected; private final MappedByteBuffer gasLimit; private final MappedByteBuffer gasNext; private final MappedByteBuffer gasPrice; - private final MappedByteBuffer hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueOrigIsZero; - private final MappedByteBuffer - hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsZero; + private final MappedByteBuffer hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueNextIsOrig; + private final MappedByteBuffer hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsCurr; private final MappedByteBuffer height; private final MappedByteBuffer heightNew; private final MappedByteBuffer hubStamp; private final MappedByteBuffer hubStampTransactionEnd; private final MappedByteBuffer instruction; - private final MappedByteBuffer isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorWarmth; + private final MappedByteBuffer isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorValueNextIsZero; private final MappedByteBuffer logInfoStamp; - private final MappedByteBuffer - markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpx; - private final MappedByteBuffer - markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorWarmthNew; + private final MappedByteBuffer markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpxXorWarmth; + private final MappedByteBuffer markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorValueOrigIsZero; private final MappedByteBuffer mmuStamp; private final MappedByteBuffer mxpOffset2Hi; private final MappedByteBuffer mxpOffset2Lo; @@ -142,6 +117,8 @@ public class Trace { private final MappedByteBuffer mxpSize2Lo; private final MappedByteBuffer mxpStamp; private final MappedByteBuffer mxpWords; + private final MappedByteBuffer nbAdded; + private final MappedByteBuffer nbRemoved; private final MappedByteBuffer nonStackRows; private final MappedByteBuffer nonce; private final MappedByteBuffer nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable; @@ -194,10 +171,8 @@ public class Trace { private final MappedByteBuffer returnFromMessageCallWillTouchRamXorStackItemPop3; private final MappedByteBuffer returnFromMessageCallWontTouchRamXorStackItemPop4; private final MappedByteBuffer rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize; - private final MappedByteBuffer - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi; - private final MappedByteBuffer - rlpaddrFlagXorCreateNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequired; + private final MappedByteBuffer rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi; + private final MappedByteBuffer rlpaddrFlagXorCreateNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequiredXorWarmthNew; private final MappedByteBuffer rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo; private final MappedByteBuffer rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2; private final MappedByteBuffer rlpaddrRecipe; @@ -236,401 +211,200 @@ public class Trace { private final MappedByteBuffer wcpFlag; static List headers(int length) { - List headers = new ArrayList<>(); - headers.add(new ColumnHeader("hub.ABSOLUTE_TRANSACTION_NUMBER", 2, length)); - headers.add( - new ColumnHeader( - "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_CALL_DATA_SIZE", - 4, - length)); - headers.add( - new ColumnHeader( - "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO", - 16, - length)); - headers.add( - new ColumnHeader( - "hub.AGAIN_IN_BLK_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_WILL_REVERT_xor_ACC_FLAG_xor_AGAIN_IN_BLK_xor_COPY_TXCD", - 1, - length)); - headers.add( - new ColumnHeader( - "hub.AGAIN_IN_CNF_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_ABORT_WONT_REVERT_xor_ADD_FLAG_xor_AGAIN_IN_CNF_xor_IS_DEPLOYMENT", - 1, - length)); - headers.add( - new ColumnHeader( - "hub.AGAIN_IN_TXN_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_BIN_FLAG_xor_AGAIN_IN_TXN_xor_IS_TYPE2", - 1, - length)); - headers.add(new ColumnHeader("hub.ALPHA", 1, length)); - headers.add( - new ColumnHeader( - "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE", - 16, - length)); - headers.add( - new ColumnHeader( - "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO", - 16, - length)); - headers.add(new ColumnHeader("hub.CALL_DATA_OFFSET_xor_MMU_SIZE", 4, length)); - headers.add(new ColumnHeader("hub.CALL_DATA_SIZE_xor_MMU_SRC_ID", 4, length)); - headers.add(new ColumnHeader("hub.CALL_STACK_DEPTH_xor_STACK_ITEM_HEIGHT_1", 2, length)); - headers.add(new ColumnHeader("hub.CALLER_CONTEXT_NUMBER", 4, length)); - headers.add(new ColumnHeader("hub.CODE_FRAGMENT_INDEX", 4, length)); - headers.add( - new ColumnHeader( - "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_COINBASE_ADDRESS_HI", - 4, - length)); - headers.add( - new ColumnHeader( - "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_STACK_ITEM_VALUE_HI_1_xor_VALUE_CURR_LO_xor_VALUE", - 16, - length)); - headers.add( - new ColumnHeader( - "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO", - 16, - length)); - headers.add( - new ColumnHeader( - "hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_STACK_ITEM_VALUE_HI_3_xor_VALUE_NEXT_LO", - 16, - length)); - headers.add( - new ColumnHeader( - "hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_STACK_ITEM_VALUE_HI_2_xor_VALUE_NEXT_HI", - 16, - length)); - headers.add( - new ColumnHeader( - "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_INIT_CODE_SIZE", - 4, - length)); - headers.add( - new ColumnHeader( - "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_FROM_ADDRESS_HI", - 4, - length)); - headers.add(new ColumnHeader("hub.CONTEXT_GETS_REVERTED", 1, length)); - headers.add(new ColumnHeader("hub.CONTEXT_MAY_CHANGE", 1, length)); - headers.add(new ColumnHeader("hub.CONTEXT_NUMBER", 4, length)); - headers.add(new ColumnHeader("hub.CONTEXT_NUMBER_NEW", 4, length)); - headers.add(new ColumnHeader("hub.CONTEXT_NUMBER_xor_MMU_TGT_ID", 4, length)); - headers.add(new ColumnHeader("hub.CONTEXT_REVERT_STAMP", 4, length)); - headers.add(new ColumnHeader("hub.CONTEXT_SELF_REVERTS", 1, length)); - headers.add(new ColumnHeader("hub.CONTEXT_WILL_REVERT", 1, length)); - headers.add(new ColumnHeader("hub.COUNTER_NSR", 1, length)); - headers.add(new ColumnHeader("hub.COUNTER_TLI", 1, length)); - headers.add(new ColumnHeader("hub.DELTA", 1, length)); - headers.add( - new ColumnHeader( - "hub.DEPLOYMENT_NUMBER_FINAL_IN_BLOCK_xor_DEPLOYMENT_NUMBER_FINAL_IN_BLOCK", - 2, - length)); - headers.add( - new ColumnHeader( - "hub.DEPLOYMENT_NUMBER_FIRST_IN_BLOCK_xor_DEPLOYMENT_NUMBER_FIRST_IN_BLOCK", - 2, - length)); - headers.add( - new ColumnHeader( - "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO", - 4, - length)); - headers.add( - new ColumnHeader( - "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS", - 4, - length)); - headers.add( - new ColumnHeader( - "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_TO_ADDRESS_HI", - 4, - length)); - headers.add( - new ColumnHeader( - "hub.DEPLOYMENT_STATUS_INFTY_xor_MXP_DEPLOYS_xor_CALL_EXCEPTION_xor_CALL_FLAG_xor_FINAL_IN_CNF_xor_STATUS_CODE", - 1, - length)); - headers.add( - new ColumnHeader( - "hub.DEPLOYMENT_STATUS_NEW_xor_MXP_FLAG_xor_CALL_PRC_FAILURE_xor_CON_FLAG_xor_FINAL_IN_TXN", - 1, - length)); - headers.add( - new ColumnHeader( - "hub.DEPLOYMENT_STATUS_xor_MMU_SUCCESS_BIT_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BTC_FLAG_xor_FINAL_IN_BLK_xor_REQUIRES_EVM_EXECUTION", - 1, - length)); - headers.add(new ColumnHeader("hub.DOM_STAMP", 4, length)); - headers.add(new ColumnHeader("hub.EXCEPTION_AHOY", 1, length)); - headers.add( - new ColumnHeader( - "hub.EXISTS_NEW_xor_MXP_MXPX_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_CREATE_FLAG_xor_FIRST_IN_CNF", - 1, - length)); - headers.add( - new ColumnHeader( - "hub.EXISTS_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_COPY_FLAG_xor_FIRST_IN_BLK", - 1, - length)); - headers.add( - new ColumnHeader( - "hub.FINAL_IN_BLK_xor_MXP_SIZE_1_NONZERO_NO_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_DEC_FLAG_1_xor_FIRST_IN_TXN", - 1, - length)); - headers.add( - new ColumnHeader( - "hub.FINAL_IN_CNF_xor_MXP_SIZE_2_NONZERO_NO_MXPX_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_2_xor_VALUE_CURR_CHANGES", - 1, - length)); - headers.add( - new ColumnHeader( - "hub.FINAL_IN_TXN_xor_OOB_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_3_xor_VALUE_CURR_IS_ORIG", - 1, - length)); - headers.add( - new ColumnHeader( - "hub.FIRST_IN_BLK_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_4_xor_VALUE_CURR_IS_ZERO", - 1, - length)); - headers.add( - new ColumnHeader( - "hub.FIRST_IN_CNF_xor_STP_FLAG_xor_CREATE_ABORT_xor_DUP_FLAG_xor_VALUE_NEXT_IS_CURR", - 1, - length)); - headers.add( - new ColumnHeader( - "hub.FIRST_IN_TXN_xor_STP_OOGX_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_EXT_FLAG_xor_VALUE_NEXT_IS_ORIG", - 1, - length)); - headers.add(new ColumnHeader("hub.GAS_ACTUAL", 8, length)); - headers.add(new ColumnHeader("hub.GAS_COST", 8, length)); - headers.add(new ColumnHeader("hub.GAS_EXPECTED", 8, length)); - headers.add(new ColumnHeader("hub.GAS_LIMIT", 8, length)); - headers.add(new ColumnHeader("hub.GAS_NEXT", 8, length)); - headers.add(new ColumnHeader("hub.GAS_PRICE", 8, length)); - headers.add( - new ColumnHeader( - "hub.HAS_CODE_NEW_xor_CREATE_EXCEPTION_xor_HASH_INFO_FLAG_xor_VALUE_ORIG_IS_ZERO", - 1, - length)); - headers.add( - new ColumnHeader( - "hub.HAS_CODE_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_HALT_FLAG_xor_VALUE_NEXT_IS_ZERO", - 1, - length)); - headers.add(new ColumnHeader("hub.HEIGHT", 2, length)); - headers.add(new ColumnHeader("hub.HEIGHT_NEW", 2, length)); - headers.add(new ColumnHeader("hub.HUB_STAMP", 4, length)); - headers.add(new ColumnHeader("hub.HUB_STAMP_TRANSACTION_END", 4, length)); - headers.add(new ColumnHeader("hub.INSTRUCTION", 32, length)); - headers.add( - new ColumnHeader( - "hub.IS_PRECOMPILE_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_ICPX_xor_WARMTH", - 1, - length)); - headers.add(new ColumnHeader("hub.LOG_INFO_STAMP", 4, length)); - headers.add( - new ColumnHeader( - "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_JUMPX", - 1, - length)); - headers.add( - new ColumnHeader( - "hub.MARKED_FOR_SELFDESTRUCT_xor_CREATE_FAILURE_CONDITION_WONT_REVERT_xor_INVALID_FLAG_xor_WARMTH_NEW", - 1, - length)); - headers.add(new ColumnHeader("hub.MMU_STAMP", 4, length)); - headers.add(new ColumnHeader("hub.MXP_OFFSET_2_HI", 16, length)); - headers.add(new ColumnHeader("hub.MXP_OFFSET_2_LO", 16, length)); - headers.add(new ColumnHeader("hub.MXP_SIZE_1_HI", 16, length)); - headers.add(new ColumnHeader("hub.MXP_SIZE_1_LO", 16, length)); - headers.add(new ColumnHeader("hub.MXP_SIZE_2_HI", 16, length)); - headers.add(new ColumnHeader("hub.MXP_SIZE_2_LO", 16, length)); - headers.add(new ColumnHeader("hub.MXP_STAMP", 4, length)); - headers.add(new ColumnHeader("hub.MXP_WORDS", 16, length)); - headers.add(new ColumnHeader("hub.NON_STACK_ROWS", 1, length)); - headers.add(new ColumnHeader("hub.NONCE", 8, length)); - headers.add( - new ColumnHeader( - "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE", 8, length)); - headers.add(new ColumnHeader("hub.NONCE_xor_STP_GAS_MXP_xor_BASEFEE", 8, length)); - headers.add(new ColumnHeader("hub.OOB_DATA_1", 16, length)); - headers.add(new ColumnHeader("hub.OOB_DATA_2", 16, length)); - headers.add(new ColumnHeader("hub.OOB_DATA_3", 16, length)); - headers.add(new ColumnHeader("hub.OOB_DATA_4", 16, length)); - headers.add(new ColumnHeader("hub.OOB_DATA_5", 16, length)); - headers.add(new ColumnHeader("hub.OOB_DATA_6", 16, length)); - headers.add(new ColumnHeader("hub.OOB_DATA_7", 16, length)); - headers.add(new ColumnHeader("hub.OOB_DATA_8", 16, length)); - headers.add(new ColumnHeader("hub.OOB_DATA_9", 16, length)); - headers.add(new ColumnHeader("hub.PEEK_AT_ACCOUNT", 1, length)); - headers.add(new ColumnHeader("hub.PEEK_AT_CONTEXT", 1, length)); - headers.add(new ColumnHeader("hub.PEEK_AT_MISCELLANEOUS", 1, length)); - headers.add(new ColumnHeader("hub.PEEK_AT_SCENARIO", 1, length)); - headers.add(new ColumnHeader("hub.PEEK_AT_STACK", 1, length)); - headers.add(new ColumnHeader("hub.PEEK_AT_STORAGE", 1, length)); - headers.add(new ColumnHeader("hub.PEEK_AT_TRANSACTION", 1, length)); - headers.add(new ColumnHeader("hub.PRC_ECMUL_xor_MACHINE_STATE_FLAG", 1, length)); - headers.add(new ColumnHeader("hub.PRC_ECPAIRING_xor_MAXCSX", 1, length)); - headers.add(new ColumnHeader("hub.PRC_ECRECOVER_xor_MOD_FLAG", 1, length)); - headers.add(new ColumnHeader("hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MUL_FLAG", 1, length)); - headers.add(new ColumnHeader("hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MXPX", 1, length)); - headers.add(new ColumnHeader("hub.PRC_IDENTITY_xor_MXP_FLAG", 1, length)); - headers.add(new ColumnHeader("hub.PRC_MODEXP_xor_OOGX", 1, length)); - headers.add(new ColumnHeader("hub.PRC_RIPEMD-160_xor_OPCX", 1, length)); - headers.add(new ColumnHeader("hub.PRC_SHA2-256_xor_PUSHPOP_FLAG", 1, length)); - headers.add(new ColumnHeader("hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_RDCX", 1, length)); - headers.add(new ColumnHeader("hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_SHF_FLAG", 1, length)); - headers.add(new ColumnHeader("hub.PRIORITY_FEE_PER_GAS", 8, length)); - headers.add(new ColumnHeader("hub.PROGRAM_COUNTER", 4, length)); - headers.add(new ColumnHeader("hub.PROGRAM_COUNTER_NEW", 4, length)); - headers.add(new ColumnHeader("hub.REFUND_COUNTER", 4, length)); - headers.add(new ColumnHeader("hub.REFUND_COUNTER_INFINITY", 8, length)); - headers.add(new ColumnHeader("hub.REFUND_COUNTER_NEW", 4, length)); - headers.add(new ColumnHeader("hub.REFUND_EFFECTIVE", 8, length)); - headers.add(new ColumnHeader("hub.RELATIVE_BLOCK_NUMBER", 2, length)); - headers.add(new ColumnHeader("hub.RETURN_AT_CAPACITY_xor_MXP_INST", 4, length)); - headers.add(new ColumnHeader("hub.RETURN_AT_OFFSET_xor_OOB_INST", 4, length)); - headers.add(new ColumnHeader("hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND", 4, length)); - headers.add(new ColumnHeader("hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION", 4, length)); - headers.add(new ColumnHeader("hub.RETURN_DATA_SIZE", 4, length)); - headers.add(new ColumnHeader("hub.RETURN_EXCEPTION_xor_SOX", 1, length)); - headers.add( - new ColumnHeader( - "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SSTOREX", 1, length)); - headers.add( - new ColumnHeader( - "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_STACKRAM_FLAG", 1, length)); - headers.add( - new ColumnHeader( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACK_ITEM_POP_1", - 1, - length)); - headers.add( - new ColumnHeader( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_2", - 1, - length)); - headers.add( - new ColumnHeader( - "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length)); - headers.add( - new ColumnHeader( - "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_4", 1, length)); - headers.add( - new ColumnHeader( - "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 4, length)); - headers.add( - new ColumnHeader( - "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_STACK_ITEM_VALUE_HI_4_xor_VALUE_ORIG_HI", - 16, - length)); - headers.add( - new ColumnHeader( - "hub.RLPADDR_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED", - 1, - length)); - headers.add( - new ColumnHeader( - "hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_STACK_ITEM_VALUE_LO_1_xor_VALUE_ORIG_LO", - 16, - length)); - headers.add( - new ColumnHeader( - "hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO_xor_STACK_ITEM_VALUE_LO_2", 16, length)); - headers.add(new ColumnHeader("hub.RLPADDR_RECIPE", 1, length)); - headers.add( - new ColumnHeader( - "hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP_xor_STACK_ITEM_VALUE_LO_3", 16, length)); - headers.add( - new ColumnHeader( - "hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI_xor_STACK_ITEM_VALUE_LO_4", 16, length)); - headers.add( - new ColumnHeader( - "hub.ROMLEX_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_FLAG", - 1, - length)); - headers.add(new ColumnHeader("hub.SELFDESTRUCT_EXCEPTION_xor_STATICX", 1, length)); - headers.add(new ColumnHeader("hub.SELFDESTRUCT_WILL_REVERT_xor_STATIC_FLAG", 1, length)); - headers.add( - new ColumnHeader("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STO_FLAG", 1, length)); - headers.add(new ColumnHeader("hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_SUX", 1, length)); - headers.add(new ColumnHeader("hub.STACK_ITEM_HEIGHT_2", 2, length)); - headers.add(new ColumnHeader("hub.STACK_ITEM_HEIGHT_3", 2, length)); - headers.add(new ColumnHeader("hub.STACK_ITEM_HEIGHT_4", 2, length)); - headers.add(new ColumnHeader("hub.STACK_ITEM_STAMP_1", 5, length)); - headers.add(new ColumnHeader("hub.STACK_ITEM_STAMP_2", 5, length)); - headers.add(new ColumnHeader("hub.STACK_ITEM_STAMP_3", 5, length)); - headers.add(new ColumnHeader("hub.STACK_ITEM_STAMP_4", 5, length)); - headers.add(new ColumnHeader("hub.STP_GAS_HI", 16, length)); - headers.add(new ColumnHeader("hub.STP_GAS_LO", 16, length)); - headers.add(new ColumnHeader("hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER", 8, length)); - headers.add(new ColumnHeader("hub.STP_VALUE_HI", 16, length)); - headers.add(new ColumnHeader("hub.STP_VALUE_LO", 16, length)); - headers.add(new ColumnHeader("hub.SUB_STAMP", 4, length)); - headers.add(new ColumnHeader("hub.SWAP_FLAG", 1, length)); - headers.add( - new ColumnHeader( - "hub.TRM_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_KEC_FLAG", - 1, - length)); - headers.add(new ColumnHeader("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO", 16, length)); - headers.add(new ColumnHeader("hub.TWO_LINE_INSTRUCTION", 1, length)); - headers.add(new ColumnHeader("hub.TX_EXEC", 1, length)); - headers.add(new ColumnHeader("hub.TX_FINL", 1, length)); - headers.add(new ColumnHeader("hub.TX_INIT", 1, length)); - headers.add(new ColumnHeader("hub.TX_SKIP", 1, length)); - headers.add(new ColumnHeader("hub.TX_WARM", 1, length)); - headers.add(new ColumnHeader("hub.TXN_FLAG", 1, length)); - headers.add(new ColumnHeader("hub.WARMTH_NEW_xor_PRC_ECADD_xor_LOG_INFO_FLAG", 1, length)); - headers.add(new ColumnHeader("hub.WARMTH_xor_PRC_BLAKE2f_xor_LOG_FLAG", 1, length)); - headers.add(new ColumnHeader("hub.WCP_FLAG", 1, length)); - return headers; - } - - public Trace(List buffers) { + List headers = new ArrayList<>(); + headers.add(new ColumnHeader("hub.ABSOLUTE_TRANSACTION_NUMBER", 2, length)); + headers.add(new ColumnHeader("hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_CALL_DATA_SIZE", 4, length)); + headers.add(new ColumnHeader("hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO", 16, length)); + headers.add(new ColumnHeader("hub.AGAIN_IN_BLK_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_WILL_REVERT_xor_ACC_FLAG_xor_AGAIN_IN_BLK_xor_COPY_TXCD", 1, length)); + headers.add(new ColumnHeader("hub.AGAIN_IN_CNF_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_ABORT_WONT_REVERT_xor_ADD_FLAG_xor_AGAIN_IN_CNF_xor_IS_DEPLOYMENT", 1, length)); + headers.add(new ColumnHeader("hub.AGAIN_IN_TXN_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_BIN_FLAG_xor_AGAIN_IN_TXN_xor_IS_TYPE2", 1, length)); + headers.add(new ColumnHeader("hub.ALPHA", 1, length)); + headers.add(new ColumnHeader("hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE", 16, length)); + headers.add(new ColumnHeader("hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO", 16, length)); + headers.add(new ColumnHeader("hub.CALL_DATA_OFFSET_xor_MMU_SIZE", 4, length)); + headers.add(new ColumnHeader("hub.CALL_DATA_SIZE_xor_MMU_SRC_ID", 4, length)); + headers.add(new ColumnHeader("hub.CALL_STACK_DEPTH_xor_STACK_ITEM_HEIGHT_1", 2, length)); + headers.add(new ColumnHeader("hub.CALLER_CONTEXT_NUMBER", 4, length)); + headers.add(new ColumnHeader("hub.CODE_FRAGMENT_INDEX", 4, length)); + headers.add(new ColumnHeader("hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_COINBASE_ADDRESS_HI", 4, length)); + headers.add(new ColumnHeader("hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_STACK_ITEM_VALUE_HI_1_xor_VALUE_CURR_LO_xor_VALUE", 16, length)); + headers.add(new ColumnHeader("hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO", 16, length)); + headers.add(new ColumnHeader("hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_STACK_ITEM_VALUE_HI_3_xor_VALUE_NEXT_LO", 16, length)); + headers.add(new ColumnHeader("hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_STACK_ITEM_VALUE_HI_2_xor_VALUE_NEXT_HI", 16, length)); + headers.add(new ColumnHeader("hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_INIT_CODE_SIZE", 4, length)); + headers.add(new ColumnHeader("hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_FROM_ADDRESS_HI", 4, length)); + headers.add(new ColumnHeader("hub.CONTEXT_GETS_REVERTED", 1, length)); + headers.add(new ColumnHeader("hub.CONTEXT_MAY_CHANGE", 1, length)); + headers.add(new ColumnHeader("hub.CONTEXT_NUMBER", 4, length)); + headers.add(new ColumnHeader("hub.CONTEXT_NUMBER_NEW", 4, length)); + headers.add(new ColumnHeader("hub.CONTEXT_NUMBER_xor_MMU_TGT_ID", 4, length)); + headers.add(new ColumnHeader("hub.CONTEXT_REVERT_STAMP", 4, length)); + headers.add(new ColumnHeader("hub.CONTEXT_SELF_REVERTS", 1, length)); + headers.add(new ColumnHeader("hub.CONTEXT_WILL_REVERT", 1, length)); + headers.add(new ColumnHeader("hub.COUNTER_NSR", 1, length)); + headers.add(new ColumnHeader("hub.COUNTER_TLI", 1, length)); + headers.add(new ColumnHeader("hub.DELTA", 1, length)); + headers.add(new ColumnHeader("hub.DEPLOYMENT_NUMBER_FINAL_IN_BLOCK_xor_DEPLOYMENT_NUMBER_FINAL_IN_BLOCK", 2, length)); + headers.add(new ColumnHeader("hub.DEPLOYMENT_NUMBER_FIRST_IN_BLOCK_xor_DEPLOYMENT_NUMBER_FIRST_IN_BLOCK", 2, length)); + headers.add(new ColumnHeader("hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO", 4, length)); + headers.add(new ColumnHeader("hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS", 4, length)); + headers.add(new ColumnHeader("hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_TO_ADDRESS_HI", 4, length)); + headers.add(new ColumnHeader("hub.DEPLOYMENT_STATUS_INFTY_xor_MXP_DEPLOYS_xor_CALL_EXCEPTION_xor_CALL_FLAG_xor_FINAL_IN_CNF_xor_STATUS_CODE", 1, length)); + headers.add(new ColumnHeader("hub.DEPLOYMENT_STATUS_NEW_xor_MXP_FLAG_xor_CALL_PRC_FAILURE_xor_CON_FLAG_xor_FINAL_IN_TXN", 1, length)); + headers.add(new ColumnHeader("hub.DEPLOYMENT_STATUS_xor_MMU_SUCCESS_BIT_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BTC_FLAG_xor_FINAL_IN_BLK_xor_REQUIRES_EVM_EXECUTION", 1, length)); + headers.add(new ColumnHeader("hub.DOM_STAMP", 4, length)); + headers.add(new ColumnHeader("hub.EXCEPTION_AHOY", 1, length)); + headers.add(new ColumnHeader("hub.EXISTS_NEW_xor_MXP_MXPX_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_CREATE_FLAG_xor_FIRST_IN_CNF", 1, length)); + headers.add(new ColumnHeader("hub.EXISTS_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_COPY_FLAG_xor_FIRST_IN_BLK", 1, length)); + headers.add(new ColumnHeader("hub.FINAL_IN_BLK_xor_MXP_SIZE_1_NONZERO_NO_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_DEC_FLAG_1_xor_FIRST_IN_TXN", 1, length)); + headers.add(new ColumnHeader("hub.FINAL_IN_CNF_xor_MXP_SIZE_2_NONZERO_NO_MXPX_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_2_xor_UNCONSTRAINED_FINAL", 1, length)); + headers.add(new ColumnHeader("hub.FINAL_IN_TXN_xor_OOB_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_3_xor_UNCONSTRAINED_FIRST", 1, length)); + headers.add(new ColumnHeader("hub.FIRST_IN_BLK_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_4_xor_VALUE_CURR_CHANGES", 1, length)); + headers.add(new ColumnHeader("hub.FIRST_IN_CNF_xor_STP_FLAG_xor_CREATE_ABORT_xor_DUP_FLAG_xor_VALUE_CURR_IS_ORIG", 1, length)); + headers.add(new ColumnHeader("hub.FIRST_IN_TXN_xor_STP_OOGX_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_EXT_FLAG_xor_VALUE_CURR_IS_ZERO", 1, length)); + headers.add(new ColumnHeader("hub.GAS_ACTUAL", 8, length)); + headers.add(new ColumnHeader("hub.GAS_COST", 8, length)); + headers.add(new ColumnHeader("hub.GAS_EXPECTED", 8, length)); + headers.add(new ColumnHeader("hub.GAS_LIMIT", 8, length)); + headers.add(new ColumnHeader("hub.GAS_NEXT", 8, length)); + headers.add(new ColumnHeader("hub.GAS_PRICE", 8, length)); + headers.add(new ColumnHeader("hub.HAS_CODE_NEW_xor_CREATE_EXCEPTION_xor_HASH_INFO_FLAG_xor_VALUE_NEXT_IS_ORIG", 1, length)); + headers.add(new ColumnHeader("hub.HAS_CODE_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_HALT_FLAG_xor_VALUE_NEXT_IS_CURR", 1, length)); + headers.add(new ColumnHeader("hub.HEIGHT", 2, length)); + headers.add(new ColumnHeader("hub.HEIGHT_NEW", 2, length)); + headers.add(new ColumnHeader("hub.HUB_STAMP", 4, length)); + headers.add(new ColumnHeader("hub.HUB_STAMP_TRANSACTION_END", 4, length)); + headers.add(new ColumnHeader("hub.INSTRUCTION", 32, length)); + headers.add(new ColumnHeader("hub.IS_PRECOMPILE_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_ICPX_xor_VALUE_NEXT_IS_ZERO", 1, length)); + headers.add(new ColumnHeader("hub.LOG_INFO_STAMP", 4, length)); + headers.add(new ColumnHeader("hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_JUMPX_xor_WARMTH", 1, length)); + headers.add(new ColumnHeader("hub.MARKED_FOR_SELFDESTRUCT_xor_CREATE_FAILURE_CONDITION_WONT_REVERT_xor_INVALID_FLAG_xor_VALUE_ORIG_IS_ZERO", 1, length)); + headers.add(new ColumnHeader("hub.MMU_STAMP", 4, length)); + headers.add(new ColumnHeader("hub.MXP_OFFSET_2_HI", 16, length)); + headers.add(new ColumnHeader("hub.MXP_OFFSET_2_LO", 16, length)); + headers.add(new ColumnHeader("hub.MXP_SIZE_1_HI", 16, length)); + headers.add(new ColumnHeader("hub.MXP_SIZE_1_LO", 16, length)); + headers.add(new ColumnHeader("hub.MXP_SIZE_2_HI", 16, length)); + headers.add(new ColumnHeader("hub.MXP_SIZE_2_LO", 16, length)); + headers.add(new ColumnHeader("hub.MXP_STAMP", 4, length)); + headers.add(new ColumnHeader("hub.MXP_WORDS", 16, length)); + headers.add(new ColumnHeader("hub.NB_ADDED", 1, length)); + headers.add(new ColumnHeader("hub.NB_REMOVED", 1, length)); + headers.add(new ColumnHeader("hub.NON_STACK_ROWS", 1, length)); + headers.add(new ColumnHeader("hub.NONCE", 8, length)); + headers.add(new ColumnHeader("hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE", 8, length)); + headers.add(new ColumnHeader("hub.NONCE_xor_STP_GAS_MXP_xor_BASEFEE", 8, length)); + headers.add(new ColumnHeader("hub.OOB_DATA_1", 16, length)); + headers.add(new ColumnHeader("hub.OOB_DATA_2", 16, length)); + headers.add(new ColumnHeader("hub.OOB_DATA_3", 16, length)); + headers.add(new ColumnHeader("hub.OOB_DATA_4", 16, length)); + headers.add(new ColumnHeader("hub.OOB_DATA_5", 16, length)); + headers.add(new ColumnHeader("hub.OOB_DATA_6", 16, length)); + headers.add(new ColumnHeader("hub.OOB_DATA_7", 16, length)); + headers.add(new ColumnHeader("hub.OOB_DATA_8", 16, length)); + headers.add(new ColumnHeader("hub.OOB_DATA_9", 16, length)); + headers.add(new ColumnHeader("hub.PEEK_AT_ACCOUNT", 1, length)); + headers.add(new ColumnHeader("hub.PEEK_AT_CONTEXT", 1, length)); + headers.add(new ColumnHeader("hub.PEEK_AT_MISCELLANEOUS", 1, length)); + headers.add(new ColumnHeader("hub.PEEK_AT_SCENARIO", 1, length)); + headers.add(new ColumnHeader("hub.PEEK_AT_STACK", 1, length)); + headers.add(new ColumnHeader("hub.PEEK_AT_STORAGE", 1, length)); + headers.add(new ColumnHeader("hub.PEEK_AT_TRANSACTION", 1, length)); + headers.add(new ColumnHeader("hub.PRC_ECMUL_xor_MACHINE_STATE_FLAG", 1, length)); + headers.add(new ColumnHeader("hub.PRC_ECPAIRING_xor_MAXCSX", 1, length)); + headers.add(new ColumnHeader("hub.PRC_ECRECOVER_xor_MOD_FLAG", 1, length)); + headers.add(new ColumnHeader("hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MUL_FLAG", 1, length)); + headers.add(new ColumnHeader("hub.PRC_FAILURE_KNOWN_TO_RAM_xor_MXPX", 1, length)); + headers.add(new ColumnHeader("hub.PRC_IDENTITY_xor_MXP_FLAG", 1, length)); + headers.add(new ColumnHeader("hub.PRC_MODEXP_xor_OOGX", 1, length)); + headers.add(new ColumnHeader("hub.PRC_RIPEMD-160_xor_OPCX", 1, length)); + headers.add(new ColumnHeader("hub.PRC_SHA2-256_xor_PUSHPOP_FLAG", 1, length)); + headers.add(new ColumnHeader("hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_RDCX", 1, length)); + headers.add(new ColumnHeader("hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_SHF_FLAG", 1, length)); + headers.add(new ColumnHeader("hub.PRIORITY_FEE_PER_GAS", 8, length)); + headers.add(new ColumnHeader("hub.PROGRAM_COUNTER", 4, length)); + headers.add(new ColumnHeader("hub.PROGRAM_COUNTER_NEW", 4, length)); + headers.add(new ColumnHeader("hub.REFUND_COUNTER", 4, length)); + headers.add(new ColumnHeader("hub.REFUND_COUNTER_INFINITY", 8, length)); + headers.add(new ColumnHeader("hub.REFUND_COUNTER_NEW", 4, length)); + headers.add(new ColumnHeader("hub.REFUND_EFFECTIVE", 8, length)); + headers.add(new ColumnHeader("hub.RELATIVE_BLOCK_NUMBER", 2, length)); + headers.add(new ColumnHeader("hub.RETURN_AT_CAPACITY_xor_MXP_INST", 4, length)); + headers.add(new ColumnHeader("hub.RETURN_AT_OFFSET_xor_OOB_INST", 4, length)); + headers.add(new ColumnHeader("hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND", 4, length)); + headers.add(new ColumnHeader("hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION", 4, length)); + headers.add(new ColumnHeader("hub.RETURN_DATA_SIZE", 4, length)); + headers.add(new ColumnHeader("hub.RETURN_EXCEPTION_xor_SOX", 1, length)); + headers.add(new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SSTOREX", 1, length)); + headers.add(new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_STACKRAM_FLAG", 1, length)); + headers.add(new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACK_ITEM_POP_1", 1, length)); + headers.add(new ColumnHeader("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_2", 1, length)); + headers.add(new ColumnHeader("hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_3", 1, length)); + headers.add(new ColumnHeader("hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_4", 1, length)); + headers.add(new ColumnHeader("hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE", 4, length)); + headers.add(new ColumnHeader("hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_STACK_ITEM_VALUE_HI_4_xor_VALUE_ORIG_HI", 16, length)); + headers.add(new ColumnHeader("hub.RLPADDR_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED_xor_WARMTH_NEW", 1, length)); + headers.add(new ColumnHeader("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_STACK_ITEM_VALUE_LO_1_xor_VALUE_ORIG_LO", 16, length)); + headers.add(new ColumnHeader("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO_xor_STACK_ITEM_VALUE_LO_2", 16, length)); + headers.add(new ColumnHeader("hub.RLPADDR_RECIPE", 1, length)); + headers.add(new ColumnHeader("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP_xor_STACK_ITEM_VALUE_LO_3", 16, length)); + headers.add(new ColumnHeader("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI_xor_STACK_ITEM_VALUE_LO_4", 16, length)); + headers.add(new ColumnHeader("hub.ROMLEX_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_FLAG", 1, length)); + headers.add(new ColumnHeader("hub.SELFDESTRUCT_EXCEPTION_xor_STATICX", 1, length)); + headers.add(new ColumnHeader("hub.SELFDESTRUCT_WILL_REVERT_xor_STATIC_FLAG", 1, length)); + headers.add(new ColumnHeader("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STO_FLAG", 1, length)); + headers.add(new ColumnHeader("hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_SUX", 1, length)); + headers.add(new ColumnHeader("hub.STACK_ITEM_HEIGHT_2", 2, length)); + headers.add(new ColumnHeader("hub.STACK_ITEM_HEIGHT_3", 2, length)); + headers.add(new ColumnHeader("hub.STACK_ITEM_HEIGHT_4", 2, length)); + headers.add(new ColumnHeader("hub.STACK_ITEM_STAMP_1", 5, length)); + headers.add(new ColumnHeader("hub.STACK_ITEM_STAMP_2", 5, length)); + headers.add(new ColumnHeader("hub.STACK_ITEM_STAMP_3", 5, length)); + headers.add(new ColumnHeader("hub.STACK_ITEM_STAMP_4", 5, length)); + headers.add(new ColumnHeader("hub.STP_GAS_HI", 16, length)); + headers.add(new ColumnHeader("hub.STP_GAS_LO", 16, length)); + headers.add(new ColumnHeader("hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER", 8, length)); + headers.add(new ColumnHeader("hub.STP_VALUE_HI", 16, length)); + headers.add(new ColumnHeader("hub.STP_VALUE_LO", 16, length)); + headers.add(new ColumnHeader("hub.SUB_STAMP", 4, length)); + headers.add(new ColumnHeader("hub.SWAP_FLAG", 1, length)); + headers.add(new ColumnHeader("hub.TRM_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_KEC_FLAG", 1, length)); + headers.add(new ColumnHeader("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO", 16, length)); + headers.add(new ColumnHeader("hub.TWO_LINE_INSTRUCTION", 1, length)); + headers.add(new ColumnHeader("hub.TX_EXEC", 1, length)); + headers.add(new ColumnHeader("hub.TX_FINL", 1, length)); + headers.add(new ColumnHeader("hub.TX_INIT", 1, length)); + headers.add(new ColumnHeader("hub.TX_SKIP", 1, length)); + headers.add(new ColumnHeader("hub.TX_WARM", 1, length)); + headers.add(new ColumnHeader("hub.TXN_FLAG", 1, length)); + headers.add(new ColumnHeader("hub.WARMTH_NEW_xor_PRC_ECADD_xor_LOG_INFO_FLAG", 1, length)); + headers.add(new ColumnHeader("hub.WARMTH_xor_PRC_BLAKE2f_xor_LOG_FLAG", 1, length)); + headers.add(new ColumnHeader("hub.WCP_FLAG", 1, length)); + return headers; + } + + public Trace (List buffers) { this.absoluteTransactionNumber = buffers.get(0); - this - .addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize = - buffers.get(1); - this - .addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo = - buffers.get(2); - this.againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd = - buffers.get(3); - this - .againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment = - buffers.get(4); - this - .againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2 = - buffers.get(5); + this.addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize = buffers.get(1); + this.addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo = buffers.get(2); + this.againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd = buffers.get(3); + this.againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment = buffers.get(4); + this.againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2 = buffers.get(5); this.alpha = buffers.get(6); - this.balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance = - buffers.get(7); - this.balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo = - buffers.get(8); + this.balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance = buffers.get(7); + this.balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo = buffers.get(8); this.callDataOffsetXorMmuSize = buffers.get(9); this.callDataSizeXorMmuSrcId = buffers.get(10); this.callStackDepthXorStackItemHeight1 = buffers.get(11); this.callerContextNumber = buffers.get(12); this.codeFragmentIndex = buffers.get(13); - this - .codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi = - buffers.get(14); + this.codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi = buffers.get(14); this.codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue = buffers.get(15); - this.codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo = - buffers.get(16); + this.codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo = buffers.get(16); this.codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo = buffers.get(17); this.codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi = buffers.get(18); - this.codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize = - buffers.get(19); - this.codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi = - buffers.get(20); + this.codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize = buffers.get(19); + this.codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi = buffers.get(20); this.contextGetsReverted = buffers.get(21); this.contextMayChange = buffers.get(22); this.contextNumber = buffers.get(23); @@ -646,53 +420,37 @@ public Trace(List buffers) { this.deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock = buffers.get(33); this.deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao = buffers.get(34); this.deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas = buffers.get(35); - this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi = - buffers.get(36); - this.deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode = - buffers.get(37); + this.deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi = buffers.get(36); + this.deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode = buffers.get(37); this.deploymentStatusNewXorMxpFlagXorCallPrcFailureXorConFlagXorFinalInTxn = buffers.get(38); - this - .deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution = - buffers.get(39); + this.deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution = buffers.get(39); this.domStamp = buffers.get(40); this.exceptionAhoy = buffers.get(41); - this.existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf = - buffers.get(42); - this.existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk = - buffers.get(43); - this - .finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn = - buffers.get(44); - this - .finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorValueCurrChanges = - buffers.get(45); - this.finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorValueCurrIsOrig = - buffers.get(46); - this.firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrIsZero = - buffers.get(47); - this.firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueNextIsCurr = buffers.get(48); - this.firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueNextIsOrig = - buffers.get(49); + this.existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf = buffers.get(42); + this.existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk = buffers.get(43); + this.finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn = buffers.get(44); + this.finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorUnconstrainedFinal = buffers.get(45); + this.finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorUnconstrainedFirst = buffers.get(46); + this.firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrChanges = buffers.get(47); + this.firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueCurrIsOrig = buffers.get(48); + this.firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueCurrIsZero = buffers.get(49); this.gasActual = buffers.get(50); this.gasCost = buffers.get(51); this.gasExpected = buffers.get(52); this.gasLimit = buffers.get(53); this.gasNext = buffers.get(54); this.gasPrice = buffers.get(55); - this.hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueOrigIsZero = buffers.get(56); - this.hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsZero = - buffers.get(57); + this.hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueNextIsOrig = buffers.get(56); + this.hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsCurr = buffers.get(57); this.height = buffers.get(58); this.heightNew = buffers.get(59); this.hubStamp = buffers.get(60); this.hubStampTransactionEnd = buffers.get(61); this.instruction = buffers.get(62); - this.isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorWarmth = buffers.get(63); + this.isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorValueNextIsZero = buffers.get(63); this.logInfoStamp = buffers.get(64); - this.markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpx = - buffers.get(65); - this.markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorWarmthNew = - buffers.get(66); + this.markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpxXorWarmth = buffers.get(65); + this.markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorValueOrigIsZero = buffers.get(66); this.mmuStamp = buffers.get(67); this.mxpOffset2Hi = buffers.get(68); this.mxpOffset2Lo = buffers.get(69); @@ -702,97 +460,98 @@ public Trace(List buffers) { this.mxpSize2Lo = buffers.get(73); this.mxpStamp = buffers.get(74); this.mxpWords = buffers.get(75); - this.nonStackRows = buffers.get(76); - this.nonce = buffers.get(77); - this.nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable = buffers.get(78); - this.nonceXorStpGasMxpXorBasefee = buffers.get(79); - this.oobData1 = buffers.get(80); - this.oobData2 = buffers.get(81); - this.oobData3 = buffers.get(82); - this.oobData4 = buffers.get(83); - this.oobData5 = buffers.get(84); - this.oobData6 = buffers.get(85); - this.oobData7 = buffers.get(86); - this.oobData8 = buffers.get(87); - this.oobData9 = buffers.get(88); - this.peekAtAccount = buffers.get(89); - this.peekAtContext = buffers.get(90); - this.peekAtMiscellaneous = buffers.get(91); - this.peekAtScenario = buffers.get(92); - this.peekAtStack = buffers.get(93); - this.peekAtStorage = buffers.get(94); - this.peekAtTransaction = buffers.get(95); - this.prcEcmulXorMachineStateFlag = buffers.get(96); - this.prcEcpairingXorMaxcsx = buffers.get(97); - this.prcEcrecoverXorModFlag = buffers.get(98); - this.prcFailureKnownToHubXorMulFlag = buffers.get(99); - this.prcFailureKnownToRamXorMxpx = buffers.get(100); - this.prcIdentityXorMxpFlag = buffers.get(101); - this.prcModexpXorOogx = buffers.get(102); - this.prcRipemd160XorOpcx = buffers.get(103); - this.prcSha2256XorPushpopFlag = buffers.get(104); - this.prcSuccessCallerWillRevertXorRdcx = buffers.get(105); - this.prcSuccessCallerWontRevertXorShfFlag = buffers.get(106); - this.priorityFeePerGas = buffers.get(107); - this.programCounter = buffers.get(108); - this.programCounterNew = buffers.get(109); - this.refundCounter = buffers.get(110); - this.refundCounterInfinity = buffers.get(111); - this.refundCounterNew = buffers.get(112); - this.refundEffective = buffers.get(113); - this.relativeBlockNumber = buffers.get(114); - this.returnAtCapacityXorMxpInst = buffers.get(115); - this.returnAtOffsetXorOobInst = buffers.get(116); - this.returnDataContextNumberXorStpGasStipend = buffers.get(117); - this.returnDataOffsetXorStpInstruction = buffers.get(118); - this.returnDataSize = buffers.get(119); - this.returnExceptionXorSox = buffers.get(120); - this.returnFromDeploymentEmptyCodeWillRevertXorSstorex = buffers.get(121); - this.returnFromDeploymentEmptyCodeWontRevertXorStackramFlag = buffers.get(122); - this.returnFromDeploymentNonemptyCodeWillRevertXorStackItemPop1 = buffers.get(123); - this.returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop2 = buffers.get(124); - this.returnFromMessageCallWillTouchRamXorStackItemPop3 = buffers.get(125); - this.returnFromMessageCallWontTouchRamXorStackItemPop4 = buffers.get(126); - this.rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize = buffers.get(127); - this.rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi = buffers.get(128); - this.rlpaddrFlagXorCreateNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequired = - buffers.get(129); - this.rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo = buffers.get(130); - this.rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2 = buffers.get(131); - this.rlpaddrRecipe = buffers.get(132); - this.rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3 = buffers.get(133); - this.rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4 = buffers.get(134); - this.romlexFlagXorCreateNonemptyInitCodeSuccessWillRevertXorJumpFlag = buffers.get(135); - this.selfdestructExceptionXorStaticx = buffers.get(136); - this.selfdestructWillRevertXorStaticFlag = buffers.get(137); - this.selfdestructWontRevertAlreadyMarkedXorStoFlag = buffers.get(138); - this.selfdestructWontRevertNotYetMarkedXorSux = buffers.get(139); - this.stackItemHeight2 = buffers.get(140); - this.stackItemHeight3 = buffers.get(141); - this.stackItemHeight4 = buffers.get(142); - this.stackItemStamp1 = buffers.get(143); - this.stackItemStamp2 = buffers.get(144); - this.stackItemStamp3 = buffers.get(145); - this.stackItemStamp4 = buffers.get(146); - this.stpGasHi = buffers.get(147); - this.stpGasLo = buffers.get(148); - this.stpGasUpfrontGasCostXorGasLeftover = buffers.get(149); - this.stpValueHi = buffers.get(150); - this.stpValueLo = buffers.get(151); - this.subStamp = buffers.get(152); - this.swapFlag = buffers.get(153); - this.trmFlagXorCreateNonemptyInitCodeSuccessWontRevertXorKecFlag = buffers.get(154); - this.trmRawAddressHiXorMxpOffset1Lo = buffers.get(155); - this.twoLineInstruction = buffers.get(156); - this.txExec = buffers.get(157); - this.txFinl = buffers.get(158); - this.txInit = buffers.get(159); - this.txSkip = buffers.get(160); - this.txWarm = buffers.get(161); - this.txnFlag = buffers.get(162); - this.warmthNewXorPrcEcaddXorLogInfoFlag = buffers.get(163); - this.warmthXorPrcBlake2FXorLogFlag = buffers.get(164); - this.wcpFlag = buffers.get(165); + this.nbAdded = buffers.get(76); + this.nbRemoved = buffers.get(77); + this.nonStackRows = buffers.get(78); + this.nonce = buffers.get(79); + this.nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable = buffers.get(80); + this.nonceXorStpGasMxpXorBasefee = buffers.get(81); + this.oobData1 = buffers.get(82); + this.oobData2 = buffers.get(83); + this.oobData3 = buffers.get(84); + this.oobData4 = buffers.get(85); + this.oobData5 = buffers.get(86); + this.oobData6 = buffers.get(87); + this.oobData7 = buffers.get(88); + this.oobData8 = buffers.get(89); + this.oobData9 = buffers.get(90); + this.peekAtAccount = buffers.get(91); + this.peekAtContext = buffers.get(92); + this.peekAtMiscellaneous = buffers.get(93); + this.peekAtScenario = buffers.get(94); + this.peekAtStack = buffers.get(95); + this.peekAtStorage = buffers.get(96); + this.peekAtTransaction = buffers.get(97); + this.prcEcmulXorMachineStateFlag = buffers.get(98); + this.prcEcpairingXorMaxcsx = buffers.get(99); + this.prcEcrecoverXorModFlag = buffers.get(100); + this.prcFailureKnownToHubXorMulFlag = buffers.get(101); + this.prcFailureKnownToRamXorMxpx = buffers.get(102); + this.prcIdentityXorMxpFlag = buffers.get(103); + this.prcModexpXorOogx = buffers.get(104); + this.prcRipemd160XorOpcx = buffers.get(105); + this.prcSha2256XorPushpopFlag = buffers.get(106); + this.prcSuccessCallerWillRevertXorRdcx = buffers.get(107); + this.prcSuccessCallerWontRevertXorShfFlag = buffers.get(108); + this.priorityFeePerGas = buffers.get(109); + this.programCounter = buffers.get(110); + this.programCounterNew = buffers.get(111); + this.refundCounter = buffers.get(112); + this.refundCounterInfinity = buffers.get(113); + this.refundCounterNew = buffers.get(114); + this.refundEffective = buffers.get(115); + this.relativeBlockNumber = buffers.get(116); + this.returnAtCapacityXorMxpInst = buffers.get(117); + this.returnAtOffsetXorOobInst = buffers.get(118); + this.returnDataContextNumberXorStpGasStipend = buffers.get(119); + this.returnDataOffsetXorStpInstruction = buffers.get(120); + this.returnDataSize = buffers.get(121); + this.returnExceptionXorSox = buffers.get(122); + this.returnFromDeploymentEmptyCodeWillRevertXorSstorex = buffers.get(123); + this.returnFromDeploymentEmptyCodeWontRevertXorStackramFlag = buffers.get(124); + this.returnFromDeploymentNonemptyCodeWillRevertXorStackItemPop1 = buffers.get(125); + this.returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop2 = buffers.get(126); + this.returnFromMessageCallWillTouchRamXorStackItemPop3 = buffers.get(127); + this.returnFromMessageCallWontTouchRamXorStackItemPop4 = buffers.get(128); + this.rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize = buffers.get(129); + this.rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi = buffers.get(130); + this.rlpaddrFlagXorCreateNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequiredXorWarmthNew = buffers.get(131); + this.rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo = buffers.get(132); + this.rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2 = buffers.get(133); + this.rlpaddrRecipe = buffers.get(134); + this.rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3 = buffers.get(135); + this.rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4 = buffers.get(136); + this.romlexFlagXorCreateNonemptyInitCodeSuccessWillRevertXorJumpFlag = buffers.get(137); + this.selfdestructExceptionXorStaticx = buffers.get(138); + this.selfdestructWillRevertXorStaticFlag = buffers.get(139); + this.selfdestructWontRevertAlreadyMarkedXorStoFlag = buffers.get(140); + this.selfdestructWontRevertNotYetMarkedXorSux = buffers.get(141); + this.stackItemHeight2 = buffers.get(142); + this.stackItemHeight3 = buffers.get(143); + this.stackItemHeight4 = buffers.get(144); + this.stackItemStamp1 = buffers.get(145); + this.stackItemStamp2 = buffers.get(146); + this.stackItemStamp3 = buffers.get(147); + this.stackItemStamp4 = buffers.get(148); + this.stpGasHi = buffers.get(149); + this.stpGasLo = buffers.get(150); + this.stpGasUpfrontGasCostXorGasLeftover = buffers.get(151); + this.stpValueHi = buffers.get(152); + this.stpValueLo = buffers.get(153); + this.subStamp = buffers.get(154); + this.swapFlag = buffers.get(155); + this.trmFlagXorCreateNonemptyInitCodeSuccessWontRevertXorKecFlag = buffers.get(156); + this.trmRawAddressHiXorMxpOffset1Lo = buffers.get(157); + this.twoLineInstruction = buffers.get(158); + this.txExec = buffers.get(159); + this.txFinl = buffers.get(160); + this.txInit = buffers.get(161); + this.txSkip = buffers.get(162); + this.txWarm = buffers.get(163); + this.txnFlag = buffers.get(164); + this.warmthNewXorPrcEcaddXorLogInfoFlag = buffers.get(165); + this.warmthXorPrcBlake2FXorLogFlag = buffers.get(166); + this.wcpFlag = buffers.get(167); } public int size() { @@ -810,13 +569,11 @@ public Trace absoluteTransactionNumber(final long b) { filled.set(0); } - if (b >= 65536L) { - throw new IllegalArgumentException( - "hub.ABSOLUTE_TRANSACTION_NUMBER has invalid value (" + b + ")"); - } + if(b >= 65536L) { throw new IllegalArgumentException("hub.ABSOLUTE_TRANSACTION_NUMBER has invalid value (" + b + ")"); } absoluteTransactionNumber.put((byte) (b >> 8)); absoluteTransactionNumber.put((byte) b); + return this; } @@ -827,14 +584,13 @@ public Trace callerContextNumber(final long b) { filled.set(1); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.CALLER_CONTEXT_NUMBER has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.CALLER_CONTEXT_NUMBER has invalid value (" + b + ")"); } callerContextNumber.put((byte) (b >> 24)); callerContextNumber.put((byte) (b >> 16)); callerContextNumber.put((byte) (b >> 8)); callerContextNumber.put((byte) b); + return this; } @@ -845,14 +601,13 @@ public Trace codeFragmentIndex(final long b) { filled.set(2); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.CODE_FRAGMENT_INDEX has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.CODE_FRAGMENT_INDEX has invalid value (" + b + ")"); } codeFragmentIndex.put((byte) (b >> 24)); codeFragmentIndex.put((byte) (b >> 16)); codeFragmentIndex.put((byte) (b >> 8)); codeFragmentIndex.put((byte) b); + return this; } @@ -887,14 +642,13 @@ public Trace contextNumber(final long b) { filled.set(5); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.CONTEXT_NUMBER has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.CONTEXT_NUMBER has invalid value (" + b + ")"); } contextNumber.put((byte) (b >> 24)); contextNumber.put((byte) (b >> 16)); contextNumber.put((byte) (b >> 8)); contextNumber.put((byte) b); + return this; } @@ -905,14 +659,13 @@ public Trace contextNumberNew(final long b) { filled.set(6); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.CONTEXT_NUMBER_NEW has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.CONTEXT_NUMBER_NEW has invalid value (" + b + ")"); } contextNumberNew.put((byte) (b >> 24)); contextNumberNew.put((byte) (b >> 16)); contextNumberNew.put((byte) (b >> 8)); contextNumberNew.put((byte) b); + return this; } @@ -923,14 +676,13 @@ public Trace contextRevertStamp(final long b) { filled.set(7); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.CONTEXT_REVERT_STAMP has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.CONTEXT_REVERT_STAMP has invalid value (" + b + ")"); } contextRevertStamp.put((byte) (b >> 24)); contextRevertStamp.put((byte) (b >> 16)); contextRevertStamp.put((byte) (b >> 8)); contextRevertStamp.put((byte) b); + return this; } @@ -965,11 +717,10 @@ public Trace counterNsr(final long b) { filled.set(10); } - if (b >= 256L) { - throw new IllegalArgumentException("hub.COUNTER_NSR has invalid value (" + b + ")"); - } + if(b >= 256L) { throw new IllegalArgumentException("hub.COUNTER_NSR has invalid value (" + b + ")"); } counterNsr.put((byte) b); + return this; } @@ -992,14 +743,13 @@ public Trace domStamp(final long b) { filled.set(12); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.DOM_STAMP has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.DOM_STAMP has invalid value (" + b + ")"); } domStamp.put((byte) (b >> 24)); domStamp.put((byte) (b >> 16)); domStamp.put((byte) (b >> 8)); domStamp.put((byte) b); + return this; } @@ -1025,18 +775,11 @@ public Trace gasActual(final Bytes b) { // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 64) { - throw new IllegalArgumentException( - "hub.GAS_ACTUAL has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.GAS_ACTUAL has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - gasActual.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { gasActual.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - gasActual.put(bs.get(j)); - } + for(int j=0; j 64) { - throw new IllegalArgumentException( - "hub.GAS_COST has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.GAS_COST has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - gasCost.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { gasCost.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - gasCost.put(bs.get(j)); - } + for(int j=0; j 64) { - throw new IllegalArgumentException( - "hub.GAS_EXPECTED has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.GAS_EXPECTED has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - gasExpected.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { gasExpected.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - gasExpected.put(bs.get(j)); - } + for(int j=0; j 64) { - throw new IllegalArgumentException( - "hub.GAS_NEXT has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.GAS_NEXT has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - gasNext.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { gasNext.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - gasNext.put(bs.get(j)); - } + for(int j=0; j= 2048L) { - throw new IllegalArgumentException("hub.HEIGHT has invalid value (" + b + ")"); - } + if(b >= 2048L) { throw new IllegalArgumentException("hub.HEIGHT has invalid value (" + b + ")"); } height.put((byte) (b >> 8)); height.put((byte) b); + return this; } @@ -1142,12 +863,11 @@ public Trace heightNew(final long b) { filled.set(19); } - if (b >= 2048L) { - throw new IllegalArgumentException("hub.HEIGHT_NEW has invalid value (" + b + ")"); - } + if(b >= 2048L) { throw new IllegalArgumentException("hub.HEIGHT_NEW has invalid value (" + b + ")"); } heightNew.put((byte) (b >> 8)); heightNew.put((byte) b); + return this; } @@ -1158,14 +878,13 @@ public Trace hubStamp(final long b) { filled.set(20); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.HUB_STAMP has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.HUB_STAMP has invalid value (" + b + ")"); } hubStamp.put((byte) (b >> 24)); hubStamp.put((byte) (b >> 16)); hubStamp.put((byte) (b >> 8)); hubStamp.put((byte) b); + return this; } @@ -1176,15 +895,13 @@ public Trace hubStampTransactionEnd(final long b) { filled.set(21); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.HUB_STAMP_TRANSACTION_END has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.HUB_STAMP_TRANSACTION_END has invalid value (" + b + ")"); } hubStampTransactionEnd.put((byte) (b >> 24)); hubStampTransactionEnd.put((byte) (b >> 16)); hubStampTransactionEnd.put((byte) (b >> 8)); hubStampTransactionEnd.put((byte) b); + return this; } @@ -1195,14 +912,13 @@ public Trace logInfoStamp(final long b) { filled.set(22); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.LOG_INFO_STAMP has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.LOG_INFO_STAMP has invalid value (" + b + ")"); } logInfoStamp.put((byte) (b >> 24)); logInfoStamp.put((byte) (b >> 16)); logInfoStamp.put((byte) (b >> 8)); logInfoStamp.put((byte) b); + return this; } @@ -1213,14 +929,13 @@ public Trace mmuStamp(final long b) { filled.set(23); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.MMU_STAMP has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.MMU_STAMP has invalid value (" + b + ")"); } mmuStamp.put((byte) (b >> 24)); mmuStamp.put((byte) (b >> 16)); mmuStamp.put((byte) (b >> 8)); mmuStamp.put((byte) b); + return this; } @@ -1231,14 +946,13 @@ public Trace mxpStamp(final long b) { filled.set(24); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.MXP_STAMP has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.MXP_STAMP has invalid value (" + b + ")"); } mxpStamp.put((byte) (b >> 24)); mxpStamp.put((byte) (b >> 16)); mxpStamp.put((byte) (b >> 8)); mxpStamp.put((byte) b); + return this; } @@ -1249,60 +963,45 @@ public Trace nonStackRows(final long b) { filled.set(25); } - if (b >= 256L) { - throw new IllegalArgumentException("hub.NON_STACK_ROWS has invalid value (" + b + ")"); - } + if(b >= 256L) { throw new IllegalArgumentException("hub.NON_STACK_ROWS has invalid value (" + b + ")"); } nonStackRows.put((byte) b); + return this; } public Trace pAccountAddressHi(final long b) { - if (filled.get(103)) { + if (filled.get(105)) { throw new IllegalStateException("hub.account/ADDRESS_HI already set"); } else { - filled.set(103); + filled.set(105); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.account/ADDRESS_HI has invalid value (" + b + ")"); - } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 24)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 16)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 8)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.account/ADDRESS_HI has invalid value (" + b + ")"); } + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 24)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 16)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 8)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) b); + return this; } public Trace pAccountAddressLo(final Bytes b) { - if (filled.get(132)) { + if (filled.get(134)) { throw new IllegalStateException("hub.account/ADDRESS_LO already set"); } else { - filled.set(132); + filled.set(134); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.account/ADDRESS_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.account/ADDRESS_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.account/BALANCE has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.account/BALANCE has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); - } + for(int i=bs.size(); i<16; i++) { balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.account/BALANCE_NEW has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.account/BALANCE_NEW has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); - } + for(int i=bs.size(); i<16; i++) { balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException( - "hub.account/CODE_FRAGMENT_INDEX has invalid value (" + b + ")"); - } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 24)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 16)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 8)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.account/CODE_FRAGMENT_INDEX has invalid value (" + b + ")"); } + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 24)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 16)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 8)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) b); + return this; } public Trace pAccountCodeHashHi(final Bytes b) { - if (filled.get(135)) { + if (filled.get(137)) { throw new IllegalStateException("hub.account/CODE_HASH_HI already set"); } else { - filled.set(135); + filled.set(137); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.account/CODE_HASH_HI has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.account/CODE_HASH_HI has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.account/CODE_HASH_HI_NEW has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.account/CODE_HASH_HI_NEW has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.account/CODE_HASH_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.account/CODE_HASH_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.account/CODE_HASH_LO_NEW has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.account/CODE_HASH_LO_NEW has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException("hub.account/CODE_SIZE has invalid value (" + b + ")"); - } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 24)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 16)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 8)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.account/CODE_SIZE has invalid value (" + b + ")"); } + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 24)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 16)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 8)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) b); + return this; } public Trace pAccountCodeSizeNew(final long b) { - if (filled.get(106)) { + if (filled.get(108)) { throw new IllegalStateException("hub.account/CODE_SIZE_NEW already set"); } else { - filled.set(106); + filled.set(108); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.account/CODE_SIZE_NEW has invalid value (" + b + ")"); - } - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put( - (byte) (b >> 24)); - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put( - (byte) (b >> 16)); - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put( - (byte) (b >> 8)); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.account/CODE_SIZE_NEW has invalid value (" + b + ")"); } + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) (b >> 24)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) (b >> 16)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) (b >> 8)); codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) b); + return this; } public Trace pAccountDeploymentNumber(final long b) { - if (filled.get(107)) { + if (filled.get(109)) { throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER already set"); } else { - filled.set(107); + filled.set(109); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.account/DEPLOYMENT_NUMBER has invalid value (" + b + ")"); - } - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put( - (byte) (b >> 24)); - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put( - (byte) (b >> 16)); - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put( - (byte) (b >> 8)); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.account/DEPLOYMENT_NUMBER has invalid value (" + b + ")"); } + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) (b >> 24)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) (b >> 16)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) (b >> 8)); deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) b); + return this; } public Trace pAccountDeploymentNumberFinalInBlock(final long b) { - if (filled.get(101)) { + if (filled.get(103)) { throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER_FINAL_IN_BLOCK already set"); } else { - filled.set(101); + filled.set(103); } - if (b >= 65536L) { - throw new IllegalArgumentException( - "hub.account/DEPLOYMENT_NUMBER_FINAL_IN_BLOCK has invalid value (" + b + ")"); - } + if(b >= 65536L) { throw new IllegalArgumentException("hub.account/DEPLOYMENT_NUMBER_FINAL_IN_BLOCK has invalid value (" + b + ")"); } deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock.put((byte) (b >> 8)); deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock.put((byte) b); + return this; } public Trace pAccountDeploymentNumberFirstInBlock(final long b) { - if (filled.get(102)) { + if (filled.get(104)) { throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER_FIRST_IN_BLOCK already set"); } else { - filled.set(102); + filled.set(104); } - if (b >= 65536L) { - throw new IllegalArgumentException( - "hub.account/DEPLOYMENT_NUMBER_FIRST_IN_BLOCK has invalid value (" + b + ")"); - } + if(b >= 65536L) { throw new IllegalArgumentException("hub.account/DEPLOYMENT_NUMBER_FIRST_IN_BLOCK has invalid value (" + b + ")"); } deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock.put((byte) (b >> 8)); deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock.put((byte) b); + return this; } public Trace pAccountDeploymentNumberInfty(final long b) { - if (filled.get(108)) { + if (filled.get(110)) { throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER_INFTY already set"); } else { - filled.set(108); + filled.set(110); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.account/DEPLOYMENT_NUMBER_INFTY has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.account/DEPLOYMENT_NUMBER_INFTY has invalid value (" + b + ")"); } deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.put((byte) (b >> 24)); deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.put((byte) (b >> 16)); deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.put((byte) (b >> 8)); deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.put((byte) b); + return this; } public Trace pAccountDeploymentNumberNew(final long b) { - if (filled.get(109)) { + if (filled.get(111)) { throw new IllegalStateException("hub.account/DEPLOYMENT_NUMBER_NEW already set"); } else { - filled.set(109); + filled.set(111); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.account/DEPLOYMENT_NUMBER_NEW has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.account/DEPLOYMENT_NUMBER_NEW has invalid value (" + b + ")"); } deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 24)); deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 16)); deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 8)); deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) b); + return this; } @@ -1673,8 +1295,7 @@ public Trace pAccountDeploymentStatus(final Boolean b) { filled.set(48); } - deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution - .put((byte) (b ? 1 : 0)); + deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } @@ -1686,8 +1307,7 @@ public Trace pAccountDeploymentStatusInfty(final Boolean b) { filled.set(49); } - deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode.put( - (byte) (b ? 1 : 0)); + deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode.put((byte) (b ? 1 : 0)); return this; } @@ -1711,8 +1331,7 @@ public Trace pAccountExists(final Boolean b) { filled.set(51); } - existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.put( - (byte) (b ? 1 : 0)); + existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.put((byte) (b ? 1 : 0)); return this; } @@ -1724,8 +1343,7 @@ public Trace pAccountExistsNew(final Boolean b) { filled.set(52); } - existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.put((byte) (b ? 1 : 0)); return this; } @@ -1737,8 +1355,7 @@ public Trace pAccountFinalInBlk(final Boolean b) { filled.set(53); } - finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn.put( - (byte) (b ? 1 : 0)); + finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn.put((byte) (b ? 1 : 0)); return this; } @@ -1750,8 +1367,7 @@ public Trace pAccountFinalInCnf(final Boolean b) { filled.set(54); } - finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorValueCurrChanges - .put((byte) (b ? 1 : 0)); + finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorUnconstrainedFinal.put((byte) (b ? 1 : 0)); return this; } @@ -1763,8 +1379,7 @@ public Trace pAccountFinalInTxn(final Boolean b) { filled.set(55); } - finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorValueCurrIsOrig.put( - (byte) (b ? 1 : 0)); + finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorUnconstrainedFirst.put((byte) (b ? 1 : 0)); return this; } @@ -1776,8 +1391,7 @@ public Trace pAccountFirstInBlk(final Boolean b) { filled.set(56); } - firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrIsZero.put( - (byte) (b ? 1 : 0)); + firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrChanges.put((byte) (b ? 1 : 0)); return this; } @@ -1789,7 +1403,7 @@ public Trace pAccountFirstInCnf(final Boolean b) { filled.set(57); } - firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); + firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueCurrIsOrig.put((byte) (b ? 1 : 0)); return this; } @@ -1801,8 +1415,7 @@ public Trace pAccountFirstInTxn(final Boolean b) { filled.set(58); } - firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueNextIsOrig.put( - (byte) (b ? 1 : 0)); + firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueCurrIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -1814,8 +1427,7 @@ public Trace pAccountHasCode(final Boolean b) { filled.set(59); } - hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); return this; } @@ -1827,7 +1439,7 @@ public Trace pAccountHasCodeNew(final Boolean b) { filled.set(60); } - hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); + hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueNextIsOrig.put((byte) (b ? 1 : 0)); return this; } @@ -1839,7 +1451,7 @@ public Trace pAccountIsPrecompile(final Boolean b) { filled.set(61); } - isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorWarmth.put((byte) (b ? 1 : 0)); + isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorValueNextIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -1851,8 +1463,7 @@ public Trace pAccountMarkedForSelfdestruct(final Boolean b) { filled.set(62); } - markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorWarmthNew.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -1864,105 +1475,81 @@ public Trace pAccountMarkedForSelfdestructNew(final Boolean b) { filled.set(63); } - markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpx.put( - (byte) (b ? 1 : 0)); + markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpxXorWarmth.put((byte) (b ? 1 : 0)); return this; } public Trace pAccountNonce(final Bytes b) { - if (filled.get(123)) { + if (filled.get(125)) { throw new IllegalStateException("hub.account/NONCE already set"); } else { - filled.set(123); + filled.set(125); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 64) { - throw new IllegalArgumentException( - "hub.account/NONCE has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.account/NONCE has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - nonceXorStpGasMxpXorBasefee.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { nonceXorStpGasMxpXorBasefee.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - nonceXorStpGasMxpXorBasefee.put(bs.get(j)); - } + for(int j=0; j 64) { - throw new IllegalArgumentException( - "hub.account/NONCE_NEW has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.account/NONCE_NEW has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException( - "hub.account/RLPADDR_DEP_ADDR_HI has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.account/RLPADDR_DEP_ADDR_HI has invalid value (" + b + ")"); } rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 24)); rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 16)); rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 8)); rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) b); + return this; } public Trace pAccountRlpaddrDepAddrLo(final Bytes b) { - if (filled.get(139)) { + if (filled.get(141)) { throw new IllegalStateException("hub.account/RLPADDR_DEP_ADDR_LO already set"); } else { - filled.set(139); + filled.set(141); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.account/RLPADDR_DEP_ADDR_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.account/RLPADDR_DEP_ADDR_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.account/RLPADDR_KEC_HI has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.account/RLPADDR_KEC_HI has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.account/RLPADDR_KEC_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.account/RLPADDR_KEC_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2.put(bs.get(j)); - } + for(int j=0; j= 256L) { - throw new IllegalArgumentException( - "hub.account/RLPADDR_RECIPE has invalid value (" + b + ")"); - } + if(b >= 256L) { throw new IllegalArgumentException("hub.account/RLPADDR_RECIPE has invalid value (" + b + ")"); } rlpaddrRecipe.put((byte) b); + return this; } public Trace pAccountRlpaddrSaltHi(final Bytes b) { - if (filled.get(142)) { + if (filled.get(144)) { throw new IllegalStateException("hub.account/RLPADDR_SALT_HI already set"); } else { - filled.set(142); + filled.set(144); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.account/RLPADDR_SALT_HI has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.account/RLPADDR_SALT_HI has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.account/RLPADDR_SALT_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.account/RLPADDR_SALT_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.account/TRM_RAW_ADDRESS_HI has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.account/TRM_RAW_ADDRESS_HI has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - trmRawAddressHiXorMxpOffset1Lo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { trmRawAddressHiXorMxpOffset1Lo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - trmRawAddressHiXorMxpOffset1Lo.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException( - "hub.context/ACCOUNT_ADDRESS_HI has invalid value (" + b + ")"); - } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 24)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 16)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 8)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.context/ACCOUNT_ADDRESS_HI has invalid value (" + b + ")"); } + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 24)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 16)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 8)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) b); + return this; } public Trace pContextAccountAddressLo(final Bytes b) { - if (filled.get(132)) { + if (filled.get(134)) { throw new IllegalStateException("hub.context/ACCOUNT_ADDRESS_LO already set"); } else { - filled.set(132); + filled.set(134); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.context/ACCOUNT_ADDRESS_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.context/ACCOUNT_ADDRESS_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException( - "hub.context/ACCOUNT_DEPLOYMENT_NUMBER has invalid value (" + b + ")"); - } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 24)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 16)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 8)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.context/ACCOUNT_DEPLOYMENT_NUMBER has invalid value (" + b + ")"); } + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 24)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 16)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 8)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) b); + return this; } public Trace pContextByteCodeAddressHi(final long b) { - if (filled.get(105)) { + if (filled.get(107)) { throw new IllegalStateException("hub.context/BYTE_CODE_ADDRESS_HI already set"); } else { - filled.set(105); + filled.set(107); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.context/BYTE_CODE_ADDRESS_HI has invalid value (" + b + ")"); - } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 24)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 16)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 8)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.context/BYTE_CODE_ADDRESS_HI has invalid value (" + b + ")"); } + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 24)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 16)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 8)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) b); + return this; } public Trace pContextByteCodeAddressLo(final Bytes b) { - if (filled.get(133)) { + if (filled.get(135)) { throw new IllegalStateException("hub.context/BYTE_CODE_ADDRESS_LO already set"); } else { - filled.set(133); + filled.set(135); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.context/BYTE_CODE_ADDRESS_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.context/BYTE_CODE_ADDRESS_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); - } + for(int i=bs.size(); i<16; i++) { balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException( - "hub.context/BYTE_CODE_CODE_FRAGMENT_INDEX has invalid value (" + b + ")"); - } - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put( - (byte) (b >> 24)); - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put( - (byte) (b >> 16)); - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put( - (byte) (b >> 8)); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.context/BYTE_CODE_CODE_FRAGMENT_INDEX has invalid value (" + b + ")"); } + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) (b >> 24)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) (b >> 16)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) (b >> 8)); codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) b); + return this; } public Trace pContextByteCodeDeploymentNumber(final long b) { - if (filled.get(107)) { + if (filled.get(109)) { throw new IllegalStateException("hub.context/BYTE_CODE_DEPLOYMENT_NUMBER already set"); } else { - filled.set(107); + filled.set(109); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.context/BYTE_CODE_DEPLOYMENT_NUMBER has invalid value (" + b + ")"); - } - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put( - (byte) (b >> 24)); - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put( - (byte) (b >> 16)); - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put( - (byte) (b >> 8)); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.context/BYTE_CODE_DEPLOYMENT_NUMBER has invalid value (" + b + ")"); } + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) (b >> 24)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) (b >> 16)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) (b >> 8)); deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) b); + return this; } public Trace pContextByteCodeDeploymentStatus(final long b) { - if (filled.get(108)) { + if (filled.get(110)) { throw new IllegalStateException("hub.context/BYTE_CODE_DEPLOYMENT_STATUS already set"); } else { - filled.set(108); + filled.set(110); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.context/BYTE_CODE_DEPLOYMENT_STATUS has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.context/BYTE_CODE_DEPLOYMENT_STATUS has invalid value (" + b + ")"); } deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.put((byte) (b >> 24)); deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.put((byte) (b >> 16)); deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.put((byte) (b >> 8)); deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.put((byte) b); + return this; } public Trace pContextCallDataContextNumber(final long b) { - if (filled.get(110)) { + if (filled.get(112)) { throw new IllegalStateException("hub.context/CALL_DATA_CONTEXT_NUMBER already set"); } else { - filled.set(110); + filled.set(112); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.context/CALL_DATA_CONTEXT_NUMBER has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.context/CALL_DATA_CONTEXT_NUMBER has invalid value (" + b + ")"); } rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 24)); rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 16)); rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 8)); rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) b); + return this; } public Trace pContextCallDataOffset(final long b) { - if (filled.get(111)) { + if (filled.get(113)) { throw new IllegalStateException("hub.context/CALL_DATA_OFFSET already set"); } else { - filled.set(111); + filled.set(113); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.context/CALL_DATA_OFFSET has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.context/CALL_DATA_OFFSET has invalid value (" + b + ")"); } callDataOffsetXorMmuSize.put((byte) (b >> 24)); callDataOffsetXorMmuSize.put((byte) (b >> 16)); callDataOffsetXorMmuSize.put((byte) (b >> 8)); callDataOffsetXorMmuSize.put((byte) b); + return this; } public Trace pContextCallDataSize(final long b) { - if (filled.get(112)) { + if (filled.get(114)) { throw new IllegalStateException("hub.context/CALL_DATA_SIZE already set"); } else { - filled.set(112); + filled.set(114); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.context/CALL_DATA_SIZE has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.context/CALL_DATA_SIZE has invalid value (" + b + ")"); } callDataSizeXorMmuSrcId.put((byte) (b >> 24)); callDataSizeXorMmuSrcId.put((byte) (b >> 16)); callDataSizeXorMmuSrcId.put((byte) (b >> 8)); callDataSizeXorMmuSrcId.put((byte) b); + return this; } public Trace pContextCallStackDepth(final long b) { - if (filled.get(97)) { + if (filled.get(99)) { throw new IllegalStateException("hub.context/CALL_STACK_DEPTH already set"); } else { - filled.set(97); + filled.set(99); } - if (b >= 2048L) { - throw new IllegalArgumentException( - "hub.context/CALL_STACK_DEPTH has invalid value (" + b + ")"); - } + if(b >= 2048L) { throw new IllegalArgumentException("hub.context/CALL_STACK_DEPTH has invalid value (" + b + ")"); } callStackDepthXorStackItemHeight1.put((byte) (b >> 8)); callStackDepthXorStackItemHeight1.put((byte) b); + return this; } public Trace pContextCallValue(final Bytes b) { - if (filled.get(135)) { + if (filled.get(137)) { throw new IllegalStateException("hub.context/CALL_VALUE already set"); } else { - filled.set(135); + filled.set(137); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.context/CALL_VALUE has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.context/CALL_VALUE has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException( - "hub.context/CALLER_ADDRESS_HI has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.context/CALLER_ADDRESS_HI has invalid value (" + b + ")"); } deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 24)); deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 16)); deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 8)); deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) b); + return this; } public Trace pContextCallerAddressLo(final Bytes b) { - if (filled.get(134)) { + if (filled.get(136)) { throw new IllegalStateException("hub.context/CALLER_ADDRESS_LO already set"); } else { - filled.set(134); + filled.set(136); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.context/CALLER_ADDRESS_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.context/CALLER_ADDRESS_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); - } + for(int i=bs.size(); i<16; i++) { balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException( - "hub.context/CONTEXT_NUMBER has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.context/CONTEXT_NUMBER has invalid value (" + b + ")"); } contextNumberXorMmuTgtId.put((byte) (b >> 24)); contextNumberXorMmuTgtId.put((byte) (b >> 16)); contextNumberXorMmuTgtId.put((byte) (b >> 8)); contextNumberXorMmuTgtId.put((byte) b); + return this; } @@ -2535,8 +2008,7 @@ public Trace pContextIsRoot(final Boolean b) { filled.set(45); } - againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } @@ -2548,104 +2020,93 @@ public Trace pContextIsStatic(final Boolean b) { filled.set(46); } - againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment.put( - (byte) (b ? 1 : 0)); + againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } public Trace pContextReturnAtCapacity(final long b) { - if (filled.get(114)) { + if (filled.get(116)) { throw new IllegalStateException("hub.context/RETURN_AT_CAPACITY already set"); } else { - filled.set(114); + filled.set(116); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.context/RETURN_AT_CAPACITY has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.context/RETURN_AT_CAPACITY has invalid value (" + b + ")"); } returnAtCapacityXorMxpInst.put((byte) (b >> 24)); returnAtCapacityXorMxpInst.put((byte) (b >> 16)); returnAtCapacityXorMxpInst.put((byte) (b >> 8)); returnAtCapacityXorMxpInst.put((byte) b); + return this; } public Trace pContextReturnAtOffset(final long b) { - if (filled.get(115)) { + if (filled.get(117)) { throw new IllegalStateException("hub.context/RETURN_AT_OFFSET already set"); } else { - filled.set(115); + filled.set(117); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.context/RETURN_AT_OFFSET has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.context/RETURN_AT_OFFSET has invalid value (" + b + ")"); } returnAtOffsetXorOobInst.put((byte) (b >> 24)); returnAtOffsetXorOobInst.put((byte) (b >> 16)); returnAtOffsetXorOobInst.put((byte) (b >> 8)); returnAtOffsetXorOobInst.put((byte) b); + return this; } public Trace pContextReturnDataContextNumber(final long b) { - if (filled.get(116)) { + if (filled.get(118)) { throw new IllegalStateException("hub.context/RETURN_DATA_CONTEXT_NUMBER already set"); } else { - filled.set(116); + filled.set(118); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.context/RETURN_DATA_CONTEXT_NUMBER has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.context/RETURN_DATA_CONTEXT_NUMBER has invalid value (" + b + ")"); } returnDataContextNumberXorStpGasStipend.put((byte) (b >> 24)); returnDataContextNumberXorStpGasStipend.put((byte) (b >> 16)); returnDataContextNumberXorStpGasStipend.put((byte) (b >> 8)); returnDataContextNumberXorStpGasStipend.put((byte) b); + return this; } public Trace pContextReturnDataOffset(final long b) { - if (filled.get(117)) { + if (filled.get(119)) { throw new IllegalStateException("hub.context/RETURN_DATA_OFFSET already set"); } else { - filled.set(117); + filled.set(119); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.context/RETURN_DATA_OFFSET has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.context/RETURN_DATA_OFFSET has invalid value (" + b + ")"); } returnDataOffsetXorStpInstruction.put((byte) (b >> 24)); returnDataOffsetXorStpInstruction.put((byte) (b >> 16)); returnDataOffsetXorStpInstruction.put((byte) (b >> 8)); returnDataOffsetXorStpInstruction.put((byte) b); + return this; } public Trace pContextReturnDataSize(final long b) { - if (filled.get(118)) { + if (filled.get(120)) { throw new IllegalStateException("hub.context/RETURN_DATA_SIZE already set"); } else { - filled.set(118); + filled.set(120); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.context/RETURN_DATA_SIZE has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.context/RETURN_DATA_SIZE has invalid value (" + b + ")"); } returnDataSize.put((byte) (b >> 24)); returnDataSize.put((byte) (b >> 16)); returnDataSize.put((byte) (b >> 8)); returnDataSize.put((byte) b); + return this; } @@ -2656,30 +2117,24 @@ public Trace pContextUpdate(final Boolean b) { filled.set(47); } - againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2 - .put((byte) (b ? 1 : 0)); + againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscCcrsStamp(final long b) { - if (filled.get(103)) { + if (filled.get(105)) { throw new IllegalStateException("hub.misc/CCRS_STAMP already set"); } else { - filled.set(103); + filled.set(105); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.misc/CCRS_STAMP has invalid value (" + b + ")"); - } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 24)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 16)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 8)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.misc/CCRS_STAMP has invalid value (" + b + ")"); } + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 24)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 16)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 8)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) b); + return this; } @@ -2691,144 +2146,102 @@ public Trace pMiscCcsrFlag(final Boolean b) { filled.set(45); } - againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscExpData1(final Bytes b) { - if (filled.get(132)) { + if (filled.get(134)) { throw new IllegalStateException("hub.misc/EXP_DATA_1 already set"); } else { - filled.set(132); + filled.set(134); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.misc/EXP_DATA_1 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/EXP_DATA_1 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/EXP_DATA_2 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/EXP_DATA_2 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); - } + for(int i=bs.size(); i<16; i++) { balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/EXP_DATA_3 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/EXP_DATA_3 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); - } + for(int i=bs.size(); i<16; i++) { balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/EXP_DATA_4 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/EXP_DATA_4 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/EXP_DATA_5 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/EXP_DATA_5 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException("hub.misc/EXP_INST has invalid value (" + b + ")"); - } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 24)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 16)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 8)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.misc/EXP_INST has invalid value (" + b + ")"); } + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 24)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 16)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 8)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) b); + return this; } public Trace pMiscMmuAuxId(final long b) { - if (filled.get(105)) { + if (filled.get(107)) { throw new IllegalStateException("hub.misc/MMU_AUX_ID already set"); } else { - filled.set(105); + filled.set(107); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.misc/MMU_AUX_ID has invalid value (" + b + ")"); - } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 24)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 16)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 8)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.misc/MMU_AUX_ID has invalid value (" + b + ")"); } + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 24)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 16)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 8)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) b); + return this; } public Trace pMiscMmuExoSum(final long b) { - if (filled.get(106)) { + if (filled.get(108)) { throw new IllegalStateException("hub.misc/MMU_EXO_SUM already set"); } else { - filled.set(106); + filled.set(108); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.misc/MMU_EXO_SUM has invalid value (" + b + ")"); - } - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put( - (byte) (b >> 24)); - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put( - (byte) (b >> 16)); - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put( - (byte) (b >> 8)); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.misc/MMU_EXO_SUM has invalid value (" + b + ")"); } + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) (b >> 24)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) (b >> 16)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) (b >> 8)); codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) b); + return this; } @@ -2918,223 +2316,185 @@ public Trace pMiscMmuFlag(final Boolean b) { filled.set(47); } - againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2 - .put((byte) (b ? 1 : 0)); + againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscMmuInst(final long b) { - if (filled.get(107)) { + if (filled.get(109)) { throw new IllegalStateException("hub.misc/MMU_INST already set"); } else { - filled.set(107); + filled.set(109); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.misc/MMU_INST has invalid value (" + b + ")"); - } - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put( - (byte) (b >> 24)); - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put( - (byte) (b >> 16)); - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put( - (byte) (b >> 8)); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.misc/MMU_INST has invalid value (" + b + ")"); } + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) (b >> 24)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) (b >> 16)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) (b >> 8)); deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) b); + return this; } public Trace pMiscMmuLimb1(final Bytes b) { - if (filled.get(137)) { + if (filled.get(139)) { throw new IllegalStateException("hub.misc/MMU_LIMB_1 already set"); } else { - filled.set(137); + filled.set(139); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.misc/MMU_LIMB_1 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/MMU_LIMB_1 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/MMU_LIMB_2 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/MMU_LIMB_2 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException("hub.misc/MMU_PHASE has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.misc/MMU_PHASE has invalid value (" + b + ")"); } deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.put((byte) (b >> 24)); deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.put((byte) (b >> 16)); deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.put((byte) (b >> 8)); deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.put((byte) b); + return this; } public Trace pMiscMmuRefOffset(final long b) { - if (filled.get(109)) { + if (filled.get(111)) { throw new IllegalStateException("hub.misc/MMU_REF_OFFSET already set"); } else { - filled.set(109); + filled.set(111); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.misc/MMU_REF_OFFSET has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.misc/MMU_REF_OFFSET has invalid value (" + b + ")"); } deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 24)); deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 16)); deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 8)); deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) b); + return this; } public Trace pMiscMmuRefSize(final long b) { - if (filled.get(110)) { + if (filled.get(112)) { throw new IllegalStateException("hub.misc/MMU_REF_SIZE already set"); } else { - filled.set(110); + filled.set(112); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.misc/MMU_REF_SIZE has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.misc/MMU_REF_SIZE has invalid value (" + b + ")"); } rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 24)); rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 16)); rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) (b >> 8)); rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.put((byte) b); + return this; } public Trace pMiscMmuSize(final long b) { - if (filled.get(111)) { + if (filled.get(113)) { throw new IllegalStateException("hub.misc/MMU_SIZE already set"); } else { - filled.set(111); + filled.set(113); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.misc/MMU_SIZE has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.misc/MMU_SIZE has invalid value (" + b + ")"); } callDataOffsetXorMmuSize.put((byte) (b >> 24)); callDataOffsetXorMmuSize.put((byte) (b >> 16)); callDataOffsetXorMmuSize.put((byte) (b >> 8)); callDataOffsetXorMmuSize.put((byte) b); + return this; } public Trace pMiscMmuSrcId(final long b) { - if (filled.get(112)) { + if (filled.get(114)) { throw new IllegalStateException("hub.misc/MMU_SRC_ID already set"); } else { - filled.set(112); + filled.set(114); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.misc/MMU_SRC_ID has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.misc/MMU_SRC_ID has invalid value (" + b + ")"); } callDataSizeXorMmuSrcId.put((byte) (b >> 24)); callDataSizeXorMmuSrcId.put((byte) (b >> 16)); callDataSizeXorMmuSrcId.put((byte) (b >> 8)); callDataSizeXorMmuSrcId.put((byte) b); + return this; } public Trace pMiscMmuSrcOffsetHi(final Bytes b) { - if (filled.get(139)) { + if (filled.get(141)) { throw new IllegalStateException("hub.misc/MMU_SRC_OFFSET_HI already set"); } else { - filled.set(139); + filled.set(141); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.misc/MMU_SRC_OFFSET_HI has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/MMU_SRC_OFFSET_HI has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/MMU_SRC_OFFSET_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/MMU_SRC_OFFSET_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException("hub.misc/MMU_TGT_ID has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.misc/MMU_TGT_ID has invalid value (" + b + ")"); } contextNumberXorMmuTgtId.put((byte) (b >> 24)); contextNumberXorMmuTgtId.put((byte) (b >> 16)); contextNumberXorMmuTgtId.put((byte) (b >> 8)); contextNumberXorMmuTgtId.put((byte) b); + return this; } public Trace pMiscMmuTgtOffsetLo(final Bytes b) { - if (filled.get(141)) { + if (filled.get(143)) { throw new IllegalStateException("hub.misc/MMU_TGT_OFFSET_LO already set"); } else { - filled.set(141); + filled.set(143); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.misc/MMU_TGT_OFFSET_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/MMU_TGT_OFFSET_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/MXP_GAS_MXP has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/MXP_GAS_MXP has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException("hub.misc/MXP_INST has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.misc/MXP_INST has invalid value (" + b + ")"); } returnAtCapacityXorMxpInst.put((byte) (b >> 24)); returnAtCapacityXorMxpInst.put((byte) (b >> 16)); returnAtCapacityXorMxpInst.put((byte) (b >> 8)); returnAtCapacityXorMxpInst.put((byte) b); + return this; } @@ -3272,8 +2614,7 @@ public Trace pMiscMxpMtntop(final Boolean b) { filled.set(51); } - existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.put( - (byte) (b ? 1 : 0)); + existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.put((byte) (b ? 1 : 0)); return this; } @@ -3285,164 +2626,121 @@ public Trace pMiscMxpMxpx(final Boolean b) { filled.set(52); } - existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscMxpOffset1Hi(final Bytes b) { - if (filled.get(143)) { + if (filled.get(145)) { throw new IllegalStateException("hub.misc/MXP_OFFSET_1_HI already set"); } else { - filled.set(143); + filled.set(145); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.misc/MXP_OFFSET_1_HI has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/MXP_OFFSET_1_HI has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/MXP_OFFSET_1_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/MXP_OFFSET_1_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - trmRawAddressHiXorMxpOffset1Lo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { trmRawAddressHiXorMxpOffset1Lo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - trmRawAddressHiXorMxpOffset1Lo.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/MXP_OFFSET_2_HI has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/MXP_OFFSET_2_HI has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - mxpOffset2Hi.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { mxpOffset2Hi.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - mxpOffset2Hi.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/MXP_OFFSET_2_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/MXP_OFFSET_2_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - mxpOffset2Lo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { mxpOffset2Lo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - mxpOffset2Lo.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/MXP_SIZE_1_HI has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/MXP_SIZE_1_HI has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - mxpSize1Hi.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { mxpSize1Hi.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - mxpSize1Hi.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/MXP_SIZE_1_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/MXP_SIZE_1_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - mxpSize1Lo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { mxpSize1Lo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - mxpSize1Lo.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/MXP_SIZE_2_HI has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/MXP_SIZE_2_HI has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - mxpSize2Hi.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { mxpSize2Hi.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - mxpSize2Hi.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/MXP_SIZE_2_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/MXP_SIZE_2_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - mxpSize2Lo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { mxpSize2Lo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - mxpSize2Lo.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/MXP_WORDS has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/MXP_WORDS has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - mxpWords.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { mxpWords.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - mxpWords.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/OOB_DATA_1 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/OOB_DATA_1 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - oobData1.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { oobData1.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - oobData1.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/OOB_DATA_2 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/OOB_DATA_2 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - oobData2.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { oobData2.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - oobData2.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/OOB_DATA_3 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/OOB_DATA_3 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - oobData3.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { oobData3.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - oobData3.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/OOB_DATA_4 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/OOB_DATA_4 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - oobData4.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { oobData4.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - oobData4.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/OOB_DATA_5 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/OOB_DATA_5 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - oobData5.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { oobData5.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - oobData5.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/OOB_DATA_6 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/OOB_DATA_6 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - oobData6.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { oobData6.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - oobData6.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/OOB_DATA_7 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/OOB_DATA_7 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - oobData7.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { oobData7.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - oobData7.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/OOB_DATA_8 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/OOB_DATA_8 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - oobData8.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { oobData8.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - oobData8.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/OOB_DATA_9 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/OOB_DATA_9 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - oobData9.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { oobData9.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - oobData9.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException("hub.misc/OOB_INST has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.misc/OOB_INST has invalid value (" + b + ")"); } returnAtOffsetXorOobInst.put((byte) (b >> 24)); returnAtOffsetXorOobInst.put((byte) (b >> 16)); returnAtOffsetXorOobInst.put((byte) (b >> 8)); returnAtOffsetXorOobInst.put((byte) b); + return this; } @@ -3823,8 +3033,7 @@ public Trace pMiscStpExists(final Boolean b) { filled.set(56); } - firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrIsZero.put( - (byte) (b ? 1 : 0)); + firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrChanges.put((byte) (b ? 1 : 0)); return this; } @@ -3836,174 +3045,137 @@ public Trace pMiscStpFlag(final Boolean b) { filled.set(57); } - firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); + firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueCurrIsOrig.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscStpGasHi(final Bytes b) { - if (filled.get(161)) { + if (filled.get(163)) { throw new IllegalStateException("hub.misc/STP_GAS_HI already set"); } else { - filled.set(161); + filled.set(163); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.misc/STP_GAS_HI has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/STP_GAS_HI has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - stpGasHi.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { stpGasHi.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - stpGasHi.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/STP_GAS_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/STP_GAS_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - stpGasLo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { stpGasLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - stpGasLo.put(bs.get(j)); - } + for(int j=0; j 64) { - throw new IllegalArgumentException( - "hub.misc/STP_GAS_MXP has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.misc/STP_GAS_MXP has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - nonceXorStpGasMxpXorBasefee.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { nonceXorStpGasMxpXorBasefee.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - nonceXorStpGasMxpXorBasefee.put(bs.get(j)); - } + for(int j=0; j 64) { - throw new IllegalArgumentException( - "hub.misc/STP_GAS_PAID_OUT_OF_POCKET has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.misc/STP_GAS_PAID_OUT_OF_POCKET has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException("hub.misc/STP_GAS_STIPEND has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.misc/STP_GAS_STIPEND has invalid value (" + b + ")"); } returnDataContextNumberXorStpGasStipend.put((byte) (b >> 24)); returnDataContextNumberXorStpGasStipend.put((byte) (b >> 16)); returnDataContextNumberXorStpGasStipend.put((byte) (b >> 8)); returnDataContextNumberXorStpGasStipend.put((byte) b); + return this; } public Trace pMiscStpGasUpfrontGasCost(final Bytes b) { - if (filled.get(125)) { + if (filled.get(127)) { throw new IllegalStateException("hub.misc/STP_GAS_UPFRONT_GAS_COST already set"); } else { - filled.set(125); + filled.set(127); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 64) { - throw new IllegalArgumentException( - "hub.misc/STP_GAS_UPFRONT_GAS_COST has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.misc/STP_GAS_UPFRONT_GAS_COST has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - stpGasUpfrontGasCostXorGasLeftover.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { stpGasUpfrontGasCostXorGasLeftover.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - stpGasUpfrontGasCostXorGasLeftover.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException("hub.misc/STP_INSTRUCTION has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.misc/STP_INSTRUCTION has invalid value (" + b + ")"); } returnDataOffsetXorStpInstruction.put((byte) (b >> 24)); returnDataOffsetXorStpInstruction.put((byte) (b >> 16)); returnDataOffsetXorStpInstruction.put((byte) (b >> 8)); returnDataOffsetXorStpInstruction.put((byte) b); + return this; } @@ -4014,60 +3186,45 @@ public Trace pMiscStpOogx(final Boolean b) { filled.set(58); } - firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueNextIsOrig.put( - (byte) (b ? 1 : 0)); + firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueCurrIsZero.put((byte) (b ? 1 : 0)); return this; } public Trace pMiscStpValueHi(final Bytes b) { - if (filled.get(163)) { + if (filled.get(165)) { throw new IllegalStateException("hub.misc/STP_VALUE_HI already set"); } else { - filled.set(163); + filled.set(165); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.misc/STP_VALUE_HI has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/STP_VALUE_HI has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - stpValueHi.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { stpValueHi.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - stpValueHi.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.misc/STP_VALUE_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.misc/STP_VALUE_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - stpValueLo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { stpValueLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - stpValueLo.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException( - "hub.scenario/PRC_CALLEE_GAS has invalid value (" + b + ")"); - } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 24)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 16)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 8)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.scenario/PRC_CALLEE_GAS has invalid value (" + b + ")"); } + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 24)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 16)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 8)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) b); + return this; } public Trace pScenarioPrcCallerGas(final long b) { - if (filled.get(104)) { + if (filled.get(106)) { throw new IllegalStateException("hub.scenario/PRC_CALLER_GAS already set"); } else { - filled.set(104); + filled.set(106); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.scenario/PRC_CALLER_GAS has invalid value (" + b + ")"); - } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 24)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 16)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 8)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.scenario/PRC_CALLER_GAS has invalid value (" + b + ")"); } + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 24)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 16)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 8)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) b); + return this; } public Trace pScenarioPrcCdo(final long b) { - if (filled.get(105)) { + if (filled.get(107)) { throw new IllegalStateException("hub.scenario/PRC_CDO already set"); } else { - filled.set(105); + filled.set(107); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.scenario/PRC_CDO has invalid value (" + b + ")"); - } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 24)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 16)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 8)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.scenario/PRC_CDO has invalid value (" + b + ")"); } + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 24)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 16)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 8)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) b); + return this; } public Trace pScenarioPrcCds(final long b) { - if (filled.get(106)) { + if (filled.get(108)) { throw new IllegalStateException("hub.scenario/PRC_CDS already set"); } else { - filled.set(106); + filled.set(108); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.scenario/PRC_CDS has invalid value (" + b + ")"); - } - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put( - (byte) (b >> 24)); - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put( - (byte) (b >> 16)); - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put( - (byte) (b >> 8)); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.scenario/PRC_CDS has invalid value (" + b + ")"); } + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) (b >> 24)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) (b >> 16)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) (b >> 8)); codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) b); + return this; } @@ -4579,60 +3682,53 @@ public Trace pScenarioPrcModexp(final Boolean b) { } public Trace pScenarioPrcRac(final long b) { - if (filled.get(107)) { + if (filled.get(109)) { throw new IllegalStateException("hub.scenario/PRC_RAC already set"); } else { - filled.set(107); + filled.set(109); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.scenario/PRC_RAC has invalid value (" + b + ")"); - } - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put( - (byte) (b >> 24)); - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put( - (byte) (b >> 16)); - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put( - (byte) (b >> 8)); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.scenario/PRC_RAC has invalid value (" + b + ")"); } + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) (b >> 24)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) (b >> 16)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) (b >> 8)); deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) b); + return this; } public Trace pScenarioPrcRao(final long b) { - if (filled.get(108)) { + if (filled.get(110)) { throw new IllegalStateException("hub.scenario/PRC_RAO already set"); } else { - filled.set(108); + filled.set(110); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.scenario/PRC_RAO has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.scenario/PRC_RAO has invalid value (" + b + ")"); } deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.put((byte) (b >> 24)); deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.put((byte) (b >> 16)); deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.put((byte) (b >> 8)); deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.put((byte) b); + return this; } public Trace pScenarioPrcReturnGas(final long b) { - if (filled.get(109)) { + if (filled.get(111)) { throw new IllegalStateException("hub.scenario/PRC_RETURN_GAS already set"); } else { - filled.set(109); + filled.set(111); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.scenario/PRC_RETURN_GAS has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.scenario/PRC_RETURN_GAS has invalid value (" + b + ")"); } deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 24)); deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 16)); deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) (b >> 8)); deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.put((byte) b); + return this; } @@ -4698,8 +3794,7 @@ public Trace pScenarioReturnException(final Boolean b) { public Trace pScenarioReturnFromDeploymentEmptyCodeWillRevert(final Boolean b) { if (filled.get(81)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT already set"); } else { filled.set(81); } @@ -4711,8 +3806,7 @@ public Trace pScenarioReturnFromDeploymentEmptyCodeWillRevert(final Boolean b) { public Trace pScenarioReturnFromDeploymentEmptyCodeWontRevert(final Boolean b) { if (filled.get(82)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT already set"); } else { filled.set(82); } @@ -4724,8 +3818,7 @@ public Trace pScenarioReturnFromDeploymentEmptyCodeWontRevert(final Boolean b) { public Trace pScenarioReturnFromDeploymentNonemptyCodeWillRevert(final Boolean b) { if (filled.get(83)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT already set"); } else { filled.set(83); } @@ -4737,8 +3830,7 @@ public Trace pScenarioReturnFromDeploymentNonemptyCodeWillRevert(final Boolean b public Trace pScenarioReturnFromDeploymentNonemptyCodeWontRevert(final Boolean b) { if (filled.get(84)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT already set"); } else { filled.set(84); } @@ -4750,8 +3842,7 @@ public Trace pScenarioReturnFromDeploymentNonemptyCodeWontRevert(final Boolean b public Trace pScenarioReturnFromMessageCallWillTouchRam(final Boolean b) { if (filled.get(85)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM already set"); } else { filled.set(85); } @@ -4763,8 +3854,7 @@ public Trace pScenarioReturnFromMessageCallWillTouchRam(final Boolean b) { public Trace pScenarioReturnFromMessageCallWontTouchRam(final Boolean b) { if (filled.get(86)) { - throw new IllegalStateException( - "hub.scenario/RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM already set"); + throw new IllegalStateException("hub.scenario/RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM already set"); } else { filled.set(86); } @@ -4800,8 +3890,7 @@ public Trace pScenarioSelfdestructWillRevert(final Boolean b) { public Trace pScenarioSelfdestructWontRevertAlreadyMarked(final Boolean b) { if (filled.get(89)) { - throw new IllegalStateException( - "hub.scenario/SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED already set"); + throw new IllegalStateException("hub.scenario/SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED already set"); } else { filled.set(89); } @@ -4813,8 +3902,7 @@ public Trace pScenarioSelfdestructWontRevertAlreadyMarked(final Boolean b) { public Trace pScenarioSelfdestructWontRevertNotYetMarked(final Boolean b) { if (filled.get(90)) { - throw new IllegalStateException( - "hub.scenario/SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED already set"); + throw new IllegalStateException("hub.scenario/SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED already set"); } else { filled.set(90); } @@ -4831,8 +3919,7 @@ public Trace pStackAccFlag(final Boolean b) { filled.set(45); } - againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd.put( - (byte) (b ? 1 : 0)); + againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd.put((byte) (b ? 1 : 0)); return this; } @@ -4844,8 +3931,7 @@ public Trace pStackAddFlag(final Boolean b) { filled.set(46); } - againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment.put( - (byte) (b ? 1 : 0)); + againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment.put((byte) (b ? 1 : 0)); return this; } @@ -4869,8 +3955,7 @@ public Trace pStackBinFlag(final Boolean b) { filled.set(47); } - againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2 - .put((byte) (b ? 1 : 0)); + againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2.put((byte) (b ? 1 : 0)); return this; } @@ -4882,8 +3967,7 @@ public Trace pStackBtcFlag(final Boolean b) { filled.set(48); } - deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution - .put((byte) (b ? 1 : 0)); + deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } @@ -4895,8 +3979,7 @@ public Trace pStackCallFlag(final Boolean b) { filled.set(49); } - deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode.put( - (byte) (b ? 1 : 0)); + deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode.put((byte) (b ? 1 : 0)); return this; } @@ -4920,8 +4003,7 @@ public Trace pStackCopyFlag(final Boolean b) { filled.set(51); } - existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.put( - (byte) (b ? 1 : 0)); + existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.put((byte) (b ? 1 : 0)); return this; } @@ -4933,8 +4015,7 @@ public Trace pStackCreateFlag(final Boolean b) { filled.set(52); } - existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.put((byte) (b ? 1 : 0)); return this; } @@ -4946,8 +4027,7 @@ public Trace pStackDecFlag1(final Boolean b) { filled.set(53); } - finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn.put( - (byte) (b ? 1 : 0)); + finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn.put((byte) (b ? 1 : 0)); return this; } @@ -4959,8 +4039,7 @@ public Trace pStackDecFlag2(final Boolean b) { filled.set(54); } - finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorValueCurrChanges - .put((byte) (b ? 1 : 0)); + finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorUnconstrainedFinal.put((byte) (b ? 1 : 0)); return this; } @@ -4972,8 +4051,7 @@ public Trace pStackDecFlag3(final Boolean b) { filled.set(55); } - finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorValueCurrIsOrig.put( - (byte) (b ? 1 : 0)); + finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorUnconstrainedFirst.put((byte) (b ? 1 : 0)); return this; } @@ -4985,8 +4063,7 @@ public Trace pStackDecFlag4(final Boolean b) { filled.set(56); } - firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrIsZero.put( - (byte) (b ? 1 : 0)); + firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrChanges.put((byte) (b ? 1 : 0)); return this; } @@ -5010,7 +4087,7 @@ public Trace pStackDupFlag(final Boolean b) { filled.set(57); } - firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); + firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueCurrIsOrig.put((byte) (b ? 1 : 0)); return this; } @@ -5022,8 +4099,7 @@ public Trace pStackExtFlag(final Boolean b) { filled.set(58); } - firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueNextIsOrig.put( - (byte) (b ? 1 : 0)); + firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueCurrIsZero.put((byte) (b ? 1 : 0)); return this; } @@ -5035,8 +4111,7 @@ public Trace pStackHaltFlag(final Boolean b) { filled.set(59); } - hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsZero.put( - (byte) (b ? 1 : 0)); + hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsCurr.put((byte) (b ? 1 : 0)); return this; } @@ -5048,63 +4123,45 @@ public Trace pStackHashInfoFlag(final Boolean b) { filled.set(60); } - hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueOrigIsZero.put((byte) (b ? 1 : 0)); + hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueNextIsOrig.put((byte) (b ? 1 : 0)); return this; } public Trace pStackHashInfoKeccakHi(final Bytes b) { - if (filled.get(132)) { + if (filled.get(134)) { throw new IllegalStateException("hub.stack/HASH_INFO_KECCAK_HI already set"); } else { - filled.set(132); + filled.set(134); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.stack/HASH_INFO_KECCAK_HI has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.stack/HASH_INFO_KECCAK_HI has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.stack/HASH_INFO_KECCAK_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.stack/HASH_INFO_KECCAK_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); - } + for(int i=bs.size(); i<16; i++) { balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - bs.get(j)); - } + for(int j=0; j 256) { - throw new IllegalArgumentException( - "hub.stack/INSTRUCTION has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 256) { throw new IllegalArgumentException("hub.stack/INSTRUCTION has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 32; i++) { - instruction.put((byte) 0); - } + for(int i=bs.size(); i<32; i++) { instruction.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - instruction.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.stack/PUSH_VALUE_HI has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.stack/PUSH_VALUE_HI has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); - } + for(int i=bs.size(); i<16; i++) { balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.stack/PUSH_VALUE_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.stack/PUSH_VALUE_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(bs.get(j)); - } + for(int j=0; j= 2048L) { - throw new IllegalArgumentException( - "hub.stack/STACK_ITEM_HEIGHT_1 has invalid value (" + b + ")"); - } + if(b >= 2048L) { throw new IllegalArgumentException("hub.stack/STACK_ITEM_HEIGHT_1 has invalid value (" + b + ")"); } callStackDepthXorStackItemHeight1.put((byte) (b >> 8)); callStackDepthXorStackItemHeight1.put((byte) b); + return this; } public Trace pStackStackItemHeight2(final long b) { - if (filled.get(98)) { + if (filled.get(100)) { throw new IllegalStateException("hub.stack/STACK_ITEM_HEIGHT_2 already set"); } else { - filled.set(98); + filled.set(100); } - if (b >= 2048L) { - throw new IllegalArgumentException( - "hub.stack/STACK_ITEM_HEIGHT_2 has invalid value (" + b + ")"); - } + if(b >= 2048L) { throw new IllegalArgumentException("hub.stack/STACK_ITEM_HEIGHT_2 has invalid value (" + b + ")"); } stackItemHeight2.put((byte) (b >> 8)); stackItemHeight2.put((byte) b); + return this; } public Trace pStackStackItemHeight3(final long b) { - if (filled.get(99)) { + if (filled.get(101)) { throw new IllegalStateException("hub.stack/STACK_ITEM_HEIGHT_3 already set"); } else { - filled.set(99); + filled.set(101); } - if (b >= 2048L) { - throw new IllegalArgumentException( - "hub.stack/STACK_ITEM_HEIGHT_3 has invalid value (" + b + ")"); - } + if(b >= 2048L) { throw new IllegalArgumentException("hub.stack/STACK_ITEM_HEIGHT_3 has invalid value (" + b + ")"); } stackItemHeight3.put((byte) (b >> 8)); stackItemHeight3.put((byte) b); + return this; } public Trace pStackStackItemHeight4(final long b) { - if (filled.get(100)) { + if (filled.get(102)) { throw new IllegalStateException("hub.stack/STACK_ITEM_HEIGHT_4 already set"); } else { - filled.set(100); + filled.set(102); } - if (b >= 2048L) { - throw new IllegalArgumentException( - "hub.stack/STACK_ITEM_HEIGHT_4 has invalid value (" + b + ")"); - } + if(b >= 2048L) { throw new IllegalArgumentException("hub.stack/STACK_ITEM_HEIGHT_4 has invalid value (" + b + ")"); } stackItemHeight4.put((byte) (b >> 8)); stackItemHeight4.put((byte) b); + return this; } @@ -5561,289 +4608,225 @@ public Trace pStackStackItemPop4(final Boolean b) { } public Trace pStackStackItemStamp1(final long b) { - if (filled.get(119)) { + if (filled.get(121)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_1 already set"); } else { - filled.set(119); + filled.set(121); } - if (b >= 68719476736L) { - throw new IllegalArgumentException( - "hub.stack/STACK_ITEM_STAMP_1 has invalid value (" + b + ")"); - } + if(b >= 68719476736L) { throw new IllegalArgumentException("hub.stack/STACK_ITEM_STAMP_1 has invalid value (" + b + ")"); } stackItemStamp1.put((byte) (b >> 32)); stackItemStamp1.put((byte) (b >> 24)); stackItemStamp1.put((byte) (b >> 16)); stackItemStamp1.put((byte) (b >> 8)); stackItemStamp1.put((byte) b); + return this; } public Trace pStackStackItemStamp2(final long b) { - if (filled.get(120)) { + if (filled.get(122)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_2 already set"); } else { - filled.set(120); + filled.set(122); } - if (b >= 68719476736L) { - throw new IllegalArgumentException( - "hub.stack/STACK_ITEM_STAMP_2 has invalid value (" + b + ")"); - } + if(b >= 68719476736L) { throw new IllegalArgumentException("hub.stack/STACK_ITEM_STAMP_2 has invalid value (" + b + ")"); } stackItemStamp2.put((byte) (b >> 32)); stackItemStamp2.put((byte) (b >> 24)); stackItemStamp2.put((byte) (b >> 16)); stackItemStamp2.put((byte) (b >> 8)); stackItemStamp2.put((byte) b); + return this; } public Trace pStackStackItemStamp3(final long b) { - if (filled.get(121)) { + if (filled.get(123)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_3 already set"); } else { - filled.set(121); + filled.set(123); } - if (b >= 68719476736L) { - throw new IllegalArgumentException( - "hub.stack/STACK_ITEM_STAMP_3 has invalid value (" + b + ")"); - } + if(b >= 68719476736L) { throw new IllegalArgumentException("hub.stack/STACK_ITEM_STAMP_3 has invalid value (" + b + ")"); } stackItemStamp3.put((byte) (b >> 32)); stackItemStamp3.put((byte) (b >> 24)); stackItemStamp3.put((byte) (b >> 16)); stackItemStamp3.put((byte) (b >> 8)); stackItemStamp3.put((byte) b); + return this; } public Trace pStackStackItemStamp4(final long b) { - if (filled.get(122)) { + if (filled.get(124)) { throw new IllegalStateException("hub.stack/STACK_ITEM_STAMP_4 already set"); } else { - filled.set(122); + filled.set(124); } - if (b >= 68719476736L) { - throw new IllegalArgumentException( - "hub.stack/STACK_ITEM_STAMP_4 has invalid value (" + b + ")"); - } + if(b >= 68719476736L) { throw new IllegalArgumentException("hub.stack/STACK_ITEM_STAMP_4 has invalid value (" + b + ")"); } stackItemStamp4.put((byte) (b >> 32)); stackItemStamp4.put((byte) (b >> 24)); stackItemStamp4.put((byte) (b >> 16)); stackItemStamp4.put((byte) (b >> 8)); stackItemStamp4.put((byte) b); + return this; } public Trace pStackStackItemValueHi1(final Bytes b) { - if (filled.get(136)) { + if (filled.get(138)) { throw new IllegalStateException("hub.stack/STACK_ITEM_VALUE_HI_1 already set"); } else { - filled.set(136); + filled.set(138); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.stack/STACK_ITEM_VALUE_HI_1 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.stack/STACK_ITEM_VALUE_HI_1 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.stack/STACK_ITEM_VALUE_HI_2 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.stack/STACK_ITEM_VALUE_HI_2 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.stack/STACK_ITEM_VALUE_HI_3 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.stack/STACK_ITEM_VALUE_HI_3 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.stack/STACK_ITEM_VALUE_HI_4 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.stack/STACK_ITEM_VALUE_HI_4 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.stack/STACK_ITEM_VALUE_LO_1 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.stack/STACK_ITEM_VALUE_LO_1 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.stack/STACK_ITEM_VALUE_LO_2 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.stack/STACK_ITEM_VALUE_LO_2 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.stack/STACK_ITEM_VALUE_LO_3 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.stack/STACK_ITEM_VALUE_LO_3 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.stack/STACK_ITEM_VALUE_LO_4 has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.stack/STACK_ITEM_VALUE_LO_4 has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException("hub.stack/STATIC_GAS has invalid value (" + b + ")"); - } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 24)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 16)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 8)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.stack/STATIC_GAS has invalid value (" + b + ")"); } + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 24)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 16)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 8)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) b); + return this; } @@ -5967,51 +4945,37 @@ public Trace pStackWcpFlag(final Boolean b) { } public Trace pStorageAddressHi(final long b) { - if (filled.get(103)) { + if (filled.get(105)) { throw new IllegalStateException("hub.storage/ADDRESS_HI already set"); } else { - filled.set(103); + filled.set(105); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.storage/ADDRESS_HI has invalid value (" + b + ")"); - } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 24)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 16)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 8)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.storage/ADDRESS_HI has invalid value (" + b + ")"); } + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 24)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 16)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 8)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) b); + return this; } public Trace pStorageAddressLo(final Bytes b) { - if (filled.get(132)) { + if (filled.get(134)) { throw new IllegalStateException("hub.storage/ADDRESS_LO already set"); } else { - filled.set(132); + filled.set(134); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.storage/ADDRESS_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.storage/ADDRESS_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException( - "hub.storage/DEPLOYMENT_NUMBER has invalid value (" + b + ")"); - } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 24)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 16)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 8)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.storage/DEPLOYMENT_NUMBER has invalid value (" + b + ")"); } + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 24)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 16)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 8)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) b); + return this; } public Trace pStorageDeploymentNumberFinalInBlock(final long b) { - if (filled.get(101)) { + if (filled.get(103)) { throw new IllegalStateException("hub.storage/DEPLOYMENT_NUMBER_FINAL_IN_BLOCK already set"); } else { - filled.set(101); + filled.set(103); } - if (b >= 65536L) { - throw new IllegalArgumentException( - "hub.storage/DEPLOYMENT_NUMBER_FINAL_IN_BLOCK has invalid value (" + b + ")"); - } + if(b >= 65536L) { throw new IllegalArgumentException("hub.storage/DEPLOYMENT_NUMBER_FINAL_IN_BLOCK has invalid value (" + b + ")"); } deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock.put((byte) (b >> 8)); deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock.put((byte) b); + return this; } public Trace pStorageDeploymentNumberFirstInBlock(final long b) { - if (filled.get(102)) { + if (filled.get(104)) { throw new IllegalStateException("hub.storage/DEPLOYMENT_NUMBER_FIRST_IN_BLOCK already set"); } else { - filled.set(102); + filled.set(104); } - if (b >= 65536L) { - throw new IllegalArgumentException( - "hub.storage/DEPLOYMENT_NUMBER_FIRST_IN_BLOCK has invalid value (" + b + ")"); - } + if(b >= 65536L) { throw new IllegalArgumentException("hub.storage/DEPLOYMENT_NUMBER_FIRST_IN_BLOCK has invalid value (" + b + ")"); } deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock.put((byte) (b >> 8)); deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock.put((byte) b); + return this; } public Trace pStorageDeploymentNumberInfty(final long b) { - if (filled.get(105)) { + if (filled.get(107)) { throw new IllegalStateException("hub.storage/DEPLOYMENT_NUMBER_INFTY already set"); } else { - filled.set(105); + filled.set(107); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.storage/DEPLOYMENT_NUMBER_INFTY has invalid value (" + b + ")"); - } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 24)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 16)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 8)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.storage/DEPLOYMENT_NUMBER_INFTY has invalid value (" + b + ")"); } + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 24)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 16)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 8)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) b); + return this; } @@ -6142,8 +5087,7 @@ public Trace pStorageFinalInBlk(final Boolean b) { filled.set(48); } - deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution - .put((byte) (b ? 1 : 0)); + deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution.put((byte) (b ? 1 : 0)); return this; } @@ -6155,8 +5099,7 @@ public Trace pStorageFinalInCnf(final Boolean b) { filled.set(49); } - deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode.put( - (byte) (b ? 1 : 0)); + deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode.put((byte) (b ? 1 : 0)); return this; } @@ -6180,8 +5123,7 @@ public Trace pStorageFirstInBlk(final Boolean b) { filled.set(51); } - existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.put( - (byte) (b ? 1 : 0)); + existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.put((byte) (b ? 1 : 0)); return this; } @@ -6193,8 +5135,7 @@ public Trace pStorageFirstInCnf(final Boolean b) { filled.set(52); } - existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.put( - (byte) (b ? 1 : 0)); + existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.put((byte) (b ? 1 : 0)); return this; } @@ -6206,434 +5147,363 @@ public Trace pStorageFirstInTxn(final Boolean b) { filled.set(53); } - finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn.put( - (byte) (b ? 1 : 0)); + finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn.put((byte) (b ? 1 : 0)); return this; } public Trace pStorageStorageKeyHi(final Bytes b) { - if (filled.get(133)) { + if (filled.get(135)) { throw new IllegalStateException("hub.storage/STORAGE_KEY_HI already set"); } else { - filled.set(133); + filled.set(135); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.storage/STORAGE_KEY_HI has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.storage/STORAGE_KEY_HI has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); - } + for(int i=bs.size(); i<16; i++) { balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.storage/STORAGE_KEY_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.storage/STORAGE_KEY_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); - } + for(int i=bs.size(); i<16; i++) { balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - bs.get(j)); + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.storage/VALUE_CURR_HI has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.storage/VALUE_CURR_HI has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.storage/VALUE_CURR_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.storage/VALUE_CURR_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.storage/VALUE_NEXT_HI has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.storage/VALUE_NEXT_HI has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.storage/VALUE_NEXT_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.storage/VALUE_NEXT_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.storage/VALUE_ORIG_HI has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.storage/VALUE_ORIG_HI has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.storage/VALUE_ORIG_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.storage/VALUE_ORIG_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.put(bs.get(j)); - } + for(int j=0; j 64) { - throw new IllegalArgumentException( - "hub.transaction/BASEFEE has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.transaction/BASEFEE has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - nonceXorStpGasMxpXorBasefee.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { nonceXorStpGasMxpXorBasefee.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - nonceXorStpGasMxpXorBasefee.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException( - "hub.transaction/CALL_DATA_SIZE has invalid value (" + b + ")"); - } - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 24)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 16)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) (b >> 8)); - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .put((byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.transaction/CALL_DATA_SIZE has invalid value (" + b + ")"); } + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 24)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 16)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) (b >> 8)); + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.put((byte) b); + return this; } public Trace pTransactionCoinbaseAddressHi(final long b) { - if (filled.get(104)) { + if (filled.get(106)) { throw new IllegalStateException("hub.transaction/COINBASE_ADDRESS_HI already set"); } else { - filled.set(104); + filled.set(106); } - if (b >= 4294967296L) { - throw new IllegalArgumentException( - "hub.transaction/COINBASE_ADDRESS_HI has invalid value (" + b + ")"); - } - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 24)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 16)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) (b >> 8)); - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .put((byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.transaction/COINBASE_ADDRESS_HI has invalid value (" + b + ")"); } + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 24)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 16)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) (b >> 8)); + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.put((byte) b); + return this; } public Trace pTransactionCoinbaseAddressLo(final Bytes b) { - if (filled.get(132)) { + if (filled.get(134)) { throw new IllegalStateException("hub.transaction/COINBASE_ADDRESS_LO already set"); } else { - filled.set(132); + filled.set(134); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.transaction/COINBASE_ADDRESS_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.transaction/COINBASE_ADDRESS_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException( - "hub.transaction/FROM_ADDRESS_HI has invalid value (" + b + ")"); - } - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 24)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 16)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) (b >> 8)); - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put( - (byte) b); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.transaction/FROM_ADDRESS_HI has invalid value (" + b + ")"); } + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 24)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 16)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) (b >> 8)); + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.put((byte) b); + return this; } public Trace pTransactionFromAddressLo(final Bytes b) { - if (filled.get(133)) { + if (filled.get(135)) { throw new IllegalStateException("hub.transaction/FROM_ADDRESS_LO already set"); } else { - filled.set(133); + filled.set(135); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.transaction/FROM_ADDRESS_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.transaction/FROM_ADDRESS_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - (byte) 0); - } + for(int i=bs.size(); i<16; i++) { balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.put( - bs.get(j)); - } + for(int j=0; j 64) { - throw new IllegalArgumentException( - "hub.transaction/GAS_INITIALLY_AVAILABLE has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.transaction/GAS_INITIALLY_AVAILABLE has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.put(bs.get(j)); - } + for(int j=0; j 64) { - throw new IllegalArgumentException( - "hub.transaction/GAS_LEFTOVER has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.transaction/GAS_LEFTOVER has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - stpGasUpfrontGasCostXorGasLeftover.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { stpGasUpfrontGasCostXorGasLeftover.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - stpGasUpfrontGasCostXorGasLeftover.put(bs.get(j)); - } + for(int j=0; j 64) { - throw new IllegalArgumentException( - "hub.transaction/GAS_LIMIT has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.transaction/GAS_LIMIT has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - gasLimit.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { gasLimit.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - gasLimit.put(bs.get(j)); - } + for(int j=0; j 64) { - throw new IllegalArgumentException( - "hub.transaction/GAS_PRICE has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.transaction/GAS_PRICE has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - gasPrice.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { gasPrice.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - gasPrice.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException( - "hub.transaction/INIT_CODE_SIZE has invalid value (" + b + ")"); - } - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put( - (byte) (b >> 24)); - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put( - (byte) (b >> 16)); - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put( - (byte) (b >> 8)); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.transaction/INIT_CODE_SIZE has invalid value (" + b + ")"); } + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) (b >> 24)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) (b >> 16)); + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) (b >> 8)); codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.put((byte) b); + return this; } public Trace pTransactionInitialBalance(final Bytes b) { - if (filled.get(134)) { + if (filled.get(136)) { throw new IllegalStateException("hub.transaction/INITIAL_BALANCE already set"); } else { - filled.set(134); + filled.set(136); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.transaction/INITIAL_BALANCE has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.transaction/INITIAL_BALANCE has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - (byte) 0); - } + for(int i=bs.size(); i<16; i++) { balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.put( - bs.get(j)); - } + for(int j=0; j 64) { - throw new IllegalArgumentException( - "hub.transaction/NONCE has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.transaction/NONCE has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - nonce.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { nonce.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - nonce.put(bs.get(j)); - } + for(int j=0; j 64) { - throw new IllegalArgumentException( - "hub.transaction/PRIORITY_FEE_PER_GAS has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.transaction/PRIORITY_FEE_PER_GAS has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - priorityFeePerGas.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { priorityFeePerGas.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - priorityFeePerGas.put(bs.get(j)); - } + for(int j=0; j 64) { - throw new IllegalArgumentException( - "hub.transaction/REFUND_COUNTER_INFINITY has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.transaction/REFUND_COUNTER_INFINITY has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - refundCounterInfinity.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { refundCounterInfinity.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - refundCounterInfinity.put(bs.get(j)); - } + for(int j=0; j 64) { - throw new IllegalArgumentException( - "hub.transaction/REFUND_EFFECTIVE has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 64) { throw new IllegalArgumentException("hub.transaction/REFUND_EFFECTIVE has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 8; i++) { - refundEffective.put((byte) 0); - } + for(int i=bs.size(); i<8; i++) { refundEffective.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - refundEffective.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException( - "hub.transaction/TO_ADDRESS_HI has invalid value (" + b + ")"); - } - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put( - (byte) (b >> 24)); - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put( - (byte) (b >> 16)); - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put( - (byte) (b >> 8)); + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.transaction/TO_ADDRESS_HI has invalid value (" + b + ")"); } + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) (b >> 24)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) (b >> 16)); + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) (b >> 8)); deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.put((byte) b); + return this; } public Trace pTransactionToAddressLo(final Bytes b) { - if (filled.get(135)) { + if (filled.get(137)) { throw new IllegalStateException("hub.transaction/TO_ADDRESS_LO already set"); } else { - filled.set(135); + filled.set(137); } // Trim array to size Bytes bs = b.trimLeadingZeros(); // Sanity check against expected width - if (bs.bitLength() > 128) { - throw new IllegalArgumentException( - "hub.transaction/TO_ADDRESS_LO has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.transaction/TO_ADDRESS_LO has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.put(bs.get(j)); - } + for(int j=0; j 128) { - throw new IllegalArgumentException( - "hub.transaction/VALUE has invalid width (" + bs.bitLength() + "bits)"); - } + if(bs.bitLength() > 128) { throw new IllegalArgumentException("hub.transaction/VALUE has invalid width (" + bs.bitLength() + "bits)"); } // Write padding (if necessary) - for (int i = bs.size(); i < 16; i++) { - codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.put((byte) 0); - } + for(int i=bs.size(); i<16; i++) { codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.put((byte) 0); } // Write bytes - for (int j = 0; j < bs.size(); j++) { - codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.put(bs.get(j)); - } + for(int j=0; j= 4294967296L) { - throw new IllegalArgumentException("hub.PROGRAM_COUNTER has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.PROGRAM_COUNTER has invalid value (" + b + ")"); } programCounter.put((byte) (b >> 24)); programCounter.put((byte) (b >> 16)); programCounter.put((byte) (b >> 8)); programCounter.put((byte) b); + return this; } @@ -7195,14 +5955,13 @@ public Trace programCounterNew(final long b) { filled.set(34); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.PROGRAM_COUNTER_NEW has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.PROGRAM_COUNTER_NEW has invalid value (" + b + ")"); } programCounterNew.put((byte) (b >> 24)); programCounterNew.put((byte) (b >> 16)); programCounterNew.put((byte) (b >> 8)); programCounterNew.put((byte) b); + return this; } @@ -7213,14 +5972,13 @@ public Trace refundCounter(final long b) { filled.set(35); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.REFUND_COUNTER has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.REFUND_COUNTER has invalid value (" + b + ")"); } refundCounter.put((byte) (b >> 24)); refundCounter.put((byte) (b >> 16)); refundCounter.put((byte) (b >> 8)); refundCounter.put((byte) b); + return this; } @@ -7231,14 +5989,13 @@ public Trace refundCounterNew(final long b) { filled.set(36); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.REFUND_COUNTER_NEW has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.REFUND_COUNTER_NEW has invalid value (" + b + ")"); } refundCounterNew.put((byte) (b >> 24)); refundCounterNew.put((byte) (b >> 16)); refundCounterNew.put((byte) (b >> 8)); refundCounterNew.put((byte) b); + return this; } @@ -7249,12 +6006,11 @@ public Trace relativeBlockNumber(final long b) { filled.set(37); } - if (b >= 65536L) { - throw new IllegalArgumentException("hub.RELATIVE_BLOCK_NUMBER has invalid value (" + b + ")"); - } + if(b >= 65536L) { throw new IllegalArgumentException("hub.RELATIVE_BLOCK_NUMBER has invalid value (" + b + ")"); } relativeBlockNumber.put((byte) (b >> 8)); relativeBlockNumber.put((byte) b); + return this; } @@ -7265,14 +6021,13 @@ public Trace subStamp(final long b) { filled.set(38); } - if (b >= 4294967296L) { - throw new IllegalArgumentException("hub.SUB_STAMP has invalid value (" + b + ")"); - } + if(b >= 4294967296L) { throw new IllegalArgumentException("hub.SUB_STAMP has invalid value (" + b + ")"); } subStamp.put((byte) (b >> 24)); subStamp.put((byte) (b >> 16)); subStamp.put((byte) (b >> 8)); subStamp.put((byte) b); + return this; } @@ -7353,56 +6108,48 @@ public Trace validateRow() { throw new IllegalStateException("hub.ABSOLUTE_TRANSACTION_NUMBER has not been filled"); } - if (!filled.get(103)) { - throw new IllegalStateException( - "hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_CALL_DATA_SIZE has not been filled"); + if (!filled.get(105)) { + throw new IllegalStateException("hub.ADDRESS_HI_xor_ACCOUNT_ADDRESS_HI_xor_CCRS_STAMP_xor_PRC_CALLEE_GAS_xor_STATIC_GAS_xor_ADDRESS_HI_xor_CALL_DATA_SIZE has not been filled"); } - if (!filled.get(132)) { - throw new IllegalStateException( - "hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO has not been filled"); + if (!filled.get(134)) { + throw new IllegalStateException("hub.ADDRESS_LO_xor_ACCOUNT_ADDRESS_LO_xor_EXP_DATA_1_xor_HASH_INFO_KECCAK_HI_xor_ADDRESS_LO_xor_COINBASE_ADDRESS_LO has not been filled"); } if (!filled.get(45)) { - throw new IllegalStateException( - "hub.AGAIN_IN_BLK_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_WILL_REVERT_xor_ACC_FLAG_xor_AGAIN_IN_BLK_xor_COPY_TXCD has not been filled"); + throw new IllegalStateException("hub.AGAIN_IN_BLK_xor_IS_ROOT_xor_CCSR_FLAG_xor_CALL_ABORT_WILL_REVERT_xor_ACC_FLAG_xor_AGAIN_IN_BLK_xor_COPY_TXCD has not been filled"); } if (!filled.get(46)) { - throw new IllegalStateException( - "hub.AGAIN_IN_CNF_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_ABORT_WONT_REVERT_xor_ADD_FLAG_xor_AGAIN_IN_CNF_xor_IS_DEPLOYMENT has not been filled"); + throw new IllegalStateException("hub.AGAIN_IN_CNF_xor_IS_STATIC_xor_EXP_FLAG_xor_CALL_ABORT_WONT_REVERT_xor_ADD_FLAG_xor_AGAIN_IN_CNF_xor_IS_DEPLOYMENT has not been filled"); } if (!filled.get(47)) { - throw new IllegalStateException( - "hub.AGAIN_IN_TXN_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_BIN_FLAG_xor_AGAIN_IN_TXN_xor_IS_TYPE2 has not been filled"); + throw new IllegalStateException("hub.AGAIN_IN_TXN_xor_UPDATE_xor_MMU_FLAG_xor_CALL_EOA_SUCCESS_CALLER_WILL_REVERT_xor_BIN_FLAG_xor_AGAIN_IN_TXN_xor_IS_TYPE2 has not been filled"); } if (!filled.get(94)) { throw new IllegalStateException("hub.ALPHA has not been filled"); } - if (!filled.get(134)) { - throw new IllegalStateException( - "hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE has not been filled"); + if (!filled.get(136)) { + throw new IllegalStateException("hub.BALANCE_NEW_xor_CALLER_ADDRESS_LO_xor_EXP_DATA_3_xor_PUSH_VALUE_HI_xor_STORAGE_KEY_LO_xor_INITIAL_BALANCE has not been filled"); } - if (!filled.get(133)) { - throw new IllegalStateException( - "hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO has not been filled"); + if (!filled.get(135)) { + throw new IllegalStateException("hub.BALANCE_xor_BYTE_CODE_ADDRESS_LO_xor_EXP_DATA_2_xor_HASH_INFO_KECCAK_LO_xor_STORAGE_KEY_HI_xor_FROM_ADDRESS_LO has not been filled"); } - if (!filled.get(111)) { + if (!filled.get(113)) { throw new IllegalStateException("hub.CALL_DATA_OFFSET_xor_MMU_SIZE has not been filled"); } - if (!filled.get(112)) { + if (!filled.get(114)) { throw new IllegalStateException("hub.CALL_DATA_SIZE_xor_MMU_SRC_ID has not been filled"); } - if (!filled.get(97)) { - throw new IllegalStateException( - "hub.CALL_STACK_DEPTH_xor_STACK_ITEM_HEIGHT_1 has not been filled"); + if (!filled.get(99)) { + throw new IllegalStateException("hub.CALL_STACK_DEPTH_xor_STACK_ITEM_HEIGHT_1 has not been filled"); } if (!filled.get(1)) { @@ -7413,39 +6160,32 @@ public Trace validateRow() { throw new IllegalStateException("hub.CODE_FRAGMENT_INDEX has not been filled"); } - if (!filled.get(104)) { - throw new IllegalStateException( - "hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_COINBASE_ADDRESS_HI has not been filled"); + if (!filled.get(106)) { + throw new IllegalStateException("hub.CODE_FRAGMENT_INDEX_xor_ACCOUNT_DEPLOYMENT_NUMBER_xor_EXP_INST_xor_PRC_CALLER_GAS_xor_DEPLOYMENT_NUMBER_xor_COINBASE_ADDRESS_HI has not been filled"); } - if (!filled.get(136)) { - throw new IllegalStateException( - "hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_STACK_ITEM_VALUE_HI_1_xor_VALUE_CURR_LO_xor_VALUE has not been filled"); + if (!filled.get(138)) { + throw new IllegalStateException("hub.CODE_HASH_HI_NEW_xor_EXP_DATA_5_xor_STACK_ITEM_VALUE_HI_1_xor_VALUE_CURR_LO_xor_VALUE has not been filled"); } - if (!filled.get(135)) { - throw new IllegalStateException( - "hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO has not been filled"); + if (!filled.get(137)) { + throw new IllegalStateException("hub.CODE_HASH_HI_xor_CALL_VALUE_xor_EXP_DATA_4_xor_PUSH_VALUE_LO_xor_VALUE_CURR_HI_xor_TO_ADDRESS_LO has not been filled"); } - if (!filled.get(138)) { - throw new IllegalStateException( - "hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_STACK_ITEM_VALUE_HI_3_xor_VALUE_NEXT_LO has not been filled"); + if (!filled.get(140)) { + throw new IllegalStateException("hub.CODE_HASH_LO_NEW_xor_MMU_LIMB_2_xor_STACK_ITEM_VALUE_HI_3_xor_VALUE_NEXT_LO has not been filled"); } - if (!filled.get(137)) { - throw new IllegalStateException( - "hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_STACK_ITEM_VALUE_HI_2_xor_VALUE_NEXT_HI has not been filled"); + if (!filled.get(139)) { + throw new IllegalStateException("hub.CODE_HASH_LO_xor_MMU_LIMB_1_xor_STACK_ITEM_VALUE_HI_2_xor_VALUE_NEXT_HI has not been filled"); } - if (!filled.get(106)) { - throw new IllegalStateException( - "hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_INIT_CODE_SIZE has not been filled"); + if (!filled.get(108)) { + throw new IllegalStateException("hub.CODE_SIZE_NEW_xor_BYTE_CODE_CODE_FRAGMENT_INDEX_xor_MMU_EXO_SUM_xor_PRC_CDS_xor_INIT_CODE_SIZE has not been filled"); } - if (!filled.get(105)) { - throw new IllegalStateException( - "hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_FROM_ADDRESS_HI has not been filled"); + if (!filled.get(107)) { + throw new IllegalStateException("hub.CODE_SIZE_xor_BYTE_CODE_ADDRESS_HI_xor_MMU_AUX_ID_xor_PRC_CDO_xor_DEPLOYMENT_NUMBER_INFTY_xor_FROM_ADDRESS_HI has not been filled"); } if (!filled.get(3)) { @@ -7464,7 +6204,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.CONTEXT_NUMBER_NEW has not been filled"); } - if (!filled.get(113)) { + if (!filled.get(115)) { throw new IllegalStateException("hub.CONTEXT_NUMBER_xor_MMU_TGT_ID has not been filled"); } @@ -7492,44 +6232,36 @@ public Trace validateRow() { throw new IllegalStateException("hub.DELTA has not been filled"); } - if (!filled.get(101)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_FINAL_IN_BLOCK_xor_DEPLOYMENT_NUMBER_FINAL_IN_BLOCK has not been filled"); + if (!filled.get(103)) { + throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_FINAL_IN_BLOCK_xor_DEPLOYMENT_NUMBER_FINAL_IN_BLOCK has not been filled"); } - if (!filled.get(102)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_FIRST_IN_BLOCK_xor_DEPLOYMENT_NUMBER_FIRST_IN_BLOCK has not been filled"); + if (!filled.get(104)) { + throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_FIRST_IN_BLOCK_xor_DEPLOYMENT_NUMBER_FIRST_IN_BLOCK has not been filled"); } - if (!filled.get(108)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO has not been filled"); + if (!filled.get(110)) { + throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_INFTY_xor_BYTE_CODE_DEPLOYMENT_STATUS_xor_MMU_PHASE_xor_PRC_RAO has not been filled"); } - if (!filled.get(109)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); + if (!filled.get(111)) { + throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_NEW_xor_CALLER_ADDRESS_HI_xor_MMU_REF_OFFSET_xor_PRC_RETURN_GAS has not been filled"); } - if (!filled.get(107)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_TO_ADDRESS_HI has not been filled"); + if (!filled.get(109)) { + throw new IllegalStateException("hub.DEPLOYMENT_NUMBER_xor_BYTE_CODE_DEPLOYMENT_NUMBER_xor_MMU_INST_xor_PRC_RAC_xor_TO_ADDRESS_HI has not been filled"); } if (!filled.get(49)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_INFTY_xor_MXP_DEPLOYS_xor_CALL_EXCEPTION_xor_CALL_FLAG_xor_FINAL_IN_CNF_xor_STATUS_CODE has not been filled"); + throw new IllegalStateException("hub.DEPLOYMENT_STATUS_INFTY_xor_MXP_DEPLOYS_xor_CALL_EXCEPTION_xor_CALL_FLAG_xor_FINAL_IN_CNF_xor_STATUS_CODE has not been filled"); } if (!filled.get(50)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_NEW_xor_MXP_FLAG_xor_CALL_PRC_FAILURE_xor_CON_FLAG_xor_FINAL_IN_TXN has not been filled"); + throw new IllegalStateException("hub.DEPLOYMENT_STATUS_NEW_xor_MXP_FLAG_xor_CALL_PRC_FAILURE_xor_CON_FLAG_xor_FINAL_IN_TXN has not been filled"); } if (!filled.get(48)) { - throw new IllegalStateException( - "hub.DEPLOYMENT_STATUS_xor_MMU_SUCCESS_BIT_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BTC_FLAG_xor_FINAL_IN_BLK_xor_REQUIRES_EVM_EXECUTION has not been filled"); + throw new IllegalStateException("hub.DEPLOYMENT_STATUS_xor_MMU_SUCCESS_BIT_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BTC_FLAG_xor_FINAL_IN_BLK_xor_REQUIRES_EVM_EXECUTION has not been filled"); } if (!filled.get(12)) { @@ -7541,43 +6273,35 @@ public Trace validateRow() { } if (!filled.get(52)) { - throw new IllegalStateException( - "hub.EXISTS_NEW_xor_MXP_MXPX_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_CREATE_FLAG_xor_FIRST_IN_CNF has not been filled"); + throw new IllegalStateException("hub.EXISTS_NEW_xor_MXP_MXPX_xor_CALL_PRC_SUCCESS_CALLER_WONT_REVERT_xor_CREATE_FLAG_xor_FIRST_IN_CNF has not been filled"); } if (!filled.get(51)) { - throw new IllegalStateException( - "hub.EXISTS_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_COPY_FLAG_xor_FIRST_IN_BLK has not been filled"); + throw new IllegalStateException("hub.EXISTS_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_COPY_FLAG_xor_FIRST_IN_BLK has not been filled"); } if (!filled.get(53)) { - throw new IllegalStateException( - "hub.FINAL_IN_BLK_xor_MXP_SIZE_1_NONZERO_NO_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_DEC_FLAG_1_xor_FIRST_IN_TXN has not been filled"); + throw new IllegalStateException("hub.FINAL_IN_BLK_xor_MXP_SIZE_1_NONZERO_NO_MXPX_xor_CALL_SMC_FAILURE_CALLER_WILL_REVERT_xor_DEC_FLAG_1_xor_FIRST_IN_TXN has not been filled"); } if (!filled.get(54)) { - throw new IllegalStateException( - "hub.FINAL_IN_CNF_xor_MXP_SIZE_2_NONZERO_NO_MXPX_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_2_xor_VALUE_CURR_CHANGES has not been filled"); + throw new IllegalStateException("hub.FINAL_IN_CNF_xor_MXP_SIZE_2_NONZERO_NO_MXPX_xor_CALL_SMC_FAILURE_CALLER_WONT_REVERT_xor_DEC_FLAG_2_xor_UNCONSTRAINED_FINAL has not been filled"); } if (!filled.get(55)) { - throw new IllegalStateException( - "hub.FINAL_IN_TXN_xor_OOB_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_3_xor_VALUE_CURR_IS_ORIG has not been filled"); + throw new IllegalStateException("hub.FINAL_IN_TXN_xor_OOB_FLAG_xor_CALL_SMC_SUCCESS_CALLER_WILL_REVERT_xor_DEC_FLAG_3_xor_UNCONSTRAINED_FIRST has not been filled"); } if (!filled.get(56)) { - throw new IllegalStateException( - "hub.FIRST_IN_BLK_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_4_xor_VALUE_CURR_IS_ZERO has not been filled"); + throw new IllegalStateException("hub.FIRST_IN_BLK_xor_STP_EXISTS_xor_CALL_SMC_SUCCESS_CALLER_WONT_REVERT_xor_DEC_FLAG_4_xor_VALUE_CURR_CHANGES has not been filled"); } if (!filled.get(57)) { - throw new IllegalStateException( - "hub.FIRST_IN_CNF_xor_STP_FLAG_xor_CREATE_ABORT_xor_DUP_FLAG_xor_VALUE_NEXT_IS_CURR has not been filled"); + throw new IllegalStateException("hub.FIRST_IN_CNF_xor_STP_FLAG_xor_CREATE_ABORT_xor_DUP_FLAG_xor_VALUE_CURR_IS_ORIG has not been filled"); } if (!filled.get(58)) { - throw new IllegalStateException( - "hub.FIRST_IN_TXN_xor_STP_OOGX_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_EXT_FLAG_xor_VALUE_NEXT_IS_ORIG has not been filled"); + throw new IllegalStateException("hub.FIRST_IN_TXN_xor_STP_OOGX_xor_CREATE_EMPTY_INIT_CODE_WILL_REVERT_xor_EXT_FLAG_xor_VALUE_CURR_IS_ZERO has not been filled"); } if (!filled.get(14)) { @@ -7592,7 +6316,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.GAS_EXPECTED has not been filled"); } - if (!filled.get(126)) { + if (!filled.get(128)) { throw new IllegalStateException("hub.GAS_LIMIT has not been filled"); } @@ -7600,18 +6324,16 @@ public Trace validateRow() { throw new IllegalStateException("hub.GAS_NEXT has not been filled"); } - if (!filled.get(127)) { + if (!filled.get(129)) { throw new IllegalStateException("hub.GAS_PRICE has not been filled"); } if (!filled.get(60)) { - throw new IllegalStateException( - "hub.HAS_CODE_NEW_xor_CREATE_EXCEPTION_xor_HASH_INFO_FLAG_xor_VALUE_ORIG_IS_ZERO has not been filled"); + throw new IllegalStateException("hub.HAS_CODE_NEW_xor_CREATE_EXCEPTION_xor_HASH_INFO_FLAG_xor_VALUE_NEXT_IS_ORIG has not been filled"); } if (!filled.get(59)) { - throw new IllegalStateException( - "hub.HAS_CODE_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_HALT_FLAG_xor_VALUE_NEXT_IS_ZERO has not been filled"); + throw new IllegalStateException("hub.HAS_CODE_xor_STP_WARMTH_xor_CREATE_EMPTY_INIT_CODE_WONT_REVERT_xor_HALT_FLAG_xor_VALUE_NEXT_IS_CURR has not been filled"); } if (!filled.get(18)) { @@ -7630,13 +6352,12 @@ public Trace validateRow() { throw new IllegalStateException("hub.HUB_STAMP_TRANSACTION_END has not been filled"); } - if (!filled.get(165)) { + if (!filled.get(167)) { throw new IllegalStateException("hub.INSTRUCTION has not been filled"); } if (!filled.get(61)) { - throw new IllegalStateException( - "hub.IS_PRECOMPILE_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_ICPX_xor_WARMTH has not been filled"); + throw new IllegalStateException("hub.IS_PRECOMPILE_xor_CREATE_FAILURE_CONDITION_WILL_REVERT_xor_ICPX_xor_VALUE_NEXT_IS_ZERO has not been filled"); } if (!filled.get(22)) { @@ -7644,40 +6365,38 @@ public Trace validateRow() { } if (!filled.get(63)) { - throw new IllegalStateException( - "hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_JUMPX has not been filled"); + throw new IllegalStateException("hub.MARKED_FOR_SELFDESTRUCT_NEW_xor_CREATE_NONEMPTY_INIT_CODE_FAILURE_WILL_REVERT_xor_JUMPX_xor_WARMTH has not been filled"); } if (!filled.get(62)) { - throw new IllegalStateException( - "hub.MARKED_FOR_SELFDESTRUCT_xor_CREATE_FAILURE_CONDITION_WONT_REVERT_xor_INVALID_FLAG_xor_WARMTH_NEW has not been filled"); + throw new IllegalStateException("hub.MARKED_FOR_SELFDESTRUCT_xor_CREATE_FAILURE_CONDITION_WONT_REVERT_xor_INVALID_FLAG_xor_VALUE_ORIG_IS_ZERO has not been filled"); } if (!filled.get(23)) { throw new IllegalStateException("hub.MMU_STAMP has not been filled"); } - if (!filled.get(145)) { + if (!filled.get(147)) { throw new IllegalStateException("hub.MXP_OFFSET_2_HI has not been filled"); } - if (!filled.get(146)) { + if (!filled.get(148)) { throw new IllegalStateException("hub.MXP_OFFSET_2_LO has not been filled"); } - if (!filled.get(147)) { + if (!filled.get(149)) { throw new IllegalStateException("hub.MXP_SIZE_1_HI has not been filled"); } - if (!filled.get(148)) { + if (!filled.get(150)) { throw new IllegalStateException("hub.MXP_SIZE_1_LO has not been filled"); } - if (!filled.get(149)) { + if (!filled.get(151)) { throw new IllegalStateException("hub.MXP_SIZE_2_HI has not been filled"); } - if (!filled.get(150)) { + if (!filled.get(152)) { throw new IllegalStateException("hub.MXP_SIZE_2_LO has not been filled"); } @@ -7685,60 +6404,67 @@ public Trace validateRow() { throw new IllegalStateException("hub.MXP_STAMP has not been filled"); } - if (!filled.get(151)) { + if (!filled.get(153)) { throw new IllegalStateException("hub.MXP_WORDS has not been filled"); } + if (!filled.get(96)) { + throw new IllegalStateException("hub.NB_ADDED has not been filled"); + } + + if (!filled.get(97)) { + throw new IllegalStateException("hub.NB_REMOVED has not been filled"); + } + if (!filled.get(25)) { throw new IllegalStateException("hub.NON_STACK_ROWS has not been filled"); } - if (!filled.get(128)) { + if (!filled.get(130)) { throw new IllegalStateException("hub.NONCE has not been filled"); } - if (!filled.get(124)) { - throw new IllegalStateException( - "hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE has not been filled"); + if (!filled.get(126)) { + throw new IllegalStateException("hub.NONCE_NEW_xor_STP_GAS_PAID_OUT_OF_POCKET_xor_GAS_INITIALLY_AVAILABLE has not been filled"); } - if (!filled.get(123)) { + if (!filled.get(125)) { throw new IllegalStateException("hub.NONCE_xor_STP_GAS_MXP_xor_BASEFEE has not been filled"); } - if (!filled.get(152)) { + if (!filled.get(154)) { throw new IllegalStateException("hub.OOB_DATA_1 has not been filled"); } - if (!filled.get(153)) { + if (!filled.get(155)) { throw new IllegalStateException("hub.OOB_DATA_2 has not been filled"); } - if (!filled.get(154)) { + if (!filled.get(156)) { throw new IllegalStateException("hub.OOB_DATA_3 has not been filled"); } - if (!filled.get(155)) { + if (!filled.get(157)) { throw new IllegalStateException("hub.OOB_DATA_4 has not been filled"); } - if (!filled.get(156)) { + if (!filled.get(158)) { throw new IllegalStateException("hub.OOB_DATA_5 has not been filled"); } - if (!filled.get(157)) { + if (!filled.get(159)) { throw new IllegalStateException("hub.OOB_DATA_6 has not been filled"); } - if (!filled.get(158)) { + if (!filled.get(160)) { throw new IllegalStateException("hub.OOB_DATA_7 has not been filled"); } - if (!filled.get(159)) { + if (!filled.get(161)) { throw new IllegalStateException("hub.OOB_DATA_8 has not been filled"); } - if (!filled.get(160)) { + if (!filled.get(162)) { throw new IllegalStateException("hub.OOB_DATA_9 has not been filled"); } @@ -7783,8 +6509,7 @@ public Trace validateRow() { } if (!filled.get(72)) { - throw new IllegalStateException( - "hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MUL_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_FAILURE_KNOWN_TO_HUB_xor_MUL_FLAG has not been filled"); } if (!filled.get(73)) { @@ -7808,16 +6533,14 @@ public Trace validateRow() { } if (!filled.get(78)) { - throw new IllegalStateException( - "hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_RDCX has not been filled"); + throw new IllegalStateException("hub.PRC_SUCCESS_CALLER_WILL_REVERT_xor_RDCX has not been filled"); } if (!filled.get(79)) { - throw new IllegalStateException( - "hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_SHF_FLAG has not been filled"); + throw new IllegalStateException("hub.PRC_SUCCESS_CALLER_WONT_REVERT_xor_SHF_FLAG has not been filled"); } - if (!filled.get(129)) { + if (!filled.get(131)) { throw new IllegalStateException("hub.PRIORITY_FEE_PER_GAS has not been filled"); } @@ -7833,7 +6556,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.REFUND_COUNTER has not been filled"); } - if (!filled.get(130)) { + if (!filled.get(132)) { throw new IllegalStateException("hub.REFUND_COUNTER_INFINITY has not been filled"); } @@ -7841,7 +6564,7 @@ public Trace validateRow() { throw new IllegalStateException("hub.REFUND_COUNTER_NEW has not been filled"); } - if (!filled.get(131)) { + if (!filled.get(133)) { throw new IllegalStateException("hub.REFUND_EFFECTIVE has not been filled"); } @@ -7849,25 +6572,23 @@ public Trace validateRow() { throw new IllegalStateException("hub.RELATIVE_BLOCK_NUMBER has not been filled"); } - if (!filled.get(114)) { + if (!filled.get(116)) { throw new IllegalStateException("hub.RETURN_AT_CAPACITY_xor_MXP_INST has not been filled"); } - if (!filled.get(115)) { + if (!filled.get(117)) { throw new IllegalStateException("hub.RETURN_AT_OFFSET_xor_OOB_INST has not been filled"); } - if (!filled.get(116)) { - throw new IllegalStateException( - "hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND has not been filled"); + if (!filled.get(118)) { + throw new IllegalStateException("hub.RETURN_DATA_CONTEXT_NUMBER_xor_STP_GAS_STIPEND has not been filled"); } - if (!filled.get(117)) { - throw new IllegalStateException( - "hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION has not been filled"); + if (!filled.get(119)) { + throw new IllegalStateException("hub.RETURN_DATA_OFFSET_xor_STP_INSTRUCTION has not been filled"); } - if (!filled.get(118)) { + if (!filled.get(120)) { throw new IllegalStateException("hub.RETURN_DATA_SIZE has not been filled"); } @@ -7876,77 +6597,63 @@ public Trace validateRow() { } if (!filled.get(81)) { - throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SSTOREX has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WILL_REVERT_xor_SSTOREX has not been filled"); } if (!filled.get(82)) { - throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_STACKRAM_FLAG has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_EMPTY_CODE_WONT_REVERT_xor_STACKRAM_FLAG has not been filled"); } if (!filled.get(83)) { - throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACK_ITEM_POP_1 has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WILL_REVERT_xor_STACK_ITEM_POP_1 has not been filled"); } if (!filled.get(84)) { - throw new IllegalStateException( - "hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_2 has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_DEPLOYMENT_NONEMPTY_CODE_WONT_REVERT_xor_STACK_ITEM_POP_2 has not been filled"); } if (!filled.get(85)) { - throw new IllegalStateException( - "hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_MESSAGE_CALL_WILL_TOUCH_RAM_xor_STACK_ITEM_POP_3 has not been filled"); } if (!filled.get(86)) { - throw new IllegalStateException( - "hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_4 has not been filled"); + throw new IllegalStateException("hub.RETURN_FROM_MESSAGE_CALL_WONT_TOUCH_RAM_xor_STACK_ITEM_POP_4 has not been filled"); } - if (!filled.get(110)) { - throw new IllegalStateException( - "hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE has not been filled"); + if (!filled.get(112)) { + throw new IllegalStateException("hub.RLPADDR_DEP_ADDR_HI_xor_CALL_DATA_CONTEXT_NUMBER_xor_MMU_REF_SIZE has not been filled"); } - if (!filled.get(139)) { - throw new IllegalStateException( - "hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_STACK_ITEM_VALUE_HI_4_xor_VALUE_ORIG_HI has not been filled"); + if (!filled.get(141)) { + throw new IllegalStateException("hub.RLPADDR_DEP_ADDR_LO_xor_MMU_SRC_OFFSET_HI_xor_STACK_ITEM_VALUE_HI_4_xor_VALUE_ORIG_HI has not been filled"); } if (!filled.get(64)) { - throw new IllegalStateException( - "hub.RLPADDR_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED has not been filled"); + throw new IllegalStateException("hub.RLPADDR_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_FAILURE_WONT_REVERT_xor_JUMP_DESTINATION_VETTING_REQUIRED_xor_WARMTH_NEW has not been filled"); } - if (!filled.get(140)) { - throw new IllegalStateException( - "hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_STACK_ITEM_VALUE_LO_1_xor_VALUE_ORIG_LO has not been filled"); + if (!filled.get(142)) { + throw new IllegalStateException("hub.RLPADDR_KEC_HI_xor_MMU_SRC_OFFSET_LO_xor_STACK_ITEM_VALUE_LO_1_xor_VALUE_ORIG_LO has not been filled"); } - if (!filled.get(141)) { - throw new IllegalStateException( - "hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO_xor_STACK_ITEM_VALUE_LO_2 has not been filled"); + if (!filled.get(143)) { + throw new IllegalStateException("hub.RLPADDR_KEC_LO_xor_MMU_TGT_OFFSET_LO_xor_STACK_ITEM_VALUE_LO_2 has not been filled"); } - if (!filled.get(96)) { + if (!filled.get(98)) { throw new IllegalStateException("hub.RLPADDR_RECIPE has not been filled"); } - if (!filled.get(142)) { - throw new IllegalStateException( - "hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP_xor_STACK_ITEM_VALUE_LO_3 has not been filled"); + if (!filled.get(144)) { + throw new IllegalStateException("hub.RLPADDR_SALT_HI_xor_MXP_GAS_MXP_xor_STACK_ITEM_VALUE_LO_3 has not been filled"); } - if (!filled.get(143)) { - throw new IllegalStateException( - "hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI_xor_STACK_ITEM_VALUE_LO_4 has not been filled"); + if (!filled.get(145)) { + throw new IllegalStateException("hub.RLPADDR_SALT_LO_xor_MXP_OFFSET_1_HI_xor_STACK_ITEM_VALUE_LO_4 has not been filled"); } if (!filled.get(65)) { - throw new IllegalStateException( - "hub.ROMLEX_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_FLAG has not been filled"); + throw new IllegalStateException("hub.ROMLEX_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_SUCCESS_WILL_REVERT_xor_JUMP_FLAG has not been filled"); } if (!filled.get(87)) { @@ -7954,66 +6661,62 @@ public Trace validateRow() { } if (!filled.get(88)) { - throw new IllegalStateException( - "hub.SELFDESTRUCT_WILL_REVERT_xor_STATIC_FLAG has not been filled"); + throw new IllegalStateException("hub.SELFDESTRUCT_WILL_REVERT_xor_STATIC_FLAG has not been filled"); } if (!filled.get(89)) { - throw new IllegalStateException( - "hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STO_FLAG has not been filled"); + throw new IllegalStateException("hub.SELFDESTRUCT_WONT_REVERT_ALREADY_MARKED_xor_STO_FLAG has not been filled"); } if (!filled.get(90)) { - throw new IllegalStateException( - "hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_SUX has not been filled"); + throw new IllegalStateException("hub.SELFDESTRUCT_WONT_REVERT_NOT_YET_MARKED_xor_SUX has not been filled"); } - if (!filled.get(98)) { + if (!filled.get(100)) { throw new IllegalStateException("hub.STACK_ITEM_HEIGHT_2 has not been filled"); } - if (!filled.get(99)) { + if (!filled.get(101)) { throw new IllegalStateException("hub.STACK_ITEM_HEIGHT_3 has not been filled"); } - if (!filled.get(100)) { + if (!filled.get(102)) { throw new IllegalStateException("hub.STACK_ITEM_HEIGHT_4 has not been filled"); } - if (!filled.get(119)) { + if (!filled.get(121)) { throw new IllegalStateException("hub.STACK_ITEM_STAMP_1 has not been filled"); } - if (!filled.get(120)) { + if (!filled.get(122)) { throw new IllegalStateException("hub.STACK_ITEM_STAMP_2 has not been filled"); } - if (!filled.get(121)) { + if (!filled.get(123)) { throw new IllegalStateException("hub.STACK_ITEM_STAMP_3 has not been filled"); } - if (!filled.get(122)) { + if (!filled.get(124)) { throw new IllegalStateException("hub.STACK_ITEM_STAMP_4 has not been filled"); } - if (!filled.get(161)) { + if (!filled.get(163)) { throw new IllegalStateException("hub.STP_GAS_HI has not been filled"); } - if (!filled.get(162)) { + if (!filled.get(164)) { throw new IllegalStateException("hub.STP_GAS_LO has not been filled"); } - if (!filled.get(125)) { - throw new IllegalStateException( - "hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER has not been filled"); + if (!filled.get(127)) { + throw new IllegalStateException("hub.STP_GAS_UPFRONT_GAS_COST_xor_GAS_LEFTOVER has not been filled"); } - if (!filled.get(163)) { + if (!filled.get(165)) { throw new IllegalStateException("hub.STP_VALUE_HI has not been filled"); } - if (!filled.get(164)) { + if (!filled.get(166)) { throw new IllegalStateException("hub.STP_VALUE_LO has not been filled"); } @@ -8026,13 +6729,11 @@ public Trace validateRow() { } if (!filled.get(66)) { - throw new IllegalStateException( - "hub.TRM_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_KEC_FLAG has not been filled"); + throw new IllegalStateException("hub.TRM_FLAG_xor_CREATE_NONEMPTY_INIT_CODE_SUCCESS_WONT_REVERT_xor_KEC_FLAG has not been filled"); } - if (!filled.get(144)) { - throw new IllegalStateException( - "hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO has not been filled"); + if (!filled.get(146)) { + throw new IllegalStateException("hub.TRM_RAW_ADDRESS_HI_xor_MXP_OFFSET_1_LO has not been filled"); } if (!filled.get(39)) { @@ -8064,13 +6765,11 @@ public Trace validateRow() { } if (!filled.get(68)) { - throw new IllegalStateException( - "hub.WARMTH_NEW_xor_PRC_ECADD_xor_LOG_INFO_FLAG has not been filled"); + throw new IllegalStateException("hub.WARMTH_NEW_xor_PRC_ECADD_xor_LOG_INFO_FLAG has not been filled"); } if (!filled.get(67)) { - throw new IllegalStateException( - "hub.WARMTH_xor_PRC_BLAKE2f_xor_LOG_FLAG has not been filled"); + throw new IllegalStateException("hub.WARMTH_xor_PRC_BLAKE2f_xor_LOG_FLAG has not been filled"); } if (!filled.get(93)) { @@ -8088,75 +6787,47 @@ public Trace fillAndValidateRow() { absoluteTransactionNumber.position(absoluteTransactionNumber.position() + 2); } - if (!filled.get(103)) { - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .position( - addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize - .position() - + 4); + if (!filled.get(105)) { + addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.position(addressHiXorAccountAddressHiXorCcrsStampXorPrcCalleeGasXorStaticGasXorAddressHiXorCallDataSize.position() + 4); } - if (!filled.get(132)) { - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .position( - addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo - .position() - + 16); + if (!filled.get(134)) { + addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.position(addressLoXorAccountAddressLoXorExpData1XorHashInfoKeccakHiXorAddressLoXorCoinbaseAddressLo.position() + 16); } if (!filled.get(45)) { - againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd - .position( - againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd - .position() - + 1); + againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd.position(againInBlkXorIsRootXorCcsrFlagXorCallAbortWillRevertXorAccFlagXorAgainInBlkXorCopyTxcd.position() + 1); } if (!filled.get(46)) { - againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment - .position( - againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment - .position() - + 1); + againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment.position(againInCnfXorIsStaticXorExpFlagXorCallAbortWontRevertXorAddFlagXorAgainInCnfXorIsDeployment.position() + 1); } if (!filled.get(47)) { - againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2 - .position( - againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2 - .position() - + 1); + againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2.position(againInTxnXorUpdateXorMmuFlagXorCallEoaSuccessCallerWillRevertXorBinFlagXorAgainInTxnXorIsType2.position() + 1); } if (!filled.get(94)) { alpha.position(alpha.position() + 1); } - if (!filled.get(134)) { - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance - .position( - balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance - .position() - + 16); + if (!filled.get(136)) { + balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.position(balanceNewXorCallerAddressLoXorExpData3XorPushValueHiXorStorageKeyLoXorInitialBalance.position() + 16); } - if (!filled.get(133)) { - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo - .position( - balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo - .position() - + 16); + if (!filled.get(135)) { + balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.position(balanceXorByteCodeAddressLoXorExpData2XorHashInfoKeccakLoXorStorageKeyHiXorFromAddressLo.position() + 16); } - if (!filled.get(111)) { + if (!filled.get(113)) { callDataOffsetXorMmuSize.position(callDataOffsetXorMmuSize.position() + 4); } - if (!filled.get(112)) { + if (!filled.get(114)) { callDataSizeXorMmuSrcId.position(callDataSizeXorMmuSrcId.position() + 4); } - if (!filled.get(97)) { + if (!filled.get(99)) { callStackDepthXorStackItemHeight1.position(callStackDepthXorStackItemHeight1.position() + 2); } @@ -8168,47 +6839,32 @@ public Trace fillAndValidateRow() { codeFragmentIndex.position(codeFragmentIndex.position() + 4); } - if (!filled.get(104)) { - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .position( - codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi - .position() - + 4); + if (!filled.get(106)) { + codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.position(codeFragmentIndexXorAccountDeploymentNumberXorExpInstXorPrcCallerGasXorDeploymentNumberXorCoinbaseAddressHi.position() + 4); } - if (!filled.get(136)) { - codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.position( - codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.position() + 16); + if (!filled.get(138)) { + codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.position(codeHashHiNewXorExpData5XorStackItemValueHi1XorValueCurrLoXorValue.position() + 16); } - if (!filled.get(135)) { - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position( - codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() - + 16); + if (!filled.get(137)) { + codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position(codeHashHiXorCallValueXorExpData4XorPushValueLoXorValueCurrHiXorToAddressLo.position() + 16); } - if (!filled.get(138)) { - codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.position( - codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.position() + 16); + if (!filled.get(140)) { + codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.position(codeHashLoNewXorMmuLimb2XorStackItemValueHi3XorValueNextLo.position() + 16); } - if (!filled.get(137)) { - codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.position( - codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.position() + 16); + if (!filled.get(139)) { + codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.position(codeHashLoXorMmuLimb1XorStackItemValueHi2XorValueNextHi.position() + 16); } - if (!filled.get(106)) { - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.position( - codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.position() - + 4); + if (!filled.get(108)) { + codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.position(codeSizeNewXorByteCodeCodeFragmentIndexXorMmuExoSumXorPrcCdsXorInitCodeSize.position() + 4); } - if (!filled.get(105)) { - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi - .position( - codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi - .position() - + 4); + if (!filled.get(107)) { + codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.position(codeSizeXorByteCodeAddressHiXorMmuAuxIdXorPrcCdoXorDeploymentNumberInftyXorFromAddressHi.position() + 4); } if (!filled.get(3)) { @@ -8227,7 +6883,7 @@ public Trace fillAndValidateRow() { contextNumberNew.position(contextNumberNew.position() + 4); } - if (!filled.get(113)) { + if (!filled.get(115)) { contextNumberXorMmuTgtId.position(contextNumberXorMmuTgtId.position() + 4); } @@ -8255,51 +6911,36 @@ public Trace fillAndValidateRow() { delta.position(delta.position() + 1); } - if (!filled.get(101)) { - deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock.position( - deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock.position() + 2); + if (!filled.get(103)) { + deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock.position(deploymentNumberFinalInBlockXorDeploymentNumberFinalInBlock.position() + 2); } - if (!filled.get(102)) { - deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock.position( - deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock.position() + 2); + if (!filled.get(104)) { + deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock.position(deploymentNumberFirstInBlockXorDeploymentNumberFirstInBlock.position() + 2); } - if (!filled.get(108)) { - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.position( - deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.position() + 4); + if (!filled.get(110)) { + deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.position(deploymentNumberInftyXorByteCodeDeploymentStatusXorMmuPhaseXorPrcRao.position() + 4); } - if (!filled.get(109)) { - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position( - deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 4); + if (!filled.get(111)) { + deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position(deploymentNumberNewXorCallerAddressHiXorMmuRefOffsetXorPrcReturnGas.position() + 4); } - if (!filled.get(107)) { - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.position( - deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.position() - + 4); + if (!filled.get(109)) { + deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.position(deploymentNumberXorByteCodeDeploymentNumberXorMmuInstXorPrcRacXorToAddressHi.position() + 4); } if (!filled.get(49)) { - deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode - .position( - deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode - .position() - + 1); + deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode.position(deploymentStatusInftyXorMxpDeploysXorCallExceptionXorCallFlagXorFinalInCnfXorStatusCode.position() + 1); } if (!filled.get(50)) { - deploymentStatusNewXorMxpFlagXorCallPrcFailureXorConFlagXorFinalInTxn.position( - deploymentStatusNewXorMxpFlagXorCallPrcFailureXorConFlagXorFinalInTxn.position() + 1); + deploymentStatusNewXorMxpFlagXorCallPrcFailureXorConFlagXorFinalInTxn.position(deploymentStatusNewXorMxpFlagXorCallPrcFailureXorConFlagXorFinalInTxn.position() + 1); } if (!filled.get(48)) { - deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution - .position( - deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution - .position() - + 1); + deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution.position(deploymentStatusXorMmuSuccessBitXorCallEoaSuccessCallerWontRevertXorBtcFlagXorFinalInBlkXorRequiresEvmExecution.position() + 1); } if (!filled.get(12)) { @@ -8311,57 +6952,35 @@ public Trace fillAndValidateRow() { } if (!filled.get(52)) { - existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.position( - existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.position() - + 1); + existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.position(existsNewXorMxpMxpxXorCallPrcSuccessCallerWontRevertXorCreateFlagXorFirstInCnf.position() + 1); } if (!filled.get(51)) { - existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.position( - existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.position() - + 1); + existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.position(existsXorMxpMtntopXorCallPrcSuccessCallerWillRevertXorCopyFlagXorFirstInBlk.position() + 1); } if (!filled.get(53)) { - finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn - .position( - finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn - .position() - + 1); + finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn.position(finalInBlkXorMxpSize1NonzeroNoMxpxXorCallSmcFailureCallerWillRevertXorDecFlag1XorFirstInTxn.position() + 1); } if (!filled.get(54)) { - finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorValueCurrChanges - .position( - finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorValueCurrChanges - .position() - + 1); + finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorUnconstrainedFinal.position(finalInCnfXorMxpSize2NonzeroNoMxpxXorCallSmcFailureCallerWontRevertXorDecFlag2XorUnconstrainedFinal.position() + 1); } if (!filled.get(55)) { - finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorValueCurrIsOrig.position( - finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorValueCurrIsOrig - .position() - + 1); + finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorUnconstrainedFirst.position(finalInTxnXorOobFlagXorCallSmcSuccessCallerWillRevertXorDecFlag3XorUnconstrainedFirst.position() + 1); } if (!filled.get(56)) { - firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrIsZero.position( - firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrIsZero - .position() - + 1); + firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrChanges.position(firstInBlkXorStpExistsXorCallSmcSuccessCallerWontRevertXorDecFlag4XorValueCurrChanges.position() + 1); } if (!filled.get(57)) { - firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueNextIsCurr.position( - firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueNextIsCurr.position() + 1); + firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueCurrIsOrig.position(firstInCnfXorStpFlagXorCreateAbortXorDupFlagXorValueCurrIsOrig.position() + 1); } if (!filled.get(58)) { - firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueNextIsOrig.position( - firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueNextIsOrig - .position() - + 1); + firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueCurrIsZero.position(firstInTxnXorStpOogxXorCreateEmptyInitCodeWillRevertXorExtFlagXorValueCurrIsZero.position() + 1); } if (!filled.get(14)) { @@ -8376,7 +6995,7 @@ public Trace fillAndValidateRow() { gasExpected.position(gasExpected.position() + 8); } - if (!filled.get(126)) { + if (!filled.get(128)) { gasLimit.position(gasLimit.position() + 8); } @@ -8384,20 +7003,16 @@ public Trace fillAndValidateRow() { gasNext.position(gasNext.position() + 8); } - if (!filled.get(127)) { + if (!filled.get(129)) { gasPrice.position(gasPrice.position() + 8); } if (!filled.get(60)) { - hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueOrigIsZero.position( - hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueOrigIsZero.position() + 1); + hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueNextIsOrig.position(hasCodeNewXorCreateExceptionXorHashInfoFlagXorValueNextIsOrig.position() + 1); } if (!filled.get(59)) { - hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsZero.position( - hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsZero - .position() - + 1); + hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsCurr.position(hasCodeXorStpWarmthXorCreateEmptyInitCodeWontRevertXorHaltFlagXorValueNextIsCurr.position() + 1); } if (!filled.get(18)) { @@ -8416,13 +7031,12 @@ public Trace fillAndValidateRow() { hubStampTransactionEnd.position(hubStampTransactionEnd.position() + 4); } - if (!filled.get(165)) { + if (!filled.get(167)) { instruction.position(instruction.position() + 32); } if (!filled.get(61)) { - isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorWarmth.position( - isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorWarmth.position() + 1); + isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorValueNextIsZero.position(isPrecompileXorCreateFailureConditionWillRevertXorIcpxXorValueNextIsZero.position() + 1); } if (!filled.get(22)) { @@ -8430,43 +7044,38 @@ public Trace fillAndValidateRow() { } if (!filled.get(63)) { - markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpx.position( - markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpx.position() - + 1); + markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpxXorWarmth.position(markedForSelfdestructNewXorCreateNonemptyInitCodeFailureWillRevertXorJumpxXorWarmth.position() + 1); } if (!filled.get(62)) { - markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorWarmthNew.position( - markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorWarmthNew - .position() - + 1); + markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorValueOrigIsZero.position(markedForSelfdestructXorCreateFailureConditionWontRevertXorInvalidFlagXorValueOrigIsZero.position() + 1); } if (!filled.get(23)) { mmuStamp.position(mmuStamp.position() + 4); } - if (!filled.get(145)) { + if (!filled.get(147)) { mxpOffset2Hi.position(mxpOffset2Hi.position() + 16); } - if (!filled.get(146)) { + if (!filled.get(148)) { mxpOffset2Lo.position(mxpOffset2Lo.position() + 16); } - if (!filled.get(147)) { + if (!filled.get(149)) { mxpSize1Hi.position(mxpSize1Hi.position() + 16); } - if (!filled.get(148)) { + if (!filled.get(150)) { mxpSize1Lo.position(mxpSize1Lo.position() + 16); } - if (!filled.get(149)) { + if (!filled.get(151)) { mxpSize2Hi.position(mxpSize2Hi.position() + 16); } - if (!filled.get(150)) { + if (!filled.get(152)) { mxpSize2Lo.position(mxpSize2Lo.position() + 16); } @@ -8474,60 +7083,67 @@ public Trace fillAndValidateRow() { mxpStamp.position(mxpStamp.position() + 4); } - if (!filled.get(151)) { + if (!filled.get(153)) { mxpWords.position(mxpWords.position() + 16); } + if (!filled.get(96)) { + nbAdded.position(nbAdded.position() + 1); + } + + if (!filled.get(97)) { + nbRemoved.position(nbRemoved.position() + 1); + } + if (!filled.get(25)) { nonStackRows.position(nonStackRows.position() + 1); } - if (!filled.get(128)) { + if (!filled.get(130)) { nonce.position(nonce.position() + 8); } - if (!filled.get(124)) { - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position( - nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 8); + if (!filled.get(126)) { + nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position(nonceNewXorStpGasPaidOutOfPocketXorGasInitiallyAvailable.position() + 8); } - if (!filled.get(123)) { + if (!filled.get(125)) { nonceXorStpGasMxpXorBasefee.position(nonceXorStpGasMxpXorBasefee.position() + 8); } - if (!filled.get(152)) { + if (!filled.get(154)) { oobData1.position(oobData1.position() + 16); } - if (!filled.get(153)) { + if (!filled.get(155)) { oobData2.position(oobData2.position() + 16); } - if (!filled.get(154)) { + if (!filled.get(156)) { oobData3.position(oobData3.position() + 16); } - if (!filled.get(155)) { + if (!filled.get(157)) { oobData4.position(oobData4.position() + 16); } - if (!filled.get(156)) { + if (!filled.get(158)) { oobData5.position(oobData5.position() + 16); } - if (!filled.get(157)) { + if (!filled.get(159)) { oobData6.position(oobData6.position() + 16); } - if (!filled.get(158)) { + if (!filled.get(160)) { oobData7.position(oobData7.position() + 16); } - if (!filled.get(159)) { + if (!filled.get(161)) { oobData8.position(oobData8.position() + 16); } - if (!filled.get(160)) { + if (!filled.get(162)) { oobData9.position(oobData9.position() + 16); } @@ -8600,11 +7216,10 @@ public Trace fillAndValidateRow() { } if (!filled.get(79)) { - prcSuccessCallerWontRevertXorShfFlag.position( - prcSuccessCallerWontRevertXorShfFlag.position() + 1); + prcSuccessCallerWontRevertXorShfFlag.position(prcSuccessCallerWontRevertXorShfFlag.position() + 1); } - if (!filled.get(129)) { + if (!filled.get(131)) { priorityFeePerGas.position(priorityFeePerGas.position() + 8); } @@ -8620,7 +7235,7 @@ public Trace fillAndValidateRow() { refundCounter.position(refundCounter.position() + 4); } - if (!filled.get(130)) { + if (!filled.get(132)) { refundCounterInfinity.position(refundCounterInfinity.position() + 8); } @@ -8628,7 +7243,7 @@ public Trace fillAndValidateRow() { refundCounterNew.position(refundCounterNew.position() + 4); } - if (!filled.get(131)) { + if (!filled.get(133)) { refundEffective.position(refundEffective.position() + 8); } @@ -8636,24 +7251,23 @@ public Trace fillAndValidateRow() { relativeBlockNumber.position(relativeBlockNumber.position() + 2); } - if (!filled.get(114)) { + if (!filled.get(116)) { returnAtCapacityXorMxpInst.position(returnAtCapacityXorMxpInst.position() + 4); } - if (!filled.get(115)) { + if (!filled.get(117)) { returnAtOffsetXorOobInst.position(returnAtOffsetXorOobInst.position() + 4); } - if (!filled.get(116)) { - returnDataContextNumberXorStpGasStipend.position( - returnDataContextNumberXorStpGasStipend.position() + 4); + if (!filled.get(118)) { + returnDataContextNumberXorStpGasStipend.position(returnDataContextNumberXorStpGasStipend.position() + 4); } - if (!filled.get(117)) { + if (!filled.get(119)) { returnDataOffsetXorStpInstruction.position(returnDataOffsetXorStpInstruction.position() + 4); } - if (!filled.get(118)) { + if (!filled.get(120)) { returnDataSize.position(returnDataSize.position() + 4); } @@ -8662,80 +7276,63 @@ public Trace fillAndValidateRow() { } if (!filled.get(81)) { - returnFromDeploymentEmptyCodeWillRevertXorSstorex.position( - returnFromDeploymentEmptyCodeWillRevertXorSstorex.position() + 1); + returnFromDeploymentEmptyCodeWillRevertXorSstorex.position(returnFromDeploymentEmptyCodeWillRevertXorSstorex.position() + 1); } if (!filled.get(82)) { - returnFromDeploymentEmptyCodeWontRevertXorStackramFlag.position( - returnFromDeploymentEmptyCodeWontRevertXorStackramFlag.position() + 1); + returnFromDeploymentEmptyCodeWontRevertXorStackramFlag.position(returnFromDeploymentEmptyCodeWontRevertXorStackramFlag.position() + 1); } if (!filled.get(83)) { - returnFromDeploymentNonemptyCodeWillRevertXorStackItemPop1.position( - returnFromDeploymentNonemptyCodeWillRevertXorStackItemPop1.position() + 1); + returnFromDeploymentNonemptyCodeWillRevertXorStackItemPop1.position(returnFromDeploymentNonemptyCodeWillRevertXorStackItemPop1.position() + 1); } if (!filled.get(84)) { - returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop2.position( - returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop2.position() + 1); + returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop2.position(returnFromDeploymentNonemptyCodeWontRevertXorStackItemPop2.position() + 1); } if (!filled.get(85)) { - returnFromMessageCallWillTouchRamXorStackItemPop3.position( - returnFromMessageCallWillTouchRamXorStackItemPop3.position() + 1); + returnFromMessageCallWillTouchRamXorStackItemPop3.position(returnFromMessageCallWillTouchRamXorStackItemPop3.position() + 1); } if (!filled.get(86)) { - returnFromMessageCallWontTouchRamXorStackItemPop4.position( - returnFromMessageCallWontTouchRamXorStackItemPop4.position() + 1); + returnFromMessageCallWontTouchRamXorStackItemPop4.position(returnFromMessageCallWontTouchRamXorStackItemPop4.position() + 1); } - if (!filled.get(110)) { - rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position( - rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 4); + if (!filled.get(112)) { + rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position(rlpaddrDepAddrHiXorCallDataContextNumberXorMmuRefSize.position() + 4); } - if (!filled.get(139)) { - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.position( - rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.position() + 16); + if (!filled.get(141)) { + rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.position(rlpaddrDepAddrLoXorMmuSrcOffsetHiXorStackItemValueHi4XorValueOrigHi.position() + 16); } if (!filled.get(64)) { - rlpaddrFlagXorCreateNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequired - .position( - rlpaddrFlagXorCreateNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequired - .position() - + 1); + rlpaddrFlagXorCreateNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequiredXorWarmthNew.position(rlpaddrFlagXorCreateNonemptyInitCodeFailureWontRevertXorJumpDestinationVettingRequiredXorWarmthNew.position() + 1); } - if (!filled.get(140)) { - rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.position( - rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.position() + 16); + if (!filled.get(142)) { + rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.position(rlpaddrKecHiXorMmuSrcOffsetLoXorStackItemValueLo1XorValueOrigLo.position() + 16); } - if (!filled.get(141)) { - rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2.position( - rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2.position() + 16); + if (!filled.get(143)) { + rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2.position(rlpaddrKecLoXorMmuTgtOffsetLoXorStackItemValueLo2.position() + 16); } - if (!filled.get(96)) { + if (!filled.get(98)) { rlpaddrRecipe.position(rlpaddrRecipe.position() + 1); } - if (!filled.get(142)) { - rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3.position( - rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3.position() + 16); + if (!filled.get(144)) { + rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3.position(rlpaddrSaltHiXorMxpGasMxpXorStackItemValueLo3.position() + 16); } - if (!filled.get(143)) { - rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4.position( - rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4.position() + 16); + if (!filled.get(145)) { + rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4.position(rlpaddrSaltLoXorMxpOffset1HiXorStackItemValueLo4.position() + 16); } if (!filled.get(65)) { - romlexFlagXorCreateNonemptyInitCodeSuccessWillRevertXorJumpFlag.position( - romlexFlagXorCreateNonemptyInitCodeSuccessWillRevertXorJumpFlag.position() + 1); + romlexFlagXorCreateNonemptyInitCodeSuccessWillRevertXorJumpFlag.position(romlexFlagXorCreateNonemptyInitCodeSuccessWillRevertXorJumpFlag.position() + 1); } if (!filled.get(87)) { @@ -8743,66 +7340,62 @@ public Trace fillAndValidateRow() { } if (!filled.get(88)) { - selfdestructWillRevertXorStaticFlag.position( - selfdestructWillRevertXorStaticFlag.position() + 1); + selfdestructWillRevertXorStaticFlag.position(selfdestructWillRevertXorStaticFlag.position() + 1); } if (!filled.get(89)) { - selfdestructWontRevertAlreadyMarkedXorStoFlag.position( - selfdestructWontRevertAlreadyMarkedXorStoFlag.position() + 1); + selfdestructWontRevertAlreadyMarkedXorStoFlag.position(selfdestructWontRevertAlreadyMarkedXorStoFlag.position() + 1); } if (!filled.get(90)) { - selfdestructWontRevertNotYetMarkedXorSux.position( - selfdestructWontRevertNotYetMarkedXorSux.position() + 1); + selfdestructWontRevertNotYetMarkedXorSux.position(selfdestructWontRevertNotYetMarkedXorSux.position() + 1); } - if (!filled.get(98)) { + if (!filled.get(100)) { stackItemHeight2.position(stackItemHeight2.position() + 2); } - if (!filled.get(99)) { + if (!filled.get(101)) { stackItemHeight3.position(stackItemHeight3.position() + 2); } - if (!filled.get(100)) { + if (!filled.get(102)) { stackItemHeight4.position(stackItemHeight4.position() + 2); } - if (!filled.get(119)) { + if (!filled.get(121)) { stackItemStamp1.position(stackItemStamp1.position() + 5); } - if (!filled.get(120)) { + if (!filled.get(122)) { stackItemStamp2.position(stackItemStamp2.position() + 5); } - if (!filled.get(121)) { + if (!filled.get(123)) { stackItemStamp3.position(stackItemStamp3.position() + 5); } - if (!filled.get(122)) { + if (!filled.get(124)) { stackItemStamp4.position(stackItemStamp4.position() + 5); } - if (!filled.get(161)) { + if (!filled.get(163)) { stpGasHi.position(stpGasHi.position() + 16); } - if (!filled.get(162)) { + if (!filled.get(164)) { stpGasLo.position(stpGasLo.position() + 16); } - if (!filled.get(125)) { - stpGasUpfrontGasCostXorGasLeftover.position( - stpGasUpfrontGasCostXorGasLeftover.position() + 8); + if (!filled.get(127)) { + stpGasUpfrontGasCostXorGasLeftover.position(stpGasUpfrontGasCostXorGasLeftover.position() + 8); } - if (!filled.get(163)) { + if (!filled.get(165)) { stpValueHi.position(stpValueHi.position() + 16); } - if (!filled.get(164)) { + if (!filled.get(166)) { stpValueLo.position(stpValueLo.position() + 16); } @@ -8815,11 +7408,10 @@ public Trace fillAndValidateRow() { } if (!filled.get(66)) { - trmFlagXorCreateNonemptyInitCodeSuccessWontRevertXorKecFlag.position( - trmFlagXorCreateNonemptyInitCodeSuccessWontRevertXorKecFlag.position() + 1); + trmFlagXorCreateNonemptyInitCodeSuccessWontRevertXorKecFlag.position(trmFlagXorCreateNonemptyInitCodeSuccessWontRevertXorKecFlag.position() + 1); } - if (!filled.get(144)) { + if (!filled.get(146)) { trmRawAddressHiXorMxpOffset1Lo.position(trmRawAddressHiXorMxpOffset1Lo.position() + 16); } @@ -8852,8 +7444,7 @@ public Trace fillAndValidateRow() { } if (!filled.get(68)) { - warmthNewXorPrcEcaddXorLogInfoFlag.position( - warmthNewXorPrcEcaddXorLogInfoFlag.position() + 1); + warmthNewXorPrcEcaddXorLogInfoFlag.position(warmthNewXorPrcEcaddXorLogInfoFlag.position() + 1); } if (!filled.get(67)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index fb97397ee8..7b4441cefd 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -138,7 +138,7 @@ public Trace trace(Trace trace) { .pStorageAgainInCnf(this != storageFirstLastConflationPair.getFirst()) .pStorageFinalInCnf(this == storageFirstLastConflationPair.getLast()) .pStorageDeploymentNumberFirstInBlock(minDeploymentNumberInBlock) - .pStorageDeploymentNumberFinalInBlock(maxDeploymentNumberInBlock); + .pStorageDeploymentNumberFinalInBlock(maxDeploymentNumberInBlock) .pStorageValueNextIsOrig(valueNext.equals(valueOriginal)); } } From 0bf82702194a5a62f67d4e94feaccbeb7fb82ff2 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Mon, 25 Nov 2024 15:19:49 +0100 Subject: [PATCH 72/74] adding the tests from debug branch --- .../statemanager/BlockwiseAccountTest.java | 151 +++++++ .../statemanager/BlockwiseDeplNoTest.java | 153 +++++++ .../statemanager/BlockwiseStorageTest.java | 206 +++------ .../statemanager/ConflationAccountTest.java | 255 +++-------- .../statemanager/ConflationStorageTest.java | 373 +++++----------- .../StateManagerTestValidator.java | 71 +-- .../zktracer/statemanager/TestContext.java | 411 ++++++++++-------- .../statemanager/TransactionAccountTest.java | 142 ++++++ .../statemanager/TransactionStorageTest.java | 125 +++--- .../zktracer/statemanager/UtilitiesTest.java | 123 ++---- testing/src/main/solidity/TestingBase.sol | 8 +- 11 files changed, 1037 insertions(+), 981 deletions(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseAccountTest.java create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseDeplNoTest.java rename arithmetization/src/test/java/net/consensys/linea/zktracer/{ => statemanager}/StateManagerTestValidator.java (55%) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionAccountTest.java diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseAccountTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseAccountTest.java new file mode 100644 index 0000000000..b7c5f8f615 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseAccountTest.java @@ -0,0 +1,151 @@ +/* + * Copyright Consensys Software 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.statemanager; + +import net.consensys.linea.testing.MultiBlockExecutionEnvironment; +import net.consensys.linea.testing.TransactionProcessingResultValidator; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; +import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; +import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Wei; +import org.junit.jupiter.api.Test; + +import java.math.BigInteger; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class BlockwiseAccountTest { + TestContext tc; + + @Test + void testBlockwiseMapAccount() { + // initialize the test context + this.tc = new TestContext(); + this.tc.initializeTestContext(); + // prepare the transaction validator + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + tc.frameworkEntryPointAccount, + // Creates, writes, reads and self-destructs generate 2 logs, + // Reverted operations only have 1 log + List.of(3, 3, 3, + 3, 3, 3, + 3, 3, 3, 1) + ); + // fetch the Hub metadata for the state manager maps + StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); + + // prepare a multi-block execution of transactions + MultiBlockExecutionEnvironment.builder() + // initialize accounts + .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) + // Block 1 + .addBlock(List.of( + tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 1L, false, BigInteger.ONE), + tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[2], tc.addresses[0], 2L, false, BigInteger.ONE), + tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 5L, false, BigInteger.ONE) + )) + .addBlock(List.of( + tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 10L, false, BigInteger.ONE), + tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[2], tc.addresses[0], 20L, false, BigInteger.ONE), + tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 50L, false, BigInteger.ONE) + )) + .addBlock(List.of( + tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 100L, false, BigInteger.ONE), + tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[2], tc.addresses[0], 200L, false, BigInteger.ONE), + tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 500L, false, BigInteger.ONE), + tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 1234L, true, BigInteger.ONE) + )) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); + + + Map> + blockMap = stateManagerMetadata.getAccountFirstLastBlockMap(); + + // prepare data for asserts + // expected first values for the keys we are testing + int noBlocks = 3; + Wei[][] expectedFirst = { + { + TestContext.defaultBalance, + TestContext.defaultBalance + }, + { + TestContext.defaultBalance.subtract(1L).add(2L).subtract(5L), + TestContext.defaultBalance.add(1L).subtract(2L).add(5L), + }, + { + TestContext.defaultBalance.subtract(1L).add(2L).subtract(5L) + .subtract(10L).add(20L).subtract(50L), + TestContext.defaultBalance.add(1L).subtract(2L).add(5L) + .add(10L).subtract(20L).add(50L), + }, + }; + // expected last values for the keys we are testing + Wei[][] expectedLast = { + { + TestContext.defaultBalance.subtract(1L).add(2L).subtract(5L), + TestContext.defaultBalance.add(1L).subtract(2L).add(5L), + }, + { + TestContext.defaultBalance.subtract(1L).add(2L).subtract(5L) + .subtract(10L).add(20L).subtract(50L), + TestContext.defaultBalance.add(1L).subtract(2L).add(5L) + .add(10L).subtract(20L).add(50L), + }, + { + TestContext.defaultBalance.subtract(1L).add(2L).subtract(5L) + .subtract(10L).add(20L).subtract(50L) + .subtract(100L).add(200L).subtract(500L), + TestContext.defaultBalance.add(1L).subtract(2L).add(5L) + .add(10L).subtract(20L).add(50L) + .add(100L).subtract(200L).add(500L) + }, + + }; + // prepare the key pairs + Address[] keys = { + tc.initialAccounts[0].getAddress(), + tc.initialAccounts[2].getAddress(), + }; + + + // blocks are numbered starting from 1 + for (int block = 1; block <= noBlocks; block++) { + for (int i = 0; i < keys.length; i++) { + StateManagerMetadata.AddrBlockPair key = + new StateManagerMetadata.AddrBlockPair( + keys[i], + block); + TransactionProcessingMetadata. FragmentFirstAndLast + accountData = blockMap.get(key); + // asserts for the first and last storage values in conflation + // -1 due to block numbering + assertEquals(expectedFirst[block-1][i], accountData.getFirst().oldState().balance()); + assertEquals(expectedLast[block-1][i], accountData.getLast().newState().balance()); + } + } + + System.out.println("Done"); + } +} \ No newline at end of file diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseDeplNoTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseDeplNoTest.java new file mode 100644 index 0000000000..ec0ad9e7d5 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseDeplNoTest.java @@ -0,0 +1,153 @@ +/* + * Copyright Consensys Software 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.statemanager; + +import net.consensys.linea.testing.MultiBlockExecutionEnvironment; +import net.consensys.linea.testing.TransactionProcessingResultValidator; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Wei; +import org.junit.jupiter.api.Test; + +import java.math.BigInteger; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class BlockwiseDeplNoTest { + TestContext tc; + + @Test + void testBlockwiseDeplNo() { + // initialize the test context + this.tc = new TestContext(); + this.tc.initializeTestContext(); + // prepare the transaction validator + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + tc.frameworkEntryPointAccount, + // Creates, writes, reads and self-destructs generate 2 logs, + // Reverted operations only have 1 log + List.of(2, 2, 2, 2, + 2, 2, + 2, 2, 1, 2, 1) + ); + // fetch the Hub metadata for the state manager maps + StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); + + // prepare a multi-block execution of transactions + MultiBlockExecutionEnvironment.builder() + // initialize accounts + .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) + // Block 1 + .addBlock(List.of( + tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, tc.salts[0], TestContext.snippetsCodeForCreate2, false), + tc.selfDestruct(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[0], tc.frameworkEntryPointAddress, false, BigInteger.ONE), + tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, tc.salts[0], TestContext.snippetsCodeForCreate2,false), + tc.selfDestruct(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[0], tc.frameworkEntryPointAddress, false, BigInteger.ONE) + )) + .addBlock(List.of( + tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, tc.salts[1], TestContext.snippetsCodeForCreate2, false), + tc.selfDestruct(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], tc.frameworkEntryPointAddress, false, BigInteger.ONE) + )) + .addBlock(List.of( // test some reverted calls + tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, tc.salts[2], TestContext.snippetsCodeForCreate2, false), + tc.selfDestruct(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[2], tc.frameworkEntryPointAddress, false, BigInteger.ONE), + tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, tc.salts[2], TestContext.snippetsCodeForCreate2, true), + tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, tc.salts[2], TestContext.snippetsCodeForCreate2, false), + tc.selfDestruct(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[2], tc.frameworkEntryPointAddress, true, BigInteger.ONE) + // since the last self-destruct gets reverted, the last call will not increase the deplNo + )) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); + + + Map + minDeplNoMap = stateManagerMetadata.getMinDeplNoBlock(); + Map + maxDeplNoMap = stateManagerMetadata.getMaxDeplNoBlock(); + + // prepare data for asserts + // expected first values for the keys we are testing + int noBlocks = 3; + Integer[][] expectedMin = { + { + 1, + null, + null + }, + { + null, + 1, + null + }, + { + null, + null, + 1 + }, + }; + // expected last values for the keys we are testing + Integer[][] expectedMax = { + { + 4, + null, + null, + }, + { + null, + 2, + null, + }, + { + null, + null, + 4 + }, + + + }; + // prepare the key pairs + Address[] keys = { + tc.newAddresses[0], + tc.newAddresses[1], + tc.newAddresses[2], + }; + + + // blocks are numbered starting from 1 + for (int block = 1; block <= noBlocks; block++) { + for (int i = 0; i < keys.length; i++) { + StateManagerMetadata.AddrBlockPair key = + new StateManagerMetadata.AddrBlockPair( + keys[i], + block); + Integer minNo = minDeplNoMap.get(key); + Integer maxNo = maxDeplNoMap.get(key); + // asserts for the first and last storage values in conflation + // -1 due to block numbering + assertEquals(expectedMin[block-1][i], minNo); + assertEquals(expectedMax[block-1][i], maxNo); + } + } + + System.out.println("Done"); + } +} \ No newline at end of file diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseStorageTest.java index 4e5e5986a2..890345e3f1 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/BlockwiseStorageTest.java @@ -15,15 +15,8 @@ package net.consensys.linea.zktracer.statemanager; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.math.BigInteger; -import java.util.List; -import java.util.Map; - import net.consensys.linea.testing.MultiBlockExecutionEnvironment; import net.consensys.linea.testing.TransactionProcessingResultValidator; -import net.consensys.linea.zktracer.StateManagerTestValidator; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; @@ -31,6 +24,12 @@ import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.junit.jupiter.api.Test; +import java.math.BigInteger; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; + public class BlockwiseStorageTest { TestContext tc; @@ -40,168 +39,99 @@ void testBlockwiseMapStorage() { this.tc = new TestContext(); this.tc.initializeTestContext(); // prepare the transaction validator - TransactionProcessingResultValidator resultValidator = - new StateManagerTestValidator( + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( tc.frameworkEntryPointAccount, // Creates, writes, reads and self-destructs generate 2 logs, // Reverted operations only have 1 log - List.of(2, 2, 2, 2, 2, 2, 2, 2, 2)); + List.of(2, 2, 2, + 2, 2, 2, + 2, 2, 2, 1) + ); // fetch the Hub metadata for the state manager maps StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); // compute the addresses for several accounts that will be deployed later - tc.newAddresses[0] = - tc.getCreate2AddressForSnippet( - "0x0000000000000000000000000000000000000000000000000000000000000002"); - tc.newAddresses[1] = - tc.getCreate2AddressForSnippet( - "0x0000000000000000000000000000000000000000000000000000000000000003"); - tc.newAddresses[2] = - tc.getCreate2AddressForSnippet( - "0x0000000000000000000000000000000000000000000000000000000000000004"); + tc.newAddresses[0] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000002"); + tc.newAddresses[1] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000003"); + tc.newAddresses[2] = tc.getCreate2AddressForSnippet("0x0000000000000000000000000000000000000000000000000000000000000004"); // prepare a multi-block execution of transactions MultiBlockExecutionEnvironment.builder() - // initialize accounts - .accounts( - List.of( - tc.initialAccounts[0], - tc.externallyOwnedAccounts[0], - tc.initialAccounts[2], - tc.frameworkEntryPointAccount)) - // Block 1 - .addBlock( - List.of( - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - 3L, - 1L, - false, - BigInteger.ONE), - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - 3L, - 2L, - false, - BigInteger.ONE), - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - 3L, - 3L, - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - 3L, - 4L, - false, - BigInteger.ONE), - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - 3L, - 5L, - false, - BigInteger.ONE), - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - 3L, - 6L, - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - 3L, - 7L, - false, - BigInteger.ONE), - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - 3L, - 8L, - false, - BigInteger.ONE), - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - 3L, - 9L, - false, - BigInteger.ONE))) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); + // initialize accounts + .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) + // Block 1 + .addBlock(List.of( + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 1L, false, BigInteger.ONE), + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 2L, false, BigInteger.ONE), + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 3L, false, BigInteger.ONE) + )) + .addBlock(List.of( + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 4L, false, BigInteger.ONE), + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 5L, false, BigInteger.ONE), + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 6L, false, BigInteger.ONE) + )) + .addBlock(List.of( + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 7L, false, BigInteger.ONE), + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 8L, false, BigInteger.ONE), + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 9L, false, BigInteger.ONE), + tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 3L, 1234L, true, BigInteger.ONE) + )) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); - Map< - StateManagerMetadata.AddrStorageKeyBlockNumTuple, - TransactionProcessingMetadata.FragmentFirstAndLast> - blockMap = stateManagerMetadata.getStorageFirstLastBlockMap(); + + Map> + blockMap = stateManagerMetadata.getStorageFirstLastBlockMap(); // prepare data for asserts // expected first values for the keys we are testing int noBlocks = 3; EWord[][] expectedFirst = { - { - EWord.of(0L), - }, - { - EWord.of(3L), - }, - { - EWord.of(6L), - }, + { + EWord.of(0L), + }, + { + EWord.of(3L), + }, + { + EWord.of(6L), + }, }; // expected last values for the keys we are testing EWord[][] expectedLast = { - { - EWord.of(3L), - }, - { - EWord.of(6L), - }, - { - EWord.of(9L), - }, + { + EWord.of(3L), + }, + { + EWord.of(6L), + }, + { + EWord.of(9L), + }, + }; // prepare the key pairs TransactionProcessingMetadata.AddrStorageKeyPair[] rawKeys = { - new TransactionProcessingMetadata.AddrStorageKeyPair( - tc.initialAccounts[0].getAddress(), EWord.of(3L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.initialAccounts[0].getAddress(), EWord.of(3L)), }; + // blocks are numbered starting from 1 for (int block = 1; block <= noBlocks; block++) { for (int i = 0; i < rawKeys.length; i++) { StateManagerMetadata.AddrStorageKeyBlockNumTuple key = - new StateManagerMetadata.AddrStorageKeyBlockNumTuple(rawKeys[i], block); - TransactionProcessingMetadata.FragmentFirstAndLast storageData = - blockMap.get(key); + new StateManagerMetadata.AddrStorageKeyBlockNumTuple( + rawKeys[i], + block); + TransactionProcessingMetadata. FragmentFirstAndLast + storageData = blockMap.get(key); // asserts for the first and last storage values in conflation // -1 due to block numbering - assertEquals(expectedFirst[block - 1][i], storageData.getFirst().getValueCurrent()); - assertEquals(expectedLast[block - 1][i], storageData.getLast().getValueNext()); + assertEquals(expectedFirst[block-1][i], storageData.getFirst().getValueCurrent()); + assertEquals(expectedLast[block-1][i], storageData.getLast().getValueNext()); } } System.out.println("Done"); } -} +} \ No newline at end of file diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationAccountTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationAccountTest.java index e0016ad787..c72d9b1c85 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationAccountTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationAccountTest.java @@ -15,15 +15,8 @@ package net.consensys.linea.zktracer.statemanager; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.math.BigInteger; -import java.util.List; -import java.util.Map; - import net.consensys.linea.testing.MultiBlockExecutionEnvironment; import net.consensys.linea.testing.TransactionProcessingResultValidator; -import net.consensys.linea.zktracer.StateManagerTestValidator; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; @@ -32,230 +25,102 @@ import org.hyperledger.besu.datatypes.Wei; import org.junit.jupiter.api.Test; +import java.math.BigInteger; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; + public class ConflationAccountTest { TestContext tc; - @Test void testConflationMapAccount() { // initialize the test context this.tc = new TestContext(); this.tc.initializeTestContext(); // prepare the transaction validator - TransactionProcessingResultValidator resultValidator = - new StateManagerTestValidator( + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( tc.frameworkEntryPointAccount, // Creates and self-destructs generate 2 logs, // Transfers generate 3 logs, the 1s are for reverted operations - List.of(3, 3, 1, 3, 2, 3, 3, 2, 3, 2, 2, 3, 2, 1)); + List.of(3, 3, 1, 3, + 2, 3, 3, + 2, 3, 2, 2, 3, + 2, 1) + ); // fetch the Hub metadata for the state manager maps StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); - // compute the addresses for several accounts that will be deployed later - tc.newAddresses[0] = - tc.getCreate2AddressForSnippet( - "0x0000000000000000000000000000000000000000000000000000000000000002"); - tc.newAddresses[1] = - tc.getCreate2AddressForSnippet( - "0x0000000000000000000000000000000000000000000000000000000000000003"); - tc.newAddresses[2] = - tc.getCreate2AddressForSnippet( - "0x0000000000000000000000000000000000000000000000000000000000000004"); // prepare a multi-block execution of transactions MultiBlockExecutionEnvironment.builder() - // initialize accounts - .accounts( - List.of( - tc.initialAccounts[0], - tc.externallyOwnedAccounts[0], - tc.initialAccounts[2], - tc.frameworkEntryPointAccount)) - // test account operations for an account prexisting in the state - .addBlock( - List.of( - tc.transferTo( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - tc.addresses[2], - 8L, - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.transferTo( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[2], - tc.addresses[0], - 20L, - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.transferTo( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - tc.addresses[2], - 50L, - true, - BigInteger.ONE))) // this action is reverted - .addBlock( - List.of( - tc.transferTo( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - tc.addresses[2], - 10L, - false, - BigInteger.ONE))) - // deploy another account ctxt.addresses[3] and perform account operations on it - .addBlock( - List.of( - tc.deployWithCreate2( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.frameworkEntryPointAddress, - "0x0000000000000000000000000000000000000000000000000000000000000002", - TestContext.snippetsCodeForCreate2))) - .addBlock( - List.of( - tc.transferTo( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - tc.newAddresses[0], - 49L, - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.transferTo( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.newAddresses[0], - tc.addresses[0], - 27L, - false, - BigInteger.ONE))) - // deploy another account and self destruct it at the end, redeploy it and change its - // balance again - .addBlock( - List.of( - tc.deployWithCreate2( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.frameworkEntryPointAddress, - "0x0000000000000000000000000000000000000000000000000000000000000003", - TestContext.snippetsCodeForCreate2))) - .addBlock( - List.of( - tc.transferTo( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - tc.newAddresses[1], - 98L, - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.selfDestruct( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.newAddresses[1], - tc.addresses[2], - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.deployWithCreate2( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.frameworkEntryPointAddress, - "0x0000000000000000000000000000000000000000000000000000000000000003", - TestContext.snippetsCodeForCreate2))) - .addBlock( - List.of( - tc.transferTo( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - tc.newAddresses[1], - 123L, - false, - BigInteger.ONE))) - // deploy a new account and check revert operations on it - .addBlock( - List.of( - tc.deployWithCreate2( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.frameworkEntryPointAddress, - "0x0000000000000000000000000000000000000000000000000000000000000004", - TestContext.snippetsCodeForCreate2))) - .addBlock( - List.of( - tc.transferTo( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[2], - tc.newAddresses[2], - 1L, - true, - BigInteger.ONE))) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); + // initialize accounts + .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) + // test account operations for an account prexisting in the state + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 8L, false, BigInteger.ONE))) + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[2], tc.addresses[0], 20L, false, BigInteger.ONE))) + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 50L, true, BigInteger.ONE))) // this action is reverted + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 10L, false, BigInteger.ONE))) + // deploy another account ctxt.addresses[3] and perform account operations on it + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, tc.salts[0], TestContext.snippetsCodeForCreate2, false))) + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.newAddresses[0], 49L, false, BigInteger.ONE))) + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[0], tc.addresses[0], 27L, false, BigInteger.ONE))) + // deploy another account and self destruct it at the end, redeploy it and change its balance again + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, tc.salts[1], TestContext.snippetsCodeForCreate2, false))) + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.newAddresses[1], 98L, false, BigInteger.ONE))) + .addBlock(List.of(tc.selfDestruct(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], tc.addresses[2], false, BigInteger.ONE))) + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, tc.salts[1], TestContext.snippetsCodeForCreate2, false))) + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.newAddresses[1], 123L, false, BigInteger.ONE))) + // deploy a new account and check revert operations on it + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, tc.salts[2], TestContext.snippetsCodeForCreate2, false))) + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[2], tc.newAddresses[2], 1L, true, BigInteger.ONE))) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); - Map> - conflationMap = stateManagerMetadata.getAccountFirstLastConflationMap(); + Map> + conflationMap = stateManagerMetadata.getAccountFirstLastConflationMap(); // prepare data for asserts // expected first values for the keys we are testing Wei[] expectedFirst = { - TestContext.defaultBalance, TestContext.defaultBalance, Wei.of(0L), Wei.of(0L), Wei.of(0L) + TestContext.defaultBalance, + TestContext.defaultBalance, + Wei.of(0L), + Wei.of(0L), + Wei.of(0L) }; // expected last values for the keys we are testing Wei[] expectedLast = { - TestContext.defaultBalance - .subtract(8L) - .add(20L) - .subtract(10L) - .subtract(49L) - .add(27L) - .subtract(98L) - .subtract(123L), - TestContext.defaultBalance - .add(8L) - .subtract(20L) - .add(10L) - .add(98L), // 98L obtained from the self destruct of the account at ctxt.addresses[4] - Wei.of(0L).add(49L).subtract(27L), - Wei.of(123L), - Wei.of(0L) + TestContext.defaultBalance.subtract(8L).add(20L). + subtract(10L).subtract(49L).add(27L) + .subtract(98L).subtract(123L), + TestContext.defaultBalance.add(8L).subtract(20L).add(10L) + .add(98L), // 98L obtained from the self destruct of the account at ctxt.addresses[4] + Wei.of(0L).add(49L).subtract(27L), + Wei.of(123L), + Wei.of(0L) }; // prepare the key pairs Address[] keys = { - tc.initialAccounts[0].getAddress(), - tc.initialAccounts[2].getAddress(), - tc.newAddresses[0], - tc.newAddresses[1], - tc.newAddresses[2] + tc.initialAccounts[0].getAddress(), + tc.initialAccounts[2].getAddress(), + tc.newAddresses[0], + tc.newAddresses[1], + tc.newAddresses[2] }; for (int i = 0; i < keys.length; i++) { - System.out.println("Index is " + i); - TransactionProcessingMetadata.FragmentFirstAndLast accountData = - conflationMap.get(keys[i]); + System.out.println("Index is "+i); + TransactionProcessingMetadata. FragmentFirstAndLast + accountData = conflationMap.get(keys[i]); // asserts for the first and last storage values in conflation assertEquals(expectedFirst[i], accountData.getFirst().oldState().balance()); assertEquals(expectedLast[i], accountData.getLast().newState().balance()); } + System.out.println("Done"); } -} +} \ No newline at end of file diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java index a1dc14a07e..623963aa2c 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/ConflationStorageTest.java @@ -15,13 +15,7 @@ package net.consensys.linea.zktracer.statemanager; -import static org.junit.jupiter.api.Assertions.*; - -import java.math.BigInteger; -import java.util.*; - import net.consensys.linea.testing.*; -import net.consensys.linea.zktracer.StateManagerTestValidator; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; @@ -31,6 +25,12 @@ import org.hyperledger.besu.datatypes.Address; import org.junit.jupiter.api.Test; +import java.math.BigInteger; +import java.util.*; + +import static org.assertj.core.api.Fail.fail; +import static org.junit.jupiter.api.Assertions.*; + public class ConflationStorageTest { TestContext tc; @@ -40,255 +40,82 @@ void testConflationMapStorage() { this.tc = new TestContext(); this.tc.initializeTestContext(); // prepare the transaction validator - TransactionProcessingResultValidator resultValidator = - new StateManagerTestValidator( + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( tc.frameworkEntryPointAccount, // Creates, writes, reads and self-destructs generate 2 logs, // Reverted operations only have 1 log - List.of(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1)); + List.of(2, 2, 2, 2, 2, + 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, + 2, 2, 1, 1) + ); // fetch the Hub metadata for the state manager maps StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); - // compute the addresses for several accounts that will be deployed later - tc.newAddresses[0] = - tc.getCreate2AddressForSnippet( - "0x0000000000000000000000000000000000000000000000000000000000000002"); - tc.newAddresses[1] = - tc.getCreate2AddressForSnippet( - "0x0000000000000000000000000000000000000000000000000000000000000003"); - tc.newAddresses[2] = - tc.getCreate2AddressForSnippet( - "0x0000000000000000000000000000000000000000000000000000000000000004"); // prepare a multi-block execution of transactions MultiBlockExecutionEnvironment.builder() - // initialize accounts - .accounts( - List.of( - tc.initialAccounts[0], - tc.externallyOwnedAccounts[0], - tc.initialAccounts[2], - tc.frameworkEntryPointAccount)) - // test storage operations for an account prexisting in the state - .addBlock( - List.of( - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - 123L, - 8L, - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.readFromStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - 123L, - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - 123L, - 10L, - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.readFromStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - 123L, - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - 123L, - 15L, - false, - BigInteger.ONE))) - // deploy another account and perform storage operations on it - .addBlock( - List.of( - tc.deployWithCreate2( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.frameworkEntryPointAddress, - "0x0000000000000000000000000000000000000000000000000000000000000002", - TestContext.snippetsCodeForCreate2))) - .addBlock( - List.of( - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.newAddresses[0], - 345L, - 20L, - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.readFromStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.newAddresses[0], - 345L, - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.newAddresses[0], - 345L, - 40L, - false, - BigInteger.ONE))) - // deploy another account and self destruct it at the end, redeploy it and change the - // storage again - // the salt will be the same twice in a row, which will be on purpose - .addBlock( - List.of( - tc.deployWithCreate2( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.frameworkEntryPointAddress, - "0x0000000000000000000000000000000000000000000000000000000000000003", - TestContext.snippetsCodeForCreate2))) - .addBlock( - List.of( - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.newAddresses[1], - 400L, - 12L, - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.readFromStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.newAddresses[1], - 400L, - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.newAddresses[1], - 400L, - 13L, - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.selfDestruct( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.newAddresses[1], - tc.frameworkEntryPointAddress, - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.deployWithCreate2( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.frameworkEntryPointAddress, - "0x0000000000000000000000000000000000000000000000000000000000000003", - TestContext.snippetsCodeForCreate2))) - .addBlock( - List.of( - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.newAddresses[1], - 400L, - 99L, - false, - BigInteger.ONE))) - // deploy a new account and check revert operations on it - .addBlock( - List.of( - tc.deployWithCreate2( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.frameworkEntryPointAddress, - "0x0000000000000000000000000000000000000000000000000000000000000004", - TestContext.snippetsCodeForCreate2))) - .addBlock( - List.of( - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.newAddresses[2], - 500L, - 23L, - false, - BigInteger.ONE))) - .addBlock( - List.of( - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.newAddresses[2], - 500L, - 53L, - true, - BigInteger.ONE))) // revert flag on - .addBlock( - List.of( - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.newAddresses[2], - 500L, - 63L, - true, - BigInteger.ONE))) // revert flag on - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); + // initialize accounts + .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) + // test storage operations for an account prexisting in the state + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, 8L, false, BigInteger.ONE))) + .addBlock(List.of(tc.readFromStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, false, BigInteger.ONE))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, 10L, false, BigInteger.ONE))) + .addBlock(List.of(tc.readFromStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, false, BigInteger.ONE))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, 15L, false, BigInteger.ONE))) + // deploy another account and perform storage operations on it + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, tc.salts[0], TestContext.snippetsCodeForCreate2, false))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[0], 345L, 20L, false, BigInteger.ONE))) + .addBlock(List.of(tc.readFromStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[0], 345L, false, BigInteger.ONE))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[0], 345L, 40L, false, BigInteger.ONE))) + // deploy another account and self destruct it at the end, redeploy it and change the storage again + // the salt will be the same twice in a row, which will be on purpose + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, tc.salts[1], TestContext.snippetsCodeForCreate2, false))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], 400L, 12L, false, BigInteger.ONE))) + .addBlock(List.of(tc.readFromStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], 400L, false, BigInteger.ONE))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], 400L, 13L, false, BigInteger.ONE))) + .addBlock(List.of(tc.selfDestruct(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], tc.frameworkEntryPointAddress, false, BigInteger.ONE))) + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, tc.salts[1], TestContext.snippetsCodeForCreate2, false))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[1], 400L, 99L, false, BigInteger.ONE))) + // deploy a new account and check revert operations on it + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, tc.salts[2], TestContext.snippetsCodeForCreate2, false))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[2], 500L, 23L, false, BigInteger.ONE))) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[2], 500L, 53L, true, BigInteger.ONE))) // revert flag on + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.newAddresses[2], 500L, 63L, true, BigInteger.ONE))) // revert flag on + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); - Map> - conflationMap = stateManagerMetadata.getAccountFirstLastConflationMap(); - Map< - TransactionProcessingMetadata.AddrStorageKeyPair, - TransactionProcessingMetadata.FragmentFirstAndLast> - conflationStorage = stateManagerMetadata.getStorageFirstLastConflationMap(); + Map> + conflationMap = stateManagerMetadata.getAccountFirstLastConflationMap(); + Map> + conflationStorage = stateManagerMetadata.getStorageFirstLastConflationMap(); // prepare data for asserts // expected first values for the keys we are testing - EWord[] expectedFirst = {EWord.of(0L), EWord.of(0), EWord.of(0), EWord.of(0)}; + EWord[] expectedFirst = { + EWord.of(0L), + EWord.of(0), + EWord.of(0), + EWord.of(0) + }; // expected last values for the keys we are testing - EWord[] expectedLast = {EWord.of(15L), EWord.of(40L), EWord.of(99L), EWord.of(23L)}; + EWord[] expectedLast = { + EWord.of(15L), + EWord.of(40L), + EWord.of(99L), + EWord.of(23L) + }; // prepare the key pairs TransactionProcessingMetadata.AddrStorageKeyPair[] keys = { - new TransactionProcessingMetadata.AddrStorageKeyPair( - tc.initialAccounts[0].getAddress(), EWord.of(123L)), - new TransactionProcessingMetadata.AddrStorageKeyPair(tc.newAddresses[0], EWord.of(345L)), - new TransactionProcessingMetadata.AddrStorageKeyPair(tc.newAddresses[1], EWord.of(400L)), - new TransactionProcessingMetadata.AddrStorageKeyPair(tc.newAddresses[2], EWord.of(500L)) + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.initialAccounts[0].getAddress(), EWord.of(123L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.newAddresses[0], EWord.of(345L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.newAddresses[1], EWord.of(400L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.newAddresses[2], EWord.of(500L)) }; for (int i = 0; i < keys.length; i++) { - TransactionProcessingMetadata.FragmentFirstAndLast storageData = - conflationStorage.get(keys[i]); + TransactionProcessingMetadata. FragmentFirstAndLast + storageData = conflationStorage.get(keys[i]); // asserts for the first and last storage values in conflation assertEquals(expectedFirst[i], storageData.getFirst().getValueCurrent()); assertEquals(expectedLast[i], storageData.getLast().getValueNext()); @@ -298,39 +125,39 @@ void testConflationMapStorage() { } /* -TransactionProcessingResultValidator resultValidator = - (Transaction transaction, TransactionProcessingResult result) -> { - // One event from the snippet - // One event from the framework entrypoint about contract call - //assertEquals(result.getLogs().size(), 1); - System.out.println("Number of logs: "+result.getLogs().size()); - var noTopics = result.getLogs().size(); - for (Log log : result.getLogs()) { - String logTopic = log.getTopics().getFirst().toHexString(); - String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); - String writeEventSignature = EventEncoder.encode(FrameworkEntrypoint.WRITE_EVENT); - String readEventSignature = EventEncoder.encode(FrameworkEntrypoint.READ_EVENT); - String destructEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); - if (callEventSignature.equals(logTopic)) { - FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - assertTrue(response.isSuccess); - assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); - continue; - } - if (writeEventSignature.equals(logTopic)) { - // write event - continue; - } - if (readEventSignature.equals(logTopic)) { - // read event - continue; - } - if (destructEventSignature.equals(logTopic)) { - // self destruct - continue; - } - fail(); - } - }; - */ + TransactionProcessingResultValidator resultValidator = + (Transaction transaction, TransactionProcessingResult result) -> { + // One event from the snippet + // One event from the framework entrypoint about contract call + //assertEquals(result.getLogs().size(), 1); + System.out.println("Number of logs: "+result.getLogs().size()); + var noTopics = result.getLogs().size(); + for (Log log : result.getLogs()) { + String logTopic = log.getTopics().getFirst().toHexString(); + String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); + String writeEventSignature = EventEncoder.encode(FrameworkEntrypoint.WRITE_EVENT); + String readEventSignature = EventEncoder.encode(FrameworkEntrypoint.READ_EVENT); + String destructEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); + if (callEventSignature.equals(logTopic)) { + FrameworkEntrypoint.CallExecutedEventResponse response = + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); + assertTrue(response.isSuccess); + assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); + continue; + } + if (writeEventSignature.equals(logTopic)) { + // write event + continue; + } + if (readEventSignature.equals(logTopic)) { + // read event + continue; + } + if (destructEventSignature.equals(logTopic)) { + // self destruct + continue; + } + fail(); + } + }; + */ \ No newline at end of file diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerTestValidator.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/StateManagerTestValidator.java similarity index 55% rename from arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerTestValidator.java rename to arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/StateManagerTestValidator.java index 34a531b094..03f3394f25 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/StateManagerTestValidator.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/StateManagerTestValidator.java @@ -1,10 +1,18 @@ -package net.consensys.linea.zktracer; - -import static org.assertj.core.api.Fail.fail; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.util.List; +/* + * Copyright Consensys Software 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.statemanager; import lombok.NonNull; import lombok.RequiredArgsConstructor; @@ -19,37 +27,45 @@ import org.hyperledger.besu.evm.log.Log; import org.web3j.abi.EventEncoder; +import java.util.List; + +import static org.assertj.core.api.Fail.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + @RequiredArgsConstructor public class StateManagerTestValidator implements TransactionProcessingResultValidator { - @NonNull ToyAccount frameworkEntryPointAccount; - @NonNull List expectedNoLogs; + @NonNull + ToyAccount frameworkEntryPointAccount; + @NonNull + List expectedNoLogs; int txCounter = 0; - @Override public void accept(Transaction transaction, TransactionProcessingResult result) { TransactionProcessingResultValidator.DEFAULT_VALIDATOR.accept(transaction, result); // One event from the snippet // One event from the framework entrypoint about contract call - System.out.println("Number of logs: " + result.getLogs().size()); - assertEquals(result.getLogs().size(), expectedNoLogs.get(txCounter)); - for (Log log : result.getLogs()) { + System.out.println("Number of logs: "+result.getLogs().size()); + assertEquals(expectedNoLogs.get(txCounter), result.getLogs().size()); + for (int i = 0; i < result.getLogs().size(); i++) { + Log currentLog = result.getLogs().get(i); String callEventSignature = EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT); String writeEventSignature = EventEncoder.encode(StateManagerEvents.WRITE_EVENT); String readEventSignature = EventEncoder.encode(StateManagerEvents.READ_EVENT); - String destroyedEventSignature = - EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); + String destroyedEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTDESTROYED_EVENT); String createdEventSignature = EventEncoder.encode(FrameworkEntrypoint.CONTRACTCREATED_EVENT); String sentETHEventSignature = EventEncoder.encode(StateManagerEvents.PAYETH_EVENT); String recETHEventSignature = EventEncoder.encode(StateManagerEvents.RECETH_EVENT); - String logTopic = log.getTopics().getFirst().toHexString(); + String logTopic = currentLog.getTopics().getFirst().toHexString(); if (EventEncoder.encode(TestSnippet_Events.DATANOINDEXES_EVENT).equals(logTopic)) { TestSnippet_Events.DataNoIndexesEventResponse response = - TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(log)); - // assertEquals(response.singleInt, BigInteger.valueOf(123456)); - } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT).equals(logTopic)) { + TestSnippet_Events.getDataNoIndexesEventFromLog(Web3jUtils.fromBesuLog(currentLog)); + //assertEquals(response.singleInt, BigInteger.valueOf(123456)); + } else if (EventEncoder.encode(FrameworkEntrypoint.CALLEXECUTED_EVENT) + .equals(logTopic)) { FrameworkEntrypoint.CallExecutedEventResponse response = - FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(log)); - if (result.getLogs().size() != 1) { + FrameworkEntrypoint.getCallExecutedEventFromLog(Web3jUtils.fromBesuLog(currentLog)); + if (i > 0 && !result.getLogs().get(i-1).getTopics().getFirst().toHexString().equals(callEventSignature)) { // when the number of logs is 1, in our tests we will have an operation // with the revert flag set to true. assertTrue(response.isSuccess); @@ -57,21 +73,14 @@ public void accept(Transaction transaction, TransactionProcessingResult result) if (logTopic.equals(createdEventSignature)) { assertEquals(response.destination, frameworkEntryPointAccount.getAddress().toHexString()); } else { - // assertEquals(response.destination, - // this.testContext.initialAccounts[0].getAddress().toHexString()); + //assertEquals(response.destination, this.testContext.initialAccounts[0].getAddress().toHexString()); } } else { - if (!(logTopic.equals(callEventSignature) - || logTopic.equals(writeEventSignature) - || logTopic.equals(readEventSignature) - || logTopic.equals(destroyedEventSignature) - || logTopic.equals(createdEventSignature) - || logTopic.equals(sentETHEventSignature) - || logTopic.equals(recETHEventSignature))) { + if (!(logTopic.equals(callEventSignature) || logTopic.equals(writeEventSignature) || logTopic.equals(readEventSignature) || logTopic.equals(destroyedEventSignature) || logTopic.equals(createdEventSignature) || logTopic.equals(sentETHEventSignature) || logTopic.equals(recETHEventSignature))) { fail(); } } } txCounter++; } -} +} \ No newline at end of file diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java index b6e5a385cc..3728039b22 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java @@ -1,10 +1,19 @@ +/* + * Copyright Consensys Software 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.statemanager; -import java.math.BigInteger; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - import lombok.Getter; import lombok.NoArgsConstructor; import net.consensys.linea.testing.*; @@ -22,26 +31,33 @@ import org.web3j.abi.datatypes.Function; import org.web3j.abi.datatypes.generated.Uint256; +import java.math.BigInteger; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.assertj.core.api.Fail.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; @NoArgsConstructor public class TestContext { Long txNonce = null; static final Long gasLimit = 5000000L; - static final Wei defaultBalance = Wei.fromEth(3); + static final Wei defaultBalance = Wei.of(4500L); static final int numberOfAccounts = 10; static final int numberOfNewAccounts = 10; static final int numberOfEOA = 1; - static final Bytes snippetsCode = - SmartContractUtils.getYulContractRuntimeByteCode("StateManagerSnippets.yul"); - static final Bytes snippetsCodeForCreate2 = - SmartContractUtils.getYulContractCompiledByteCode("StateManagerSnippets.yul"); - @Getter ToyAccount frameworkEntryPointAccount; + static final Bytes snippetsCode = SmartContractUtils.getYulContractRuntimeByteCode("StateManagerSnippets.yul"); + static final Bytes snippetsCodeForCreate2 = SmartContractUtils.getYulContractCompiledByteCode("StateManagerSnippets.yul"); + @Getter + ToyAccount frameworkEntryPointAccount; Address frameworkEntryPointAddress; ToyAccount[] initialAccounts; ToyAccount[] externallyOwnedAccounts; KeyPair[] keyPairs; Address[] addresses; Address[] newAddresses; - + String[] salts = new String[numberOfNewAccounts]; public void initializeTestContext() { // initialize vectors initialAccounts = new ToyAccount[numberOfAccounts]; @@ -54,17 +70,17 @@ public void initializeTestContext() { KeyPair keyPair = new SECP256K1().generateKeyPair(); Address senderAddress = Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())); externallyOwnedAccounts[i] = - ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); + ToyAccount.builder().balance(Wei.fromEth(1)).nonce(5).address(senderAddress).build(); keyPairs[i] = keyPair; } // initialize the testing framework entry point account frameworkEntryPointAccount = - ToyAccount.builder() - .address(Address.fromHexString("0x123456")) - .balance(defaultBalance) - .nonce(5) - .code(SmartContractUtils.getSolidityContractRuntimeByteCode(FrameworkEntrypoint.class)) - .build(); + ToyAccount.builder() + .address(Address.fromHexString("0x123456")) + .balance(defaultBalance) + .nonce(5) + .code(SmartContractUtils.getSolidityContractRuntimeByteCode(FrameworkEntrypoint.class)) + .build(); frameworkEntryPointAddress = frameworkEntryPointAccount.getAddress(); // add to arrays // initialize the .yul snippets account @@ -72,52 +88,52 @@ public void initializeTestContext() { for (int i = 0; i < numberOfAccounts; i++) { initialAccounts[i] = - ToyAccount.builder() - .address(Address.fromHexString("0x" + i + i + i + i + i)) - .balance(defaultBalance) - .nonce(6) - .code(TestContext.snippetsCode) - .build(); + ToyAccount.builder() + .address(Address.fromHexString("0x" + i + i + i + i + i)) + .balance(defaultBalance) + .nonce(6) + .code(TestContext.snippetsCode) + .build(); addresses[i] = initialAccounts[i].getAddress(); } + + // initialize the new addresses vector + for (int i = 0; i < numberOfAccounts; i++) { + salts[i] = "0x000000000000000000000000000000000000000000000000000000000000000" + i; + newAddresses[i] = getCreate2AddressForSnippet(salts[i]); + } } + // destination must be our .yul smart contract - FrameworkEntrypoint.ContractCall writeToStorageCall( - Address destination, Long key, Long value, boolean revertFlag, BigInteger callType) { - Function yulFunction = - new Function( - "writeToStorage", - Arrays.asList( - new Uint256(BigInteger.valueOf(key)), - new Uint256(BigInteger.valueOf(value)), - new org.web3j.abi.datatypes.Bool(revertFlag)), + FrameworkEntrypoint.ContractCall writeToStorageCall(Address destination, Long key, Long value, boolean revertFlag, BigInteger callType) { + Function yulFunction = new Function("writeToStorage", + Arrays.asList(new Uint256(BigInteger.valueOf(key)), new Uint256(BigInteger.valueOf(value)), new org.web3j.abi.datatypes.Bool(revertFlag)), Collections.emptyList()); var encoding = FunctionEncoder.encode(yulFunction); FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ callType); + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); return snippetContractCall; } // destination must be our .yul smart contract - Transaction wrapWrite( - ToyAccount sender, KeyPair senderKeyPair, FrameworkEntrypoint.ContractCall[] contractCalls) { + Transaction newTxFromCalls(ToyAccount sender, KeyPair senderKeyPair, FrameworkEntrypoint.ContractCall[] contractCalls) { Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + - ToyTransaction.ToyTransactionBuilder tempTx = - ToyTransaction.builder() + ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() .sender(sender) .to(this.frameworkEntryPointAccount) .payload(txPayload) @@ -134,44 +150,34 @@ Transaction wrapWrite( return tx; } + + // destination must be our .yul smart contract - Transaction writeToStorage( - ToyAccount sender, - KeyPair senderKeyPair, - Address destination, - Long key, - Long value, - boolean revertFlag, - BigInteger callType) { - Function yulFunction = - new Function( - "writeToStorage", - Arrays.asList( - new Uint256(BigInteger.valueOf(key)), - new Uint256(BigInteger.valueOf(value)), - new org.web3j.abi.datatypes.Bool(revertFlag)), + Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, Address destination, Long key, Long value, boolean revertFlag, BigInteger callType) { + Function yulFunction = new Function("writeToStorage", + Arrays.asList(new Uint256(BigInteger.valueOf(key)), new Uint256(BigInteger.valueOf(value)), new org.web3j.abi.datatypes.Bool(revertFlag)), Collections.emptyList()); var encoding = FunctionEncoder.encode(yulFunction); FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ callType); + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); List contractCalls = List.of(snippetContractCall); Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + - ToyTransaction.ToyTransactionBuilder tempTx = - ToyTransaction.builder() + ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() .sender(sender) .to(this.frameworkEntryPointAccount) .payload(txPayload) @@ -188,41 +194,33 @@ Transaction writeToStorage( return tx; } + // destination must be our .yul smart contract - Transaction readFromStorage( - ToyAccount sender, - KeyPair senderKeyPair, - Address destination, - Long key, - boolean revertFlag, - BigInteger callType) { - Function yulFunction = - new Function( - "readFromStorage", - Arrays.asList( - new Uint256(BigInteger.valueOf(key)), new org.web3j.abi.datatypes.Bool(revertFlag)), + Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, Address destination, Long key, boolean revertFlag, BigInteger callType) { + Function yulFunction = new Function("readFromStorage", + Arrays.asList(new Uint256(BigInteger.valueOf(key)), new org.web3j.abi.datatypes.Bool(revertFlag)), Collections.emptyList()); + var encoding = FunctionEncoder.encode(yulFunction); FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ callType); + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); List contractCalls = List.of(snippetContractCall); Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - ToyTransaction.ToyTransactionBuilder tempTx = - ToyTransaction.builder() + ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() .sender(sender) .to(this.frameworkEntryPointAccount) .payload(txPayload) @@ -240,42 +238,32 @@ Transaction readFromStorage( } // destination must be our .yul smart contract - Transaction selfDestruct( - ToyAccount sender, - KeyPair senderKeyPair, - Address destination, - Address recipient, - boolean revertFlag, - BigInteger callType) { + Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, Address destination, Address recipient, boolean revertFlag, BigInteger callType) { String recipientAddressString = recipient.toHexString(); - Function yulFunction = - new Function( - "selfDestruct", - Arrays.asList( - new org.web3j.abi.datatypes.Address(recipientAddressString), - new org.web3j.abi.datatypes.Bool(revertFlag)), + Function yulFunction = new Function("selfDestruct", + Arrays.asList(new org.web3j.abi.datatypes.Address(recipientAddressString), new org.web3j.abi.datatypes.Bool(revertFlag)), Collections.emptyList()); + var encoding = FunctionEncoder.encode(yulFunction); FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ callType); // Normal call, not a delegate call as would be the default + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); // Normal call, not a delegate call as would be the default List contractCalls = List.of(snippetContractCall); Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - ToyTransaction.ToyTransactionBuilder tempTx = - ToyTransaction.builder() + ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() .sender(sender) .to(this.frameworkEntryPointAccount) .payload(txPayload) @@ -293,44 +281,52 @@ Transaction selfDestruct( } // destination must be our .yul smart contract - Transaction transferTo( - ToyAccount sender, - KeyPair senderKeyPair, - Address destination, - Address recipient, - long amount, - boolean revertFlag, - BigInteger callType) { + FrameworkEntrypoint.ContractCall selfDestructCall(Address destination, Address recipient, boolean revertFlag, BigInteger callType) { + String recipientAddressString = recipient.toHexString(); + Function yulFunction = new Function("selfDestruct", + Arrays.asList(new org.web3j.abi.datatypes.Address(recipientAddressString), new org.web3j.abi.datatypes.Bool(revertFlag)), + Collections.emptyList()); + + + var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); // Normal call, not a delegate call as would be the default + + return snippetContractCall; + } + + // destination must be our .yul smart contract + Transaction transferTo(ToyAccount sender, KeyPair senderKeyPair, Address destination, Address recipient, long amount, boolean revertFlag, BigInteger callType) { String recipientAddressString = recipient.toHexString(); - Function yulFunction = - new Function( - "transferTo", - Arrays.asList( - new org.web3j.abi.datatypes.Address(recipientAddressString), - new Uint256(amount), - new org.web3j.abi.datatypes.Bool(revertFlag)), + Function yulFunction = new Function("transferTo", + Arrays.asList(new org.web3j.abi.datatypes.Address(recipientAddressString), new Uint256(amount), new org.web3j.abi.datatypes.Bool(revertFlag)), Collections.emptyList()); + var encoding = FunctionEncoder.encode(yulFunction); FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ callType); // Normal call, not a delegate call as would be the default + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); // Normal call, not a delegate call as would be the default List contractCalls = List.of(snippetContractCall); Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - ToyTransaction.ToyTransactionBuilder tempTx = - ToyTransaction.builder() + ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() .sender(sender) .to(this.frameworkEntryPointAccount) .payload(txPayload) @@ -347,48 +343,63 @@ Transaction transferTo( return tx; } + FrameworkEntrypoint.ContractCall transferToCall(Address destination, Address recipient, long amount, boolean revertFlag, BigInteger callType) { + String recipientAddressString = recipient.toHexString(); + Function yulFunction = new Function("transferTo", + Arrays.asList(new org.web3j.abi.datatypes.Address(recipientAddressString), new Uint256(amount), new org.web3j.abi.datatypes.Bool(revertFlag)), + Collections.emptyList()); + + + var encoding = FunctionEncoder.encode(yulFunction); + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ callType); // Normal call, not a delegate call as would be the default + return snippetContractCall; + } + + + + // destination must be our .yul smart contract - Transaction deployWithCreate2( - ToyAccount sender, - KeyPair senderKeyPair, - Address destination, - String saltString, - Bytes contractBytes) { + Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, Address destination, String saltString, Bytes contractBytes, boolean revertFlag) { Bytes salt = Bytes.fromHexStringLenient(saltString); // the following is the bytecode of the .yul contract - // Bytes yulContractBytes = - // Bytes.fromHexStringLenient("61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); + // Bytes yulContractBytes = Bytes.fromHexStringLenient("61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); // prepare the Create2 function Function create2Function = - new Function( - FrameworkEntrypoint.FUNC_DEPLOYWITHCREATE2, - Arrays.asList( - new org.web3j.abi.datatypes.generated.Bytes32(salt.toArray()), - new org.web3j.abi.datatypes.DynamicBytes(contractBytes.toArray())), - Collections.emptyList()); + new Function( + FrameworkEntrypoint.FUNC_DEPLOYWITHCREATE2, + Arrays.asList(new org.web3j.abi.datatypes.generated.Bytes32(salt.toArray()), + new org.web3j.abi.datatypes.DynamicBytes(contractBytes.toArray()), + new org.web3j.abi.datatypes.Bool(revertFlag)), + Collections.emptyList()); String encoding = FunctionEncoder.encode(create2Function); FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ BigInteger.ONE); // Normal call, not a delegate call as it is the default + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ONE); // Normal call, not a delegate call as it is the default + List contractCalls = List.of(snippetContractCall); Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); + new Function( + FrameworkEntrypoint.FUNC_EXECUTECALLS, + List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), + Collections.emptyList()); Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - ToyTransaction.ToyTransactionBuilder tempTx = - ToyTransaction.builder() + ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() .sender(sender) .to(this.frameworkEntryPointAccount) .payload(txPayload) @@ -405,14 +416,36 @@ Transaction deployWithCreate2( return tx; } + FrameworkEntrypoint.ContractCall deployWithCreate2Call(Address destination, String saltString, Bytes contractBytes) { + Bytes salt = Bytes.fromHexStringLenient(saltString); + // the following is the bytecode of the .yul contract + // Bytes yulContractBytes = Bytes.fromHexStringLenient("61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); + // prepare the Create2 function + Function create2Function = + new Function( + FrameworkEntrypoint.FUNC_DEPLOYWITHCREATE2, + Arrays.asList(new org.web3j.abi.datatypes.generated.Bytes32(salt.toArray()), + new org.web3j.abi.datatypes.DynamicBytes(contractBytes.toArray())), + Collections.emptyList()); + + String encoding = FunctionEncoder.encode(create2Function); + + FrameworkEntrypoint.ContractCall snippetContractCall = + new FrameworkEntrypoint.ContractCall( + /*Address*/ destination.toHexString(), + /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), + /*gasLimit*/ BigInteger.ZERO, + /*value*/ BigInteger.ZERO, + /*callType*/ BigInteger.ONE); // Normal call, not a delegate call as it is the default + + return snippetContractCall; + } + public Address getCreate2AddressForSnippet(String salt) { - org.apache.tuweni.bytes.Bytes32 initCodeHash = - org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(TestContext.snippetsCodeForCreate2)); - org.apache.tuweni.bytes.Bytes32 targetAddress = - AddressUtils.getCreate2RawAddress( - frameworkEntryPointAccount.getAddress(), + org.apache.tuweni.bytes.Bytes32 initCodeHash = org.hyperledger.besu.crypto.Hash.keccak256(Bytes.wrap(TestContext.snippetsCodeForCreate2)); + org.apache.tuweni.bytes.Bytes32 targetAddress = AddressUtils.getCreate2RawAddress(frameworkEntryPointAccount.getAddress(), org.apache.tuweni.bytes.Bytes32.wrap(Bytes.fromHexStringLenient(salt).toArray()), initCodeHash); return Address.extract(targetAddress); } -} +} \ No newline at end of file diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionAccountTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionAccountTest.java new file mode 100644 index 0000000000..014450b951 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionAccountTest.java @@ -0,0 +1,142 @@ +/* + * Copyright Consensys Software 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.statemanager; + +import net.consensys.linea.testing.MultiBlockExecutionEnvironment; +import net.consensys.linea.testing.TransactionProcessingResultValidator; +import net.consensys.linea.testing.generated.FrameworkEntrypoint; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; +import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; +import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; +import net.consensys.linea.zktracer.types.EWord; +import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; +import org.hyperledger.besu.datatypes.Address; +import org.hyperledger.besu.datatypes.Wei; +import org.junit.jupiter.api.Test; + +import java.math.BigInteger; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class TransactionAccountTest { + TestContext tc; + + @Test + void testTransactionMapAccount() { + // initialize the test context + this.tc = new TestContext(); + this.tc.initializeTestContext(); + // prepare the transaction validator + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + tc.frameworkEntryPointAccount, + // Creates, writes, reads and self-destructs generate 2 logs, + // transfers generate 3 logs + // Reverted operations only have 1 log + List.of(10, 10) + ); + // fetch the Hub metadata for the state manager maps + StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); + + // prepare a multi-block execution of transactions + MultiBlockExecutionEnvironment.builder() + // initialize accounts + .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) + // Block 1 + .addBlock(List.of( + tc.newTxFromCalls(tc.externallyOwnedAccounts[0], tc.keyPairs[0], new FrameworkEntrypoint.ContractCall[] + { + tc.transferToCall(tc.addresses[0], tc.addresses[2], 8L, false, BigInteger.ONE), + tc.transferToCall(tc.addresses[2], tc.addresses[0], 9L, false, BigInteger.ONE), + tc.transferToCall(tc.addresses[0], tc.addresses[2], 15L, false, BigInteger.ONE), + tc.transferToCall(tc.addresses[2], tc.addresses[0], 1234L, true, BigInteger.ONE), // revert this one + }), + tc.newTxFromCalls(tc.externallyOwnedAccounts[0], tc.keyPairs[0], new FrameworkEntrypoint.ContractCall[] + { + tc.transferToCall(tc.addresses[0], tc.addresses[2], 200L, false, BigInteger.ONE), + tc.transferToCall(tc.addresses[2], tc.addresses[0], 500L, false, BigInteger.ONE), + tc.transferToCall(tc.addresses[2], tc.addresses[0], 1234L, true, BigInteger.ONE), // revert this one + tc.transferToCall(tc.addresses[0], tc.addresses[2], 900L, false, BigInteger.ONE), + }) + + )) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); + + + List txn = Hub.stateManagerMetadata().getHub().txStack().getTransactions();; + + + + // prepare data for asserts + // expected first values for the keys we are testing + Wei[][] expectedFirst = { + { + TestContext.defaultBalance, + TestContext.defaultBalance, + }, + { + TestContext.defaultBalance.subtract(8L).add(9L). + subtract(15L), + TestContext.defaultBalance.add(8L).subtract(9L). + add(15L), + } + }; + + // expected last values for the keys we are testing + Wei[][] expectedLast = { + { + TestContext.defaultBalance.subtract(8L).add(9L). + subtract(15L), + TestContext.defaultBalance.add(8L).subtract(9L). + add(15L), + }, + { + TestContext.defaultBalance.subtract(8L).add(9L). + subtract(15L).subtract(200L).add(500L). + subtract(900L), + TestContext.defaultBalance.add(8L).subtract(9L). + add(15L).add(200L).subtract(500L). + add(900L), + } + }; + + // prepare the key pairs + Address[] keys = { + tc.initialAccounts[0].getAddress(), + tc.initialAccounts[2].getAddress(), + }; + + // blocks are numbered starting from 1 + for (int txCounter = 1; txCounter <= txn.size(); txCounter++) { + Map> + accountMap = txn.get(txCounter-1).getAccountFirstAndLastMap(); + for (int i = 0; i < keys.length; i++) { + TransactionProcessingMetadata. FragmentFirstAndLast + accountData = accountMap.get(keys[i]); + // asserts for the first and last storage values in conflation + // -1 due to block numbering + assertEquals(expectedFirst[txCounter-1][i], accountData.getFirst().oldState().balance()); + assertEquals(expectedLast[txCounter-1][i], accountData.getLast().newState().balance()); + } + } + + System.out.println("Done"); + } +} \ No newline at end of file diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java index e31b728e5f..384ecac1d0 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TransactionStorageTest.java @@ -15,23 +15,23 @@ package net.consensys.linea.zktracer.statemanager; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.math.BigInteger; -import java.util.List; -import java.util.Map; - import net.consensys.linea.testing.MultiBlockExecutionEnvironment; import net.consensys.linea.testing.TransactionProcessingResultValidator; import net.consensys.linea.testing.generated.FrameworkEntrypoint; -import net.consensys.linea.zktracer.StateManagerTestValidator; import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.module.hub.fragment.account.AccountFragment; import net.consensys.linea.zktracer.module.hub.fragment.storage.StorageFragment; import net.consensys.linea.zktracer.module.hub.transients.StateManagerMetadata; import net.consensys.linea.zktracer.types.EWord; import net.consensys.linea.zktracer.types.TransactionProcessingMetadata; import org.junit.jupiter.api.Test; +import java.math.BigInteger; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; + public class TransactionStorageTest { TestContext tc; @@ -41,93 +41,86 @@ void testTransactionMapStorage() { this.tc = new TestContext(); this.tc.initializeTestContext(); // prepare the transaction validator - TransactionProcessingResultValidator resultValidator = - new StateManagerTestValidator( + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( tc.frameworkEntryPointAccount, // Creates, writes, reads and self-destructs generate 2 logs, // Reverted operations only have 1 log - List.of(6, 6)); + List.of(7, 7) + ); // fetch the Hub metadata for the state manager maps StateManagerMetadata stateManagerMetadata = Hub.stateManagerMetadata(); // prepare a multi-block execution of transactions MultiBlockExecutionEnvironment.builder() - // initialize accounts - .accounts( - List.of( - tc.initialAccounts[0], - tc.externallyOwnedAccounts[0], - tc.initialAccounts[2], - tc.frameworkEntryPointAccount)) - // Block 1 - .addBlock( - List.of( - tc.wrapWrite( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - new FrameworkEntrypoint.ContractCall[] { - tc.writeToStorageCall(tc.addresses[0], 3L, 1L, false, BigInteger.ONE), - tc.writeToStorageCall(tc.addresses[0], 3L, 2L, false, BigInteger.ONE), - tc.writeToStorageCall(tc.addresses[0], 3L, 3L, false, BigInteger.ONE), - }), - tc.wrapWrite( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - new FrameworkEntrypoint.ContractCall[] { - tc.writeToStorageCall(tc.addresses[0], 3L, 4L, false, BigInteger.ONE), - tc.writeToStorageCall(tc.addresses[0], 3L, 5L, false, BigInteger.ONE), - tc.writeToStorageCall(tc.addresses[0], 3L, 6L, false, BigInteger.ONE), - }))) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); - - List txn = - Hub.stateManagerMetadata().getHub().txStack().getTransactions(); - ; + // initialize accounts + .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) + // Block 1 + .addBlock(List.of( + tc.newTxFromCalls(tc.externallyOwnedAccounts[0], tc.keyPairs[0], new FrameworkEntrypoint.ContractCall[] + { + tc.writeToStorageCall(tc.addresses[0], 3L, 1L, false, BigInteger.ONE), + tc.writeToStorageCall(tc.addresses[0], 3L, 2L, false, BigInteger.ONE), + tc.writeToStorageCall(tc.addresses[0], 3L, 3L, false, BigInteger.ONE), + tc.writeToStorageCall(tc.addresses[0], 3L, 1234L, true, BigInteger.ONE), + }), + tc.newTxFromCalls(tc.externallyOwnedAccounts[0], tc.keyPairs[0], new FrameworkEntrypoint.ContractCall[] + { + tc.writeToStorageCall(tc.addresses[0], 3L, 1234L, true, BigInteger.ONE), + tc.writeToStorageCall(tc.addresses[0], 3L, 4L, false, BigInteger.ONE), + tc.writeToStorageCall(tc.addresses[0], 3L, 5L, false, BigInteger.ONE), + tc.writeToStorageCall(tc.addresses[0], 3L, 6L, false, BigInteger.ONE), + }) + + )) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); + + + List txn = Hub.stateManagerMetadata().getHub().txStack().getTransactions();; + + // prepare data for asserts // expected first values for the keys we are testing int noBlocks = 3; EWord[][] expectedFirst = { - { - EWord.of(0L), - }, - { - EWord.of(3L), - }, + { + EWord.of(0L), + }, + { + EWord.of(3L), + }, }; // expected last values for the keys we are testing EWord[][] expectedLast = { - { - EWord.of(3L), - }, - { - EWord.of(6L), - }, + { + EWord.of(3L), + }, + { + EWord.of(6L), + }, }; // prepare the key pairs TransactionProcessingMetadata.AddrStorageKeyPair[] keys = { - new TransactionProcessingMetadata.AddrStorageKeyPair( - tc.initialAccounts[0].getAddress(), EWord.of(3L)), + new TransactionProcessingMetadata.AddrStorageKeyPair(tc.initialAccounts[0].getAddress(), EWord.of(3L)), }; + // blocks are numbered starting from 1 for (int txCounter = 1; txCounter <= txn.size(); txCounter++) { - Map< - TransactionProcessingMetadata.AddrStorageKeyPair, - TransactionProcessingMetadata.FragmentFirstAndLast> - storageMap = txn.get(txCounter - 1).getStorageFirstAndLastMap(); + Map> + storageMap = txn.get(txCounter-1).getStorageFirstAndLastMap(); for (int i = 0; i < keys.length; i++) { - TransactionProcessingMetadata.FragmentFirstAndLast storageData = - storageMap.get(keys[i]); + TransactionProcessingMetadata. FragmentFirstAndLast + storageData = storageMap.get(keys[i]); // asserts for the first and last storage values in conflation // -1 due to block numbering - assertEquals(expectedFirst[txCounter - 1][i], storageData.getFirst().getValueCurrent()); - assertEquals(expectedLast[txCounter - 1][i], storageData.getLast().getValueNext()); + assertEquals(expectedFirst[txCounter-1][i], storageData.getFirst().getValueCurrent()); + assertEquals(expectedLast[txCounter-1][i], storageData.getLast().getValueNext()); } } System.out.println("Done"); } -} +} \ No newline at end of file diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/UtilitiesTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/UtilitiesTest.java index a1c912ff83..483cf05ecd 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/UtilitiesTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/UtilitiesTest.java @@ -15,14 +15,15 @@ package net.consensys.linea.zktracer.statemanager; -import java.math.BigInteger; -import java.util.List; - import net.consensys.linea.testing.MultiBlockExecutionEnvironment; import net.consensys.linea.testing.TransactionProcessingResultValidator; -import net.consensys.linea.zktracer.StateManagerTestValidator; import org.junit.jupiter.api.Test; +import java.math.BigInteger; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + public class UtilitiesTest { TestContext tc; @@ -31,102 +32,50 @@ void testBuildingBlockOperations() { // initialize the test context this.tc = new TestContext(); this.tc.initializeTestContext(); - TransactionProcessingResultValidator resultValidator = - new StateManagerTestValidator( + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( tc.frameworkEntryPointAccount, // Creates and self-destructs generate 2 logs, // Transfers generate 3 logs, the 1s are for reverted operations - List.of(2, 2, 3, 2, 2)); + List.of(2, 2, 3, 2, 2) + ); MultiBlockExecutionEnvironment.builder() - .accounts( - List.of( - tc.initialAccounts[0], - tc.externallyOwnedAccounts[0], - tc.initialAccounts[2], - tc.frameworkEntryPointAccount)) - .addBlock( - List.of( - tc.writeToStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - 123L, - 1L, - false, - BigInteger.ZERO))) - .addBlock( - List.of( - tc.readFromStorage( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - 123L, - false, - BigInteger.ZERO))) - .addBlock( - List.of( - tc.transferTo( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - tc.addresses[2], - 8L, - false, - BigInteger.ONE))) - // test operations above, before self-destructing a snippet in the next line - .addBlock( - List.of( - tc.selfDestruct( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.addresses[0], - tc.frameworkEntryPointAddress, - false, - BigInteger - .ONE))) // use BigInteger.ONE, otherwise the framework entry point gets - // destroyed - .addBlock( - List.of( - tc.deployWithCreate2( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.frameworkEntryPointAddress, - "0x0000000000000000000000000000000000000000000000000000000000000002", - TestContext.snippetsCodeForCreate2))) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); + .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.initialAccounts[2], tc.frameworkEntryPointAccount)) + .addBlock(List.of(tc.writeToStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, 1L, false, BigInteger.ZERO))) + .addBlock(List.of(tc.readFromStorage(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], 123L, false, BigInteger.ZERO))) + .addBlock(List.of(tc.transferTo(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.addresses[2], 8L, false, BigInteger.ONE))) + // test operations above, before self-destructing a snippet in the next line + .addBlock(List.of(tc.selfDestruct(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.addresses[0], tc.frameworkEntryPointAddress, false, BigInteger.ONE))) // use BigInteger.ONE, otherwise the framework entry point gets destroyed + .addBlock(List.of(tc.deployWithCreate2(tc.externallyOwnedAccounts[0], tc.keyPairs[0], tc.frameworkEntryPointAddress, "0x0000000000000000000000000000000000000000000000000000000000000002", TestContext.snippetsCodeForCreate2, false))) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); System.out.println("Done"); } // Create 2 has a weird behavior and does not seem to work with the - // bytecode output by the function - // SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul") + // bytecode output by the function SmartContractUtils.getYulContractByteCode("StateManagerSnippets.yul") @Test void testCreate2Snippets() { - // initialize the test context +// initialize the test context this.tc = new TestContext(); this.tc.initializeTestContext(); - TransactionProcessingResultValidator resultValidator = - new StateManagerTestValidator(tc.frameworkEntryPointAccount, List.of(2)); + TransactionProcessingResultValidator resultValidator = new StateManagerTestValidator( + tc.frameworkEntryPointAccount, + List.of(2) + ); MultiBlockExecutionEnvironment.builder() - .accounts( - List.of( - tc.initialAccounts[0], - tc.externallyOwnedAccounts[0], - tc.frameworkEntryPointAccount)) - .addBlock( - List.of( - tc.deployWithCreate2( - tc.externallyOwnedAccounts[0], - tc.keyPairs[0], - tc.frameworkEntryPointAddress, - "0x0000000000000000000000000000000000000000000000000000000000004312", - TestContext.snippetsCodeForCreate2))) - .transactionProcessingResultValidator(resultValidator) - .build() - .run(); + .accounts(List.of(tc.initialAccounts[0], tc.externallyOwnedAccounts[0], tc.frameworkEntryPointAccount)) + .addBlock(List.of( + tc.deployWithCreate2(tc.externallyOwnedAccounts[0], + tc.keyPairs[0], + tc.frameworkEntryPointAddress, + "0x0000000000000000000000000000000000000000000000000000000000004312", + TestContext.snippetsCodeForCreate2, + false))) + .transactionProcessingResultValidator(resultValidator) + .build() + .run(); System.out.println("Done"); } -} +} \ No newline at end of file diff --git a/testing/src/main/solidity/TestingBase.sol b/testing/src/main/solidity/TestingBase.sol index e5d4ee0c90..8b460d05f2 100644 --- a/testing/src/main/solidity/TestingBase.sol +++ b/testing/src/main/solidity/TestingBase.sol @@ -271,7 +271,8 @@ abstract contract TestingBase { */ function deployWithCreate2( bytes32 _salt, - bytes memory _bytecode + bytes memory _bytecode, + bool _revertFlag ) public payable returns (address addr) { assembly { let value := callvalue() @@ -287,6 +288,9 @@ abstract contract TestingBase { } emit ContractCreated(addr); + if (_revertFlag) { + revert(); + } } /** @@ -327,4 +331,4 @@ abstract contract TestingBase { emit ContractDestroyed(address(this)); selfdestruct(_fundAddress); } -} +} \ No newline at end of file From 0760c5d01ceda65344710f3ab3e80b922958d17d Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Tue, 26 Nov 2024 01:27:06 +0100 Subject: [PATCH 73/74] small bug in storage tracing --- .../zktracer/module/hub/fragment/storage/StorageFragment.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java index 7b4441cefd..ae0a66ede4 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/storage/StorageFragment.java @@ -138,7 +138,6 @@ public Trace trace(Trace trace) { .pStorageAgainInCnf(this != storageFirstLastConflationPair.getFirst()) .pStorageFinalInCnf(this == storageFirstLastConflationPair.getLast()) .pStorageDeploymentNumberFirstInBlock(minDeploymentNumberInBlock) - .pStorageDeploymentNumberFinalInBlock(maxDeploymentNumberInBlock) - .pStorageValueNextIsOrig(valueNext.equals(valueOriginal)); + .pStorageDeploymentNumberFinalInBlock(maxDeploymentNumberInBlock); } } From aa31579eb206ab6b2c1d1d1e4ac7439132e583e3 Mon Sep 17 00:00:00 2001 From: Bogdan Ursu Date: Tue, 3 Dec 2024 11:34:17 +0100 Subject: [PATCH 74/74] refactor --- .../zktracer/statemanager/TestContext.java | 219 ++---------------- 1 file changed, 23 insertions(+), 196 deletions(-) diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java index 3728039b22..7c47bf0868 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/statemanager/TestContext.java @@ -104,24 +104,6 @@ public void initializeTestContext() { } } - - // destination must be our .yul smart contract - FrameworkEntrypoint.ContractCall writeToStorageCall(Address destination, Long key, Long value, boolean revertFlag, BigInteger callType) { - Function yulFunction = new Function("writeToStorage", - Arrays.asList(new Uint256(BigInteger.valueOf(key)), new Uint256(BigInteger.valueOf(value)), new org.web3j.abi.datatypes.Bool(revertFlag)), - Collections.emptyList()); - - var encoding = FunctionEncoder.encode(yulFunction); - FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ callType); - return snippetContractCall; - } - // destination must be our .yul smart contract Transaction newTxFromCalls(ToyAccount sender, KeyPair senderKeyPair, FrameworkEntrypoint.ContractCall[] contractCalls) { Function frameworkEntryPointFunction = @@ -151,9 +133,8 @@ Transaction newTxFromCalls(ToyAccount sender, KeyPair senderKeyPair, FrameworkEn } - // destination must be our .yul smart contract - Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, Address destination, Long key, Long value, boolean revertFlag, BigInteger callType) { + FrameworkEntrypoint.ContractCall writeToStorageCall(Address destination, Long key, Long value, boolean revertFlag, BigInteger callType) { Function yulFunction = new Function("writeToStorage", Arrays.asList(new Uint256(BigInteger.valueOf(key)), new Uint256(BigInteger.valueOf(value)), new org.web3j.abi.datatypes.Bool(revertFlag)), Collections.emptyList()); @@ -166,37 +147,18 @@ Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, Address des /*gasLimit*/ BigInteger.ZERO, /*value*/ BigInteger.ZERO, /*callType*/ callType); + return snippetContractCall; + } - List contractCalls = List.of(snippetContractCall); - Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); - Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - - - ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() - .sender(sender) - .to(this.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit); - if (this.txNonce != null) { - tempTx = tempTx.nonce(++this.txNonce); - } - Transaction tx = tempTx.build(); - if (this.txNonce == null) { - this.txNonce = tx.getNonce(); - } - return tx; + // destination must be our .yul smart contract + Transaction writeToStorage(ToyAccount sender, KeyPair senderKeyPair, Address destination, Long key, Long value, boolean revertFlag, BigInteger callType) { + FrameworkEntrypoint.ContractCall snippetContractCall = writeToStorageCall(destination, key, value, revertFlag, callType); + return newTxFromCalls(sender, senderKeyPair, new FrameworkEntrypoint.ContractCall[]{snippetContractCall}); } - // destination must be our .yul smart contract - Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, Address destination, Long key, boolean revertFlag, BigInteger callType) { + FrameworkEntrypoint.ContractCall readFromStorageCall(ToyAccount sender, KeyPair senderKeyPair, Address destination, Long key, boolean revertFlag, BigInteger callType) { Function yulFunction = new Function("readFromStorage", Arrays.asList(new Uint256(BigInteger.valueOf(key)), new org.web3j.abi.datatypes.Bool(revertFlag)), Collections.emptyList()); @@ -211,73 +173,20 @@ Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, Address de /*value*/ BigInteger.ZERO, /*callType*/ callType); - List contractCalls = List.of(snippetContractCall); - Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); - Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); + return snippetContractCall; + } - ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() - .sender(sender) - .to(this.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit); - if (this.txNonce != null) { - tempTx = tempTx.nonce(++this.txNonce); - } - Transaction tx = tempTx.build(); - if (this.txNonce == null) { - this.txNonce = tx.getNonce(); - } - return tx; + // destination must be our .yul smart contract + Transaction readFromStorage(ToyAccount sender, KeyPair senderKeyPair, Address destination, Long key, boolean revertFlag, BigInteger callType) { + FrameworkEntrypoint.ContractCall snippetContractCall = readFromStorageCall(sender, senderKeyPair, destination, key, revertFlag, callType); + return newTxFromCalls(sender, senderKeyPair, new FrameworkEntrypoint.ContractCall[]{snippetContractCall}); } // destination must be our .yul smart contract Transaction selfDestruct(ToyAccount sender, KeyPair senderKeyPair, Address destination, Address recipient, boolean revertFlag, BigInteger callType) { - String recipientAddressString = recipient.toHexString(); - Function yulFunction = new Function("selfDestruct", - Arrays.asList(new org.web3j.abi.datatypes.Address(recipientAddressString), new org.web3j.abi.datatypes.Bool(revertFlag)), - Collections.emptyList()); - - - var encoding = FunctionEncoder.encode(yulFunction); - FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ callType); // Normal call, not a delegate call as would be the default - - List contractCalls = List.of(snippetContractCall); - Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); - Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - - ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() - .sender(sender) - .to(this.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit); - - if (this.txNonce != null) { - tempTx = tempTx.nonce(++this.txNonce); - } - Transaction tx = tempTx.build(); - if (this.txNonce == null) { - this.txNonce = tx.getNonce(); - } - return tx; + FrameworkEntrypoint.ContractCall snippetContractCall = selfDestructCall(destination, recipient, revertFlag, callType); + return newTxFromCalls(sender, senderKeyPair, new FrameworkEntrypoint.ContractCall[]{snippetContractCall}); } // destination must be our .yul smart contract @@ -302,45 +211,8 @@ FrameworkEntrypoint.ContractCall selfDestructCall(Address destination, Address r // destination must be our .yul smart contract Transaction transferTo(ToyAccount sender, KeyPair senderKeyPair, Address destination, Address recipient, long amount, boolean revertFlag, BigInteger callType) { - String recipientAddressString = recipient.toHexString(); - Function yulFunction = new Function("transferTo", - Arrays.asList(new org.web3j.abi.datatypes.Address(recipientAddressString), new Uint256(amount), new org.web3j.abi.datatypes.Bool(revertFlag)), - Collections.emptyList()); - - - var encoding = FunctionEncoder.encode(yulFunction); - FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ callType); // Normal call, not a delegate call as would be the default - - List contractCalls = List.of(snippetContractCall); - Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); - Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - - ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() - .sender(sender) - .to(this.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit); - - if (this.txNonce != null) { - tempTx = tempTx.nonce(++this.txNonce); - } - Transaction tx = tempTx.build(); - if (this.txNonce == null) { - this.txNonce = tx.getNonce(); - } - return tx; + FrameworkEntrypoint.ContractCall snippetContractCall = transferToCall(destination, recipient, amount, revertFlag, callType); + return newTxFromCalls(sender, senderKeyPair, new FrameworkEntrypoint.ContractCall[]{snippetContractCall}); } FrameworkEntrypoint.ContractCall transferToCall(Address destination, Address recipient, long amount, boolean revertFlag, BigInteger callType) { @@ -366,57 +238,11 @@ FrameworkEntrypoint.ContractCall transferToCall(Address destination, Address rec // destination must be our .yul smart contract Transaction deployWithCreate2(ToyAccount sender, KeyPair senderKeyPair, Address destination, String saltString, Bytes contractBytes, boolean revertFlag) { - Bytes salt = Bytes.fromHexStringLenient(saltString); - // the following is the bytecode of the .yul contract - // Bytes yulContractBytes = Bytes.fromHexStringLenient("61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); - // prepare the Create2 function - Function create2Function = - new Function( - FrameworkEntrypoint.FUNC_DEPLOYWITHCREATE2, - Arrays.asList(new org.web3j.abi.datatypes.generated.Bytes32(salt.toArray()), - new org.web3j.abi.datatypes.DynamicBytes(contractBytes.toArray()), - new org.web3j.abi.datatypes.Bool(revertFlag)), - Collections.emptyList()); - - String encoding = FunctionEncoder.encode(create2Function); - - FrameworkEntrypoint.ContractCall snippetContractCall = - new FrameworkEntrypoint.ContractCall( - /*Address*/ destination.toHexString(), - /*calldata*/ Bytes.fromHexStringLenient(encoding).toArray(), - /*gasLimit*/ BigInteger.ZERO, - /*value*/ BigInteger.ZERO, - /*callType*/ BigInteger.ONE); // Normal call, not a delegate call as it is the default - - - List contractCalls = List.of(snippetContractCall); - Function frameworkEntryPointFunction = - new Function( - FrameworkEntrypoint.FUNC_EXECUTECALLS, - List.of(new DynamicArray<>(FrameworkEntrypoint.ContractCall.class, contractCalls)), - Collections.emptyList()); - - Bytes txPayload = - Bytes.fromHexStringLenient(FunctionEncoder.encode(frameworkEntryPointFunction)); - - ToyTransaction.ToyTransactionBuilder tempTx = ToyTransaction.builder() - .sender(sender) - .to(this.frameworkEntryPointAccount) - .payload(txPayload) - .keyPair(senderKeyPair) - .gasLimit(TestContext.gasLimit); - - if (this.txNonce != null) { - tempTx = tempTx.nonce(++this.txNonce); - } - Transaction tx = tempTx.build(); - if (this.txNonce == null) { - this.txNonce = tx.getNonce(); - } - return tx; + FrameworkEntrypoint.ContractCall snippetContractCall = deployWithCreate2Call(destination, saltString, contractBytes, revertFlag); + return newTxFromCalls(sender, senderKeyPair, new FrameworkEntrypoint.ContractCall[]{snippetContractCall}); } - FrameworkEntrypoint.ContractCall deployWithCreate2Call(Address destination, String saltString, Bytes contractBytes) { + FrameworkEntrypoint.ContractCall deployWithCreate2Call(Address destination, String saltString, Bytes contractBytes, boolean revertFlag) { Bytes salt = Bytes.fromHexStringLenient(saltString); // the following is the bytecode of the .yul contract // Bytes yulContractBytes = Bytes.fromHexStringLenient("61037d61001060003961037d6000f3fe6100076102e1565b63a770741d8114610064576397deb47b81146100715763acf07154811461007d57632d97bf1081146100b45763eba7ff7f81146100e757632b261e94811461012157633ecfd51e811461015b5763ffffffff811461017057600080fd5b61006c610177565b610171565b60005460005260206000f35b6004356024356044356100918183856102c7565b61009b828461019d565b600181036100ac576100ab61034d565b5b505050610171565b6004356024356100c481836102cf565b6100ce81846101da565b600182036100df576100de61034d565b5b505050610171565b6004356024356100f682610253565b600081036101095761010881836102db565b5b6001810361011a5761011961034d565b5b5050610171565b6004356024356044353061013682848661030a565b610141838583610217565b600182036101525761015161034d565b5b50505050610171565b61016361028b565b61016b61037a565b610171565b5b5061037c565b7f0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef600055565b7f577269746528616464726573732c75696e743235362c75696e74323536290000604051818152601e8120308585828460606020a4505050505050565b7f5265616428616464726573732c75696e743235362c75696e7432353629202020604051818152601d8120308585828460606020a4505050505050565b7f50617945544828616464726573732c616464726573732c75696e743235362900604051818152601f81208585858360606020a4505050505050565b7f436f6e747261637444657374726f796564286164647265737329000000000000604051818152601a8120838160606020a250505050565b7f52656345544828616464726573732c75696e743235362900000000000000000060405181815260178120303480828460606020a35050505050565b818155505050565b60008154905092915050565b80ff5050565b60007c010000000000000000000000000000000000000000000000000000000060003504905090565b6040517f3ecfd51e0000000000000000000000000000000000000000000000000000000080825260008060208487875af18061034557600080fd5b505050505050565b7f526576657274696e67000000000000000000000000000000000000000000000060206040518281528181fd5b565b"); @@ -425,7 +251,8 @@ FrameworkEntrypoint.ContractCall deployWithCreate2Call(Address destination, Stri new Function( FrameworkEntrypoint.FUNC_DEPLOYWITHCREATE2, Arrays.asList(new org.web3j.abi.datatypes.generated.Bytes32(salt.toArray()), - new org.web3j.abi.datatypes.DynamicBytes(contractBytes.toArray())), + new org.web3j.abi.datatypes.DynamicBytes(contractBytes.toArray()), + new org.web3j.abi.datatypes.Bool(revertFlag)), Collections.emptyList()); String encoding = FunctionEncoder.encode(create2Function);