Search in sources :

Example 1 with Operation

use of org.hyperledger.besu.evm.operation.Operation in project besu by hyperledger.

the class EVMTest method assertThatEndOfScriptNotExplicitlySetInCodeReturnsAVirtualOperation.

@Test
public void assertThatEndOfScriptNotExplicitlySetInCodeReturnsAVirtualOperation() {
    final Bytes noEnd = Bytes.fromHexString("0x60203560003555606035604035556000");
    final Code code = Code.createLegacyCode(noEnd, Hash.hash(noEnd));
    final Operation operation = evm.operationAtOffset(code, code.getSize());
    assertThat(operation).isNotNull();
    assertThat(operation.isVirtualOperation()).isTrue();
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Operation(org.hyperledger.besu.evm.operation.Operation) StopOperation(org.hyperledger.besu.evm.operation.StopOperation) Code(org.hyperledger.besu.evm.Code) Test(org.junit.Test)

Example 2 with Operation

use of org.hyperledger.besu.evm.operation.Operation in project besu by hyperledger.

the class BaseFeeOperationTest method shouldReturnGasCost.

@Test
public void shouldReturnGasCost() {
    final MessageFrame frame = createMessageFrame(100, Optional.of(Wei.of(5L)));
    final Operation operation = new BaseFeeOperation(gasCalculator);
    final OperationResult result = operation.execute(frame, null);
    assertThat(result.getGasCost().isPresent()).isTrue();
    assertThat(result.getGasCost().getAsLong()).isEqualTo(gasCalculator.getBaseTierGasCost());
    assertSuccessResult(result);
}
Also used : MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) BaseFeeOperation(org.hyperledger.besu.evm.operation.BaseFeeOperation) OperationResult(org.hyperledger.besu.evm.operation.Operation.OperationResult) Operation(org.hyperledger.besu.evm.operation.Operation) BaseFeeOperation(org.hyperledger.besu.evm.operation.BaseFeeOperation) Test(org.junit.Test)

Example 3 with Operation

use of org.hyperledger.besu.evm.operation.Operation in project besu by hyperledger.

the class BaseFeeOperationTest method shouldHaltIfNoBaseFeeInBlockHeader.

@Test
public void shouldHaltIfNoBaseFeeInBlockHeader() {
    final MessageFrame frame = createMessageFrame(100, Optional.empty());
    final Operation operation = new BaseFeeOperation(gasCalculator);
    final OperationResult result = operation.execute(frame, null);
    assertExceptionalHalt(result, ExceptionalHaltReason.INVALID_OPERATION);
}
Also used : MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) BaseFeeOperation(org.hyperledger.besu.evm.operation.BaseFeeOperation) OperationResult(org.hyperledger.besu.evm.operation.Operation.OperationResult) Operation(org.hyperledger.besu.evm.operation.Operation) BaseFeeOperation(org.hyperledger.besu.evm.operation.BaseFeeOperation) Test(org.junit.Test)

Example 4 with Operation

use of org.hyperledger.besu.evm.operation.Operation in project besu by hyperledger.

the class DebugOperationTracer method traceExecution.

@Override
public void traceExecution(final MessageFrame frame, final ExecuteOperation executeOperation) {
    final Operation currentOperation = frame.getCurrentOperation();
    final int depth = frame.getMessageStackDepth();
    final String opcode = currentOperation.getName();
    final int pc = frame.getPC();
    final long gasRemaining = frame.getRemainingGas();
    final Bytes inputData = frame.getInputData();
    final Optional<Bytes32[]> stack = captureStack(frame);
    final WorldUpdater worldUpdater = frame.getWorldUpdater();
    final Optional<Bytes32[]> stackPostExecution;
    final Operation.OperationResult operationResult = executeOperation.execute();
    final Bytes outputData = frame.getOutputData();
    final Optional<Bytes[]> memory = captureMemory(frame);
    stackPostExecution = captureStack(frame);
    if (lastFrame != null) {
        lastFrame.setGasRemainingPostExecution(gasRemaining);
    }
    final Optional<Map<UInt256, UInt256>> storage = captureStorage(frame);
    final Optional<Map<Address, Wei>> maybeRefunds = frame.getRefunds().isEmpty() ? Optional.empty() : Optional.of(frame.getRefunds());
    lastFrame = new TraceFrame(pc, Optional.of(opcode), gasRemaining, operationResult.getGasCost(), frame.getGasRefund(), depth, operationResult.getHaltReason(), frame.getRecipientAddress(), frame.getApparentValue(), pc == 0 ? inputData.copy() : inputData, outputData, stack, memory, storage, worldUpdater, frame.getRevertReason(), maybeRefunds, Optional.ofNullable(frame.getMessageFrameStack().peek()).map(MessageFrame::getCode), frame.getCurrentOperation().getStackItemsProduced(), stackPostExecution, currentOperation.isVirtualOperation(), frame.getMaybeUpdatedMemory(), frame.getMaybeUpdatedStorage());
    traceFrames.add(lastFrame);
    frame.reset();
}
Also used : WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) Operation(org.hyperledger.besu.evm.operation.Operation) Bytes(org.apache.tuweni.bytes.Bytes) TreeMap(java.util.TreeMap) Map(java.util.Map) TraceFrame(org.hyperledger.besu.ethereum.debug.TraceFrame)

Example 5 with Operation

use of org.hyperledger.besu.evm.operation.Operation in project besu by hyperledger.

the class EVM method operationAtOffset.

@VisibleForTesting
public Operation operationAtOffset(final Code code, final int offset) {
    final Bytes bytecode = code.getBytes();
    // If the length of the program code is shorter than the offset halt execution.
    if (offset >= bytecode.size()) {
        return endOfScriptStop;
    }
    final byte opcode = bytecode.get(offset);
    final Operation operation = operations.get(opcode);
    return Objects.requireNonNullElseGet(operation, () -> new InvalidOperation(opcode, null));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Operation(org.hyperledger.besu.evm.operation.Operation) InvalidOperation(org.hyperledger.besu.evm.operation.InvalidOperation) VirtualOperation(org.hyperledger.besu.evm.operation.VirtualOperation) StopOperation(org.hyperledger.besu.evm.operation.StopOperation) InvalidOperation(org.hyperledger.besu.evm.operation.InvalidOperation) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

Operation (org.hyperledger.besu.evm.operation.Operation)9 Bytes (org.apache.tuweni.bytes.Bytes)5 Test (org.junit.Test)5 MessageFrame (org.hyperledger.besu.evm.frame.MessageFrame)4 OperationResult (org.hyperledger.besu.evm.operation.Operation.OperationResult)4 StopOperation (org.hyperledger.besu.evm.operation.StopOperation)4 BaseFeeOperation (org.hyperledger.besu.evm.operation.BaseFeeOperation)3 Code (org.hyperledger.besu.evm.Code)2 InvalidOperation (org.hyperledger.besu.evm.operation.InvalidOperation)2 VirtualOperation (org.hyperledger.besu.evm.operation.VirtualOperation)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 TraceFrame (org.hyperledger.besu.ethereum.debug.TraceFrame)1 ExceptionalHaltReason (org.hyperledger.besu.evm.frame.ExceptionalHaltReason)1 OverflowException (org.hyperledger.besu.evm.internal.FixedStack.OverflowException)1 UnderflowException (org.hyperledger.besu.evm.internal.FixedStack.UnderflowException)1 WorldUpdater (org.hyperledger.besu.evm.worldstate.WorldUpdater)1