Search in sources :

Example 26 with Account

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));
}
Also used : Account(org.hyperledger.besu.evm.account.Account)

Example 27 with Account

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());
}
Also used : Account(org.hyperledger.besu.evm.account.Account) Bytes(org.apache.tuweni.bytes.Bytes) Address(org.hyperledger.besu.datatypes.Address)

Example 28 with Account

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));
    }
}
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 29 with Account

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()));
}
Also used : TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions) TransactionTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace) Account(org.hyperledger.besu.evm.account.Account) JsonRpcError(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError) BlockchainQueries(org.hyperledger.besu.ethereum.api.query.BlockchainQueries) ImmutableDebugAccountAtResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.ImmutableDebugAccountAtResult) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse) DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) Bytes(org.apache.tuweni.bytes.Bytes) Address(org.hyperledger.besu.datatypes.Address) Supplier(java.util.function.Supplier) Quantity(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity) Objects(java.util.Objects) List(java.util.List) RpcMethod(org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod) BlockWithMetadata(org.hyperledger.besu.ethereum.api.query.BlockWithMetadata) TransactionWithMetadata(org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) BlockParameterOrBlockHash(org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameterOrBlockHash) BlockTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace) Optional(java.util.Optional) Collections(java.util.Collections) Hash(org.hyperledger.besu.datatypes.Hash) BlockTracer(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTracer) Account(org.hyperledger.besu.evm.account.Account) Address(org.hyperledger.besu.datatypes.Address) DebugOperationTracer(org.hyperledger.besu.ethereum.vm.DebugOperationTracer) BlockWithMetadata(org.hyperledger.besu.ethereum.api.query.BlockWithMetadata) TransactionWithMetadata(org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata) TransactionTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.TransactionTrace) Objects(java.util.Objects) TraceOptions(org.hyperledger.besu.ethereum.debug.TraceOptions) BlockTrace(org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockTrace) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Example 30 with Account

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));
}
Also used : Account(org.hyperledger.besu.evm.account.Account) DebugStorageRangeAtResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.DebugStorageRangeAtResult) AccountStorageEntry(org.hyperledger.besu.evm.account.AccountStorageEntry) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Bytes32(org.apache.tuweni.bytes.Bytes32)

Aggregations

Account (org.hyperledger.besu.evm.account.Account)56 Address (org.hyperledger.besu.datatypes.Address)24 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)19 Hash (org.hyperledger.besu.datatypes.Hash)18 Bytes (org.apache.tuweni.bytes.Bytes)15 Bytes32 (org.apache.tuweni.bytes.Bytes32)14 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)14 Test (org.junit.Test)13 Optional (java.util.Optional)12 WorldState (org.hyperledger.besu.evm.worldstate.WorldState)12 Map (java.util.Map)11 Wei (org.hyperledger.besu.datatypes.Wei)10 Blockchain (org.hyperledger.besu.ethereum.chain.Blockchain)10 WorldUpdater (org.hyperledger.besu.evm.worldstate.WorldUpdater)10 Transaction (org.hyperledger.besu.ethereum.core.Transaction)9 WorldStateArchive (org.hyperledger.besu.ethereum.worldstate.WorldStateArchive)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 HashSet (java.util.HashSet)7 Set (java.util.Set)7