Page MenuHomePhabricator

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

Authored by majcosta on Jul 21 2020, 23:15.

Details

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

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Jul 22 2020, 06:49

[Bot Message]
One or more PR numbers were detected in the summary.
Links to those PRs have been inserted into the summary for reference.