From 99b6d04e504024995938b2c8e49468bc36dcf728 Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Thu, 16 Sep 2021 21:45:49 -0600 Subject: [PATCH] Undo TransacitonGasCalculator Re-unify the gas calculators. To avoid having to drag in a Transaction class the gas calcualtor uses the relevant values from the transaction: the payload size, if it is contract creation, and the access list contents. Signed-off-by: Danno Ferrin Add SPDX license header to docker_interop source files (#11) Signed-off-by: Usman Saleem Signed-off-by: Danno Ferrin --- .../controller/QbftBesuControllerBuilder.java | 2 +- .../hyperledger/besu/PrivacyReorgTest.java | 2 +- .../consensus/ibft/BftBlockHashingTest.java | 2 +- .../QbftBlockCreatorFactoryTest.java | 2 +- .../QbftValidatorsValidationRuleTest.java | 2 +- .../api/jsonrpc/JsonRpcResponseUtils.java | 2 +- .../eea/PluginEeaSendRawTransaction.java | 17 ++-- .../internal/processor/TransactionTracer.java | 2 +- .../results/TransactionCompleteResult.java | 2 +- .../results/TransactionPendingResult.java | 2 +- .../PrivateTransactionReceiptResult.java | 2 +- .../jsonrpc/methods/EeaJsonRpcMethods.java | 2 +- .../PrivacyApiGroupJsonRpcMethods.java | 7 -- .../ethereum/api/query/BlockchainQueries.java | 2 +- .../besu/ethereum/api/query/LogsQuery.java | 2 +- .../internal/filter/LogsQueryTest.java | 2 +- .../internal/methods/EthGasPriceTest.java | 2 +- .../methods/EthGetTransactionReceiptTest.java | 2 - .../eea/BaseEeaSendRawTransaction.java | 6 +- .../query/BlockchainQueriesLogCacheTest.java | 2 +- ...umPrivateTxBloomBlockchainQueriesTest.java | 2 +- ...mPrivateTransactionLogBloomCacherTest.java | 2 +- .../cache/TransactionLogBloomCacherTest.java | 2 +- .../api/util/DomainObjectDecodeUtilsTest.java | 2 +- .../besu/ethereum/chain/GenesisState.java | 2 +- .../besu/ethereum/core/Transaction.java | 1 + .../core/encoding/TransactionDecoder.java | 2 +- .../core/encoding/TransactionEncoder.java | 4 +- .../goquorum/GoQuorumBlockProcessor.java | 2 +- .../BerlinTransactionGasCalculator.java | 67 --------------- .../besu/ethereum/mainnet/BodyValidation.java | 2 +- .../mainnet/ClassicProtocolSpecs.java | 2 - .../FrontierTransactionGasCalculator.java | 72 ---------------- .../IstanbulTransactionGasCalculator.java | 58 ------------- .../LondonTransactionGasCalculator.java | 26 ------ .../mainnet/MainnetBlockBodyValidator.java | 2 +- .../mainnet/MainnetProtocolSpecs.java | 21 ++--- .../mainnet/MainnetTransactionProcessor.java | 47 +++++++---- .../mainnet/MainnetTransactionValidator.java | 20 +++-- .../besu/ethereum/mainnet/ProtocolSpec.java | 14 ---- .../ethereum/mainnet/ProtocolSpecBuilder.java | 28 ++----- .../mainnet/TransactionGasCalculator.java | 60 -------------- .../OnChainPrivacyPrecompiledContract.java | 3 +- .../ethereum/privacy/PrivateTransaction.java | 2 - .../privacy/PrivateTransactionProcessor.java | 10 +-- ...ueStoragePrefixedKeyBlockchainStorage.java | 2 +- .../transaction/TransactionSimulator.java | 2 +- .../ethereum/core/BlockDataGenerator.java | 1 + .../besu/ethereum/bonsai/LogRollingTests.java | 2 +- .../ethereum/core/TransactionBuilderTest.java | 1 + .../ethereum/core/TransactionEIP1559Test.java | 5 +- .../ethereum/mainnet/IntrinsicGasTest.java | 17 ++-- .../ethereum/mainnet/KeccakHasherTest.java | 2 +- .../MainnetTransactionProcessorTest.java | 2 - .../MainnetTransactionValidatorTest.java | 83 +++++++------------ .../besu/ethereum/vm/VMReferenceTest.java | 20 ++--- .../eth/messages/RequestIdMessageTest.java | 2 +- .../besu/evmtool/EvmToolCommand.java | 21 +++-- .../besu/evmtool/StateTestSubCommand.java | 3 +- .../BlockchainReferenceTestCaseSpec.java | 2 +- .../referencetests/ReferenceTestEnv.java | 2 +- .../StateTestAccessListDeserializer.java | 2 +- .../StateTestVersionedTransaction.java | 2 +- .../NoRewardProtocolScheduleWrapper.java | 1 - .../besu/evm}/AccessListEntry.java | 17 ++-- .../java/org/hyperledger/besu/evm/Gas.java | 2 +- .../hyperledger/besu/evm/frame/Memory.java | 6 +- .../gascalculator/BerlinGasCalculator.java | 8 ++ .../gascalculator/FrontierGasCalculator.java | 46 +++++++++- .../besu/evm/gascalculator/GasCalculator.java | 54 ++++++++++++ .../gascalculator/HomesteadGasCalculator.java | 4 +- .../gascalculator/IstanbulGasCalculator.java | 28 +++++++ .../gascalculator/LondonGasCalculator.java | 8 ++ .../TangerineWhistleGasCalculator.java | 2 +- .../besu/evm/operation/MStore8Operation.java | 2 +- 75 files changed, 341 insertions(+), 525 deletions(-) delete mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BerlinTransactionGasCalculator.java delete mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/FrontierTransactionGasCalculator.java delete mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/IstanbulTransactionGasCalculator.java delete mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/LondonTransactionGasCalculator.java delete mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/TransactionGasCalculator.java rename {ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core => evm/src/main/java/org/hyperledger/besu/evm}/AccessListEntry.java (80%) rename ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/HomesteadTransactionGasCalculator.java => evm/src/main/java/org/hyperledger/besu/evm/gascalculator/HomesteadGasCalculator.java (85%) diff --git a/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java index 926a298beba..4a8f8e4c3f2 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/QbftBesuControllerBuilder.java @@ -58,9 +58,9 @@ import org.hyperledger.besu.consensus.qbft.validator.ForkingValidatorProvider; import org.hyperledger.besu.consensus.qbft.validator.TransactionValidatorProvider; import org.hyperledger.besu.consensus.qbft.validator.ValidatorContractController; -import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.consensus.qbft.validator.ValidatorSelectorConfig; import org.hyperledger.besu.consensus.qbft.validator.ValidatorSelectorForksSchedule; +import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.api.jsonrpc.methods.JsonRpcMethods; import org.hyperledger.besu.ethereum.blockcreation.MiningCoordinator; diff --git a/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java b/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java index 3d69e5a173a..ce1d5c6d92f 100644 --- a/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java +++ b/besu/src/test/java/org/hyperledger/besu/PrivacyReorgTest.java @@ -41,7 +41,6 @@ import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; import org.hyperledger.besu.ethereum.core.InMemoryPrivacyStorageProvider; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.core.Transaction; @@ -56,6 +55,7 @@ import org.hyperledger.besu.ethereum.privacy.storage.PrivacyStorageProvider; import org.hyperledger.besu.ethereum.privacy.storage.PrivateStateStorage; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem; import org.hyperledger.besu.plugin.data.Restriction; import org.hyperledger.besu.plugin.data.TransactionType; diff --git a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/BftBlockHashingTest.java b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/BftBlockHashingTest.java index c0a77b8111c..6a0cf9e2416 100644 --- a/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/BftBlockHashingTest.java +++ b/consensus/ibft/src/test/java/org/hyperledger/besu/consensus/ibft/BftBlockHashingTest.java @@ -31,9 +31,9 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.core.Util; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import java.util.Arrays; import java.util.List; diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactoryTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactoryTest.java index 936b626ff1e..bc6057a7873 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactoryTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/blockcreation/QbftBlockCreatorFactoryTest.java @@ -21,9 +21,9 @@ import org.hyperledger.besu.consensus.common.bft.BftExtraData; import org.hyperledger.besu.consensus.qbft.QbftExtraDataCodec; -import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.consensus.qbft.validator.ValidatorSelectorConfig; import org.hyperledger.besu.consensus.qbft.validator.ValidatorSelectorForksSchedule; +import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.MiningParameters; diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java index a03e1674b4a..105e94af024 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/headervalidationrules/QbftValidatorsValidationRuleTest.java @@ -21,8 +21,8 @@ import org.hyperledger.besu.consensus.common.bft.BftExtraData; import org.hyperledger.besu.consensus.common.bft.Vote; -import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.consensus.qbft.QbftContext; +import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.ProtocolContext; import org.hyperledger.besu.ethereum.core.AddressHelpers; import org.hyperledger.besu.ethereum.core.BlockHeader; diff --git a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseUtils.java b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseUtils.java index 4c385b08d63..3cecd31b7ed 100644 --- a/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseUtils.java +++ b/ethereum/api/src/integration-test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcResponseUtils.java @@ -49,9 +49,9 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.plugin.data.TransactionType; import java.math.BigInteger; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/PluginEeaSendRawTransaction.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/PluginEeaSendRawTransaction.java index 1dba530a859..96017b5bc2e 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/PluginEeaSendRawTransaction.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/PluginEeaSendRawTransaction.java @@ -20,12 +20,12 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.privacy.methods.PrivacyIdProvider; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; -import org.hyperledger.besu.ethereum.mainnet.TransactionGasCalculator; import org.hyperledger.besu.ethereum.mainnet.ValidationResult; import org.hyperledger.besu.ethereum.privacy.PrivacyController; import org.hyperledger.besu.ethereum.privacy.PrivateTransaction; import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; import org.hyperledger.besu.ethereum.util.NonceProvider; +import org.hyperledger.besu.evm.gascalculator.GasCalculator; import org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFactory; import java.util.Optional; @@ -36,7 +36,7 @@ public class PluginEeaSendRawTransaction extends AbstractEeaSendRawTransaction { private final PrivacyController privacyController; private final PrivacyIdProvider privacyIdProvider; - private final TransactionGasCalculator transactionGasCalculator; + private final GasCalculator gasCalculator; public PluginEeaSendRawTransaction( final TransactionPool transactionPool, @@ -44,11 +44,11 @@ public PluginEeaSendRawTransaction( final PrivateMarkerTransactionFactory privateMarkerTransactionFactory, final NonceProvider publicNonceProvider, final PrivacyController privacyController, - final TransactionGasCalculator transactionGasCalculator) { + final GasCalculator gasCalculator) { super(transactionPool, privacyIdProvider, privateMarkerTransactionFactory, publicNonceProvider); this.privacyController = privacyController; this.privacyIdProvider = privacyIdProvider; - this.transactionGasCalculator = transactionGasCalculator; + this.gasCalculator = gasCalculator; } @Override @@ -83,13 +83,8 @@ protected long getGasLimit(final PrivateTransaction privateTransaction, final St // choose the highest of the two options return Math.max( privateTransaction.getGasLimit(), - transactionGasCalculator - .transactionIntrinsicGasCostAndAccessedState( - new Transaction.Builder() - .to(PLUGIN_PRIVACY) - .payload(Bytes.fromBase64String(pmtPayload)) - .build()) - .getGas() + gasCalculator + .transactionIntrinsicGasCost(Bytes.fromBase64String(pmtPayload), false) .toLong()); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/processor/TransactionTracer.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/processor/TransactionTracer.java index 39c4bd71207..7b129016601 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/processor/TransactionTracer.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/processor/TransactionTracer.java @@ -187,7 +187,7 @@ public static String summaryTrace( "gasUsed", StandardJsonTracer.shortNumber( UInt256.valueOf(transaction.getGasLimit() - result.getGasRemaining()))); - // summaryLine.put("time", timer); + summaryLine.put("time", timer); return summaryLine.toString(); } } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionCompleteResult.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionCompleteResult.java index bb03f3276ed..a3c845bcac0 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionCompleteResult.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionCompleteResult.java @@ -16,9 +16,9 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata; -import org.hyperledger.besu.ethereum.core.AccessListEntry; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.encoding.TransactionEncoder; +import org.hyperledger.besu.evm.AccessListEntry; import org.hyperledger.besu.plugin.data.TransactionType; import java.util.List; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionPendingResult.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionPendingResult.java index f63c775a95f..3221995f422 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionPendingResult.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/TransactionPendingResult.java @@ -16,9 +16,9 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.AccessListEntry; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; +import org.hyperledger.besu.evm.AccessListEntry; import org.hyperledger.besu.plugin.data.TransactionType; import java.util.List; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/privacy/PrivateTransactionReceiptResult.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/privacy/PrivateTransactionReceiptResult.java index 95bb6e9d206..ab36e695e76 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/privacy/PrivateTransactionReceiptResult.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/results/privacy/PrivateTransactionReceiptResult.java @@ -17,8 +17,8 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.Quantity; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.TransactionReceiptLogResult; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.evm.log.Log; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import java.util.ArrayList; import java.util.List; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EeaJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EeaJsonRpcMethods.java index 6691d1a8e6e..4835430ea85 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EeaJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/EeaJsonRpcMethods.java @@ -65,7 +65,7 @@ protected Map create( privateMarkerTransactionFactory, nonceProvider, privacyController, - getTransactionGasCalculator()), + getGasCalculator()), new PrivGetEeaTransactionCount(privacyController, privacyIdProvider)); } else if (getPrivacyParameters().isOnchainPrivacyGroupsEnabled()) { return mapOf( diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java index 245c21aeb24..152635739f4 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/methods/PrivacyApiGroupJsonRpcMethods.java @@ -24,7 +24,6 @@ import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; -import org.hyperledger.besu.ethereum.mainnet.TransactionGasCalculator; import org.hyperledger.besu.ethereum.privacy.ChainHeadPrivateNonceProvider; import org.hyperledger.besu.ethereum.privacy.PluginPrivacyController; import org.hyperledger.besu.ethereum.privacy.PrivacyController; @@ -93,12 +92,6 @@ public GasCalculator getGasCalculator() { .getGasCalculator(); } - public TransactionGasCalculator getTransactionGasCalculator() { - return protocolSchedule - .getByBlockNumber(blockchainQueries.headBlockNumber()) - .getTransactionGasCalculator(); - } - @Override protected Map create() { final PrivateMarkerTransactionFactory markerTransactionFactory = diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java index 881db239459..29a8f3a7593 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueries.java @@ -30,12 +30,12 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.LogWithMetadata; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.evm.worldstate.WorldState; import java.io.EOFException; diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/LogsQuery.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/LogsQuery.java index 07c523abbbd..79d5f0246c5 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/LogsQuery.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/query/LogsQuery.java @@ -21,9 +21,9 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.TopicsDeserializer; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.evm.log.Log; import org.hyperledger.besu.evm.log.LogTopic; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import java.util.ArrayList; import java.util.Arrays; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/filter/LogsQueryTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/filter/LogsQueryTest.java index fac4c65683a..041130ad4fc 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/filter/LogsQueryTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/filter/LogsQueryTest.java @@ -20,9 +20,9 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.ethereum.api.query.LogsQuery; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.evm.log.Log; import org.hyperledger.besu.evm.log.LogTopic; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import java.util.ArrayList; import java.util.List; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java index 70673bff52c..ed79714b4f9 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGasPriceTest.java @@ -35,8 +35,8 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import java.util.List; import java.util.Optional; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java index e0f41336e6c..9baabd173cb 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthGetTransactionReceiptTest.java @@ -107,7 +107,6 @@ public class EthGetTransactionReceiptTest { null, false, null, - null, GasLimitCalculator.constant(), FeeMarket.legacy(), null, @@ -133,7 +132,6 @@ public class EthGetTransactionReceiptTest { null, false, null, - null, GasLimitCalculator.constant(), FeeMarket.legacy(), null, diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/BaseEeaSendRawTransaction.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/BaseEeaSendRawTransaction.java index 507284c9eee..a916d489720 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/BaseEeaSendRawTransaction.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/privacy/methods/eea/BaseEeaSendRawTransaction.java @@ -27,12 +27,12 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool; -import org.hyperledger.besu.ethereum.mainnet.BerlinTransactionGasCalculator; -import org.hyperledger.besu.ethereum.mainnet.TransactionGasCalculator; import org.hyperledger.besu.ethereum.privacy.PrivacyController; import org.hyperledger.besu.ethereum.privacy.PrivateTransaction; import org.hyperledger.besu.ethereum.privacy.markertransaction.FixedKeySigningPrivateMarkerTransactionFactory; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; +import org.hyperledger.besu.evm.gascalculator.BerlinGasCalculator; +import org.hyperledger.besu.evm.gascalculator.GasCalculator; import org.hyperledger.besu.plugin.data.Restriction; import org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFactory; @@ -65,7 +65,7 @@ public class BaseEeaSendRawTransaction { final PrivateMarkerTransactionFactory privateMarkerTransactionFactory = new FixedKeySigningPrivateMarkerTransactionFactory(keyPair); - final TransactionGasCalculator transactionGasCalculator = new BerlinTransactionGasCalculator(); + final GasCalculator transactionGasCalculator = new BerlinGasCalculator(); final Transaction PUBLIC_ONCHAIN_TRANSACTION = new Transaction( diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java index 647ff9474da..33b82e3a18c 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/BlockchainQueriesLogCacheTest.java @@ -30,11 +30,11 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.log.Log; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import java.io.IOException; import java.io.RandomAccessFile; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/GoQuorumPrivateTxBloomBlockchainQueriesTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/GoQuorumPrivateTxBloomBlockchainQueriesTest.java index 4fab378932e..4770214e20f 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/GoQuorumPrivateTxBloomBlockchainQueriesTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/GoQuorumPrivateTxBloomBlockchainQueriesTest.java @@ -29,11 +29,11 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.log.Log; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import java.util.Collections; import java.util.List; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/cache/GoQuorumPrivateTransactionLogBloomCacherTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/cache/GoQuorumPrivateTransactionLogBloomCacherTest.java index 95973e8490a..d84aeb9b22b 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/cache/GoQuorumPrivateTransactionLogBloomCacherTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/cache/GoQuorumPrivateTransactionLogBloomCacherTest.java @@ -33,11 +33,11 @@ import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; import org.hyperledger.besu.evm.log.Log; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import java.io.File; import java.io.IOException; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/cache/TransactionLogBloomCacherTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/cache/TransactionLogBloomCacherTest.java index 5432a54dbc0..32352886b35 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/cache/TransactionLogBloomCacherTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/query/cache/TransactionLogBloomCacherTest.java @@ -28,10 +28,10 @@ import org.hyperledger.besu.ethereum.chain.MutableBlockchain; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.eth.manager.EthScheduler; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.evm.log.Log; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import java.io.File; import java.io.IOException; diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtilsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtilsTest.java index 5d1d8156a91..942898b8128 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtilsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/util/DomainObjectDecodeUtilsTest.java @@ -20,11 +20,11 @@ import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.AccessListEntry; import org.hyperledger.besu.ethereum.core.BlockDataGenerator; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.encoding.TransactionEncoder; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; +import org.hyperledger.besu.evm.AccessListEntry; import java.math.BigInteger; import java.util.List; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java index f4beee97faf..0a2daff0a45 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/GenesisState.java @@ -24,13 +24,13 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions; import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStateKeyValueStorage; import org.hyperledger.besu.ethereum.storage.keyvalue.WorldStatePreimageKeyValueStorage; import org.hyperledger.besu.ethereum.worldstate.DefaultMutableWorldState; import org.hyperledger.besu.evm.account.MutableAccount; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.evm.worldstate.MutableWorldState; import org.hyperledger.besu.evm.worldstate.WorldUpdater; import org.hyperledger.besu.services.kvstore.InMemoryKeyValueStorage; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java index 24630d9b599..345b4b2852e 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/Transaction.java @@ -32,6 +32,7 @@ import org.hyperledger.besu.ethereum.rlp.RLPInput; import org.hyperledger.besu.ethereum.rlp.RLPOutput; import org.hyperledger.besu.ethereum.transaction.GoQuorumPrivateTransactionDetector; +import org.hyperledger.besu.evm.AccessListEntry; import org.hyperledger.besu.plugin.data.Quantity; import org.hyperledger.besu.plugin.data.TransactionType; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoder.java index 9ecc66df0c8..a922be0488f 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionDecoder.java @@ -27,11 +27,11 @@ import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.AccessListEntry; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPInput; import org.hyperledger.besu.ethereum.transaction.GoQuorumPrivateTransactionDetector; +import org.hyperledger.besu.evm.AccessListEntry; import org.hyperledger.besu.plugin.data.TransactionType; import java.math.BigInteger; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionEncoder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionEncoder.java index cfa5a903d8b..9123bd0a1fb 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionEncoder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/encoding/TransactionEncoder.java @@ -18,10 +18,10 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.AccessListEntry; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.rlp.RLPOutput; +import org.hyperledger.besu.evm.AccessListEntry; import org.hyperledger.besu.plugin.data.TransactionType; import java.math.BigInteger; @@ -170,7 +170,7 @@ public static void writeAccessList( accessListEntryRLPOutput.startList(); out.writeBytes(accessListEntry.getAddress()); out.writeList( - accessListEntry.getStorageKeysBytes(), + accessListEntry.getStorageKeys(), (storageKeyBytes, storageKeyBytesRLPOutput) -> storageKeyBytesRLPOutput.writeBytes(storageKeyBytes)); accessListEntryRLPOutput.endList(); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/goquorum/GoQuorumBlockProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/goquorum/GoQuorumBlockProcessor.java index 5be5e4a0659..a60ef8f814a 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/goquorum/GoQuorumBlockProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/goquorum/GoQuorumBlockProcessor.java @@ -23,7 +23,6 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.GoQuorumPrivacyParameters; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.mainnet.AbstractBlockProcessor; @@ -38,6 +37,7 @@ import org.hyperledger.besu.ethereum.vm.BlockHashLookup; import org.hyperledger.besu.ethereum.worldstate.GoQuorumMutablePrivateWorldStateUpdater; import org.hyperledger.besu.evm.account.EvmAccount; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.evm.tracing.OperationTracer; import org.hyperledger.besu.evm.worldstate.MutableWorldState; import org.hyperledger.besu.evm.worldstate.WorldUpdater; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BerlinTransactionGasCalculator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BerlinTransactionGasCalculator.java deleted file mode 100644 index d3f04f8b447..00000000000 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BerlinTransactionGasCalculator.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright contributors to Hyperledger Besu - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.mainnet; - -import static java.util.Collections.emptyList; - -import org.hyperledger.besu.datatypes.Address; -import org.hyperledger.besu.ethereum.core.AccessListEntry; -import org.hyperledger.besu.ethereum.core.GasAndAccessedState; -import org.hyperledger.besu.ethereum.core.Transaction; -import org.hyperledger.besu.evm.Gas; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; -import org.apache.tuweni.bytes.Bytes32; - -public class BerlinTransactionGasCalculator extends IstanbulTransactionGasCalculator { - - // new constants for EIP-2929 - private static final Gas ACCESS_LIST_ADDRESS_COST = Gas.of(2400); - protected static final Gas ACCESS_LIST_STORAGE_COST = Gas.of(1900); - - @Override - public GasAndAccessedState transactionIntrinsicGasCostAndAccessedState( - final Transaction transaction) { - // As per https://eips.ethereum.org/EIPS/eip-2930 - final List accessList = transaction.getAccessList().orElse(emptyList()); - - long accessedStorageCount = 0; - final Set
accessedAddresses = new HashSet<>(); - final Multimap accessedStorage = HashMultimap.create(); - - for (final AccessListEntry accessListEntry : accessList) { - final Address address = accessListEntry.getAddress(); - - accessedAddresses.add(address); - for (final Bytes32 storageKeyBytes : accessListEntry.getStorageKeysBytes()) { - accessedStorage.put(address, storageKeyBytes); - ++accessedStorageCount; - } - } - - return new GasAndAccessedState( - super.transactionIntrinsicGasCostAndAccessedState(transaction) - .getGas() - .plus(ACCESS_LIST_ADDRESS_COST.times(accessList.size())) - .plus(ACCESS_LIST_STORAGE_COST.times(accessedStorageCount)), - accessedAddresses, - accessedStorage); - } -} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidation.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidation.java index 0f9f1de010b..8d8fe3efd84 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidation.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/BodyValidation.java @@ -18,13 +18,13 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.core.encoding.TransactionEncoder; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.ethereum.trie.MerklePatriciaTrie; import org.hyperledger.besu.ethereum.trie.SimpleMerklePatriciaTrie; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import java.util.List; import java.util.stream.IntStream; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java index d2f15b4a6bc..22ca5235a8d 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java @@ -169,13 +169,11 @@ public static ProtocolSpecBuilder atlantisDefinition( 1)) .transactionProcessorBuilder( (gasCalculator, - transactionGasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor) -> new MainnetTransactionProcessor( gasCalculator, - transactionGasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/FrontierTransactionGasCalculator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/FrontierTransactionGasCalculator.java deleted file mode 100644 index 768f0e6a4c6..00000000000 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/FrontierTransactionGasCalculator.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright contributors to Hyperledger Besu - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.mainnet; - -import org.hyperledger.besu.ethereum.core.GasAndAccessedState; -import org.hyperledger.besu.ethereum.core.Transaction; -import org.hyperledger.besu.evm.Gas; - -import org.apache.tuweni.bytes.Bytes; - -public class FrontierTransactionGasCalculator implements TransactionGasCalculator { - - private static final Gas TX_DATA_ZERO_COST = Gas.of(4L); - - private static final Gas TX_DATA_NON_ZERO_COST = Gas.of(68L); - - private static final Gas TX_BASE_COST = Gas.of(21_000L); - - private static final Gas TX_CREATE_EXTRA_COST = Gas.of(0L); - - @Override - public GasAndAccessedState transactionIntrinsicGasCostAndAccessedState( - final Transaction transaction) { - final Bytes payload = transaction.getPayload(); - 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(TX_DATA_NON_ZERO_COST.times(nonZeros)); - - if (transaction.isContractCreation()) { - cost = cost.plus(txCreateExtraGasCost()); - } - - return new GasAndAccessedState(cost); - } - - /** - * Returns the additional gas cost for contract creation transactions - * - * @return the additional gas cost for contract creation transactions - */ - protected Gas txCreateExtraGasCost() { - return TX_CREATE_EXTRA_COST; - } - - @Override - public Gas getMaximumPmtCost() { - // what would be the gas for PMT with hash of all non-zeros - int nonZeros = 64; - return TX_BASE_COST.plus(TX_DATA_NON_ZERO_COST.times(nonZeros)); - } -} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/IstanbulTransactionGasCalculator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/IstanbulTransactionGasCalculator.java deleted file mode 100644 index cb01062361d..00000000000 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/IstanbulTransactionGasCalculator.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright contributors to Hyperledger Besu - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.mainnet; - -import org.hyperledger.besu.ethereum.core.GasAndAccessedState; -import org.hyperledger.besu.ethereum.core.Transaction; -import org.hyperledger.besu.evm.Gas; - -import org.apache.tuweni.bytes.Bytes; - -public class IstanbulTransactionGasCalculator extends HomesteadTransactionGasCalculator { - - private static final Gas TX_DATA_ZERO_COST = Gas.of(4L); - private static final Gas ISTANBUL_TX_DATA_NON_ZERO_COST = Gas.of(16L); - private static final Gas TX_BASE_COST = Gas.of(21_000L); - - @Override - public GasAndAccessedState transactionIntrinsicGasCostAndAccessedState( - final Transaction transaction) { - final Bytes payload = transaction.getPayload(); - 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)); - - if (transaction.isContractCreation()) { - cost = cost.plus(txCreateExtraGasCost()); - } - - return new GasAndAccessedState(cost); - } - - @Override - public Gas getMaximumPmtCost() { - int nonZeros = 64; - return TX_BASE_COST.plus(ISTANBUL_TX_DATA_NON_ZERO_COST.times(nonZeros)); - } -} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/LondonTransactionGasCalculator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/LondonTransactionGasCalculator.java deleted file mode 100644 index f27bbf7c0f2..00000000000 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/LondonTransactionGasCalculator.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright contributors to Hyperledger Besu - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.mainnet; - -public class LondonTransactionGasCalculator extends BerlinTransactionGasCalculator { - - // redefinitions for EIP-3529 - private static final int NEW_MAX_REFUND_QUOTIENT = 5; - - @Override - public long getMaxRefundQuotient() { - return NEW_MAX_REFUND_QUOTIENT; - } -} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidator.java index aaecdb36b68..55272aa0a7c 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetBlockBodyValidator.java @@ -19,8 +19,8 @@ import org.hyperledger.besu.ethereum.core.Block; import org.hyperledger.besu.ethereum.core.BlockBody; import org.hyperledger.besu.ethereum.core.BlockHeader; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.core.TransactionReceipt; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import java.util.HashSet; import java.util.List; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java index f85a2fd2cec..bda2515f6fb 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java @@ -43,6 +43,7 @@ import org.hyperledger.besu.evm.gascalculator.ByzantiumGasCalculator; import org.hyperledger.besu.evm.gascalculator.ConstantinopleGasCalculator; import org.hyperledger.besu.evm.gascalculator.FrontierGasCalculator; +import org.hyperledger.besu.evm.gascalculator.HomesteadGasCalculator; import org.hyperledger.besu.evm.gascalculator.IstanbulGasCalculator; import org.hyperledger.besu.evm.gascalculator.LondonGasCalculator; import org.hyperledger.besu.evm.gascalculator.PetersburgGasCalculator; @@ -104,7 +105,6 @@ public static ProtocolSpecBuilder frontierDefinition( final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); return new ProtocolSpecBuilder() .gasCalculator(FrontierGasCalculator::new) - .transactionGasCalculator(new FrontierTransactionGasCalculator()) .gasLimitCalculator(new FrontierTargetingGasLimitCalculator()) .evmBuilder(MainnetEVMs::frontier) .precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::frontier) @@ -118,18 +118,16 @@ public static ProtocolSpecBuilder frontierDefinition( Collections.singletonList(MaxCodeSizeRule.of(contractSizeLimit)), 0)) .transactionValidatorBuilder( - transactionGasCalculator -> + gasCalculator -> new MainnetTransactionValidator( - transactionGasCalculator, false, Optional.empty(), goQuorumMode)) + gasCalculator, false, Optional.empty(), goQuorumMode)) .transactionProcessorBuilder( (gasCalculator, - transactionGasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor) -> new MainnetTransactionProcessor( gasCalculator, - transactionGasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor, @@ -138,13 +136,13 @@ public static ProtocolSpecBuilder frontierDefinition( FeeMarket.legacy(), CoinbaseFeePriceCalculator.frontier())) .privateTransactionProcessorBuilder( - (transactionGasCalculator, + (gasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor, privateTransactionValidator) -> new PrivateTransactionProcessor( - transactionGasCalculator, + gasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor, @@ -211,7 +209,7 @@ public static ProtocolSpecBuilder homesteadDefinition( final int contractSizeLimit = configContractSizeLimit.orElse(FRONTIER_CONTRACT_SIZE_LIMIT); return frontierDefinition( configContractSizeLimit, configStackSizeLimit, quorumCompatibilityMode) - .transactionGasCalculator(new HomesteadTransactionGasCalculator()) + .gasCalculator(HomesteadGasCalculator::new) .evmBuilder(MainnetEVMs::homestead) .contractCreationProcessorBuilder( (gasCalculator, evm) -> @@ -306,13 +304,11 @@ public static ProtocolSpecBuilder spuriousDragonDefinition( transactionGasCalculator, true, chainId, quorumCompatibilityMode)) .transactionProcessorBuilder( (gasCalculator, - transactionGasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor) -> new MainnetTransactionProcessor( gasCalculator, - transactionGasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor, @@ -409,7 +405,6 @@ public static ProtocolSpecBuilder istanbulDefinition( enableRevertReason, quorumCompatibilityMode) .gasCalculator(IstanbulGasCalculator::new) - .transactionGasCalculator(new IstanbulTransactionGasCalculator()) .evmBuilder( gasCalculator -> MainnetEVMs.istanbul(gasCalculator, chainId.orElse(BigInteger.ZERO))) .precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::istanbul) @@ -454,7 +449,6 @@ static ProtocolSpecBuilder berlinDefinition( enableRevertReason, quorumCompatibilityMode) .gasCalculator(BerlinGasCalculator::new) - .transactionGasCalculator(new BerlinTransactionGasCalculator()) .transactionValidatorBuilder( transactionGasCalculator -> new MainnetTransactionValidator( @@ -490,7 +484,6 @@ static ProtocolSpecBuilder londonDefinition( enableRevertReason, quorumCompatibilityMode) .gasCalculator(LondonGasCalculator::new) - .transactionGasCalculator(new LondonTransactionGasCalculator()) .gasLimitCalculator( new LondonTargetingGasLimitCalculator(londonForkBlockNumber, londonFeeMarket)) .transactionValidatorBuilder( @@ -507,13 +500,11 @@ static ProtocolSpecBuilder londonDefinition( quorumCompatibilityMode)) .transactionProcessorBuilder( (gasCalculator, - transactionGasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor) -> new MainnetTransactionProcessor( gasCalculator, - transactionGasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java index f851c16e156..a8faabc3275 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessor.java @@ -22,7 +22,6 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.chain.Blockchain; -import org.hyperledger.besu.ethereum.core.GasAndAccessedState; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.feemarket.CoinbaseFeePriceCalculator; import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket; @@ -31,6 +30,7 @@ import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; import org.hyperledger.besu.ethereum.vm.BlockHashLookup; import org.hyperledger.besu.ethereum.worldstate.GoQuorumMutablePrivateWorldStateUpdater; +import org.hyperledger.besu.evm.AccessListEntry; import org.hyperledger.besu.evm.Code; import org.hyperledger.besu.evm.Gas; import org.hyperledger.besu.evm.account.Account; @@ -46,12 +46,18 @@ import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; +import java.util.HashSet; +import java.util.List; import java.util.Optional; +import java.util.Set; +import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Multimap; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.tuweni.bytes.Bytes; +import org.apache.tuweni.bytes.Bytes32; public class MainnetTransactionProcessor { @@ -59,8 +65,6 @@ public class MainnetTransactionProcessor { protected final GasCalculator gasCalculator; - protected final TransactionGasCalculator transactionGasCalculator; - protected final MainnetTransactionValidator transactionValidator; private final AbstractMessageProcessor contractCreationProcessor; @@ -226,7 +230,6 @@ public TransactionProcessingResult processTransaction( public MainnetTransactionProcessor( final GasCalculator gasCalculator, - final TransactionGasCalculator transacitonGasCalculator, final MainnetTransactionValidator transactionValidator, final AbstractMessageProcessor contractCreationProcessor, final AbstractMessageProcessor messageCallProcessor, @@ -235,7 +238,6 @@ public MainnetTransactionProcessor( final FeeMarket feeMarket, final CoinbaseFeePriceCalculator coinbaseFeePriceCalculator) { this.gasCalculator = gasCalculator; - this.transactionGasCalculator = transacitonGasCalculator; this.transactionValidator = transactionValidator; this.contractCreationProcessor = contractCreationProcessor; this.messageCallProcessor = messageCallProcessor; @@ -299,10 +301,27 @@ public TransactionProcessingResult processTransaction( previousBalance, sender.getBalance()); - final GasAndAccessedState gasAndAccessedState = - transactionGasCalculator.transactionIntrinsicGasCostAndAccessedState(transaction); - final Gas intrinsicGas = gasAndAccessedState.getGas(); - final Gas gasAvailable = Gas.of(transaction.getGasLimit()).minus(intrinsicGas); + List accessListEntries = transaction.getAccessList().orElse(List.of()); + // we need to keep a separate hash set of addresses in case they specify no storage. + // No-storage is a common pattern, especially for Externally Owned Accounts + Set
addressList = new HashSet<>(); + Multimap storageList = HashMultimap.create(); + int accessListStorageCount = 0; + for (var entry : accessListEntries) { + Address address = entry.getAddress(); + addressList.add(address); + List storageKeys = entry.getStorageKeys(); + storageList.putAll(address, storageKeys); + accessListStorageCount += storageKeys.size(); + } + + final Gas intrinsicGas = + gasCalculator.transactionIntrinsicGasCost( + transaction.getPayload(), transaction.isContractCreation()); + final Gas accessListGas = + gasCalculator.accessListGasCost(accessListEntries.size(), accessListStorageCount); + final Gas gasAvailable = + Gas.of(transaction.getGasLimit()).minus(intrinsicGas).minus(accessListGas); LOG.trace( "Gas available for execution {} = {} - {} (limit - intrinsic)", gasAvailable, @@ -337,8 +356,8 @@ public TransactionProcessingResult processTransaction( .miningBeneficiary(miningBeneficiary) .blockHashLookup(blockHashLookup) .contextVariables(contextVariablesBuilder.build()) - .accessListWarmAddresses(gasAndAccessedState.getAccessListAddressSet()) - .accessListWarmStorage(gasAndAccessedState.getAccessListStorageByAddress()); + .accessListWarmAddresses(addressList) + .accessListWarmStorage(storageList); final MessageFrame initialFrame; if (transaction.isContractCreation()) { @@ -354,6 +373,7 @@ public TransactionProcessingResult processTransaction( .code(new Code(transaction.getPayload())) .build(); } else { + @SuppressWarnings("OptionalGetWithoutIsPresent") // isContractCall tests isPresent final Address to = transaction.getTo().get(); final Optional maybeContract = Optional.ofNullable(worldState.get(to)); initialFrame = @@ -445,8 +465,7 @@ public TransactionProcessingResult processTransaction( LOG.error("Critical Exception Processing Transaction", re); return TransactionProcessingResult.invalid( ValidationResult.invalid( - TransactionInvalidReason.INTERNAL_ERROR, - "Internal Error in Besu - " + re.toString())); + TransactionInvalidReason.INTERNAL_ERROR, "Internal Error in Besu - " + re)); } } @@ -482,7 +501,7 @@ protected Gas refunded( final Gas maxRefundAllowance = Gas.of(transaction.getGasLimit()) .minus(gasRemaining) - .dividedBy(transactionGasCalculator.getMaxRefundQuotient()); + .dividedBy(gasCalculator.getMaxRefundQuotient()); final Gas refundAllowance = maxRefundAllowance.min(gasRefund); return gasRemaining.plus(refundAllowance); } 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 7c7903e464f..b13f959e32c 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 @@ -24,6 +24,7 @@ import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; import org.hyperledger.besu.evm.Gas; import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.gascalculator.GasCalculator; import org.hyperledger.besu.plugin.data.TransactionType; import java.math.BigInteger; @@ -38,7 +39,7 @@ */ public class MainnetTransactionValidator { - private final TransactionGasCalculator transactionGasCalculator; + private final GasCalculator gasCalculator; private final FeeMarket feeMarket; private final boolean disallowSignatureMalleability; @@ -50,12 +51,12 @@ public class MainnetTransactionValidator { private final boolean goQuorumCompatibilityMode; public MainnetTransactionValidator( - final TransactionGasCalculator transactionGasCalculator, + final GasCalculator gasCalculator, final boolean checkSignatureMalleability, final Optional chainId, final boolean goQuorumCompatibilityMode) { this( - transactionGasCalculator, + gasCalculator, checkSignatureMalleability, chainId, Set.of(TransactionType.FRONTIER), @@ -63,13 +64,13 @@ public MainnetTransactionValidator( } public MainnetTransactionValidator( - final TransactionGasCalculator transactionGasCalculator, + final GasCalculator gasCalculator, final boolean checkSignatureMalleability, final Optional chainId, final Set acceptedTransactionTypes, final boolean quorumCompatibilityMode) { this( - transactionGasCalculator, + gasCalculator, FeeMarket.legacy(), checkSignatureMalleability, chainId, @@ -78,13 +79,13 @@ public MainnetTransactionValidator( } public MainnetTransactionValidator( - final TransactionGasCalculator transactionGasCalculator, + final GasCalculator gasCalculator, final FeeMarket feeMarket, final boolean checkSignatureMalleability, final Optional chainId, final Set acceptedTransactionTypes, final boolean goQuorumCompatibilityMode) { - this.transactionGasCalculator = transactionGasCalculator; + this.gasCalculator = gasCalculator; this.feeMarket = feeMarket; this.disallowSignatureMalleability = checkSignatureMalleability; this.chainId = chainId; @@ -151,7 +152,10 @@ public ValidationResult validate( } final Gas intrinsicGasCost = - transactionGasCalculator.transactionIntrinsicGasCostAndAccessedState(transaction).getGas(); + gasCalculator + .transactionIntrinsicGasCost(transaction.getPayload(), transaction.isContractCreation()) + .plus( + transaction.getAccessList().map(gasCalculator::accessListGasCost).orElse(Gas.ZERO)); if (intrinsicGasCost.compareTo(Gas.of(transaction.getGasLimit())) > 0) { return ValidationResult.invalid( TransactionInvalidReason.INTRINSIC_GAS_EXCEEDS_GAS_LIMIT, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpec.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpec.java index f1f424df003..f2828012654 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpec.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpec.java @@ -36,8 +36,6 @@ public class ProtocolSpec { private final GasCalculator gasCalculator; - private final TransactionGasCalculator transactionGasCalculator; - private final GasLimitCalculator gasLimitCalculator; private final MainnetTransactionValidator transactionValidator; @@ -100,7 +98,6 @@ public class ProtocolSpec { * @param precompileContractRegistry all the pre-compiled contracts added * @param skipZeroBlockRewards should rewards be skipped if it is zero * @param gasCalculator the gas calculator to use. - * @param transactionGasCalculator the transaction gas calculator to use. * @param gasLimitCalculator the gas limit calculator to use. * @param feeMarket an {@link Optional} wrapping {@link FeeMarket} class if appropriate. * @param badBlockManager the cache to use to keep invalid blocks @@ -126,7 +123,6 @@ public ProtocolSpec( final PrecompileContractRegistry precompileContractRegistry, final boolean skipZeroBlockRewards, final GasCalculator gasCalculator, - final TransactionGasCalculator transactionGasCalculator, final GasLimitCalculator gasLimitCalculator, final FeeMarket feeMarket, final BadBlockManager badBlockManager, @@ -150,7 +146,6 @@ public ProtocolSpec( this.precompileContractRegistry = precompileContractRegistry; this.skipZeroBlockRewards = skipZeroBlockRewards; this.gasCalculator = gasCalculator; - this.transactionGasCalculator = transactionGasCalculator; this.gasLimitCalculator = gasLimitCalculator; this.feeMarket = feeMarket; this.badBlockManager = badBlockManager; @@ -315,15 +310,6 @@ public GasCalculator getGasCalculator() { return gasCalculator; } - /** - * Returns the transactionGasCalculator used in this specification. - * - * @return the transaction processing gas calculator - */ - public TransactionGasCalculator getTransactionGasCalculator() { - return transactionGasCalculator; - } - /** * Returns the gasLimitCalculator used in this specification. * diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java index a75d22a64f0..a1bcfb7cb04 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java @@ -45,7 +45,6 @@ public class ProtocolSpecBuilder { private Supplier gasCalculatorBuilder; - private TransactionGasCalculator transactionGasCalculator; private GasLimitCalculator gasLimitCalculator; private Wei blockReward; private boolean skipZeroBlockRewards; @@ -53,8 +52,7 @@ public class ProtocolSpecBuilder { private AbstractBlockProcessor.TransactionReceiptFactory transactionReceiptFactory; private DifficultyCalculator difficultyCalculator; private Function evmBuilder; - private Function - transactionValidatorBuilder; + private Function transactionValidatorBuilder; private Function blockHeaderValidatorBuilder; private Function ommerHeaderValidatorBuilder; private Function blockBodyValidatorBuilder; @@ -81,12 +79,6 @@ public ProtocolSpecBuilder gasCalculator(final Supplier gasCalcul return this; } - public ProtocolSpecBuilder transactionGasCalculator( - final TransactionGasCalculator transactionGasCalculator) { - this.transactionGasCalculator = transactionGasCalculator; - return this; - } - public ProtocolSpecBuilder gasLimitCalculator(final GasLimitCalculator gasLimitCalculator) { this.gasLimitCalculator = gasLimitCalculator; return this; @@ -124,8 +116,7 @@ public ProtocolSpecBuilder evmBuilder(final Function evmBuil } public ProtocolSpecBuilder transactionValidatorBuilder( - final Function - transactionValidatorBuilder) { + final Function transactionValidatorBuilder) { this.transactionValidatorBuilder = transactionValidatorBuilder; return this; } @@ -246,7 +237,6 @@ public ProtocolSpecBuilder powHasher(final PoWHasher powHasher) { public ProtocolSpec build(final ProtocolSchedule protocolSchedule) { checkNotNull(gasCalculatorBuilder, "Missing gasCalculator"); - checkNotNull(transactionGasCalculator, "Missing transactionGasCalculator"); checkNotNull(gasLimitCalculator, "Missing gasLimitCalculator"); checkNotNull(evmBuilder, "Missing operation registry"); checkNotNull(transactionValidatorBuilder, "Missing transaction validator"); @@ -277,7 +267,7 @@ public ProtocolSpec build(final ProtocolSchedule protocolSchedule) { final PrecompiledContractConfiguration precompiledContractConfiguration = new PrecompiledContractConfiguration(gasCalculator, privacyParameters); final MainnetTransactionValidator transactionValidator = - transactionValidatorBuilder.apply(transactionGasCalculator); + transactionValidatorBuilder.apply(gasCalculator); final AbstractMessageProcessor contractCreationProcessor = contractCreationProcessorBuilder.apply(gasCalculator, evm); final PrecompileContractRegistry precompileContractRegistry = @@ -286,11 +276,7 @@ public ProtocolSpec build(final ProtocolSchedule protocolSchedule) { messageCallProcessorBuilder.apply(evm, precompileContractRegistry); final MainnetTransactionProcessor transactionProcessor = transactionProcessorBuilder.apply( - gasCalculator, - transactionGasCalculator, - transactionValidator, - contractCreationProcessor, - messageCallProcessor); + gasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor); final BlockHeaderValidator blockHeaderValidator = blockHeaderValidatorBuilder @@ -320,7 +306,7 @@ public ProtocolSpec build(final ProtocolSchedule protocolSchedule) { privateTransactionValidatorBuilder.apply(); privateTransactionProcessor = privateTransactionProcessorBuilder.apply( - transactionGasCalculator, + gasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor, @@ -381,7 +367,6 @@ public ProtocolSpec build(final ProtocolSchedule protocolSchedule) { precompileContractRegistry, skipZeroBlockRewards, gasCalculator, - transactionGasCalculator, gasLimitCalculator, feeMarket, badBlockManager, @@ -391,7 +376,6 @@ public ProtocolSpec build(final ProtocolSchedule protocolSchedule) { public interface TransactionProcessorBuilder { MainnetTransactionProcessor apply( GasCalculator gasCalculator, - TransactionGasCalculator transactionGasCalculator, MainnetTransactionValidator transactionValidator, AbstractMessageProcessor contractCreationProcessor, AbstractMessageProcessor messageCallProcessor); @@ -399,7 +383,7 @@ MainnetTransactionProcessor apply( public interface PrivateTransactionProcessorBuilder { PrivateTransactionProcessor apply( - TransactionGasCalculator transactionGasCalculator, + GasCalculator transactionGasCalculator, MainnetTransactionValidator transactionValidator, AbstractMessageProcessor contractCreationProcessor, AbstractMessageProcessor messageCallProcessor, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/TransactionGasCalculator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/TransactionGasCalculator.java deleted file mode 100644 index b5ddc8c7733..00000000000 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/TransactionGasCalculator.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright contributors to Hyperledger Besu - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.ethereum.mainnet; - -import org.hyperledger.besu.ethereum.core.GasAndAccessedState; -import org.hyperledger.besu.ethereum.core.Transaction; -import org.hyperledger.besu.evm.Gas; -import org.hyperledger.besu.evm.gascalculator.GasCalculator; - -/** - * Provides various gas cost lookups and calculations used during transaction processing outside the - * EVM. - * - *

The {@code TransactionGasCalculator} is meant to encapsulate all {@link Gas}-related - * calculations not needed during EVM execution or caused by EVM execution. EVM Relevant or caused - * gas calculations live in the {@link GasCalculator}. Current calculations revolve around block - * encoding of transactions, account creation, how much refund to apply, and private transaction gas - * reservations. - */ -public interface TransactionGasCalculator { - - /** - * Returns a {@link Transaction}s intrinsic gas cost, i.e. the cost deriving from its encoded - * binary representation when stored on-chain. - * - * @param transaction The transaction - * @return the transaction's intrinsic gas cost - */ - GasAndAccessedState transactionIntrinsicGasCostAndAccessedState(Transaction transaction); - - /** - * A measure of the maximum amount of refunded gas a transaction will be credited with. - * - * @return the quotient of the equation `txGasCost / refundQuotient`. - */ - default long getMaxRefundQuotient() { - return 2; - } - - /** - * Maximum Cost of a Privacy Marker Transaction (PMT). See {@link - * org.hyperledger.besu.plugin.services.privacy.PrivateMarkerTransactionFactory} - * - * @return the maximum gas cost - */ - // what would be the gas for a PMT with hash of all non-zeros - Gas getMaximumPmtCost(); -} diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/OnChainPrivacyPrecompiledContract.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/OnChainPrivacyPrecompiledContract.java index aeee0688d75..8f53c56b514 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/OnChainPrivacyPrecompiledContract.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/OnChainPrivacyPrecompiledContract.java @@ -346,8 +346,7 @@ protected boolean onChainPrivacyGroupVersionMatches( final Bytes32 version) { final Optional contractVersionResult = onchainPrivacyGroupContract.getVersion(privacyGroupId.toBase64String(), Optional.empty()); - final boolean versionEqual = - contractVersionResult.map(version::equals).orElse(false); + final boolean versionEqual = contractVersionResult.map(version::equals).orElse(false); if (!versionEqual) { LOG.debug( diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateTransaction.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateTransaction.java index 69794bc043a..4fd2e4ecd83 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateTransaction.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateTransaction.java @@ -16,8 +16,6 @@ import static com.google.common.base.Preconditions.checkState; import static org.hyperledger.besu.crypto.Hash.keccak256; -import static org.hyperledger.besu.ethereum.core.PrivacyParameters.ONCHAIN_PRIVACY_PROXY; -import static org.hyperledger.besu.ethereum.privacy.group.OnChainGroupManagement.REMOVE_PARTICIPANT_METHOD_SIGNATURE; import static org.hyperledger.besu.plugin.data.Restriction.RESTRICTED; import static org.hyperledger.besu.plugin.data.Restriction.UNRESTRICTED; import static org.hyperledger.besu.plugin.data.Restriction.UNSUPPORTED; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateTransactionProcessor.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateTransactionProcessor.java index ef985c48a90..0ee3a4dac62 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateTransactionProcessor.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/privacy/PrivateTransactionProcessor.java @@ -21,7 +21,6 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.mainnet.MainnetTransactionValidator; -import org.hyperledger.besu.ethereum.mainnet.TransactionGasCalculator; import org.hyperledger.besu.ethereum.mainnet.ValidationResult; import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; @@ -30,6 +29,7 @@ import org.hyperledger.besu.evm.Gas; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.gascalculator.GasCalculator; import org.hyperledger.besu.evm.processor.AbstractMessageProcessor; import org.hyperledger.besu.evm.tracing.OperationTracer; import org.hyperledger.besu.evm.worldstate.WorldUpdater; @@ -49,7 +49,7 @@ public class PrivateTransactionProcessor { private static final Logger LOG = LogManager.getLogger(); - private final TransactionGasCalculator transactionGasCalculator; + private final GasCalculator gasCalculator; @SuppressWarnings("unused") private final MainnetTransactionValidator transactionValidator; @@ -66,14 +66,14 @@ public class PrivateTransactionProcessor { private final boolean clearEmptyAccounts; public PrivateTransactionProcessor( - final TransactionGasCalculator transactionGasCalculator, + final GasCalculator gasCalculator, final MainnetTransactionValidator transactionValidator, final AbstractMessageProcessor contractCreationProcessor, final AbstractMessageProcessor messageCallProcessor, final boolean clearEmptyAccounts, final int maxStackSize, final PrivateTransactionValidator privateTransactionValidator) { - this.transactionGasCalculator = transactionGasCalculator; + this.gasCalculator = gasCalculator; this.transactionValidator = transactionValidator; this.contractCreationProcessor = contractCreationProcessor; this.messageCallProcessor = messageCallProcessor; @@ -227,7 +227,7 @@ private Gas refunded(final Transaction transaction, final Gas gasRemaining, fina final Gas maxRefundAllowance = Gas.of(transaction.getGasLimit()) .minus(gasRemaining) - .dividedBy(transactionGasCalculator.getMaxRefundQuotient()); + .dividedBy(gasCalculator.getMaxRefundQuotient()); final Gas refundAllowance = maxRefundAllowance.min(gasRefund); return gasRemaining.plus(refundAllowance); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/GoQuorumKeyValueStoragePrefixedKeyBlockchainStorage.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/GoQuorumKeyValueStoragePrefixedKeyBlockchainStorage.java index 8744e650304..55254d7ebd3 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/GoQuorumKeyValueStoragePrefixedKeyBlockchainStorage.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/storage/keyvalue/GoQuorumKeyValueStoragePrefixedKeyBlockchainStorage.java @@ -17,8 +17,8 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.rlp.RLP; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.plugin.services.storage.KeyValueStorage; import org.hyperledger.besu.plugin.services.storage.KeyValueStorageTransaction; diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java index cfd447e28e7..5652bb55e19 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/transaction/TransactionSimulator.java @@ -234,7 +234,7 @@ public Optional process( // fail. if (GoQuorumOptions.goQuorumCompatibilityMode && value.isZero()) { Gas privateGasEstimateAndState = - protocolSpec.getTransactionGasCalculator().getMaximumPmtCost(); + protocolSpec.getGasCalculator().getMaximumTransactionCost(64); if (privateGasEstimateAndState.toLong() > result.getEstimateGasUsedByTransaction()) { // modify the result to have the larger estimate TransactionProcessingResult resultPmt = diff --git a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockDataGenerator.java b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockDataGenerator.java index cf9d8bb0b93..dea79f9cd7d 100644 --- a/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockDataGenerator.java +++ b/ethereum/core/src/test-support/java/org/hyperledger/besu/ethereum/core/BlockDataGenerator.java @@ -29,6 +29,7 @@ import org.hyperledger.besu.ethereum.mainnet.BodyValidation; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive; +import org.hyperledger.besu.evm.AccessListEntry; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.account.MutableAccount; import org.hyperledger.besu.evm.log.Log; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/LogRollingTests.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/LogRollingTests.java index fce7a7e4463..5cb81456140 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/LogRollingTests.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/bonsai/LogRollingTests.java @@ -26,11 +26,11 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPInput; import org.hyperledger.besu.ethereum.storage.keyvalue.KeyValueSegmentIdentifier; import org.hyperledger.besu.evm.account.MutableAccount; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.evm.worldstate.WorldUpdater; import org.hyperledger.besu.plugin.services.storage.KeyValueStorage; import org.hyperledger.besu.plugin.services.storage.KeyValueStorageTransaction; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionBuilderTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionBuilderTest.java index 7c01cfb3d25..87e6ba758b7 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionBuilderTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionBuilderTest.java @@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat; import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.evm.AccessListEntry; import org.hyperledger.besu.plugin.data.TransactionType; import java.util.List; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionEIP1559Test.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionEIP1559Test.java index d30ff1366f7..2a2211b9380 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionEIP1559Test.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/core/TransactionEIP1559Test.java @@ -21,6 +21,7 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.ethereum.rlp.RLP; +import org.hyperledger.besu.evm.AccessListEntry; import java.math.BigInteger; import java.util.List; @@ -66,8 +67,8 @@ public void buildEip1559Transaction() { final String raw = out.encoded().toHexString(); final Transaction decoded = Transaction.readFrom(RLP.input(Bytes.fromHexString(raw))); System.out.println(decoded); - System.out.println(decoded.getAccessList().orElseThrow().get(0).getAddress().toHexString()); - System.out.println(decoded.getAccessList().orElseThrow().get(0).getStorageKeys()); + System.out.println(decoded.getAccessList().orElseThrow().get(0).getAddressString()); + System.out.println(decoded.getAccessList().orElseThrow().get(0).getStorageKeysString()); } private static KeyPair keyPair(final String privateKey) { 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 14ed01d60e4..3b6a9445619 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 @@ -17,6 +17,9 @@ import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.rlp.RLP; import org.hyperledger.besu.evm.Gas; +import org.hyperledger.besu.evm.gascalculator.FrontierGasCalculator; +import org.hyperledger.besu.evm.gascalculator.GasCalculator; +import org.hyperledger.besu.evm.gascalculator.IstanbulGasCalculator; import java.util.Arrays; import java.util.Collection; @@ -31,23 +34,21 @@ @RunWith(Parameterized.class) public class IntrinsicGasTest { - private final TransactionGasCalculator transactionGasCalculator; + private final GasCalculator gasCalculator; private final Gas expectedGas; private final String txRlp; public IntrinsicGasTest( - final TransactionGasCalculator transactionGasCalculator, - final Gas expectedGas, - final String txRlp) { - this.transactionGasCalculator = transactionGasCalculator; + final GasCalculator gasCalculator, final Gas expectedGas, final String txRlp) { + this.gasCalculator = gasCalculator; this.expectedGas = expectedGas; this.txRlp = txRlp; } @Parameters public static Collection data() { - final TransactionGasCalculator frontier = new FrontierTransactionGasCalculator(); - final TransactionGasCalculator istanbul = new IstanbulTransactionGasCalculator(); + final GasCalculator frontier = new FrontierGasCalculator(); + final GasCalculator istanbul = new IstanbulGasCalculator(); return Arrays.asList( new Object[][] { // EnoughGAS @@ -112,7 +113,7 @@ public static Collection data() { public void validateGasCost() { Transaction t = Transaction.readFrom(RLP.input(Bytes.fromHexString(txRlp))); Assertions.assertThat( - transactionGasCalculator.transactionIntrinsicGasCostAndAccessedState(t).getGas()) + gasCalculator.transactionIntrinsicGasCost(t.getPayload(), t.isContractCreation())) .isEqualTo(expectedGas); } } diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/KeccakHasherTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/KeccakHasherTest.java index 9ea4d8405b4..ab5c3a75c88 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/KeccakHasherTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/KeccakHasherTest.java @@ -19,8 +19,8 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.core.SealableBlockHeader; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.apache.tuweni.bytes.Bytes; import org.junit.Test; diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java index 02d19274e70..10a466ed456 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionProcessorTest.java @@ -45,7 +45,6 @@ public class MainnetTransactionProcessorTest { private MainnetTransactionProcessor transactionProcessor; @Mock private GasCalculator gasCalculator; - @Mock private TransactionGasCalculator transactionGasCalculator; @Mock private MainnetTransactionValidator transactionValidator; @Mock private AbstractMessageProcessor contractCreationProcessor; @Mock private AbstractMessageProcessor messageCallProcessor; @@ -61,7 +60,6 @@ public void before() { transactionProcessor = new MainnetTransactionProcessor( gasCalculator, - transactionGasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor, diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidatorTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidatorTest.java index 1192f39a5d5..965e2df16b6 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidatorTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/MainnetTransactionValidatorTest.java @@ -31,7 +31,6 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; -import org.hyperledger.besu.ethereum.core.GasAndAccessedState; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionFilter; import org.hyperledger.besu.ethereum.core.TransactionTestFixture; @@ -39,6 +38,7 @@ import org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason; import org.hyperledger.besu.evm.Gas; import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.gascalculator.GasCalculator; import org.hyperledger.besu.plugin.data.TransactionType; import java.math.BigInteger; @@ -64,7 +64,7 @@ public class MainnetTransactionValidatorTest { private static final TransactionValidationParams transactionValidationParams = TransactionValidationParams.processingBlockParams; - @Mock private TransactionGasCalculator transactionGasCalculator; + @Mock private GasCalculator gasCalculator; private final Transaction basicTransaction = new TransactionTestFixture() @@ -77,14 +77,13 @@ public class MainnetTransactionValidatorTest { public void shouldRejectTransactionIfIntrinsicGasExceedsGasLimit() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode); + gasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode); final Transaction transaction = new TransactionTestFixture() .gasLimit(10) .chainId(Optional.empty()) .createTransaction(senderKeys); - when(transactionGasCalculator.transactionIntrinsicGasCostAndAccessedState(transaction)) - .thenReturn(new GasAndAccessedState(Gas.of(50))); + when(gasCalculator.transactionIntrinsicGasCost(any(), anyBoolean())).thenReturn(Gas.of(50)); assertThat(validator.validate(transaction, Optional.empty(), transactionValidationParams)) .isEqualTo( @@ -95,7 +94,7 @@ public void shouldRejectTransactionIfIntrinsicGasExceedsGasLimit() { public void shouldRejectTransactionWhenTransactionHasChainIdAndValidatorDoesNot() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode); + gasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode); assertThat(validator.validate(basicTransaction, Optional.empty(), transactionValidationParams)) .isEqualTo( ValidationResult.invalid( @@ -106,7 +105,7 @@ public void shouldRejectTransactionWhenTransactionHasChainIdAndValidatorDoesNot( public void shouldRejectTransactionWhenTransactionHasIncorrectChainId() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, + gasCalculator, false, Optional.of(BigInteger.valueOf(2)), defaultGoQuorumCompatibilityMode); @@ -118,10 +117,7 @@ public void shouldRejectTransactionWhenTransactionHasIncorrectChainId() { public void shouldRejectTransactionWhenSenderAccountDoesNotExist() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, - false, - Optional.of(BigInteger.ONE), - defaultGoQuorumCompatibilityMode); + gasCalculator, false, Optional.of(BigInteger.ONE), defaultGoQuorumCompatibilityMode); assertThat(validator.validateForSender(basicTransaction, null, false)) .isEqualTo(ValidationResult.invalid(TransactionInvalidReason.UPFRONT_COST_EXCEEDS_BALANCE)); } @@ -130,10 +126,7 @@ public void shouldRejectTransactionWhenSenderAccountDoesNotExist() { public void shouldRejectTransactionWhenTransactionNonceBelowAccountNonce() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, - false, - Optional.of(BigInteger.ONE), - defaultGoQuorumCompatibilityMode); + gasCalculator, false, Optional.of(BigInteger.ONE), defaultGoQuorumCompatibilityMode); final Account account = accountWithNonce(basicTransaction.getNonce() + 1); assertThat(validator.validateForSender(basicTransaction, account, false)) @@ -145,10 +138,7 @@ public void shouldRejectTransactionWhenTransactionNonceBelowAccountNonce() { shouldRejectTransactionWhenTransactionNonceAboveAccountNonceAndFutureNonceIsNotAllowed() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, - false, - Optional.of(BigInteger.ONE), - defaultGoQuorumCompatibilityMode); + gasCalculator, false, Optional.of(BigInteger.ONE), defaultGoQuorumCompatibilityMode); final Account account = accountWithNonce(basicTransaction.getNonce() - 1); assertThat(validator.validateForSender(basicTransaction, account, false)) @@ -160,10 +150,7 @@ public void shouldRejectTransactionWhenTransactionNonceBelowAccountNonce() { shouldAcceptTransactionWhenTransactionNonceAboveAccountNonceAndFutureNonceIsAllowed() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, - false, - Optional.of(BigInteger.ONE), - defaultGoQuorumCompatibilityMode); + gasCalculator, false, Optional.of(BigInteger.ONE), defaultGoQuorumCompatibilityMode); final Account account = accountWithNonce(basicTransaction.getNonce() - 1); assertThat(validator.validateForSender(basicTransaction, account, true)) @@ -174,10 +161,7 @@ public void shouldRejectTransactionWhenTransactionNonceBelowAccountNonce() { public void shouldRejectTransactionWhenNonceExceedsMaximumAllowedNonce() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, - false, - Optional.of(BigInteger.ONE), - defaultGoQuorumCompatibilityMode); + gasCalculator, false, Optional.of(BigInteger.ONE), defaultGoQuorumCompatibilityMode); final Transaction transaction = new TransactionTestFixture().nonce(11).createTransaction(senderKeys); @@ -191,10 +175,7 @@ public void shouldRejectTransactionWhenNonceExceedsMaximumAllowedNonce() { public void transactionWithNullSenderCanBeValidIfGasPriceAndValueIsZero() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, - false, - Optional.of(BigInteger.ONE), - defaultGoQuorumCompatibilityMode); + gasCalculator, false, Optional.of(BigInteger.ONE), defaultGoQuorumCompatibilityMode); final TransactionTestFixture builder = new TransactionTestFixture(); final KeyPair senderKeyPair = SIGNATURE_ALGORITHM.get().generateKeyPair(); @@ -209,7 +190,7 @@ public void transactionWithNullSenderCanBeValidIfGasPriceAndValueIsZero() { public void shouldRejectTransactionIfAccountIsNotEOA() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode); + gasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode); validator.setTransactionFilter(transactionFilter(false)); Account invalidEOA = @@ -225,7 +206,7 @@ public void shouldRejectTransactionIfAccountIsNotEOA() { public void shouldRejectTransactionIfAccountIsNotPermitted() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode); + gasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode); validator.setTransactionFilter(transactionFilter(false)); assertThat(validator.validateForSender(basicTransaction, accountWithNonce(0), true)) @@ -236,7 +217,7 @@ public void shouldRejectTransactionIfAccountIsNotPermitted() { public void shouldAcceptValidTransactionIfAccountIsPermitted() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode); + gasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode); validator.setTransactionFilter(transactionFilter(true)); assertThat(validator.validateForSender(basicTransaction, accountWithNonce(0), true)) @@ -247,7 +228,7 @@ public void shouldAcceptValidTransactionIfAccountIsPermitted() { public void shouldRejectTransactionWithMaxFeeTimesGasLimitGreaterThanBalance() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode); + gasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode); validator.setTransactionFilter(transactionFilter(true)); assertThat( @@ -272,7 +253,7 @@ public void shouldRejectTransactionWithMaxFeeTimesGasLimitGreaterThanBalance() { public void shouldRejectTransactionWithMaxPriorityFeeGreaterThanMaxFee() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, + gasCalculator, FeeMarket.london(0L), false, Optional.of(BigInteger.ONE), @@ -316,7 +297,7 @@ public void shouldPropagateCorrectStateChangeParamToTransactionFilter() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode); + gasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode); validator.setTransactionFilter(transactionFilter); final TransactionValidationParams validationParams = @@ -334,7 +315,7 @@ public void shouldNotCheckAccountPermissionIfBothValidationParamsCheckPermission final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode); + gasCalculator, false, Optional.empty(), defaultGoQuorumCompatibilityMode); validator.setTransactionFilter(transactionFilter); final TransactionValidationParams validationParams = @@ -355,7 +336,7 @@ public void shouldNotCheckAccountPermissionIfBothValidationParamsCheckPermission public void shouldAcceptOnlyTransactionsInAcceptedTransactionTypes() { final MainnetTransactionValidator frontierValidator = new MainnetTransactionValidator( - transactionGasCalculator, + gasCalculator, FeeMarket.legacy(), false, Optional.of(BigInteger.ONE), @@ -364,7 +345,7 @@ public void shouldAcceptOnlyTransactionsInAcceptedTransactionTypes() { final MainnetTransactionValidator eip1559Validator = new MainnetTransactionValidator( - transactionGasCalculator, + gasCalculator, FeeMarket.london(0L), false, Optional.of(BigInteger.ONE), @@ -384,8 +365,7 @@ public void shouldAcceptOnlyTransactionsInAcceptedTransactionTypes() { frontierValidator.validate(transaction, Optional.empty(), transactionValidationParams)) .isEqualTo(ValidationResult.invalid(TransactionInvalidReason.INVALID_TRANSACTION_FORMAT)); - when(transactionGasCalculator.transactionIntrinsicGasCostAndAccessedState(transaction)) - .thenReturn(new GasAndAccessedState(Gas.of(0))); + when(gasCalculator.transactionIntrinsicGasCost(any(), anyBoolean())).thenReturn(Gas.of(0)); assertThat(eip1559Validator.validate(transaction, Optional.of(1L), transactionValidationParams)) .isEqualTo(ValidationResult.valid()); @@ -395,7 +375,7 @@ public void shouldAcceptOnlyTransactionsInAcceptedTransactionTypes() { public void shouldRejectTransactionIfEIP1559TransactionGasPriceLessBaseFee() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, + gasCalculator, FeeMarket.london(0L), false, Optional.of(BigInteger.ONE), @@ -417,7 +397,7 @@ public void shouldRejectTransactionIfEIP1559TransactionGasPriceLessBaseFee() { public void shouldAcceptValidEIP1559() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, + gasCalculator, FeeMarket.london(0L), false, Optional.of(BigInteger.ONE), @@ -431,8 +411,7 @@ public void shouldAcceptValidEIP1559() { .chainId(Optional.of(BigInteger.ONE)) .createTransaction(senderKeys); final Optional basefee = Optional.of(150000L); - when(transactionGasCalculator.transactionIntrinsicGasCostAndAccessedState(transaction)) - .thenReturn(new GasAndAccessedState(Gas.of(50))); + when(gasCalculator.transactionIntrinsicGasCost(any(), anyBoolean())).thenReturn(Gas.of(50)); assertThat(validator.validate(transaction, basefee, transactionValidationParams)) .isEqualTo(ValidationResult.valid()); @@ -442,7 +421,7 @@ public void shouldAcceptValidEIP1559() { public void shouldValidate1559TransactionWithPriceLowerThanBaseFeeForTransactionPool() { final MainnetTransactionValidator validator = new MainnetTransactionValidator( - transactionGasCalculator, + gasCalculator, FeeMarket.london(0L), false, Optional.of(BigInteger.ONE), @@ -455,8 +434,7 @@ public void shouldValidate1559TransactionWithPriceLowerThanBaseFeeForTransaction .type(TransactionType.EIP1559) .chainId(Optional.of(BigInteger.ONE)) .createTransaction(senderKeys); - when(transactionGasCalculator.transactionIntrinsicGasCostAndAccessedState(transaction)) - .thenReturn(new GasAndAccessedState(Gas.of(50))); + when(gasCalculator.transactionIntrinsicGasCost(any(), anyBoolean())).thenReturn(Gas.of(50)); assertThat( validator.validate( @@ -467,7 +445,7 @@ public void shouldValidate1559TransactionWithPriceLowerThanBaseFeeForTransaction @Test public void goQuorumCompatibilityModeRejectNonZeroGasPrice() { final MainnetTransactionValidator validator = - new MainnetTransactionValidator(transactionGasCalculator, false, Optional.empty(), true); + new MainnetTransactionValidator(gasCalculator, false, Optional.empty(), true); final Transaction transaction = new TransactionTestFixture() .gasPrice(Wei.ONE) @@ -489,15 +467,14 @@ public void goQuorumCompatibilityModeRejectNonZeroGasPrice() { @Test public void goQuorumCompatibilityModeSuccessZeroGasPrice() { final MainnetTransactionValidator validator = - new MainnetTransactionValidator(transactionGasCalculator, false, Optional.empty(), true); + new MainnetTransactionValidator(gasCalculator, false, Optional.empty(), true); final Transaction transaction = new TransactionTestFixture() .gasPrice(Wei.ZERO) .chainId(Optional.empty()) .createTransaction(senderKeys); - when(transactionGasCalculator.transactionIntrinsicGasCostAndAccessedState(transaction)) - .thenReturn(new GasAndAccessedState(Gas.of(50))); + when(gasCalculator.transactionIntrinsicGasCost(any(), anyBoolean())).thenReturn(Gas.of(50)); assertThat( validator diff --git a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/VMReferenceTest.java b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/VMReferenceTest.java index 45fc3a40c51..c8773663905 100644 --- a/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/VMReferenceTest.java +++ b/ethereum/core/src/test/java/org/hyperledger/besu/ethereum/vm/VMReferenceTest.java @@ -50,16 +50,16 @@ public class VMReferenceTest extends AbstractRetryingTest { /** The path where all of the VM test configuration files live. */ private static final String[] TEST_CONFIG_FILE_DIR_PATHS = { "LegacyTests/Constantinople/VMTests/vmArithmeticTest", -// "LegacyTests/Constantinople/VMTests/vmBitwiseLogicOperation", -// "LegacyTests/Constantinople/VMTests/vmBlockInfoTest", -// "LegacyTests/Constantinople/VMTests/vmEnvironmentalInfo", -// "LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", -// "LegacyTests/Constantinople/VMTests/vmLogTest", -// "LegacyTests/Constantinople/VMTests/vmPushDupSwapTest", -// "LegacyTests/Constantinople/VMTests/vmRandomTest", -// "LegacyTests/Constantinople/VMTests/vmSha3Test", -// "LegacyTests/Constantinople/VMTests/vmTests", -// "LegacyTests/Constantinople/VMTests/vmSystemOperations" + // "LegacyTests/Constantinople/VMTests/vmBitwiseLogicOperation", + // "LegacyTests/Constantinople/VMTests/vmBlockInfoTest", + // "LegacyTests/Constantinople/VMTests/vmEnvironmentalInfo", + // "LegacyTests/Constantinople/VMTests/vmIOandFlowOperations", + // "LegacyTests/Constantinople/VMTests/vmLogTest", + // "LegacyTests/Constantinople/VMTests/vmPushDupSwapTest", + // "LegacyTests/Constantinople/VMTests/vmRandomTest", + // "LegacyTests/Constantinople/VMTests/vmSha3Test", + // "LegacyTests/Constantinople/VMTests/vmTests", + // "LegacyTests/Constantinople/VMTests/vmSystemOperations" }; // The ignored test cases fall into two categories: diff --git a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/RequestIdMessageTest.java b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/RequestIdMessageTest.java index 1dd2ab0c692..65df8714fd1 100644 --- a/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/RequestIdMessageTest.java +++ b/ethereum/eth/src/test/java/org/hyperledger/besu/ethereum/eth/messages/RequestIdMessageTest.java @@ -32,11 +32,11 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.Difficulty; import org.hyperledger.besu.ethereum.core.LogWithMetadata; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.TransactionReceipt; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.evm.log.LogTopic; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.plugin.data.TransactionType; import java.io.IOException; diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java index 922f1b4d38a..3c115349d7e 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java @@ -24,7 +24,6 @@ import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.core.Difficulty; -import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.mainnet.MainnetBlockHeaderFunctions; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; @@ -33,6 +32,7 @@ import org.hyperledger.besu.evm.EVM; import org.hyperledger.besu.evm.Gas; import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.log.LogsBloomFilter; import org.hyperledger.besu.evm.precompile.PrecompileContractRegistry; import org.hyperledger.besu.evm.processor.MessageCallProcessor; import org.hyperledger.besu.evm.tracing.OperationTracer; @@ -282,17 +282,26 @@ public void run() { final Gas intrinsicGasCost = protocolSpec - .getTransactionGasCalculator() - .transactionIntrinsicGasCostAndAccessedState(tx) - .getGas(); + .getGasCalculator() + .transactionIntrinsicGasCost(tx.getPayload(), tx.isContractCreation()); + final Gas accessListCost = + tx.getAccessList() + .map(list -> protocolSpec.getGasCalculator().accessListGasCost(list)) + .orElse(Gas.ZERO); final Gas evmGas = gas.minus(messageFrame.getRemainingGas()); out.println(); out.println( new JsonObject() .put("gasUser", evmGas.asUInt256().toShortHexString()) .put("timens", lastTime) - // .put("time", lastTime / 1000) - .put("gasTotal", evmGas.plus(intrinsicGasCost).asUInt256().toShortHexString())); + .put("time", lastTime / 1000) + .put( + "gasTotal", + evmGas + .plus(intrinsicGasCost) + .plus(accessListCost) + .asUInt256() + .toShortHexString())); } } lastTime = stopwatch.elapsed().toNanos(); diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/StateTestSubCommand.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/StateTestSubCommand.java index d8a76916999..86b11c96a94 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/StateTestSubCommand.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/StateTestSubCommand.java @@ -50,6 +50,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; import com.fasterxml.jackson.core.JsonParser.Feature; import com.fasterxml.jackson.core.JsonProcessingException; @@ -216,7 +217,7 @@ private void traceTestSpecs(final String test, final List storageKeys) { public static AccessListEntry createAccessListEntry( @JsonProperty("address") final Address address, @JsonProperty("storageKeys") final List storageKeys) { - return new AccessListEntry(address, - storageKeys.stream().map(Bytes32::fromHexString).collect(Collectors.toList())); + return new AccessListEntry( + address, storageKeys.stream().map(Bytes32::fromHexString).collect(Collectors.toList())); } + @JsonIgnore public Address getAddress() { return address; } @JsonIgnore - public List getStorageKeysBytes() { + public List getStorageKeys() { return storageKeys; } - public List getStorageKeys() { + @JsonProperty("address") + public String getAddressString() { + return address.toHexString(); + } + + @JsonProperty("storageKeys") + public List getStorageKeysString() { return storageKeys.stream().map(Bytes::toHexString).collect(Collectors.toList()); } } diff --git a/evm/src/main/java/org/hyperledger/besu/evm/Gas.java b/evm/src/main/java/org/hyperledger/besu/evm/Gas.java index 18f09eac238..9aaf8cb3a22 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/Gas.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/Gas.java @@ -16,8 +16,8 @@ import org.hyperledger.besu.datatypes.Wei; -import javax.annotation.concurrent.Immutable; import java.math.BigInteger; +import javax.annotation.concurrent.Immutable; import com.google.common.primitives.Longs; import org.apache.tuweni.bytes.Bytes; diff --git a/evm/src/main/java/org/hyperledger/besu/evm/frame/Memory.java b/evm/src/main/java/org/hyperledger/besu/evm/frame/Memory.java index 6442ff13cc3..aa523081e30 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/frame/Memory.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/frame/Memory.java @@ -244,9 +244,9 @@ public void setBytes( * copied and so never fails. * * @param location the location in memory at which to start copying the bytes of {@code value}. - * @param numBytes the number of bytes to set in memory. Note that this value may differ from {@code - * value.size()}: if {@code numBytes < value.size()} bytes, only {@code numBytes} will be - * copied from {@code value}; if {@code numBytes > value.size()}, then only the bytes in + * @param numBytes the number of bytes to set in memory. Note that this value may differ from + * {@code value.size()}: if {@code numBytes < value.size()} bytes, only {@code numBytes} will + * be copied from {@code value}; if {@code numBytes > value.size()}, then only the bytes in * {@code value} will be copied, but the memory will be expanded if necessary to cover {@code * numBytes} (in other words, {@link #getActiveWords()} will return a value consistent with * having set {@code numBytes} bytes, even if less than that have been concretely set due to diff --git a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/BerlinGasCalculator.java b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/BerlinGasCalculator.java index ed6eba921d3..652cd18e465 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/BerlinGasCalculator.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/BerlinGasCalculator.java @@ -34,6 +34,7 @@ public class BerlinGasCalculator extends IstanbulGasCalculator { private static final Gas COLD_SLOAD_COST = Gas.of(2100); private static final Gas COLD_ACCOUNT_ACCESS_COST = Gas.of(2600); private static final Gas WARM_STORAGE_READ_COST = Gas.of(100); + private static final Gas ACCESS_LIST_ADDRESS_COST = Gas.of(2400); protected static final Gas ACCESS_LIST_STORAGE_COST = Gas.of(1900); // redefinitions for EIP-2929 @@ -61,6 +62,13 @@ public BerlinGasCalculator() { this(BLAKE2B_F_COMPRESSION.toArrayUnsafe()[19]); } + @Override + public Gas accessListGasCost(final int addresses, final int storageSlots) { + return ACCESS_LIST_ADDRESS_COST + .times(addresses) + .plus(ACCESS_LIST_STORAGE_COST.times(storageSlots)); + } + @Override public boolean isPrecompile(final Address address) { final byte[] addressBytes = address.toArrayUnsafe(); 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 bad37c76a5d..9b450e10bdc 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 @@ -29,6 +29,16 @@ public class FrontierGasCalculator implements GasCalculator { + private static final Gas TX_DATA_ZERO_COST = Gas.of(4L); + + private static final Gas TX_DATA_NON_ZERO_COST = Gas.of(68L); + + private static final Gas TX_BASE_COST = Gas.of(21_000L); + + private static final Gas TX_CREATE_EXTRA_COST = Gas.of(0L); + + private static final Gas CODE_DEPOSIT_BYTE_COST = Gas.of(200L); + private static final Gas ID_PRECOMPILED_BASE_GAS_COST = Gas.of(15L); private static final Gas ID_PRECOMPILED_WORD_GAS_COST = Gas.of(3L); @@ -101,7 +111,37 @@ public class FrontierGasCalculator implements GasCalculator { private static final Gas SELF_DESTRUCT_REFUND_AMOUNT = Gas.of(24_000L); - private static final Gas CODE_DEPOSIT_BYTE_COST = Gas.of(200L); + @Override + public Gas transactionIntrinsicGasCost(final Bytes payload, final boolean isContractCreate) { + 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(TX_DATA_NON_ZERO_COST.times(nonZeros)); + + return isContractCreate ? cost.plus(txCreateExtraGasCost()) : cost; + } + + /** + * Returns the additional gas cost for contract creation transactions + * + * @return the additional gas cost for contract creation transactions + */ + protected Gas txCreateExtraGasCost() { + return TX_CREATE_EXTRA_COST; + } + + @Override + public Gas codeDepositGasCost(final int codeSize) { + return CODE_DEPOSIT_BYTE_COST.times(codeSize); + } @Override public Gas idPrecompiledContractGasCost(final Bytes input) { @@ -414,7 +454,7 @@ private static Gas memoryCost(final long length) { } @Override - public Gas codeDepositGasCost(final int codeSize) { - return CODE_DEPOSIT_BYTE_COST.times(codeSize); + public Gas getMaximumTransactionCost(final int size) { + return TX_BASE_COST.plus(TX_DATA_NON_ZERO_COST.times(size)); } } 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 9fd71a566f8..937103541c5 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 @@ -16,6 +16,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.evm.AccessListEntry; import org.hyperledger.besu.evm.Gas; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -39,6 +40,8 @@ import org.hyperledger.besu.evm.precompile.SHA256PrecompiledContract; import org.hyperledger.besu.evm.processor.AbstractMessageProcessor; +import java.util.List; + import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.units.bigints.UInt256; @@ -420,4 +423,55 @@ default Gas modExpGasCost(final Bytes input) { * @return the code deposit cost */ Gas codeDepositGasCost(int codeSize); + + /** + * Returns the intrinsic gas cost of a transaction pauload, i.e. the cost deriving from its + * encoded binary representation when stored on-chain. + * + * @param transactionPayload The encoded transaction, as bytes + * @param isContractCreate Is this transaction a contract creation transaction? + * @return the transaction's intrinsic gas cost + */ + Gas transactionIntrinsicGasCost(Bytes transactionPayload, boolean isContractCreate); + + /** + * Returns the gas cost of the explicitly declared access list. + * + * @param accessListEntries The access list entries + * @return the access list's gas cost + */ + default Gas accessListGasCost(final List accessListEntries) { + return accessListGasCost( + accessListEntries.size(), + accessListEntries.stream().mapToInt(e -> e.getStorageKeys().size()).sum()); + } + + /** + * Returns the gas cost of the explicitly declared access list. + * + * @param addresses The count of addresses accessed + * @param storageSlots The count of storage slots accessed + * @return the access list's gas cost + */ + default Gas accessListGasCost(final int addresses, final int storageSlots) { + return Gas.ZERO; + } + + /** + * A measure of the maximum amount of refunded gas a transaction will be credited with. + * + * @return the quotient of the equation `txGasCost / refundQuotient`. + */ + default long getMaxRefundQuotient() { + return 2; + } + + /** + * Maximum Cost of a Transaction of a certain length. + * + * @param size the length of the transaction, in bytes + * @return the maximum gas cost + */ + // what would be the gas for a PMT with hash of all non-zeros + Gas getMaximumTransactionCost(int size); } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/HomesteadTransactionGasCalculator.java b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/HomesteadGasCalculator.java similarity index 85% rename from ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/HomesteadTransactionGasCalculator.java rename to evm/src/main/java/org/hyperledger/besu/evm/gascalculator/HomesteadGasCalculator.java index a0b425234b7..bfd172635a0 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/HomesteadTransactionGasCalculator.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/HomesteadGasCalculator.java @@ -12,11 +12,11 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package org.hyperledger.besu.ethereum.mainnet; +package org.hyperledger.besu.evm.gascalculator; import org.hyperledger.besu.evm.Gas; -public class HomesteadTransactionGasCalculator extends FrontierTransactionGasCalculator { +public class HomesteadGasCalculator extends FrontierGasCalculator { private static final Gas TX_CREATE_EXTRA = Gas.of(32_000L); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/IstanbulGasCalculator.java b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/IstanbulGasCalculator.java index 80317ae8bdc..fda905069af 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/IstanbulGasCalculator.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/IstanbulGasCalculator.java @@ -17,10 +17,15 @@ import org.hyperledger.besu.evm.Gas; import org.hyperledger.besu.evm.account.Account; +import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.units.bigints.UInt256; public class IstanbulGasCalculator extends PetersburgGasCalculator { + private static final Gas TX_DATA_ZERO_COST = Gas.of(4L); + private static final Gas ISTANBUL_TX_DATA_NON_ZERO_COST = Gas.of(16L); + private static final Gas TX_BASE_COST = Gas.of(21_000L); + private static final Gas SLOAD_GAS = Gas.of(800); private static final Gas BALANCE_OPERATION_GAS_COST = Gas.of(700); private static final Gas EXTCODE_HASH_COST = Gas.of(700); @@ -33,6 +38,24 @@ public class IstanbulGasCalculator extends PetersburgGasCalculator { private static final Gas SSTORE_RESET_GAS_LESS_SLOAD_GAS = SSTORE_RESET_GAS.minus(SLOAD_GAS); private static final Gas NEGATIVE_SSTORE_CLEARS_SCHEDULE = Gas.ZERO.minus(SSTORE_CLEARS_SCHEDULE); + @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; + } + @Override // As per https://eips.ethereum.org/EIPS/eip-2200 public Gas calculateStorageCost( @@ -108,4 +131,9 @@ public Gas getBalanceOperationGasCost() { public Gas extCodeHashOperationGasCost() { return EXTCODE_HASH_COST; } + + @Override + public Gas getMaximumTransactionCost(final int size) { + return TX_BASE_COST.plus(ISTANBUL_TX_DATA_NON_ZERO_COST.times(size)); + } } diff --git a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/LondonGasCalculator.java b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/LondonGasCalculator.java index 0fe085fbeb3..4350d09728c 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/LondonGasCalculator.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/LondonGasCalculator.java @@ -26,6 +26,9 @@ public class LondonGasCalculator extends BerlinGasCalculator { private static final Gas NEGATIVE_SSTORE_CLEARS_SCHEDULE = Gas.ZERO.minus(SSTORE_CLEARS_SCHEDULE); + // redefinitions for EIP-3529 + private static final int NEW_MAX_REFUND_QUOTIENT = 5; + public LondonGasCalculator() {} // Redefined refund amount from EIP-3529 @@ -73,4 +76,9 @@ public Gas calculateStorageRefundAmount( } } } + + @Override + public long getMaxRefundQuotient() { + return NEW_MAX_REFUND_QUOTIENT; + } } diff --git a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/TangerineWhistleGasCalculator.java b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/TangerineWhistleGasCalculator.java index 114af6fafae..5384c6de296 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/TangerineWhistleGasCalculator.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/gascalculator/TangerineWhistleGasCalculator.java @@ -20,7 +20,7 @@ import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.frame.MessageFrame; -public class TangerineWhistleGasCalculator extends FrontierGasCalculator { +public class TangerineWhistleGasCalculator extends HomesteadGasCalculator { private static final Gas BALANCE_OPERATION_GAS_COST = Gas.of(400L); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/operation/MStore8Operation.java b/evm/src/main/java/org/hyperledger/besu/evm/operation/MStore8Operation.java index d9119ae05ef..e9c9263d9f9 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/operation/MStore8Operation.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/operation/MStore8Operation.java @@ -36,7 +36,7 @@ public MStore8Operation(final GasCalculator gasCalculator) { public OperationResult execute(final MessageFrame frame, final EVM evm) { final long location = clampedToLong(frame.popStackItem()); final Bytes value = frame.popStackItem(); - final byte theByte = (value.size() > 0) ? value.get(value.size() - 1) : 0; + final byte theByte = (value.size() > 0) ? value.get(value.size() - 1) : 0; final Gas cost = gasCalculator().mStore8OperationGasCost(frame, location); final Optional optionalCost = Optional.of(cost);