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