Search in sources :

Example 1 with HederaStackedWorldStateUpdater

use of com.hedera.services.store.contracts.HederaStackedWorldStateUpdater 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 2 with HederaStackedWorldStateUpdater

use of com.hedera.services.store.contracts.HederaStackedWorldStateUpdater in project hedera-services by hashgraph.

the class HederaLogOperation method execute.

@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
    final long dataLocation = clampedToLong(frame.popStackItem());
    final long numBytes = clampedToLong(frame.popStackItem());
    final Gas cost = gasCalculator().logOperationGasCost(frame, dataLocation, numBytes, numTopics);
    final Optional<Gas> optionalCost = Optional.of(cost);
    if (frame.isStatic()) {
        return new OperationResult(optionalCost, Optional.of(ExceptionalHaltReason.ILLEGAL_STATE_CHANGE));
    } else if (frame.getRemainingGas().compareTo(cost) < 0) {
        return new OperationResult(optionalCost, Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
    }
    final var addressOrAlias = frame.getRecipientAddress();
    final var updater = (HederaStackedWorldStateUpdater) frame.getWorldUpdater();
    final var aliases = updater.aliases();
    var address = aliases.resolveForEvm(addressOrAlias);
    if (!aliases.isMirror(address)) {
        address = UNRESOLVABLE_ADDRESS_STANDIN;
        log.warn("Could not resolve logger address {}", addressOrAlias);
    }
    final Bytes data = frame.readMemory(dataLocation, numBytes);
    final ImmutableList.Builder<LogTopic> builder = ImmutableList.builderWithExpectedSize(numTopics);
    for (int i = 0; i < numTopics; i++) {
        builder.add(LogTopic.create(leftPad(frame.popStackItem())));
    }
    frame.addLog(new Log(address, data, builder.build()));
    return new OperationResult(optionalCost, Optional.empty());
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Log(org.hyperledger.besu.evm.log.Log) ImmutableList(com.google.common.collect.ImmutableList) HederaStackedWorldStateUpdater(com.hedera.services.store.contracts.HederaStackedWorldStateUpdater) Gas(org.hyperledger.besu.evm.Gas) LogTopic(org.hyperledger.besu.evm.log.LogTopic)

Aggregations

HederaStackedWorldStateUpdater (com.hedera.services.store.contracts.HederaStackedWorldStateUpdater)2 ImmutableList (com.google.common.collect.ImmutableList)1 Bytes (org.apache.tuweni.bytes.Bytes)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 Address (org.hyperledger.besu.datatypes.Address)1 Gas (org.hyperledger.besu.evm.Gas)1 Log (org.hyperledger.besu.evm.log.Log)1 LogTopic (org.hyperledger.besu.evm.log.LogTopic)1