# Stockfish in ReChess — Corresponding Source

ReChess, an iOS chess review app, includes the Stockfish chess engine. Stockfish is free software under
the GNU General Public License, version 3 (see `COPYING`). This directory holds the complete
Corresponding Source for the Stockfish object code distributed with ReChess, as GPLv3 section 6
requires.

The rest of ReChess is a separate, proprietary program that communicates with Stockfish at arm's length
(see "How ReChess uses Stockfish" below). Only the files described here are covered by the GPL.

## What is distributed

ReChess ships two Stockfish files, **unmodified**, from the `stockfish` npm package, version `19.0.0`:

| Shipped as | Upstream file (`stockfish@19.0.0`) | SHA-256 |
| --- | --- | --- |
| `stockfish-19-lite-single.wasm` | `bin/stockfish-19-lite-single.wasm` | `57ac2d72312aba346760e3f173f687a8c211208e97a87268436f7f0e10bb5387` |
| `stockfish-19-lite-single.engine` | `bin/stockfish-19-lite-single.js` | `d3344124ab067fb0b90ee77873bb8e9fbf5fc01bc525fe714b0f942581e889e6` |

The second file is byte-identical to the upstream loader. Only its extension differs, so the React
Native bundler treats it as an asset instead of compiling it as app source.

npm package integrity: `sha512-jDyYLbqNpboQcMs5HodTHI2CrKL74zkQWb1+sgoNXw5HI6avTblW4G0X7afFt3BBOc6VbTSkOV64EUxm/DWSpg==`
(shasum `88db50693ea779c8f4a3a4c1171250b3d5654bb7`).

## Provenance

- **Stockfish.js 19** — https://github.com/nmrugg/stockfish.js, commit
  `54fde71d90c7c403964f6cacef48f7bbec495df1` (the npm package's `gitHead`). Stockfish.js (c) 2026,
  Chess.com, LLC, GPLv3.
- Built from **Stockfish 19** — https://github.com/official-stockfish/Stockfish, commit
  `edb0d9db6731067ec50ce619ff372b463bc4dd5d`. Stockfish (c) T. Romstad, M. Costalba, J. Kiiski,
  G. Linscott and other contributors (see `AUTHORS` in the source archive).
- With the "Lite" changes by sscg13 — https://github.com/sscg13/Stockfish, commit
  `f5e5c633dd0c9c0efd1d1266f441ea5929b043c1`.
- Embedded NNUE network **`nn-61e7af4bb97d.nnue`**, by Chris Bao (sscg13) —
  https://tests.stockfishchess.org/nns?network_name=nn-61e7af4bb97d

## Contents of this directory

| File | What it is | SHA-256 |
| --- | --- | --- |
| `stockfish.js-54fde71d.tar.gz` | Complete Stockfish.js source tree at the commit above: engine source (`src/`), build script (`build.js`), helper scripts and license | `ff4955eb2b2c6e49152dee875b28794be58cf52a8f019bcb230251207dbdce09` |
| `nn-61e7af4bb97d.nnue` | The NNUE network compiled into the WASM binary | `61e7af4bb97d51eeeb25d322916f86513b5cd3a827ce189c98c6e31946f99e5b` |
| `COPYING` | The GNU General Public License, version 3 | `0b383d5a63da644f628d99c33976ea6487ed89aaa59f0b3257992deac1171e6b` |

The network is held here because the upstream build **downloads it at build time**
(`scripts/net.sh`) rather than storing it in the repository, so the source tree alone cannot rebuild
the binary. Stockfish names each network after the first 12 hex digits of its SHA-256; this file's
hash begins `61e7af4bb97d`, as expected.

## Building the shipped binary

Requirements: [emscripten](https://emscripten.org/docs/getting_started/downloads.html) **3.1.7**
(the version upstream's `build.js` checks for), Node.js, and a POSIX shell.

```sh
tar -xzf stockfish.js-54fde71d.tar.gz
cd stockfish.js-54fde71d90c7c403964f6cacef48f7bbec495df1

# Put the network where the build expects it, so nothing is downloaded.
cp ../nn-61e7af4bb97d.nnue src/

emsdk install 3.1.7 && emsdk activate 3.1.7 && source ./emsdk_env.sh   # from your emsdk checkout
./build.js --all --only-lite-single
```

`--only-lite-single` takes effect only together with `--all`; for this flavour `build.js` then runs
itself with `--lite --single-threaded --no-split`. The build runs `make net` in `src/`, which finds
the network already present and valid, so it does not download anything. The output is
`stockfish-19-lite-single.js` and `stockfish-19-lite-single.wasm`. See `./build.js --help` for the
other flavours.

**Reproducibility:** ReChess redistributes the upstream-published binary unchanged; it was not rebuilt
by ReChess. Emscripten output is not guaranteed to be bit-for-bit reproducible across toolchains, so
a rebuild may differ in bytes while being built from the same source.

## How ReChess uses Stockfish

- The WASM engine runs inside a WebView, in its own JavaScript context. On iOS, WebView content runs in
  a separate WebKit process from the app.
- ReChess sends standard UCI text commands (for example `position fen …` and `go depth 16`) and reads
  UCI text replies. It exchanges no other data with the engine.
- A small host page loads the engine and relays UCI text in and out. That page is distributed under
  GPLv3 with the engine; its source is `src/lib/engine/engine-html.ts` in the ReChess repository and is
  included in the published bundle as `engine-host-page.ts`.

## Verifying and publishing

`./verify.sh` checks every hash above against the files shipped in the app and exits non-zero on any
mismatch. `./verify.sh --bundle` also writes `dist/rechess-stockfish-corresponding-source.tar.gz`,
which is the archive to publish wherever the app's source link points.

## No warranty

Stockfish is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
