Precompile calls were not traced when insuficient gas (#7462)

* Precompile calls were not traced when insuficient gas

Signed-off-by: Luis Pinto <luis.pinto@consensys.net>

* fixup! Precompile calls were not traced when insuficient gas

 revert RuntimeException in StateDiffGenerator

Signed-off-by: Luis Pinto <luis.pinto@consensys.net>

---------

Signed-off-by: Luis Pinto <luis.pinto@consensys.net>
pull/7473/head
Luis Pinto 3 months ago committed by GitHub
parent adf19afb1a
commit b99cdf6273
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 1
      evm/src/main/java/org/hyperledger/besu/evm/processor/MessageCallProcessor.java
  3. 66
      evm/src/test/java/org/hyperledger/besu/evm/processor/MessageCallProcessorTest.java

@ -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

@ -153,6 +153,7 @@ public class MessageCallProcessor extends AbstractMessageProcessor {
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 =

@ -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<MessageCallP
@Mock EVM evm;
@Mock PrecompileContractRegistry precompileContractRegistry;
@Mock PrecompiledContract contract;
@Override
protected MessageCallProcessor getAbstractMessageProcessor() {
return new MessageCallProcessor(evm, precompileContractRegistry);
}
@Test
public void shouldTracePrecompileContractCall() {
Address sender = Address.ZERO;
Address recipient = Address.fromHexString("0x1");
ToyWorld toyWorld = new ToyWorld();
toyWorld.createAccount(sender);
toyWorld.createAccount(recipient);
final MessageFrame messageFrame =
new TestMessageFrameBuilder()
.worldUpdater(toyWorld)
.sender(sender)
.address(recipient)
.initialGas(20L)
.build();
when(precompileContractRegistry.get(any())).thenReturn(contract);
when(contract.gasRequirement(any())).thenReturn(10L);
when(contract.computePrecompile(any(), eq(messageFrame)))
.thenReturn(PrecompiledContract.PrecompileContractResult.success(any()));
getAbstractMessageProcessor().process(messageFrame, operationTracer);
verify(operationTracer, times(1)).tracePrecompileCall(eq(messageFrame), anyLong(), any());
}
@Test
public void shouldTracePrecompileContractCallOutOfGas() {
Address sender = Address.ZERO;
Address recipient = Address.fromHexString("0x1");
ToyWorld toyWorld = new ToyWorld();
toyWorld.createAccount(sender);
toyWorld.createAccount(recipient);
final MessageFrame messageFrame =
new TestMessageFrameBuilder()
.worldUpdater(toyWorld)
.sender(sender)
.address(recipient)
.initialGas(5L)
.build();
when(precompileContractRegistry.get(any())).thenReturn(contract);
when(contract.gasRequirement(any())).thenReturn(10L);
getAbstractMessageProcessor().process(messageFrame, operationTracer);
verify(operationTracer, times(1)).tracePrecompileCall(eq(messageFrame), anyLong(), any());
}
}

Loading…
Cancel
Save