Skip to content

Commit

Permalink
renamed evmGasUsed to baselineGas
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Lehrner <[email protected]>
  • Loading branch information
daniellehrner committed Dec 18, 2024
1 parent 1aa0f6d commit cee6c18
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@ private ValidationResult<TransactionInvalidReason> validateCostAndFee(
}
}

final long evmGasUsed =
final long baselineGas =
clampedAdd(
transaction.getAccessList().map(gasCalculator::accessListGasCost).orElse(0L),
gasCalculator.delegateCodeGasCost(transaction.codeDelegationListSize()));
final long intrinsicGasCost =
gasCalculator.transactionIntrinsicGasCost(
transaction.getPayload(), transaction.isContractCreation(), evmGasUsed);
transaction.getPayload(), transaction.isContractCreation(), baselineGas);
if (Long.compareUnsigned(intrinsicGasCost, transaction.getGasLimit()) > 0) {
return ValidationResult.invalid(
TransactionInvalidReason.INTRINSIC_GAS_EXCEEDS_GAS_LIMIT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void validateGasCost(
Transaction t = Transaction.readFrom(RLP.input(rlp));
Assertions.assertThat(
gasCalculator.transactionIntrinsicGasCost(
t.getPayload(), t.isContractCreation(), evmGasUsed(gasCalculator, t)))
t.getPayload(), t.isContractCreation(), baselineGas(gasCalculator, t)))
.isEqualTo(expectedGas);
}

Expand All @@ -129,7 +129,7 @@ void dryRunDetector() {
.isTrue();
}

long evmGasUsed(final GasCalculator gasCalculator, final Transaction transaction) {
long baselineGas(final GasCalculator gasCalculator, final Transaction transaction) {
final List<AccessListEntry> accessListEntries = transaction.getAccessList().orElse(List.of());

int accessListStorageCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ public void milestone(

assertThat(transaction.getSender()).isEqualTo(expected.getSender());
assertThat(transaction.getHash()).isEqualTo(expected.getHash());
final long evmGasUsed =
final long baselineGas =
transaction.getAccessList().map(gasCalculator::accessListGasCost).orElse(0L) +
gasCalculator.delegateCodeGasCost(transaction.codeDelegationListSize());
final long intrinsicGasCost = gasCalculator.transactionIntrinsicGasCost(
transaction.getPayload(),
transaction.isContractCreation(),
evmGasUsed);
baselineGas);
assertThat(intrinsicGasCost).isEqualTo(expected.getIntrinsicGas());
} catch (final Exception e) {
if (expected.isSucceeds()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ public FrontierGasCalculator() {

@Override
public long transactionIntrinsicGasCost(
final Bytes payload, final boolean isContractCreation, final long evmGasUsed) {
final Bytes payload, final boolean isContractCreation, final long baselineGas) {
final long dynamicIntrinsicGasCost =
dynamicIntrinsicGasCost(payload, isContractCreation, evmGasUsed);
dynamicIntrinsicGasCost(payload, isContractCreation, baselineGas);

if (dynamicIntrinsicGasCost == Long.MIN_VALUE || dynamicIntrinsicGasCost == Long.MAX_VALUE) {
return dynamicIntrinsicGasCost;
Expand All @@ -145,14 +145,14 @@ public long transactionIntrinsicGasCost(
*
* @param payload the call data payload
* @param isContractCreation whether the transaction is a contract creation
* @param evmGasUsed how much gas is used by access lists and code delegations
* @param baselineGas how much gas is used by access lists and code delegations
* @return the dynamic part of the intrinsic gas cost
*/
protected long dynamicIntrinsicGasCost(
final Bytes payload, final boolean isContractCreation, final long evmGasUsed) {
final Bytes payload, final boolean isContractCreation, final long baselineGas) {
final int payloadSize = payload.size();
final long zeroBytes = zeroBytes(payload);
long cost = clampedAdd(callDataCost(payloadSize, zeroBytes), evmGasUsed);
long cost = clampedAdd(callDataCost(payloadSize, zeroBytes), baselineGas);

if (cost == Long.MIN_VALUE || cost == Long.MAX_VALUE) {
return cost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,11 @@ default long modExpGasCost(final Bytes input) {
*
* @param transactionPayload The encoded transaction, as bytes
* @param isContractCreation Is this transaction a contract creation transaction?
* @param evmGasUsed The gas used by access lists and code delegation authorizations
* @param baselineGas The gas used by access lists and code delegation authorizations
* @return the transaction's intrinsic gas cost
*/
long transactionIntrinsicGasCost(
Bytes transactionPayload, boolean isContractCreation, long evmGasUsed);
Bytes transactionPayload, boolean isContractCreation, long baselineGas);

/**
* Returns the gas cost of the explicitly declared access list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public long calculateDelegateCodeGasRefund(final long alreadyExistingAccounts) {

@Override
public long transactionIntrinsicGasCost(
final Bytes payload, final boolean isContractCreation, final long evmGasUsed) {
final Bytes payload, final boolean isContractCreation, final long baselineGas) {
final long dynamicIntrinsicGasCost =
dynamicIntrinsicGasCost(payload, isContractCreation, evmGasUsed);
dynamicIntrinsicGasCost(payload, isContractCreation, baselineGas);
final long totalCostFloor =
tokensInCallData(payload.size(), zeroBytes(payload)) * TOTAL_COST_FLOOR_PER_TOKEN;

Expand Down

0 comments on commit cee6c18

Please sign in to comment.