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