kiosk-pow-equihash 0.5.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +136 -0
- data/LICENSE.txt +202 -0
- data/README.md +295 -0
- data/bench/README.md +60 -0
- data/bench/bench.py +153 -0
- data/lib/kiosk/pow/equihash/railtie.rb +16 -0
- data/lib/kiosk/pow/equihash/solver.rb +31 -0
- data/lib/kiosk/pow/equihash/version.rb +9 -0
- data/lib/kiosk/pow/equihash.rb +134 -0
- data/requirements.txt +1 -0
- data/solve.py +273 -0
- metadata +97 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 6baa5d5c03c64ca19948932dd4093dcfd863d400cbee4c558bc8664d96004703
|
|
4
|
+
data.tar.gz: 3e6ae6eecbdaa8f4e13d65cdc2f887843d049b1bf89f06cba3196aa4950628b5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8923be034745ce4856296a4ce2fe7a684c82bbd294c443b0547d2109d076e9b344ee10ae249a96e0586f2e0c8d8e53f88050678100602eb48017bdfbceb0d556
|
|
7
|
+
data.tar.gz: 386b0c5de1f4f348a496824e672eac748e3e722209bff3d9149539e899a005febfc97bc16d93042cbd644bb51f9f86ac1a89eec11ebdcf217599d482ddbb8e52
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes follow [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and [Semantic Versioning](https://semver.org/).
|
|
4
|
+
|
|
5
|
+
How to write an entry, and what a release section means: `CHANGELOG-RULE.md` at
|
|
6
|
+
the root of this repository —
|
|
7
|
+
<https://github.com/kiosk-hq/kiosk/blob/main/CHANGELOG-RULE.md>. In short: under
|
|
8
|
+
200 characters, one or two sentences, the essence rather than the content; write it
|
|
9
|
+
under `## [Unreleased]`; a cut renames that heading to
|
|
10
|
+
`## [MAJOR.MINOR.PATCH] — <date>` and opens a fresh empty one above it; nothing
|
|
11
|
+
already written is edited.
|
|
12
|
+
|
|
13
|
+
## [Unreleased]
|
|
14
|
+
|
|
15
|
+
## [0.5.20] — 2026-10-20
|
|
16
|
+
|
|
17
|
+
- 2026-10-20: Version 0.5.20, the tree cut that matches skill 0.5.20.
|
|
18
|
+
|
|
19
|
+
## [0.5.19] — 2026-10-20
|
|
20
|
+
|
|
21
|
+
- 2026-10-20: `solve.py`'s numpy error says that the solver has no path without numpy.
|
|
22
|
+
|
|
23
|
+
## [0.5.18] — 2026-10-18
|
|
24
|
+
|
|
25
|
+
- 2026-10-18: Version 0.5.18, the tree cut that matches skill 0.5.18.
|
|
26
|
+
|
|
27
|
+
## [0.5.17] — 2026-10-18
|
|
28
|
+
|
|
29
|
+
- 2026-10-18: The README gives a valid verify's memory as measured: under 3 KB live, and ~16 MB of short-lived objects that the GC frees.
|
|
30
|
+
- 2026-10-18: The gemspec and README give the verify cost as measured: ~22 ms for a valid proof at n=168 k=7 in pure Ruby, ~15 ms with YJIT.
|
|
31
|
+
## [0.5.16] — 2026-10-18
|
|
32
|
+
|
|
33
|
+
- 2026-10-18: `Kiosk::Pow::Equihash.solver_path` is removed; a client solves with `Kiosk::Pow::Equihash.solve`.
|
|
34
|
+
- 2026-10-18: Built on kiosk-pow: BLAKE2b-256 is `Kiosk::Pow::Blake2b.digest256`, and `Equihash.blake2b256` is gone. Verify results are byte-for-byte the same.
|
|
35
|
+
|
|
36
|
+
## [0.5.15] — 2026-10-18
|
|
37
|
+
|
|
38
|
+
- 2026-10-18: Version 0.5.15, the tree cut that matches skill 0.5.15.
|
|
39
|
+
|
|
40
|
+
## [0.5.14] — 2026-10-18
|
|
41
|
+
|
|
42
|
+
- 2026-10-18: Version 0.5.14, the tree cut that matches skill 0.5.14.
|
|
43
|
+
|
|
44
|
+
- 2026-10-17: In a Rails app the gem registers itself as the `equihash` proof-of-work backend at boot; an app no longer registers it by hand.
|
|
45
|
+
|
|
46
|
+
## [0.5.13] — 2026-10-11
|
|
47
|
+
|
|
48
|
+
- 2026-10-11: Version 0.5.13, the tree cut that matches skill 0.5.13.
|
|
49
|
+
|
|
50
|
+
- 2026-10-09: **`Kiosk::Pow::Equihash::Difficulty` and its `KIOSK_POW_DIFFICULTY` variable are removed**; an operator passes `(n, k)` explicitly.
|
|
51
|
+
|
|
52
|
+
## [0.5.12] — 2026-10-08
|
|
53
|
+
|
|
54
|
+
- 2026-10-08: Version 0.5.12, the tree cut that matches skill 0.5.12; this gem's surface is unchanged.
|
|
55
|
+
|
|
56
|
+
## [0.5.11] — 2026-10-08
|
|
57
|
+
|
|
58
|
+
- 2026-10-08: Version 0.5.11, the tree cut that matches skill 0.5.11; this gem's surface is unchanged.
|
|
59
|
+
|
|
60
|
+
## [0.5.10] — 2026-10-08
|
|
61
|
+
|
|
62
|
+
- 2026-10-08: Version 0.5.10, the tree cut that matches skill 0.5.10; this gem's surface is unchanged.
|
|
63
|
+
|
|
64
|
+
## [0.5.9] — 2026-10-08
|
|
65
|
+
|
|
66
|
+
- 2026-10-08: Version 0.5.9, the tree cut that matches skill 0.5.9; this gem's surface is unchanged.
|
|
67
|
+
|
|
68
|
+
## [0.5.8] — 2026-10-07
|
|
69
|
+
|
|
70
|
+
- 2026-10-07: Version 0.5.8, the tree cut that matches skill 0.5.8; this gem's surface is unchanged.
|
|
71
|
+
|
|
72
|
+
## [0.5.7] — 2026-10-07
|
|
73
|
+
|
|
74
|
+
- 2026-10-07: **The published solver drops an uncalled helper, an unsourced claim and an untested `--toy` mode**; it solves and verifies exactly as before (K-1678).
|
|
75
|
+
|
|
76
|
+
- 2026-10-07: **The heavy-toll `pow_notice` points at the solver the Kiosk skill pins**, not at this gem's bundled one (K-2017).
|
|
77
|
+
|
|
78
|
+
## [0.5.6] — 2026-10-07
|
|
79
|
+
|
|
80
|
+
- 2026-10-07: Version 0.5.6, the tree cut that matches skill 0.5.6; this gem's surface is unchanged.
|
|
81
|
+
|
|
82
|
+
## [0.5.5] — 2026-10-07
|
|
83
|
+
|
|
84
|
+
- 2026-10-07: Version 0.5.5, the tree cut that matches skill 0.5.5; this gem's surface is unchanged.
|
|
85
|
+
|
|
86
|
+
## [0.5.4] — 2026-10-07
|
|
87
|
+
|
|
88
|
+
- 2026-10-07: Version 0.5.4, the tree cut that matches skill 0.5.4; this gem's surface is unchanged.
|
|
89
|
+
|
|
90
|
+
## [0.5.3] — 2026-10-06
|
|
91
|
+
|
|
92
|
+
- 2026-10-06: Version 0.5.3, the tree cut that matches skill 0.5.3; this gem's surface is unchanged.
|
|
93
|
+
|
|
94
|
+
## [0.5.2] — 2026-10-06
|
|
95
|
+
|
|
96
|
+
- 2026-10-05: **The package ships `requirements.txt` beside `solve.py`**, declaring the solver's `numpy` the way `kiosk-pow` declares `argon2-cffi`.
|
|
97
|
+
|
|
98
|
+
## [0.5.0] — 2026-09-26
|
|
99
|
+
|
|
100
|
+
### Added
|
|
101
|
+
|
|
102
|
+
- `Kiosk::Pow::Equihash` — pure-Ruby Equihash (Biryukov & Khovratovich) verifier, the shipped default Kiosk PoW backend. No runtime dependencies: BLAKE2b-256 is clean-room pure Ruby from the public-domain BLAKE2 spec, and the gem depends on neither `kiosk-core` nor Rails.
|
|
103
|
+
- `Kiosk::Pow::Equihash::NAME = "equihash"` — algorithm identifier for the challenge wire format.
|
|
104
|
+
- `Kiosk::Pow::Equihash.params(n: 168, k: 7)` — challenge params; `DEFAULT_N` / `DEFAULT_K` carry the shipped defaults.
|
|
105
|
+
- `Kiosk::Pow::Equihash.valid_params?(params)` — could a proof at these parameters ever verify? Exactly `verify`'s Step 0 parameter checks, extracted so a gate can refuse to MINT an unsatisfiable challenge instead of issuing one and blaming the client's correct proof (K-843). `verify` calls it, so the accepted set is identical by construction.
|
|
106
|
+
- `Kiosk::Pow::Equihash.verify(salt:, params:, nonce:)` — recomputes the `2^k` BLAKE2b-256 leaf hashes named by the proof's indices, checks their XOR is zero over all `n` bits, and walks the Wagner collision tree (per-level XOR cancellation plus the Zcash-canonical subtree ordering). Difficulty is set by `(n, k)` alone — there is no post-hoc target check.
|
|
107
|
+
- `Kiosk::Pow::Equihash.blake2b256` — public so specs can check it directly against Python `hashlib.blake2b` vectors.
|
|
108
|
+
- `solve.py` — reference Python + numpy solver (a correct full-Wagner implementation, not a tuned miner), with a `--toy` `(n=24, k=3)` mode for tests.
|
|
109
|
+
- `Kiosk::Pow::Equihash.solver_path` — public accessor returning the absolute path of the packaged `solve.py`, so consumers (the `kiosk-redteam` client first) shell out to the shipped solver by asking this gem instead of hardcoding a checkout-relative path that breaks in an installed gem.
|
|
110
|
+
- `Kiosk::Pow::Equihash.solve(challenge)`, in `kiosk/pow/equihash/solver` — the client half of `verify`: runs the packaged solver on one challenge the provider minted and returns the proof nonce, raising `SolverError` with the solver's own message. Callers stop repeating the `Open3` invocation and the two error branches around it, and nothing outside this gem has to know where `solve.py` lives. It is a SEPARATE require on purpose: a provider verifies a proof on an unauthenticated register, and what it loads there must not be able to spawn a process.
|
|
111
|
+
- `Kiosk::Pow::Equihash::Difficulty` — the operator's `KIOSK_POW_DIFFICULTY` knob: `low` (n=96, k=5, sub-second) or `high` (the gem's own `DEFAULT_N`/`DEFAULT_K`), with `params`, `level`, `high?` and a `pow_notice` for a discovery document's owner block. An unset or unrecognised value always lands on `low`, so a typo cannot price a verb out of reach. The heavy level is read off the shipped defaults rather than written out again.
|
|
112
|
+
- `bench/bench.py` and `bench/README.md` — the `(n, k)` sweep behind the default, reporting p50/p95 solve time and peak RSS.
|
|
113
|
+
- Known-answer tests frozen at the SHIPPED production parameters (n=168, k=7), not only at toy params — a toy-only KAT is what let a broken verifier pass, and `k=2`/`k=3` vectors now cover the tree check the old one could not see.
|
|
114
|
+
- Live solver-to-verifier parity spec at 168/7 — `solve.py` produces a proof and `.verify` accepts it; CI installs numpy so the job actually runs it rather than skipping.
|
|
115
|
+
- `spec/solver_pin_spec.rb` — runs `bin/check-solver-pin` from this gem's own suite, so editing `solve.py` fails here rather than silently breaking every assistant that verifies the file's SHA-256 against the pin published in the skill. Skips, stating why, in a gem-only checkout where the script is absent.
|
|
116
|
+
|
|
117
|
+
### Changed
|
|
118
|
+
|
|
119
|
+
- **The verifier's comments now describe the verifier (K-1679..K-1682).** They named the opposite traversal, cited nothing, skipped a step number and kept a short list.
|
|
120
|
+
- The gemspec said `~17 ms` to verify where the README, the docstring and this gem's own spec all say `~18 ms`. A new example holds the two together.
|
|
121
|
+
- **The README states the verify/solve split, and a guard in the repository holds it (K-1396).** Verifying is the operator's Ruby — nothing a served request loads spawns a process, and `solve.py` is here for the caller that pays the toll. `bin/check-served-pow-purity` fails if any process-spawning construct becomes reachable from the served PoW path. No code change; the property was already true.
|
|
122
|
+
|
|
123
|
+
- **`.verify` now has an ANSWER for degenerate `(n, k)` — `false` — instead of a crash or a vacuous accept (K-840).** A negative `k` collapsed `1 << k` to 0, so an EMPTY indices array satisfied the length check and the root step dereferenced an empty stack (`NoMethodError`); `n = 0` (or any `n` below one byte) made every leaf the integer 0, so ANY `2^k` distinct ascending indices verified TRUE — a proof nobody supplied. `n` is now required to be `8..256` (the width a BLAKE2b-256 leaf can actually carry), `k` non-negative, and `n / (k + 1)` at least one bit per level; anything else is a malformed challenge, not an exception and not a solution. Not reachable over the wire — `Challenge.verify` re-derives the parameters from live config before the backend runs — so this is robustness against operator mis-config. The accepted set is unchanged: `n % (k + 1) == 0` is deliberately NOT required, because the hand-computed `(n=8, k=2)` KAT is a real accepted solution with `8 % 3 == 2`.
|
|
124
|
+
|
|
125
|
+
- Default parameters retuned from n=192, k=7 to **n=168, k=7** after benchmarking: 192/7 measured ~155 s and ~5.4 GiB on the reference solver, too heavy for a consumer laptop; 168/7 lands at p95 ~10 s and ~1.3 GiB.
|
|
126
|
+
- README and docstrings state what the gem actually is — a cheap-to-verify metered toll at ~17 ms and a few KB per verify, priced by the reputation policy's N-proofs knob. The ASIC-/GPU-resistance claims and the microsecond-verify figure are gone: Equihash was ASIC'd on Zcash, and neither claim was supportable.
|
|
127
|
+
- `DEFAULT = true` removed — defaultness is established by registry wiring, not by a constant on this module.
|
|
128
|
+
- `.verify` now costs a WRONG proof far less than a right one: the index checks (count, type, u64 range, distinctness, canonical subtree ordering) run before any hashing, and the leaf hashes are computed one at a time as the Wagner tree folds, so verification stops at the first node that fails. Measured at n=168 k=7: unordered rubbish 0.012 ms and well-ordered rubbish 0.30 ms, against 18.7 ms when every proof paid the full 128-hash loop; a valid proof is unchanged at ~18 ms. Which proofs verify is unchanged — `verify` is reachable unauthenticated on `POST /auth/register`, so what changes is how much an attacker can buy with a proof they did not solve (K-540).
|
|
129
|
+
- An index at or above 2**64 is rejected instead of being truncated by `pack("Q<")`, which had made `idx` and `idx + 2**64` two spellings of one leaf.
|
|
130
|
+
- `bench/` and everything under `lib/` ship unconditionally, so the packaged README's links to the benchmark evidence resolve inside the gem. `CHANGELOG.md` is listed the same way: the file list has no `File.exist?` guard, so a file this gemspec names and cannot find breaks the build instead of going quiet.
|
|
131
|
+
- The gemspec declares a description, a homepage and the `homepage_uri` / `source_code_uri` / `bug_tracker_uri` / `changelog_uri` metadata, which it had never carried — the default PoW backend used to render on RubyGems as a bare summary line with no prose and no links.
|
|
132
|
+
|
|
133
|
+
### Fixed
|
|
134
|
+
|
|
135
|
+
- Verifier rewritten to the Zcash-canonical collision-tree check. The previous one checked leaf-prefix *equality* plus a global ascending sort; both are invisible at k=1, which is all the tests exercised, so it never accepted a real proof at the production parameters.
|
|
136
|
+
- `verify` returns `false` instead of raising on a malformed proof — a non-Integer or negative index, a duplicate index, a wrong-length index list, or a non-numeric `header_nonce`.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
# Kiosk::Pow::Equihash
|
|
2
|
+
|
|
3
|
+
Memory-hard proof-of-work for Kiosk. Default PoW backend.
|
|
4
|
+
|
|
5
|
+
Its job is a **cheap-to-verify metered toll**, not a hardware equaliser.
|
|
6
|
+
Equihash is not ASIC- or GPU-proof — it was ASIC'd on Zcash (Antminer Z9/Z15)
|
|
7
|
+
and GPUs solve it well (the Wagner sort/collide parallelises, and it is
|
|
8
|
+
memory-bandwidth-bound). What it buys the provider is a few-KB, ~22 ms
|
|
9
|
+
`verify` against a solve that costs the client real time and memory, plus an
|
|
10
|
+
`N×PoW` count knob. Abuse resistance comes from reputation and caps
|
|
11
|
+
(PoW = metered pricing, not a hardware wall).
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
> **Not on RubyGems yet** — so every `gem` line below carries `github: "kiosk-hq/kiosk"`, which is what makes it copy-pasteable today. Publication status and the canonical install are stated once, in the monorepo README's [Install](https://github.com/kiosk-hq/kiosk#install) section.
|
|
16
|
+
|
|
17
|
+
Default does not mean bundled: neither `kiosk-server` nor `kiosk-all` depends
|
|
18
|
+
on a PoW backend, so an origin that gates on PoW adds this gem itself.
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
gem "kiosk-pow-equihash", github: "kiosk-hq/kiosk"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The verifier is pure Ruby. Its one runtime dependency is `kiosk-pow`, the
|
|
25
|
+
pure-Ruby base that holds BLAKE2b-256. It needs no `kiosk-core`, no Rails and no
|
|
26
|
+
native extension. In a Rails app the gem registers itself as the
|
|
27
|
+
`equihash` backend when the app boots. The registry lives in `kiosk-reputation`,
|
|
28
|
+
which an origin adds to its Gemfile the same way. Outside Rails, register it
|
|
29
|
+
yourself:
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
require "kiosk/pow/equihash"
|
|
33
|
+
|
|
34
|
+
# Kiosk::Pow::Equihash::NAME == "equihash"
|
|
35
|
+
Kiosk::Reputation::Backends.register(Kiosk::Pow::Equihash::NAME, Kiosk::Pow::Equihash)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
That is the whole install for an **operator**, and it is deliberately this
|
|
39
|
+
small: verifying is what a served request does. **Solving is the caller's
|
|
40
|
+
side**, and it is the only part with a prerequisite outside Ruby — `solve.py`
|
|
41
|
+
ships inside the package and needs **`python3` with `numpy`**
|
|
42
|
+
(`pip install -r requirements.txt`, which ships beside it). Ask the gem for
|
|
43
|
+
the file's installed location rather than hardcoding a path, and read the
|
|
44
|
+
Solver section below first: numpy is not optional there, and the default
|
|
45
|
+
parameters cost real time and memory to solve.
|
|
46
|
+
|
|
47
|
+
## Why Equihash is the shipped default
|
|
48
|
+
|
|
49
|
+
| | Argon2id | Cuckatoo29 | **Equihash (default)** |
|
|
50
|
+
|---|---|---|---|
|
|
51
|
+
| Verify memory | 64 MiB ⚠️ | ~KB | **~KB** |
|
|
52
|
+
| Verify time | ~ms (1 Argon2id) | 42 SipHash + walk (unbenched) | **~22 ms valid / 0.3 ms wrong (Ruby)** |
|
|
53
|
+
| Lever (solve/verify) | tens× | unbenched | **~440×** (9.6 s / 22 ms) |
|
|
54
|
+
| Dependencies | argon2 gem (C-ext) | Pure Ruby | **Pure Ruby (kiosk-pow only)** |
|
|
55
|
+
| Difficulty tuning | D=0..256 (smooth) | edgebits | **N×PoW (discrete)** |
|
|
56
|
+
|
|
57
|
+
**The lever is measured, not asserted.** `~440×` is this README's own two
|
|
58
|
+
numbers divided: the p50 reference-solver solve at the shipped n=168 k=7
|
|
59
|
+
(~9.6 s, *Performance* below) over a valid proof's verify (~22 ms, *Verify* above);
|
|
60
|
+
p95 solve gives ~470×. With YJIT (~15 ms verify) the p50 lever is ~640×. It is a cross-language ratio — a numpy solver against a
|
|
61
|
+
pure-Ruby verifier — so read it as the order of magnitude a provider actually
|
|
62
|
+
buys, and note that it moves the WRONG way with a faster solver and the right way
|
|
63
|
+
with a native verifier. It is not millions at any tuning in the tables below
|
|
64
|
+
(192/7, at ~155 s of solve, gives ~7000×), and the number matters
|
|
65
|
+
because the lever IS the economic argument for a metered toll — a price on
|
|
66
|
+
abuse, not a hardware wall. Cuckatoo29's column says `unbenched` for the same
|
|
67
|
+
reason its verify row does: no measurement of it exists here.
|
|
68
|
+
|
|
69
|
+
The one property that actually matters for a gateway is **cheap verify**:
|
|
70
|
+
|
|
71
|
+
- **Asymmetric verify.** A few KB (and ~22 ms, pure Ruby — far less for a
|
|
72
|
+
wrong proof, see below) to check — the
|
|
73
|
+
memory footprint is the point: Argon2id needs 64 MiB to _verify_, so a flood
|
|
74
|
+
of bad proofs is a DoS on the verifier itself — unacceptable for a
|
|
75
|
+
high-throughput endpoint.
|
|
76
|
+
- **No native code.** Pure Ruby BLAKE2b-256 from `kiosk-pow`. Argon2id needs a C extension.
|
|
77
|
+
- **Progressive difficulty via N×PoW.** Instead of a continuous dial the policy
|
|
78
|
+
asks for _N independent proofs_: "1 normally, 10 if you're scraping." Prices
|
|
79
|
+
throughput, not latency (a solver with enough memory runs them in parallel).
|
|
80
|
+
|
|
81
|
+
No hardware-parity claim is made — none of Argon2id, Cuckatoo, or Equihash
|
|
82
|
+
delivers it. Equihash wins on verify cost + no native code, which is what a
|
|
83
|
+
provider's own machine pays on every request.
|
|
84
|
+
|
|
85
|
+
## Parameters
|
|
86
|
+
|
|
87
|
+
Default: **n=168, k=7** — benchmark-chosen (see [bench/](bench/README.md)):
|
|
88
|
+
the largest params whose reference numpy solve stays under a ~30 s / 1–2 GiB
|
|
89
|
+
consumer-laptop budget (p95 ~10 s on one M-series laptop core — the only
|
|
90
|
+
hardware the seconds have ever been measured on; the ~1.3 GiB peak is THIS
|
|
91
|
+
solver's sorted-nonce table, not the host's — and not a floor `(n, k)`
|
|
92
|
+
imposes on every implementation, since a memory-optimised solver trades the
|
|
93
|
+
table for time, which is precisely how Equihash 200/9's real footprint fell
|
|
94
|
+
to ~144 MB and made it ASIC-able). Cost is driven by `n_div = n/(k+1)`.
|
|
95
|
+
|
|
96
|
+
| Param | **n=168, k=7 (default)** | n=192, k=7 | Zcash (n=200, k=9) | Toy (n=24, k=3) |
|
|
97
|
+
|---|---|---|---|---|
|
|
98
|
+
| n_div = n/(k+1) | **21** | 24 | 20 | 6 |
|
|
99
|
+
| Nonces generated | **2^22 ≈ 4.2M** | 2^25 ≈ 33.5M | 2^21 ≈ 2M | 2^7 = 128 |
|
|
100
|
+
| Nonces in proof | **2^7 = 128** | 128 | 2^9 = 512 | 2^3 = 8 |
|
|
101
|
+
| Reference solve (numpy, one M-series laptop core) | **~10 s, ~1.3 GiB** | ~155 s, ~5.4 GiB | — | instant |
|
|
102
|
+
| Verify cost | **128 BLAKE2b** | 128 BLAKE2b | 512 BLAKE2b | 8 BLAKE2b |
|
|
103
|
+
|
|
104
|
+
192/7 measures ~155 s and ~5.4 GiB on the reference numpy
|
|
105
|
+
solver — too heavy for a laptop, which is why 168/7 is the default. Providers
|
|
106
|
+
pick their own `(n, k)` and proof count for their own cost/latency trade-off.
|
|
107
|
+
|
|
108
|
+
## Memory reuse across parallel challenges
|
|
109
|
+
|
|
110
|
+
**Buffer reuse: yes. Work reuse: no.**
|
|
111
|
+
|
|
112
|
+
The solver allocates one sorted-nonce-table buffer (~1.3 GiB at the default
|
|
113
|
+
params). This buffer can be reused across challenges (same allocation, different
|
|
114
|
+
data). However, the _computational work_ cannot be reused:
|
|
115
|
+
|
|
116
|
+
- Each challenge has a unique `salt` (raw random bytes, minted by the
|
|
117
|
+
challenge issuer — `kiosk-reputation` mints 16, see its README)
|
|
118
|
+
- The seed = `salt ‖ LE32(header_nonce)` is hashed with each nonce
|
|
119
|
+
- Different salt → completely different BLAKE2b-256 outputs
|
|
120
|
+
- The sorted nonce table must be rebuilt from scratch
|
|
121
|
+
|
|
122
|
+
This is a deliberate design property: honest clients doing occasional PoWs pay the allocation cost once (buffer reuse). Attackers doing many parallel PoWs must do the full computational work for each — no amortization.
|
|
123
|
+
|
|
124
|
+
## Anti-abuse strategy: N×PoW
|
|
125
|
+
|
|
126
|
+
Equihash has discrete difficulty — only via (n, k) parameter changes. Instead of a continuous difficulty dial, the protocol uses **proof count**. A policy picks the count for each client, for example:
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
Normal client: solve 1 PoW (1× memory, 1× work)
|
|
130
|
+
Suspicious: solve 3 PoWs (3× work; parallel if RAM allows)
|
|
131
|
+
Abuser: solve 10 PoWs (10× work)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
N prices _throughput_, not latency: a solver with enough memory runs the N
|
|
135
|
+
independent proofs in parallel, so wall-clock need not grow 10× — but the total
|
|
136
|
+
compute/energy does, which is the cost that lands on a sustained scraper.
|
|
137
|
+
|
|
138
|
+
This is superior to Argon2id's `D` parameter because:
|
|
139
|
+
|
|
140
|
+
1. **No verifier changes.** Same `verify()` call, just N times.
|
|
141
|
+
2. **Self-documenting.** "You need 10 proofs" tells the client exactly how throttled they are.
|
|
142
|
+
3. **Operator-friendly.** Adjust N per-client based on abuse score, no parameter tuning.
|
|
143
|
+
4. **Predictable cost.** Each proof is independent — the solver knows exactly how much work is needed.
|
|
144
|
+
|
|
145
|
+
## Wire format
|
|
146
|
+
|
|
147
|
+
Challenge (as issued by the gate — `Kiosk::Reputation::Challenge.issue`):
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"id": "<opaque id>",
|
|
151
|
+
"alg": "equihash",
|
|
152
|
+
"params": { "n": 168, "k": 7 },
|
|
153
|
+
"salt": "<base64 salt>",
|
|
154
|
+
"exp": 1751846400,
|
|
155
|
+
"sig": "<HMAC-SHA256 hex>"
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Proof:
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"indices": [128 u64 integers in Zcash-canonical tree order],
|
|
163
|
+
"header_nonce": 0
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The solver accepts the salt under either key — the gate/challenge wire key
|
|
168
|
+
`salt` or the alias `salt_b64`. `header_nonce` is a solver-chosen field of the
|
|
169
|
+
*proof*, not a wire-challenge field.
|
|
170
|
+
|
|
171
|
+
`indices` are **not** globally sorted — they are in canonical Wagner-tree
|
|
172
|
+
order (see "Verification contract" below).
|
|
173
|
+
|
|
174
|
+
## Verification (Ruby)
|
|
175
|
+
|
|
176
|
+
```ruby
|
|
177
|
+
Kiosk::Pow::Equihash.verify(
|
|
178
|
+
salt: raw_bytes,
|
|
179
|
+
params: { n: 168, k: 7 },
|
|
180
|
+
nonce: { indices: [/* 128 u64 */] }
|
|
181
|
+
)
|
|
182
|
+
# => true / false
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Checks performed (in order):
|
|
186
|
+
1. Exactly 2^k distinct non-negative indices below 2^64 (no floats)
|
|
187
|
+
2. Collision tree — at each level j, every group of 2^(j+1) leaves:
|
|
188
|
+
- is in **canonical order**: the left half's first index < the right half's, and
|
|
189
|
+
- has its **XOR cancel** the top (j+1)×n_div bits (Wagner cancellation)
|
|
190
|
+
3. Global XOR of all 2^k leaf hashes = 0 on n bits
|
|
191
|
+
|
|
192
|
+
Verification cost: **~22 ms for a valid proof** (128 BLAKE2b-256 hashes, pure
|
|
193
|
+
Ruby; measured median at n=168 k=7 on one Apple M3 core, Ruby 4.0.1). Live
|
|
194
|
+
memory stays under 3 KB: 1.8 KB at most inside one hash, 0.8 KB between hashes.
|
|
195
|
+
The hashes allocate ~16 MB of short-lived objects, and the GC frees them.
|
|
196
|
+
With YJIT, which a Rails app enables, it is ~15 ms. A native verifier would be
|
|
197
|
+
sub-millisecond. Verify scales with 2^k, not with n: at n=96 k=5 a valid proof
|
|
198
|
+
costs ~5.6 ms (32 hashes, same machine) — cheaper to verify, but cheaper to
|
|
199
|
+
solve by far more.
|
|
200
|
+
|
|
201
|
+
**A wrong proof costs far less, deliberately.** The list above is also the
|
|
202
|
+
evaluation ORDER, cheapest first, and the leaf hashes are computed one at a
|
|
203
|
+
time as the tree folds — so verification stops at the first tree node that does
|
|
204
|
+
not cancel. Rubbish indices are rejected without a single hash (0.012 ms
|
|
205
|
+
measured); rubbish that is at least well-ordered stops after two hashes
|
|
206
|
+
(0.30 ms), against ~22 ms for a complete one. That gap is the point, because
|
|
207
|
+
`verify` is reachable unauthenticated on `POST /auth/register`: an attacker who
|
|
208
|
+
wants the whole hash loop has to hand over an almost-complete solution, against
|
|
209
|
+
a salt that is fresh per challenge.
|
|
210
|
+
|
|
211
|
+
### Verification contract (why it is XOR-cancellation, not prefix-equality)
|
|
212
|
+
|
|
213
|
+
Equihash is a *generalized-birthday* PoW: a valid solution is a binary tree of
|
|
214
|
+
2^k leaf hashes where **sibling XORs cancel** one n_div-bit block per level.
|
|
215
|
+
The leaves in a group do **not** share a common prefix — only their XOR is
|
|
216
|
+
zero on that block. Two consequences the verifier must respect:
|
|
217
|
+
|
|
218
|
+
- **Tree check = XOR, not equality.** Checking "all 2^(j+1) leaves share the
|
|
219
|
+
top (j+1)×n_div bits" is wrong for groups larger than 2 (it is satisfiable
|
|
220
|
+
only by an astronomically rare all-equal cluster — at n=168,k=7 it asks 128
|
|
221
|
+
leaves to share 147 bits, expected count ≈ 2^22/2^147 ≈ 0). The correct
|
|
222
|
+
check is that the group's **XOR** cancels those bits.
|
|
223
|
+
- **Order = canonical, not a global sort.** A real solution's tree order is
|
|
224
|
+
not ascending (pair (a,b)+(c,d) may interleave when flattened). Requiring a
|
|
225
|
+
global sort rejects every genuine k≥2 solution. We use Zcash "algorithm
|
|
226
|
+
binding": at each node the left subtree's first index precedes the right's.
|
|
227
|
+
|
|
228
|
+
## Solver (Python + numpy)
|
|
229
|
+
|
|
230
|
+
**Verifying is the operator's Ruby; solving is the caller's problem.** Nothing
|
|
231
|
+
an operator's server loads to serve a request ever executes a subprocess — the
|
|
232
|
+
`verify` above is pure Ruby with no shell-out anywhere in its reach, and
|
|
233
|
+
`solve.py` is here for the CALLER that pays the toll, run by the caller's own
|
|
234
|
+
process. No process-spawning construct — `Open3`, `system`, backticks,
|
|
235
|
+
`IO.popen`, `spawn`, `exec`, `%x` — is reachable from the served set, and no
|
|
236
|
+
served file names the solver. The example below is what a CLIENT does, and that is why it is safe.
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
pip install numpy # REQUIRED — see performance note below
|
|
240
|
+
python3 solve.py '{"salt_b64":"...", "params":{"n":168,"k":7}}'
|
|
241
|
+
# => {"indices": [...128 u64 in canonical tree order...], "header_nonce": 0}
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
`solve.py` ships inside the gem package. From Ruby, a client solves through it
|
|
245
|
+
with one call; it raises `SolverError` when the solver refuses:
|
|
246
|
+
|
|
247
|
+
```ruby
|
|
248
|
+
require "kiosk/pow/equihash/solver"
|
|
249
|
+
Kiosk::Pow::Equihash.solve(challenge)
|
|
250
|
+
# => {"indices" => [...], "header_nonce" => 0}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
The solver runs full Wagner's algorithm (all pairs within each collision
|
|
254
|
+
bucket, not greedy adjacent pairs) and emits the solution in Zcash-canonical
|
|
255
|
+
tree order. Every hot step is vectorised in numpy: leaf hashes are packed into
|
|
256
|
+
a uint64 array, each level sorts by the n_div-bit collision block, and
|
|
257
|
+
collisions/XORs run as whole-array ops. Deep Wagner levels grow degenerate
|
|
258
|
+
"megabuckets" of index-reusing entries; the solver caps bucket participation
|
|
259
|
+
(`BUCKET_CAP`) to keep work and memory bounded — the real solution comes from
|
|
260
|
+
the healthy small buckets, and unsolved seeds retry with the next
|
|
261
|
+
`header_nonce`.
|
|
262
|
+
|
|
263
|
+
**Performance (measured, reference numpy solver, one M-series laptop core):**
|
|
264
|
+
|
|
265
|
+
| params | p50 solve | p95 solve | peak RSS |
|
|
266
|
+
|---|---|---|---|
|
|
267
|
+
| n=96, k=5 | ~0.2 s | ~0.3 s | ~44 MiB |
|
|
268
|
+
| **n=168, k=7 (default)** | ~9.6 s | ~10.3 s | ~1.3 GiB |
|
|
269
|
+
| n=192, k=7 | ~155 s | ~155 s | ~5.4 GiB |
|
|
270
|
+
|
|
271
|
+
Full grid in [bench/README.md](bench/README.md). This is a REFERENCE
|
|
272
|
+
implementation — correct and dependency-light, not a miner. **numpy is not
|
|
273
|
+
optional**: the Wagner sort/collide steps are vectorised, and without numpy
|
|
274
|
+
`solve.py` refuses to run (exit 3). These numbers are the honest-client
|
|
275
|
+
*floor* (slowest participant): a native or GPU solver is faster, since Equihash
|
|
276
|
+
parallelises well — which is exactly why the security story is verify-asymmetry
|
|
277
|
+
+ reputation, not hardware parity. A provider that needs faster
|
|
278
|
+
honest solves lowers `n`; the Ruby verifier stays ~22 ms either way.
|
|
279
|
+
|
|
280
|
+
See `solve.py` for the implementation.
|
|
281
|
+
|
|
282
|
+
## Algorithm
|
|
283
|
+
|
|
284
|
+
Equihash (Biryukov & Khovratovich, 2016). Birthday-collision proof-of-work.
|
|
285
|
+
|
|
286
|
+
1. Generate 2^(n/(k+1) + 1) nonces
|
|
287
|
+
2. For each nonce `i`: `hash_i = BLAKE2b-256(salt ‖ header_nonce ‖ LE64(i))[:n/8]`
|
|
288
|
+
3. Wagner's algorithm: k levels of collision search
|
|
289
|
+
- Level j: group entries by top (j+1)×n_div bits, pair within groups
|
|
290
|
+
- Each pair's XOR zeroes those bits
|
|
291
|
+
4. Solution: 2^k nonces where XOR of all hashes = 0 on n bits AND the collision tree is valid
|
|
292
|
+
|
|
293
|
+
## License
|
|
294
|
+
|
|
295
|
+
Apache-2.0. See `LICENSE.txt`.
|