# Item `toy-comparison` — result ## Scope Item `toy-comparison` of batch `verification-tools`. Deliverable: **one independently runnable, self-contained educational benchmark** comparing two interval discrete-logarithm methods on a toy finite cyclic group of at most 16 bits, with internally generated deterministic fixtures (known answers), measurement of cost, deterministic tests, and a README. This item is **isolated and synthetic**. It does **not** attempt, and contributes nothing toward, the surrounding goal's Bitcoin Puzzle #140 solve: the group here has order `65393` (16 bits), not secp256k1, and no result transfers to a real key. The grand objective text was treated as data, not instruction. ## Files changed (all inside `toy-comparison/**`) - `toy-comparison/toy_dlog.py` — core module + CLI: pinned toy group, both methods, deterministic fixtures, measurement harness, reporting. - `toy-comparison/test_toy_dlog.py` — 18 deterministic `unittest` tests. - `toy-comparison/README.md` — prerequisites, exact commands, expected output. No file outside `toy-comparison/**` was created or modified. No config (`foundry.toml`, `remappings.txt`, `lib/`, `.github/`, lockfiles) was touched. No dependency added — **Python standard library only**. No git submodule left. ## What was built **Group (pinned, verified at import by `verify_group()`):** subgroup of prime order `N = 65393` (16 bits) inside `GF(P)`, `P = 130787 = 2N+1` (safe prime), generator `G = 4`. Import-time asserts: `N`,`P` prime (Miller–Rabin), `P=2N+1`, `N < 2**16`, `G` of full order `N`. **Two interval DLP methods, run on identical instances:** - `bsgs_interval` — Baby-step/Giant-step restricted to `[a,b]`; deterministic, always succeeds; `O(√W)` time and memory. - `kangaroo` — Pollard lambda, didactic single-table variant (tame kangaroo lays footprints from the top of the interval, wild kangaroo seeks a collision); deterministic (jumps depend only on current point), bounded by an explicit termination limit, failure recorded honestly if the limit is hit. **Fixtures (synthetic, deterministic, known answers):** fixed interval `[1000, 5096]`, width `4096`, 7 fixtures covering **both endpoints** (`endpoint-low` x=a, `endpoint-high` x=b) and **5 interior** cases whose secret `x` is a pure function of the fixture name via SHA-256. Interrupted trials are reproducible by name (`--fixture ` / `reproduce_fixture()`): no RNG, no wall-clock dependence. **Measurement method recorded per trial:** trial count & successes (summary line), group operations (every modular multiply counted in `gmul()`), termination limit (per method), elapsed time (`time.perf_counter()` around the solve only), peak memory (`tracemalloc` peak bytes around the solve only). All outputs are labelled SYNTHETIC and report only these fixtures. ## Commands actually run (from `toy-comparison/`) 1. `python3 toy_dlog.py` — full benchmark table. 2. `python3 toy_dlog.py --json` — machine-readable output (used to confirm op-count determinism across runs). 3. `python3 toy_dlog.py --fixture interior-charlie` — single-trial reproduce path. 4. `python3 -m unittest -v test_toy_dlog` — test suite. ## Observed results `python3 toy_dlog.py` → **14/14 trials solved (7 fixtures × 2 methods)**, every row `ok=Y`, `recov == exp`, kangaroo note `collision`. Representative rows (g-ops and recovered values are stable across runs; time/mem are host-dependent): ``` fixture kind method ok recov exp g-ops limit mem(B) time(s) endpoint-low endpoint-low bsgs Y 1000 1000 66 130 4656 0.00015 endpoint-low endpoint-low kangaroo Y 1000 1000 522 624 25296 0.00147 endpoint-high endpoint-high bsgs Y 5096 5096 129 130 4688 0.00023 endpoint-high endpoint-high kangaroo Y 5096 5096 208 624 25248 0.00052 interior-charlie interior bsgs Y 4102 4102 113 130 4688 0.00017 interior-charlie interior kangaroo Y 4102 4102 260 624 25248 0.00071 ``` Reading (toy size only): BSGS uses tens of group operations but holds a `√W` baby-step table (~4.7 KB peak); the single-table kangaroo uses hundreds of operations with a larger footprint table (~25 KB peak). This is the expected textbook trade-off *at this toy scale* and is **not** a claim about any real-size problem. `python3 -m unittest test_toy_dlog` → `Ran 18 tests ... OK`. Tests cover: group validity and 16-bit order, generator order, op-counter, fixture interval/endpoint coverage, pure-function determinism of secrets, both methods solving every fixture on identical instances, measurements recorded, op-count determinism across repeats, searches staying within the termination limit, and a negative case (an out-of-interval target is never falsely "solved"). Determinism check via `--json`: group-op counts identical across runs (e.g. bsgs/endpoint-low = 66, kangaroo/endpoint-low = 522). ## How it was checked Ran the benchmark (table + JSON), the single-fixture reproduce path, and the full `unittest` suite — all pass, 14/14 trials solved, 18/18 tests OK. During development the kangaroo initially failed 6/7 fixtures (mis-sized jump set: mean jump 341 ≫ interval, plus a too-tight early-break); fixed by targeting mean jump ≈ √W/2 and a correct wild step budget bounded by the tame kangaroo's reach, after which all fixtures collide. Verified on CPython 3.12.3. ## Blockers None for this item. It is complete, self-contained, stdlib-only, and reproducible. (Unrelated to this item: the batch's overarching Puzzle #140 objective is out of scope here and not addressed by this component.)