aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2019-08-30 09:10:08 +0800
committerfanquake <fanquake@gmail.com>2019-08-30 09:22:31 +0800
commita8ecd0dadaabaaf8c87dfc42d5e27cf2cd714132 (patch)
tree6220e74c9bd8aae07259e79edae7a3faa013d346 /src
parent74da99e010744e8759e728a6e136e13c9b3ba433 (diff)
parent798a589aff64b83a0844688a661f4bd987c3340c (diff)
Merge #16753: wallet: extract PubKey from P2PK script with Solver
798a589aff64b83a0844688a661f4bd987c3340c wallet: extract PubKey from P2PK script with Solver (Sebastian Falbesoner) Pull request description: The function `ExtractPubKey()` checks if a given script matches the P2PK pattern (`<PubKey> OP_CHECKSIG`), extracts the PubKey and additionally checks if it is cryptographically valid (full validation with ECC library via `CPubKey::IsFullyValid()`). Currently this is done manually in the following order: 1. check if first script OP is data push with valid PubKey length (first part of pattern match), extract PubKey 2. create `CPubKey` object with extracted PubKey 3. fully validate public key 4. check if last script OP is `OP_CHECKSIG` (second part of pattern match) Using Solver, the pattern matching and PubKey extraction can be done via a single step, leading to the following simplified order with shorter code: 1. check if given script matches P2PK pattern with Solver (also contains valid PubKey length check), extracts Pubkey 2. create `CPubKey` object with extracted Pubkey 3. fully validate public key ACKs for top commit: instagibbs: utACK https://github.com/bitcoin/bitcoin/pull/16753/commits/798a589aff64b83a0844688a661f4bd987c3340c theStack: > utACK [798a589](https://github.com/bitcoin/bitcoin/commit/798a589aff64b83a0844688a661f4bd987c3340c) sipa: ACK 798a589aff64b83a0844688a661f4bd987c3340c achow101: Code Review ACK 798a589aff64b83a0844688a661f4bd987c3340c Tree-SHA512: 350358a89afed8c2a7967c50e9714a2d4a909259b50e694ce68dde3e7d0fa0bf3238d33642e73f2bdb53860f6d3f7327ca3eb6426b74eaffacfbca0a384d68cd
Diffstat (limited to 'src')
-rw-r--r--src/wallet/wallet.cpp15
1 files changed, 3 insertions, 12 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 03acf23508..f4992e5ab6 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -523,18 +523,9 @@ bool CWallet::LoadCScript(const CScript& redeemScript)
static bool ExtractPubKey(const CScript &dest, CPubKey& pubKeyOut)
{
- //TODO: Use Solver to extract this?
- CScript::const_iterator pc = dest.begin();
- opcodetype opcode;
- std::vector<unsigned char> vch;
- if (!dest.GetOp(pc, opcode, vch) || !CPubKey::ValidSize(vch))
- return false;
- pubKeyOut = CPubKey(vch);
- if (!pubKeyOut.IsFullyValid())
- return false;
- if (!dest.GetOp(pc, opcode, vch) || opcode != OP_CHECKSIG || dest.GetOp(pc, opcode, vch))
- return false;
- return true;
+ std::vector<std::vector<unsigned char>> solutions;
+ return Solver(dest, solutions) == TX_PUBKEY &&
+ (pubKeyOut = CPubKey(solutions[0])).IsFullyValid();
}
bool CWallet::AddWatchOnlyInMem(const CScript &dest)