Search in sources :

Example 1 with GasCalculator

use of org.hyperledger.besu.evm.gascalculator.GasCalculator in project besu by hyperledger.

the class RefundSstoreGasTest method scenarios.

@Parameters(name = "calculator: {0}, original: {2}, current: {3}, new: {4}")
public static Object[][] scenarios() {
    final GasCalculator constantinople = new ConstantinopleGasCalculator();
    final GasCalculator petersburg = new PetersburgGasCalculator();
    final GasCalculator istanbul = new IstanbulGasCalculator();
    return new Object[][] { // Zero no-op
    { "constantinople", constantinople, ZERO, ZERO, ZERO, 200L, 0L }, { "petersburg", petersburg, ZERO, ZERO, ZERO, 5_000L, 0L }, { "istanbul", istanbul, ZERO, ZERO, ZERO, 800L, 0L }, // Zero fresh change
    { "constantinople", constantinople, ZERO, ZERO, ONE, 20_000L, 0L }, { "petersburg", petersburg, ZERO, ZERO, ONE, 20_000L, 0L }, { "istanbul", istanbul, ZERO, ZERO, ONE, 20_000L, 0L }, // Dirty, reset to zero
    { "constantinople", constantinople, ZERO, ONE, ZERO, 200L, 19_800L }, { "petersburg", petersburg, ZERO, ONE, ZERO, 5_000L, 15_000L }, { "istanbul", istanbul, ZERO, ONE, ZERO, 800L, 19_200L }, // Dirty, changed but not reset
    { "constantinople", constantinople, ZERO, ONE, TWO, 200L, 0L }, { "petersburg", petersburg, ZERO, ONE, TWO, 5_000L, 0L }, { "istanbul", istanbul, ZERO, ONE, TWO, 800L, 0L }, // Dirty no-op
    { "constantinople", constantinople, ZERO, ONE, ONE, 200L, 0L }, { "petersburg", petersburg, ZERO, ONE, ONE, 5_000L, 0L }, { "istanbul", istanbul, ZERO, ONE, ONE, 800L, 0L }, // Dirty, zero no-op
    { "constantinople", constantinople, ONE, ZERO, ZERO, 200L, 0L }, { "petersburg", petersburg, ONE, ZERO, ZERO, 5_000L, 0L }, { "istanbul", istanbul, ONE, ZERO, ZERO, 800L, 0L }, // Dirty, reset to non-zero
    { "constantinople", constantinople, ONE, ZERO, ONE, 200L, -15_000L + 4_800L }, { "petersburg", petersburg, ONE, ZERO, ONE, 20_000L, 0L }, { "istanbul", istanbul, ONE, ZERO, ONE, 800L, -15_000L + 4_200L }, // Fresh change to zero
    { "constantinople", constantinople, ONE, ONE, ZERO, 5_000L, 15_000L }, { "petersburg", petersburg, ONE, ONE, ZERO, 5_000L, 15_000L }, { "istanbul", istanbul, ONE, ONE, ZERO, 5_000L, 15_000L }, // Fresh change with all non-zero
    { "constantinople", constantinople, ONE, ONE, TWO, 5_000L, 0L }, { "petersburg", petersburg, ONE, ONE, TWO, 5_000L, 0L }, { "istanbul", istanbul, ONE, ONE, TWO, 5_000L, 0L }, // Dirty, clear originally set value
    { "constantinople", constantinople, ONE, TWO, ZERO, 200L, 15_000L }, { "petersburg", petersburg, ONE, TWO, ZERO, 5_000L, 15_000L }, { "istanbul", istanbul, ONE, TWO, ZERO, 800L, 15_000L }, // Non-zero no-op
    { "constantinople", constantinople, ONE, ONE, ONE, 200L, 0L }, { "petersburg", petersburg, ONE, ONE, ONE, 5_000L, 0L }, { "istanbul", istanbul, ONE, ONE, ONE, 800L, 0L } };
}
Also used : PetersburgGasCalculator(org.hyperledger.besu.evm.gascalculator.PetersburgGasCalculator) GasCalculator(org.hyperledger.besu.evm.gascalculator.GasCalculator) IstanbulGasCalculator(org.hyperledger.besu.evm.gascalculator.IstanbulGasCalculator) ConstantinopleGasCalculator(org.hyperledger.besu.evm.gascalculator.ConstantinopleGasCalculator) PetersburgGasCalculator(org.hyperledger.besu.evm.gascalculator.PetersburgGasCalculator) ConstantinopleGasCalculator(org.hyperledger.besu.evm.gascalculator.ConstantinopleGasCalculator) IstanbulGasCalculator(org.hyperledger.besu.evm.gascalculator.IstanbulGasCalculator) Parameters(org.junit.runners.Parameterized.Parameters)

Example 2 with GasCalculator

use of org.hyperledger.besu.evm.gascalculator.GasCalculator in project besu by hyperledger.

the class IntrinsicGasTest method data.

@Parameters
public static Collection<Object[]> data() {
    final GasCalculator frontier = new FrontierGasCalculator();
    final GasCalculator istanbul = new IstanbulGasCalculator();
    return Arrays.asList(new Object[][] { // EnoughGAS
    { frontier, 21952L, "0xf86d80018259d894095e7baea6a6c7c4c2dfeb977efac326af552d870a8e0358ac39584bc98a7c979f984b031ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a01fffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804" }, { istanbul, 21224L, "0xf86d80018259d894095e7baea6a6c7c4c2dfeb977efac326af552d870a8e0358ac39584bc98a7c979f984b031ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a01fffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804" }, // FirstZeroBytes
    { frontier, 21180L, "0xf87c80018261a894095e7baea6a6c7c4c2dfeb977efac326af552d870a9d00000000000000000000000000010000000000000000000000000000001ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a01fffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804" }, { istanbul, 21128L, "0xf87c80018261a894095e7baea6a6c7c4c2dfeb977efac326af552d870a9d00000000000000000000000000010000000000000000000000000000001ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a01fffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804" }, // LastZeroBytes
    { frontier, 21180L, "0xf87c80018261a894095e7baea6a6c7c4c2dfeb977efac326af552d870a9d01000000000000000000000000000000000000000000000000000000001ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a01fffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804" }, { istanbul, 21128L, "0xf87c80018261a894095e7baea6a6c7c4c2dfeb977efac326af552d870a9d01000000000000000000000000000000000000000000000000000000001ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a01fffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804" }, // NotEnoughGAS
    { frontier, 21952L, "0xf86d800182521c94095e7baea6a6c7c4c2dfeb977efac326af552d870a8e0358ac39584bc98a7c979f984b031ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804" }, { istanbul, 21224L, "0xf86d800182521c94095e7baea6a6c7c4c2dfeb977efac326af552d870a8e0358ac39584bc98a7c979f984b031ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804" }, // ZeroBytes
    { frontier, 21116L, "0xf87c80018261a894095e7baea6a6c7c4c2dfeb977efac326af552d870a9d00000000000000000000000000000000000000000000000000000000001ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a01fffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804" }, { istanbul, 21116L, "0xf87c80018261a894095e7baea6a6c7c4c2dfeb977efac326af552d870a9d00000000000000000000000000000000000000000000000000000000001ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a01fffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804" } });
}
Also used : GasCalculator(org.hyperledger.besu.evm.gascalculator.GasCalculator) IstanbulGasCalculator(org.hyperledger.besu.evm.gascalculator.IstanbulGasCalculator) FrontierGasCalculator(org.hyperledger.besu.evm.gascalculator.FrontierGasCalculator) FrontierGasCalculator(org.hyperledger.besu.evm.gascalculator.FrontierGasCalculator) IstanbulGasCalculator(org.hyperledger.besu.evm.gascalculator.IstanbulGasCalculator) Parameters(org.junit.runners.Parameterized.Parameters)

Example 3 with GasCalculator

use of org.hyperledger.besu.evm.gascalculator.GasCalculator in project besu by hyperledger.

the class ProtocolSpecBuilder method build.

public ProtocolSpec build(final ProtocolSchedule protocolSchedule) {
    checkNotNull(gasCalculatorBuilder, "Missing gasCalculator");
    checkNotNull(gasLimitCalculator, "Missing gasLimitCalculator");
    checkNotNull(evmBuilder, "Missing operation registry");
    checkNotNull(evmConfiguration, "Missing evm configuration");
    checkNotNull(transactionValidatorBuilder, "Missing transaction validator");
    checkNotNull(privateTransactionValidatorBuilder, "Missing private transaction validator");
    checkNotNull(contractCreationProcessorBuilder, "Missing contract creation processor");
    checkNotNull(precompileContractRegistryBuilder, "Missing precompile contract registry");
    checkNotNull(messageCallProcessorBuilder, "Missing message call processor");
    checkNotNull(transactionProcessorBuilder, "Missing transaction processor");
    checkNotNull(privateTransactionProcessorBuilder, "Missing private transaction processor");
    checkNotNull(blockHeaderValidatorBuilder, "Missing block header validator");
    checkNotNull(blockBodyValidatorBuilder, "Missing block body validator");
    checkNotNull(blockProcessorBuilder, "Missing block processor");
    checkNotNull(blockImporterBuilder, "Missing block importer");
    checkNotNull(blockValidatorBuilder, "Missing block validator");
    checkNotNull(blockHeaderFunctions, "Missing block hash function");
    checkNotNull(blockReward, "Missing block reward");
    checkNotNull(difficultyCalculator, "Missing difficulty calculator");
    checkNotNull(transactionReceiptFactory, "Missing transaction receipt factory");
    checkNotNull(name, "Missing name");
    checkNotNull(miningBeneficiaryCalculator, "Missing Mining Beneficiary Calculator");
    checkNotNull(protocolSchedule, "Missing protocol schedule");
    checkNotNull(privacyParameters, "Missing privacy parameters");
    checkNotNull(feeMarket, "Missing fee market");
    checkNotNull(badBlockManager, "Missing bad blocks manager");
    final GasCalculator gasCalculator = gasCalculatorBuilder.get();
    final EVM evm = evmBuilder.apply(gasCalculator, evmConfiguration);
    final PrecompiledContractConfiguration precompiledContractConfiguration = new PrecompiledContractConfiguration(gasCalculator, privacyParameters);
    final MainnetTransactionValidator transactionValidator = transactionValidatorBuilder.apply(gasCalculator);
    final AbstractMessageProcessor contractCreationProcessor = contractCreationProcessorBuilder.apply(gasCalculator, evm);
    final PrecompileContractRegistry precompileContractRegistry = precompileContractRegistryBuilder.apply(precompiledContractConfiguration);
    final AbstractMessageProcessor messageCallProcessor = messageCallProcessorBuilder.apply(evm, precompileContractRegistry);
    final MainnetTransactionProcessor transactionProcessor = transactionProcessorBuilder.apply(gasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor);
    final BlockHeaderValidator blockHeaderValidator = blockHeaderValidatorBuilder.apply(feeMarket).difficultyCalculator(difficultyCalculator).build();
    final BlockHeaderValidator ommerHeaderValidator = ommerHeaderValidatorBuilder.apply(feeMarket).difficultyCalculator(difficultyCalculator).build();
    final BlockBodyValidator blockBodyValidator = blockBodyValidatorBuilder.apply(protocolSchedule);
    BlockProcessor blockProcessor = blockProcessorBuilder.apply(transactionProcessor, transactionReceiptFactory, blockReward, miningBeneficiaryCalculator, skipZeroBlockRewards, privacyParameters.getGoQuorumPrivacyParameters());
    // Set private Tx Processor
    PrivateTransactionProcessor privateTransactionProcessor = null;
    if (privacyParameters.isEnabled()) {
        final PrivateTransactionValidator privateTransactionValidator = privateTransactionValidatorBuilder.apply();
        privateTransactionProcessor = privateTransactionProcessorBuilder.apply(gasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor, privateTransactionValidator);
        if (privacyParameters.isPrivacyPluginEnabled()) {
            final PrivacyPluginPrecompiledContract privacyPluginPrecompiledContract = (PrivacyPluginPrecompiledContract) precompileContractRegistry.get(PLUGIN_PRIVACY);
            privacyPluginPrecompiledContract.setPrivateTransactionProcessor(privateTransactionProcessor);
        } else if (privacyParameters.isFlexiblePrivacyGroupsEnabled()) {
            final FlexiblePrivacyPrecompiledContract flexiblePrivacyPrecompiledContract = (FlexiblePrivacyPrecompiledContract) precompileContractRegistry.get(FLEXIBLE_PRIVACY);
            flexiblePrivacyPrecompiledContract.setPrivateTransactionProcessor(privateTransactionProcessor);
        } else {
            final PrivacyPrecompiledContract privacyPrecompiledContract = (PrivacyPrecompiledContract) precompileContractRegistry.get(DEFAULT_PRIVACY);
            privacyPrecompiledContract.setPrivateTransactionProcessor(privateTransactionProcessor);
        }
        blockProcessor = new PrivacyBlockProcessor(blockProcessor, protocolSchedule, privacyParameters.getEnclave(), privacyParameters.getPrivateStateStorage(), privacyParameters.getPrivateWorldStateArchive(), privacyParameters.getPrivateStateRootResolver(), privacyParameters.getPrivateStateGenesisAllocator());
    }
    final BlockValidator blockValidator = blockValidatorBuilder.apply(blockHeaderValidator, blockBodyValidator, blockProcessor, badBlockManager, privacyParameters.getGoQuorumPrivacyParameters());
    final BlockImporter blockImporter = blockImporterBuilder.apply(blockValidator);
    return new ProtocolSpec(name, evm, transactionValidator, transactionProcessor, privateTransactionProcessor, blockHeaderValidator, ommerHeaderValidator, blockBodyValidator, blockProcessor, blockImporter, blockValidator, blockHeaderFunctions, transactionReceiptFactory, difficultyCalculator, blockReward, miningBeneficiaryCalculator, precompileContractRegistry, skipZeroBlockRewards, gasCalculator, gasLimitCalculator, feeMarket, badBlockManager, Optional.ofNullable(powHasher));
}
Also used : GasCalculator(org.hyperledger.besu.evm.gascalculator.GasCalculator) PrivateTransactionProcessor(org.hyperledger.besu.ethereum.privacy.PrivateTransactionProcessor) PrivacyPluginPrecompiledContract(org.hyperledger.besu.ethereum.mainnet.precompiles.privacy.PrivacyPluginPrecompiledContract) FlexiblePrivacyPrecompiledContract(org.hyperledger.besu.ethereum.mainnet.precompiles.privacy.FlexiblePrivacyPrecompiledContract) PrecompileContractRegistry(org.hyperledger.besu.evm.precompile.PrecompileContractRegistry) BlockValidator(org.hyperledger.besu.ethereum.BlockValidator) BlockImporter(org.hyperledger.besu.ethereum.core.BlockImporter) AbstractMessageProcessor(org.hyperledger.besu.evm.processor.AbstractMessageProcessor) PrivateTransactionValidator(org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator) EVM(org.hyperledger.besu.evm.EVM) PrivacyPrecompiledContract(org.hyperledger.besu.ethereum.mainnet.precompiles.privacy.PrivacyPrecompiledContract) FlexiblePrivacyPrecompiledContract(org.hyperledger.besu.ethereum.mainnet.precompiles.privacy.FlexiblePrivacyPrecompiledContract)

Aggregations

GasCalculator (org.hyperledger.besu.evm.gascalculator.GasCalculator)3 IstanbulGasCalculator (org.hyperledger.besu.evm.gascalculator.IstanbulGasCalculator)2 Parameters (org.junit.runners.Parameterized.Parameters)2 BlockValidator (org.hyperledger.besu.ethereum.BlockValidator)1 BlockImporter (org.hyperledger.besu.ethereum.core.BlockImporter)1 FlexiblePrivacyPrecompiledContract (org.hyperledger.besu.ethereum.mainnet.precompiles.privacy.FlexiblePrivacyPrecompiledContract)1 PrivacyPluginPrecompiledContract (org.hyperledger.besu.ethereum.mainnet.precompiles.privacy.PrivacyPluginPrecompiledContract)1 PrivacyPrecompiledContract (org.hyperledger.besu.ethereum.mainnet.precompiles.privacy.PrivacyPrecompiledContract)1 PrivateTransactionProcessor (org.hyperledger.besu.ethereum.privacy.PrivateTransactionProcessor)1 PrivateTransactionValidator (org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator)1 EVM (org.hyperledger.besu.evm.EVM)1 ConstantinopleGasCalculator (org.hyperledger.besu.evm.gascalculator.ConstantinopleGasCalculator)1 FrontierGasCalculator (org.hyperledger.besu.evm.gascalculator.FrontierGasCalculator)1 PetersburgGasCalculator (org.hyperledger.besu.evm.gascalculator.PetersburgGasCalculator)1 PrecompileContractRegistry (org.hyperledger.besu.evm.precompile.PrecompileContractRegistry)1 AbstractMessageProcessor (org.hyperledger.besu.evm.processor.AbstractMessageProcessor)1