HomePhabricator

[backport#16753] wallet: extract PubKey from P2PK script with Solver

Description

[backport#16753] wallet: extract PubKey from P2PK script with Solver

Summary:
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

https://github.com/bitcoin/bitcoin/pull/16753/commits/798a589aff64b83a0844688a661f4bd987c3340c

Backport of Core PR16753

Test Plan:

ninja check check-functional

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D6999

Details

Provenance
fanquake <fanquake@gmail.com>Authored on Aug 30 2019, 01:10
majcostaCommitted on Jul 22 2020, 18:38
majcostaPushed on Jul 22 2020, 18:38
Reviewer
Restricted Project
Differential Revision
D6999: [backport#16753] wallet: extract PubKey from P2PK script with Solver
Parents
rABCb4fa9a213c24: Fix OSX SDK caching in Gitian builds
Branches
Unknown
Tags
Unknown