[PAN-3010] Enforce privateFrom to be present. (#1829)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Ivaylo Kirilov 5 years ago committed by MadelineMurray
parent 41ece1de64
commit faf7521fa0
  1. 26
      ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransaction.java
  2. 5
      ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/eea/EeaSendRawTransaction.java
  3. 35
      ethereum/jsonrpc/src/test/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/eea/EeaSendRawTransactionTest.java

@ -90,13 +90,8 @@ public class PrivateTransaction {
return new Builder();
}
public static PrivateTransaction readFrom(final RLPInput input) throws RLPException {
return readFrom(input, null);
}
@SuppressWarnings({"unchecked"})
public static PrivateTransaction readFrom(final RLPInput input, final BytesValue enclavePublicKey)
throws RLPException {
public static PrivateTransaction readFrom(final RLPInput input) throws RLPException {
input.enterList();
final Builder builder =
@ -124,22 +119,9 @@ public class PrivateTransaction {
final BigInteger s = BytesValues.asUnsignedBigInteger(input.readUInt256Scalar().getBytes());
final SECP256K1.Signature signature = SECP256K1.Signature.create(r, s, recId);
final RLPInput item1 = input.readAsRlp(); // privateFrom or privateFor/PrivacyGroupId
final RLPInput item2 = input.readAsRlp(); // privateFor/PrivacyGroupId or restriction
final BytesValue privateFrom;
final Object privateForOrPrivacyGroupId;
final Restriction restriction;
if (input.isEndOfCurrentList()) {
privateFrom = enclavePublicKey;
privateForOrPrivacyGroupId = resolvePrivateForOrPrivacyGroupId(item1);
restriction = convertToEnum(item2.readBytesValue());
} else {
privateFrom = item1.readBytesValue();
privateForOrPrivacyGroupId = resolvePrivateForOrPrivacyGroupId(item2);
restriction = convertToEnum(input.readBytesValue());
}
final BytesValue privateFrom = input.readBytesValue();
final Object privateForOrPrivacyGroupId = resolvePrivateForOrPrivacyGroupId(input.readAsRlp());
final Restriction restriction = convertToEnum(input.readBytesValue());
input.leaveList();

@ -35,7 +35,6 @@ import tech.pegasys.pantheon.ethereum.privacy.Restriction;
import tech.pegasys.pantheon.ethereum.rlp.RLP;
import tech.pegasys.pantheon.ethereum.rlp.RLPException;
import tech.pegasys.pantheon.util.bytes.BytesValue;
import tech.pegasys.pantheon.util.bytes.BytesValues;
import java.util.OptionalLong;
@ -134,9 +133,7 @@ public class EeaSendRawTransaction implements JsonRpcMethod {
private PrivateTransaction decodeRawTransaction(final String hash)
throws InvalidJsonRpcRequestException {
try {
return PrivateTransaction.readFrom(
RLP.input(BytesValue.fromHexString(hash)),
BytesValues.fromBase64(privateTransactionHandler.getEnclaveKey()));
return PrivateTransaction.readFrom(RLP.input(BytesValue.fromHexString(hash)));
} catch (final IllegalArgumentException | RLPException e) {
LOG.debug(e);
throw new InvalidJsonRpcRequestException("Invalid raw private transaction hex", e);

@ -16,6 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import tech.pegasys.pantheon.crypto.SECP256K1;
@ -80,7 +81,7 @@ public class EeaSendRawTransactionTest {
+ "200e885ff29e973e2576b6600181d1b0a2b5294e30d9be4a1981"
+ "ffb33a0b8c8a72657374726963746564";
private static final String VALID_PRIVATE_TRANSACTION_RLP_PRIVACY_GROUP_NO_PRIVATE_FROM =
private static final String PRIVATE_TRANSACTION_RLP_PRIVACY_GROUP_NO_PRIVATE_FROM =
"0xf88b800182520894095e7baea6a6c7c4c2dfeb977efac326af55"
+ "2d8780801ba048b55bfa915ac795c431978d8a6a992b628d55"
+ "7da5ff759b307d495a36649353a01fffd310ac743f371de3b9"
@ -124,9 +125,6 @@ public class EeaSendRawTransactionTest {
@Before
public void before() {
when(transactionPool.getPendingTransactions()).thenReturn(pendingTransactions);
when(privateTxHandler.getEnclaveKey())
.thenReturn("A1aVtMxLCUHmBVHXoZzzBgPbW/wj5axDpW9X8l91SGo=");
method =
new EeaSendRawTransaction(blockchainQueries, privateTxHandler, transactionPool, parameter);
}
@ -278,42 +276,23 @@ public class EeaSendRawTransactionTest {
}
@Test
public void validTransactionPrivacyGroupNoPrivateFromIsSentToTransactionPool() throws Exception {
public void transactionPrivacyGroupNoPrivateFromReturnsError() throws Exception {
when(parameter.required(any(Object[].class), anyInt(), any()))
.thenReturn(VALID_PRIVATE_TRANSACTION_RLP_PRIVACY_GROUP_NO_PRIVATE_FROM);
when(privateTxHandler.sendToOrion(any(PrivateTransaction.class))).thenReturn(MOCK_ORION_KEY);
when(privateTxHandler.getPrivacyGroup(any(String.class), any(PrivateTransaction.class)))
.thenReturn(MOCK_PRIVACY_GROUP);
when(privateTxHandler.validatePrivateTransaction(
any(PrivateTransaction.class), any(String.class)))
.thenReturn(ValidationResult.valid());
when(privateTxHandler.createPrivacyMarkerTransaction(
any(String.class), any(PrivateTransaction.class), any(Long.class)))
.thenReturn(PUBLIC_TRANSACTION);
when(transactionPool.addLocalTransaction(any(Transaction.class)))
.thenReturn(ValidationResult.valid());
.thenReturn(PRIVATE_TRANSACTION_RLP_PRIVACY_GROUP_NO_PRIVATE_FROM);
final JsonRpcRequest request =
new JsonRpcRequest(
"2.0",
"eea_sendRawTransaction",
new String[] {VALID_PRIVATE_TRANSACTION_RLP_PRIVACY_GROUP_NO_PRIVATE_FROM});
new String[] {PRIVATE_TRANSACTION_RLP_PRIVACY_GROUP_NO_PRIVATE_FROM});
final JsonRpcResponse expectedResponse =
new JsonRpcSuccessResponse(
request.getId(), "0x221e930a2c18d91fca4d509eaa3512f3e01fef266f660e32473de67474b36c15");
new JsonRpcErrorResponse(request.getId(), JsonRpcError.DECODE_ERROR);
final JsonRpcResponse actualResponse = method.response(request);
assertThat(actualResponse).isEqualToComparingFieldByField(expectedResponse);
verify(privateTxHandler).sendToOrion(any(PrivateTransaction.class));
verify(privateTxHandler).getPrivacyGroup(any(String.class), any(PrivateTransaction.class));
verify(privateTxHandler)
.validatePrivateTransaction(any(PrivateTransaction.class), any(String.class));
verify(privateTxHandler)
.createPrivacyMarkerTransaction(
any(String.class), any(PrivateTransaction.class), any(Long.class));
verify(transactionPool).addLocalTransaction(any(Transaction.class));
verifyZeroInteractions(privateTxHandler);
}
@Test

Loading…
Cancel
Save