From b99cdf627378ad4da646c105b24025ba0006e9c4 Mon Sep 17 00:00:00 2001 From: Luis Pinto Date: Wed, 14 Aug 2024 16:54:13 +0000 Subject: [PATCH] Precompile calls were not traced when insuficient gas (#7462) * Precompile calls were not traced when insuficient gas Signed-off-by: Luis Pinto * fixup! Precompile calls were not traced when insuficient gas revert RuntimeException in StateDiffGenerator Signed-off-by: Luis Pinto --------- Signed-off-by: Luis Pinto --- CHANGELOG.md | 1 + .../evm/processor/MessageCallProcessor.java | 1 + .../processor/MessageCallProcessorTest.java | 66 +++++++++++++++++++ 3 files changed, 68 insertions(+) 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/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