Skip to content

Commit 2b1ac2b

Browse files
authored
btc: G0/G1 bake golden share-format fixture + parity KAT (#392)
* btc: G0/G1 bake golden share-format fixture + parity KAT Bake the BTC share-format baseline now that the fork pin is resolved to p2pool-btc-jtoomim @ ece15b03fc23. Emit the golden fixture via tools/conformance/extract_share_format.py (static extraction) and add a gtest KAT that asserts the c2pool BTC port against it. Bucket discipline (3-bucket rule): - Isolation primitives (IDENTIFIER/PREFIX/P2P_PORT/SEGWIT=33): byte-equal. - MINIMUM_PROTOCOL_VERSION: c2pool floor (3500) >= baseline (3301), an intentional forward-compatible raise, not a parity break. - share-versions additive-v36: boundary pinned by BTC_version_gate KAT. Rides the existing allowlisted btc_share_test exe (no new target, no build.yml change). btc_share_test 14/14 green; fixture re-emit MATCH 9/9. * btc/test: G0/G1 lock share-version additive to exactly v36 (version_gate SSOT) Strengthen the G0/G1 share-format parity gate so an unsanctioned extra/ shifted share-version fails here, not only in the separate activation- boundary KAT. c2pool has no p2pool-style version array to compare element- wise, so the single sanctioned additive over the baseline [0,17,32,33,34,35] is locked against core::version_gate::V36_ACTIVATION_VERSION (==36) plus an exact-boundary check (36 active, 35 not). Baseline set transcribed from btc.g01.golden.json @ ece15b03fc23. Test-only, fenced to src/impl/btc/test. --------- Co-authored-by: frstrtr <frstrtr@users.noreply.github.com>
1 parent f649af7 commit 2b1ac2b

3 files changed

Lines changed: 122 additions & 1 deletion

File tree

src/impl/btc/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
if (BUILD_TESTING AND GTest_FOUND)
22
# btc twin of ltc share_test — uniquely named to avoid the CMP0002 target
33
# collision with src/impl/ltc/test (both subdirs build in the same tree).
4-
add_executable(btc_share_test share_test.cpp f11_donation_invariance_test.cpp f10b_version_punish_removal_test.cpp)
4+
add_executable(btc_share_test share_test.cpp f11_donation_invariance_test.cpp f10b_version_punish_removal_test.cpp g01_share_format_parity_test.cpp)
55
target_link_libraries(btc_share_test PRIVATE
66
GTest::gtest_main GTest::gtest
77
core btc
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include <gtest/gtest.h>
2+
3+
#include <string>
4+
5+
#include <impl/btc/config_pool.hpp>
6+
#include <core/version_gate.hpp> // SSOT: V36_ACTIVATION_VERSION / is_v36_active
7+
8+
// G0/G1 — BTC share-format byte-parity against the BAKED p2pool baseline.
9+
//
10+
// Golden fixture: tools/conformance/fixtures/btc.g01.golden.json
11+
// provenance: p2pool-btc-jtoomim @ ece15b03fc23 (the canonical BTC fork pin),
12+
// emitted by tools/conformance/extract_share_format.py (static extraction).
13+
//
14+
// The fixture is the SSOT; the literals below are transcribed from it so the
15+
// C++ port asserts byte-identity at run time. If the fixture is re-baked (a
16+
// fork re-pin => a different --tree), update both in lockstep; the python
17+
// `compare` subcommand guards the fixture against silent baseline drift.
18+
//
19+
// Bucket discipline (operator 3-bucket rule):
20+
// * ISOLATION PRIMITIVES (IDENTIFIER / PREFIX / P2P_PORT) — must be
21+
// byte-identical to the live sharechain or peers reject us. EQUALITY.
22+
// * Intentional / v36-native deltas — NOT asserted equal here:
23+
// - MINIMUM_PROTOCOL_VERSION: c2pool raises the floor (3500) above the
24+
// baseline (3301) to admit jtoomim-master/SPB and exclude forrestv-era
25+
// v17/v32. A floor RAISE is forward-compatible => assert >=, not ==.
26+
// - share-versions: c2pool is additive-v36 over the baseline [0..35]; the
27+
// v36 activation boundary is pinned separately by
28+
// BTC_version_gate.V36ActivationBoundary. Not re-asserted here.
29+
30+
namespace {
31+
32+
// --- transcribed from btc.g01.golden.json @ ece15b03fc23 ---------------------
33+
constexpr const char* GOLDEN_IDENTIFIER = "fc70035c7a81bc6f";
34+
constexpr const char* GOLDEN_PREFIX = "2472ef181efcd37b";
35+
constexpr uint16_t GOLDEN_P2P_PORT = 9333;
36+
constexpr uint32_t GOLDEN_SEGWIT_ACTIVATION_VERSION = 33;
37+
constexpr uint32_t GOLDEN_MINIMUM_PROTOCOL_VERSION = 3301;
38+
39+
} // namespace
40+
41+
// Isolation primitives: byte-identical or we are off-network.
42+
TEST(BTC_g01_share_format, IsolationPrimitivesMatchBaseline)
43+
{
44+
EXPECT_EQ(btc::PoolConfig::DEFAULT_IDENTIFIER_HEX, std::string(GOLDEN_IDENTIFIER));
45+
EXPECT_EQ(btc::PoolConfig::DEFAULT_PREFIX_HEX, std::string(GOLDEN_PREFIX));
46+
EXPECT_EQ(btc::PoolConfig::P2P_PORT, GOLDEN_P2P_PORT);
47+
// Testnet shares the mainnet transport identity in this phase (config_pool).
48+
EXPECT_EQ(btc::PoolConfig::TESTNET_IDENTIFIER_HEX, std::string(GOLDEN_IDENTIFIER));
49+
EXPECT_EQ(btc::PoolConfig::TESTNET_PREFIX_HEX, std::string(GOLDEN_PREFIX));
50+
}
51+
52+
// Segwit activation version is a consensus byte — must match the baseline.
53+
TEST(BTC_g01_share_format, SegwitActivationMatchesBaseline)
54+
{
55+
EXPECT_EQ(btc::PoolConfig::SEGWIT_ACTIVATION_VERSION, GOLDEN_SEGWIT_ACTIVATION_VERSION);
56+
}
57+
58+
// Protocol floor is an INTENTIONAL raise, not a parity break: forward-compatible.
59+
TEST(BTC_g01_share_format, ProtocolFloorIsForwardCompatibleRaise)
60+
{
61+
EXPECT_GE(btc::PoolConfig::MINIMUM_PROTOCOL_VERSION, GOLDEN_MINIMUM_PROTOCOL_VERSION)
62+
<< "c2pool floor must not drop below the p2pool baseline";
63+
}
64+
65+
66+
// Share-version additive discipline (G1 bucket-2): the c2pool sharechain extends
67+
// the p2pool baseline version set by EXACTLY ONE sanctioned version -- 36 -- the
68+
// V36 share-format / consensus-revision boundary owned by the core::version_gate
69+
// SSOT. c2pool has no p2pool-style share-version array to compare element-wise,
70+
// so the additive is locked against the SSOT instead. The baseline set is
71+
// transcribed from the golden fixture (constants.share_versions @ ece15b03fc23).
72+
// This catches two drift modes the byte-parity TESTs above do not:
73+
// 1. boundary drift -- V36_ACTIVATION_VERSION moving off 36 (an unsanctioned /
74+
// shifted version) fails here;
75+
// 2. baseline-composition drift -- no baseline version may be treated as V36.
76+
TEST(BTC_g01_share_format, ShareVersionAdditiveIsExactlyV36)
77+
{
78+
// Transcribed from btc.g01.golden.json -> constants.share_versions.
79+
constexpr uint64_t GOLDEN_BASELINE_VERSIONS[] = {0, 17, 32, 33, 34, 35};
80+
81+
// The SINGLE sanctioned additive over the p2pool baseline is the V36 boundary.
82+
EXPECT_EQ(core::version_gate::V36_ACTIVATION_VERSION, 36u)
83+
<< "only sanctioned c2pool version added over the baseline is 36";
84+
85+
// No baseline version is on the V36 side of the gate -- all pre-revision.
86+
for (uint64_t v : GOLDEN_BASELINE_VERSIONS)
87+
EXPECT_FALSE(core::version_gate::is_v36_active(v))
88+
<< "baseline version " << v << " must remain pre-V36";
89+
90+
// Boundary is exact: 36 activates, 35 (max baseline) does not.
91+
EXPECT_TRUE (core::version_gate::is_v36_active(36));
92+
EXPECT_FALSE(core::version_gate::is_v36_active(35));
93+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"coin": "bitcoin",
3+
"constants": {
4+
"DONATION_SCRIPT": "4104ffd03de44a6e11b9917f3a29f9443283d9871c9d743ef30d5eddcd37094b64d1b3d8090496b53256786bf5c82932ec23c3b74d9f05a6f95a8b5529352656664bac",
5+
"IDENTIFIER": "fc70035c7a81bc6f",
6+
"MINIMUM_PROTOCOL_VERSION": 3301,
7+
"P2P_PORT": 9333,
8+
"PREFIX": "2472ef181efcd37b",
9+
"SEGWIT_ACTIVATION_VERSION": 33,
10+
"gentx_before_refhash_expr": "pack.VarStrType().pack(DONATION_SCRIPT) + pack.IntType(64).pack(0) + pack.VarStrType().pack('\\x6a\\x28' + pack.IntType(256).pack(0) + pack.IntType(64).pack(0))[:3]",
11+
"gentx_layout_sig": "5193e3e6ee1a562e23a5a36be01c7d072306a1743bd0998abaa1d7874372c62f",
12+
"share_versions": [
13+
0,
14+
17,
15+
32,
16+
33,
17+
34,
18+
35
19+
]
20+
},
21+
"provenance": {
22+
"data_source": "p2pool/data.py",
23+
"git_rev": "ece15b03fc23",
24+
"network_source": "p2pool/networks/bitcoin.py",
25+
"tree": "/home/ubuntu/Github/p2pool-btc-jtoomim"
26+
},
27+
"schema": "c2pool.g01.share-format/v1"
28+
}

0 commit comments

Comments
 (0)