HomePhabricator

[backport#16821] Fix bug where duplicate PSBT keys are accepted

Description

[backport#16821] Fix bug where duplicate PSBT keys are accepted

Summary:
9743432034586385cfef87df4b377c255ed0cba8 Fix bug where duplicate PSBT keys are accepted (John L. Jegutanis)

Pull request description:

As per the BIP 174 spec a PSBT key cannot be duplicated,
however the current code accepts key duplication.
The PSBT key/value entries can be duplicated when the value
is `empty()` or `IsNull()` for `CScript` or `CTxOut` respectively
and if those key/value entries are serialized before the non-empty ones.

For example, the following PSBT, included in the test vectors,
contains a duplicate field:

```
// magic
70736274ff

// global tx
//// key
0100
//// value
2a02000000000140420f000000000017a9146e91b72d5593e7d4391e2ff44e91e985c31641f08700000000
//// separator
00

// no inputs

// outputs
//// key PSBT_OUT_WITNESSSCRIPT
0101
//// value (empty script)
00
//// key PSBT_OUT_WITNESSSCRIPT (same as the above)
0101
//// value (an OP_RETURN script)
016a
//// separator
00
```

ACKs for top commit:

achow101:
  ACK 9743432034586385cfef87df4b377c255ed0cba8
instagibbs:
  code review ACK https://github.com/bitcoin/bitcoin/pull/16821/commits/9743432034586385cfef87df4b377c255ed0cba8

Backport of Core PR16821

Test Plan:

ninja all check check-functional

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

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

Details

Provenance
fanquake <fanquake@gmail.com>Authored on Oct 9 2019, 13:04
majcostaCommitted on Oct 7 2020, 23:08
majcostaPushed on Oct 7 2020, 23:08
Reviewer
Restricted Project
Differential Revision
D7809: [backport#16821] Fix bug where duplicate PSBT keys are accepted
Parents
rABC64fb78dde102: [backport#12461] scripted-diff: Rename key size consts to be relative to their…
Branches
Unknown
Tags
Unknown