Search in sources :

Example 16 with Gas

use of org.hyperledger.besu.evm.Gas in project besu by hyperledger.

the class FrontierGasCalculator method memoryCost.

private static Gas memoryCost(final long length) {
    final Gas len = Gas.of(length);
    final Gas base = len.times(len).dividedBy(512);
    return MEMORY_WORD_GAS_COST.times(len).plus(base);
}
Also used : Gas(org.hyperledger.besu.evm.Gas)

Example 17 with Gas

use of org.hyperledger.besu.evm.Gas in project besu by hyperledger.

the class FrontierGasCalculator method memoryExpansionGasCost.

@Override
public Gas memoryExpansionGasCost(final MessageFrame frame, final long offset, final long length) {
    final Gas pre = memoryCost(frame.memoryWordSize());
    final Gas post = memoryCost(frame.calculateMemoryExpansion(offset, length));
    return post.minus(pre);
}
Also used : Gas(org.hyperledger.besu.evm.Gas)

Example 18 with Gas

use of org.hyperledger.besu.evm.Gas in project besu by hyperledger.

the class IstanbulGasCalculator method transactionIntrinsicGasCost.

@Override
public Gas transactionIntrinsicGasCost(final Bytes payload, final boolean isContractCreation) {
    int zeros = 0;
    for (int i = 0; i < payload.size(); i++) {
        if (payload.get(i) == 0) {
            ++zeros;
        }
    }
    final int nonZeros = payload.size() - zeros;
    Gas cost = TX_BASE_COST.plus(TX_DATA_ZERO_COST.times(zeros)).plus(ISTANBUL_TX_DATA_NON_ZERO_COST.times(nonZeros));
    return isContractCreation ? cost.plus(txCreateExtraGasCost()) : cost;
}
Also used : Gas(org.hyperledger.besu.evm.Gas)

Example 19 with Gas

use of org.hyperledger.besu.evm.Gas in project besu by hyperledger.

the class Sha3Operation method execute.

@Override
public OperationResult execute(final MessageFrame frame, final EVM evm) {
    final long from = clampedToLong(frame.popStackItem());
    final long length = clampedToLong(frame.popStackItem());
    final Gas cost = gasCalculator().sha3OperationGasCost(frame, from, length);
    final Optional<Gas> optionalCost = Optional.of(cost);
    if (frame.getRemainingGas().compareTo(cost) < 0) {
        return new OperationResult(optionalCost, Optional.of(ExceptionalHaltReason.INSUFFICIENT_GAS));
    }
    final Bytes bytes = frame.readMutableMemory(from, length);
    frame.pushStackItem(UInt256.fromBytes(keccak256(bytes)));
    return new OperationResult(optionalCost, Optional.empty());
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) Gas(org.hyperledger.besu.evm.Gas)

Example 20 with Gas

use of org.hyperledger.besu.evm.Gas in project besu by hyperledger.

the class ConstantinopleGasCalculator method create2OperationGasCost.

@Override
public Gas create2OperationGasCost(final MessageFrame frame) {
    final UInt256 initCodeLength = UInt256.fromBytes(frame.getStackItem(2));
    final UInt256 numWords = UInt256.fromBytes(initCodeLength.divideCeil(Bytes32.SIZE));
    final Gas initCodeHashCost = SHA3_OPERATION_WORD_GAS_COST.times(Gas.of(numWords));
    return createOperationGasCost(frame).plus(initCodeHashCost);
}
Also used : Gas(org.hyperledger.besu.evm.Gas) UInt256(org.apache.tuweni.units.bigints.UInt256)

Aggregations

Gas (org.hyperledger.besu.evm.Gas)29 Address (org.hyperledger.besu.datatypes.Address)6 Bytes (org.apache.tuweni.bytes.Bytes)5 Wei (org.hyperledger.besu.datatypes.Wei)4 MutableAccount (org.hyperledger.besu.evm.account.MutableAccount)4 UInt256 (org.apache.tuweni.units.bigints.UInt256)3 MessageFrame (org.hyperledger.besu.evm.frame.MessageFrame)3 HederaWorldState (com.hedera.services.store.contracts.HederaWorldState)2 HederaWorldUpdater (com.hedera.services.store.contracts.HederaWorldUpdater)2 ImmutableList (com.google.common.collect.ImmutableList)1 InvalidTransactionException (com.hedera.services.exceptions.InvalidTransactionException)1 HederaStackedWorldStateUpdater (com.hedera.services.store.contracts.HederaStackedWorldStateUpdater)1 ArrayDeque (java.util.ArrayDeque)1 Map (java.util.Map)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 BadBlockManager (org.hyperledger.besu.ethereum.chain.BadBlockManager)1 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)1 MutableProtocolSchedule (org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule)1 ProtocolSpec (org.hyperledger.besu.ethereum.mainnet.ProtocolSpec)1 PrivateTransactionValidator (org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator)1