Search in sources :

Example 1 with Address

use of org.hyperledger.besu.datatypes.Address in project hedera-services by hashgraph.

the class AbstractRecordingCreateOperation method execute.

@Override
public Operation.OperationResult execute(final MessageFrame frame, final EVM evm) {
    // We have a feature flag for CREATE2
    if (!isEnabled()) {
        return INVALID_RESPONSE;
    }
    // manual check because some reads won't come until the "complete" step.
    if (frame.stackSize() < getStackItemsConsumed()) {
        return UNDERFLOW_RESPONSE;
    }
    final Gas cost = cost(frame);
    final Optional<Gas> optionalCost = Optional.ofNullable(cost);
    if (cost != null) {
        if (frame.isStatic()) {
            return haltWith(optionalCost, ILLEGAL_STATE_CHANGE);
        } else if (frame.getRemainingGas().compareTo(cost) < 0) {
            return new Operation.OperationResult(optionalCost, Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
        }
        final Wei value = Wei.wrap(frame.getStackItem(0));
        final Address address = frame.getRecipientAddress();
        final MutableAccount account = frame.getWorldUpdater().getAccount(address).getMutable();
        frame.clearReturnData();
        if (value.compareTo(account.getBalance()) > 0 || frame.getMessageStackDepth() >= MAX_STACK_DEPTH) {
            fail(frame);
        } else {
            spawnChildMessage(frame);
        }
    }
    return new Operation.OperationResult(optionalCost, Optional.empty());
}
Also used : Address(org.hyperledger.besu.datatypes.Address) Gas(org.hyperledger.besu.evm.Gas) Wei(org.hyperledger.besu.datatypes.Wei) MutableAccount(org.hyperledger.besu.evm.account.MutableAccount) AbstractOperation(org.hyperledger.besu.evm.operation.AbstractOperation) Operation(org.hyperledger.besu.evm.operation.Operation)

Example 2 with Address

use of org.hyperledger.besu.datatypes.Address in project hedera-services by hashgraph.

the class AbstractRecordingCreateOperation method spawnChildMessage.

private void spawnChildMessage(final MessageFrame frame) {
    // memory cost needs to be calculated prior to memory expansion
    final Gas cost = cost(frame);
    frame.decrementRemainingGas(cost);
    final Address address = frame.getRecipientAddress();
    final MutableAccount account = frame.getWorldUpdater().getAccount(address).getMutable();
    account.incrementNonce();
    final Wei value = Wei.wrap(frame.getStackItem(0));
    final long inputOffset = clampedToLong(frame.getStackItem(1));
    final long inputSize = clampedToLong(frame.getStackItem(2));
    final Bytes inputData = frame.readMemory(inputOffset, inputSize);
    final Address contractAddress = targetContractAddress(frame);
    final Gas childGasStipend = gasCalculator().gasAvailableForChildCreate(frame.getRemainingGas());
    frame.decrementRemainingGas(childGasStipend);
    final MessageFrame childFrame = MessageFrame.builder().type(MessageFrame.Type.CONTRACT_CREATION).messageFrameStack(frame.getMessageFrameStack()).worldUpdater(frame.getWorldUpdater().updater()).initialGas(childGasStipend).address(contractAddress).originator(frame.getOriginatorAddress()).contract(contractAddress).gasPrice(frame.getGasPrice()).inputData(Bytes.EMPTY).sender(frame.getRecipientAddress()).value(value).apparentValue(value).code(new Code(inputData, Hash.EMPTY)).blockValues(frame.getBlockValues()).depth(frame.getMessageStackDepth() + 1).completer(child -> complete(frame, child)).miningBeneficiary(frame.getMiningBeneficiary()).blockHashLookup(frame.getBlockHashLookup()).maxStackSize(frame.getMaxStackSize()).build();
    frame.incrementRemainingGas(cost);
    frame.getMessageFrameStack().addFirst(childFrame);
    frame.setState(MessageFrame.State.CODE_SUSPENDED);
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Address(org.hyperledger.besu.datatypes.Address) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) Gas(org.hyperledger.besu.evm.Gas) MutableAccount(org.hyperledger.besu.evm.account.MutableAccount) Wei(org.hyperledger.besu.datatypes.Wei) Code(org.hyperledger.besu.evm.Code)

Example 3 with Address

use of org.hyperledger.besu.datatypes.Address in project hedera-services by hashgraph.

the class HederaCreate2Operation method targetContractAddress.

@Override
protected Address targetContractAddress(final MessageFrame frame) {
    final var sourceAddressOrAlias = frame.getRecipientAddress();
    final var offset = clampedToLong(frame.getStackItem(1));
    final var length = clampedToLong(frame.getStackItem(2));
    final var updater = (HederaStackedWorldStateUpdater) frame.getWorldUpdater();
    final var source = updater.priorityAddress(sourceAddressOrAlias);
    final Bytes32 salt = UInt256.fromBytes(frame.getStackItem(3));
    final var initCode = frame.readMutableMemory(offset, length);
    final var hash = keccak256(Bytes.concatenate(PREFIX, source, salt, keccak256(initCode)));
    final var alias = Address.wrap(hash.slice(12, 20));
    final Address address = updater.newAliasedContractAddress(sourceAddressOrAlias, alias);
    frame.warmUpAddress(address);
    frame.warmUpAddress(alias);
    return alias;
}
Also used : Address(org.hyperledger.besu.datatypes.Address) HederaStackedWorldStateUpdater(com.hedera.services.store.contracts.HederaStackedWorldStateUpdater) Bytes32(org.apache.tuweni.bytes.Bytes32)

Example 4 with Address

use of org.hyperledger.besu.datatypes.Address in project hedera-services by hashgraph.

the class HederaCreateOperation method targetContractAddress.

@Override
protected Address targetContractAddress(final MessageFrame frame) {
    final var updater = (HederaWorldUpdater) frame.getWorldUpdater();
    final Address address = updater.newContractAddress(frame.getRecipientAddress());
    frame.warmUpAddress(address);
    return address;
}
Also used : Address(org.hyperledger.besu.datatypes.Address) HederaWorldUpdater(com.hedera.services.store.contracts.HederaWorldUpdater)

Example 5 with Address

use of org.hyperledger.besu.datatypes.Address in project hedera-services by hashgraph.

the class HederaExtCodeHashOperation method execute.

@Override
public OperationResult execute(MessageFrame frame, EVM evm) {
    try {
        final Address address = Words.toAddress(frame.popStackItem());
        if (!addressValidator.test(address, frame)) {
            return new OperationResult(Optional.of(cost(true)), Optional.of(HederaExceptionalHaltReason.INVALID_SOLIDITY_ADDRESS));
        }
        final var account = frame.getWorldUpdater().get(address);
        boolean accountIsWarm = frame.warmUpAddress(address) || this.gasCalculator().isPrecompile(address);
        Optional<Gas> optionalCost = Optional.of(this.cost(accountIsWarm));
        if (frame.getRemainingGas().compareTo(optionalCost.get()) < 0) {
            return new OperationResult(optionalCost, Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
        } else {
            if (!account.isEmpty()) {
                frame.pushStackItem(UInt256.fromBytes(account.getCodeHash()));
            } else {
                frame.pushStackItem(UInt256.ZERO);
            }
            return new OperationResult(optionalCost, Optional.empty());
        }
    } catch (final FixedStack.UnderflowException ufe) {
        return new OperationResult(Optional.of(cost(true)), Optional.of(ExceptionalHaltReason.INSUFFICIENT_STACK_ITEMS));
    }
}
Also used : FixedStack(org.hyperledger.besu.evm.internal.FixedStack) Address(org.hyperledger.besu.datatypes.Address) Gas(org.hyperledger.besu.evm.Gas)

Aggregations

Address (org.hyperledger.besu.datatypes.Address)408 Test (org.junit.Test)230 Bytes (org.apache.tuweni.bytes.Bytes)94 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)87 Hash (org.hyperledger.besu.datatypes.Hash)43 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)43 NodeKey (org.hyperledger.besu.crypto.NodeKey)42 ArrayList (java.util.ArrayList)41 SECPSignature (org.hyperledger.besu.crypto.SECPSignature)39 List (java.util.List)38 ProtocolContext (org.hyperledger.besu.ethereum.ProtocolContext)38 Wei (org.hyperledger.besu.datatypes.Wei)36 BftExtraData (org.hyperledger.besu.consensus.common.bft.BftExtraData)31 BlockHeaderValidator (org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator)29 Optional (java.util.Optional)25 BytesValueRLPOutput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput)25 Account (org.hyperledger.besu.evm.account.Account)25 ValidatorProvider (org.hyperledger.besu.consensus.common.validator.ValidatorProvider)24 JsonRpcResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse)24 Log (org.hyperledger.besu.evm.log.Log)24