From 3e4953fd23f1096e2733570180cf7a2f469c8386 Mon Sep 17 00:00:00 2001 From: Ivaylo Kirilov Date: Thu, 13 Jun 2019 20:48:39 +0100 Subject: [PATCH] Allow signing private transaction with any key (#1561) - Previously you had to sign the private transaction with the same key as the privacy marker transaction. Signed-off-by: Adrian Sutton --- .../ethereum/privacy/PrivateTransactionHandler.java | 9 ++++++++- .../internal/methods/privacy/EeaSendRawTransaction.java | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionHandler.java b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionHandler.java index 93b8b6c802..35ad7c22e2 100644 --- a/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionHandler.java +++ b/ethereum/core/src/main/java/tech/pegasys/pantheon/ethereum/privacy/PrivateTransactionHandler.java @@ -23,6 +23,7 @@ import tech.pegasys.pantheon.enclave.types.SendRequest; import tech.pegasys.pantheon.enclave.types.SendResponse; import tech.pegasys.pantheon.ethereum.core.Account; import tech.pegasys.pantheon.ethereum.core.Address; +import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.core.PrivacyParameters; import tech.pegasys.pantheon.ethereum.core.Transaction; import tech.pegasys.pantheon.ethereum.mainnet.TransactionValidator.TransactionInvalidReason; @@ -47,6 +48,7 @@ public class PrivateTransactionHandler { private final Enclave enclave; private final Address privacyPrecompileAddress; private final SECP256K1.KeyPair nodeKeyPair; + private final Address signerAddress; private final PrivateStateStorage privateStateStorage; private final WorldStateArchive privateWorldStateArchive; @@ -68,6 +70,7 @@ public class PrivateTransactionHandler { this.enclave = enclave; this.privacyPrecompileAddress = privacyPrecompileAddress; this.nodeKeyPair = nodeKeyPair; + this.signerAddress = Address.extract(Hash.hash(nodeKeyPair.getPublicKey().getEncodedBytes())); this.privateStateStorage = privateStateStorage; this.privateWorldStateArchive = privateWorldStateArchive; } @@ -112,7 +115,7 @@ public class PrivateTransactionHandler { .to(privacyPrecompileAddress) .value(privateTransaction.getValue()) .payload(BytesValue.wrap(transactionEnclaveKey.getBytes(Charsets.UTF_8))) - .sender(privateTransaction.getSender()) + .sender(signerAddress) .signAndBuild(nodeKeyPair); } @@ -185,4 +188,8 @@ public class PrivateTransactionHandler { // private state does not exist Account.DEFAULT_NONCE); } + + public Address getSignerAddress() { + return signerAddress; + } } diff --git a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaSendRawTransaction.java b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaSendRawTransaction.java index 1b05c0f9a5..f3c74fef7b 100644 --- a/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaSendRawTransaction.java +++ b/ethereum/jsonrpc/src/main/java/tech/pegasys/pantheon/ethereum/jsonrpc/internal/methods/privacy/EeaSendRawTransaction.java @@ -108,7 +108,9 @@ public class EeaSendRawTransaction implements JsonRpcMethod { () -> { final Transaction privacyMarkerTransaction = privateTransactionHandler.createPrivacyMarkerTransaction( - enclaveKey, privateTransaction, getNonce(privateTransaction.getSender())); + enclaveKey, + privateTransaction, + getNonce(privateTransactionHandler.getSignerAddress())); return transactionPool .addLocalTransaction(privacyMarkerTransaction) .either(