协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
bitcoin-testing-property-based【开发与工程】Property-based testing: proptest / quickcheck (Rust), hypothesis (Python). Strategies for tx serialization, descriptor round-trip, miniscript satisfaction. USE WHEN: testing Bitcoin parsers, ensuring round-trip invariants, catching edge cases beyond example tests.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Test that properties (universal invariants) hold for all inputs, not just specific examples.
Common properties:
decode(encode(x)) == x for tx, script, address,
descriptor, PSBT.H(x) == H(x) always; consistent across
serialization.use proptest::prelude::*;
proptest! {
#[test]
fn tx_roundtrip(tx in any_tx()) {
let encoded = tx.consensus_encode_to_vec();
let decoded = Transaction::consensus_decode(&mut &encoded[..]).unwrap();
prop_assert_eq!(tx, decoded);
}
}
#[quickcheck]
fn descriptor_checksum_invariant(desc: ValidDescriptor) -> bool {
let s = desc.to_string();
let with_checksum = with_checksum(&s);
parse(&with_checksum).is_ok()
}
from hypothesis import given, strategies as st
@given(st.binary(min_size=1, max_size=520))
def test_script_roundtrip(data):
s = Script(data)
assert Script(bytes(s)) == s
| Aspect | Example tests | Property-based |
|---|---|---|
| Coverage | known cases | random + edge |
| Setup effort | low | medium (writing strategies) |
| Bug discovery | misses unknowns | finds unknowns |
| Failure repro | trivial | needs shrinking |
proptest_config!().A property test samples the input space; a machine-checked proof quantifies over all of it. For consensus code — where the failing input is exactly the one no test suite imagined — the tier above proptest is a proof assistant.
ComputeMerkleRoot (src/consensus/merkle.cpp),
mutation scan included, is transcribed into Lean and proved to imply
the spec's canonicality, so two nonempty equal-width leaf lists Core
accepts with equal roots are equal — or a concrete double-SHA-256
collision exists.libshrincs is a
proof-of-concept (as of September 2026) tying a C implementation of
SHRINCS' WOTS+C leaf signature to a game-based one-time-unforgeability
bound via Rocq/VST plus SSProve, under six named SHA-256 hardness
assumptions.What a proof does not buy: it is about a model and its stated assumptions. btc-verified's author is explicit that the repository "is structurally incapable of giving guarantees about Bitcoin Core's behavior" — a wrong model, an unproved axiom, or a compiler doing something else all still bite. Property tests remain the cheap check that the model matches the code you ship.