Skip to content

Commit b7ebc45

Browse files
authored
Merge pull request #233 from frstrtr/nmc/p1pe-2b0-pin-testnet-genesis
nmc(P1 PE 2b-0): pin testnet genesis + chain_id=1 in NMCChainParams
2 parents c2a0894 + cbf0b4c commit b7ebc45

2 files changed

Lines changed: 48 additions & 4 deletions

File tree

src/impl/nmc/coin/header_chain.hpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ struct NMCChainParams {
526526
int32_t testnet_auxpow_activation_height{-1}; // TO-CONFIRM: testnet analog (unpinned sentinel)
527527
// aux_chain_id: the chain id this NMC instance claims in the parent's
528528
// merged-mining tree. -1 = unpinned sentinel.
529-
int32_t aux_chain_id{-1}; // TO-CONFIRM: Namecoin mainnet chain id (unpinned)
529+
int32_t aux_chain_id{1}; // Namecoin nAuxpowChainId = 0x0001 (both nets); see chainparams.cpp
530530

531531
int64_t difficulty_adjustment_interval() const {
532532
return target_timespan / target_spacing;
@@ -565,12 +565,31 @@ struct NMCChainParams {
565565
p.target_spacing = TESTNET_TARGET_SPACING;
566566
p.allow_min_difficulty = TESTNET_ALLOW_MIN_DIFF;
567567
p.no_retargeting = false;
568-
// TO-CONFIRM: Namecoin testnet powLimit (placeholder = BTC default).
568+
// Namecoin testnet powLimit = Bitcoin default (chainparams.cpp CTestNetParams).
569569
p.pow_limit.SetHex("00000000ffff0000000000000000000000000000000000000000000000000000");
570-
// TO-CONFIRM: Namecoin testnet genesis hash (placeholder = null).
571-
p.genesis_hash.SetNull();
570+
// Genesis PINNED against a live namecoind on namecoin testnet
571+
// (getblockhash 0 / getblockheader, 2026-06-19). block_hash(genesis_header)
572+
// re-derives this value (nmc_auxpow_wire_test GenesisTestnet KAT).
573+
p.genesis_hash.SetHex("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008");
572574
return p;
573575
}
576+
577+
/// Namecoin testnet genesis header (the 80-byte parent the HeaderChain seeds
578+
/// at height 0). Fields PINNED against a live namecoind getblockheader on
579+
/// namecoin testnet, 2026-06-19:
580+
/// version=1 time=1296688602 bits=0x1d07fff8 nonce=384568319
581+
/// merkleroot=4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
582+
/// SHA256d(header) == genesis_hash() above (verified locally + by KAT).
583+
static BlockHeaderType testnet_genesis_header() {
584+
BlockHeaderType g;
585+
g.m_previous_block.SetNull();
586+
g.m_version = 1;
587+
g.m_merkle_root.SetHex("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b");
588+
g.m_timestamp = 1296688602;
589+
g.m_bits = 0x1d07fff8;
590+
g.m_nonce = 384568319;
591+
return g;
592+
}
574593
};
575594

576595
// ─── Index Entry ─────────────────────────────────────────────────────────────

src/impl/nmc/test/auxpow_wire_test.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,29 @@ TEST(NmcP1AuxPowWire, MainnetBlock829949RoundTrip)
258258
EXPECT_LT(80 + auxlen, total);
259259
}
260260

261+
// ---------------------------------------------------------------------------
262+
// Genesis pin KAT (P1 PE 2b-0). NMCChainParams::testnet_genesis_header() is the
263+
// 80-byte parent the embedded HeaderChain seeds at height 0. Its SHA256d MUST
264+
// reproduce NMCChainParams::testnet().genesis_hash, which was pinned against a
265+
// live namecoind (getblockhash 0 / getblockheader) on namecoin testnet,
266+
// 2026-06-19. A wrong field (endianness, bits, nonce, merkleroot) makes the
267+
// re-derived hash diverge from the daemon-sourced value rather than be mirrored
268+
// -- the expected hash is external truth, not self-derived from the header.
269+
// chain_id is also pinned to Namecoin's nAuxpowChainId (0x0001).
270+
// ---------------------------------------------------------------------------
271+
TEST(NmcP1Genesis, TestnetHeaderRederivesPinnedHash)
272+
{
273+
const auto params = nmc::coin::NMCChainParams::testnet();
274+
const auto g = nmc::coin::NMCChainParams::testnet_genesis_header();
275+
276+
EXPECT_TRUE(g.m_previous_block.IsNull());
277+
EXPECT_EQ(nmc::coin::block_hash(g), params.genesis_hash);
278+
279+
uint256 expect;
280+
expect.SetHex("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008");
281+
EXPECT_EQ(params.genesis_hash, expect);
282+
283+
EXPECT_EQ(params.aux_chain_id, 1); // Namecoin nAuxpowChainId = 0x0001
284+
}
285+
261286
} // namespace

0 commit comments

Comments
 (0)