use of org.hyperledger.besu.evm.account.Account in project besu by hyperledger.
the class CallOperation method cost.
@Override
public long cost(final MessageFrame frame) {
final long stipend = gas(frame);
final long inputDataOffset = inputDataOffset(frame);
final long inputDataLength = inputDataLength(frame);
final long outputDataOffset = outputDataOffset(frame);
final long outputDataLength = outputDataLength(frame);
final Account recipient = frame.getWorldUpdater().get(address(frame));
return gasCalculator().callOperationGasCost(frame, stipend, inputDataOffset, inputDataLength, outputDataOffset, outputDataLength, value(frame), recipient, to(frame));
}
use of org.hyperledger.besu.evm.account.Account in project besu by hyperledger.
the class ExtCodeCopyOperation method execute.
@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
final Address address = Words.toAddress(frame.popStackItem());
final long memOffset = clampedToLong(frame.popStackItem());
final long sourceOffset = clampedToLong(frame.popStackItem());
final long numBytes = clampedToLong(frame.popStackItem());
final boolean accountIsWarm = frame.warmUpAddress(address) || gasCalculator().isPrecompile(address);
final long cost = cost(frame, memOffset, numBytes, accountIsWarm);
if (frame.getRemainingGas() < cost) {
return new OperationResult(OptionalLong.of(cost), Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
}
final Account account = frame.getWorldUpdater().get(address);
final Bytes code = account != null ? account.getCode() : Bytes.EMPTY;
frame.writeMemory(memOffset, sourceOffset, numBytes, code);
return new OperationResult(OptionalLong.of(cost), Optional.empty());
}
use of org.hyperledger.besu.evm.account.Account 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.account.Account in project besu by hyperledger.
the class DebugAccountAt method resultByBlockHash.
@Override
protected Object resultByBlockHash(final JsonRpcRequestContext requestContext, final Hash blockHash) {
final Integer txIndex = requestContext.getRequiredParameter(1, Integer.class);
final Address address = requestContext.getRequiredParameter(2, Address.class);
Optional<BlockWithMetadata<TransactionWithMetadata, Hash>> block = blockchainQueries.get().blockByHash(blockHash);
if (block.isEmpty()) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.BLOCK_NOT_FOUND);
}
List<TransactionWithMetadata> transactions = block.get().getTransactions();
if (transactions.isEmpty() || txIndex < 0 || txIndex > block.get().getTransactions().size()) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_PARAMS);
}
final Optional<TransactionTrace> transactionTrace = blockTracerSupplier.get().trace(blockHash, new DebugOperationTracer(new TraceOptions(false, true, true))).map(BlockTrace::getTransactionTraces).orElse(Collections.emptyList()).stream().filter(trxTrace -> trxTrace.getTransaction().getHash().equals(transactions.get(txIndex).getTransaction().getHash())).findFirst();
if (transactionTrace.isEmpty()) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.TRANSACTION_NOT_FOUND);
}
Optional<Account> account = transactionTrace.get().getTraceFrames().stream().map(traceFrame -> traceFrame.getWorldUpdater().get(address)).filter(Objects::nonNull).filter(a -> a.getAddress().equals(address)).findFirst();
if (account.isEmpty()) {
return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.NO_ACCOUNT_FOUND);
}
return debugAccountAtResult(account.get().getCode(), Quantity.create(account.get().getNonce()), Quantity.create(account.get().getBalance()), Quantity.create(account.get().getCodeHash()));
}
use of org.hyperledger.besu.evm.account.Account in project besu by hyperledger.
the class DebugStorageRangeAt method extractStorageAt.
private JsonRpcSuccessResponse extractStorageAt(final JsonRpcRequestContext requestContext, final Address accountAddress, final Hash startKey, final int limit, final WorldState worldState) {
final Account account = worldState.get(accountAddress);
final NavigableMap<Bytes32, AccountStorageEntry> entries = account.storageEntriesFrom(startKey, limit + 1);
Bytes32 nextKey = null;
if (entries.size() == limit + 1) {
nextKey = entries.lastKey();
entries.remove(nextKey);
}
return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), new DebugStorageRangeAtResult(entries, nextKey, shortValues));
}
Aggregations