Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ dependencies {
implementation 'org.hyperledger.besu:besu-plugin-api'
implementation 'org.hyperledger.besu.internal:besu-metrics-core'
implementation 'org.hyperledger.besu.internal:besu-services-kvstore'
implementation 'org.hyperledger.besu.internal:besu-util:25.10-develop-d28fd4f'
implementation 'org.hyperledger.besu.internal:besu-util:25.10-develop-ae58083'
implementation 'org.hyperledger.besu.internal:besu-crypto-algorithms:25.10-develop-ae58083'
}

graalvmNative {
Expand Down Expand Up @@ -184,6 +185,7 @@ graalvmNative {

// Link against the static libraries
buildArgs.add("-H:NativeLinkerOption=-lsecp256k1")
buildArgs.add("-H:NativeLinkerOption=-lsecp256k1_ecrecover")
buildArgs.add("-H:NativeLinkerOption=-lgnark_jni")
buildArgs.add("-H:NativeLinkerOption=-lgnark_eip_196")
buildArgs.add("-H:NativeLinkerOption=-lgnark_eip_2537")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import org.hyperledger.besu.config.GenesisConfig;
import org.hyperledger.besu.consensus.merge.PostMergeContext;
import org.hyperledger.besu.crypto.SignatureAlgorithm;
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.BlockProcessingResult;
import org.hyperledger.besu.ethereum.ProtocolContext;
Expand Down Expand Up @@ -48,9 +50,11 @@
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.ServiceManager;
import org.hyperledger.besu.plugin.services.BesuService;
import org.hyperledger.besu.riscv.poc.crypto.SECP256K1Graal;
import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage;
import org.hyperledger.besu.services.kvstore.SegmentedInMemoryKeyValueStorage;

import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Comparator;
Expand Down Expand Up @@ -80,38 +84,36 @@ private record CommandLineArgs(
Optional<String> blockRlpPath,
Optional<String> genesisConfigPath) {}

/**
* Factory method that builds a complete in-memory Besu execution environment. It imports previous
* headers, reconstructs the world state from a witness, and returns a {@link BlockRunner} ready
* to process a block.
*/
private static final NoOpMetricsSystem noOpMetricsSystem = new NoOpMetricsSystem();

// Configure the EVM with in-memory (stacked) world updater mode.
private static final EvmConfiguration evmConfiguration =
new EvmConfiguration(
EvmConfiguration.DEFAULT.jumpDestCacheWeightKB(),
EvmConfiguration.WorldUpdaterMode.STACKED,
true);
/*

/**
* Factory method that builds a complete in-memory Besu execution environment. It imports previous
* headers, reconstructs the world state from a witness, and returns a {@link BlockRunner} ready
* to process a block.
*/
public static BlockRunner create(
final BlockHeader targetBlockHeader,
final List<BlockHeader> prevHeaders,
final Map<Hash, Bytes> trieNodes,
final Map<Hash, Bytes> codes,
final String genesisConfigJson) {

final GenesisConfig genesisConfig = GenesisConfig.fromConfig(genesisConfigJson);

final NoOpMetricsSystem noOpMetricsSystem = new NoOpMetricsSystem();
// use a minimal protocol schedule:
final ProtocolSchedule protocolSchedule = constructMinimalConfig(genesisConfig, targetBlockHeader);

// Configure the EVM with in-memory (stacked) world updater mode.
final EvmConfiguration evmConfiguration =
new EvmConfiguration(
EvmConfiguration.DEFAULT.jumpDestCacheWeightKB(),
EvmConfiguration.WorldUpdaterMode.STACKED,
true);

// Build the mainnet protocol schedule based on the genesis config.
final ProtocolSchedule protocolSchedule =
MainnetProtocolSchedule.fromConfig(
genesisConfig.getConfigOptions(),
evmConfiguration,
MiningConfiguration.MINING_DISABLED,
new BadBlockManager(),
false,
false,
noOpMetricsSystem);
//TODO: possibly make minimal vs mainnet protocol schedule configurable
// // or use the mainnet-derived protocol schedule
// final ProtocolSchedule protocolSchedule = constructFromGenesisConfig(genesisConfig);

// Construct the genesis state and world state root.
final GenesisState genesisState =
Expand Down Expand Up @@ -234,6 +236,8 @@ public <T extends BesuService> Optional<T> getService(Class<T> serviceType) {
.withServiceManager(serviceManager)
.build();

// The MinimalProtocolSchedule already created the correct precompile registry
// with Graal-native implementations, so no additional decoration is needed.
return new BlockRunner(protocolSchedule, protocolContext, blockchain);
}

Expand Down Expand Up @@ -337,6 +341,33 @@ public void processBlock(final Block block) {
System.out.println(" Stateroot: " + result.getYield().get().getWorldState().rootHash());
}

private static ProtocolSchedule constructMinimalConfig(
GenesisConfig genesisConfig,
BlockHeader targetBlockHeader) {
return MinimalProtocolSchedule.create(
targetBlockHeader,
genesisConfig,
evmConfiguration,
new BadBlockManager(),
noOpMetricsSystem);

}

private static ProtocolSchedule constructFromGenesisConfig(
final GenesisConfig genesisConfig) {
// Build the mainnet protocol schedule based on the genesis config.
return
MainnetProtocolSchedule.fromConfig(
genesisConfig.getConfigOptions(),
evmConfiguration,
MiningConfiguration.MINING_DISABLED,
new BadBlockManager(),
false,
false,
noOpMetricsSystem);


}
/** Print usage information and exit. */
private static void printUsageAndExit() {
System.out.println("Usage: BlockRunner [OPTIONS]");
Expand Down Expand Up @@ -402,7 +433,7 @@ private static String loadFileContent(
try (var inputStream = BlockRunner.class.getResourceAsStream(path)) {
if (inputStream != null) {
System.out.println("Loading from classpath: " + path);
return new String(inputStream.readAllBytes());
return new String(inputStream.readAllBytes(), Charset.defaultCharset());
}
}
// Fall back to filesystem
Expand All @@ -415,6 +446,12 @@ public static void main(final String[] args) {

System.out.println("Starting BlockRunner .");
CommandLineArgs cmdArgs = parseArguments(args);

// set graal signature algorithm:
SignatureAlgorithm graalSig = new SECP256K1Graal();
graalSig.maybeEnableNative();
SignatureAlgorithmFactory.setInstance(graalSig);

try {
ObjectMapper objectMapper = new ObjectMapper();

Expand Down Expand Up @@ -481,7 +518,8 @@ public static void main(final String[] args) {
System.out.println(String.format("\n✓ Setup completed in %.2f ms\n", setupTimeMs));

final BlockRunner runner =
BlockRunner.create(previousHeaders, trieNodes, codes, genesisConfigJson);
BlockRunner.create(
blockToImport.getHeader(), previousHeaders, trieNodes, codes, genesisConfigJson);

runner.processBlock(blockToImport);

Expand Down
Loading