{"componentChunkName":"component---src-templates-post-js","path":"/blog/crypto-club-square-and-multiply","result":{"data":{"prevPost":{"html":"<blockquote>\n<p><strong>Correction, 11 November 2026.</strong> The SBAS design matrix in this pipeline is a\npermutation matrix. The certified residual is therefore identically zero for any\ninput, which makes the 2.3173862534e-7 quoted below float32 cumsum-then-diff\nrounding noise rather than a measurement of fit. Every draw accepts because every\ndraw would have accepted whatever the solver returned, so the completeness line\nfurther down proves nothing about the physics. The coverage argument, which is what\nthis post is about, never depended on that number and still holds. So do the cycle\ncounts, the receipt sizes and the on-chain gas.</p>\n</blockquote>\n<p>You can draw your audit sample with randomness the prover cannot rig, publish every residual, prove the whole check inside a zkVM, and still miss the only fault anyone would pay you to find.</p>\n<p>I know because I built one and it works exactly as designed. Chaotic Era pulls NASA NISAR L-band radar, runs a small-baseline time-series inversion on a GPU, and emits a certificate that anyone can check without a GPU. On the 141/54 frame the certificate audits 256 pixels drawn by Fiat-Shamir, and the worst of them missed the pinned equations by 2.3173862534e-7 against a tolerance of 1e-3. A RISC Zero guest re-executes that check in 8,388,608 cycles. The Groth16 wrap verifies on Base Sepolia for 249,749 gas.</p>\n<p>Every number there is measured. None of them says what I assumed it said.</p>\n<h2 id=\"the-asymmetry-is-real-and-it-is-the-whole-product\" style=\"position:relative;\"><a href=\"#the-asymmetry-is-real-and-it-is-the-whole-product\" aria-label=\"the asymmetry is real and it is the whole product permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The asymmetry is real, and it is the whole product</h2>\n<p>The pitch for a computation certificate is an asymmetry. Solving is expensive, checking is cheap, so you sell the expensive thing and hand over a cheap receipt.</p>\n<p>That part holds up for the heavy estimator. Phase-linking on the 141/54 frame took 13,512 seconds of L4 time across 12,774,412,800 pixels per acquisition. Re-checking a published answer from the public inputs takes 16.62 seconds on my laptop, and more than half of that is hashing a 666 MB output array rather than doing any mathematics.</p>\n<p>One caveat belongs here rather than buried at the bottom. The certificate I proved does not cover that run. It covers the small-baseline inversion over the same frame, and that solve takes 1.5321 seconds. So for this certificate the asymmetry runs backwards: checking costs ten times more than solving, because the check re-hashes 1.4 GB of inputs and outputs while the solve is a 7 by 7 pseudo-inverse. The asymmetry argument is sound for the expensive estimator, and I have not yet built a certificate for the expensive estimator.</p>\n<p>That's a gap, and it isn't the one this post is about. The one this post is about is worse.</p>\n<h2 id=\"the-sample-the-prover-cannot-rig\" style=\"position:relative;\"><a href=\"#the-sample-the-prover-cannot-rig\" aria-label=\"the sample the prover cannot rig permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The sample the prover cannot rig</h2>\n<p>The audit indices come from the input commitment itself.</p>\n<div class=\"gatsby-highlight\" data-language=\"python\"><pre class=\"language-python\"><code class=\"language-python\"><span class=\"token keyword\">def</span> <span class=\"token function\">sample_indices</span><span class=\"token punctuation\">(</span>seed_hex<span class=\"token punctuation\">,</span> n_total<span class=\"token punctuation\">,</span> n_sample<span class=\"token operator\">=</span>SAMPLE_PIXELS<span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    n_sample <span class=\"token operator\">=</span> <span class=\"token builtin\">min</span><span class=\"token punctuation\">(</span>n_sample<span class=\"token punctuation\">,</span> n_total<span class=\"token punctuation\">)</span>\n    rng <span class=\"token operator\">=</span> np<span class=\"token punctuation\">.</span>random<span class=\"token punctuation\">.</span>default_rng<span class=\"token punctuation\">(</span><span class=\"token builtin\">int</span><span class=\"token punctuation\">(</span>seed_hex<span class=\"token punctuation\">[</span><span class=\"token punctuation\">:</span><span class=\"token number\">16</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span> <span class=\"token number\">16</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">return</span> np<span class=\"token punctuation\">.</span>sort<span class=\"token punctuation\">(</span>rng<span class=\"token punctuation\">.</span>choice<span class=\"token punctuation\">(</span>n_total<span class=\"token punctuation\">,</span> size<span class=\"token operator\">=</span>n_sample<span class=\"token punctuation\">,</span> replace<span class=\"token operator\">=</span><span class=\"token boolean\">False</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p><code class=\"language-text\">seed_hex</code> is the SHA-256 over the sorted digests of every input granule. To choose which pixels get audited, I'd have to choose the hash, which means choosing the inputs, which are NASA's. So the sample is unriggable in the sense that matters. The prover commits to the data before learning which pixels the auditor will look at, and that is a real property with a real proof behind it.</p>\n<p>Unriggable is not the same as covering. I merged those two ideas for about two months without noticing, because the word \"Fiat-Shamir\" in a design document makes you feel like the soundness question has been handled.</p>\n<p>It has not. Fiat-Shamir tells you the sample is fair. It says nothing about how much of the scene 256 fair draws can see.</p>\n<h2 id=\"watch-it-miss\" style=\"position:relative;\"><a href=\"#watch-it-miss\" aria-label=\"watch it miss permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Watch it miss</h2>\n<p>The scene below is one NISAR frame. The dark region is a fault: a patch where the published displacement is wrong, either through a bad solve or a deliberate edit. The dots are the 256 audited pixels, drawn uniformly, exactly as <code class=\"language-text\">sample_indices</code> draws them.</p>\n<p>Move the slider to set how much of the scene is corrupted, then run audits.</p>\n<div class=\"dpw\" id=\"miss\" data-initialised=\"false\">\n  <div class=\"dpw-controls\">\n    <label class=\"dpw-label\">Corrupted fraction of the scene\n      <input type=\"range\" id=\"ms-f\" min=\"0\" max=\"10\" step=\"1\" value=\"3\" />\n      <span class=\"dpw-val\" id=\"ms-f-val\">0.1%</span>\n    </label>\n    <div class=\"dpw-hint\" id=\"ms-px\">24,950 pixels of 24,950,025 are wrong. The auditor looks at 256 of them.</div>\n  </div>\n  <svg id=\"ms-svg\" viewBox=\"0 0 480 240\" class=\"dpw-svg\" role=\"img\" aria-label=\"A radar scene with a corrupted region and 256 uniformly sampled audit pixels\"></svg>\n  <div class=\"dpw-btnrow\">\n    <button class=\"dpw-btn\" id=\"ms-once\">New audit</button>\n    <button class=\"dpw-btn\" id=\"ms-many\">Run 200 audits</button>\n    <button class=\"dpw-btn dpw-btn-ghost\" id=\"ms-reset\">Reset tally</button>\n  </div>\n  <div class=\"dpw-verdict\" id=\"ms-verdict\">the fault survived this audit</div>\n  <div class=\"dpw-readout\">\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"ms-caught\">0</span><span class=\"dpw-cap\">audits that caught it</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"ms-total\">0</span><span class=\"dpw-cap\">audits run</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"ms-emp\">&mdash;</span><span class=\"dpw-cap\">observed detection rate</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"ms-theory\">22.6%</span><span class=\"dpw-cap\">theory: 1 &minus; (1 &minus; f)<sup>256</sup></span></div>\n  </div>\n</div>\n<p>At a fault covering a tenth of one percent of the scene, the audit catches it in a bit under a quarter of runs. Which means a prover who corrupts that much of the answer walks past the certificate three times out of four.</p>\n<p>A tenth of one percent of this frame is 24,950 pixels. The frame is a 4,995 by 4,995 grid, so that fault is a contiguous block about 158 pixels on a side, a little over three percent of the scene width. A glacier terminus fits inside it. So does a subsiding industrial site, a stretch of embankment, or whichever single place a claim happens to name.</p>\n<h2 id=\"the-localised-fault-game\" style=\"position:relative;\"><a href=\"#the-localised-fault-game\" aria-label=\"the localised fault game permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The Localised Fault Game</h2>\n<p>Here is the property I thought I had, written as a game so it can be graded.</p>\n<p><strong>Setup</strong>: The challenger <strong>C</strong> fixes a population of pixels of size <strong>N</strong>, a sample size <strong>s</strong>, and a commitment scheme. It publishes the input commitment <strong>c</strong> and the tolerance <strong>τ</strong>.</p>\n<p><strong>Challenge</strong>: The adversary <strong>A</strong>, a probabilistic polynomial-time algorithm, chooses a region <strong>R</strong> with |<strong>R</strong>| = <strong>k</strong> and publishes a solution that satisfies the normal equations within <strong>τ</strong> everywhere outside <strong>R</strong> and violates them inside <strong>R</strong>.</p>\n<p><strong>Oracle</strong>: <strong>C</strong> derives the audit set <strong>I</strong> = <code class=\"language-text\">sample_indices(c, N, s)</code>, a uniform draw without replacement. <strong>A</strong> cannot influence <strong>I</strong>, because <strong>c</strong> was fixed before <strong>A</strong> saw it.</p>\n<p><strong>Win condition</strong>: <strong>A</strong> wins if <strong>I</strong> ∩ <strong>R</strong> = ∅.</p>\n<p>The advantage follows straight from the hypergeometric distribution.</p>\n<div class=\"dpw-formula\">Adv(<b>A</b>) &nbsp;=&nbsp; C(N &minus; k, s) / C(N, s) &nbsp;&asymp;&nbsp; (1 &minus; k/N)<sup>s</sup></div>\n<p>Now grade the protocol on the standard properties, the way you would grade any interactive proof.</p>\n<p><strong>Completeness</strong>: An honest prover publishes a solution whose residual is within <strong>τ</strong> at every pixel, so every draw of <strong>I</strong> accepts. The measured maximum over the real sample is 2.3173862534e-7, four orders of magnitude inside the line. <strong>Perfect.</strong></p>\n<p><strong>Soundness</strong>: This is where it breaks, and it breaks in a specific way. Soundness error should be negligible in the security parameter. Here it is negligible in <strong>k</strong>, and <strong>k</strong> belongs to the adversary. Fix <strong>s</strong> = 256 and <strong>N</strong> = 24,950,025. For <strong>k</strong>/<strong>N</strong> = 0.5 the advantage is 8.6e-78, which is lovely. For <strong>k</strong>/<strong>N</strong> = 0.001 the advantage is 0.774. The adversary chooses which of those two worlds to live in, so the protocol's soundness is whatever the adversary decides it should be. <strong>Fails against a localised adversary.</strong></p>\n<p><strong>Zero-knowledge</strong>: Not claimed by the certificate, and not needed. The inputs are NASA's and public, the output is published, and the whole point is that a buyer can recompute. The zkVM layer that came later adds succinctness, not secrecy.</p>\n<p>The verdict I care about is the middle one. A soundness error that the adversary parameterises is not a soundness error in the cryptographic sense. It's a coverage statistic wearing a cryptographic word.</p>\n<h2 id=\"where-the-advantage-actually-lives\" style=\"position:relative;\"><a href=\"#where-the-advantage-actually-lives\" aria-label=\"where the advantage actually lives permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Where the advantage actually lives</h2>\n<p>Slide across the fault size and watch what happens to the four sample sizes.</p>\n<div class=\"dpw\" id=\"adv\" data-initialised=\"false\">\n  <svg id=\"av-svg\" viewBox=\"0 0 480 280\" class=\"dpw-svg\" role=\"img\" aria-label=\"Adversary advantage against corrupted fraction, for four sample sizes\"></svg>\n  <div class=\"dpw-legend\">\n    <span class=\"dpw-key\"><i style=\"background:#a72e2b\"></i>s = 256 (shipped)</span>\n    <span class=\"dpw-key\"><i style=\"background:#8ba2b8\"></i>s = 1,024</span>\n    <span class=\"dpw-key\"><i style=\"background:#b9c8d6\"></i>s = 4,096</span>\n    <span class=\"dpw-key\"><i style=\"background:#d8e2ea\"></i>s = 16,384</span>\n  </div>\n  <div class=\"dpw-hint\">Hover the chart. The shaded band is where a deformation fault that matters to an insurer actually sits.</div>\n  <div class=\"dpw-readout\" id=\"av-read\">\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"av-f\">0.1%</span><span class=\"dpw-cap\">corrupted fraction</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"av-256\">77.4%</span><span class=\"dpw-cap\">evades s = 256</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"av-16k\">0.0%</span><span class=\"dpw-cap\">evades s = 16,384</span></div>\n  </div>\n</div>\n<p>The curves all have the same shape and the shape is the problem. Each one falls off a cliff, and the cliff sits at a fault size inversely proportional to <strong>s</strong>. Multiplying the sample by 64 divides the smallest visible fault by 63.9, which you can read straight off the chart by comparing where the first and last curves cross the halfway line. Coverage is bought linearly. To halve the fault you're willing to miss, you double the guest.</p>\n<p>The shaded band is not decoration. Chaotic Era's stated destination is a verification oracle for parametric insurance, where a payout keys on ground movement in one named place. A subsidence claim over a single industrial site, a glacier terminus, a stretch of embankment. Those are all four figures of pixels in a scene of twenty-five million. The certificate is strongest exactly where nobody is writing cheques and weakest exactly where they are.</p>\n<p>That is the opinion I'd defend in a room: for this application, uniform Fiat-Shamir sampling is the wrong primitive, and no amount of sample-size tuning fixes it.</p>\n<h2 id=\"the-proof-does-not-help-and-i-want-to-be-precise-about-why\" style=\"position:relative;\"><a href=\"#the-proof-does-not-help-and-i-want-to-be-precise-about-why\" aria-label=\"the proof does not help and i want to be precise about why permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The proof does not help, and I want to be precise about why</h2>\n<p>It's tempting to think the zkVM covers this. It does not, and the distinction is worth stating carefully because I got it wrong first.</p>\n<p>The RISC Zero guest re-executes the residual check and commits a journal binding the input commitment, the design matrix commitment, the output commitment, the index commitment, the sampled-columns digest, and the measured maximum residual. It ran in 8,388,608 cycles across 8 segments, and the Groth16 seal verifies on chain in 249,749 gas.</p>\n<p>What that proof establishes is that the check was performed honestly on the indices in <strong>I</strong>. It is a statement about the integrity of the auditor, not the coverage of the audit. If <strong>I</strong> never touches <strong>R</strong>, the guest happily proves that every pixel it was shown is fine, because every pixel it was shown is fine. The proof is true. The conclusion people will draw from it is not.</p>\n<p>There's a second gap in the same area that I should name rather than let a reader find. The guest checks that the sampled columns hash to the committed <code class=\"language-text\">samples_digest</code>, but it does not check that those columns were extracted from the published output array. That binding is done outside the circuit today, and it's written down as an honesty box in the repository rather than fixed. Merkle inclusion proofs are the fix and they are not built yet.</p>\n<h2 id=\"what-closing-the-gap-costs\" style=\"position:relative;\"><a href=\"#what-closing-the-gap-costs\" aria-label=\"what closing the gap costs permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What closing the gap costs</h2>\n<p>If you want to keep uniform sampling and just buy more of it, the sample size is set by the fault you refuse to miss.</p>\n<div class=\"dpw\" id=\"cost\" data-initialised=\"false\">\n  <div class=\"dpw-controls dpw-grid\">\n    <label class=\"dpw-label\">Smallest fault you refuse to miss\n      <input type=\"range\" id=\"ct-f\" min=\"0\" max=\"10\" step=\"1\" value=\"3\" />\n      <span class=\"dpw-val\" id=\"ct-f-val\">0.1%</span>\n    </label>\n    <div class=\"dpw-toggle-row\">\n      <span class=\"dpw-toggle-cap\">Detection confidence</span>\n      <button class=\"dpw-toggle\" id=\"ct-90\">90%</button>\n      <button class=\"dpw-toggle\" id=\"ct-99\" data-on=\"true\">99%</button>\n      <button class=\"dpw-toggle\" id=\"ct-999\">99.9%</button>\n    </div>\n  </div>\n  <div class=\"dpw-two\">\n    <div class=\"dpw-panel\">\n      <div class=\"dpw-panel-h\">what it takes</div>\n      <div class=\"dpw-line\">samples needed <b id=\"ct-s\">4,603</b></div>\n      <div class=\"dpw-line\">against the shipped 256 <b id=\"ct-mult\">18.0&times;</b></div>\n    </div>\n    <div class=\"dpw-panel\">\n      <div class=\"dpw-panel-h\">what it costs in the guest</div>\n      <div class=\"dpw-line\">cycles <b id=\"ct-cyc\">151 M</b> <span class=\"dpw-inflate\">upper bound</span></div>\n      <div class=\"dpw-line\">segments <b id=\"ct-seg\">144</b> <span class=\"dpw-inflate\">at 2<sup>20</sup> each</span></div>\n    </div>\n  </div>\n  <div class=\"dpw-hint\">Cycle figures scale the measured 8,388,608 for s = 256 linearly. That is an upper bound, since part of the trace is fixed cost that does not grow with the sample. I have not measured the split.</div>\n</div>\n<p>Catching a fault of one tenth of one percent with 99% confidence needs 4,603 samples, an eighteenfold increase, and the guest grows with it. That is affordable. Catching a fault of one hundredth of one percent at the same confidence needs 46,050 samples, and now you are proving a trace of roughly 1.5 billion cycles to audit 0.18% of a scene.</p>\n<p>The arithmetic says brute force runs out before the faults do. So the answer is not a bigger sample.</p>\n<p>The answer is to stop sampling uniformly. If the buyer cares about a named region, the certificate should commit to a Merkle tree over the output and prove residuals over an inclusion path into the region under contract, with the uniform sample kept as a cheap global sanity check. Then the soundness error stops being a function of the adversary's choice of <strong>k</strong> and starts being a function of the hash. That is the version I'd sell to an insurer, and it is not the version I have built.</p>\n<h2 id=\"the-rule-i-took-away\" style=\"position:relative;\"><a href=\"#the-rule-i-took-away\" aria-label=\"the rule i took away permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The rule I took away</h2>\n<p>The mistake was not statistical. I can compute a hypergeometric tail. The mistake was that I let a cryptographic word stand in for a security argument, and then proved the wrong half of the system very carefully.</p>\n<p>So before I call a sampling scheme sound now, I write down the adversary and let them pick their parameters. Not \"can the prover choose the sample\" but \"given that they cannot, what is the cheapest lie that survives it\". If the answer to the second question contains a variable the adversary controls, the guarantee is a coverage statistic, and it belongs in the documentation with its actual number next to it rather than behind the words \"Fiat-Shamir\".</p>\n<p>The 256 pixels are still in the certificate. They still catch a wholesale error, a swapped stack, a broken solver, a wrong design matrix, and they catch it with an advantage of 1e-78. That's worth keeping. It just isn't the claim I was making.</p>\n<style>\n.dpw {\n  --ink: #1b2228; --ink2: #5b7085; --line: #dae4ed;\n  --maroon: #a72e2b; --maroon-d: #6a1d1b; --rose: #f2cdcc; --green: #3f8f5b;\n  border: 1px solid var(--line); border-radius: 6px; padding: 20px;\n  margin: 32px 0; background: #fff; font-family: 'Open Sans', sans-serif;\n}\n.dpw * { box-sizing: border-box; }\n.dpw-formula { text-align: center; font-family: 'Inconsolata', monospace; font-size: 19px;\n  color: #1b2228; margin: 22px 0; letter-spacing: .01em; }\n.dpw-formula sup { font-size: 12px; }\n.dpw-controls { margin-bottom: 14px; }\n.dpw-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 24px; }\n.dpw-label { display: block; font-size: 13px; color: var(--ink2); }\n.dpw-label input[type=range] { display: block; width: 100%; margin: 8px 0 0; accent-color: var(--maroon); }\n.dpw-val { color: var(--maroon-d); font-family: 'Inconsolata', monospace; font-weight: 700; }\n.dpw-hint { font-size: 12px; color: var(--ink2); margin-top: 8px; font-style: italic; }\n.dpw-svg { width: 100%; height: auto; display: block; margin: 6px 0 4px;\n  background: linear-gradient(180deg, #fbfcfe, #f4f7fa); border-radius: 4px; }\n.dpw-btnrow { display: flex; gap: 8px; margin: 12px 0 10px; flex-wrap: wrap; }\n.dpw-btn { font-family: 'Inconsolata', monospace; font-size: 13px; border: 1px solid var(--maroon);\n  background: var(--maroon); color: #fff; padding: 7px 14px; border-radius: 4px; cursor: pointer; transition: opacity .15s; }\n.dpw-btn:hover { opacity: .85; }\n.dpw-btn-ghost { background: #fff; color: var(--ink2); border-color: var(--line); }\n.dpw-verdict { margin: 4px 0 12px; padding: 8px 12px; border-radius: 4px; font-size: 13px; font-weight: 700;\n  background: var(--rose); color: var(--maroon-d); text-align: center; font-family: 'Inconsolata', monospace; }\n.dpw-verdict.dpw-ok { background: #dcefe3; color: var(--green); }\n.dpw-readout { display: flex; gap: 24px; margin-top: 10px; flex-wrap: wrap; }\n.dpw-stat { display: flex; flex-direction: column; }\n.dpw-num { font-family: 'Josefin Sans', sans-serif; font-size: 24px; color: var(--maroon-d); line-height: 1.1; }\n.dpw-cap { font-size: 11px; color: var(--ink2); text-transform: uppercase; letter-spacing: .04em; }\n.dpw-cap sup { text-transform: none; }\n.dpw-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 6px; }\n.dpw-key { font-size: 12px; color: var(--ink2); display: flex; align-items: center; gap: 6px; }\n.dpw-key i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }\n.dpw-toggle-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }\n.dpw-toggle-cap { width: 100%; margin-bottom: 2px; font-size: 12px; color: var(--ink2); }\n.dpw-toggle { font-family: 'Inconsolata', monospace; font-size: 12px; border: 1px solid var(--line);\n  background: #fff; color: var(--ink2); padding: 5px 9px; border-radius: 4px; cursor: pointer; transition: all .15s; }\n.dpw-toggle[data-on=true] { background: var(--maroon); color: #fff; border-color: var(--maroon); }\n.dpw-two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 6px; }\n.dpw-panel { border: 1px solid var(--line); border-radius: 5px; padding: 14px; }\n.dpw-panel-h { font-family: 'Josefin Sans', sans-serif; font-size: 13px; text-transform: uppercase;\n  letter-spacing: .04em; color: var(--ink2); margin-bottom: 10px; }\n.dpw-line { font-size: 14px; color: var(--ink2); margin: 6px 0; }\n.dpw-line b { font-family: 'Inconsolata', monospace; font-size: 17px; color: var(--ink); }\n.dpw-inflate { font-size: 11px; color: #94a6b8; }\n@media (max-width: 480px) { .dpw-grid, .dpw-two { grid-template-columns: 1fr; } .dpw-readout { gap: 16px; } }\n@media (prefers-reduced-motion: reduce) { .dpw * { transition: none !important; } }\n</style>\n<script>\n(function () {\n  var root = document.getElementById('miss');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var SVG = 'http://www.w3.org/2000/svg';\n  var svg = root.querySelector('#ms-svg');\n  var W = 480, H = 240, S = 256;\n  var N_PIX = 24950025;                       // real population, frame 141/54\n  var FS = [0.0001, 0.0002, 0.0005, 0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2];\n\n  var seed = 20260824;\n  function rnd() { seed = (seed * 1103515245 + 12345) & 0x7fffffff; return seed / 0x7fffffff; }\n\n  var tally = { caught: 0, total: 0 };\n  var lastHit = false, dots = [], fault = null;\n\n  function faultRect(f) {\n    var area = f * W * H;\n    var w = Math.min(W, Math.sqrt(area * 1.7));\n    var h = area / w;\n    return { x: 150 - w / 2, y: 118 - h / 2, w: w, h: h };\n  }\n  function fmtPct(v) {\n    if (v >= 0.1) return (v * 100).toFixed(1) + '%';\n    if (v >= 0.01) return (v * 100).toFixed(2) + '%';\n    return (v * 100).toFixed(3) + '%';\n  }\n\n  // deterministic speckle backdrop so the panel reads as a radar scene\n  var speck = [];\n  (function () { var s2 = 99; function r2() { s2 = (s2 * 1103515245 + 12345) & 0x7fffffff; return s2 / 0x7fffffff; }\n    for (var i = 0; i < 260; i++) speck.push({ x: r2() * W, y: r2() * H, o: 0.04 + r2() * 0.06 }); })();\n\n  function audit() {\n    var f = FS[parseInt(root.querySelector('#ms-f').value, 10)];\n    fault = faultRect(f);\n    dots = []; var hit = false;\n    for (var i = 0; i < S; i++) {\n      var p = { x: rnd() * W, y: rnd() * H };\n      p.hit = p.x >= fault.x && p.x <= fault.x + fault.w && p.y >= fault.y && p.y <= fault.y + fault.h;\n      if (p.hit) hit = true;\n      dots.push(p);\n    }\n    lastHit = hit;\n    tally.total++; if (hit) tally.caught++;\n    return hit;\n  }\n\n  function draw() {\n    var f = FS[parseInt(root.querySelector('#ms-f').value, 10)];\n    if (!fault) fault = faultRect(f);\n    while (svg.firstChild) svg.removeChild(svg.firstChild);\n\n    speck.forEach(function (s) {\n      var c = document.createElementNS(SVG, 'circle');\n      c.setAttribute('cx', s.x); c.setAttribute('cy', s.y); c.setAttribute('r', 1.4);\n      c.setAttribute('fill', '#5b7085'); c.setAttribute('opacity', s.o);\n      svg.appendChild(c);\n    });\n    var fr = document.createElementNS(SVG, 'rect');\n    fr.setAttribute('x', fault.x); fr.setAttribute('y', fault.y);\n    fr.setAttribute('width', Math.max(fault.w, 1.2)); fr.setAttribute('height', Math.max(fault.h, 1.2));\n    fr.setAttribute('fill', '#6a1d1b'); fr.setAttribute('opacity', '0.82');\n    fr.setAttribute('stroke', '#a72e2b'); fr.setAttribute('stroke-width', '1');\n    svg.appendChild(fr);\n\n    dots.forEach(function (p) {\n      var c = document.createElementNS(SVG, 'circle');\n      c.setAttribute('cx', p.x); c.setAttribute('cy', p.y);\n      c.setAttribute('r', p.hit ? 4 : 1.7);\n      c.setAttribute('fill', p.hit ? '#a72e2b' : '#8ba2b8');\n      if (p.hit) { c.setAttribute('stroke', '#fff'); c.setAttribute('stroke-width', '1.5'); }\n      svg.appendChild(c);\n    });\n  }\n\n  function readout() {\n    var f = FS[parseInt(root.querySelector('#ms-f').value, 10)];\n    root.querySelector('#ms-f-val').textContent = fmtPct(f);\n    root.querySelector('#ms-px').textContent =\n      Math.round(f * N_PIX).toLocaleString() + ' pixels of 24,950,025 are wrong. The auditor looks at 256 of them.';\n    var theory = 1 - Math.pow(1 - f, S);\n    root.querySelector('#ms-theory').textContent = (theory * 100).toFixed(1) + '%';\n    root.querySelector('#ms-caught').textContent = tally.caught.toLocaleString();\n    root.querySelector('#ms-total').textContent = tally.total.toLocaleString();\n    root.querySelector('#ms-emp').textContent =\n      tally.total ? (100 * tally.caught / tally.total).toFixed(1) + '%' : 'n/a';\n    var v = root.querySelector('#ms-verdict');\n    if (!tally.total) { v.textContent = 'no audit run yet'; v.className = 'dpw-verdict'; }\n    else if (lastHit) { v.textContent = 'caught: a sampled pixel landed inside the fault'; v.className = 'dpw-verdict dpw-ok'; }\n    else { v.textContent = 'the fault survived this audit'; v.className = 'dpw-verdict'; }\n  }\n\n  on(root.querySelector('#ms-f'), 'input', function () {\n    tally = { caught: 0, total: 0 }; dots = []; lastHit = false;\n    fault = faultRect(FS[parseInt(root.querySelector('#ms-f').value, 10)]);\n    draw(); readout();\n  });\n  on(root.querySelector('#ms-once'), 'click', function () { audit(); draw(); readout(); });\n  on(root.querySelector('#ms-many'), 'click', function () {\n    for (var i = 0; i < 200; i++) audit();\n    draw(); readout();\n  });\n  on(root.querySelector('#ms-reset'), 'click', function () {\n    tally = { caught: 0, total: 0 }; dots = []; lastHit = false; draw(); readout();\n  });\n  draw(); readout();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('adv');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var SVG = 'http://www.w3.org/2000/svg';\n  var svg = root.querySelector('#av-svg');\n  var W = 480, H = 280, P = { l: 46, r: 14, t: 16, b: 40 };\n  var SS = [{ s: 256, c: '#a72e2b', w: 2.4 }, { s: 1024, c: '#8ba2b8', w: 1.6 },\n            { s: 4096, c: '#b9c8d6', w: 1.6 }, { s: 16384, c: '#d8e2ea', w: 1.6 }];\n  var LO = -6, HI = 0;                          // log10 of corrupted fraction\n\n  function X(lf) { return P.l + (lf - LO) / (HI - LO) * (W - P.l - P.r); }\n  function Y(a) { return P.t + (1 - a) * (H - P.t - P.b); }\n  function el(n, at) { var e = document.createElementNS(SVG, n); for (var k in at) e.setAttribute(k, at[k]); return e; }\n  function fmtPct(v) { return v >= 0.1 ? (v * 100).toFixed(1) + '%' : v >= 0.001 ? (v * 100).toFixed(2) + '%' : (v * 100).toFixed(3) + '%'; }\n\n  var hoverLf = -3;\n\n  function draw() {\n    while (svg.firstChild) svg.removeChild(svg.firstChild);\n\n    // insurance-relevant band: 1e-4 .. 1e-2 of the scene\n    svg.appendChild(el('rect', { x: X(-4), y: P.t, width: X(-2) - X(-4), height: H - P.t - P.b,\n      fill: '#f2cdcc', opacity: '0.35' }));\n\n    // grid + axes\n    for (var g = LO; g <= HI; g++) {\n      svg.appendChild(el('line', { x1: X(g), y1: P.t, x2: X(g), y2: H - P.b, stroke: '#dae4ed', 'stroke-width': 1 }));\n      var lab = g === 0 ? '100%' : g === -2 ? '1%' : '1e' + g;\n      svg.appendChild(el('text', { x: X(g), y: H - P.b + 15, 'text-anchor': 'middle',\n        'font-size': 10, fill: '#5b7085', 'font-family': 'Inconsolata, monospace' })).textContent = lab;\n    }\n    [0, 0.25, 0.5, 0.75, 1].forEach(function (a) {\n      svg.appendChild(el('line', { x1: P.l, y1: Y(a), x2: W - P.r, y2: Y(a), stroke: '#dae4ed', 'stroke-width': 1 }));\n      svg.appendChild(el('text', { x: P.l - 6, y: Y(a) + 3, 'text-anchor': 'end',\n        'font-size': 10, fill: '#5b7085', 'font-family': 'Inconsolata, monospace' })).textContent = (a * 100) + '%';\n    });\n    svg.appendChild(el('text', { x: (W + P.l) / 2, y: H - 6, 'text-anchor': 'middle',\n      'font-size': 11, fill: '#5b7085' })).textContent = 'fraction of the scene corrupted (k / N)';\n\n    // curves, drawn faintest first\n    for (var i = SS.length - 1; i >= 0; i--) {\n      var d = '', s = SS[i].s;\n      for (var px = 0; px <= 240; px++) {\n        var lf = LO + (HI - LO) * px / 240;\n        var adv = Math.pow(1 - Math.pow(10, lf), s);\n        d += (px ? 'L' : 'M') + X(lf).toFixed(2) + ' ' + Y(adv).toFixed(2);\n      }\n      svg.appendChild(el('path', { d: d, fill: 'none', stroke: SS[i].c, 'stroke-width': SS[i].w }));\n    }\n\n    // hover marker on the shipped curve\n    var f = Math.pow(10, hoverLf);\n    svg.appendChild(el('line', { x1: X(hoverLf), y1: P.t, x2: X(hoverLf), y2: H - P.b,\n      stroke: '#6a1d1b', 'stroke-width': 1, 'stroke-dasharray': '3 3' }));\n    SS.forEach(function (c) {\n      svg.appendChild(el('circle', { cx: X(hoverLf), cy: Y(Math.pow(1 - f, c.s)), r: c.s === 256 ? 4.5 : 3,\n        fill: c.c, stroke: '#fff', 'stroke-width': 1.2 }));\n    });\n\n    root.querySelector('#av-f').textContent = fmtPct(f);\n    root.querySelector('#av-256').textContent = (100 * Math.pow(1 - f, 256)).toFixed(1) + '%';\n    root.querySelector('#av-16k').textContent = (100 * Math.pow(1 - f, 16384)).toFixed(1) + '%';\n  }\n\n  function move(ev) {\n    var r = svg.getBoundingClientRect();\n    var cx = (ev.touches ? ev.touches[0].clientX : ev.clientX) - r.left;\n    var lf = LO + (cx / r.width * W - P.l) / (W - P.l - P.r) * (HI - LO);\n    hoverLf = Math.max(LO, Math.min(HI, lf));\n    draw();\n  }\n  on(svg, 'mousemove', move);\n  on(svg, 'touchmove', function (e) { move(e); e.preventDefault(); });\n  draw();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('cost');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var FS = [0.0001, 0.0002, 0.0005, 0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2];\n  var MEASURED_CYCLES = 8388608, MEASURED_S = 256, SEG = 1048576;   // 2^20\n  var conf = 0.99;\n\n  function fmtPct(v) { return v >= 0.1 ? (v * 100).toFixed(1) + '%' : v >= 0.01 ? (v * 100).toFixed(2) + '%' : (v * 100).toFixed(3) + '%'; }\n  function fmtCyc(c) {\n    if (c >= 1e9) return (c / 1e9).toFixed(2) + ' B';\n    if (c >= 1e6) return (c / 1e6).toFixed(0) + ' M';\n    return c.toLocaleString();\n  }\n  function render() {\n    var f = FS[parseInt(root.querySelector('#ct-f').value, 10)];\n    root.querySelector('#ct-f-val').textContent = fmtPct(f);\n    var s = Math.ceil(Math.log(1 - conf) / Math.log(1 - f));\n    var cyc = MEASURED_CYCLES * (s / MEASURED_S);\n    root.querySelector('#ct-s').textContent = s.toLocaleString();\n    root.querySelector('#ct-mult').innerHTML = (s / MEASURED_S).toFixed(1) + '&times;';\n    root.querySelector('#ct-cyc').textContent = fmtCyc(cyc);\n    root.querySelector('#ct-seg').textContent = Math.ceil(cyc / SEG).toLocaleString();\n    [['#ct-90', 0.9], ['#ct-99', 0.99], ['#ct-999', 0.999]].forEach(function (p) {\n      root.querySelector(p[0]).setAttribute('data-on', conf === p[1]);\n    });\n  }\n  on(root.querySelector('#ct-f'), 'input', render);\n  [['#ct-90', 0.9], ['#ct-99', 0.99], ['#ct-999', 0.999]].forEach(function (p) {\n    on(root.querySelector(p[0]), 'click', function () { conf = p[1]; render(); });\n  });\n  render();\n})();\n</script>","headings":[{"value":"The asymmetry is real, and it is the whole product","depth":2},{"value":"The sample the prover cannot rig","depth":2},{"value":"Watch it miss","depth":2},{"value":"The Localised Fault Game","depth":2},{"value":"Where the advantage actually lives","depth":2},{"value":"The proof does not help, and I want to be precise about why","depth":2},{"value":"What closing the gap costs","depth":2},{"value":"The rule I took away","depth":2}],"frontmatter":{"date_created":"2026-08-24","path":"/blog/fiat-shamir-coverage-gap","tags":["Zero Knowledge Proofs","Verifiable Computation","Formal Verification"],"title":"Your Spot Check Cannot See the Fault You Are Paid to Catch"}},"currPost":{"html":"<p>Last week, we left off talking about this thing called the discrete log problem, DLP.</p>\n<div class=\"dpw-formula\">f(x) = g<sup>x</sup> mod p</div>\n<p>p is a large prime, and g is a number that comes from our Z<sub>p</sub><sup>∗</sup> group.</p>\n<h2 id=\"the-group-we-are-working-in\" style=\"position:relative;\"><a href=\"#the-group-we-are-working-in\" aria-label=\"the group we are working in permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The group we are working in</h2>\n<p>Z<sub>p</sub><sup>∗</sup> is a set. It goes from one all the way up to p − 1. If I say something like Z<sub>7</sub><sup>∗</sup>, it's going to be 1, 2, 3, 4, 5, 6. Instead of us calling it Z<sub>p</sub><sup>∗</sup> every time, we're going to call this a multiplicative group, because that's what it is.</p>\n<p>We can't just call any set a group. For a set to be a group, it needs to satisfy four conditions.</p>\n<ol>\n<li>The first is closure, which means if we choose two elements in the group, a · b is also in Z<sub>p</sub><sup>∗</sup>. For example, 2 · 6 = 12, and now if we mod this by 7, 12 mod 7 is 5. You can also verify that 5 is in Z<sub>7</sub><sup>∗</sup>.</li>\n<li>The second is associativity. If we choose a, b and c in Z<sub>p</sub><sup>∗</sup>, it should follow the associative property: (a · b) · c = a · (b · c).</li>\n<li>The third property that a group has to have is the identity element, which pretty much means that if we choose any integer a in Z<sub>p</sub><sup>∗</sup>, a · e and e · a should both equal a, where e is the identity element. In the case of Z<sub>p</sub><sup>∗</sup>, the identity element is 1, because a · 1 = 1 · a = a. If we multiply it by 0, we would not get a. So 0 is not the identity element of Z<sub>p</sub><sup>∗</sup>. It's only 1.</li>\n<li>The fourth thing is the inverse element. If we choose a in Z<sub>p</sub><sup>∗</sup>, there should be an inverse in Z<sub>p</sub><sup>∗</sup> such that a · a<sup>−1</sup> = a<sup>−1</sup> · a = 1, the identity element. Suppose a = 2. What can we multiply 2 with to get 1 mod 7? 2 · 2 = 4. 2 · 3 = 6. 2 · 4 = 8, and 8 mod 7 is 1. So the inverse of 2 is 4.</li>\n</ol>\n<p>These four properties must be true for each integer in Z<sub>p</sub><sup>∗</sup>, and that's what we call a group. Basically, what it's saying is we can do multiplication in the set without things breaking.</p>\n<h2 id=\"the-generator\" style=\"position:relative;\"><a href=\"#the-generator\" aria-label=\"the generator permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The generator</h2>\n<p>We can call a group cyclic if there exists a generator g in that group. It's not exactly a random number. It's a special number, where if we raise it to the powers 1 up to p − 1, we get the set back. The value you will get is all the elements in the original Z<sub>p</sub><sup>∗</sup>. This is all mod p.</p>\n<p>In Z<sub>p</sub><sup>∗</sup>, we already know, through proofs that have already been proven, that there is at least one generator that generates the entire group.</p>\n<p>For Z<sub>7</sub><sup>∗</sup>, the generator is three. Let's see what happens when we multiply this generator by itself p − 1 times: g<sup>1</sup>, g<sup>2</sup>, g<sup>3</sup>, g<sup>4</sup>, g<sup>5</sup> and g<sup>6</sup>. We have to do all of these multiplications mod p.</p>\n<div class=\"dpw-formula\">3<sup>1</sup> = 3 &nbsp;&nbsp; 3<sup>2</sup> = 9 &equiv; 2 &nbsp;&nbsp; 3<sup>3</sup> = 27 &equiv; 6 &nbsp;&nbsp; 3<sup>4</sup> &equiv; 4 &nbsp;&nbsp; 3<sup>5</sup> &equiv; 5 &nbsp;&nbsp; 3<sup>6</sup> &equiv; 1 &nbsp;&nbsp; (mod 7)</div>\n<p>What we notice now is that we have one, two, three, four, five, and six. All the elements appear only once. So there are no duplicates. There are no collisions, in other words.</p>\n<p>Someone asked how I knew the generator is three. To be honest, I'm not sure. I think for small numbers, it's easy. But for large numbers, I'm not sure how the generator is picked. My guess is there's some trial and error algorithm, or there's a math proof where you could do it very quickly.</p>\n<p>While you were talking, I just tried g = 2, and we already found a duplicate. 2<sup>1</sup> = 2, and 2<sup>2</sup> = 4. Then 2<sup>3</sup> = 8, and 8 mod 7 is 1. And 2<sup>4</sup> = 16, and 16 mod 7 is 2, which we have already seen. So this is not a generator. I should also specify: generate the entire group once.</p>\n<p>So which numbers generate the whole group, and how many of them are there? Pick a prime, then a base.</p>\n<div class=\"dpw\" id=\"cc4-gen\">\n  <div class=\"dpw-toggle-row\">\n    <span class=\"dpw-toggle-cap\">Prime p</span>\n    <button class=\"dpw-toggle\" data-p=\"7\" data-on=\"true\">7</button>\n    <button class=\"dpw-toggle\" data-p=\"11\" data-on=\"false\">11</button>\n    <button class=\"dpw-toggle\" data-p=\"13\" data-on=\"false\">13</button>\n    <button class=\"dpw-toggle\" data-p=\"17\" data-on=\"false\">17</button>\n    <button class=\"dpw-toggle\" data-p=\"23\" data-on=\"false\">23</button>\n  </div>\n  <div class=\"dpw-toggle-row\" id=\"cc4-bases\">\n    <span class=\"dpw-toggle-cap\">Base g <span class=\"dpw-inflate\">(filled chips are generators)</span></span>\n  </div>\n  <div class=\"dpw-toggle-cap\" id=\"cc4-powcap\">&ndash;</div>\n  <div class=\"cc4-cells\" id=\"cc4-cells\"></div>\n  <div class=\"dpw-readout\">\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc4-hit\">&ndash;</span><span class=\"dpw-cap\">elements reached</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc4-rep\">&ndash;</span><span class=\"dpw-cap\">powers before it repeats</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc4-count\">&ndash;</span><span class=\"dpw-cap\">generators in this group</span></div>\n  </div>\n  <div class=\"dpw-verdict\" id=\"cc4-gv\">&ndash;</div>\n  <div class=\"dpw-hint\">Each cell is g<sup>k</sup> mod p for k = 1 up to p &minus; 1. Once a power comes back to 1 the list starts over, so everything after that is a duplicate and is shown faded.</div>\n</div>\n<p>For p = 7 only 3 and 5 generate the group. The guess in the session is how it is done in practice: you try candidates, and the test is cheap, because g is a generator exactly when g<sup>(p−1)/q</sup> is not 1 for every prime q that divides p − 1.</p>\n<p>Everyone is using a fixed generator when wallet addresses are being generated. As far as I know, there's a specific number that everyone uses as a generator. If you were to change that number, then you could have one private key mapped to two public keys, or something like that. So that's why the generator is a fixed, global and public variable. Everyone knows this, even attackers.</p>\n<h2 id=\"the-hard-direction\" style=\"position:relative;\"><a href=\"#the-hard-direction\" aria-label=\"the hard direction permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The hard direction</h2>\n<p>We said that doing this calculation, g<sup>x</sup> mod p, is very easy. What is hard is when you're given f(x), which is the answer to this, and you're given the generator, which is also public, and you're given the prime value, finding the x.</p>\n<div class=\"dpw-formula\">given y, g, p: &nbsp; find x such that &nbsp; y &equiv; g<sup>x</sup> (mod p)</div>\n<p>By the way, I'm using three lines here. That's just a way of showing it's congruent. 27 was the same as 6 mod 7.</p>\n<p>Go back to the simple example. Given this number 4, and also g = 3 and p = 7, finding x is hard. As the person who calculated this equation, I know x is four. But what the attacker sees is not that top part of the screen. They're only given this.</p>\n<p>Obviously, for small groups like this, you could just brute force it. You could just run this function seven times, and you will find it. But where p values are very large, it is very hard to find that x, and that is actually what's called the discrete log problem. This is why we also call this a one-way function, or a candidate one-way function, because we assume that it's secure.</p>\n<div class=\"dpw-formula\">DLP assumption: no PPT algorithm computes x = log<sub>g</sub> y (mod p) with non-negligible probability</div>\n<p>People have tried to disprove it. People have tried to create algorithms to break it, to find that x. But the closest people have come is sub-exponential. You can bypass this type of attack by increasing your security parameter.</p>\n<p>Bitcoin is not using this equation. Some of it has to do with the fact that people can break it in sub-exponential time. To bypass, you increase key size, and that increase leads to more storage costs. Things are just now larger for no reason.</p>\n<h2 id=\"the-easy-direction\" style=\"position:relative;\"><a href=\"#the-easy-direction\" aria-label=\"the easy direction permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The easy direction</h2>\n<p>Was anyone able to figure out why this calculation is easy? It doesn't matter what p is. Imagine p is 256 bits, 512 bits, 1024 bits, whatever. By the way, x is your private key here, your secret key, because the attacker is trying to guess this x.</p>\n<p>Someone suggested building it up one step at a time: g<sup>2</sup> is g · g, g<sup>3</sup> is g<sup>2</sup> · g, and so on. You're getting the point, but there are still some things we can optimize. The question I'll ask is, why do we even care about g<sup>3</sup>? If we've already calculated g<sup>2</sup>, why not just skip to g<sup>4</sup>, which is g<sup>2</sup> · g<sup>2</sup>? That saves us one multiplication. So I do g<sup>2</sup>, then I calculate g<sup>4</sup>, then g<sup>8</sup>, then g<sup>16</sup>.</p>\n<p>We don't need to take every single step. We can just start hopping, in a way. It's much easier if I just square this, because I'm moving closer to my number this way, if I do repeated squaring, versus if I only add 1 each time. It's called exponentiation by squaring.</p>\n<p>If we have, say, x = 5, what we should do first is convert this to the binary representation. 2<sup>0</sup>, 2<sup>1</sup>, 2<sup>2</sup>: that's 1, 2, 4. 4 + 1 = 5, so it's going to be 1, 0, 1. That's the binary representation of 5. We know that this number is something we need, and this number is something we need. We do not need this one. This is not part of the active bits, we could say.</p>\n<p>Let's just take p = 7. 3<sup>1</sup> = 3 mod 7. For the next value, we square this: 3<sup>2</sup> = 9, which is 2 mod 7. For 3<sup>4</sup>, we just have to square that again, because we know that the last value is 3<sup>2</sup>. So we just have to do 2<sup>2</sup>, which is equal to 4 mod 7.</p>\n<p>So now we have these values: 3, 2, and 4. If I take my bit representation of the secret value, 1, 0, 1, I know that this is an active bit, so we take this 3. This is an inactive bit, so it's 0. And this is an active bit, so we take the 4. Now we have to multiply these, 4 · 3 only. We're not taking the 0.</p>\n<div class=\"dpw-formula\">3<sup>5</sup> &equiv; 4 &times; 3 = 12 &equiv; 5 (mod 7)</div>\n<p>That is the answer for g<sup>5</sup> mod 7, instead of doing 3 · 3 · 3 · 3 · 3. That's 243, I calculated it, which is 238 with a remainder of 5. So if you check it, it's the same answer.</p>\n<p>Someone asked what the active bits mean. If you change this to 1, then what are you actually doing? 5 in binary is 1, 0, 1, but if you take this as an active bit too, this becomes 4 + 2 + 1, which is 7. So then you're actually finding it for x = 7.</p>\n<p>Here is the same board for any exponent. Which squares get multiplied in, and how many multiplications does it take compared with multiplying g by itself x times?</p>\n<div class=\"dpw\" id=\"cc4-sqm\">\n  <div class=\"dpw-toggle-row\">\n    <span class=\"dpw-toggle-cap\">Prime p &nbsp;<span class=\"dpw-inflate\">(g is 3)</span></span>\n    <button class=\"dpw-toggle\" data-p=\"7\" data-on=\"true\">7</button>\n    <button class=\"dpw-toggle\" data-p=\"23\" data-on=\"false\">23</button>\n    <button class=\"dpw-toggle\" data-p=\"101\" data-on=\"false\">101</button>\n  </div>\n  <div class=\"dpw-controls\">\n    <label class=\"dpw-label\">Exponent x &nbsp; <span class=\"dpw-val\" id=\"cc4-x\">5</span> &nbsp;=&nbsp; <span class=\"dpw-val\" id=\"cc4-bin\">101</span> in binary\n      <input type=\"range\" id=\"cc4-xr\" min=\"1\" max=\"255\" step=\"1\" value=\"5\" />\n    </label>\n  </div>\n  <div class=\"cc4-table\" id=\"cc4-table\"></div>\n  <div class=\"dpw-formula\" id=\"cc4-prod\">&ndash;</div>\n  <div class=\"dpw-readout\">\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc4-fast\">&ndash;</span><span class=\"dpw-cap\">multiplications, by squaring</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc4-naive\">&ndash;</span><span class=\"dpw-cap\">multiplications, one at a time</span></div>\n  </div>\n  <div class=\"dpw-verdict dpw-ok\" id=\"cc4-check\">&ndash;</div>\n  <div class=\"dpw-hint\">Each row squares the row above it. Rows whose bit is 1 are multiplied into the answer. The count by squaring is one multiplication per row after the first, plus one for each extra active bit. The check at the bottom recomputes the answer the slow way.</div>\n</div>\n<h2 id=\"how-much-work-is-that\" style=\"position:relative;\"><a href=\"#how-much-work-is-that\" aria-label=\"how much work is that permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How much work is that?</h2>\n<p>Multiplying one at a time first. The time complexity of this is easy to guess: 2<sup>n</sup>, where n is the number of bits in x. As the value of our input increases, the number of computations we have to do increases exponentially.</p>\n<p>Now repeated squaring. In the worst case, if we think of the value 1, 1, 1, everything is active. So this is n, and then you would have to multiply each active bit, so that would be another n, which adds up to 2n, which, if you drop the constant, is n.</p>\n<p>This is also something I learned later on. If we convert a number into its binary representation, we can convert a calculation like this from an exponential time complexity algorithm to a linear complexity algorithm, just by converting it to binary and then doing that repeated squaring.</p>\n<p>What does that difference look like at the size of a real key? Slide the number of bits in x.</p>\n<div class=\"dpw\" id=\"cc4-scale\">\n  <div class=\"dpw-controls\">\n    <label class=\"dpw-label\">Bits in x, n &nbsp; <span class=\"dpw-val\" id=\"cc4-n\">256</span>\n      <input type=\"range\" id=\"cc4-nr\" min=\"2\" max=\"256\" step=\"1\" value=\"256\" />\n    </label>\n  </div>\n  <div class=\"cc4-bars\">\n    <div class=\"cc4-bar-row\"><span class=\"cc4-bar-cap\">one at a time</span><span class=\"cc4-bar-track\"><i id=\"cc4-b1\" class=\"cc4-bar cc4-bar-bad\"></i></span></div>\n    <div class=\"cc4-bar-row\"><span class=\"cc4-bar-cap\">by squaring</span><span class=\"cc4-bar-track\"><i id=\"cc4-b2\" class=\"cc4-bar\"></i></span></div>\n  </div>\n  <div class=\"dpw-readout\">\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc4-sn\">&ndash;</span><span class=\"dpw-cap\">multiplications, one at a time</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc4-sf\">&ndash;</span><span class=\"dpw-cap\">multiplications, by squaring</span></div>\n  </div>\n  <div class=\"dpw-verdict dpw-ok\" id=\"cc4-sv\">&ndash;</div>\n  <div class=\"dpw-hint\">Worst case for an n-bit exponent with every bit active: 2<sup>n</sup> &minus; 2 multiplications one at a time, against 2n &minus; 2 by squaring. The bars are on a log scale, so each step to the right is a doubling.</div>\n</div>\n<p>Someone pointed out that since g is fixed, the table of squares could be computed once and stored. Yeah, of course. And then that would just be even easier. The whole point is that this should be an easy equation to compute. If you store these values somewhere, it just becomes easier, and now you have more space complexity. That's the trade-off.</p>\n<p>This is very fast anyway. It doesn't grow exponentially with the size of the input. That's the main point. But this DLP assumption is saying that reversing that whole thing is extremely hard.</p>\n<h2 id=\"where-this-goes-next\" style=\"position:relative;\"><a href=\"#where-this-goes-next\" aria-label=\"where this goes next permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Where this goes next</h2>\n<p>What Bitcoin uses is the elliptic curve discrete log problem. Bitcoin has its own equation, and they have a generator as well, a generator G, which is a point on this curve. The public key and secret key, at least the raw parts, are derived from this curve using a generator, which is well known. It's a public parameter. We'll talk about this next week.</p>\n<style>\n.dpw {\n  --ink: #1b2228; --ink2: #5b7085; --line: #dae4ed;\n  --maroon: #a72e2b; --maroon-d: #6a1d1b; --rose: #f2cdcc; --green: #3f8f5b; --slate: #8ba2b8;\n  border: 1px solid var(--line); border-radius: 6px; padding: 20px;\n  margin: 32px 0; background: #fff; font-family: 'Open Sans', sans-serif;\n}\n.dpw * { box-sizing: border-box; }\n/* index.scss sets font on every span directly; let class-less spans inherit from the widget instead */\n.dpw span:not([class]) { font-size: inherit; line-height: inherit; font-family: inherit; }\n.dpw-formula { text-align: center; font-family: 'Inconsolata', monospace; font-size: 17px;\n  color: #1b2228; margin: 22px 0; letter-spacing: .01em; line-height: 1.6; overflow-x: auto; }\n.dpw-formula sup, .dpw-formula sub { font-size: 11px; }\n.dpw-controls { margin-bottom: 14px; }\n.dpw-label { display: block; font-size: 13px; color: var(--ink2); }\n.dpw-label input[type=range] { display: block; width: 100%; margin: 8px 0 0; accent-color: var(--maroon); }\n.dpw-val { color: var(--maroon-d); font-family: 'Inconsolata', monospace; font-weight: 700; }\n.dpw-hint { font-size: 12px; color: var(--ink2); margin-top: 10px; font-style: italic; line-height: 1.55; }\n.dpw-verdict { margin: 10px 0 4px; padding: 8px 12px; border-radius: 4px; font-size: 13px; font-weight: 700;\n  background: var(--rose); color: var(--maroon-d); text-align: center; font-family: 'Inconsolata', monospace; }\n.dpw-verdict.dpw-ok { background: #dcefe3; color: var(--green); }\n.dpw-readout { display: flex; gap: 24px; margin-top: 12px; flex-wrap: wrap; }\n.dpw-stat { display: flex; flex-direction: column; }\n.dpw-num { font-family: 'Josefin Sans', sans-serif; font-size: 23px; color: var(--maroon-d); line-height: 1.15; }\n.dpw-cap { font-size: 11px; color: var(--ink2); text-transform: uppercase; letter-spacing: .04em; }\n.dpw-toggle-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }\n.dpw-toggle-cap { width: 100%; margin-bottom: 3px; font-size: 12px; color: var(--ink2); }\n.dpw-toggle { font-family: 'Inconsolata', monospace; font-size: 12px; border: 1px solid var(--line);\n  background: #fff; color: var(--ink2); padding: 5px 9px; border-radius: 4px; cursor: pointer; transition: all .15s; }\n.dpw-toggle[data-on=true] { background: var(--maroon); color: #fff; border-color: var(--maroon); }\n.dpw-inflate { font-size: 11px; color: #94a6b8; }\n.cc4-chip { font-family: 'Inconsolata', monospace; font-size: 12px; min-width: 30px; text-align: center;\n  border: 1px solid var(--line); background: #fff; color: var(--ink2); padding: 5px 6px; border-radius: 4px; cursor: pointer; }\n.cc4-chip[data-gen=true] { background: #dcefe3; color: var(--green); border-color: #b9dcc6; }\n.cc4-chip[data-on=true] { outline: 2px solid var(--maroon); outline-offset: 1px; }\n.cc4-cells { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 6px; }\n.cc4-cell { font-family: 'Inconsolata', monospace; width: 40px; padding: 4px 0 5px; text-align: center;\n  border: 1px solid var(--line); border-radius: 4px; background: #fbfcfe; line-height: 1.2; }\n.cc4-cell small { display: block; font-size: 10px; color: #94a6b8; }\n.cc4-cell b { font-size: 15px; color: var(--ink); font-weight: 700; }\n.cc4-cell.cc4-dup { opacity: .35; }\n.cc4-cell.cc4-one { border-color: var(--maroon); }\n.cc4-table { border: 1px solid var(--line); border-radius: 5px; overflow: hidden; font-family: 'Inconsolata', monospace; font-size: 13px; }\n.cc4-tr { display: grid; grid-template-columns: 44px 1fr 44px 76px; gap: 8px; align-items: center;\n  padding: 7px 12px; border-bottom: 1px solid #eef3f7; color: var(--ink2); }\n.cc4-tr:last-child { border-bottom: 0; }\n.cc4-tr.cc4-th { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; background: #fbfcfe; font-family: 'Open Sans', sans-serif; }\n.cc4-tr[data-on=true] { background: #f6faf7; color: var(--ink); }\n.cc4-tr[data-on=false]:not(.cc4-th) { opacity: .5; }\n.cc4-tag { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; padding: 2px 6px; border-radius: 3px;\n  text-align: center; font-family: 'Josefin Sans', sans-serif; background: #eef3f7; color: var(--ink2); }\n.cc4-tr[data-on=true] .cc4-tag { background: #dcefe3; color: var(--green); }\n.cc4-bars { margin: 6px 0 4px; }\n.cc4-bar-row { display: grid; grid-template-columns: 96px 1fr; gap: 10px; align-items: center; margin: 8px 0; }\n.cc4-bar-cap { font-size: 12px; color: var(--ink2); }\n.cc4-bar-track { display: block; height: 14px; background: #eef3f7; border-radius: 3px; overflow: hidden; }\n.cc4-bar { display: block; height: 100%; width: 0; background: var(--green); border-radius: 3px; transition: width .15s; }\n.cc4-bar.cc4-bar-bad { background: var(--maroon); }\n@media (max-width: 520px) {\n  .dpw-readout { gap: 16px; }\n  .cc4-tr { grid-template-columns: 42px 1fr 24px 56px; gap: 6px; padding: 7px 8px; font-size: 12px; }\n  .cc4-bar-row { grid-template-columns: 1fr; gap: 3px; }\n}\n@media (prefers-reduced-motion: reduce) { .dpw * { transition: none !important; } }\n</style>\n<script>\n(function () {\n  var root = document.getElementById('cc4-gen');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var p = 7, g = 3;\n  var bases = root.querySelector('#cc4-bases'), cells = root.querySelector('#cc4-cells');\n  var CAP = '<span class=\"dpw-toggle-cap\">Base g <span class=\"dpw-inflate\">(filled chips are generators)</span></span>';\n\n  // multiplicative order of a mod p: the first k with a^k = 1\n  function order(a) { var v = a % p, k = 1; while (v !== 1) { v = (v * a) % p; k++; } return k; }\n\n  function buildBases() {\n    bases.innerHTML = CAP;\n    for (var a = 1; a < p; a++) (function (a) {\n      var b = document.createElement('button');\n      b.className = 'cc4-chip'; b.textContent = a;\n      b.setAttribute('data-g', a);\n      b.setAttribute('data-gen', String(order(a) === p - 1));\n      on(b, 'click', function () { g = a; draw(); });\n      bases.appendChild(b);\n    })(a);\n  }\n\n  function draw() {\n    var ord = order(g), html = '', v = 1, gens = 0;\n    for (var k = 1; k < p; k++) {\n      v = (v * g) % p;\n      html += '<span class=\"cc4-cell' + (k > ord ? ' cc4-dup' : '') + (v === 1 && k <= ord ? ' cc4-one' : '') +\n        '\"><small>' + g + '<sup>' + k + '</sup></small><b>' + v + '</b></span>';\n    }\n    cells.innerHTML = html;\n    for (var a = 1; a < p; a++) if (order(a) === p - 1) gens++;\n    [].forEach.call(bases.querySelectorAll('.cc4-chip'), function (c) { c.setAttribute('data-on', String(+c.getAttribute('data-g') === g)); });\n    root.querySelector('#cc4-powcap').textContent = 'Powers of ' + g + ' mod ' + p;\n    root.querySelector('#cc4-hit').textContent = ord + ' of ' + (p - 1);\n    root.querySelector('#cc4-rep').textContent = ord;\n    root.querySelector('#cc4-count').textContent = gens + ' of ' + (p - 1);\n    var gv = root.querySelector('#cc4-gv');\n    if (ord === p - 1) { gv.className = 'dpw-verdict dpw-ok'; gv.textContent = g + ' is a generator: every element appears exactly once'; }\n    else { gv.className = 'dpw-verdict'; gv.textContent = g + ' is not a generator: it comes back to 1 after ' + ord + (ord === 1 ? ' power' : ' powers'); }\n  }\n\n  [].forEach.call(root.querySelectorAll('[data-p]'), function (b) {\n    on(b, 'click', function () {\n      p = +b.getAttribute('data-p');\n      [].forEach.call(root.querySelectorAll('[data-p]'), function (o) { o.setAttribute('data-on', String(o === b)); });\n      if (g >= p) g = 3;\n      buildBases(); draw();\n    });\n  });\n  buildBases(); draw();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('cc4-sqm');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var G = 3, p = 7;\n  var xr = root.querySelector('#cc4-xr'), table = root.querySelector('#cc4-table');\n\n  function draw() {\n    var x = +xr.value, bin = x.toString(2), n = bin.length;\n    root.querySelector('#cc4-x').textContent = x;\n    root.querySelector('#cc4-bin').textContent = bin;\n\n    var html = '<div class=\"cc4-tr cc4-th\"><span>power</span><span>value mod ' + p + '</span><span>bit</span><span></span></div>';\n    var sq = G % p, prev = null, picked = [], result = 1;\n    for (var i = 0; i < n; i++) {\n      if (i > 0) { prev = sq; sq = (sq * sq) % p; }\n      var bit = (x >> i) & 1;\n      if (bit) { picked.push(sq); result = (result * sq) % p; }\n      html += '<div class=\"cc4-tr\" data-on=\"' + (bit ? 'true' : 'false') + '\"><span>' + G + '<sup>' + (1 << i) + '</sup></span>' +\n        '<span>' + (i === 0 ? sq : prev + '² = ' + (prev * prev) + ' ≡ ' + sq) + '</span>' +\n        '<span>' + bit + '</span><span class=\"cc4-tag\">' + (bit ? 'take' : 'skip') + '</span></div>';\n    }\n    table.innerHTML = html;\n\n    var raw = 1; picked.forEach(function (v) { raw *= v; });       // product before the final mod (stays small for these p)\n    var shown = picked.slice().reverse().join(' × ');\n    root.querySelector('#cc4-prod').innerHTML = G + '<sup>' + x + '</sup> ≡ ' +\n      (picked.length > 1 && raw < 1e15 ? shown + ' = ' + raw + ' ≡ ' : picked.length > 1 ? shown + ' ≡ ' : '') + result + ' (mod ' + p + ')';\n\n    var fast = (n - 1) + (picked.length - 1), naive = x - 1;\n    root.querySelector('#cc4-fast').textContent = fast;\n    root.querySelector('#cc4-naive').textContent = naive;\n\n    // independent check: multiply by g one step at a time, with no squaring\n    var slow = 1; for (var k = 0; k < x; k++) slow = (slow * G) % p;\n    var c = root.querySelector('#cc4-check');\n    var exact = x <= 20 ? G + '^' + x + ' = ' + Math.pow(G, x).toLocaleString('en-US') + ' ≡ ' : 'one step at a time also gives ';\n    if (slow === result) { c.className = 'dpw-verdict dpw-ok'; c.textContent = 'check: ' + exact + slow + ' (mod ' + p + ')'; }\n    else { c.className = 'dpw-verdict'; c.textContent = 'mismatch: squaring gave ' + result + ', one step at a time gave ' + slow; }\n  }\n\n  [].forEach.call(root.querySelectorAll('[data-p]'), function (b) {\n    on(b, 'click', function () {\n      p = +b.getAttribute('data-p');\n      [].forEach.call(root.querySelectorAll('[data-p]'), function (o) { o.setAttribute('data-on', String(o === b)); });\n      draw();\n    });\n  });\n  on(xr, 'input', draw);\n  draw();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('cc4-scale');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var nr = root.querySelector('#cc4-nr');\n  var SUP = { '-': '⁻', 0: '⁰', 1: '¹', 2: '²', 3: '³', 4: '⁴', 5: '⁵', 6: '⁶', 7: '⁷', 8: '⁸', 9: '⁹' };\n  function sup(e) { return String(e).split('').map(function (c) { return SUP[c]; }).join(''); }\n  function fmt(v) { // BigInt -> readable\n    var s = v.toString();\n    if (s.length <= 15) return Number(s).toLocaleString('en-US');\n    var e = s.length - 1, m = Math.round(Number(s.slice(0, 3)) / 10) / 10;\n    if (m >= 10) { m = 1; e += 1; }\n    return m.toFixed(1) + '×10' + sup(e);\n  }\n  function log2big(v) { var s = v.toString(2); return s.length - 1; }\n\n  function draw() {\n    var n = +nr.value;\n    var naive = (1n << BigInt(n)) - 2n, fast = BigInt(2 * n - 2);\n    root.querySelector('#cc4-n').textContent = n;\n    root.querySelector('#cc4-sn').textContent = fmt(naive);\n    root.querySelector('#cc4-sf').textContent = fmt(fast);\n    root.querySelector('#cc4-b1').style.width = Math.max(1, (log2big(naive) / 256) * 100) + '%';\n    root.querySelector('#cc4-b2').style.width = Math.max(1, (log2big(fast) / 256) * 100) + '%';\n    // small n: exact decimal ratio; large n: BigInt ratio (Number would overflow past 2^1024 and loses digits long before)\n    var times = n <= 40 ? (Number(naive) / Number(fast)) : null;\n    var shown = times !== null ? (times < 10 ? times.toFixed(1) : Math.round(times).toLocaleString('en-US')) : fmt(naive / fast);\n    root.querySelector('#cc4-sv').textContent = naive <= fast\n      ? 'at ' + n + ' bits both ways take ' + fmt(fast) + ' multiplications'\n      : 'at ' + n + ' bits, squaring is about ' + shown + ' times less work';\n  }\n  on(nr, 'input', draw);\n  draw();\n})();\n</script>","headings":[{"value":"The group we are working in","depth":2},{"value":"The generator","depth":2},{"value":"The hard direction","depth":2},{"value":"The easy direction","depth":2},{"value":"How much work is that?","depth":2},{"value":"Where this goes next","depth":2}],"frontmatter":{"date_created":"2026-08-28","path":"/blog/crypto-club-square-and-multiply","tags":["Cryptography","Bitcoin"],"title":"Why Computing g To The x Is Easy"}},"nextPost":{"html":"<p>Just for a recap, the discrete log problem is the fact that if we have an equation like this, where g is a generator of the group Z<sub>p</sub><sup>∗</sup>, and x is your private key, calculating f(x) is easy with binary exponentiation. But given g, f(x), and p, finding x is hard.</p>\n<div class=\"dpw-formula\">f(x) = g<sup>x</sup> mod p</div>\n<p>From here, I want to move on to talking about elliptic curve cryptography, or ECC. This is a different candidate one-way function, which works over a different group.</p>\n<h2 id=\"a-different-kind-of-group\" style=\"position:relative;\"><a href=\"#a-different-kind-of-group\" aria-label=\"a different kind of group permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>A different kind of group</h2>\n<p>In the discrete log problem, we were working over the multiplicative group, and the multiplicative group has a few properties that it must satisfy. The first one was closure. The second was associativity. The third was an identity element. And the fourth was an inverse.</p>\n<p>The elliptic curve works over a different group. Here, we are talking about additive groups. A standard elliptic curve equation is this:</p>\n<div class=\"dpw-formula\">y<sup>2</sup> = x<sup>3</sup> + ax + b</div>\n<p>At the x-axis, it's reflected. The exact same thing is being shown here, but it's negative.</p>\n<p>An additive group has a different set of properties that it must fulfill. An identity element exists. The inverse must exist. We must also have point addition defined. And lastly, we should have point doubling also defined. What do all of these mean?</p>\n<p>The identity element. In an additive group, we have this special abstract point. You can just call it big O. It's just an abstract point, which is called the point of infinity. To be honest, I don't think it's that easy to visualize these things. With integers, it's very easy to just visualize things, but when we start moving into these graph-based groups, things become more abstract. Its purpose is that if we have a point P on this curve, P + O should equal P. Nothing should happen to it. I can't just say zero here, because I think with the curve properties, that might not be true.</p>\n<p>The inverse. We have this point, which is just coordinates on an xy coordinate plane. There also exists −P, whose coordinates are (x, −y). In an elliptic curve, the top half is just a reflection of the bottom half, because of this y<sup>2</sup>. For every point P, there's also a negative of that point, which should mean that when you add that original point with that inverse point, you should get the identity element. This is very similar language to our multiplicative group: when we have our original element and we multiply it by the inverse of that element, we get the identity element, which in that case was one.</p>\n<div class=\"dpw-formula\">P = (x, y) &nbsp;&nbsp;&nbsp; &minus;P = (x, &minus;y) &nbsp;&nbsp;&nbsp; P + (&minus;P) = O</div>\n<p>Point addition. If you draw a straight line through P and Q, by the nature of this graph you are bound to intersect one more point, which we can call R. The negative of that R, which is −R, is P + Q.</p>\n<div class=\"dpw-formula\">P + Q = &minus;R</div>\n<p>Point doubling. We have a point P, and we want to find 2P, which is the same as P + P. There's only one P, so you can't draw a line between two points. But if I draw the tangent line, the line which just touches the curve at P, and extend it until it hits the graph again, I get one more point. We're able to double a point by drawing the tangent line through it and then reflecting it across the x-axis. And that gives us the double of that point.</p>\n<h2 id=\"why-−r\" style=\"position:relative;\"><a href=\"#why-%E2%88%92r\" aria-label=\"why −r permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Why −R?</h2>\n<p>Someone asked the obvious question: the line meets the curve at R, so why is the answer −R and not R? This is the property of the graph. In an elliptic curve, if you take P and Q, two random points on the curve, and you draw a line through them, it's guaranteed to intersect one more point on that curve, and the negative of that point is the answer to P + Q. The exact concept, I'm not sure where the math is coming from there. For this lesson specifically, proving the definition of an additive group is not the scope of this session. It might be a good exercise: prove this. But for now, I'm just trusting the literature.</p>\n<p>Someone in the room suggested it might simply be a convention, and that is close. The group law is set up so that three points on one line add up to the identity, P + Q + R = O. Move R to the other side and you get P + Q = −R.</p>\n<p>That's why I was also saying it's hard to visualize this. Let's take a step back.</p>\n<h2 id=\"multiplication-on-a-parabola\" style=\"position:relative;\"><a href=\"#multiplication-on-a-parabola\" aria-label=\"multiplication on a parabola permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Multiplication on a parabola</h2>\n<p>Let's look at a parabola, which is simple. Everyone can visualize this easily. The equation is y = x<sup>2</sup>. The idea is that within this graph, we're able to do operations. That's the idea you should get from even this elliptic curve. In this case, the operations are addition. In a parabola, we are able to do multiplication.</p>\n<p>If I want to do a × b, what I'm going to do in a parabola is pick P and pick Q, which are (−a, a<sup>2</sup>) and (b, b<sup>2</sup>). In this case, it's going to be 3 × 4, which is 12. We pick these two points: (−3, 9) and (4, 16). And the line through them crosses the y-axis at 12 as well.</p>\n<div class=\"dpw-formula\">P = (&minus;3, 9) &nbsp;&nbsp;&nbsp; Q = (4, 16) &nbsp;&nbsp;&nbsp; the line through them crosses the y-axis at 12 = 3 &times; 4</div>\n<p>Does that work for any two numbers, or was 3 and 4 a lucky pick? Move a and b and watch where the line crosses.</p>\n<div class=\"dpw\" id=\"cc5-par\">\n  <div class=\"dpw-controls\">\n    <label class=\"dpw-label\">a &nbsp; <span class=\"dpw-val\" id=\"cc5-a\">3</span>\n      <input type=\"range\" id=\"cc5-ar\" min=\"0.5\" max=\"6\" step=\"0.5\" value=\"3\" />\n    </label>\n    <label class=\"dpw-label\" style=\"margin-top:12px\">b &nbsp; <span class=\"dpw-val\" id=\"cc5-b\">4</span>\n      <input type=\"range\" id=\"cc5-br\" min=\"0.5\" max=\"6\" step=\"0.5\" value=\"4\" />\n    </label>\n  </div>\n  <svg id=\"cc5-psvg\" viewBox=\"0 0 480 300\" class=\"dpw-svg\" role=\"img\" aria-label=\"The parabola y equals x squared with a line through two points\"></svg>\n  <div class=\"dpw-readout\">\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc5-c\">&ndash;</span><span class=\"dpw-cap\">where the line crosses the y-axis</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc5-ab\">&ndash;</span><span class=\"dpw-cap\"><span class=\"dpw-var\">a</span> &times; <span class=\"dpw-var\">b</span></span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc5-m\">&ndash;</span><span class=\"dpw-cap\">slope of the line</span></div>\n  </div>\n  <div class=\"dpw-verdict dpw-ok\" id=\"cc5-pv\">&ndash;</div>\n  <div class=\"dpw-hint\">The crossing point is measured from the two points, P = (&minus;a, a<sup>2</sup>) and Q = (b, b<sup>2</sup>), and is not computed as a &times; b. The two numbers are then compared.</div>\n</div>\n<p>A fact of parabolas is that our line, y = mx + c, intersects the y-axis at c, and a × b is also equal to c. For parabolas, I can just show you very quickly why it's true. We have two points, (−a, a<sup>2</sup>) and (b, b<sup>2</sup>). If I substitute them into y = mx + c, I get a<sup>2</sup> = −ma + c and b<sup>2</sup> = mb + c. We will try to solve for c.</p>\n<div class=\"dpw-formula\">a<sup>2</sup> = &minus;ma + c &nbsp;&nbsp;&nbsp;&nbsp; b<sup>2</sup> = mb + c &nbsp;&nbsp;&rArr;&nbsp;&nbsp; m = (b<sup>2</sup> &minus; c) / b</div>\n<div class=\"dpw-formula\">a<sup>2</sup>b &minus; bc = ac &minus; ab<sup>2</sup> &nbsp;&nbsp;&rArr;&nbsp;&nbsp; a<sup>2</sup>b + ab<sup>2</sup> = c(a + b) &nbsp;&nbsp;&rArr;&nbsp;&nbsp; ab(a + b) / (a + b) = c &nbsp;&nbsp;&rArr;&nbsp;&nbsp; a &middot; b = c</div>\n<p>So the (a + b) cancels. In this case, I chose three and four. I choose the points in this form, and then I draw a straight line through them, and where it crosses the y-axis is going to be a × b. And for that, this is a proof.</p>\n<h2 id=\"back-to-the-curve\" style=\"position:relative;\"><a href=\"#back-to-the-curve\" aria-label=\"back to the curve permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Back to the curve</h2>\n<p>For an elliptic curve, there's also something similar. The intuition you should understand is that we're able to do operations on a curve to get the answers of those operations. Here we were multiplying. Here we're doing addition, pretty much. That's it. And doubling is pretty much the same as point addition. Here we just have two P's, so it's P + P.</p>\n<p>I have a visual here, maybe to help understand things better. The curve is y<sup>2</sup> = x<sup>3</sup> − 2x + 2. P is (1, 1) and Q is (2, 2.45). We drew a line through them. The green dot, which is R, the reflection of that across the x-axis is the value of P + Q. As I shift my point, we're just reflecting that point, and that's giving us the addition of those two points. Now, if I just have one point, which is P, you can see that the tangent line at P hits the curve at one more point, which is the green dot, and the reflection of that is the doubling of that point P. If I move that point, we're just creating a different tangent line, and then the value of R changes.</p>\n<p>Here is that visual. Where does P + Q land when you move the points, when Q is the same point as P, and when Q is the mirror image of P?</p>\n<div class=\"dpw\" id=\"cc5-add\">\n  <div class=\"dpw-controls\">\n    <label class=\"dpw-label\">x of P &nbsp; <span class=\"dpw-val\" id=\"cc5-xp\">1.00</span>\n      <input type=\"range\" id=\"cc5-xpr\" min=\"-1.75\" max=\"3.5\" step=\"0.05\" value=\"1\" />\n    </label>\n    <label class=\"dpw-label\" style=\"margin-top:12px\">x of Q &nbsp; <span class=\"dpw-val\" id=\"cc5-xq\">2.00</span>\n      <input type=\"range\" id=\"cc5-xqr\" min=\"-1.75\" max=\"3.5\" step=\"0.05\" value=\"2\" />\n    </label>\n  </div>\n  <div class=\"dpw-toggle-row\">\n    <span class=\"dpw-toggle-cap\">Which half of the curve</span>\n    <button class=\"dpw-toggle\" id=\"cc5-pb\" data-on=\"true\">P on top</button>\n    <button class=\"dpw-toggle\" id=\"cc5-qb\" data-on=\"true\">Q on top</button>\n    <button class=\"dpw-toggle\" id=\"cc5-dbl\" data-on=\"false\">set Q = P</button>\n    <button class=\"dpw-toggle\" id=\"cc5-neg\" data-on=\"false\">set Q = &minus;P</button>\n  </div>\n  <svg id=\"cc5-asvg\" viewBox=\"0 0 480 360\" class=\"dpw-svg\" role=\"img\" aria-label=\"An elliptic curve with the line through P and Q, the third point R and its reflection\"></svg>\n  <div class=\"dpw-readout\">\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc5-r\">&ndash;</span><span class=\"dpw-cap\">R, where the line hits again</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc5-sum\">&ndash;</span><span class=\"dpw-cap\">P + Q = &minus;R</span></div>\n  </div>\n  <div class=\"dpw-verdict dpw-ok\" id=\"cc5-av\">&ndash;</div>\n  <div class=\"dpw-hint\">The curve is y<sup>2</sup> = x<sup>3</sup> &minus; 2x + 2, the one from the session, drawn over the real numbers. The line is solved for its third crossing, and the result is checked against the curve equation each time.</div>\n</div>\n<p>When Q is the mirror image of P the line is vertical and never meets the curve a third time. That is the case the point at infinity exists for: P + (−P) = O.</p>\n<h2 id=\"from-the-group-law-to-bitcoins-keys\" style=\"position:relative;\"><a href=\"#from-the-group-law-to-bitcoins-keys\" aria-label=\"from the group law to bitcoins keys permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>From the group law to Bitcoin's keys</h2>\n<p>Knowing that the elliptic curve has these properties of an additive group, we can now look at the elliptic curve discrete log problem. Similar to how we talked about the discrete log problem, the equation is just this:</p>\n<div class=\"dpw-formula\">Q = k &middot; G</div>\n<p>Q is going to be your public key. Remember that Q is a coordinate point. It's not an integer. So it's going to be in the form (x, y). G is a generator. And k would be your private key. In the case of the discrete log problem, x was your private key. Similarly, k is your private key, and the public key is what the output will be, which, again, is a point on an elliptic curve.</p>\n<p>If you want to talk about Bitcoin specifically: the standard elliptic curve equation has x and y, that's all good, but what are these constants, a and b? Different equations can change this constant value, and then it generates a new curve. If I remember correctly, for Bitcoin, a is zero and b is seven. In that case, the equation becomes y<sup>2</sup> = x<sup>3</sup> + 7. For Bitcoin, this is the elliptic curve that they use to pick points on the curve and generate public and private keys.</p>\n<div class=\"dpw-formula\">secp256k1: &nbsp; y<sup>2</sup> = x<sup>3</sup> + 7</div>\n<p>Calculating Q = k · G is easy, given point addition and point doubling. The generator is a point on this curve, and you add it k times, where k is generated randomly. You can do point doubling and point addition for that.</p>\n<p>Two people corrected me here. k is not a point on the curve. It is a number, a 256-bit random number, and the generator is the point, added k times. In an additive group we cannot multiply two points. Yeah, I also think that makes more sense, to be honest.</p>\n<p>I drew this graph here, but for a lot of curves, there's not even a graph. You have random points scattered across the graph, and they're part of the curve, but the curve is not continuous.</p>\n<p>So it looks something like this: just random points. G is fixed. You can Google it. The upper bound of k is also fixed: a large prime, close to 2<sup>256</sup>. We start at G, and we jump around k times. It's very hard to predict how many times we jumped. Let's say it was here. This is now our Q. Given these two points that are public, it's very hard to trace these random steps that we took to find that k value. This is the intuition I understand around ECDLP.</p>\n<p>This is how Bitcoin generates its raw public keys and raw private key. I don't know what it does after generating these points. I think it compresses them and does a bunch of other stuff. But the raw points that come out from this curve are, in a sense, the raw values of your public and private key.</p>\n<h2 id=\"why-any-point-is-a-generator\" style=\"position:relative;\"><a href=\"#why-any-point-is-a-generator\" aria-label=\"why any point is a generator permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Why any point is a generator</h2>\n<p>For this specific curve, any point other than the point at infinity is a valid generator. What I understood about why that's the case: in Z<sub>p</sub><sup>∗</sup>, I said that there is at least one generator, and that's true. It's also true that not every element is a generator. We can't choose any number within this range and expect it to generate this entire range again.</p>\n<p>That is because of the fact that the order of Z<sub>p</sub><sup>∗</sup> is p − 1, because it has p − 1 elements, which means that it's composite. p is a prime, so p − 1 is even, which makes it composite. If the order of a group is composite, you can't have every element be a generator. This is a hand-wavy explanation, I guess, but you might get stuck. If you're trying to generate g<sup>1</sup>, g<sup>2</sup>, g<sup>3</sup>, and you end up at an element that you've already seen before, then you're going to start that loop again. That can exist for groups which have a size of a composite number, because they have many factors.</p>\n<p>In the case of this curve, the order of this group is prime. It has a prime number of elements inside. So if we choose any random point inside this group, we are not expected to accidentally start this loop, where we keep repeating the same numbers and the other numbers are missed out. That's the hand-wavy explanation I'll give, and the best that I understand, for why, in the case of Bitcoin, any point is a valid generator.</p>\n<style>\n.dpw {\n  --ink: #1b2228; --ink2: #5b7085; --line: #dae4ed;\n  --maroon: #a72e2b; --maroon-d: #6a1d1b; --rose: #f2cdcc; --green: #3f8f5b; --slate: #8ba2b8;\n  border: 1px solid var(--line); border-radius: 6px; padding: 20px;\n  margin: 32px 0; background: #fff; font-family: 'Open Sans', sans-serif;\n}\n.dpw * { box-sizing: border-box; }\n/* index.scss sets font on every span directly; let class-less spans inherit from the widget instead */\n.dpw span:not([class]) { font-size: inherit; line-height: inherit; font-family: inherit; }\n.dpw-formula { text-align: center; font-family: 'Inconsolata', monospace; font-size: 17px;\n  color: #1b2228; margin: 22px 0; letter-spacing: .01em; line-height: 1.6; overflow-x: auto; }\n.dpw-formula sup, .dpw-formula sub { font-size: 11px; }\n.dpw-controls { margin-bottom: 14px; }\n.dpw-label { display: block; font-size: 13px; color: var(--ink2); }\n.dpw-label input[type=range] { display: block; width: 100%; margin: 8px 0 0; accent-color: var(--maroon); }\n.dpw-val { color: var(--maroon-d); font-family: 'Inconsolata', monospace; font-weight: 700; }\n.dpw-hint { font-size: 12px; color: var(--ink2); margin-top: 10px; font-style: italic; line-height: 1.55; }\n.dpw-svg { width: 100%; height: auto; display: block; margin: 6px 0 4px;\n  background: linear-gradient(180deg, #fbfcfe, #f4f7fa); border-radius: 4px; }\n.dpw-verdict { margin: 10px 0 4px; padding: 8px 12px; border-radius: 4px; font-size: 13px; font-weight: 700;\n  background: var(--rose); color: var(--maroon-d); text-align: center; font-family: 'Inconsolata', monospace; }\n.dpw-verdict.dpw-ok { background: #dcefe3; color: var(--green); }\n.dpw-readout { display: flex; gap: 24px; margin-top: 12px; flex-wrap: wrap; }\n.dpw-stat { display: flex; flex-direction: column; }\n.dpw-num { font-family: 'Josefin Sans', sans-serif; font-size: 23px; color: var(--maroon-d); line-height: 1.15; }\n.dpw-cap { font-size: 11px; color: var(--ink2); text-transform: uppercase; letter-spacing: .04em; }\n/* variable names keep their case inside the upper-cased captions (k is a number, G is a point) */\n.dpw-cap .dpw-var { text-transform: none; font-size: inherit; line-height: inherit; font-family: inherit; }\n.dpw-toggle-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }\n.dpw-toggle-cap { width: 100%; margin-bottom: 3px; font-size: 12px; color: var(--ink2); }\n.dpw-toggle { font-family: 'Inconsolata', monospace; font-size: 12px; border: 1px solid var(--line);\n  background: #fff; color: var(--ink2); padding: 5px 9px; border-radius: 4px; cursor: pointer; transition: all .15s; }\n.dpw-toggle[data-on=true] { background: var(--maroon); color: #fff; border-color: var(--maroon); }\n@media (max-width: 520px) { .dpw-readout { gap: 16px; } .dpw-num { font-size: 19px; } }\n@media (prefers-reduced-motion: reduce) { .dpw * { transition: none !important; } }\n</style>\n<script>\n(function () {\n  var root = document.getElementById('cc5-par');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var SVG = 'http://www.w3.org/2000/svg', svg = root.querySelector('#cc5-psvg');\n  var ar = root.querySelector('#cc5-ar'), br = root.querySelector('#cc5-br');\n  var W = 480, H = 300, XMIN = -7, XMAX = 7, YMIN = -3, YMAX = 40;\n  function el(n, at, txt) { var e = document.createElementNS(SVG, n); for (var k in at) e.setAttribute(k, at[k]); if (txt !== undefined) e.textContent = txt; return e; }\n  function sx(x) { return (x - XMIN) / (XMAX - XMIN) * W; }\n  function sy(y) { return H - (y - YMIN) / (YMAX - YMIN) * H; }\n  function num(v) { return (Math.round(v * 100) / 100).toString(); }\n\n  function draw() {\n    var a = +ar.value, b = +br.value;\n    root.querySelector('#cc5-a').textContent = num(a);\n    root.querySelector('#cc5-b').textContent = num(b);\n    var x1 = -a, y1 = a * a, x2 = b, y2 = b * b;\n    var m = (y2 - y1) / (x2 - x1);          // slope from the two points\n    var c = y1 - m * x1;                    // where that line meets x = 0\n    var FS = Math.min(20, 12 * (W / (svg.getBoundingClientRect().width || W)));\n\n    while (svg.firstChild) svg.removeChild(svg.firstChild);\n    svg.appendChild(el('line', { x1: 0, x2: W, y1: sy(0), y2: sy(0), stroke: '#dae4ed' }));\n    svg.appendChild(el('line', { x1: sx(0), x2: sx(0), y1: 0, y2: H, stroke: '#dae4ed' }));\n    var d = '';\n    for (var x = XMIN; x <= XMAX + 1e-9; x += 0.1) d += (d ? 'L' : 'M') + sx(x).toFixed(1) + ' ' + sy(x * x).toFixed(1);\n    svg.appendChild(el('path', { d: d, fill: 'none', stroke: '#8ba2b8', 'stroke-width': 1.5 }));\n    svg.appendChild(el('line', { x1: sx(XMIN), y1: sy(m * XMIN + c), x2: sx(XMAX), y2: sy(m * XMAX + c), stroke: '#a72e2b', 'stroke-width': 1.5 }));\n    // labels sit outside the two points, but flip inwards when a point is close to the edge of the chart\n    var pIn = sx(x1) < 130, qIn = sx(x2) > W - 130;\n    [[x1, y1, 'P', pIn ? 'start' : 'end', pIn ? 8 : -8], [x2, y2, 'Q', qIn ? 'end' : 'start', qIn ? -8 : 8]].forEach(function (p) {\n      svg.appendChild(el('circle', { cx: sx(p[0]), cy: sy(p[1]), r: 5, fill: '#6a1d1b' }));\n      svg.appendChild(el('text', { x: sx(p[0]) + p[4], y: sy(p[1]) - 6, 'text-anchor': p[3], 'font-size': FS, fill: '#1b2228', 'font-family': 'Inconsolata, monospace' }, p[2] + ' (' + num(p[0]) + ', ' + num(p[1]) + ')'));\n    });\n    svg.appendChild(el('circle', { cx: sx(0), cy: sy(c), r: 6, fill: '#3f8f5b' }));\n    svg.appendChild(el('text', { x: sx(0) + 10, y: sy(c) + FS * 1.1, 'font-size': FS, fill: '#3f8f5b', 'font-family': 'Inconsolata, monospace' }, 'c = ' + num(c)));\n\n    root.querySelector('#cc5-c').textContent = num(c);\n    root.querySelector('#cc5-ab').textContent = num(a * b);\n    root.querySelector('#cc5-m').textContent = num(m);\n    var v = root.querySelector('#cc5-pv'), same = Math.abs(c - a * b) < 1e-9;\n    v.className = 'dpw-verdict' + (same ? ' dpw-ok' : '');\n    v.textContent = same ? 'the line crosses at ' + num(c) + ', which is ' + num(a) + ' × ' + num(b)\n                         : 'crossing ' + num(c) + ' does not match ' + num(a) + ' × ' + num(b);\n  }\n  on(ar, 'input', draw); on(br, 'input', draw); on(window, 'resize', draw);\n  draw();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('cc5-add');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var SVG = 'http://www.w3.org/2000/svg', svg = root.querySelector('#cc5-asvg');\n  var xpr = root.querySelector('#cc5-xpr'), xqr = root.querySelector('#cc5-xqr');\n  var pb = root.querySelector('#cc5-pb'), qb = root.querySelector('#cc5-qb');\n  var A = -2, B = 2;                                   // y^2 = x^3 - 2x + 2\n  var W = 480, H = 360, XMIN = -2.6, XMAX = 5, YMIN = -10, YMAX = 10;\n  var pTop = true, qTop = true;\n  function f(x) { return x * x * x + A * x + B; }\n  function el(n, at, txt) { var e = document.createElementNS(SVG, n); for (var k in at) e.setAttribute(k, at[k]); if (txt !== undefined) e.textContent = txt; return e; }\n  function sx(x) { return (x - XMIN) / (XMAX - XMIN) * W; }\n  function sy(y) { return H - (y - YMIN) / (YMAX - YMIN) * H; }\n  function num(v) { return (Math.round(v * 100) / 100).toFixed(2); }\n  function pt(p) { return '(' + num(p[0]) + ', ' + num(p[1]) + ')'; }\n  // leftmost point of the curve: the real root of x^3 - 2x + 2\n  var ROOT = (function () { var lo = -3, hi = 0; for (var i = 0; i < 60; i++) { var mid = (lo + hi) / 2; if (f(mid) < 0) lo = mid; else hi = mid; } return hi; })();\n  function onCurve(x, top) { var v = Math.max(0, f(Math.max(x, ROOT))); return [Math.max(x, ROOT), (top ? 1 : -1) * Math.sqrt(v)]; }\n\n  function draw() {\n    var P = onCurve(+xpr.value, pTop), Q = onCurve(+xqr.value, qTop);\n    root.querySelector('#cc5-xp').textContent = num(P[0]);\n    root.querySelector('#cc5-xq').textContent = num(Q[0]);\n    pb.textContent = pTop ? 'P on top' : 'P on bottom'; pb.setAttribute('data-on', String(pTop));\n    qb.textContent = qTop ? 'Q on top' : 'Q on bottom'; qb.setAttribute('data-on', String(qTop));\n    var FS = Math.min(20, 12 * (W / (svg.getBoundingClientRect().width || W)));\n\n    var sameX = Math.abs(P[0] - Q[0]) < 1e-9, sameY = Math.abs(P[1] - Q[1]) < 1e-9;\n    var mode = sameX && sameY ? (Math.abs(P[1]) < 1e-9 ? 'inf' : 'double') : sameX ? 'inf' : 'add';\n    var m = null, R = null, S = null;\n    if (mode === 'add') m = (Q[1] - P[1]) / (Q[0] - P[0]);\n    if (mode === 'double') m = (3 * P[0] * P[0] + A) / (2 * P[1]);\n    if (m !== null) {\n      var x3 = m * m - P[0] - Q[0];                    // third crossing of the line with the curve\n      var yR = m * (x3 - P[0]) + P[1];\n      R = [x3, yR]; S = [x3, -yR];                     // P + Q is R reflected across the x-axis\n    }\n\n    while (svg.firstChild) svg.removeChild(svg.firstChild);\n    svg.appendChild(el('line', { x1: 0, x2: W, y1: sy(0), y2: sy(0), stroke: '#dae4ed' }));\n    svg.appendChild(el('line', { x1: sx(0), x2: sx(0), y1: 0, y2: H, stroke: '#dae4ed' }));\n    var up = [], dn = [];\n    for (var i = 0; i <= 400; i++) { var x = ROOT + (XMAX - ROOT) * (i / 400) * (i / 400), y = Math.sqrt(Math.max(0, f(x))); up.push(sx(x).toFixed(1) + ' ' + sy(y).toFixed(1)); dn.push(sx(x).toFixed(1) + ' ' + sy(-y).toFixed(1)); }\n    svg.appendChild(el('path', { d: 'M' + up.reverse().join('L') + 'L' + dn.join('L'), fill: 'none', stroke: '#8ba2b8', 'stroke-width': 1.5 }));\n\n    if (m !== null) {\n      svg.appendChild(el('line', { x1: sx(XMIN), y1: sy(m * (XMIN - P[0]) + P[1]), x2: sx(XMAX), y2: sy(m * (XMAX - P[0]) + P[1]), stroke: '#a72e2b', 'stroke-width': 1.5 }));\n      svg.appendChild(el('line', { x1: sx(R[0]), y1: sy(R[1]), x2: sx(S[0]), y2: sy(S[1]), stroke: '#3f8f5b', 'stroke-width': 1, 'stroke-dasharray': '4 4' }));\n    } else {\n      svg.appendChild(el('line', { x1: sx(P[0]), y1: 0, x2: sx(P[0]), y2: H, stroke: '#a72e2b', 'stroke-width': 1.5 }));\n    }\n    function dot(p, label, fill, dx, anchor) {\n      svg.appendChild(el('circle', { cx: sx(p[0]), cy: sy(p[1]), r: 5, fill: fill }));\n      svg.appendChild(el('text', { x: sx(p[0]) + dx, y: sy(p[1]) - 7, 'text-anchor': anchor, 'font-size': FS, fill: '#1b2228', 'font-family': 'Inconsolata, monospace' }, label));\n    }\n    dot(P, mode === 'double' ? 'P = Q' : 'P', '#6a1d1b', -8, 'end');\n    if (mode !== 'double') dot(Q, 'Q', '#6a1d1b', 8, 'start');\n    if (R) { dot(R, 'R', '#3f8f5b', 8, 'start'); dot(S, mode === 'double' ? '2P' : 'P + Q', '#1b2228', 8, 'start'); }\n\n    var v = root.querySelector('#cc5-av');\n    root.querySelector('#cc5-dbl').setAttribute('data-on', String(mode === 'double'));\n    root.querySelector('#cc5-neg').setAttribute('data-on', String(mode === 'inf'));\n    if (!R) {\n      root.querySelector('#cc5-r').textContent = 'none';\n      root.querySelector('#cc5-sum').textContent = 'O';\n      v.className = 'dpw-verdict dpw-ok';\n      v.textContent = 'vertical line: P + (−P) = O, the point at infinity';\n      return;\n    }\n    root.querySelector('#cc5-r').textContent = pt(R);\n    root.querySelector('#cc5-sum').textContent = pt(S);\n    // independent check: the result has to satisfy y^2 = x^3 - 2x + 2\n    var lhs = S[1] * S[1], rhs = f(S[0]), okCurve = Math.abs(lhs - rhs) <= 1e-6 * Math.max(1, Math.abs(rhs));\n    var off = R[0] > XMAX || Math.abs(R[1]) > YMAX ? ' (off the chart)' : '';\n    v.className = 'dpw-verdict' + (okCurve ? ' dpw-ok' : '');\n    v.textContent = okCurve\n      ? (mode === 'double' ? 'tangent at P: 2P = ' : 'P + Q = ') + pt(S) + ', and it is on the curve' + off\n      : 'result ' + pt(S) + ' is not on the curve';\n  }\n\n  on(xpr, 'input', draw); on(xqr, 'input', draw); on(window, 'resize', draw);\n  on(pb, 'click', function () { pTop = !pTop; draw(); });\n  on(qb, 'click', function () { qTop = !qTop; draw(); });\n  on(root.querySelector('#cc5-dbl'), 'click', function () { xqr.value = xpr.value; qTop = pTop; draw(); });\n  on(root.querySelector('#cc5-neg'), 'click', function () { xqr.value = xpr.value; qTop = !pTop; draw(); });\n  draw();\n})();\n</script>","headings":[{"value":"A different kind of group","depth":2},{"value":"Why −R?","depth":2},{"value":"Multiplication on a parabola","depth":2},{"value":"Back to the curve","depth":2},{"value":"From the group law to Bitcoin's keys","depth":2},{"value":"Why any point is a generator","depth":2}],"frontmatter":{"date_created":"2026-09-04","path":"/blog/crypto-club-multiplying-with-a-parabola","tags":["Cryptography","Bitcoin","Elliptic Curves"],"title":"Multiplying With A Parabola"}}},"pageContext":{"prevPostPath":"/blog/fiat-shamir-coverage-gap","currPostPath":"/blog/crypto-club-square-and-multiply","nextPostPath":"/blog/crypto-club-multiplying-with-a-parabola"}},"staticQueryHashes":[]}