Skip to content

Cross-platform HW VDF client builds (Linux/macOS arm64/Windows) + callback/prover hardening#299

Merged
hoffmang9 merged 80 commits into
mainfrom
hw-vdf-macos-arm64
Feb 17, 2026
Merged

Cross-platform HW VDF client builds (Linux/macOS arm64/Windows) + callback/prover hardening#299
hoffmang9 merged 80 commits into
mainfrom
hw-vdf-macos-arm64

Conversation

@hoffmang9
Copy link
Copy Markdown
Member

@hoffmang9 hoffmang9 commented Feb 5, 2026

Summary

  • Extend HW build coverage to Ubuntu, macOS arm64, and Windows in .github/workflows/hw-build.yml, including smoke tests and platform artifacts.
  • Add FT4222 driver provisioning scripts for all target OSes:
    • scripts/get-libft4222.sh (Linux/macOS)
    • scripts/get-libft4222.ps1 (Windows)
  • Update CMake/Make wiring for platform-specific HW libs, Windows socket/link settings, and macOS runtime dylib loading (@executable_path rpath).
  • Improve HW client/emulator portability and stability (Winsock lifecycle, socket wrappers, argument parsing, timing/sleep portability).
  • Apply asm/ABI/build portability fixes for Windows/macOS and supporting anchor/init objects for HW tool linkage.

Review Follow-ups Addressed (Opus)

  • Addressed Opus review follow-up on two-weso transition publication consistency:
    • TwoWesolowskiCallback::OnIteration() now uses a single transition_state snapshot for effective stride + position decisions under lock.
    • kl is retained only as a fast-path hint.
  • Widened two-weso position types to size_t to remove narrowing/truncation risk and align with forms_capacity/array indexing.
  • Documented the single-thread invariant for TwoWesolowskiProver::GetForm() returning &cached_form.

Test Plan

  • CI
    • HW Build (Ubuntu)
    • HW Build (macOS arm64)
    • HW Build (Windows)
  • Local smoke checks
    • ./scripts/get-libft4222.sh install && cd src && make -f Makefile.vdf-client emu_hw_test hw_test emu_hw_vdf_client hw_vdf_client
    • ./src/emu_hw_test 1 2000
    • ./src/emu_hw_vdf_client --list

Note

Medium Risk
Touches build/CI plus low-level platform-specific code paths (Windows sockets, driver linking, asm/CPU-feature gating) that can easily break compilation or runtime on specific OS/toolchains. Logic changes are mostly defensive but affect hot-path callback checkpointing and feature detection.

Overview
Adds cross-platform CI coverage for the hardware VDF client: Ubuntu build now uses a shared FT4222 provisioning script and includes a basic smoke test; new jobs build+smoke-test+upload artifacts for macOS arm64 and Windows (Windows uses CMake/Ninja + MPIR checkout).

Introduces FT4222 driver download/install helpers (get-libft4222.sh for Linux/macOS, get-libft4222.ps1 for Windows) and updates build wiring (CMake + Makefile.vdf-client) to link the correct vendor libraries per-OS, add macOS @executable_path rpath handling, and add Windows-specific defines/libs (MPIR, ws2_32) while avoiding generated-asm link collisions on Windows.

Improves portability/stability of HW tools and emulator: replaces usleep/sleep usage with portable std::this_thread helpers, adds Winsock lifecycle + socket wrappers + manual arg parsing in hw_vdf_client, and adjusts vendor header import macros for the emulator on Windows.

Hardens core runtime behavior: adds overflow/ bounds checks in OneWesolowskiCallback, makes TwoWesolowskiCallback transition state publication and indexing thread-safer via atomics/snapshots, updates AVX feature gating to respect OS xstate (XCR0), and adds small ABI/compile fixes for Windows/macOS (weak symbols, asm arg handling, header includes).

Written by Cursor Bugbot for commit e42cabd. This will update automatically on new commits. Configure here.

@hoffmang9 hoffmang9 changed the base branch from main to nudupl-arm64-ci February 5, 2026 07:58
@hoffmang9
Copy link
Copy Markdown
Member Author

hoffmang@MacBook-Air-2025-07 src % ./hw_vdf_client --list
List of available devices:
Device 0: 'Chia VDF A', loc 17

hoffmang@MacBook-Air-2025-07 src % ./hw_test
2026-02-05T16:47:42.944 Setting frequency to 1100.000000 MHz
2026-02-05T16:47:43.066 Frequency is 1100.000000 MHz
2026-02-05T16:47:43.068 Board voltage is 0.849 V
2026-02-05T16:47:43.068 Setting voltage to 0.880 V
2026-02-05T16:47:43.069 Board voltage is now 0.875 V
2026-02-05T16:47:43.083 Board current is 0.590 A
2026-02-05T16:47:43.096 Board power is 0.516 W
2026-02-05T16:47:43.099 VDF 0: Allocating intermediate values, total 2 * 4096
2026-02-05T16:47:43.100 VDF 1: Allocating intermediate values, total 2 * 4096
2026-02-05T16:47:43.101 VDF 2: Allocating intermediate values, total 2 * 4096
2026-02-05T16:47:43.101 ASIC Temp = 27.08 C; Frequency = 1100.0 MHz; freq_idx = 7634
2026-02-05T16:47:44.500
2026-02-05T16:47:44.500 VDF 0: 1000000 HW iters done in 1s, HW speed: 714040 ips
2026-02-05T16:47:44.500 VDF 0: 152879 SW iters done in 0s, SW speed: 247521 ips
2026-02-05T16:47:44.500
2026-02-05T16:47:44.500
2026-02-05T16:47:44.500 VDF 1: 1000000 HW iters done in 1s, HW speed: 714364 ips
2026-02-05T16:47:44.500 VDF 1: 151803 SW iters done in 0s, SW speed: 244842 ips
2026-02-05T16:47:44.500
2026-02-05T16:47:44.500
2026-02-05T16:47:44.500 VDF 2: 1000000 HW iters done in 1s, HW speed: 714474 ips
2026-02-05T16:47:44.500 VDF 2: 150589 SW iters done in 0s, SW speed: 243553 ips
2026-02-05T16:47:44.500
2026-02-05T16:47:45.239 VDF 0: Proof done for iters=1000000, length=1000000 in 0.739s
2026-02-05T16:47:45.257 VDF 1: Proof done for iters=1000000, length=1000000 in 0.757s [checkpoint]
2026-02-05T16:47:45.269 VDF 2: Proof done for iters=1000000, length=1000000 in 0.769s [checkpoint]

Comment thread src/Makefile.vdf-client Outdated
Comment thread scripts/get-libft4222.sh Outdated
Comment thread scripts/get-libft4222.sh Outdated
@hoffmang9 hoffmang9 added the enhancement New feature or request label Feb 6, 2026
Base automatically changed from nudupl-arm64-ci to main February 7, 2026 01:54
Comment thread src/Makefile.vdf-client
Comment thread .github/workflows/test.yaml Outdated
Comment thread scripts/get-libft4222.ps1 Outdated
Comment thread .github/workflows/hw-build.yml Outdated
Comment thread .github/workflows/hw-build.yml Outdated
Comment thread .github/workflows/hw-build.yml Outdated
Comment thread scripts/get-libft4222.ps1
Comment thread src/hw/hw_vdf_client.cpp
Comment thread src/hw/hw_vdf_client.cpp Outdated
Comment thread src/hw/emu_runner.cpp
Comment thread src/hw/emu_runner.cpp
Comment thread src/alloc.hpp Outdated
Comment thread src/hw/hw_proof.cpp Outdated
Comment thread scripts/get-libft4222.ps1 Outdated
Comment thread src/hw/hw_test.cpp Outdated
Comment thread src/hw/hw_test.cpp Outdated
Comment thread src/hw/hw_test.cpp Outdated
@hoffmang9 hoffmang9 changed the title macOS arm64: build HW VDF client with FT4222H drivers (CI + docs) macOS arm64 and Windows: build HW VDF client with FT4222H drivers (CI + docs) Feb 8, 2026
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Comment thread src/parameters.h Outdated
Comment thread src/callback.h
hoffmang9 and others added 2 commits February 13, 2026 13:18
Validate checkpoint stride and forms capacity arithmetic before allocation so malformed parameters fail fast instead of risking undersized storage.

Co-authored-by: Cursor <cursoragent@cursor.com>
Fix a real race where readers could observe a new switch_iters value with a stale switch_index during the 2-wesolowski constant transition, which could compute an incorrect checkpoint slot. Use release store on switch_iters to pair with existing acquire load and preserve correct metadata visibility with negligible performance impact.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Comment thread src/parameters.h Outdated
Comment thread src/hw/hw_vdf_client.cpp
Comment thread src/hw/hw_vdf_client.cpp
hoffmang9 and others added 4 commits February 13, 2026 13:25
Prevent AVX2/AVX512 IFMA enablement unless OSXSAVE is present and XCR0 has required AVX/AVX-512 state bits, avoiding illegal-instruction crashes when OS context management is unavailable.

Co-authored-by: Cursor <cursoragent@cursor.com>
Avoid enabling AVX2/AVX512 execution paths when the OS hasn't enabled xstate, even when force env toggles are set, preventing illegal-instruction crashes.

Co-authored-by: Cursor <cursoragent@cursor.com>
Store switch index and switch iteration in one atomic state so readers cannot observe mixed transition values during the 10-to-100 checkpoint switch.

Co-authored-by: Cursor <cursoragent@cursor.com>
Ensure hw_vdf_client_main calls WSACleanup on parse, list, and init_hw failure paths after successful WSAStartup so repeated in-process invocations do not leak Winsock references.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Comment thread src/hw/hw_vdf_client.cpp
hoffmang9 and others added 2 commits February 13, 2026 13:43
Guard IncreaseConstants and GetPosition with forms_mutex so transition state publication and form index reads share one synchronization domain at the 10->100 switch.

Co-authored-by: Cursor <cursoragent@cursor.com>
Collect positional port/VDF arguments while scanning all options so CLI parsing remains valid regardless of argument ordering.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Comment thread src/hw/hw_vdf_client.cpp
hoffmang9 and others added 3 commits February 13, 2026 13:50
Disallow single-dash tokens from being treated as positional arguments and parse PORT/N_VDFS with strict numeric bounds so negative values cannot wrap through htons to unintended endpoints.

Co-authored-by: Cursor <cursoragent@cursor.com>
Use a local guard in hw_vdf_client_main() so any successful WSAStartup() is always paired with WSACleanup(), including all early-return paths.

Co-authored-by: Cursor <cursoragent@cursor.com>
Address Opus review follow-ups by making checkpoint position/stride decisions derive from a single transition_state snapshot and widening two-weso position indices to size_t to avoid narrowing risk. Also document the single-thread invariant for cached_form in TwoWesolowskiProver::GetForm.

Co-authored-by: Cursor <cursoragent@cursor.com>
@hoffmang9 hoffmang9 changed the title macOS arm64 and Windows: build HW VDF client with FT4222H drivers (CI + docs) Cross-platform HW VDF client builds (Linux/macOS arm64/Windows) + callback/prover hardening Feb 13, 2026
xearl4 referenced this pull request Feb 16, 2026
…ilds (#300)

* Windows asm/ABI and runtime fixes

* CMake: Windows + perf experiment options

* CI: perf experiments and Windows benchmarking

* ci: streamline test workflow

* build: remove perf-only CMake toggles

* core: gate AVX logging behind env flag

* asm: document Windows ABI restore

* docs: remove Windows perf notes

* Nit note in README and clean up some language in test.yaml

* Fix step name

* various workflow clean ups and fix AVX512 flag

* fix windows runners in test.yaml

* more cmake instruction issues

* harden finding boost on Mac intel

* now cmake isn't always there...

* more install cmake

* fix ASAN, remove TSAN for windows runners

* initiate windows dev env on ASAN runner

* more ASAN windows issues - harden brew handling in cibuildwheel

* giving up on ASAN

* Add required linker flag for Windows asm - fix unchecked vector access

* potentially fix bug in the 2weso test

* consolidate 2weso fail-hunting phases 40-43

Collapse the contiguous phase-40 through phase-43 debug commits into one checkpoint while preserving the net tree state before phase 44.

Co-authored-by: Cursor <cursoragent@cursor.com>

* 2weso fail hunting 44

* 2weso fail hunting 45

* 2weso fail hunting 46

* cleanup: strip 2weso debug scaffolding after Windows root-cause isolation

* ci - add an asm path to the c++ test path, fix HW headers

* ci - bring windows back around to main ubuntu/macos testing

* address cursor review issues

* everything on windows should take the asm path

* something about the windows asm path is broken

* and we are off again searching for the asm issue

* cache all the things and chase the asm issue

* look closer at the ubuntu vs windows asm changes

* Consolidate Windows asm investigation commits 1-17.

Squash iterative CI and asm-path probing changes into one reviewable checkpoint before the final CI fix commit.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Fix Windows asm CI and align optimized test coverage (#304)

* Instrument Windows asm failures and collect runtime evidence.

Add targeted Windows probes and disassembly checks to localize crash offsets and failing asm paths.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Fix Windows asm addressing to be ASLR-safe.

Convert global and table references to RIP-relative forms for Windows asm generation paths.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Stabilize Windows gcd_unsigned dispatch control flow.

Correct dispatch indexing and use explicit compare/branch selection to avoid executing table data.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Fix Windows CI probe exit-code handling.

Ensure PowerShell helpers compare integer process exit codes so successful probes do not fail the workflow.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Remove temporary Windows debug instrumentation.

Drop crash-debug hooks and probes after validation, including the final vdf_fast cleanup.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Align Windows optimized test coverage with other runners.

Run the full optimized test set in the Windows PowerShell test step by removing ad-hoc iteration args and adding prover_test with fast mode.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Clean up leftover no-op debug checks in fast path and tighten macOS-only branch selection in gcd_unsigned.

This removes empty instrumentation cleanup blocks and keeps the dispatch path logic aligned with platform-specific behavior.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Restore Windows jump-table dispatch path in gcd_unsigned.

This reverts an accidental macOS-only condition change from the prior cleanup commit that caused 1weso_test to crash on Windows CI.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>

* cleanup: finalize Windows asm follow-ups and include hygiene

Tighten Windows asm/runtime plumbing and related docs/tests while removing stale duplicate include clutter from vdf headers.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix windows avx512 add table rip-relative access

Include CHIA_WINDOWS in the avx512_add_table addressing branch so Windows emits LEA+ADD RIP-relative access instead of absolute table addressing.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Remove unused max_test_iteration in 2weso_test.

Drop dead local state that was computed and immediately discarded to avoid implying a missing iteration guard.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix gcd_unsigned compare against end_index

Use end_index instead of size in the jump-table compare to match the mapped index logic and avoid incorrect branch selection.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Harden callback state synchronization and update build/runtime tuning docs.

This captures the current branch updates, including the TwoWesolowski position-locking fix and related CMake/parameter/readme adjustments for current CI work.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Guard POSIX-only emulator hardware targets on Windows.

Prevent `emu_hw_test` and `emu_hw_vdf_client` from being defined on Windows so CMake does not try to compile sources that depend on POSIX headers.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Initialize FastAlgorithmCallback forms_capacity.

Set forms_capacity when allocating FastAlgorithmCallback forms so all WesolowskiCallback subclasses consistently initialize capacity metadata for safe bounds checks.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Harden macOS/Windows gcd_unsigned dispatch bounds check.

Add the same a_end_index range guard used on Linux before the CMP/JE chain so out-of-range values jump to the error path instead of falling through to a kernel label.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Define CHIAOSX for macOS CMake asm generation.

Match the Makefile behavior so compile_asm emits Mach-O-compatible assembly on Intel macOS instead of falling back to Linux/ELF code paths.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Refine Windows asm argument handling and remove unused SEH include.

Allow asm_function Windows stack-arg loading to be toggled for internal call sites, and drop dead <excpt.h> from threading since no SEH constructs are used.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Preserve non-Windows asm behavior and gate fallback logging.

Keep Linux absolute addressing and restore macOS/Linux jump-dispatch parity with main, while making detached-thread fallback logging debug-only.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Reply to Opus review with dispatch, bounds, and const-correctness fixes.

This replies to Opus review feedback by fixing macOS gcd_unsigned end-index dispatch, aligning bounds checks across platforms and callbacks, enabling Windows AVX512 CI coverage, and removing unused asm/cast paths.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Avoid synchronous fallback in TwoWesolowski prover start.

Make prover form retrieval value-based and throw on thread-start failure so TwoWesolowski recursion preserves parallel proof generation instead of silently serializing work.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Gate AVX512 IFMA dispatch on OS XSAVE/XCR0 state.

Require OSXSAVE and XCR0 ZMM/opmask state in init_avx_flags() before enabling AVX-512 IFMA to prevent illegal-instruction crashes on unsupported OS configurations.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
xearl4 and others added 5 commits February 16, 2026 14:01
Match the non-HW prover interfaces with main by returning forms by value, eliminating mixed pointer/value virtual signatures that surfaced after the ODR cherry-pick and destabilized cross-platform builds.

Co-authored-by: Cursor <cursoragent@cursor.com>
Add a Linux-only switch to compare RIP-relative and absolute track_asm addressing from the same code path, and extend Ubuntu CI to build both variants, emit benchmark deltas, and upload asm/benchmark artifacts for reviewer verification.

Co-authored-by: Cursor <cursoragent@cursor.com>
Use the vdf-client makefile for clean in the addressing benchmark step, and temporarily run short 2weso_test on Ubuntu optimized jobs to reduce CI runtime while preserving coverage elsewhere.

Co-authored-by: Cursor <cursoragent@cursor.com>
…lute mode

Remove the temporary Ubuntu A/B benchmark workflow changes and reinstate full optimized 2weso coverage, while restoring Linux track_asm accesses to absolute addressing by default.

Co-authored-by: Cursor <cursoragent@cursor.com>
wjblanke
wjblanke previously approved these changes Feb 17, 2026
Copy link
Copy Markdown
Contributor

@wjblanke wjblanke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aok glad to see absolute back

Resolve the PR #307 merge conflict in vdf_base.hpp by adopting the shared prover header layout, and add explicit HW runtime wiring so emu/hw tool targets continue linking on macOS arm64.

Co-authored-by: Cursor <cursoragent@cursor.com>
Include prover_runtime.o in HW_OBJS for Makefile.vdf-client so emu_hw_test and emu_hw_vdf_client resolve Prover/ParallelProver symbols after the prover header consolidation.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown
Contributor

@wjblanke wjblanke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aok

@hoffmang9 hoffmang9 merged commit 8408015 into main Feb 17, 2026
65 checks passed
@hoffmang9 hoffmang9 deleted the hw-vdf-macos-arm64 branch February 17, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants