Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package org.hyperledger.besu.evm.operation;

import static org.hyperledger.besu.evm.internal.Words.clampedToLong;
import static org.hyperledger.besu.evm.operation.AbstractCallOperation.LEGACY_FAILURE_STACK_ITEM;

import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
Expand Down Expand Up @@ -158,12 +157,18 @@ protected int getPcIncrement() {
*/
protected abstract Code getInitCode(MessageFrame frame, EVM evm);

private void fail(final MessageFrame frame) {
/**
* Handles stack items when operation fails for validation reasons (noe enough ether, bad eof
* code)
*
* @param frame the current execution frame
*/
protected void fail(final MessageFrame frame) {
final long inputOffset = clampedToLong(frame.getStackItem(1));
final long inputSize = clampedToLong(frame.getStackItem(2));
frame.readMutableMemory(inputOffset, inputSize);
frame.popStackItems(getStackItemsConsumed());
frame.pushStackItem(LEGACY_FAILURE_STACK_ITEM);
frame.pushStackItem(Bytes.EMPTY);
}

private void spawnChildMessage(final MessageFrame parent, final Code code, final EVM evm) {
Expand Down Expand Up @@ -227,12 +232,12 @@ private void complete(final MessageFrame frame, final MessageFrame childFrame, f
} else {
frame.getWorldUpdater().deleteAccount(childFrame.getRecipientAddress());
frame.setReturnData(childFrame.getOutputData());
frame.pushStackItem(LEGACY_FAILURE_STACK_ITEM);
frame.pushStackItem(Bytes.EMPTY);
onInvalid(frame, (CodeInvalid) outputCode);
}
} else {
frame.setReturnData(childFrame.getOutputData());
frame.pushStackItem(LEGACY_FAILURE_STACK_ITEM);
frame.pushStackItem(Bytes.EMPTY);
onFailure(frame, childFrame.getExceptionalHaltReason());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.evm.operation;

import static org.hyperledger.besu.evm.internal.Words.clampedAdd;
import static org.hyperledger.besu.evm.worldstate.DelegatedCodeGasCostHelper.deductDelegatedCodeGasCost;

import org.hyperledger.besu.datatypes.Address;
Expand Down Expand Up @@ -116,9 +117,11 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) {
}
if (toBytes.size() > Address.SIZE) {
return new OperationResult(
gasCalculator.memoryExpansionGasCost(frame, inputOffset, inputLength)
+ (zeroValue ? 0 : gasCalculator.callValueTransferGasCost())
+ gasCalculator.getColdAccountAccessCost(),
clampedAdd(
clampedAdd(
gasCalculator.memoryExpansionGasCost(frame, inputOffset, inputLength),
(zeroValue ? 0 : gasCalculator.callValueTransferGasCost())),
gasCalculator.getColdAccountAccessCost()),
ExceptionalHaltReason.ADDRESS_OUT_OF_RANGE);
}
Address to = Words.toAddress(toBytes);
Expand All @@ -135,16 +138,21 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) {

boolean accountCreation = contract == null && !zeroValue;
long cost =
gasCalculator.memoryExpansionGasCost(frame, inputOffset, inputLength)
+ (zeroValue ? 0 : gasCalculator.callValueTransferGasCost())
+ (frame.warmUpAddress(to) || gasCalculator.isPrecompile(to)
? gasCalculator.getWarmStorageReadCost()
: gasCalculator.getColdAccountAccessCost())
+ (accountCreation ? gasCalculator.newAccountGasCost() : 0);
long currentGas = frame.getRemainingGas() - cost;
if (currentGas < 0) {
clampedAdd(
clampedAdd(
clampedAdd(
gasCalculator.memoryExpansionGasCost(frame, inputOffset, inputLength),
(zeroValue ? 0 : gasCalculator.callValueTransferGasCost())),
(frame.warmUpAddress(to) || gasCalculator.isPrecompile(to)
? gasCalculator.getWarmStorageReadCost()
: gasCalculator.getColdAccountAccessCost())),
(accountCreation ? gasCalculator.newAccountGasCost() : 0));
long currentGas = frame.getRemainingGas();
if (currentGas < cost) {
return new OperationResult(cost, ExceptionalHaltReason.INSUFFICIENT_GAS);
}
currentGas -= cost;
frame.expandMemory(inputOffset, inputLength);

final Code code =
contract == null
Expand Down Expand Up @@ -202,7 +210,7 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) {
.build();

frame.setState(MessageFrame.State.CODE_SUSPENDED);
return new OperationResult(cost + childGas, null, 0);
return new OperationResult(clampedAdd(cost, childGas), null, 0);
}

private @Nonnull OperationResult softFailure(final MessageFrame frame, final long cost) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import static org.hyperledger.besu.crypto.Hash.keccak256;
import static org.hyperledger.besu.evm.internal.Words.clampedAdd;
import static org.hyperledger.besu.evm.internal.Words.clampedToInt;
import static org.hyperledger.besu.evm.internal.Words.clampedToLong;

import org.hyperledger.besu.datatypes.Address;
Expand Down Expand Up @@ -49,8 +48,8 @@ public EOFCreateOperation(final GasCalculator gasCalculator) {

@Override
public long cost(final MessageFrame frame, final Supplier<Code> codeSupplier) {
final int inputOffset = clampedToInt(frame.getStackItem(2));
final int inputSize = clampedToInt(frame.getStackItem(3));
final long inputOffset = clampedToLong(frame.getStackItem(2));
final long inputSize = clampedToLong(frame.getStackItem(3));
return clampedAdd(
gasCalculator().memoryExpansionGasCost(frame, inputOffset, inputSize),
clampedAdd(
Expand Down Expand Up @@ -86,4 +85,13 @@ protected Bytes getInputData(final MessageFrame frame) {
protected int getPcIncrement() {
return 2;
}

@Override
protected void fail(final MessageFrame frame) {
final long inputOffset = clampedToLong(frame.getStackItem(2));
final long inputSize = clampedToLong(frame.getStackItem(3));
frame.readMutableMemory(inputOffset, inputSize);
frame.popStackItems(getStackItemsConsumed());
frame.pushStackItem(Bytes.EMPTY);
}
}