Skip to content

Commit

Permalink
Allow signing private transaction with any key (PegaSysEng#1561)
Browse files Browse the repository at this point in the history
- Previously you had to sign the private transaction with the same key as the privacy marker transaction.
  • Loading branch information
iikirilov authored and ekellstrand committed Jun 13, 2019
1 parent f39b0b6 commit 1d4946c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand All @@ -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;

Expand All @@ -68,6 +70,7 @@ public 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;
}
Expand Down Expand Up @@ -112,7 +115,7 @@ public Transaction createPrivacyMarkerTransaction(
.to(privacyPrecompileAddress)
.value(privateTransaction.getValue())
.payload(BytesValue.wrap(transactionEnclaveKey.getBytes(Charsets.UTF_8)))
.sender(privateTransaction.getSender())
.sender(signerAddress)
.signAndBuild(nodeKeyPair);
}

Expand Down Expand Up @@ -185,4 +188,8 @@ private long getSenderNonce(
// private state does not exist
Account.DEFAULT_NONCE);
}

public Address getSignerAddress() {
return signerAddress;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ public JsonRpcResponse response(final JsonRpcRequest request) {
() -> {
final Transaction privacyMarkerTransaction =
privateTransactionHandler.createPrivacyMarkerTransaction(
enclaveKey, privateTransaction, getNonce(privateTransaction.getSender()));
enclaveKey,
privateTransaction,
getNonce(privateTransactionHandler.getSignerAddress()));
return transactionPool
.addLocalTransaction(privacyMarkerTransaction)
.either(
Expand Down

0 comments on commit 1d4946c

Please sign in to comment.