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