Skip to content

Commit

Permalink
[1404] Fixed NPE when executing eth_estimateGas with privacy enabled. (
Browse files Browse the repository at this point in the history
…hyperledger#1424)

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

Signed-off-by: Mark Terry <mark.terry@consensys.net>
  • Loading branch information
mark-terry authored Oct 8, 2020
1 parent d6a7046 commit 5c0ee9d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public boolean removePrivateTransactionObserver(final long observerId) {
@Override
public Bytes compute(final Bytes input, final MessageFrame messageFrame) {

if (isMining(messageFrame)) {
if (skipContractExecution(messageFrame)) {
return Bytes.EMPTY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public Gas gasRequirement(final Bytes input) {
@Override
public Bytes compute(final Bytes input, final MessageFrame messageFrame) {

if (isMining(messageFrame)) {
if (skipContractExecution(messageFrame)) {
return Bytes.EMPTY;
}

Expand Down Expand Up @@ -242,6 +242,17 @@ ReceiveResponse getReceiveResponse(final String key) {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,19 @@ public void testInvalidPrivateTransaction() {
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);
Expand Down

0 comments on commit 5c0ee9d

Please sign in to comment.