diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java index 63a11f5c723..ff08307399e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidator.java @@ -253,13 +253,13 @@ private ValidationResult 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, diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/IntrinsicGasTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/IntrinsicGasTest.java index eee7c4fde5d..7979cf1338b 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/IntrinsicGasTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/IntrinsicGasTest.java @@ -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); } @@ -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 accessListEntries = transaction.getAccessList().orElse(List.of()); int accessListStorageCount = 0; diff --git a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java index 19c1781f926..a3758422c4f 100644 --- a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/core/TransactionTest.java @@ -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()) { diff --git a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/FrontierGasCalculator.java b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/FrontierGasCalculator.java index e629aaf02ae..8eb4770c49b 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/FrontierGasCalculator.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/FrontierGasCalculator.java @@ -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; @@ -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; diff --git a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/GasCalculator.java b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/GasCalculator.java index d2c1ff4a362..7061834cd14 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/GasCalculator.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/GasCalculator.java @@ -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. diff --git a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/PragueGasCalculator.java b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/PragueGasCalculator.java index 26369dea22b..162db9e4f2f 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/PragueGasCalculator.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/PragueGasCalculator.java @@ -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;