Skip to content

bch/abla: MSVC-portable 128-bit muldiv (fixes c2pool-bch Windows build) - #688

Merged
frstrtr merged 1 commit into
masterfrom
bch/abla-msvc-portable-muldiv
Jul 13, 2026
Merged

bch/abla: MSVC-portable 128-bit muldiv (fixes c2pool-bch Windows build)#688
frstrtr merged 1 commit into
masterfrom
bch/abla-msvc-portable-muldiv

Conversation

@frstrtr

@frstrtr frstrtr commented Jul 13, 2026

Copy link
Copy Markdown
Owner

What

Make the BCH ABLA 128-bit muldiv MSVC-portable. Fixes the c2pool-bch Windows compile failure blocking the v0.2.1 Windows package:

src/impl/bch/coin/abla.hpp(46-48): error C4235: '__int128' keyword not supported on this architecture [c2pool-bch.vcxproj]

How

  • #if defined(__SIZEOF_INT128__) -> native unsigned __int128 path, byte-exact / unchanged (this is what the shipping Linux/macOS merged builds already have).
  • #else (MSVC, no __int128) -> boost::multiprecision::uint128_t fallback. Header-only, boost already a project dep (conan + system libboost). Exact 128-bit intermediate.
  • No __int128 token reaches a non-__int128 compiler (all native code is inside the guard).

Guard (the KAT the task asked for)

New bch_muldiv_kat_test:

  • Layer A — cross-platform known answers (several with >2^64 products, so a 64-bit multiply would fail); muldiv must satisfy these on every compiler incl. MSVC.
  • Layer B (platforms with __int128) — muldiv_native == muldiv_portable across the full ABLA operand space + a deterministic 200k-vector wide fuzz. Proves the portable arithmetic is bit-identical to native on the trusted platform, which certifies the MSVC path CI cannot execute here.

Wired into src/impl/bch/test/CMakeLists.txt and both build.yml COIN_BCH target lists.

Verified locally (dev host, gcc-13 c++20)

  • bch_muldiv_kat_test: ALL PASS — native==portable over 150260 in-domain fuzz vectors, release and debug.
  • ABLA growth soak regression: unchanged (mainnet final 41305530, testnet pinned 32000000).

Scope / safety

  • src/impl/bch only. p2pool-merged-v36 surface: NONE — ABLA is a local build-time block-size budget; no PoW / share / coinbase / PPLNS math touched.
  • Consensus-critical arithmetic kept exact; ABLA still 1:1 BCHN v29.0.0.
  • No self-merge — integrator review + operator tap. Once landed, re-run the v0.2.1 Windows cell to fill the missing c2pool-bch-windows package.

Related: btc / dgb / dash Windows cells failed this run too (each likely its own MSVC gap) — separate look, ci-steward CC'd.

… build)

abla.hpp evaluated the ABLA control-function muldiv(x,y,z)=x*y/z in a native
unsigned __int128 intermediate. __int128 is a GCC/Clang extension MSVC does not
provide (error C4235 __int128 keyword not supported on this architecture), so
c2pool-bch failed to compile on Windows while Linux/macOS passed -- blocking the
v0.2.1 c2pool-bch-windows package.

Keep the native __int128 path BYTE-EXACT for GCC/Clang (the shipping Linux/macOS
builds are unchanged) under #if defined(__SIZEOF_INT128__). For any compiler
without __int128 (MSVC), fall back to boost::multiprecision::uint128_t -- a fixed
128-bit unsigned type, header-only, already a project dependency (conan + system
libboost). ABLA math stays exact.

Guard: new bch_muldiv_kat_test pins the two paths equal. Layer A is a set of
cross-platform known answers (several with >2^64 products, so a 64-bit multiply
would fail) that muldiv must satisfy on every compiler incl. MSVC. Layer B, on
platforms with __int128, asserts muldiv_native == muldiv_portable across the full
ABLA operand space plus a deterministic 200k-vector wide fuzz -- proving the
portable arithmetic is bit-identical to native on the trusted platform, which
certifies the MSVC path we cannot run in this CI. Verified locally: KAT PASS
(native==portable over 150260 in-domain fuzz vectors, release+debug); ABLA growth
soak unchanged (mainnet final=41305530).

Wired bch_muldiv_kat_test into src/impl/bch/test/CMakeLists.txt and both
build.yml COIN_BCH target lists. p2pool-merged-v36 surface: NONE (ABLA is a local
build-time block-size budget only; no PoW/share/coinbase/PPLNS math touched).
@frstrtr
frstrtr merged commit 451ffb1 into master Jul 13, 2026
36 of 37 checks passed
@frstrtr
frstrtr deleted the bch/abla-msvc-portable-muldiv branch July 13, 2026 07:23
frstrtr added a commit that referenced this pull request Jul 13, 2026
Add the consensus-arithmetic KAT integrator required to merge #690: assert
the MSVC-portability rework of the DigiShield 256-bit retarget math is
BIT-IDENTICAL across the native and portable branches, mirroring the bch
#688 muldiv_kat precedent.

The MSVC branch routes through the x64 _umul128/_udiv128 intrinsics that
cannot be compiled or run on the Linux/macOS CI, so dgb_arith256.hpp now
exposes a third, fully SOFTWARE oracle (detail::umul128_soft/udiv128_soft,
the *_portable primitive twins, and u256_portable) using only 32-bit-limb
arithmetic -- no __int128, no intrinsic. It is a genuinely independent
computation; proving software == native across the DigiShield operand
domain on Linux certifies the MSVC path we cannot run, since the x64
intrinsics are by ISA definition exactly the 64x64->128 product and 128/64
quotient the software reproduces. The oracle is header-only, compiled
unconditionally, and NEVER referenced by the shipping u256 / mul_div_u256
-- the GCC/Clang retarget bytes stay byte-identical.

arith256_muldiv_kat_test asserts mul_add_u128 / div_u128 / add_u128 and
u256 mul_u64 / div_u64 / operator+= are bit-identical native-vs-portable
across DigiShield target/scalar vectors + a 100k deterministic LCG fuzz,
with dedicated stress of the _udiv128 hi<d running-remainder boundary
(hi = d-1) so a precondition violation surfaces as a KAT fail, not field
UB. Registered unconditionally in CMake and in BOTH build.yml --target
allowlists (#143 NOT_BUILT trap). Pure header math: links only GTest.

Local: 7/7 PASS; digishield_walk 6/6 + header_chain 35/35 unregressed.
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