Skip to content

Commit 2624ef7

Browse files
authored
Merge pull request #2015 from darosior/2509_consensus_cleanup_test_vectors
BIP54: Consensus Cleanup test vectors
2 parents 3851847 + 0777a81 commit 2624ef7

File tree

6 files changed

+26112
-1
lines changed

6 files changed

+26112
-1
lines changed

bip-0054.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,24 @@ knowledge, there does not exist an open source reference broadly in use today fo
156156
We encourage mining pools to update their software to craft coinbase transactions that are
157157
forward-compatible with the changes proposed in this BIP.
158158

159+
## Reference implementation
160+
161+
An implementation of BIP54 for Bitcoin Core is available [here][inquisition-implem].
162+
163+
## Test vectors
164+
165+
Documented test vectors are available [here](./bip-0054/test_vectors/) for all mitigations
166+
introduced in this BIP.
167+
159168
## Acknowledgements
160169

161170
This document builds upon an [earlier proposal][BIP-XXXX] by Matt Corallo.
162171

163172
The authors would like to thank everyone involved in researching the most appropriate mitigation for
164173
each of these bugs. We would like to thank in particular Anthony Towns and Sjors Provoost for their
165174
direct contributions to this proposal, as well as @0xb10c and Brian Groll for providing the authors
166-
with data to analyze the proposed mitigations.
175+
with data to analyze the proposed mitigations. Thanks to Chris Stewart for digging up historical
176+
violations to the new transaction size rule, which are partially reused in this BIP's test vectors.
167177

168178
## Copyright
169179

@@ -234,3 +244,4 @@ notably of Bitcoin Core but also of all other implementations the authors are aw
234244
[Delving duplicable]: https://delvingbitcoin.org/t/great-consensus-cleanup-revival/710/4
235245
[Core 0.16.1]: https://bitcoincore.org/en/releases/0.16.1
236246
[Core 29.0]: https://bitcoincore.org/en/releases/29.0
247+
[inquisition-implem]: https://github.com/darosior/bitcoin/tree/2509_inquisition_consensus_cleanup

bip-0054/test_vectors/README.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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 detail.
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

Comments
 (0)