Skip to content

Commit

Permalink
Restore CancunEOF
Browse files Browse the repository at this point in the history
Signed-off-by: Danno Ferrin <[email protected]>
  • Loading branch information
shemnon committed Oct 3, 2024
1 parent 27dc982 commit 830b030
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,7 @@ private void configureNativeLibs() {
}

if (genesisConfigOptionsSupplier.get().getCancunTime().isPresent()
|| genesisConfigOptionsSupplier.get().getCancunEOFTime().isPresent()
|| genesisConfigOptionsSupplier.get().getPragueTime().isPresent()
|| genesisConfigOptionsSupplier.get().getOsakaTime().isPresent()) {
if (kzgTrustedSetupFile != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ default boolean isConsensusMigration() {
*/
OptionalLong getCancunTime();

/**
* Gets cancun EOF time.
*
* @return the cancun EOF time
*/
OptionalLong getCancunEOFTime();

/**
* Gets prague time.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ public OptionalLong getShanghaiTime() {
return getOptionalLong("shanghaitime");
}

@Override
public OptionalLong getCancunEOFTime() {
return getOptionalLong("cancuneoftime");
}

@Override
public OptionalLong getCancunTime() {
return getOptionalLong("cancuntime");
Expand Down Expand Up @@ -479,6 +484,7 @@ public Map<String, Object> asMap() {
getMergeNetSplitBlockNumber().ifPresent(l -> builder.put("mergeNetSplitBlock", l));
getShanghaiTime().ifPresent(l -> builder.put("shanghaiTime", l));
getCancunTime().ifPresent(l -> builder.put("cancunTime", l));
getCancunEOFTime().ifPresent(l -> builder.put("cancunEOFTime", l));
getPragueTime().ifPresent(l -> builder.put("pragueTime", l));
getOsakaTime().ifPresent(l -> builder.put("osakaTime", l));
getTerminalBlockNumber().ifPresent(l -> builder.put("terminalBlockNumber", l));
Expand Down Expand Up @@ -632,6 +638,7 @@ public List<Long> getForkBlockTimestamps() {
Stream.of(
getShanghaiTime(),
getCancunTime(),
getCancunEOFTime(),
getPragueTime(),
getOsakaTime(),
getFutureEipsTime(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions, Cloneable
private OptionalLong mergeNetSplitBlockNumber = OptionalLong.empty();
private OptionalLong shanghaiTime = OptionalLong.empty();
private OptionalLong cancunTime = OptionalLong.empty();
private OptionalLong cancunEOFTime = OptionalLong.empty();
private OptionalLong pragueTime = OptionalLong.empty();
private OptionalLong osakaTime = OptionalLong.empty();
private OptionalLong futureEipsTime = OptionalLong.empty();
Expand Down Expand Up @@ -240,6 +241,11 @@ public OptionalLong getCancunTime() {
return cancunTime;
}

@Override
public OptionalLong getCancunEOFTime() {
return cancunEOFTime;
}

@Override
public OptionalLong getPragueTime() {
return pragueTime;
Expand Down Expand Up @@ -642,6 +648,17 @@ public StubGenesisConfigOptions cancunTime(final long timestamp) {
return this;
}

/**
* Cancun EOF time.
*
* @param timestamp the timestamp
* @return the stub genesis config options
*/
public StubGenesisConfigOptions cancunEOFTime(final long timestamp) {
cancunEOFTime = OptionalLong.of(timestamp);
return this;
}

/**
* Prague time.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ void shouldGetCancunTime() {
assertThat(config.getCancunTime()).hasValue(1670470142);
}

@Test
void shouldGetCancunEOFTime() {
final GenesisConfigOptions config =
fromConfigOptions(singletonMap("cancunEOFTime", 1670470142));
assertThat(config.getCancunEOFTime()).hasValue(1670470142);
}

@Test
void shouldGetPragueTime() {
final GenesisConfigOptions config = fromConfigOptions(singletonMap("pragueTime", 1670470143));
Expand Down Expand Up @@ -237,6 +244,7 @@ void shouldNotReturnEmptyOptionalWhenBlockNumberNotSpecified() {
assertThat(config.getMergeNetSplitBlockNumber()).isEmpty();
assertThat(config.getShanghaiTime()).isEmpty();
assertThat(config.getCancunTime()).isEmpty();
assertThat(config.getCancunEOFTime()).isEmpty();
assertThat(config.getPragueTime()).isEmpty();
assertThat(config.getOsakaTime()).isEmpty();
assertThat(config.getFutureEipsTime()).isEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ enum MainnetHardforkId implements HardforkId {
SHANGHAI(true, "Shanghai"),
/** Cancun fork. */
CANCUN(true, "Cancun"),
/** Cancun + EOF fork. */
CANCUN_EOF(false, "Cancun + EOF"),
/** Prague fork. */
PRAGUE(false, "Prague"),
/** Osaka fork. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,15 @@ private static boolean isCancunAtGenesis(final GenesisConfigFile genesis) {
if (cancunTimestamp.isPresent()) {
return genesis.getTimestamp() >= cancunTimestamp.getAsLong();
}
return isPragueAtGenesis(genesis) || isOsakaAtGenesis(genesis);
return isPragueAtGenesis(genesis) || isCancunEOFAtGenesis(genesis);
}

private static boolean isCancunEOFAtGenesis(final GenesisConfigFile genesis) {
final OptionalLong cancunEOFTimestamp = genesis.getConfigOptions().getCancunEOFTime();
if (cancunEOFTimestamp.isPresent()) {
return genesis.getTimestamp() >= cancunEOFTimestamp.getAsLong();
}
return false;
}

private static boolean isPragueAtGenesis(final GenesisConfigFile genesis) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,17 @@ public ProtocolSpecBuilder cancunDefinition(final GenesisConfigOptions genesisCo
metricsSystem);
}

public ProtocolSpecBuilder cancunEOFDefinition(final GenesisConfigOptions genesisConfigOptions) {
return MainnetProtocolSpecs.cancunEOFDefinition(
chainId,
isRevertReasonEnabled,
genesisConfigOptions,
evmConfiguration,
miningParameters,
isParallelTxProcessingEnabled,
metricsSystem);
}

public ProtocolSpecBuilder pragueDefinition(final GenesisConfigOptions genesisConfigOptions) {
return MainnetProtocolSpecs.pragueDefinition(
chainId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,27 @@ static ProtocolSpecBuilder cancunDefinition(
.name("Cancun");
}

static ProtocolSpecBuilder cancunEOFDefinition(
final Optional<BigInteger> chainId,
final boolean enableRevertReason,
final GenesisConfigOptions genesisConfigOptions,
final EvmConfiguration evmConfiguration,
final MiningParameters miningParameters,
final boolean isParallelTxProcessingEnabled,
final MetricsSystem metricsSystem) {

ProtocolSpecBuilder protocolSpecBuilder =
cancunDefinition(
chainId,
enableRevertReason,
genesisConfigOptions,
evmConfiguration,
miningParameters,
isParallelTxProcessingEnabled,
metricsSystem);
return addEOF(chainId, evmConfiguration, protocolSpecBuilder).name("CancunEOF");
}

static ProtocolSpecBuilder pragueDefinition(
final Optional<BigInteger> chainId,
final boolean enableRevertReason,
Expand Down Expand Up @@ -812,6 +833,13 @@ static ProtocolSpecBuilder osakaDefinition(
miningParameters,
isParallelTxProcessingEnabled,
metricsSystem);
return addEOF(chainId, evmConfiguration, protocolSpecBuilder).name("Osaka");
}

private static ProtocolSpecBuilder addEOF(
final Optional<BigInteger> chainId,
final EvmConfiguration evmConfiguration,
final ProtocolSpecBuilder protocolSpecBuilder) {
return protocolSpecBuilder
// EIP-7692 EOF v1 Gas calculator
.gasCalculator(OsakaGasCalculator::new)
Expand All @@ -827,8 +855,7 @@ static ProtocolSpecBuilder osakaDefinition(
true,
List.of(MaxCodeSizeRule.from(evm), EOFValidationCodeRule.from(evm)),
1,
SPURIOUS_DRAGON_FORCE_DELETE_WHEN_EMPTY_ADDRESSES))
.name("Osaka");
SPURIOUS_DRAGON_FORCE_DELETE_WHEN_EMPTY_ADDRESSES));
}

static ProtocolSpecBuilder futureEipsDefinition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ private void validateEthereumForkOrdering() {
// Begin timestamp forks
lastForkBlock = validateForkOrder("Shanghai", config.getShanghaiTime(), lastForkBlock);
lastForkBlock = validateForkOrder("Cancun", config.getCancunTime(), lastForkBlock);
lastForkBlock = validateForkOrder("CancunEOF", config.getCancunEOFTime(), lastForkBlock);
lastForkBlock = validateForkOrder("Prague", config.getPragueTime(), lastForkBlock);
lastForkBlock = validateForkOrder("Osaka", config.getOsakaTime(), lastForkBlock);
lastForkBlock = validateForkOrder("FutureEips", config.getFutureEipsTime(), lastForkBlock);
Expand Down Expand Up @@ -404,6 +405,10 @@ private List<BuilderMapEntry> createMilestones(final MainnetProtocolSpecFactory
HardforkId.MainnetHardforkId.CANCUN,
config.getCancunTime(),
specFactory.cancunDefinition(config)),
timestampMilestone(
HardforkId.MainnetHardforkId.CANCUN_EOF,
config.getCancunEOFTime(),
specFactory.cancunEOFDefinition(config)),
timestampMilestone(
HardforkId.MainnetHardforkId.PRAGUE,
config.getPragueTime(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,21 @@ public static Map<String, Supplier<ProtocolSchedule>> createSchedules(final BigI
"cancun",
createSchedule(
new StubGenesisConfigOptions().cancunTime(0).baseFeePerGas(0x0a).chainId(chainId))),
Map.entry(
"cancuneof",
createSchedule(
new StubGenesisConfigOptions()
.cancunEOFTime(0)
.baseFeePerGas(0x0a)
.chainId(chainId))),
Map.entry(
"prague",
createSchedule(
new StubGenesisConfigOptions().pragueTime(0).baseFeePerGas(0x0a).chainId(chainId))),
new StubGenesisConfigOptions()
.pragueTime(0)
.osakaTime(0) // TODO remove this once osaka_devnet_0 launches
.baseFeePerGas(0x0a)
.chainId(chainId))),
Map.entry(
"osaka",
createSchedule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public static GasCalculator gasCalculatorForFork(final String fork) {
case LONDON, PARIS -> new LondonGasCalculator();
case SHANGHAI -> new ShanghaiGasCalculator();
case CANCUN -> new CancunGasCalculator();
case CANCUN_EOF -> new OsakaGasCalculator();
case PRAGUE -> new PragueGasCalculator();
case OSAKA -> new OsakaGasCalculator();
case AMSTERDAM, BOGOTA, POLIS, BANGKOK, FUTURE_EIPS, EXPERIMENTAL_EIPS ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,18 @@ public static ReferenceTestProtocolSchedules create(final StubGenesisConfigOptio
"ShanghaiToCancunAtTime15k",
createSchedule(genesisStub.clone().shanghaiTime(0).cancunTime(15000))),
Map.entry("Cancun", createSchedule(genesisStub.clone().cancunTime(0))),
Map.entry("CancunEOF", createSchedule(genesisStub.clone().cancunEOFTime(0))),
Map.entry(
"CancunToPragueAtTime15k",
createSchedule(genesisStub.clone().cancunTime(0).pragueTime(15000))),
Map.entry("Prague", createSchedule(genesisStub.clone().pragueTime(0))),
Map.entry(
"Prague",
createSchedule(
genesisStub
.clone()
.pragueTime(0)
.osakaTime(0) // TODO remove this once osaka_devnet_0 ships
)),
Map.entry("Osaka", createSchedule(genesisStub.clone().osakaTime(0))),
Map.entry("Amsterdam", createSchedule(genesisStub.clone().futureEipsTime(0))),
Map.entry("Bogota", createSchedule(genesisStub.clone().futureEipsTime(0))),
Expand Down
10 changes: 10 additions & 0 deletions evm/src/main/java/org/hyperledger/besu/evm/EvmSpecVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public enum EvmSpecVersion {
SHANGHAI(MainnetHardforkId.SHANGHAI, 0x6000, 0xc000, 0),
/** Cancun evm spec version. */
CANCUN(MainnetHardforkId.CANCUN, 0x6000, 0xc000, 0),
/** Cancun evm spec version. */
CANCUN_EOF(MainnetHardforkId.CANCUN_EOF, 0x6000, 0xc000, 1),
/** Prague evm spec version. */
PRAGUE(MainnetHardforkId.PRAGUE, 0x6000, 0xc000, 0),
/** Osaka evm spec version. */
Expand Down Expand Up @@ -179,6 +181,14 @@ public void maybeWarnVersion() {
* @return the EVM spec version for that fork, or null if no fork matched.
*/
public static EvmSpecVersion fromName(final String name) {
// TODO remove once CancunEOF tests are removed from EEST
if ("prague".equalsIgnoreCase(name)) {
return EvmSpecVersion.OSAKA;
}
// TODO remove once CancunEOF tests are removed from EEST
if ("cancuneof".equalsIgnoreCase(name)) {
return EvmSpecVersion.CANCUN_EOF;
}
for (var version : EvmSpecVersion.values()) {
if (version.name().equalsIgnoreCase(name)) {
return version;
Expand Down
75 changes: 75 additions & 0 deletions evm/src/main/java/org/hyperledger/besu/evm/MainnetEVMs.java
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,76 @@ public static void registerCancunOperations(
registry.put(new BlobBaseFeeOperation(gasCalculator));
}

/**
* CancunEOF evm.
*
* @param evmConfiguration the evm configuration
* @return the evm
*/
public static EVM cancunEOF(final EvmConfiguration evmConfiguration) {
return cancunEOF(DEV_NET_CHAIN_ID, evmConfiguration);
}

/**
* CancunEOF evm.
*
* @param chainId the chain id
* @param evmConfiguration the evm configuration
* @return the evm
*/
public static EVM cancunEOF(final BigInteger chainId, final EvmConfiguration evmConfiguration) {
return cancunEOF(new CancunGasCalculator(), chainId, evmConfiguration);
}

/**
* CancunEOF evm.
*
* @param gasCalculator the gas calculator
* @param chainId the chain id
* @param evmConfiguration the evm configuration
* @return the evm
*/
public static EVM cancunEOF(
final GasCalculator gasCalculator,
final BigInteger chainId,
final EvmConfiguration evmConfiguration) {
return new EVM(
cancunEOFOperations(gasCalculator, chainId),
gasCalculator,
evmConfiguration,
EvmSpecVersion.CANCUN_EOF);
}

/**
* Operation registry for PragueEOF's operations.
*
* @param gasCalculator the gas calculator
* @param chainId the chain id
* @return the operation registry
*/
public static OperationRegistry cancunEOFOperations(
final GasCalculator gasCalculator, final BigInteger chainId) {
OperationRegistry operationRegistry = new OperationRegistry();
registerCancunEOFOperations(operationRegistry, gasCalculator, chainId);
return operationRegistry;
}

/**
* Register CancunEOF's operations.
*
* @param registry the registry
* @param gasCalculator the gas calculator
* @param chainID the chain id
*/
public static void registerCancunEOFOperations(
final OperationRegistry registry,
final GasCalculator gasCalculator,
final BigInteger chainID) {
registerCancunOperations(registry, gasCalculator, chainID);

registerEOFOperations(registry, gasCalculator);
}

/**
* Prague evm.
*
Expand Down Expand Up @@ -1024,6 +1094,11 @@ public static void registerOsakaOperations(
final BigInteger chainID) {
registerPragueOperations(registry, gasCalculator, chainID);

registerEOFOperations(registry, gasCalculator);
}

private static void registerEOFOperations(
final OperationRegistry registry, final GasCalculator gasCalculator) {
// EIP-663 Unlimited Swap and Dup
registry.put(new DupNOperation(gasCalculator));
registry.put(new SwapNOperation(gasCalculator));
Expand Down
Loading

0 comments on commit 830b030

Please sign in to comment.