Skip to content

Commit

Permalink
exception if --privacy-marker-transaction-signing-key-file not specif…
Browse files Browse the repository at this point in the history
…ied in non-zero-gas network (#1182)

* exception if min-gas-price > 0 and pmt key file not specified

Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
  • Loading branch information
macfarla authored Jul 2, 2020
1 parent 87d04ca commit 70ce168
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
16 changes: 13 additions & 3 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ void setBannedNodeIds(final List<String> values) {
@Option(
names = {"--target-gas-limit"},
description =
"Sets target gas limit per block. If set each blocks gas limit will approach this setting over time if the current gas limit is different.")
"Sets target gas limit per block. If set each block's gas limit will approach this setting over time if the current gas limit is different.")
private final Long targetGasLimit = null;

@Option(
Expand Down Expand Up @@ -1314,13 +1314,13 @@ private void validateMiningParams() {
if (isMiningEnabled && coinbase == null) {
throw new ParameterException(
this.commandLine,
"Unable to mine without a valid coinbase. Either disable mining (remove --miner-enabled)"
"Unable to mine without a valid coinbase. Either disable mining (remove --miner-enabled) "
+ "or specify the beneficiary of mining (via --miner-coinbase <Address>)");
}
if (!isMiningEnabled && iStratumMiningEnabled) {
throw new ParameterException(
this.commandLine,
"Unable to mine with Stratum if mining is disabled. Either disable Stratum mining (remove --miner-stratum-enabled)"
"Unable to mine with Stratum if mining is disabled. Either disable Stratum mining (remove --miner-stratum-enabled) "
+ "or specify mining is enabled (--miner-enabled)");
}
}
Expand Down Expand Up @@ -1882,6 +1882,16 @@ private PrivacyParameters privacyParameters() {
throw new ParameterException(
commandLine, "Please specify Enclave public key file path to enable privacy");
}

if (Wei.ZERO.compareTo(minTransactionGasPrice) < 0) {
// if gas is required, cannot use random keys to sign private tx
// ie --privacy-marker-transaction-signing-key-file must be set
if (privacyMarkerTransactionSigningKeyPath == null) {
throw new ParameterException(
commandLine,
"Not a free gas network. --privacy-marker-transaction-signing-key-file must be specified and must be a funded account. Private transactions cannot be signed by random (non-funded) accounts in paid gas networks");
}
}
privacyParametersBuilder.setPrivacyAddress(privacyPrecompiledAddress);
privacyParametersBuilder.setPrivateKeyPath(privacyMarkerTransactionSigningKeyPath);
privacyParametersBuilder.setStorageProvider(
Expand Down
35 changes: 30 additions & 5 deletions besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1540,9 +1540,14 @@ public void privacyTlsOptionsRequiresTlsToBeEnabled() {
when(storageService.getByName("rocksdb-privacy"))
.thenReturn(Optional.of(rocksDBSPrivacyStorageFactory));
final URL configFile = this.getClass().getResource("/orion_publickey.pub");
final String coinbaseStr = String.format("%040x", 1);

parseCommand(
"--privacy-enabled",
"--miner-enabled",
"--miner-coinbase=" + coinbaseStr,
"--min-gas-price",
"0",
"--privacy-url",
ENCLAVE_URI,
"--privacy-public-key-file",
Expand Down Expand Up @@ -2622,7 +2627,7 @@ public void miningOptionsRequiresServiceToBeEnabled() {
assertThat(commandOutput.toString()).isEmpty();
assertThat(commandErrorOutput.toString())
.startsWith(
"Unable to mine with Stratum if mining is disabled. Either disable Stratum mining (remove --miner-stratum-enabled)or specify mining is enabled (--miner-enabled)");
"Unable to mine with Stratum if mining is disabled. Either disable Stratum mining (remove --miner-stratum-enabled) or specify mining is enabled (--miner-enabled)");
}

@Test
Expand Down Expand Up @@ -2912,7 +2917,9 @@ public void mustUseEnclaveUriAndOptions() {
"--privacy-url",
ENCLAVE_URI,
"--privacy-public-key-file",
configFile.getPath());
configFile.getPath(),
"--min-gas-price",
"0");

final ArgumentCaptor<PrivacyParameters> enclaveArg =
ArgumentCaptor.forClass(PrivacyParameters.class);
Expand Down Expand Up @@ -2982,7 +2989,9 @@ public void privacyMultiTenancyIsConfiguredWhenConfiguredWithNecessaryOptions()
"--rpc-http-authentication-enabled",
"--privacy-multi-tenancy-enabled",
"--rpc-http-authentication-jwt-public-key-file",
"/non/existent/file");
"/non/existent/file",
"--min-gas-price",
"0");

final ArgumentCaptor<PrivacyParameters> privacyParametersArgumentCaptor =
ArgumentCaptor.forClass(PrivacyParameters.class);
Expand Down Expand Up @@ -3023,7 +3032,12 @@ public void privacyMultiTenancyWithPrivacyPublicKeyFileFails() {

@Test
public void onChainPrivacyGroupEnabledFlagDefaultValueIsFalse() {
parseCommand("--privacy-enabled", "--privacy-public-key-file", ENCLAVE_PUBLIC_KEY_PATH);
parseCommand(
"--privacy-enabled",
"--privacy-public-key-file",
ENCLAVE_PUBLIC_KEY_PATH,
"--min-gas-price",
"0");

final ArgumentCaptor<PrivacyParameters> privacyParametersArgumentCaptor =
ArgumentCaptor.forClass(PrivacyParameters.class);
Expand All @@ -3044,7 +3058,9 @@ public void onChainPrivacyGroupEnabledFlagValueIsSet() {
"--privacy-enabled",
"--privacy-public-key-file",
ENCLAVE_PUBLIC_KEY_PATH,
"--privacy-onchain-groups-enabled");
"--privacy-onchain-groups-enabled",
"--min-gas-price",
"0");

final ArgumentCaptor<PrivacyParameters> privacyParametersArgumentCaptor =
ArgumentCaptor.forClass(PrivacyParameters.class);
Expand Down Expand Up @@ -3073,6 +3089,15 @@ public void onchainPrivacyAndMultiTenancyCannotBeUsedTogether() {
.startsWith("Privacy multi-tenancy and onchain privacy groups cannot be used together");
}

@Test
public void privacyMarkerTransactionSigningKeyFileRequiredIfMinGasPriceNonZero() {
parseCommand("--privacy-enabled", "--privacy-public-key-file", ENCLAVE_PUBLIC_KEY_PATH);

assertThat(commandErrorOutput.toString())
.startsWith(
"Not a free gas network. --privacy-marker-transaction-signing-key-file must be specified");
}

private Path createFakeGenesisFile(final JsonObject jsonGenesis) throws IOException {
final Path genesisFile = Files.createTempFile("genesisFile", "");
Files.write(genesisFile, encodeJsonGenesis(jsonGenesis).getBytes(UTF_8));
Expand Down

0 comments on commit 70ce168

Please sign in to comment.