Search in sources :

Example 1 with ExceptionalHaltReason

use of org.hyperledger.besu.evm.frame.ExceptionalHaltReason in project besu by hyperledger.

the class EVM method executeNextOperation.

private void executeNextOperation(final MessageFrame frame, final OperationTracer operationTracer) {
    frame.setCurrentOperation(operationAtOffset(frame.getCode(), frame.getPC()));
    operationTracer.traceExecution(frame, () -> {
        OperationResult result;
        final Operation operation = frame.getCurrentOperation();
        try {
            result = operation.execute(frame, this);
        } catch (final OverflowException oe) {
            result = OVERFLOW_RESPONSE;
        } catch (final UnderflowException ue) {
            result = UNDERFLOW_RESPONSE;
        }
        logState(frame, result.getGasCost().orElse(0L));
        final Optional<ExceptionalHaltReason> haltReason = result.getHaltReason();
        if (haltReason.isPresent()) {
            LOG.trace("MessageFrame evaluation halted because of {}", haltReason.get());
            frame.setExceptionalHaltReason(haltReason);
            frame.setState(State.EXCEPTIONAL_HALT);
        } else if (result.getGasCost().isPresent()) {
            frame.decrementRemainingGas(result.getGasCost().getAsLong());
        }
        if (frame.getState() == State.CODE_EXECUTING) {
            final int currentPC = frame.getPC();
            final int opSize = result.getPcIncrement();
            frame.setPC(currentPC + opSize);
        }
        return result;
    });
}
Also used : OperationResult(org.hyperledger.besu.evm.operation.Operation.OperationResult) ExceptionalHaltReason(org.hyperledger.besu.evm.frame.ExceptionalHaltReason) 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) UnderflowException(org.hyperledger.besu.evm.internal.FixedStack.UnderflowException) OverflowException(org.hyperledger.besu.evm.internal.FixedStack.OverflowException)

Example 2 with ExceptionalHaltReason

use of org.hyperledger.besu.evm.frame.ExceptionalHaltReason in project besu by hyperledger.

the class ContractCreationProcessor method codeSuccess.

@Override
public void codeSuccess(final MessageFrame frame, final OperationTracer operationTracer) {
    final Bytes contractCode = frame.getOutputData();
    final long depositFee = gasCalculator.codeDepositGasCost(contractCode.size());
    if (frame.getRemainingGas() < depositFee) {
        LOG.trace("Not enough gas to pay the code deposit fee for {}: " + "remaining gas = {} < {} = deposit fee", frame.getContractAddress(), frame.getRemainingGas(), depositFee);
        if (requireCodeDepositToSucceed) {
            LOG.trace("Contract creation error: insufficient funds for code deposit");
            frame.setExceptionalHaltReason(Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
            frame.setState(MessageFrame.State.EXCEPTIONAL_HALT);
            operationTracer.traceAccountCreationResult(frame, Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
        } else {
            frame.setState(MessageFrame.State.COMPLETED_SUCCESS);
        }
    } else {
        final var invalidReason = contractValidationRules.stream().map(rule -> rule.validate(frame)).filter(Optional::isPresent).findFirst();
        if (invalidReason.isEmpty()) {
            frame.decrementRemainingGas(depositFee);
            // Finalize contract creation, setting the contract code.
            final MutableAccount contract = frame.getWorldUpdater().getOrCreate(frame.getContractAddress()).getMutable();
            contract.setCode(contractCode);
            LOG.trace("Successful creation of contract {} with code of size {} (Gas remaining: {})", frame.getContractAddress(), contractCode.size(), frame.getRemainingGas());
            frame.setState(MessageFrame.State.COMPLETED_SUCCESS);
        } else {
            final Optional<ExceptionalHaltReason> exceptionalHaltReason = invalidReason.get();
            frame.setExceptionalHaltReason(exceptionalHaltReason);
            frame.setState(MessageFrame.State.EXCEPTIONAL_HALT);
            operationTracer.traceAccountCreationResult(frame, exceptionalHaltReason);
        }
    }
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) MutableAccount(org.hyperledger.besu.evm.account.MutableAccount) ExceptionalHaltReason(org.hyperledger.besu.evm.frame.ExceptionalHaltReason)

Aggregations

ExceptionalHaltReason (org.hyperledger.besu.evm.frame.ExceptionalHaltReason)2 Bytes (org.apache.tuweni.bytes.Bytes)1 MutableAccount (org.hyperledger.besu.evm.account.MutableAccount)1 OverflowException (org.hyperledger.besu.evm.internal.FixedStack.OverflowException)1 UnderflowException (org.hyperledger.besu.evm.internal.FixedStack.UnderflowException)1 InvalidOperation (org.hyperledger.besu.evm.operation.InvalidOperation)1 Operation (org.hyperledger.besu.evm.operation.Operation)1 OperationResult (org.hyperledger.besu.evm.operation.Operation.OperationResult)1 StopOperation (org.hyperledger.besu.evm.operation.StopOperation)1 VirtualOperation (org.hyperledger.besu.evm.operation.VirtualOperation)1