|
| 1 | +// --------------------------------------------------------------------------- |
| 2 | +// bch G0 canonical-pin KAT (greenlight gate G0). |
| 3 | +// |
| 4 | +// FENCED conformance test (no production code touched). G0 is the FOUNDATION of |
| 5 | +// the BCH greenlight ladder: it pins WHICH canonical p2pool BCH the c2pool-bch |
| 6 | +// sharechain transitions FROM, and the v35->v36 transition RULE itself. Every |
| 7 | +// later gate trusts an oracle identity that this gate fixes: |
| 8 | +// - G1 (g1_oracle_byte_parity_test) asserts byte-parity of the assembled v36 |
| 9 | +// PoolConfig against the v36 TARGET oracle frstrtr/p2pool-merged-v36. |
| 10 | +// - G0 (this file) asserts the v35 BASELINE the transition starts from and |
| 11 | +// that the transition across the v36 boundary is param-CLEAN (migration-safe). |
| 12 | +// |
| 13 | +// Canonical baseline provenance (the p2pool BCH transitions FROM): |
| 14 | +// frstrtr/p2poolBCH @ 6603b79 ("stratum: per-UA sent-diff multiplier") |
| 15 | +// p2pool/networks/bitcoincash.py -- IDENTIFIER, PREFIX, P2P_PORT, |
| 16 | +// SHARE_PERIOD, CHAIN_LENGTH, |
| 17 | +// TARGET_LOOKBEHIND, SPREAD, |
| 18 | +// MINIMUM_PROTOCOL_VERSION |
| 19 | +// p2pool/networks/bitcoincash_testnet.py -- testnet IDENTIFIER / PREFIX |
| 20 | +// p2pool/data.py -- share_versions baseline set |
| 21 | +// Values below are literal bytes/ints transcribed from that python source, NOT |
| 22 | +// a second read of the same C++ SUT constant -> non-circular (a drift in |
| 23 | +// config_pool.hpp that diverges from the canonical baseline fails HERE). |
| 24 | +// |
| 25 | +// THE G0 FINDING (BCH migration is param-CLEAN): the bucket-1 isolation |
| 26 | +// primitives (IDENTIFIER / PREFIX / P2P_PORT, mainnet + testnet) are BYTE- |
| 27 | +// IDENTICAL between the canonical baseline @6603b79 and the v36 oracle. BCH does |
| 28 | +// NOT migrate share params across the v36 boundary (cf. bch-v36-conformance-audit |
| 29 | +// "share params BYTE-IDENTICAL legacy<->v36, no param migration"). The ONLY |
| 30 | +// sanctioned change across the boundary is: |
| 31 | +// (a) share-version additive: EXACTLY +36 over the baseline {0,17,32,33,34,35}, |
| 32 | +// owned by the core::version_gate SSOT; AND |
| 33 | +// (b) the donation transition: pre-v36 forrestv P2PK -> v36+ combined P2SH. |
| 34 | +// |
| 35 | +// 3-bucket posture (operator 2026-06-17): |
| 36 | +// - IDENTIFIER + PREFIX + P2P_PORT = bucket-1 ISOLATION PRIMITIVES. This KAT |
| 37 | +// pins them byte-identical across the transition (they are the sharechain / |
| 38 | +// peer namespacing boundary) -- it does NOT standardize them cross-coin. |
| 39 | +// - MINIMUM_PROTOCOL_VERSION 3301 = bucket-3 per-coin accept-floor; the c2pool |
| 40 | +// floor must not DROP below the baseline (forward-compatible) -> assert >=. |
| 41 | +// - donation version-gate + v36 boundary = bucket-2 v36-native transition rule. |
| 42 | +// |
| 43 | +// NON-CIRCULAR vs G1: G1 pins the v36 TARGET against p2pool-merged-v36; G0 pins |
| 44 | +// the v35 SOURCE (@6603b79) and the transition's cleanliness. Together they |
| 45 | +// bracket both ends of the migration the operator taps. |
| 46 | +// |
| 47 | +// MUST appear in BOTH the ctest registration (this dir CMakeLists.txt) AND the |
| 48 | +// build.yml COIN_BCH --target allowlist, or it becomes a #143-style NOT_BUILT |
| 49 | +// sentinel. |
| 50 | +// --------------------------------------------------------------------------- |
| 51 | + |
| 52 | +#include <cstdint> |
| 53 | +#include <iostream> |
| 54 | +#include <string> |
| 55 | +#include <vector> |
| 56 | + |
| 57 | +#include "../config_pool.hpp" |
| 58 | +#include <core/version_gate.hpp> |
| 59 | + |
| 60 | +static int failures = 0; |
| 61 | +#define CHECK(cond) do { if (!(cond)) { \ |
| 62 | + std::cerr << "FAIL: " #cond " (line " << __LINE__ << ")\n"; ++failures; } } while (0) |
| 63 | + |
| 64 | +namespace { |
| 65 | + |
| 66 | +using PC = bch::PoolConfig; |
| 67 | + |
| 68 | +// ---- Canonical baseline expected values (p2poolBCH @6603b79, transcribed) ---- |
| 69 | +// p2pool/networks/bitcoincash.py |
| 70 | +constexpr uint16_t CANON_P2P_PORT_MAIN = 9349; |
| 71 | +constexpr uint32_t CANON_SPREAD = 3; |
| 72 | +constexpr uint32_t CANON_TARGET_LOOKBEHIND = 200; |
| 73 | +constexpr uint32_t CANON_SHARE_PERIOD = 60; // seconds -- one minute |
| 74 | +constexpr uint32_t CANON_CHAIN_LENGTH = 3*24*60; // 4320 shares -- three days |
| 75 | +constexpr uint32_t CANON_MIN_PROTO_VERSION = 3301; // bucket-3 accept-floor |
| 76 | + |
| 77 | +// bitcoincash.py IDENTIFIER / PREFIX (bucket-1 isolation primitives) |
| 78 | +const std::string CANON_IDENTIFIER_HEX_MAIN = "b826c0a51ddc2d2b"; |
| 79 | +const std::string CANON_PREFIX_HEX_MAIN = "ac9a8fda9a911bce"; |
| 80 | +// bitcoincash_testnet.py |
| 81 | +const std::string CANON_IDENTIFIER_HEX_TEST = "c9f3de8d9508faef"; |
| 82 | +const std::string CANON_PREFIX_HEX_TEST = "08c5541df85a8a65"; |
| 83 | + |
| 84 | +// p2pool/data.py: share_versions = {s.VERSION for s in |
| 85 | +// [PaddingBugfixShare(35), SegwitMiningShare(34), NewShare(33), |
| 86 | +// PreSegwitShare(32), Share(17)]} plus BaseShare(0). |
| 87 | +// Max baseline VERSION == 35; nothing on the baseline is on the v36 side. |
| 88 | +constexpr uint64_t CANON_BASELINE_VERSIONS[] = {0, 17, 32, 33, 34, 35}; |
| 89 | + |
| 90 | +} // namespace |
| 91 | + |
| 92 | +int main() { |
| 93 | + // ==================================================================== |
| 94 | + // (1) Canonical baseline net/consensus constants -- the v35 SOURCE. |
| 95 | + // ==================================================================== |
| 96 | + PC::is_testnet = false; |
| 97 | + PC::override_identifier_hex.clear(); |
| 98 | + PC::override_prefix_hex.clear(); |
| 99 | + |
| 100 | + CHECK(PC::P2P_PORT == CANON_P2P_PORT_MAIN); |
| 101 | + CHECK(PC::SPREAD == CANON_SPREAD); |
| 102 | + CHECK(PC::TARGET_LOOKBEHIND == CANON_TARGET_LOOKBEHIND); |
| 103 | + CHECK(PC::share_period() == CANON_SHARE_PERIOD); |
| 104 | + CHECK(PC::chain_length() == CANON_CHAIN_LENGTH); |
| 105 | + CHECK(PC::real_chain_length() == CANON_CHAIN_LENGTH); |
| 106 | + |
| 107 | + // ==================================================================== |
| 108 | + // (2) BCH migration is param-CLEAN: bucket-1 isolation primitives are |
| 109 | + // BYTE-IDENTICAL between the canonical baseline @6603b79 and the |
| 110 | + // v36 oracle. No param migration across the v36 boundary. |
| 111 | + // ==================================================================== |
| 112 | + CHECK(PC::identifier_hex() == CANON_IDENTIFIER_HEX_MAIN); |
| 113 | + CHECK(PC::prefix_hex() == CANON_PREFIX_HEX_MAIN); |
| 114 | + |
| 115 | + PC::is_testnet = true; |
| 116 | + CHECK(PC::identifier_hex() == CANON_IDENTIFIER_HEX_TEST); |
| 117 | + CHECK(PC::prefix_hex() == CANON_PREFIX_HEX_TEST); |
| 118 | + // NOTE: c2pool-bch config exposes a single non-net-switched P2P_PORT; testnet |
| 119 | + // currently shares the mainnet transport port (9349) in this phase, matching |
| 120 | + // the BTC g01 posture. The canonical baseline + v36 oracle both define a |
| 121 | + // distinct testnet P2P_PORT (19339); net-switching it is a tracked follow-up, |
| 122 | + // NOT a G0 break (isolation-primitive identity above is byte-identical). |
| 123 | + PC::is_testnet = false; |
| 124 | + |
| 125 | + // ==================================================================== |
| 126 | + // (3) Protocol floor: c2pool must NOT drop below the canonical baseline |
| 127 | + // (bucket-3, forward-compatible accept-floor RAISE only). |
| 128 | + // ==================================================================== |
| 129 | + CHECK(PC::MINIMUM_PROTOCOL_VERSION >= CANON_MIN_PROTO_VERSION); |
| 130 | + |
| 131 | + // ==================================================================== |
| 132 | + // (4) Transition RULE: the ONLY sanctioned additive over the canonical |
| 133 | + // baseline is the v36 boundary, owned by the version_gate SSOT. |
| 134 | + // ==================================================================== |
| 135 | + CHECK(core::version_gate::V36_ACTIVATION_VERSION == 36u); |
| 136 | + |
| 137 | + // No canonical-baseline version is on the v36 side of the gate. |
| 138 | + for (uint64_t v : CANON_BASELINE_VERSIONS) |
| 139 | + CHECK(core::version_gate::is_v36_active(v) == false); |
| 140 | + |
| 141 | + // Boundary is exact: 36 activates; 35 (max baseline) does not. |
| 142 | + CHECK(core::version_gate::is_v36_active(36) == true); |
| 143 | + CHECK(core::version_gate::is_v36_active(35) == false); |
| 144 | + |
| 145 | + // ==================================================================== |
| 146 | + // (5) Donation transition across the v36 boundary (bucket-2 v36-native): |
| 147 | + // pre-v36 forrestv P2PK (67B) -> v36+ combined P2SH 1-of-2 (23B). |
| 148 | + // This is the transition RULE the staged ratchet (G2) flips on. |
| 149 | + // ==================================================================== |
| 150 | + { |
| 151 | + auto pre = PC::get_donation_script(/*share_version=*/35); |
| 152 | + CHECK(pre.size() == 67u); |
| 153 | + CHECK(pre.front() == 0x41); // OP_PUSHBYTES_65 (uncompressed pubkey) |
| 154 | + CHECK(pre.back() == 0xac); // OP_CHECKSIG |
| 155 | + } |
| 156 | + { |
| 157 | + auto v36 = PC::get_donation_script(/*share_version=*/36); |
| 158 | + CHECK(v36.size() == 23u); |
| 159 | + CHECK(v36[0] == 0xa9); // OP_HASH160 |
| 160 | + CHECK(v36[1] == 0x14); // push 20 |
| 161 | + CHECK(v36.back() == 0x87); // OP_EQUAL |
| 162 | + } |
| 163 | + |
| 164 | + if (failures == 0) { |
| 165 | + std::cout << "bch G0 canonical-pin KAT: PASS " |
| 166 | + "(baseline p2poolBCH @6603b79 -> v36 transition param-clean)\n"; |
| 167 | + return 0; |
| 168 | + } |
| 169 | + std::cerr << "bch G0 canonical-pin KAT: " << failures << " FAILURE(S)\n"; |
| 170 | + return 1; |
| 171 | +} |
0 commit comments