The WASM backend (PR #415) supports single-word field arithmetic for primes < 2^63. BN254 (254-bit prime) needs 4-word arithmetic.
What's already in place
- compileModule accepts numWords parameter (default 1)
- snarkjs ABI handles n32 = numWords * 2 and signalBytes = n32 * 4
- fieldHelpers has a multi-word path (currently stubbed)
Work needed
1. Multi-word field arithmetic in WAT for 4-word elements
- fadd_4: word-by-word add with carry + conditional sub of prime
- fsub_4: word-by-word sub with borrow + conditional add of prime
- fmul_4: double-and-add (requires only fadd, about 254 iterations per mul)
- finv_4: Fermat little theorem via fpow_4
2. Expression compilers parameterized by numWords
Each FExpr operation pushes/pops numWords i64 values instead of 1. NExpr and BExpr unchanged.
3. Witness function signature
For numWords > 1, the direct witness function takes numWords * numInputs params and returns numWords * tw results.
Approach
Write the multi-word arithmetic as a standalone .wat file, test with wat2wasm + Node.js against known BN254 test vectors, then integrate into the Lean WAT generator in Compile.lean.
The WASM backend (PR #415) supports single-word field arithmetic for primes < 2^63. BN254 (254-bit prime) needs 4-word arithmetic.
What's already in place
Work needed
1. Multi-word field arithmetic in WAT for 4-word elements
2. Expression compilers parameterized by numWords
Each FExpr operation pushes/pops numWords i64 values instead of 1. NExpr and BExpr unchanged.
3. Witness function signature
For numWords > 1, the direct witness function takes numWords * numInputs params and returns numWords * tw results.
Approach
Write the multi-word arithmetic as a standalone .wat file, test with wat2wasm + Node.js against known BN254 test vectors, then integrate into the Lean WAT generator in Compile.lean.