From 3a7436a540601398b62552f73590239df4ed8755 Mon Sep 17 00:00:00 2001 From: garyschulte Date: Thu, 9 Apr 2026 13:59:50 -0700 Subject: [PATCH 1/4] overload decodeTrieLog to enable historical trielog decoding Signed-off-by: garyschulte --- .../shomei/trielog/TrieLogLayerConverter.java | 18 +++++++++++++----- ...ollupGetVirtualZkEVMStateMerkleProofV1.java | 6 ++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/net/consensys/shomei/trielog/TrieLogLayerConverter.java b/core/src/main/java/net/consensys/shomei/trielog/TrieLogLayerConverter.java index 1278aeec..7be92ec7 100644 --- a/core/src/main/java/net/consensys/shomei/trielog/TrieLogLayerConverter.java +++ b/core/src/main/java/net/consensys/shomei/trielog/TrieLogLayerConverter.java @@ -41,13 +41,17 @@ public class TrieLogLayerConverter { private static final Logger LOG = LoggerFactory.getLogger(TrieLogLayerConverter.class); - final WorldStateStorage worldStateStorage; + final WorldStateStorage headWorldStateStorage; public TrieLogLayerConverter(final WorldStateStorage worldStateStorage) { - this.worldStateStorage = worldStateStorage; + this.headWorldStateStorage = worldStateStorage; } public TrieLogLayer decodeTrieLog(final RLPInput input) { + return decodeTrieLog(input, headWorldStateStorage); + } + + public TrieLogLayer decodeTrieLog(final RLPInput input, WorldStateStorage wss) { TrieLogLayer trieLogLayer = new TrieLogLayer(); @@ -80,7 +84,7 @@ public TrieLogLayer decodeTrieLog(final RLPInput input) { if (input.nextIsNull()) { input.skipNext(); maybeAccountIndex = - worldStateStorage + wss .getFlatLeaf(WRAP_ACCOUNT.apply(accountKey.accountHash())) .map(FlattenedLeaf::leafIndex); } else { @@ -122,7 +126,7 @@ public TrieLogLayer decodeTrieLog(final RLPInput input) { maybeAccountIndex .flatMap( index -> { - return new StorageTrieRepositoryWrapper(index, worldStateStorage, null) + return new StorageTrieRepositoryWrapper(index, wss, null) .getFlatLeaf(storageSlotKey.slotHash()) .map(FlattenedLeaf::leafValue) .map(UInt256::fromBytes); @@ -181,11 +185,15 @@ public TrieLogLayer decodeTrieLog(final RLPInput input) { record PriorAccount(ZkAccount account, Bytes32 evmStorageRoot, Optional index) {} public PriorAccount preparePriorTrieLogAccount(final AccountKey accountKey, final RLPInput in) { + return preparePriorTrieLogAccount(accountKey, in , headWorldStateStorage); + } + + public PriorAccount preparePriorTrieLogAccount(final AccountKey accountKey, final RLPInput in, final WorldStateStorage wss) { final ZkAccount oldAccountValue; final Optional flatLeaf = - worldStateStorage.getFlatLeaf(WRAP_ACCOUNT.apply(accountKey.accountHash())); + wss.getFlatLeaf(WRAP_ACCOUNT.apply(accountKey.accountHash())); if (in.nextIsNull() && flatLeaf.isEmpty()) { diff --git a/services/rpc/server/src/main/java/net/consensys/shomei/rpc/server/method/RollupGetVirtualZkEVMStateMerkleProofV1.java b/services/rpc/server/src/main/java/net/consensys/shomei/rpc/server/method/RollupGetVirtualZkEVMStateMerkleProofV1.java index 770c43fd..49810ffc 100644 --- a/services/rpc/server/src/main/java/net/consensys/shomei/rpc/server/method/RollupGetVirtualZkEVMStateMerkleProofV1.java +++ b/services/rpc/server/src/main/java/net/consensys/shomei/rpc/server/method/RollupGetVirtualZkEVMStateMerkleProofV1.java @@ -75,7 +75,8 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { } // do not have it in cache - if (worldStateArchive.getCachedWorldState(parentBlockNumber).isEmpty()) { + final var optWorldState = worldStateArchive.getCachedWorldState(parentBlockNumber); + if (optWorldState.isEmpty()) { return new ShomeiJsonRpcErrorResponse( requestContext.getRequest().getId(), RpcErrorType.INVALID_PARAMS, @@ -90,7 +91,8 @@ public JsonRpcResponse response(final JsonRpcRequestContext requestContext) { // Decode the trielog final TrieLogLayer trieLogLayer = - worldStateArchive.getTrieLogLayerConverter().decodeTrieLog(RLP.input(trieLogBytes)); + worldStateArchive.getTrieLogLayerConverter().decodeTrieLog( + RLP.input(trieLogBytes), optWorldState.get().getZkEvmWorldStateStorage()); // Apply the virtual trielog and generate the trace // This generates a trace without persisting the state From be19f52f9da19e37a054a157fb732869b0ac096e Mon Sep 17 00:00:00 2001 From: garyschulte Date: Thu, 9 Apr 2026 14:11:13 -0700 Subject: [PATCH 2/4] add worldstatestorage to preparePriorTrieLogAccount call, remove unused overload Signed-off-by: garyschulte --- .../shomei/trielog/TrieLogLayerConverter.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/net/consensys/shomei/trielog/TrieLogLayerConverter.java b/core/src/main/java/net/consensys/shomei/trielog/TrieLogLayerConverter.java index 7be92ec7..c37e8dd0 100644 --- a/core/src/main/java/net/consensys/shomei/trielog/TrieLogLayerConverter.java +++ b/core/src/main/java/net/consensys/shomei/trielog/TrieLogLayerConverter.java @@ -43,8 +43,8 @@ public class TrieLogLayerConverter { final WorldStateStorage headWorldStateStorage; - public TrieLogLayerConverter(final WorldStateStorage worldStateStorage) { - this.headWorldStateStorage = worldStateStorage; + public TrieLogLayerConverter(final WorldStateStorage headWorldStateStorage) { + this.headWorldStateStorage = headWorldStateStorage; } public TrieLogLayer decodeTrieLog(final RLPInput input) { @@ -89,7 +89,7 @@ public TrieLogLayer decodeTrieLog(final RLPInput input, WorldStateStorage wss) { .map(FlattenedLeaf::leafIndex); } else { input.enterList(); - final PriorAccount priorAccount = preparePriorTrieLogAccount(accountKey, input); + final PriorAccount priorAccount = preparePriorTrieLogAccount(accountKey, input, wss); maybeAccountIndex = priorAccount.index; final ZkAccount newAccountValue = TrieLogLayer.nullOrValue( @@ -184,10 +184,6 @@ public TrieLogLayer decodeTrieLog(final RLPInput input, WorldStateStorage wss) { record PriorAccount(ZkAccount account, Bytes32 evmStorageRoot, Optional index) {} - public PriorAccount preparePriorTrieLogAccount(final AccountKey accountKey, final RLPInput in) { - return preparePriorTrieLogAccount(accountKey, in , headWorldStateStorage); - } - public PriorAccount preparePriorTrieLogAccount(final AccountKey accountKey, final RLPInput in, final WorldStateStorage wss) { final ZkAccount oldAccountValue; From 97a2266de2619a6b35747549f3d637e9437a3c26 Mon Sep 17 00:00:00 2001 From: garyschulte Date: Thu, 9 Apr 2026 19:35:38 -0700 Subject: [PATCH 3/4] fix unit test mock Signed-off-by: garyschulte --- .../method/RollupGetVirtualZkEVMStateMerkleProofV1Test.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/rpc/server/src/test/java/net/consensys/shomei/rpc/server/method/RollupGetVirtualZkEVMStateMerkleProofV1Test.java b/services/rpc/server/src/test/java/net/consensys/shomei/rpc/server/method/RollupGetVirtualZkEVMStateMerkleProofV1Test.java index 060b6732..f4026d97 100644 --- a/services/rpc/server/src/test/java/net/consensys/shomei/rpc/server/method/RollupGetVirtualZkEVMStateMerkleProofV1Test.java +++ b/services/rpc/server/src/test/java/net/consensys/shomei/rpc/server/method/RollupGetVirtualZkEVMStateMerkleProofV1Test.java @@ -148,7 +148,7 @@ public void shouldReturnValidResponseWhenSimulationSucceeds() throws Exception { // Mock the trielog layer converter when(worldStateArchive.getTrieLogLayerConverter()).thenReturn(trieLogLayerConverter); - when(trieLogLayerConverter.decodeTrieLog(any())).thenReturn(trieLogLayer); + when(trieLogLayerConverter.decodeTrieLog(any(), any())).thenReturn(trieLogLayer); // Mock virtual trace generation final List> mockTraces = List.of(List.of()); From d9976fe11af889c0ed7e154de9d366b9a786e916 Mon Sep 17 00:00:00 2001 From: garyschulte Date: Thu, 9 Apr 2026 16:20:48 -0700 Subject: [PATCH 4/4] initial commit, use blockImportTracer during simulate Signed-off-by: garyschulte --- .../shomei/rpc/client/BesuSimulateClient.java | 2 +- .../shomei/rpc/client/model/SimulateV1Request.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/services/rpc/client/src/main/java/net/consensys/shomei/rpc/client/BesuSimulateClient.java b/services/rpc/client/src/main/java/net/consensys/shomei/rpc/client/BesuSimulateClient.java index f6d77d3b..5f76d976 100644 --- a/services/rpc/client/src/main/java/net/consensys/shomei/rpc/client/BesuSimulateClient.java +++ b/services/rpc/client/src/main/java/net/consensys/shomei/rpc/client/BesuSimulateClient.java @@ -169,7 +169,7 @@ public CompletableFuture simulateTransaction( // Create params with returnTrieLog=true final SimulateV1Request.SimulateV1Params params = - new SimulateV1Request.SimulateV1Params(List.of(blockStateCall), true, true); + new SimulateV1Request.SimulateV1Params(List.of(blockStateCall), true, true, true); // Specify the parent block number as the block parameter for simulation context final String blockParameter = "0x" + Long.toHexString(parentBlockNumber); diff --git a/services/rpc/client/src/main/java/net/consensys/shomei/rpc/client/model/SimulateV1Request.java b/services/rpc/client/src/main/java/net/consensys/shomei/rpc/client/model/SimulateV1Request.java index a28075cf..bab5c3f6 100644 --- a/services/rpc/client/src/main/java/net/consensys/shomei/rpc/client/model/SimulateV1Request.java +++ b/services/rpc/client/src/main/java/net/consensys/shomei/rpc/client/model/SimulateV1Request.java @@ -42,13 +42,18 @@ public static class SimulateV1Params { @JsonProperty("returnTrieLog") private final boolean returnTrieLog; + @JsonProperty("traceBlockImport") + private final boolean traceBlockImport; + public SimulateV1Params( final List blockStateCalls, final boolean validation, - final boolean returnTrieLog) { + final boolean returnTrieLog, + final boolean traceBlockImport) { this.blockStateCalls = blockStateCalls; this.validation = validation; this.returnTrieLog = returnTrieLog; + this.traceBlockImport = traceBlockImport; } public List getBlockStateCalls() { @@ -62,6 +67,10 @@ public boolean isValidation() { public boolean isReturnTrieLog() { return returnTrieLog; } + + public boolean isTraceBlockImport() { + return traceBlockImport; + } } public static class BlockStateCall {