Search in sources :

Example 1 with PrivateTransactionValidator

use of org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator in project besu by hyperledger.

the class MainnetProtocolSpecs method frontierDefinition.

public static ProtocolSpecBuilder frontierDefinition(final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit, final boolean goQuorumMode, final EvmConfiguration evmConfiguration) {
    final int contractSizeLimit = configContractSizeLimit.orElse(FRONTIER_CONTRACT_SIZE_LIMIT);
    final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE);
    return new ProtocolSpecBuilder().gasCalculator(FrontierGasCalculator::new).gasLimitCalculator(new FrontierTargetingGasLimitCalculator()).evmBuilder(MainnetEVMs::frontier).precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::frontier).messageCallProcessorBuilder(MessageCallProcessor::new).contractCreationProcessorBuilder((gasCalculator, evm) -> new ContractCreationProcessor(gasCalculator, evm, false, Collections.singletonList(MaxCodeSizeRule.of(contractSizeLimit)), 0)).transactionValidatorBuilder(gasCalculator -> new MainnetTransactionValidator(gasCalculator, false, Optional.empty(), goQuorumMode)).transactionProcessorBuilder((gasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor) -> new MainnetTransactionProcessor(gasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor, false, stackSizeLimit, FeeMarket.legacy(), CoinbaseFeePriceCalculator.frontier())).privateTransactionProcessorBuilder((gasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor, privateTransactionValidator) -> new PrivateTransactionProcessor(gasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor, false, stackSizeLimit, new PrivateTransactionValidator(Optional.empty()))).difficultyCalculator(MainnetDifficultyCalculators.FRONTIER).blockHeaderValidatorBuilder(feeMarket -> MainnetBlockHeaderValidator.create()).ommerHeaderValidatorBuilder(feeMarket -> MainnetBlockHeaderValidator.createLegacyFeeMarketOmmerValidator()).blockBodyValidatorBuilder(MainnetBlockBodyValidator::new).transactionReceiptFactory(MainnetProtocolSpecs::frontierTransactionReceiptFactory).blockReward(FRONTIER_BLOCK_REWARD).skipZeroBlockRewards(false).blockProcessorBuilder(MainnetProtocolSpecs.blockProcessorBuilder(goQuorumMode)).blockValidatorBuilder(MainnetProtocolSpecs.blockValidatorBuilder(goQuorumMode)).blockImporterBuilder(MainnetBlockImporter::new).blockHeaderFunctions(new MainnetBlockHeaderFunctions()).miningBeneficiaryCalculator(BlockHeader::getCoinbase).evmConfiguration(evmConfiguration).name("Frontier");
}
Also used : MessageCallProcessor(org.hyperledger.besu.evm.processor.MessageCallProcessor) WorldUpdater(org.hyperledger.besu.evm.worldstate.WorldUpdater) GoQuorumBlockProcessor(org.hyperledger.besu.ethereum.goquorum.GoQuorumBlockProcessor) PowAlgorithm(org.hyperledger.besu.config.PowAlgorithm) FeeMarket(org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket) GenesisConfigOptions(org.hyperledger.besu.config.GenesisConfigOptions) ByzantiumGasCalculator(org.hyperledger.besu.evm.gascalculator.ByzantiumGasCalculator) BlockValidatorBuilder(org.hyperledger.besu.ethereum.mainnet.ProtocolSpecBuilder.BlockValidatorBuilder) BlockProcessorBuilder(org.hyperledger.besu.ethereum.mainnet.ProtocolSpecBuilder.BlockProcessorBuilder) TransactionReceipt(org.hyperledger.besu.ethereum.core.TransactionReceipt) MainnetEVMs(org.hyperledger.besu.evm.MainnetEVMs) TangerineWhistleGasCalculator(org.hyperledger.besu.evm.gascalculator.TangerineWhistleGasCalculator) BigInteger(java.math.BigInteger) HomesteadGasCalculator(org.hyperledger.besu.evm.gascalculator.HomesteadGasCalculator) ImmutableSet(com.google.common.collect.ImmutableSet) Blockchain(org.hyperledger.besu.ethereum.chain.Blockchain) CoinbaseFeePriceCalculator(org.hyperledger.besu.ethereum.core.feemarket.CoinbaseFeePriceCalculator) Set(java.util.Set) EvmConfiguration(org.hyperledger.besu.evm.internal.EvmConfiguration) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) TransactionProcessingResult(org.hyperledger.besu.ethereum.processing.TransactionProcessingResult) List(java.util.List) IstanbulGasCalculator(org.hyperledger.besu.evm.gascalculator.IstanbulGasCalculator) MutableAccount(org.hyperledger.besu.evm.account.MutableAccount) Optional(java.util.Optional) ContractCreationProcessor(org.hyperledger.besu.evm.processor.ContractCreationProcessor) TransactionType(org.hyperledger.besu.plugin.data.TransactionType) PrefixCodeRule(org.hyperledger.besu.evm.contractvalidation.PrefixCodeRule) IntStream(java.util.stream.IntStream) MessageCallProcessor(org.hyperledger.besu.evm.processor.MessageCallProcessor) PrivateTransactionValidator(org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator) Address(org.hyperledger.besu.datatypes.Address) OptionalInt(java.util.OptionalInt) MaxCodeSizeRule(org.hyperledger.besu.evm.contractvalidation.MaxCodeSizeRule) FrontierGasCalculator(org.hyperledger.besu.evm.gascalculator.FrontierGasCalculator) BaseFeeMarket(org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket) Wei(org.hyperledger.besu.datatypes.Wei) LondonGasCalculator(org.hyperledger.besu.evm.gascalculator.LondonGasCalculator) PetersburgGasCalculator(org.hyperledger.besu.evm.gascalculator.PetersburgGasCalculator) PrivateMetadataUpdater(org.hyperledger.besu.ethereum.privacy.storage.PrivateMetadataUpdater) WorldState(org.hyperledger.besu.evm.worldstate.WorldState) GoQuorumBlockValidator(org.hyperledger.besu.ethereum.goquorum.GoQuorumBlockValidator) Resources(com.google.common.io.Resources) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) IOException(java.io.IOException) PrivateTransactionProcessor(org.hyperledger.besu.ethereum.privacy.PrivateTransactionProcessor) JsonArray(io.vertx.core.json.JsonArray) MainnetBlockValidator(org.hyperledger.besu.ethereum.MainnetBlockValidator) SpuriousDragonGasCalculator(org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator) BerlinGasCalculator(org.hyperledger.besu.evm.gascalculator.BerlinGasCalculator) ConstantinopleGasCalculator(org.hyperledger.besu.evm.gascalculator.ConstantinopleGasCalculator) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) Transaction(org.hyperledger.besu.ethereum.core.Transaction) Collections(java.util.Collections) MainnetEVMs(org.hyperledger.besu.evm.MainnetEVMs) FrontierGasCalculator(org.hyperledger.besu.evm.gascalculator.FrontierGasCalculator) PrivateTransactionProcessor(org.hyperledger.besu.ethereum.privacy.PrivateTransactionProcessor) ContractCreationProcessor(org.hyperledger.besu.evm.processor.ContractCreationProcessor) PrivateTransactionValidator(org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader)

Example 2 with PrivateTransactionValidator

use of org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator in project besu by hyperledger.

the class ProtocolScheduleBuilder method addProtocolSpec.

private void addProtocolSpec(final MutableProtocolSchedule protocolSchedule, final long blockNumber, final ProtocolSpecBuilder definition, final Function<ProtocolSpecBuilder, ProtocolSpecBuilder> modifier) {
    definition.badBlocksManager(badBlockManager).privacyParameters(privacyParameters).privateTransactionValidatorBuilder(() -> new PrivateTransactionValidator(protocolSchedule.getChainId()));
    protocolSchedule.putMilestone(blockNumber, modifier.apply(definition).build(protocolSchedule));
}
Also used : PrivateTransactionValidator(org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator)

Example 3 with PrivateTransactionValidator

use of org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator 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)

Example 4 with PrivateTransactionValidator

use of org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator in project besu by hyperledger.

the class VMReferenceTest method runTest.

@Override
protected void runTest() {
    final MutableWorldState worldState = new DefaultMutableWorldState(spec.getInitialWorldState());
    final EnvironmentInformation execEnv = spec.getExec();
    final ProtocolSpec protocolSpec = MainnetProtocolSpecs.frontierDefinition(OptionalInt.empty(), OptionalInt.empty(), false, EvmConfiguration.DEFAULT).privacyParameters(PrivacyParameters.DEFAULT).privateTransactionValidatorBuilder(() -> new PrivateTransactionValidator(CHAIN_ID)).badBlocksManager(new BadBlockManager()).build(new MutableProtocolSchedule(CHAIN_ID));
    final ReferenceTestBlockchain blockchain = new ReferenceTestBlockchain(execEnv.getBlockHeader().getNumber());
    final MessageFrame frame = MessageFrame.builder().type(MessageFrame.Type.MESSAGE_CALL).messageFrameStack(new ArrayDeque<>()).worldUpdater(worldState.updater()).initialGas(spec.getExec().getGas()).contract(execEnv.getAccountAddress()).address(execEnv.getAccountAddress()).originator(execEnv.getOriginAddress()).gasPrice(execEnv.getGasPrice()).inputData(execEnv.getData()).sender(execEnv.getCallerAddress()).value(execEnv.getValue()).apparentValue(execEnv.getValue()).code(execEnv.getCode()).blockValues(execEnv.getBlockHeader()).depth(execEnv.getDepth()).completer(c -> {
    }).miningBeneficiary(execEnv.getBlockHeader().getCoinbase()).blockHashLookup(new BlockHashLookup(execEnv.getBlockHeader(), blockchain)).maxStackSize(MessageFrame.DEFAULT_MAX_STACK_SIZE).build();
    // This is normally set inside the containing message executing the code.
    frame.setState(MessageFrame.State.CODE_EXECUTING);
    protocolSpec.getEvm().runToHalt(frame, OperationTracer.NO_TRACING);
    if (spec.isExceptionHaltExpected()) {
        assertThat(frame.getState() == MessageFrame.State.EXCEPTIONAL_HALT).withFailMessage("VM should have exceptionally halted").isTrue();
    } else {
        // This is normally performed when the message processor executing the VM
        // executes to completion successfully.
        frame.getWorldUpdater().commit();
        assertThat(frame.getState() == MessageFrame.State.EXCEPTIONAL_HALT).withFailMessage("VM should not have exceptionally halted with " + frame.getExceptionalHaltReason()).isFalse();
        assertThat(frame.getOutputData()).withFailMessage("VM output differs").isEqualTo(spec.getOut());
        assertThat(worldState.rootHash()).withFailMessage("Final world state differs").isEqualTo(spec.getFinalWorldState().rootHash());
        final Gas actualGas = frame.getRemainingGas();
        final Gas expectedGas = spec.getFinalGas();
        final Gas difference = (expectedGas.compareTo(actualGas) > 0) ? expectedGas.minus(actualGas) : actualGas.minus(expectedGas);
        assertThat(actualGas).withFailMessage("Final gas does not match, with difference of %s", difference).isEqualTo(expectedGas);
    }
}
Also used : MutableProtocolSchedule(org.hyperledger.besu.ethereum.mainnet.MutableProtocolSchedule) DefaultMutableWorldState(org.hyperledger.besu.ethereum.worldstate.DefaultMutableWorldState) MutableWorldState(org.hyperledger.besu.ethereum.core.MutableWorldState) ProtocolSpec(org.hyperledger.besu.ethereum.mainnet.ProtocolSpec) MessageFrame(org.hyperledger.besu.evm.frame.MessageFrame) DefaultMutableWorldState(org.hyperledger.besu.ethereum.worldstate.DefaultMutableWorldState) Gas(org.hyperledger.besu.evm.Gas) EnvironmentInformation(org.hyperledger.besu.ethereum.referencetests.EnvironmentInformation) PrivateTransactionValidator(org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator) BadBlockManager(org.hyperledger.besu.ethereum.chain.BadBlockManager) ReferenceTestBlockchain(org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain)

Aggregations

PrivateTransactionValidator (org.hyperledger.besu.ethereum.privacy.PrivateTransactionValidator)4 MutableWorldState (org.hyperledger.besu.ethereum.core.MutableWorldState)2 PrivateTransactionProcessor (org.hyperledger.besu.ethereum.privacy.PrivateTransactionProcessor)2 MessageFrame (org.hyperledger.besu.evm.frame.MessageFrame)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Resources (com.google.common.io.Resources)1 JsonArray (io.vertx.core.json.JsonArray)1 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 OptionalInt (java.util.OptionalInt)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 GenesisConfigOptions (org.hyperledger.besu.config.GenesisConfigOptions)1 PowAlgorithm (org.hyperledger.besu.config.PowAlgorithm)1 Address (org.hyperledger.besu.datatypes.Address)1