[1404] Fixed NPE when executing eth_estimateGas with privacy enabled. (#1424)

* [1404] Fixed NPE when executing eth_estimateGas with privacy enabled.

Signed-off-by: Mark Terry <mark.terry@consensys.net>
pull/1427/head
mark-terry 4 years ago committed by GitHub
parent d6a704625d
commit 5c0ee9d846
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 2
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/OnChainPrivacyPrecompiledContract.java
  3. 13
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContract.java
  4. 13
      ethereum/core/src/test/java/org/hyperledger/besu/ethereum/mainnet/precompiles/privacy/PrivacyPrecompiledContractTest.java

@ -17,6 +17,7 @@ Hyperledger Besu is moving its versioning scheme to [CalVer](https://calver.org/
### Bug Fixes
* Log block import rejection reasons at "INFO" level. Bug [#1412](https://github.com/hyperledger/besu/issues/1412)
* Fixed NPE when executing `eth_estimateGas` with privacy enabled. Bug [#1404](https://github.com/hyperledger/besu/issues/1404)
#### Previously identified known issues

@ -102,7 +102,7 @@ public class OnChainPrivacyPrecompiledContract extends PrivacyPrecompiledContrac
@Override
public Bytes compute(final Bytes input, final MessageFrame messageFrame) {
if (isMining(messageFrame)) {
if (skipContractExecution(messageFrame)) {
return Bytes.EMPTY;
}

@ -102,7 +102,7 @@ public class PrivacyPrecompiledContract extends AbstractPrecompiledContract {
@Override
public Bytes compute(final Bytes input, final MessageFrame messageFrame) {
if (isMining(messageFrame)) {
if (skipContractExecution(messageFrame)) {
return Bytes.EMPTY;
}
@ -242,6 +242,17 @@ public class PrivacyPrecompiledContract extends AbstractPrecompiledContract {
return receiveResponse;
}
boolean skipContractExecution(final MessageFrame messageFrame) {
return isSimulatingPMT(messageFrame) || isMining(messageFrame);
}
boolean isSimulatingPMT(final MessageFrame messageFrame) {
// If there's no PrivateMetadataUpdater, the precompile has not been called through the
// PrivacyBlockProcessor. This indicates the PMT is being simulated and execution of the
// precompile is not required.
return messageFrame.getPrivateMetadataUpdater() == null;
}
boolean isMining(final MessageFrame messageFrame) {
boolean isMining = false;
final ProcessableBlockHeader currentBlockHeader = messageFrame.getBlockHeader();

@ -303,6 +303,19 @@ public class PrivacyPrecompiledContractTest {
assertThat(actual).isEqualTo(Bytes.EMPTY);
}
@Test
public void testSimulatedPublicTransactionIsSkipped() {
final PrivacyPrecompiledContract emptyContract =
new PrivacyPrecompiledContract(null, null, null, null);
// A simulated public transaction doesn't contain a PrivateMetadataUpdater
final MessageFrame frame = mock(MessageFrame.class);
when(frame.getPrivateMetadataUpdater()).thenReturn(null);
final Bytes result = emptyContract.compute(null, frame);
assertThat(result).isEqualTo(Bytes.EMPTY);
}
private byte[] convertPrivateTransactionToBytes(final PrivateTransaction privateTransaction) {
final BytesValueRLPOutput bytesValueRLPOutput = new BytesValueRLPOutput();
privateTransaction.writeTo(bytesValueRLPOutput);

Loading…
Cancel
Save