Search in sources :

Example 1 with OverflowException

use of org.hyperledger.besu.evm.internal.FixedStack.OverflowException in project hedera-services by hashgraph.

the class HederaSLoadOperation method execute.

@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
    try {
        final Account account = frame.getWorldUpdater().get(frame.getRecipientAddress());
        final Address address = account.getAddress();
        final Bytes32 key = UInt256.fromBytes(frame.popStackItem());
        final boolean slotIsWarm = frame.warmUpStorage(address, key);
        final Optional<Gas> optionalCost = slotIsWarm ? warmCost : coldCost;
        if (frame.getRemainingGas().compareTo(optionalCost.orElse(Gas.ZERO)) < 0) {
            return new OperationResult(optionalCost, Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
        } else {
            UInt256 storageValue = account.getStorageValue(UInt256.fromBytes(key));
            if (dynamicProperties.shouldEnableTraceability()) {
                HederaOperationUtil.cacheExistingValue(frame, address, key, storageValue);
            }
            frame.pushStackItem(storageValue);
            return slotIsWarm ? warmSuccess : coldSuccess;
        }
    } catch (final UnderflowException ufe) {
        return new OperationResult(warmCost, Optional.of(ExceptionalHaltReason.INSUFFICIENT_STACK_ITEMS));
    } catch (final OverflowException ofe) {
        return new OperationResult(warmCost, Optional.of(ExceptionalHaltReason.TOO_MANY_STACK_ITEMS));
    }
}
Also used : Account(org.hyperledger.besu.evm.account.Account) Address(org.hyperledger.besu.datatypes.Address) Gas(org.hyperledger.besu.evm.Gas) UnderflowException(org.hyperledger.besu.evm.internal.FixedStack.UnderflowException) OverflowException(org.hyperledger.besu.evm.internal.FixedStack.OverflowException) Bytes32(org.apache.tuweni.bytes.Bytes32) UInt256(org.apache.tuweni.units.bigints.UInt256)

Example 2 with OverflowException

use of org.hyperledger.besu.evm.internal.FixedStack.OverflowException 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 3 with OverflowException

use of org.hyperledger.besu.evm.internal.FixedStack.OverflowException in project besu by hyperledger.

the class SLoadOperation method execute.

@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
    try {
        final Account account = frame.getWorldUpdater().get(frame.getRecipientAddress());
        final Address address = account.getAddress();
        final Bytes32 key = UInt256.fromBytes(frame.popStackItem());
        final boolean slotIsWarm = frame.warmUpStorage(address, key);
        final OptionalLong cost = slotIsWarm ? warmCost : coldCost;
        if (frame.getRemainingGas() < cost.orElse(0L)) {
            return new OperationResult(cost, Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
        } else {
            frame.pushStackItem(account.getStorageValue(UInt256.fromBytes(key)));
            return slotIsWarm ? warmSuccess : coldSuccess;
        }
    } catch (final UnderflowException ufe) {
        return new OperationResult(warmCost, Optional.of(ExceptionalHaltReason.INSUFFICIENT_STACK_ITEMS));
    } catch (final OverflowException ofe) {
        return new OperationResult(warmCost, Optional.of(ExceptionalHaltReason.TOO_MANY_STACK_ITEMS));
    }
}
Also used : Account(org.hyperledger.besu.evm.account.Account) Address(org.hyperledger.besu.datatypes.Address) OptionalLong(java.util.OptionalLong) UnderflowException(org.hyperledger.besu.evm.internal.FixedStack.UnderflowException) OverflowException(org.hyperledger.besu.evm.internal.FixedStack.OverflowException) Bytes32(org.apache.tuweni.bytes.Bytes32)

Example 4 with OverflowException

use of org.hyperledger.besu.evm.internal.FixedStack.OverflowException in project besu by hyperledger.

the class BalanceOperation method execute.

@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
    try {
        final Address address = Words.toAddress(frame.popStackItem());
        final boolean accountIsWarm = frame.warmUpAddress(address) || gasCalculator().isPrecompile(address);
        final long cost = cost(accountIsWarm);
        if (frame.getRemainingGas() < cost) {
            return new OperationResult(OptionalLong.of(cost), Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
        } else {
            final Account account = frame.getWorldUpdater().get(address);
            frame.pushStackItem(account == null ? UInt256.ZERO : account.getBalance());
            return new OperationResult(OptionalLong.of(cost), Optional.empty());
        }
    } catch (final UnderflowException ufe) {
        return new OperationResult(OptionalLong.of(cost(true)), Optional.of(ExceptionalHaltReason.INSUFFICIENT_STACK_ITEMS));
    } catch (final OverflowException ofe) {
        return new OperationResult(OptionalLong.of(cost(true)), Optional.of(ExceptionalHaltReason.TOO_MANY_STACK_ITEMS));
    }
}
Also used : Account(org.hyperledger.besu.evm.account.Account) Address(org.hyperledger.besu.datatypes.Address) UnderflowException(org.hyperledger.besu.evm.internal.FixedStack.UnderflowException) OverflowException(org.hyperledger.besu.evm.internal.FixedStack.OverflowException)

Example 5 with OverflowException

use of org.hyperledger.besu.evm.internal.FixedStack.OverflowException in project besu by hyperledger.

the class ExtCodeHashOperation method execute.

@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
    try {
        final Address address = Words.toAddress(frame.popStackItem());
        final boolean accountIsWarm = frame.warmUpAddress(address) || gasCalculator().isPrecompile(address);
        final long cost = cost(accountIsWarm);
        if (frame.getRemainingGas() < cost) {
            return new OperationResult(OptionalLong.of(cost), Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
        } else {
            final Account account = frame.getWorldUpdater().get(address);
            if (account == null || account.isEmpty()) {
                frame.pushStackItem(UInt256.ZERO);
            } else {
                frame.pushStackItem(UInt256.fromBytes(account.getCodeHash()));
            }
            return new OperationResult(OptionalLong.of(cost), Optional.empty());
        }
    } catch (final UnderflowException ufe) {
        return new OperationResult(OptionalLong.of(cost(true)), Optional.of(ExceptionalHaltReason.INSUFFICIENT_STACK_ITEMS));
    } catch (final OverflowException ofe) {
        return new OperationResult(OptionalLong.of(cost(true)), Optional.of(ExceptionalHaltReason.TOO_MANY_STACK_ITEMS));
    }
}
Also used : Account(org.hyperledger.besu.evm.account.Account) Address(org.hyperledger.besu.datatypes.Address) UnderflowException(org.hyperledger.besu.evm.internal.FixedStack.UnderflowException) OverflowException(org.hyperledger.besu.evm.internal.FixedStack.OverflowException)

Aggregations

OverflowException (org.hyperledger.besu.evm.internal.FixedStack.OverflowException)6 UnderflowException (org.hyperledger.besu.evm.internal.FixedStack.UnderflowException)6 Address (org.hyperledger.besu.datatypes.Address)5 Account (org.hyperledger.besu.evm.account.Account)5 Bytes32 (org.apache.tuweni.bytes.Bytes32)2 OptionalLong (java.util.OptionalLong)1 UInt256 (org.apache.tuweni.units.bigints.UInt256)1 Gas (org.hyperledger.besu.evm.Gas)1 ExceptionalHaltReason (org.hyperledger.besu.evm.frame.ExceptionalHaltReason)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