cap icon indicating copy to clipboard operation
cap copied to clipboard

Port wasm solver to C and add regression coverage

Open Soccera1 opened this issue 7 months ago • 4 comments

What changed

  • Replaced the Rust WASM solver with a C implementation in wasm/src/c/src/cap_wasm.c, including SHA-256 hashing, hex-prefix target parsing, nonce formatting, and wasm allocator shims.
  • Removed the old Rust crate under wasm/src/rust and updated the docs/package metadata to describe the solver as C-based WASM.
  • Tightened the test suite: wasm/src/c/test-regression.cjs became a fixed regression suite, wasm/test/node.js now asserts expected nonces for the full challenge set, and wasm/test/node_odd_difficulty.js verifies the odd-length target case.
  • Updated wasm/build.js so the build runs the regression suite.

Commit breakdown

  • 629ed2f: Port wasm from Rust to C
  • 978c1f5: Remove Rust code
  • dee457e: Update tests

This was done as the rust implementation had many external dependencies, and rustc is very difficult to bootstrap. This version has no external dependencies; it can be compiled with -ffreestanding. I have also done some unscientific testing and this is over 13% faster.

Summary by CodeRabbit

  • New Features

    • Added a full benchmark suite (Node + browser) with runner, browser UI, and an easy local server to compare solver implementations and report speedups.
  • Documentation

    • Updated docs and READMEs to describe the client solver as a C-based WebAssembly implementation.
  • Tests

    • Added regression tests validating solver correctness across multiple challenge cases.
  • Chores

    • Build pipeline updated to produce a C-based WASM solver and related build orchestration.

Soccera1 avatar Apr 09 '26 11:04 Soccera1

Re-open of #206 since all the commit hashes got fucked, closing branches, thus closing the PR.

Soccera1 avatar Apr 09 '26 11:04 Soccera1

make phone happy

opuadm avatar Apr 09 '26 11:04 opuadm

did it end up being faster than the current rust one?

tiagozip avatar Apr 22 '26 08:04 tiagozip

did it end up being faster than the current rust one?

Only in bun. I'm currently working on resolving this issue.

Soccera1 avatar Apr 22 '26 13:04 Soccera1