Skip to content

Commit

Permalink
feat: Use Journaled EVM Updater (0.46) (#11172)
Browse files Browse the repository at this point in the history
Use Journaled EVM updater in v046 EVMs.
Signed-off-by: Danno Ferrin <[email protected]>
  • Loading branch information
shemnon authored Jan 26, 2024
1 parent c963b4a commit a723e9c
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ document which major hardfork corresponds to each internal version.
|---------------:|:------------------------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `v0.30` | [London](https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/london.md) | |
| `v0.34` | [Paris](https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/paris.md) | Replaces `DIFFICULTY` with `RANDAO`, removes errors from Invalid Solidity Addresses. Adds lazy creation (hollow account creation) capabilities in the EVM as per HIP-583. |
| ? | [Shanghai](https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md) | Expected Q2 2023 or later |
| `v0.38` | [Shanghai](https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md) | Adds `PUSH0` opcode needed for solidity compatibility |
| `v0.46` | Shanghai | Change to non-existing call behavior for EVM Equivalence |

## Open Questions

Expand All @@ -62,6 +63,7 @@ The exact timing of versions that correspond to Ethereum Mainnet forks is out of
## Acceptance Tests

Acceptance tests use the Paris re-definition of `DIFFICULTY` as the test for activation

* Test that when dynamic is set to false that changing the version has no effect
* Test when dynamic is set to true the evm version can change at each transaction
* verify 0.30 still returns zeros for difficulty
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2023 Hedera Hashgraph, LLC
* Copyright (C) 2021-2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -98,6 +98,9 @@ class HederaEvmTxProcessorTest {
@Mock
private BlockMetaSource blockMetaSource;

@Mock
private EvmConfiguration evmConfiguration;

private final HederaEvmAccount sender =
new HederaEvmAccount(Address.fromHexString("0x000000000000000000000000000000000000071e"));
private final Address senderAddress = Address.fromHexString("0x000000000000000000000000000000000000070e");
Expand All @@ -118,7 +121,9 @@ void setup() {
MainnetEVMs.registerLondonOperations(operationRegistry, gasCalculator, BigInteger.ZERO);
operations.forEach(operationRegistry::put);
when(globalDynamicProperties.evmVersion()).thenReturn(EVM_VERSION_0_30);
final var evm30 = new EVM(operationRegistry, gasCalculator, EvmConfiguration.DEFAULT, EvmSpecVersion.LONDON);
when(evmConfiguration.getJumpDestCacheWeightBytes())
.thenReturn(EvmConfiguration.DEFAULT.getJumpDestCacheWeightBytes());
final var evm30 = new EVM(operationRegistry, gasCalculator, evmConfiguration, EvmSpecVersion.LONDON);
final Map<String, Provider<MessageCallProcessor>> mcps = Map.of(
EVM_VERSION_0_30,
() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,15 @@ static Operation provideSStoreOperation(
@Provides
@Singleton
@V_0_46
static EVM provideV_0_46EVM(@V_0_46 Set<Operation> hederaOperations, GasCalculator gasCalculator) {
static EVM provideV_0_46EVM(
@V_0_46 Set<Operation> hederaOperations,
final EvmConfiguration evmConfiguration,
GasCalculator gasCalculator) {
var operationRegistry = new OperationRegistry();
// ChainID will be overridden
registerShanghaiOperations(operationRegistry, gasCalculator, BigInteger.ZERO);
hederaOperations.forEach(operationRegistry::put);
return new EVM(operationRegistry, gasCalculator, EvmConfiguration.DEFAULT, EvmSpecVersion.SHANGHAI);
return new EVM(operationRegistry, gasCalculator, evmConfiguration, EvmSpecVersion.SHANGHAI);
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ class CallEvmTxProcessorTest {
@Mock
private InHandleBlockMetaSource blockMetaSource;

@Mock
private EvmConfiguration evmConfiguration;

private final Account sender = new Account(new Id(0, 0, 1002));
private final Account receiver = new Account(new Id(0, 0, 1006));
private final Account relayer = new Account(new Id(0, 0, 1007));
Expand All @@ -159,7 +162,9 @@ void setup() {
MainnetEVMs.registerLondonOperations(operationRegistry, gasCalculator, BigInteger.ZERO);
operations.forEach(operationRegistry::put);
when(globalDynamicProperties.evmVersion()).thenReturn(EVM_VERSION_0_30);
var evm30 = new EVM(operationRegistry, gasCalculator, EvmConfiguration.DEFAULT, EvmSpecVersion.LONDON);
when(evmConfiguration.getJumpDestCacheWeightBytes())
.thenReturn(EvmConfiguration.DEFAULT.getJumpDestCacheWeightBytes());
var evm30 = new EVM(operationRegistry, gasCalculator, evmConfiguration, EvmSpecVersion.LONDON);
Map<String, Provider<MessageCallProcessor>> mcps = Map.of(
EVM_VERSION_0_30,
() -> {
Expand Down Expand Up @@ -637,7 +642,9 @@ void assertProcessingResourceExhaustionChargesBothSenderAndRelayerWithoutRefunds
MainnetEVMs.registerLondonOperations(operationRegistry, gasCalculator, BigInteger.ZERO);
operations.forEach(operationRegistry::put);
when(globalDynamicProperties.evmVersion()).thenReturn(EVM_VERSION_0_30);
var evm30 = new EVM(operationRegistry, gasCalculator, EvmConfiguration.DEFAULT, EvmSpecVersion.LONDON);
when(evmConfiguration.getJumpDestCacheWeightBytes())
.thenReturn(EvmConfiguration.DEFAULT.getJumpDestCacheWeightBytes());
var evm30 = new EVM(operationRegistry, gasCalculator, evmConfiguration, EvmSpecVersion.LONDON);
final MessageCallProcessor messageCallProcessor = mock(MessageCallProcessor.class);
Map<String, Provider<MessageCallProcessor>> mcps =
Map.of(EVM_VERSION_0_30, () -> messageCallProcessor, EVM_VERSION_0_34, () -> messageCallProcessor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class CallLocalEvmTxProcessorTest {
@Mock
private HederaBlockValues hederaBlockValues;

@Mock
private EvmConfiguration evmConfiguration;

private final Account sender = new Account(new Id(0, 0, 1002));
private final Account receiver = new Account(new Id(0, 0, 1006));
private final Address receiverAddress = receiver.getId().asEvmAddress();
Expand All @@ -120,7 +123,9 @@ void setup() {
MainnetEVMs.registerLondonOperations(operationRegistry, gasCalculator, BigInteger.ZERO);
operations.forEach(operationRegistry::put);
when(globalDynamicProperties.evmVersion()).thenReturn(EVM_VERSION_0_30);
var evm30 = new EVM(operationRegistry, gasCalculator, EvmConfiguration.DEFAULT, EvmSpecVersion.LONDON);
when(evmConfiguration.getJumpDestCacheWeightBytes())
.thenReturn(EvmConfiguration.DEFAULT.getJumpDestCacheWeightBytes());
var evm30 = new EVM(operationRegistry, gasCalculator, evmConfiguration, EvmSpecVersion.LONDON);
Map<String, Provider<MessageCallProcessor>> mcps =
Map.of(EVM_VERSION_0_30, () -> new MessageCallProcessor(evm30, new PrecompileContractRegistry()));
Map<String, Provider<ContractCreationProcessor>> ccps =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2023 Hedera Hashgraph, LLC
* Copyright (C) 2021-2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -106,6 +106,9 @@ class CreateEvmTxProcessorTest {
@Mock
private AliasManager aliasManager;

@Mock
EvmConfiguration evmConfiguration;

private CreateEvmTxProcessor createEvmTxProcessor;
private final Account sender = new Account(new Id(0, 0, 1002));
private final Account receiver = new Account(new Id(0, 0, 1006));
Expand All @@ -124,7 +127,9 @@ void setup() {
MainnetEVMs.registerLondonOperations(operationRegistry, gasCalculator, BigInteger.ZERO);
operations.forEach(operationRegistry::put);
when(globalDynamicProperties.evmVersion()).thenReturn(EVM_VERSION_0_30);
var evm30 = new EVM(operationRegistry, gasCalculator, EvmConfiguration.DEFAULT, EvmSpecVersion.LONDON);
when(evmConfiguration.getJumpDestCacheWeightBytes())
.thenReturn(EvmConfiguration.DEFAULT.getJumpDestCacheWeightBytes());
var evm30 = new EVM(operationRegistry, gasCalculator, evmConfiguration, EvmSpecVersion.LONDON);
Map<String, Provider<MessageCallProcessor>> mcps =
Map.of(EVM_VERSION_0_30, () -> new MessageCallProcessor(evm30, new PrecompileContractRegistry()));
Map<String, Provider<ContractCreationProcessor>> ccps =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

/**
* Provides the Services 0.46 EVM implementation, which consists of Shanghai operations and
* Instanbul precompiles plus the Hedera gas calculator, system contracts, and operations
* Istanbul precompiles plus the Hedera gas calculator, system contracts, and operations
* as they were configured in the 0.46 release (with treatment of calls to non-existing addresses
* returning successful results in order to enhance EVM equivalence).
*/
Expand Down Expand Up @@ -125,12 +125,14 @@ static CustomMessageCallProcessor provideMessageCallProcessor(
@Singleton
@ServicesV046
static EVM provideEVM(
@ServicesV046 @NonNull final Set<Operation> customOperations, @NonNull final GasCalculator gasCalculator) {
// Use Paris EVM with 0.38 custom operations and 0x00 chain id (set at runtime)
@ServicesV046 @NonNull final Set<Operation> customOperations,
@NonNull final EvmConfiguration evmConfiguration,
@NonNull final GasCalculator gasCalculator) {
// Use Shanghai EVM with 0.46 custom operations and 0x00 chain id (set at runtime)
final var operationRegistry = new OperationRegistry();
registerShanghaiOperations(operationRegistry, gasCalculator, BigInteger.ZERO);
customOperations.forEach(operationRegistry::put);
return new EVM(operationRegistry, gasCalculator, EvmConfiguration.DEFAULT, EvmSpecVersion.SHANGHAI);
return new EVM(operationRegistry, gasCalculator, evmConfiguration, EvmSpecVersion.SHANGHAI);
}

@Provides
Expand Down

0 comments on commit a723e9c

Please sign in to comment.