From 98c472ea5e48610aedac647e426ff3bc75867e17 Mon Sep 17 00:00:00 2001 From: Luis Pinto Date: Tue, 13 Aug 2024 22:55:35 +0100 Subject: [PATCH 1/2] Precompile calls were not traced when insuficient gas Signed-off-by: Luis Pinto --- CHANGELOG.md | 1 + .../tracing/diff/StateDiffGenerator.java | 2 +- .../evm/processor/MessageCallProcessor.java | 1 + .../processor/MessageCallProcessorTest.java | 66 +++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d30381a921..8a162840153 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Correct entrypoint in Docker evmtool [#7430](https://github.com/hyperledger/besu/pull/7430) - Fix protocol schedule check for devnets [#7429](https://github.com/hyperledger/besu/pull/7429) - Fix behaviour when starting in a pre-merge network [#7431](https://github.com/hyperledger/besu/pull/7431) +- Fix tracing in precompiled contracts when halting for out of gas [#7318](https://github.com/hyperledger/besu/issues/7318) ## 24.7.1 diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/diff/StateDiffGenerator.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/diff/StateDiffGenerator.java index 8656c8e0c1b..5e98075e64c 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/diff/StateDiffGenerator.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/diff/StateDiffGenerator.java @@ -38,7 +38,7 @@ public class StateDiffGenerator { public Stream generateStateDiff(final TransactionTrace transactionTrace) { final List traceFrames = transactionTrace.getTraceFrames(); if (traceFrames.isEmpty()) { - return Stream.empty(); + throw new RuntimeException("expected to have at least one processed frame"); } // This corresponds to the world state after the TX executed diff --git a/evm/src/main/java/org/hyperledger/besu/evm/processor/MessageCallProcessor.java b/evm/src/main/java/org/hyperledger/besu/evm/processor/MessageCallProcessor.java index 1963bba8a5c..e3ce69d74ab 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/processor/MessageCallProcessor.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/processor/MessageCallProcessor.java @@ -153,6 +153,7 @@ private void executePrecompile( if (frame.getRemainingGas() < gasRequirement) { frame.setExceptionalHaltReason(Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS)); frame.setState(MessageFrame.State.EXCEPTIONAL_HALT); + operationTracer.tracePrecompileCall(frame, gasRequirement, null); } else { frame.decrementRemainingGas(gasRequirement); final PrecompiledContract.PrecompileContractResult result = diff --git a/evm/src/test/java/org/hyperledger/besu/evm/processor/MessageCallProcessorTest.java b/evm/src/test/java/org/hyperledger/besu/evm/processor/MessageCallProcessorTest.java index c3f04c07c58..d17744c8580 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/processor/MessageCallProcessorTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/processor/MessageCallProcessorTest.java @@ -14,10 +14,23 @@ */ package org.hyperledger.besu.evm.processor; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.evm.EVM; +import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.precompile.PrecompileContractRegistry; +import org.hyperledger.besu.evm.precompile.PrecompiledContract; +import org.hyperledger.besu.evm.testutils.TestMessageFrameBuilder; +import org.hyperledger.besu.evm.toy.ToyWorld; import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -28,9 +41,62 @@ class MessageCallProcessorTest extends AbstractMessageProcessorTest Date: Wed, 14 Aug 2024 17:30:22 +0100 Subject: [PATCH 2/2] fixup! Precompile calls were not traced when insuficient gas revert RuntimeException in StateDiffGenerator Signed-off-by: Luis Pinto --- .../internal/results/tracing/diff/StateDiffGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/diff/StateDiffGenerator.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/diff/StateDiffGenerator.java index 5e98075e64c..8656c8e0c1b 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/diff/StateDiffGenerator.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/tracing/diff/StateDiffGenerator.java @@ -38,7 +38,7 @@ public class StateDiffGenerator { public Stream generateStateDiff(final TransactionTrace transactionTrace) { final List traceFrames = transactionTrace.getTraceFrames(); if (traceFrames.isEmpty()) { - throw new RuntimeException("expected to have at least one processed frame"); + return Stream.empty(); } // This corresponds to the world state after the TX executed