Skip to content

Commit

Permalink
Reftests 13.3 / EIP-7610 implementation (#7055)
Browse files Browse the repository at this point in the history
* Upgrade reftests to 13.3
* Implement retroactive EIP-7610

We need to do both of these at once as the reference tests needed to be
updated to reflect the changes in the retroactive EIP.

EIPTests for prague are disabled as they are still in flux

Signed-off-by: Danno Ferrin <[email protected]>
  • Loading branch information
shemnon authored May 7, 2024
1 parent 46475ce commit 9f11eba
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public static BonsaiAccount fromRLP(
context, address, address.addressHash(), nonce, balance, storageRoot, codeHash, mutable);
}

@Override
public boolean isStorageEmpty() {
return Hash.EMPTY_TRIE_HASH.equals(storageRoot);
}

@Override
public NavigableMap<Bytes32, AccountStorageEntry> storageEntriesFrom(
final Bytes32 startKeyHash, final int limit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,6 @@ public void commit() {
new StorageConsumingMap<>(
updatedAddress, new ConcurrentHashMap<>(), storagePreloader));

if (tracked.getStorageWasCleared()) {
storageToClear.add(updatedAddress);
pendingStorageUpdates.clear();
}

if (tracked.getWrappedAccount() == null) {
updatedAccount = createAccount(this, tracked);
tracked.setWrappedAccount(updatedAccount);
Expand Down Expand Up @@ -358,6 +353,11 @@ public void commit() {
pendingCode.setUpdated(updatedAccount.getCode());
}

if (tracked.getStorageWasCleared()) {
storageToClear.add(updatedAddress);
pendingStorageUpdates.clear();
}

// This is especially to avoid unnecessary computation for withdrawals and
// self-destruct beneficiaries
if (updatedAccount.getUpdatedStorage().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,18 @@ public NavigableMap<Bytes32, AccountStorageEntry> storageEntriesFrom(
return storageEntries;
}

/**
* Does this account have any storage slots that are set to non-zero values?
*
* @return true if the account has no storage values set to non-zero values. False if any
* storage is set.
*/
@Override
public boolean isStorageEmpty() {
return Hash.EMPTY_TRIE_HASH.equals(
storageTrie == null ? getStorageRoot() : storageTrie.getRootHash());
}

@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
Expand Down
2 changes: 1 addition & 1 deletion ethereum/referencetests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ tasks.register('validateReferenceTestSubmodule') {
description = "Checks that the reference tests submodule is not accidentally changed"
doLast {
def result = new ByteArrayOutputStream()
def expectedHash = '52ddcbcef0d58ec7de6b768b564725391a30b934'
def expectedHash = 'faf33b471465d3c6cdc3d04fbd690895f78d33f2'
def submodulePath = java.nio.file.Path.of("${rootProject.projectDir}", "ethereum/referencetests/src/reference-test/external-resources").toAbsolutePath()
try {
exec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public class BlockchainReferenceTestTools {

// EOF tests are written against an older version of the spec
params.ignore("/stEOF/");

// None of the Prague tests have withdrawls and deposits handling
params.ignore("\\[Prague\\]");
}

private BlockchainReferenceTestTools() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ private static ProtocolSpec protocolSpec(final String name) {

// EOF tests are written against an older version of the spec
params.ignore("/stEOF/");

// None of the Prague tests have withdrawls and deposits handling
params.ignore("-Prague$");
}

private GeneralStateReferenceTestTools() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,12 @@ public interface Account extends AccountState {
* @return the account address
*/
Address getAddress();

/**
* Does this account have any storage slots that are set to non-zero values?
*
* @return true if the account has no storage values set to non-zero values. False if any storage
* is set.
*/
boolean isStorageEmpty();
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ public Map<UInt256, UInt256> getUpdatedStorage() {
return storage;
}

/**
* Does this account have any storage slots that are set to non-zero values?
*
* @return true if the account has no storage values set to non-zero values. False if any storage
* is set.
*/
@Override
public boolean isStorageEmpty() {
return storage.isEmpty();
}

@Override
public void becomeImmutable() {
immutable = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public ContractCreationProcessor(
private static boolean accountExists(final Account account) {
// The account exists if it has sent a transaction
// or already has its code initialized.
return account.getNonce() != 0 || !account.getCode().isEmpty();
return account.getNonce() != 0 || !account.getCode().isEmpty() || !account.isStorageEmpty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,18 @@ public void clearStorage() {
updatedStorage.clear();
}

/**
* Does this account have any storage slots that are set to non-zero values?
*
* @return true if the account has no storage values set to non-zero values. False if any storage
* is set.
*/
@Override
public boolean isStorageEmpty() {
return updatedStorage.isEmpty()
&& (storageWasCleared || account == null || account.isStorageEmpty());
}

/**
* Gets storage was cleared.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ public void clearStorage() {
updatedStorage.clear();
}

/**
* Does this account have any storage slots that are set to non-zero values?
*
* @return true if the account has no storage values set to non-zero values. False if any storage
* is set.
*/
@Override
public boolean isStorageEmpty() {
return updatedStorage.isEmpty()
&& (storageWasCleared || account == null || account.isStorageEmpty());
}

@Override
public void becomeImmutable() {
immutable = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ private void executeOperation(final Bytes contract, final EVM evm) {
when(worldUpdater.getSenderAccount(any())).thenReturn(account);
when(worldUpdater.getOrCreate(any())).thenReturn(newAccount);
when(newAccount.getCode()).thenReturn(Bytes.EMPTY);
when(newAccount.isStorageEmpty()).thenReturn(true);
when(worldUpdater.updater()).thenReturn(worldUpdater);

operation.execute(messageFrame, evm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ void shanghaiMaxInitCodeSizeCreate() {
when(worldUpdater.getSenderAccount(any())).thenReturn(account);
when(worldUpdater.getOrCreate(any())).thenReturn(newAccount);
when(newAccount.getCode()).thenReturn(Bytes.EMPTY);
when(newAccount.isStorageEmpty()).thenReturn(true);
when(worldUpdater.updater()).thenReturn(worldUpdater);

final EVM evm = MainnetEVMs.shanghai(DEV_NET_CHAIN_ID, EvmConfiguration.DEFAULT);
Expand Down Expand Up @@ -247,6 +248,7 @@ void shanghaiMaxInitCodeSizePlus1Create() {
when(worldUpdater.getSenderAccount(any())).thenReturn(account);
when(worldUpdater.getOrCreate(any())).thenReturn(newAccount);
when(newAccount.getCode()).thenReturn(Bytes.EMPTY);
when(newAccount.isStorageEmpty()).thenReturn(true);
when(worldUpdater.updater()).thenReturn(worldUpdater);

final EVM evm = MainnetEVMs.shanghai(DEV_NET_CHAIN_ID, EvmConfiguration.DEFAULT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void createFromMemoryMutationSafe() {
when(worldUpdater.getSenderAccount(any())).thenReturn(account);
when(worldUpdater.getOrCreate(any())).thenReturn(newAccount);
when(newAccount.getCode()).thenReturn(Bytes.EMPTY);
when(newAccount.isStorageEmpty()).thenReturn(true);
when(worldUpdater.updater()).thenReturn(worldUpdater);

final EVM evm = MainnetEVMs.london(EvmConfiguration.DEFAULT);
Expand Down Expand Up @@ -185,6 +186,7 @@ void shanghaiMaxInitCodeSizeCreate() {
when(worldUpdater.getSenderAccount(any())).thenReturn(account);
when(worldUpdater.getOrCreate(any())).thenReturn(newAccount);
when(newAccount.getCode()).thenReturn(Bytes.EMPTY);
when(newAccount.isStorageEmpty()).thenReturn(true);
when(worldUpdater.updater()).thenReturn(worldUpdater);

final EVM evm = MainnetEVMs.shanghai(DEV_NET_CHAIN_ID, EvmConfiguration.DEFAULT);
Expand Down
11 changes: 11 additions & 0 deletions evm/src/test/java/org/hyperledger/besu/evm/toy/ToyAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ public Map<UInt256, UInt256> getUpdatedStorage() {
return storage;
}

/**
* Does this account have any storage slots that are set to non-zero values?
*
* @return true if the account has no storage values set to non-zero values. False if any storage
* is set.
*/
@Override
public boolean isStorageEmpty() {
return storage.isEmpty();
}

@Override
public void becomeImmutable() {
immutable = true;
Expand Down

0 comments on commit 9f11eba

Please sign in to comment.