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();
}
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);
}
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);
}
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();
}
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));
}
Aggregations