Skip to content

bch(M5): ASERT DAA known-answer test vs BCHN gold properties - #215

Merged
frstrtr merged 2 commits into
masterfrom
bch/m5-asert-kat
Jun 19, 2026
Merged

bch(M5): ASERT DAA known-answer test vs BCHN gold properties#215
frstrtr merged 2 commits into
masterfrom
bch/m5-asert-kat

Conversation

@frstrtr

@frstrtr frstrtr commented Jun 19, 2026

Copy link
Copy Markdown
Owner

What

Adds asert_kat_test — a known-answer test pinning BCH ASERT (aserti3-2d, CHIP-2020-05) against BCHN gold properties. Closes the unverified-DAA gap in the M5 embedded body.

Why

asert.hpp documents CalculateASERT() as a 1:1 BCHN src/pow.cpp port validated against gold vectors, but no test exercised it: every getwork/template test deliberately stays below the ASERT anchor (height 100k << 661647) to skip the retarget, so the synced-state bits/target branch shipped unverified. After IBD the synced-state work template emits ASERT-computed bits at heights >= anchor — this is the headline BCH-specific consensus divergence from BTC Core (M1 §4).

Conformance (pinned refs)

  • Gold properties from BCHN @89a591f (v29.0.0) src/test/pow_tests.cpp asert_difficulty_test: on-schedule→unchanged, +2-day→target doubles, −2-day→halves, +2 halflives→×4, huge exponent→clamp to powLimit, testnet allow-min-difficulty rule.
  • Mainnet anchor from BCHN @89a591f src/chainparams.cpp:169-172: {661647, 0x1804dafe, 1605447844}, halflife 2 days.
  • Exact uint256 identities (integer halflife multiples ⇒ pure power-of-two shifts), not float tolerances.

Oracle note

p2poolBCH @6603b79 carries NO ASERT — it defers DAA to bitcoind getblocktemplate. The embedded daemon replaces that bitcoind, so the ASERT oracle is BCHN itself, not p2poolBCH.

Scope / isolation

  • Fenced to src/impl/bch/test/ only (test + CMake registration in BCH_ABLA_TESTS, COIN_BCH leg).
  • Zero p2pool-merged-v36 surface: ASERT governs only header-accept target, never PoW hash / share format / coinbase / PPLNS.
  • Verified locally: g++ -std=c++20 compile + run = ALL PASS.

Merge operator-gated (I author + push; integrator merges on operator push-approval).

CI-wiring follow-up @ac72d68f6

Per integrator review: the KAT registered with ctest (bch_asert_kat_test, via the BCH_ABLA_TESTS foreach) but was absent from the explicit --target allowlist in .github/workflows/build.yml "Build BCH test targets" (both Linux Release + ASan legs). Under ctest -R "^bch_" that reproduces the documented NOT_BUILT false-green mode (build.yml:228-234) — the binary never builds, ctest finds no executable.

Fix ac72d68f6 adds bch_asert_kat_test to both COIN_BCH allowlist legs. This is a COIN_BCH-scoped, additive CI-config change outside the src/impl/bch/ fence — noting it explicitly so the scope label stays honest. No consensus-value change; the diff is now src/impl/bch/test/{CMakeLists.txt,asert_kat_test.cpp} + .github/workflows/build.yml (BCH allowlist only).

frstrtr added 2 commits June 19, 2026 14:49
Closes the unverified-DAA gap in the M5 embedded body. asert.hpp claims
CalculateASERT() is a 1:1 BCHN src/pow.cpp port validated against gold
vectors, but no test exercised it: every getwork/template test stays
below the ASERT anchor (height 100k << 661647) to skip the retarget, so
the synced-state bits/target branch shipped unverified.

asert_kat_test pins CalculateASERT() and the anchor-formulated
get_next_work_required_asert() against the canonical gold PROPERTIES of
BCHN asert_difficulty_test (src/test/pow_tests.cpp) and the real mainnet
anchor constants (src/chainparams.cpp:169-172), both BCHN tag v29.0.0
@89a591f: on-schedule -> unchanged, +2-day -> target doubles, -2-day ->
halves, +2 halflives -> x4, huge exponent -> clamp to powLimit, testnet
allow-min-difficulty rule. Exact uint256 identities (integer halflife
multiples -> pure power-of-two shifts), not float tolerances.

Oracle note: p2poolBCH @6603b79 carries NO ASERT (defers DAA to
bitcoind getblocktemplate); the embedded daemon replaces that bitcoind,
so the ASERT oracle is BCHN itself. Zero p2pool-merged-v36 surface:
ASERT governs only header-accept target, not PoW hash/share/coinbase/
PPLNS. Fenced to src/impl/bch/test/; registered in BCH_ABLA_TESTS
(COIN_BCH leg). Verified: g++ -std=c++20 compile+run = ALL PASS.
The ASERT KAT registers with ctest at configure time (BCH_ABLA_TESTS
foreach) but bch_asert_kat_test was absent from the explicit --target
allowlist in the Build BCH test targets step (Linux Release + ASan).
Under ctest -R ^bch_ that yields the documented NOT_BUILT false-green
failure mode (build.yml:228-234). Add the target to both legs so the
binary is built and the KAT actually runs.
@frstrtr
frstrtr merged commit 28d7f43 into master Jun 19, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant