|
| 1 | +## BIP54 test vectors |
| 2 | + |
| 3 | +This folder contains a set of test vectors for each mitigation introduced in the BIP. This document |
| 4 | +presents them in more details. |
| 5 | + |
| 6 | +The code used to generate half of the test vectors is included with the implementation and available |
| 7 | +[here][other-vectors]. The other half requires mining mainnet blocks and is [published |
| 8 | +separately][bip54-miner]. In both cases it is implemented as a regular Bitcoin Core unit test, and |
| 9 | +the test vectors are persisted as a JSON file if the `UPDATE_JSON_TESTS` preprocessor directive is |
| 10 | +set (off by default). |
| 11 | + |
| 12 | +To compile the [header][header-miner] and [block][block-miner] miners you may have to link to |
| 13 | +libatomic explicitly. This can be achieved like so: |
| 14 | +``` |
| 15 | +cmake -B atomicbuild -DAPPEND_LDFLAGS="-latomic" |
| 16 | +cmake --build atomicbuild/ -j $(nproc) |
| 17 | +``` |
| 18 | + |
| 19 | +[Premined headers][premined-headers] are also provided along with the header miner to allow changing |
| 20 | +some of the last headers without having to re-generate the whole chain. |
| 21 | + |
| 22 | + |
| 23 | +### Difficulty adjustment exploits |
| 24 | + |
| 25 | +The [`timestamps.json`](./timestamps.json) test vectors exercise the two constraints on block header |
| 26 | +timestamps introduced by BIP54 to mitigate the Timewarp and Murch-Zawy attacks. Each test case |
| 27 | +features a chain of mainnet headers starting from the genesis block, and whether this header chain |
| 28 | +is valid by BIP54 rules. Each test case also contains a comment describing why this particular chain |
| 29 | +is (in)valid according to BIP54. All test cases are valid according to current Bitcoin consensus |
| 30 | +rules. It is intended to be used to test a BIP54 implementation by feeding the header chain to a |
| 31 | +Bitcoin node implementation, enforcing the BIP54 rules on this chain from genesis. |
| 32 | + |
| 33 | +The test vector file features a JSON array of JSON objects, each corresponding to a test case. Each |
| 34 | +JSON object features the following entries: |
| 35 | +- `header_chain`: a JSON array of strings. An ordered list of hex-encoded mainnet block headers. |
| 36 | +- `valid`: a JSON boolean. Whether this chain of headers is valid according to BIP54. |
| 37 | +- `comment`: a JSON string. Description of the test case. |
| 38 | + |
| 39 | +For the purpose of testing a Timewarp fix, a Timewarp attack was included early on in the history of |
| 40 | +testnet3. An implementer of BIP54 may want to ensure that syncing testnet3 by enforcing BIP54 since |
| 41 | +genesis will treat block `00000000118da1e2165a19307b86f87eba814845e8a0f99734dce279ca3fb029` as |
| 42 | +invalid. |
| 43 | + |
| 44 | + |
| 45 | +### Long block validation time |
| 46 | + |
| 47 | +The [`sigops.json`](sigops.json) file contains test vectors for the limit on the number of |
| 48 | +potentially-executed legacy signature operations in a single transaction, introduced by BIP54 in |
| 49 | +order to mitigate long block validation times. Each test case represents a transaction and whether a |
| 50 | +block containing it would be valid according to BIP54. The test cases feature an extensive set of |
| 51 | +combinations of inputs and output types, ways to run into the limit, historical violations and some |
| 52 | +pathological transactions exhibiting the specific implementation details. All test cases but those |
| 53 | +belonging to this last category feature transactions that are valid under current Bitcoin consensus |
| 54 | +rules. Each test case also features a comment describing why the transaction is (in)valid according |
| 55 | +to BIP54. |
| 56 | + |
| 57 | +The test vector file features a JSON array of JSON objects, each corresponding to a test case. Each |
| 58 | +JSON object features the following entries: |
| 59 | +- `spent_outputs`: a JSON array of strings. An ordered list of hex-encoded Bitcoin-serialized |
| 60 | + transaction outputs spent by each input of this test case's transaction. |
| 61 | +- `tx`: a JSON string. A hex-encoded Bitcoin-serialized transaction to be evaluated. |
| 62 | +- `valid`: a JSON boolean. Whether this transaction is valid according to current consensus rules |
| 63 | + supplemented by BIP54. |
| 64 | +- `comment`: a JSON string. Description of the test case. |
| 65 | + |
| 66 | + |
| 67 | +### Merkle tree malleability with 64-byte transactions |
| 68 | + |
| 69 | +The [`txsize.json`](./txsize.json) file contains test cases exercising the new constraint on |
| 70 | +non-witness transaction size introduced in BIP54. Each test case contains a transaction and whether |
| 71 | +it would be valid according to BIP54, as well as a comment describing why it is (in)valid. All test |
| 72 | +cases are otherwise valid according to current Bitcoin consensus rules. |
| 73 | + |
| 74 | +The test vector file features a JSON array of JSON objects, each corresponding to a test case. Each |
| 75 | +JSON object features the following entries: |
| 76 | +- `tx`: a JSON string. A hex-encoded Bitcoin-serialized transaction to be evaluated. |
| 77 | +- `valid`: a JSON boolean. Whether this transaction is valid according to BIP54. |
| 78 | +- `comment`: a JSON string. Description of the test case. |
| 79 | + |
| 80 | + |
| 81 | +### Possibility of duplicate coinbase transactions |
| 82 | + |
| 83 | +The [`coinbases.json`](./coinbases.json) file contains test cases exercising the new restrictions on |
| 84 | +coinbase transactions introduced in BIP54 to prevent duplicate coinbase transactions without |
| 85 | +resorting to BIP30 validation. Each test case contains a chain of mainnet blocks (including the |
| 86 | +genesis block), and whether this block chain is valid according to BIP54. All test cases are valid |
| 87 | +according to current Bitcoin's consensus rules, except one that features a block containing a |
| 88 | +coinbase transaction timelocked to a future block height. |
| 89 | + |
| 90 | +The test vector file features a JSON array of JSON objects, each corresponding to a test case. Each |
| 91 | +JSON object features the following entries: |
| 92 | +- `block_chain`: a JSON array of strings. An ordered list of hex-encoded mainnet blocks. |
| 93 | +- `valid`: a JSON boolean. Whether this block chain is valid according to current Bitcoin consensus |
| 94 | + rules supplemented by BIP54. |
| 95 | +- `comment`: a JSON string. Description of the test case. |
| 96 | + |
| 97 | + |
| 98 | +[bip54-miner]: https://github.com/darosior/bitcoin/blob/bip54_miner/commits |
| 99 | +[header-miner]: https://github.com/darosior/bitcoin/blob/bip54_miner/src/test/bip54_header_miner.cpp |
| 100 | +[block-miner]: https://github.com/darosior/bitcoin/blob/bip54_miner/src/test/bip54_block_miner.cpp |
| 101 | +[other-vectors]: https://github.com/darosior/bitcoin/blob/2509_inquisition_consensus_cleanup/src/test/bip54_tests.cpp |
| 102 | +[premined-headers]: https://github.com/darosior/bitcoin/blob/bip54_miner/src/test/bip54_premined_headers.h |
0 commit comments