Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markers for the First and Last Account/Storage for the State Manager #1192

Draft
wants to merge 83 commits into
base: arith-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
f8b4577
Adding transaction level map
arijitdutta67 Sep 10, 2024
b3fee90
adding map update method
arijitdutta67 Sep 10, 2024
58ec254
block level maps—first idea
bogdanbear Sep 11, 2024
56b90f8
fixing minor typos
arijitdutta67 Sep 12, 2024
0c8e16d
remove update from post transaction defer.
bogdanbear Sep 13, 2024
459005c
StateManagerMetadata class
bogdanbear Sep 13, 2024
7e08c94
TxMetadataInStorage
bogdanbear Sep 13, 2024
b7373cd
Generic class for accounts and storage
bogdanbear Sep 13, 2024
4eb9b77
refactor
bogdanbear Sep 13, 2024
850ddf8
refactor
bogdanbear Sep 13, 2024
d556f4a
refactor and (addr, storage) pair
bogdanbear Sep 13, 2024
da23d1d
update for storage
bogdanbear Sep 13, 2024
8f53510
map update for storage fragments
bogdanbear Sep 13, 2024
808611e
adding deployment numbers in StorageFragment
bogdanbear Sep 13, 2024
06773a4
adding comments
arijitdutta67 Sep 16, 2024
9bbcfaa
Min/Max DeplNo maps
bogdanbear Sep 18, 2024
6045a65
adding conflation level map for account
arijitdutta67 Sep 18, 2024
8e3da28
adding the remaining maps for the storage
arijitdutta67 Sep 18, 2024
dbb0f9c
Merge branch 'arith-dev' into arijit-bogdan/account-first-last
arijitdutta67 Sep 19, 2024
d111681
fixing import
arijitdutta67 Sep 19, 2024
0d359f7
Merge branch 'arith-dev' into arijit-bogdan/account-first-last
arijitdutta67 Sep 19, 2024
7ce5ad0
fixing gradlew formatting
arijitdutta67 Sep 19, 2024
5d1d8ff
Fix multi block tests
gauravahuja Sep 23, 2024
704aa6a
Merge branch 'arith-dev' into arijit-bogdan/account-first-last
arijitdutta67 Sep 23, 2024
77ffad9
Adding simple multiblock account test
arijitdutta67 Sep 24, 2024
3f5b9ee
Merge branch 'arith-dev' into arijit-bogdan/account-first-last
arijitdutta67 Sep 25, 2024
765ff27
Fixing conflation-level account maps
bogdanbear Sep 27, 2024
deaffdc
annotations
bogdanbear Sep 27, 2024
659dff2
Adding simple multiblock storage test
arijitdutta67 Sep 27, 2024
bf596c0
Adding storage test with warming of accounts
arijitdutta67 Oct 1, 2024
bd30f8e
Merge branch 'arith-dev' into arijit-bogdan/account-first-last
arijitdutta67 Oct 4, 2024
a9382b5
Bug fix
arijitdutta67 Oct 4, 2024
261fdc6
new multi-block test with solidity integration
bogdanbear Oct 11, 2024
741d473
.yul functions and events, and calls from java
bogdanbear Oct 14, 2024
646e718
refactoring—prepping for tests
bogdanbear Oct 14, 2024
6315837
refactoring
bogdanbear Oct 15, 2024
90abb31
Merge branch 'arith-dev' into arijit-bogdan/account-first-last
bogdanbear Oct 15, 2024
690ba09
refactor after merging from main
bogdanbear Oct 15, 2024
cd34771
refactor to use plugin-generated .yul
bogdanbear Oct 15, 2024
6f3030a
seld destruct
bogdanbear Oct 16, 2024
b162f42
self-destruct calls, to be tested more
bogdanbear Oct 16, 2024
dc969d0
Merge branch 'arith-dev' into arijit-bogdan/account-first-last
bogdanbear Oct 23, 2024
18ac0b6
updating with latest .yul and latest arith-dev
bogdanbear Oct 23, 2024
ec3bd15
Create StateManagerEvents.sol
bogdanbear Oct 23, 2024
9f9ace8
first basic storage test
bogdanbear Oct 24, 2024
c38f025
predict create2 address function wip
bogdanbear Oct 24, 2024
0d4ad1f
testing writes after creates
bogdanbear Oct 24, 2024
94a08a5
debugging create2
bogdanbear Oct 24, 2024
669c360
testing create2 storage
bogdanbear Oct 24, 2024
4c33994
refactor
bogdanbear Oct 24, 2024
6e29c45
bug in bytecode
bogdanbear Oct 24, 2024
3612c88
bug in bytecode
bogdanbear Oct 24, 2024
b643a5d
self destructs
bogdanbear Oct 24, 2024
9728748
typo
bogdanbear Oct 24, 2024
15f9036
adding some reverts
bogdanbear Oct 24, 2024
0c53280
explanations
bogdanbear Oct 24, 2024
5202005
reverts, but the validator is wip
bogdanbear Oct 25, 2024
f8476ba
transfer tests wip
bogdanbear Oct 25, 2024
bc9808a
testing Gaurav's bytecode utilities PR
bogdanbear Oct 28, 2024
3ef5435
fixed nonce bug when running tests all the once
bogdanbear Oct 28, 2024
72dc1b5
found a bug
bogdanbear Oct 28, 2024
300ce6f
account map
bogdanbear Oct 28, 2024
ff547ed
account maps
bogdanbear Oct 29, 2024
9a8dd04
account operations
bogdanbear Oct 29, 2024
50a7660
bug fix
bogdanbear Oct 29, 2024
ae5efd2
better transaction validator
bogdanbear Oct 29, 2024
b93f02c
refactor
bogdanbear Oct 29, 2024
cc62290
refactor to avoid batched testing bug
bogdanbear Oct 29, 2024
5310763
bug fix + debugging blockwise storage
bogdanbear Oct 29, 2024
ac67471
transaction map storage testing
bogdanbear Oct 29, 2024
bb1977f
two tx testing in the txMap
bogdanbear Oct 29, 2024
ff93b7e
refactor asserts
bogdanbear Oct 30, 2024
045487a
refactor
bogdanbear Oct 30, 2024
ca6bb51
Merge branch 'arith-dev' into arijit-bogdan/account-first-last
bogdanbear Oct 30, 2024
405ff2c
fix: added tracing for FIRST/AGAIN/FINAL in the account perspective
OlivierBBB Oct 30, 2024
096942b
fix: added tracing for FIRST/AGAIN/FINAL in the storage perspective
OlivierBBB Oct 30, 2024
aa20124
spotless
OlivierBBB Oct 30, 2024
11a9127
fixing bugs
bogdanbear Oct 31, 2024
279bcea
Merge branch 'arith-dev' into arijit-bogdan/account-first-last
bogdanbear Nov 24, 2024
ce70bfb
fixing compiler errors
bogdanbear Nov 25, 2024
0bf8270
adding the tests from debug branch
bogdanbear Nov 25, 2024
0760c5d
small bug in storage tracing
bogdanbear Nov 26, 2024
aa31579
refactor
bogdanbear Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -432,6 +440,7 @@ public Hub(
blockdata /* WARN: must be called AFTER txnData */),
precompileLimitModules().stream())
.toList();
stateManagerMetadata.setHub(this);
}

@Override
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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<AccountFragment>>
blockMapAccount = Hub.stateManagerMetadata().getAccountFirstLastBlockMap();

List<TransactionProcessingMetadata> txn = txStack.getTransactions();

for (TransactionProcessingMetadata metadata : txn) {
if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) {
int blockNumber = transients.block().blockNumber();
Map<Address, TransactionProcessingMetadata.FragmentFirstAndLast<AccountFragment>>
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<AccountFragment> localValueAccount =
localMapAccount.get(addr);
if (!blockMapAccount.containsKey(pairAddrBlock)) {
// the pair is not present in the map
blockMapAccount.put(pairAddrBlock, localValueAccount);
} else {
TransactionProcessingMetadata.FragmentFirstAndLast<AccountFragment> 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<AccountFragment> 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<StorageFragment>>
blockMapStorage = Hub.stateManagerMetadata().getStorageFirstLastBlockMap();

List<TransactionProcessingMetadata> txn = txStack.getTransactions();

for (TransactionProcessingMetadata metadata : txn) {
if (metadata.getRelativeBlockNumber() == transients.block().blockNumber()) {
int blockNumber = transients.block().blockNumber();
Map<
TransactionProcessingMetadata.AddrStorageKeyPair,
TransactionProcessingMetadata.FragmentFirstAndLast<StorageFragment>>
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<StorageFragment> localValueStorage =
localMapStorage.get(addrStorageKeyPair);

if (!blockMapStorage.containsKey(addrStorageBlockTuple)) {
// the pair is not present in the map
blockMapStorage.put(addrStorageBlockTuple, localValueStorage);
} else {
TransactionProcessingMetadata.FragmentFirstAndLast<StorageFragment> 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<StorageFragment> 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<Address, TransactionProcessingMetadata.FragmentFirstAndLast<AccountFragment>>
conflationMapAccount = Hub.stateManagerMetadata().getAccountFirstLastConflationMap();

List<TransactionProcessingMetadata> txn = txStack.getTransactions();
HashSet<Address> allAccounts = new HashSet<Address>();

Map<
StateManagerMetadata.AddrBlockPair,
TransactionProcessingMetadata.FragmentFirstAndLast<AccountFragment>>
blockMapAccount = Hub.stateManagerMetadata().getAccountFirstLastBlockMap();

for (TransactionProcessingMetadata metadata : txn) {

Map<Address, TransactionProcessingMetadata.FragmentFirstAndLast<AccountFragment>>
txnMapAccount = metadata.getAccountFirstAndLastMap();

allAccounts.addAll(txnMapAccount.keySet());
}

for (Address addr : allAccounts) {
TransactionProcessingMetadata.FragmentFirstAndLast<AccountFragment> 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<AccountFragment> blockValue =
blockMapAccount.get(pairAddrBlock);

TransactionProcessingMetadata.FragmentFirstAndLast<AccountFragment> updatedValue =
new TransactionProcessingMetadata.FragmentFirstAndLast<AccountFragment>(
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<StorageFragment>>
conflationMapStorage = Hub.stateManagerMetadata().getStorageFirstLastConflationMap();

List<TransactionProcessingMetadata> txn = txStack.getTransactions();
HashSet<TransactionProcessingMetadata.AddrStorageKeyPair> allStorage =
new HashSet<TransactionProcessingMetadata.AddrStorageKeyPair>();
Map<
StateManagerMetadata.AddrStorageKeyBlockNumTuple,
TransactionProcessingMetadata.FragmentFirstAndLast<StorageFragment>>
blockMapStorage = Hub.stateManagerMetadata().getStorageFirstLastBlockMap();
for (TransactionProcessingMetadata metadata : txn) {

Map<
TransactionProcessingMetadata.AddrStorageKeyPair,
TransactionProcessingMetadata.FragmentFirstAndLast<StorageFragment>>
txnMapStorage = metadata.getStorageFirstAndLastMap();

allStorage.addAll(txnMapStorage.keySet());
}

for (TransactionProcessingMetadata.AddrStorageKeyPair addrStorageKeyPair : allStorage) {
TransactionProcessingMetadata.FragmentFirstAndLast<StorageFragment> 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<StorageFragment> blockValue =
blockMapStorage.get(addrStorageBlockTuple);

TransactionProcessingMetadata.FragmentFirstAndLast<StorageFragment> updatedValue =
new TransactionProcessingMetadata.FragmentFirstAndLast<StorageFragment>(
firstValue.getFirst(),
blockValue.getLast(),
firstValue.getFirstDom(),
firstValue.getFirstSub(),
blockValue.getLastDom(),
blockValue.getLastSub());
conflationMapStorage.put(addrStorageKeyPair, updatedValue);
break;
}
}
}
}
}
Loading
Loading