use of org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator in project besu by hyperledger.
the class PrivacyPrecompiledContractIntegrationTest method testSendAndReceive.
@Test
public void testSendAndReceive() {
final List<String> publicKeys = testHarness.getPublicKeys();
final PrivateTransaction privateTransaction = PrivateTransactionDataFixture.privateContractDeploymentTransactionBesu(publicKeys.get(0));
final BytesValueRLPOutput bytesValueRLPOutput = new BytesValueRLPOutput();
privateTransaction.writeTo(bytesValueRLPOutput);
final String s = bytesValueRLPOutput.encoded().toBase64String();
final SendResponse sr = enclave.send(s, publicKeys.get(0), Lists.newArrayList(publicKeys.get(0)));
final PrivacyPrecompiledContract privacyPrecompiledContract = new PrivacyPrecompiledContract(new SpuriousDragonGasCalculator(), enclave, worldStateArchive, new PrivateStateRootResolver(privateStateStorage), new PrivateStateGenesisAllocator(false, (privacyGroupId, blockNumber) -> Collections::emptyList), "IntegrationTest");
privacyPrecompiledContract.setPrivateTransactionProcessor(mockPrivateTxProcessor());
final PrecompiledContract.PrecompileContractResult result = privacyPrecompiledContract.computePrecompile(Bytes.fromBase64String(sr.getKey()), messageFrame);
final Bytes actual = result.getOutput();
assertThat(actual).isEqualTo(Bytes.fromHexString(DEFAULT_OUTPUT));
}
use of org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator in project besu by hyperledger.
the class MainnetProtocolSpecs method spuriousDragonDefinition.
public static ProtocolSpecBuilder spuriousDragonDefinition(final Optional<BigInteger> chainId, final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit, final boolean quorumCompatibilityMode, final EvmConfiguration evmConfiguration) {
final int contractSizeLimit = configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT);
final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE);
return tangerineWhistleDefinition(OptionalInt.empty(), configStackSizeLimit, quorumCompatibilityMode, evmConfiguration).gasCalculator(SpuriousDragonGasCalculator::new).skipZeroBlockRewards(true).messageCallProcessorBuilder((evm, precompileContractRegistry) -> new MessageCallProcessor(evm, precompileContractRegistry, SPURIOUS_DRAGON_FORCE_DELETE_WHEN_EMPTY_ADDRESSES)).contractCreationProcessorBuilder((gasCalculator, evm) -> new ContractCreationProcessor(gasCalculator, evm, true, Collections.singletonList(MaxCodeSizeRule.of(contractSizeLimit)), 1, SPURIOUS_DRAGON_FORCE_DELETE_WHEN_EMPTY_ADDRESSES)).transactionValidatorBuilder(gasCalculator -> new MainnetTransactionValidator(gasCalculator, true, chainId, quorumCompatibilityMode)).transactionProcessorBuilder((gasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor) -> new MainnetTransactionProcessor(gasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor, true, stackSizeLimit, FeeMarket.legacy(), CoinbaseFeePriceCalculator.frontier())).name("SpuriousDragon");
}
use of org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator in project besu by hyperledger.
the class ClassicProtocolSpecs method atlantisDefinition.
public static ProtocolSpecBuilder atlantisDefinition(final Optional<BigInteger> chainId, final OptionalInt configContractSizeLimit, final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final OptionalLong ecip1017EraRounds, final boolean quorumCompatibilityMode, final EvmConfiguration evmConfiguration) {
final int contractSizeLimit = configContractSizeLimit.orElse(MainnetProtocolSpecs.SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT);
final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE);
return gothamDefinition(chainId, configContractSizeLimit, configStackSizeLimit, ecip1017EraRounds, quorumCompatibilityMode, evmConfiguration).evmBuilder(MainnetEVMs::byzantium).evmConfiguration(evmConfiguration).gasCalculator(SpuriousDragonGasCalculator::new).skipZeroBlockRewards(true).messageCallProcessorBuilder(MessageCallProcessor::new).precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::byzantium).difficultyCalculator(ClassicDifficultyCalculators.EIP100).transactionReceiptFactory(enableRevertReason ? ClassicProtocolSpecs::byzantiumTransactionReceiptFactoryWithReasonEnabled : ClassicProtocolSpecs::byzantiumTransactionReceiptFactory).contractCreationProcessorBuilder((gasCalculator, evm) -> new ContractCreationProcessor(gasCalculator, evm, true, Collections.singletonList(MaxCodeSizeRule.of(contractSizeLimit)), 1)).transactionProcessorBuilder((gasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor) -> new MainnetTransactionProcessor(gasCalculator, transactionValidator, contractCreationProcessor, messageCallProcessor, true, stackSizeLimit, FeeMarket.legacy(), CoinbaseFeePriceCalculator.frontier())).name("Atlantis");
}
use of org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator in project besu by hyperledger.
the class FlexiblePrivacyPrecompiledContractTest method testInvalidPrivateTransaction.
@Test
public void testInvalidPrivateTransaction() {
final Enclave enclave = mock(Enclave.class);
final FlexiblePrivacyPrecompiledContract contract = new FlexiblePrivacyPrecompiledContract(new SpuriousDragonGasCalculator(), enclave, worldStateArchive, privateStateRootResolver, privateStateGenesisAllocator);
contract.setPrivateTransactionProcessor(mockPrivateTxProcessor(TransactionProcessingResult.invalid(ValidationResult.invalid(TransactionInvalidReason.INCORRECT_NONCE))));
final FlexiblePrivacyPrecompiledContract contractSpy = spy(contract);
Mockito.doReturn(true).when(contractSpy).canExecute(any(), any(), any(), any(), any(), any(), any(), any());
final VersionedPrivateTransaction privateTransaction = versionedPrivateTransactionBesu();
final byte[] payload = convertVersionedPrivateTransactionToBytes(privateTransaction);
final String privateFrom = privateTransaction.getPrivateTransaction().getPrivateFrom().toBase64String();
final ReceiveResponse response = new ReceiveResponse(payload, PAYLOAD_TEST_PRIVACY_GROUP_ID, privateFrom);
when(enclave.receive(any(String.class))).thenReturn(response);
final PrecompiledContract.PrecompileContractResult result = contractSpy.computePrecompile(privateTransactionLookupId, messageFrame);
final Bytes actual = result.getOutput();
assertThat(actual).isEqualTo(Bytes.EMPTY);
}
use of org.hyperledger.besu.evm.gascalculator.SpuriousDragonGasCalculator in project besu by hyperledger.
the class PrivacyPluginPrecompiledContractTest method setup.
@Before
public void setup() {
final PrivateStateStorage privateStateStorage = mock(PrivateStateStorage.class);
messageFrame = mock(MessageFrame.class);
final BlockDataGenerator blockGenerator = new BlockDataGenerator();
final Block genesis = blockGenerator.genesisBlock();
final Block block = blockGenerator.block(new BlockDataGenerator.BlockOptions().setParentHash(genesis.getHeader().getHash()));
when(messageFrame.getContextVariable(KEY_IS_PERSISTING_PRIVATE_STATE, false)).thenReturn(false);
when(messageFrame.hasContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(true);
when(messageFrame.getContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(mock(PrivateMetadataUpdater.class));
when(messageFrame.getBlockValues()).thenReturn(block.getHeader());
when(privateStateStorage.getPrivacyGroupHeadBlockMap(any())).thenReturn(Optional.of(PrivacyGroupHeadBlockMap.empty()));
final PrivateMetadataUpdater privateMetadataUpdater = mock(PrivateMetadataUpdater.class);
when(messageFrame.hasContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(true);
when(messageFrame.getContextVariable(KEY_PRIVATE_METADATA_UPDATER)).thenReturn(privateMetadataUpdater);
when(privateMetadataUpdater.getPrivacyGroupHeadBlockMap()).thenReturn(PrivacyGroupHeadBlockMap.empty());
contract = new PrivacyPluginPrecompiledContract(new SpuriousDragonGasCalculator(), new PrivacyParameters.Builder().setEnabled(true).setPrivacyPluginEnabled(true).setStorageProvider(new InMemoryPrivacyStorageProvider()).setPrivacyService(new PrivacyPluginService() {
@Override
public void setPayloadProvider(final PrivacyPluginPayloadProvider provider) {
}
@Override
public PrivacyPluginPayloadProvider getPayloadProvider() {
return new PrivacyPluginPayloadProvider() {
@Override
public Bytes generateMarkerPayload(final org.hyperledger.besu.plugin.data.PrivateTransaction privateTransaction, final String privacyUserId) {
return serialize(privateTransaction).encoded();
}
@Override
public Optional<org.hyperledger.besu.plugin.data.PrivateTransaction> getPrivateTransactionFromPayload(final org.hyperledger.besu.plugin.data.Transaction transaction) {
final BytesValueRLPInput bytesValueRLPInput = new BytesValueRLPInput(transaction.getPayload(), false);
return Optional.of(readFrom(bytesValueRLPInput));
}
};
}
@Override
public void setPrivacyGroupAuthProvider(final PrivacyGroupAuthProvider privacyGroupAuthProvider) {
}
@Override
public PrivacyGroupAuthProvider getPrivacyGroupAuthProvider() {
return (privacyGroupId, privacyUserId, blockNumber) -> true;
}
@Override
public void setPrivacyGroupGenesisProvider(final PrivacyGroupGenesisProvider privacyGroupAuthProvider) {
}
@Override
public PrivacyGroupGenesisProvider getPrivacyGroupGenesisProvider() {
return (privacyGroupId, blockNumber) -> (PrivacyGenesis) Collections::emptyList;
}
@Override
public PrivateMarkerTransactionFactory getPrivateMarkerTransactionFactory() {
return null;
}
@Override
public void setPrivateMarkerTransactionFactory(final PrivateMarkerTransactionFactory privateMarkerTransactionFactory) {
}
}).setEnclaveFactory(mock(EnclaveFactory.class)).build());
}
Aggregations