{"componentChunkName":"component---src-templates-post-js","path":"/blog/crypto-club-why-schnorr-adds-up","result":{"data":{"prevPost":{"html":"<p>Notice how a lot of these schemes assume that this problem, the discrete log problem, is hard to solve. If someone comes up with an easy solution, then all of a sudden private keys can be computed easily. All of a sudden transactions can be signed easily, because we would be able to create a forgery of the signature.</p>\n<p>Before I talk about the actual signature scheme, we'll look at what was first discovered. The Schnorr digital signature scheme came after something called the Schnorr proof of knowledge. And this is modelled, again, as an interactive game, similar to how we saw this game between a challenger and an adversary. The goal is for a prover to prove to a verifier that they know a secret X without revealing X.</p>\n<h2 id=\"peter-and-veronica\" style=\"position:relative;\"><a href=\"#peter-and-veronica\" aria-label=\"peter and veronica 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>Peter and Veronica</h2>\n<p>We have the discrete log problem, which is Y = G<sup>X</sup> mod P, where P is a prime. This Y will be our public key, and this X will be our secret key. And we basically want to prove to someone that we possess this X without showing them X. So you're proving that you have knowledge of X. You're not showing X, though.</p>\n<p>Q is a large prime, so that's public info. The generator, everyone knows. The generator is also a public parameter. Let's give them names: the prover is Peter, and V is Veronica.</p>\n<ol>\n<li>We randomly pick a secret value X from the set of integers up to Q, so this is from 0 to Q − 1. And then we calculate our public key, Y = G<sup>X</sup>. We know that if we just give Veronica a Y, it's very hard for her to get the X from this.</li>\n<li>Peter gives Veronica the output, Y. And he also creates another random value. Think of this as two steps. This random value is again from the same field. We're just going to create a random R as well, which also comes from Z<sub>Q</sub>. I'll just call this α = G<sup>R</sup>. And then we send both Y and α to Veronica.</li>\n<li>Veronica picks a random value C too, from the same field, and she sends it over to Peter.</li>\n<li>Then we just do this calculation: S = R + X·C mod Q. And then we send the output S to Veronica.</li>\n<li>What does she know right now? She knows Y, she knows α, and she just got S. So based on these values that she got, she checks if G<sup>S</sup> equals α · Y<sup>C</sup>.</li>\n</ol>\n<div class=\"dpw-formula\">s = r + x&middot;c mod q &nbsp;&nbsp;&nbsp;&nbsp; g<sup>s</sup> &#8799; &alpha; &middot; y<sup>c</sup></div>\n<p>Why does this work? If we try to expand this equation: α is G<sup>R</sup>, and Y is G<sup>X</sup>, so Y<sup>C</sup> is (G<sup>X</sup>)<sup>C</sup>. When we raise a power to a power, we multiply the exponents, and when we multiply powers of the same base, we add the exponents. So the right side becomes G<sup>R + XC</sup>. And if you notice, S was also exactly this, R + XC. So it's basically checking if G<sup>R + XC</sup> is equal to G<sup>R + XC</sup>. But obviously, they don't see this X. They're just computing on the actual output.</p>\n<p>R is supposed to be like a masking factor. If we didn't have R, and we just sent X·C mod Q, Veronica is the one who gave C, so she might be able to calculate what X is. But if we mask this whole equation with a random value, then X stays hidden, which is our secret key. We don't want Veronica to know the secret key. We just need her to know that I have this key.</p>\n<p>And why is she sending C? We need another party to send another random value. Otherwise, Peter could just create an equation that would satisfy this property without actually knowing X. So there has to be some input given to Peter that is not something he himself calculated. Both prover and verifier have skin in the game, because the verifier is the one who's controlling the C, and the prover is the one who's controlling these things.</p>\n<div class=\"dpw\" id=\"cc8-pok\">\n  <div class=\"dpw-q\">Run it: does Veronica's check pass, and does she ever see x?</div>\n  <div class=\"dpw-detail-b\">Toy parameters: p = 2039, q = 1019, g = 4 (g has order q mod p). Real Schnorr uses 256-bit numbers; the algebra is identical.</div>\n  <div class=\"dpw-toggle-row\" style=\"margin-top:12px\">\n    <button class=\"dpw-toggle\" id=\"cc8p-new\">new secret x</button>\n    <button class=\"dpw-toggle\" id=\"cc8p-show\" data-on=\"false\">peek at x</button>\n  </div>\n  <div class=\"dpw-grid2\">\n    <div>\n      <div class=\"dpw-cap\">Peter (prover)</div>\n      <div class=\"dpw-line\"><span>secret x</span><span><b id=\"cc8p-x\">hidden</b></span></div>\n      <div class=\"dpw-line\"><span>y = g<sup>x</sup> mod p</span><span><b id=\"cc8p-y\"></b></span></div>\n      <div class=\"dpw-line\"><span>mask r</span><span><b id=\"cc8p-r\">hidden</b></span></div>\n      <div class=\"dpw-line\"><span>&alpha; = g<sup>r</sup> mod p</span><span><b id=\"cc8p-a\"></b></span></div>\n    </div>\n    <div>\n      <div class=\"dpw-cap\">Veronica (verifier)</div>\n      <label class=\"dpw-label\">challenge c &nbsp; <span class=\"dpw-val\" id=\"cc8p-cv\"></span>\n        <input type=\"range\" id=\"cc8p-c\" min=\"0\" max=\"1018\" step=\"1\" value=\"300\" /></label>\n      <div class=\"dpw-line\"><span>s = r + x&middot;c mod q</span><span><b id=\"cc8p-s\"></b></span></div>\n      <div class=\"dpw-line\"><span>g<sup>s</sup> mod p</span><span><b id=\"cc8p-l\"></b></span></div>\n      <div class=\"dpw-line\"><span>&alpha;&middot;y<sup>c</sup> mod p</span><span><b id=\"cc8p-rr\"></b></span></div>\n    </div>\n  </div>\n  <div class=\"dpw-verdict dpw-ok\" id=\"cc8p-v\"></div>\n  <div class=\"dpw-hint\">Veronica only ever sees y, &alpha;, c and s. Drag the challenge: s moves all over the field, the check passes every time, and x is never sent.</div>\n</div>\n<h2 id=\"three-things-to-prove\" style=\"position:relative;\"><a href=\"#three-things-to-prove\" aria-label=\"three things to prove 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>Three things to prove</h2>\n<p>With a proof of knowledge, we have to show three things.</p>\n<ul>\n<li>Completeness means an honest prover plus an honest verifier always pass the check. There shouldn't be a bug in the code where, even if we're always honest, sometimes it says you failed.</li>\n<li>Soundness means a dishonest prover, being someone who actually doesn't know X, fails the check every time, except with negligible probability. There might be a fluke once in a while, because all of these values are chosen randomly. So there is a chance of one over the order of the field that they might get it correct.</li>\n<li>Zero knowledge means that nothing about the private information, which is X in this case, leaks to the verifier. The whole point is for us to not show Veronica X.</li>\n</ul>\n<p>For completeness, I showed you how this check works during the honest case, which is the easy case.</p>\n<div class=\"dpw\" id=\"cc8-cheat\">\n  <div class=\"dpw-q\">How often does a Peter who does not know x get through?</div>\n  <div class=\"dpw-detail-b\">A cheating Peter's best move: guess the challenge c* in advance, pick any s, and send &alpha; = g<sup>s</sup>&middot;y<sup>&minus;c*</sup>. If Veronica happens to send c*, the check passes. Every run below is the real modular arithmetic.</div>\n  <div class=\"dpw-toggle-row\" style=\"margin-top:12px\">\n    <span class=\"dpw-toggle-cap\">group size q</span>\n    <button class=\"dpw-toggle\" data-q=\"11\" data-on=\"true\">q = 11</button>\n    <button class=\"dpw-toggle\" data-q=\"1019\" data-on=\"false\">q = 1019</button>\n    <button class=\"dpw-toggle\" data-q=\"big\" data-on=\"false\">q &asymp; 2<sup>256</sup></button>\n  </div>\n  <div class=\"dpw-toggle-row\">\n    <span class=\"dpw-toggle-cap\">who picks the challenge?</span>\n    <button class=\"dpw-toggle\" id=\"cc8c-v\" data-on=\"true\">Veronica, at random</button>\n    <button class=\"dpw-toggle\" id=\"cc8c-p\" data-on=\"false\">Peter, himself</button>\n  </div>\n  <div class=\"dpw-toggle-row\">\n    <button class=\"dpw-toggle\" id=\"cc8c-run\">run 10,000 cheating attempts</button>\n  </div>\n  <div class=\"dpw-readout\">\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc8c-n\">0</span><span class=\"dpw-cap\">attempts</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc8c-w\">0</span><span class=\"dpw-cap\">passed the check</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc8c-r\">&ndash;</span><span class=\"dpw-cap\">pass rate</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc8c-e\"></span><span class=\"dpw-cap\">1 / <span class=\"dpw-var\">q</span></span></div>\n  </div>\n  <div class=\"dpw-verdict dpw-neutral\" id=\"cc8c-vd\">Press run.</div>\n  <div class=\"dpw-hint\">When Peter picks c himself he passes every time without knowing x, which is why c has to come from someone else. The same trick, run with Veronica's real c, is what the zero-knowledge simulator does: it writes transcripts (y, &alpha;, c, s) that verify, and it never knew x.</div>\n</div>\n<h2 id=\"soundness-rewind-the-tape\" style=\"position:relative;\"><a href=\"#soundness-rewind-the-tape\" aria-label=\"soundness rewind the tape 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>Soundness: rewind the tape</h2>\n<p>Initially, when I first learned it, I was also kind of confused, because it didn't make any practical sense. But I was told to just think of this as a mental experiment, and maybe you can also try to do the same. Hear me out, and then let's talk about it.</p>\n<p>X and R are both created from this field, and then we calculate Y = G<sup>X</sup> and α = G<sup>R</sup>, and we send both of these to the verifier. Now the verifier creates a random value, again from this field, and sends that over to the prover. We'll call this C<sub>1</sub>. And now the prover calculates this S value, I'll call it S<sub>1</sub>, which is R + C<sub>1</sub>X mod Q.</p>\n<div class=\"dpw-formula\">s<sub>1</sub> = r + c<sub>1</sub>x mod q</div>\n<p>Now what happens is we stop this game, and we rewind the tape. We rewind the program, the tape, the virtual machine, whatever you want to think of it. Basically, you go back in time to this point. And at this point, the α value is already calculated, and R is already calculated. Now what we can do is tell the prover to prove it again: \"Hey, you've done it once, do it again.\" So the verifier creates a C<sub>2</sub> and gives C<sub>2</sub> to the prover. But our random value is fixed, remember. So S<sub>2</sub> will now be the same random value plus C<sub>2</sub>X mod Q.</p>\n<div class=\"dpw-formula\">s<sub>2</sub> = r + c<sub>2</sub>x mod q</div>\n<p>We have the same R, the same X. We can subtract these equations, and the R will cancel out. R − R cancels out, and we can solve for X:</p>\n<div class=\"dpw-formula\">x = (s<sub>1</sub> &minus; s<sub>2</sub>) / (c<sub>1</sub> &minus; c<sub>2</sub>) mod q</div>\n<p>If we were able to give two challenges to a prover at this point in time, they must know X, because if they've created valid S values, then we can see that X is easily computable. And if a prover does not know X, then they would not be able to compute these S<sub>1</sub> and S<sub>2</sub> correctly, so this equation would not be possible.</p>\n<p>This is the idea behind the forking lemma. This is a point at which we forked and we fixed our random value, and then we consider two cases with the same random value. We go back, we rewind the tape, and then we look at two cases with our previous values fixed, to prove whatever we want to prove.</p>\n<div class=\"dpw\" id=\"cc8-fork\">\n  <div class=\"dpw-q\">Rewind Peter once. How much of his secret do two answers give away?</div>\n  <div class=\"dpw-detail-b\">Same toy group (p = 2039, q = 1019, g = 4). Peter commits to &alpha; once. Veronica asks c<sub>1</sub>, then the tape is rewound to just after &alpha; and she asks c<sub>2</sub>.</div>\n  <div class=\"dpw-controls\" style=\"margin-top:12px\">\n    <label class=\"dpw-label\">first challenge c<sub>1</sub> &nbsp; <span class=\"dpw-val\" id=\"cc8f-c1v\"></span>\n      <input type=\"range\" id=\"cc8f-c1\" min=\"0\" max=\"1018\" value=\"120\" /></label>\n    <label class=\"dpw-label\">second challenge c<sub>2</sub> (after rewinding) &nbsp; <span class=\"dpw-val\" id=\"cc8f-c2v\"></span>\n      <input type=\"range\" id=\"cc8f-c2\" min=\"0\" max=\"1018\" value=\"777\" /></label>\n  </div>\n  <div class=\"dpw-toggle-row\">\n    <button class=\"dpw-toggle\" id=\"cc8f-new\">new Peter (new x and r)</button>\n  </div>\n  <div class=\"dpw-line\"><span>&alpha; (fixed by the fork)</span><span><b id=\"cc8f-a\"></b></span></div>\n  <div class=\"dpw-line\"><span>s<sub>1</sub>, s<sub>2</sub> (both pass Veronica's check)</span><span><b id=\"cc8f-s\"></b></span></div>\n  <div class=\"dpw-line\"><span>(s<sub>1</sub> &minus; s<sub>2</sub>)&middot;(c<sub>1</sub> &minus; c<sub>2</sub>)<sup>&minus;1</sup> mod q</span><span><b id=\"cc8f-x\"></b></span></div>\n  <div class=\"dpw-line\"><span>Peter's actual secret x</span><span><b id=\"cc8f-xr\"></b></span></div>\n  <div class=\"dpw-verdict\" id=\"cc8f-v\"></div>\n  <div class=\"dpw-hint\">All of it. The only case that fails is c<sub>1</sub> = c<sub>2</sub>, where there is nothing to divide by.</div>\n</div>\n<p>Someone in the room connected this to signatures: if the same random value is used for two signatures, it cancels out and exposes the private key. That's the same algebra. Here the rewind is a thought experiment that proves soundness. In a signature scheme, reusing the random value by accident leaks the key.</p>\n<h2 id=\"zero-knowledge\" style=\"position:relative;\"><a href=\"#zero-knowledge\" aria-label=\"zero knowledge 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>Zero knowledge</h2>\n<p>With zero knowledge, you basically want to rely on a simulator. And the simulator, imagine it's just a computer program. It should be able to simulate all of the important transcript values of the scheme without actually knowing X. Whatever it does, it should give us Y, α and S, which should be computationally indistinguishable from the real Y, α and S, which were created by the actual prover. Maybe we need a full session on this: what does it mean to be computationally indistinguishable? But if we can show that a program is able to produce this type of output, and it has no knowledge of X, then we can prove that it's zero knowledge.</p>\n<p>This is not a digital signature. This is just a proof of knowledge scheme, which came first. And then from this, Schnorr created a digital signature scheme. We'll talk about how to convert this interactive proof of knowledge into a non-interactive digital signature, and then how to turn that into an elliptic curve version, which is the one used in Bitcoin.</p>\n<style>\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 {\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; color: var(--ink);\n}\n.dpw * { box-sizing: border-box; }\n.dpw-q { font-family: 'Josefin Sans', sans-serif; font-size: 14px; text-transform: uppercase; letter-spacing: .04em;\n  color: var(--maroon-d); margin: 0 0 12px; line-height: 1.4; }\n.dpw-controls { margin-bottom: 14px; display: grid; gap: 12px; }\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-verdict.dpw-neutral { background: #e3ecf4; color: #3d566b; }\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 */\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: 6px; }\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-toggle:disabled { opacity: .45; cursor: default; }\n.dpw-detail { border: 1px solid var(--line); border-radius: 5px; padding: 13px 14px; margin-top: 10px; }\n.dpw-detail-h { font-family: 'Josefin Sans', sans-serif; font-size: 13px; text-transform: uppercase;\n  letter-spacing: .04em; color: var(--maroon-d); margin-bottom: 7px; }\n.dpw-detail-b { font-size: 13px; color: var(--ink2); line-height: 1.6; }\n.dpw-line { font-size: 13px; color: var(--ink2); margin: 9px 0; display: flex; justify-content: space-between;\n  align-items: baseline; gap: 10px; flex-wrap: wrap; }\n.dpw-line b { font-family: 'Inconsolata', monospace; font-size: 15px; color: var(--ink); font-weight: 700; }\n.dpw-mono { font-family: 'Inconsolata', monospace; }\n.dpw-input { font-family: 'Inconsolata', monospace; font-size: 14px; border: 1px solid var(--line); border-radius: 4px;\n  padding: 5px 8px; width: 80px; color: var(--ink); }\n.dpw-chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0; }\n.dpw-chip { font-family: 'Inconsolata', monospace; font-size: 12px; padding: 3px 7px; border-radius: 3px;\n  background: #f4f7fa; border: 1px solid var(--line); color: var(--ink); }\n.dpw-chip.dpw-chip-hot { background: #dcefe3; border-color: #b9dcc5; color: var(--green); }\n.dpw-chip.dpw-chip-bad { background: var(--rose); border-color: #e7b3b1; color: var(--maroon-d); }\n.dpw-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }\n.dpw-table { width: 100%; border-collapse: collapse; font-size: 13px; display: block; overflow-x: auto; }\n.dpw-table td, .dpw-table th { padding: 5px 6px; border-bottom: 1px solid #eef3f7; text-align: left; }\n/* table headers hold maths: f(3) must not become F(3) */\n.dpw-table th { font-size: 11px; color: var(--ink2); text-transform: none; letter-spacing: .04em; font-weight: 600; }\n.dpw-table td.dpw-mono { white-space: nowrap; }\n@media (max-width: 560px) { .dpw { padding: 14px; } .dpw-grid2 { 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 P = 2039n, Q = 1019n, G = 4n;\n  function mp(b, e, m) { b %= m; if (b < 0n) b += m; var r = 1n; while (e > 0n) { if (e & 1n) r = r * b % m; b = b * b % m; e >>= 1n; } return r; }\n  function rnd(n) { return BigInt(Math.floor(Math.random() * Number(n))); }\n  function md(a, m) { a %= m; return a < 0n ? a + m : a; }\n  window.__cc8 = { P: P, Q: Q, G: G, mp: mp, rnd: rnd, md: md };\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('cc8-pok');\n  if (!root || !window.__cc8) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { 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  var Z = window.__cc8, $ = function (id) { return root.querySelector('#' + id); };\n  var x, r, show = false;\n  function fresh() { x = 1n + Z.rnd(Z.Q - 1n); r = Z.rnd(Z.Q); draw(); }\n  function draw() {\n    var c = BigInt($('cc8p-c').value);\n    var y = Z.mp(Z.G, x, Z.P), a = Z.mp(Z.G, r, Z.P);\n    var s = Z.md(r + x * c, Z.Q);\n    var lhs = Z.mp(Z.G, s, Z.P), rhs = a * Z.mp(y, c, Z.P) % Z.P;\n    $('cc8p-x').textContent = show ? String(x) : 'hidden';\n    $('cc8p-r').textContent = show ? String(r) : 'hidden';\n    $('cc8p-y').textContent = String(y); $('cc8p-a').textContent = String(a);\n    $('cc8p-cv').textContent = String(c); $('cc8p-s').textContent = String(s);\n    $('cc8p-l').textContent = String(lhs); $('cc8p-rr').textContent = String(rhs);\n    var v = $('cc8p-v');\n    v.className = lhs === rhs ? 'dpw-verdict dpw-ok' : 'dpw-verdict';\n    v.innerHTML = '' + (lhs === rhs ? lhs + ' = ' + rhs + ' &rarr; Veronica accepts' : 'mismatch &rarr; reject') + '';\n  }\n  on($('cc8p-c'), 'input', draw);\n  on($('cc8p-new'), 'click', fresh);\n  on($('cc8p-show'), 'click', function () { show = !show; $('cc8p-show').setAttribute('data-on', String(show)); draw(); });\n  fresh();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('cc8-cheat');\n  if (!root || !window.__cc8) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { 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  var Z = window.__cc8, $ = function (id) { return root.querySelector('#' + id); };\n  var GROUPS = { '11': { P: 23n, Q: 11n, G: 4n }, '1019': { P: 2039n, Q: 1019n, G: 4n } };\n  var qsel = '11', peterPicks = false, n = 0, w = 0;\n  var qbtns = root.querySelectorAll('[data-q]');\n  function resetCounts() { n = 0; w = 0; paint(); $('cc8c-vd').className = 'dpw-verdict dpw-neutral'; $('cc8c-vd').innerHTML = 'Press run.'; }\n  function paint() {\n    $('cc8c-n').textContent = n.toLocaleString(); $('cc8c-w').textContent = w.toLocaleString();\n    $('cc8c-r').textContent = n ? (100 * w / n).toFixed(2) + '%' : '–';\n    $('cc8c-e').innerHTML = qsel === 'big' ? '&asymp; 10<sup>&minus;77</sup>' : (100 / Number(qsel)).toFixed(2) + '%';\n  }\n  function run() {\n    var vd = $('cc8c-vd');\n    if (qsel === 'big') {\n      n += 10000;\n      if (peterPicks) w += 10000;\n      paint();\n      vd.className = peterPicks ? 'dpw-verdict' : 'dpw-verdict dpw-ok';\n      vd.innerHTML = peterPicks ? 'Peter picks c: he passes every time, and he never knew x.'\n        : 'Too big to simulate: the chance any of these 10,000 tries passes is about 10<sup>&minus;73</sup>.';\n      return;\n    }\n    var g = GROUPS[qsel], x = 1n + Z.rnd(g.Q - 1n), y = Z.mp(g.G, x, g.P); // Peter is given y but not x\n    var yinv = Z.mp(y, g.Q - 1n, g.P);\n    for (var i = 0; i < 10000; i++) {\n      var cs = Z.rnd(g.Q), s = Z.rnd(g.Q);\n      var alpha = Z.mp(g.G, s, g.P) * Z.mp(yinv, cs, g.P) % g.P;   // alpha = g^s * y^(-c*)\n      var c = peterPicks ? cs : Z.rnd(g.Q);\n      var ok = Z.mp(g.G, s, g.P) === alpha * Z.mp(y, c, g.P) % g.P;\n      n++; if (ok) w++;\n    }\n    paint();\n    vd.className = peterPicks ? 'dpw-verdict' : 'dpw-verdict dpw-ok';\n    vd.innerHTML = peterPicks ? 'Peter picks c: he passes every time, and he never knew x.'\n      : 'Pass rate tracks 1/q. Make q 2<sup>256</sup> and the fluke is negligible.';\n  }\n  [].forEach.call(qbtns, function (b) {\n    on(b, 'click', function () {\n      qsel = b.getAttribute('data-q');\n      [].forEach.call(qbtns, function (o) { o.setAttribute('data-on', String(o === b)); });\n      resetCounts();\n    });\n  });\n  on($('cc8c-v'), 'click', function () { peterPicks = false; $('cc8c-v').setAttribute('data-on', 'true'); $('cc8c-p').setAttribute('data-on', 'false'); resetCounts(); });\n  on($('cc8c-p'), 'click', function () { peterPicks = true; $('cc8c-p').setAttribute('data-on', 'true'); $('cc8c-v').setAttribute('data-on', 'false'); resetCounts(); });\n  on($('cc8c-run'), 'click', run);\n  resetCounts();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('cc8-fork');\n  if (!root || !window.__cc8) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { 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  var Z = window.__cc8, $ = function (id) { return root.querySelector('#' + id); };\n  var x, r;\n  function fresh() { x = 1n + Z.rnd(Z.Q - 1n); r = Z.rnd(Z.Q); draw(); }\n  function draw() {\n    var c1 = BigInt($('cc8f-c1').value), c2 = BigInt($('cc8f-c2').value);\n    $('cc8f-c1v').textContent = String(c1); $('cc8f-c2v').textContent = String(c2);\n    var s1 = Z.md(r + c1 * x, Z.Q), s2 = Z.md(r + c2 * x, Z.Q);\n    $('cc8f-a').textContent = String(Z.mp(Z.G, r, Z.P));\n    $('cc8f-s').textContent = s1 + ', ' + s2;\n    $('cc8f-xr').textContent = String(x);\n    var v = $('cc8f-v');\n    if (c1 === c2) {\n      $('cc8f-x').textContent = 'divide by 0';\n      v.className = 'dpw-verdict dpw-ok'; v.innerHTML = 'Same challenge twice: s<sub>1</sub> = s<sub>2</sub>, nothing learned.'; return;\n    }\n    var inv = Z.mp(Z.md(c1 - c2, Z.Q), Z.Q - 2n, Z.Q);\n    var xr = Z.md((s1 - s2) * inv, Z.Q);\n    $('cc8f-x').textContent = String(xr);\n    v.className = 'dpw-verdict';\n    v.innerHTML = '' + (xr === x ? 'Extracted x = ' + xr + '. Two answers to the same &alpha; are the secret.' : 'mismatch') + '';\n  }\n  on($('cc8f-c1'), 'input', draw); on($('cc8f-c2'), 'input', draw); on($('cc8f-new'), 'click', fresh);\n  fresh();\n})();\n</script>","headings":[{"value":"Peter and Veronica","depth":2},{"value":"Three things to prove","depth":2},{"value":"Soundness: rewind the tape","depth":2},{"value":"Zero knowledge","depth":2}],"frontmatter":{"date_created":"2026-09-25","path":"/blog/crypto-club-rewinding-the-prover","tags":["Cryptography","Bitcoin","Digital Signatures","Zero Knowledge Proofs"],"title":"Rewinding The Prover"}},"currPost":{"html":"<p>In Bitcoin, we're using two variations of signature schemes. You could have a Taproot transaction, or you could have the legacy transaction, and they both use different signature schemes. We've been talking about the Taproot example so far, which is the Schnorr signature scheme. Taproot is a Bitcoin upgrade, and its Schnorr signatures are specified in BIP-340. And the other version, that we haven't discussed much because it's quite messy, is ECDSA, which stands for elliptic curve digital signature algorithm.</p>\n<p>A digital signature scheme has three functions: a key generation algorithm, a signing algorithm, and lastly a verify algorithm. We'll talk about the digital signature scheme for both of these constructions: keygen, sign and verify.</p>\n<h2 id=\"schnorr\" style=\"position:relative;\"><a href=\"#schnorr\" aria-label=\"schnorr 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>Schnorr</h2>\n<p>For Schnorr, it's quite simple. You have a private key, which is a scalar, which you randomly pick from 1 up to n − 1, where n is the order of the elliptic curve, specifically the secp256k1 elliptic curve. Then you compute your public key, which we'll call P = d·G. The generator G is a point, so it has x and y coordinates, and you add it to itself d times, where d is your private scalar value. And then your public key is another coordinate point on the secp256k1 curve. With Schnorr specifically, we only care about points where the y value is even.</p>\n<p>For signing:</p>\n<ol>\n<li>You pick a random value k, again from the scalar interval, and you compute the random nonce, which is R = k·G.</li>\n<li>To make it non-interactive, we need a hash function. Typically, this is something the verifier would have to give us. But we can actually compute the challenge ourselves, by hashing the x-coordinate of the public key, the x-coordinate of R, and the message. If you don't quite understand what's going on, just imagine we're hashing P and R.</li>\n<li>Finally, you calculate your equation, s, which is your random nonce plus your challenge times your private key, mod n.</li>\n</ol>\n<div class=\"dpw-formula\">R = k&middot;G &nbsp;&nbsp; c = H(x<sub>R</sub> &#8214; x<sub>P</sub> &#8214; m) &nbsp;&nbsp; s = k + c&middot;d mod n &nbsp;&nbsp; &sigma; = (x<sub>R</sub>, s)</div>\n<p>We spoke about what happens if we first have our challenge. From that, we could basically cheat and create a nonce R that cancels out the verification without us needing to know the private key. So this is why you first calculate R and then c. You can only find c by hashing the value of R, so there's no way you could calculate c before R.</p>\n<p>For verification, we calculate our own R by multiplying this s value with our generator, which is public, and then we subtract our challenge times P from that. They're checking if the x coordinate of this R that they found is equal to the x coordinate of the original R. For this c, they can recompute this themselves. They don't need the signer to send them this information, because x<sub>P</sub> is public, x<sub>R</sub> has been sent with the signature, and the message is a common thing between the prover and the verifier.</p>\n<div class=\"dpw-formula\">R&prime; = s&middot;G &minus; c&middot;P &nbsp;&nbsp;&nbsp; accept if x<sub>R&prime;</sub> = x<sub>R</sub></div>\n<h2 id=\"ecdsa\" style=\"position:relative;\"><a href=\"#ecdsa\" aria-label=\"ecdsa 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>ECDSA</h2>\n<p>What about the elliptic curve digital signature algorithm? That's also being used, and that's an older signature scheme, and Bitcoin has since upgraded. So what is this, and why did we upgrade?</p>\n<p>For key generation, again, you pick your private key, and again, you compute your public key, P = d·G. For signing, again, we pick a random value k, a scalar value, and we find our nonce, R = k·G. Now the computation that we do for s is a little bit more involved, and not as nice to look at. You calculate the modular inverse of the k that you just picked, and you multiply it by the hash of the message plus the x coordinate of R times the private key d. And all of that is mod n, again.</p>\n<div class=\"dpw-formula\">s = k<sup>&minus;1</sup>(H(m) + x<sub>R</sub>&middot;d) mod n</div>\n<p>For verify, it will output accept or reject, and we have to compute our own R value as c (the hash of the message) times the modular inverse of s, times G, plus the x coordinate of R times, again, the modular inverse of s, times P. And what we're then checking is if the x coordinate of the R that we calculated is congruent to the x coordinate of the random nonce the signer sent to us, mod n.</p>\n<div class=\"dpw-formula\">R&prime; = H(m)&middot;s<sup>&minus;1</sup>&middot;G + x<sub>R</sub>&middot;s<sup>&minus;1</sup>&middot;P &nbsp;&nbsp;&nbsp; accept if x<sub>R&prime;</sub> &equiv; x<sub>R</sub> mod n</div>\n<h2 id=\"the-modular-inverse-makes-things-hard\" style=\"position:relative;\"><a href=\"#the-modular-inverse-makes-things-hard\" aria-label=\"the modular inverse makes things hard 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 modular inverse makes things hard</h2>\n<p>If we simply compare this with this, even if we say c equals the hash of the message, you can already see how this extra thing, this modular inverse, makes things hard. Why? It makes things hard for multisignatures.</p>\n<p>When multiple people have their own random nonce values, their own challenge values, their own private keys, we're able to do simple addition. We can just add nonce values, and the addition of those nonce values scales linearly, meaning it increases linearly as you add. But with a modular inverse, that's not the case. You can pick random numbers and try to do it yourself with two people.</p>\n<div class=\"dpw\" id=\"cc11-inv\">\n  <div class=\"dpw-q\">Is the inverse of a sum the sum of the inverses?</div>\n  <div class=\"dpw-controls\">\n    <label class=\"dpw-label\">Alice's nonce k<sub>A</sub> &nbsp; <span class=\"dpw-val\" id=\"cc11i-av\"></span>\n      <input type=\"range\" id=\"cc11i-a\" min=\"1\" max=\"66\" value=\"5\" /></label>\n    <label class=\"dpw-label\">Bob's nonce k<sub>B</sub> &nbsp; <span class=\"dpw-val\" id=\"cc11i-bv\"></span>\n      <input type=\"range\" id=\"cc11i-b\" min=\"1\" max=\"66\" value=\"9\" /></label>\n  </div>\n  <div class=\"dpw-grid2\">\n    <div>\n      <div class=\"dpw-cap\">Schnorr needs: add, then use</div>\n      <div class=\"dpw-line\"><span>k<sub>A</sub> + k<sub>B</sub></span><span><b id=\"cc11i-s1\"></b></span></div>\n      <div class=\"dpw-line\"><span>the aggregate nonce</span><span><b id=\"cc11i-s2\"></b></span></div>\n    </div>\n    <div>\n      <div class=\"dpw-cap\">ECDSA would need: invert</div>\n      <div class=\"dpw-line\"><span>(k<sub>A</sub> + k<sub>B</sub>)<sup>&minus;1</sup> mod 67</span><span><b id=\"cc11i-e1\"></b></span></div>\n      <div class=\"dpw-line\"><span>k<sub>A</sub><sup>&minus;1</sup> + k<sub>B</sub><sup>&minus;1</sup> mod 67</span><span><b id=\"cc11i-e2\"></b></span></div>\n    </div>\n  </div>\n  <div class=\"dpw-verdict\" id=\"cc11i-v\"></div>\n  <div class=\"dpw-line\" style=\"margin-top:14px\"><span>pairs (k<sub>A</sub>, k<sub>B</sub>) mod 67 where the two inverses agree</span><span><b id=\"cc11i-c\"></b></span></div>\n  <div class=\"dpw-hint\">Every nonzero pair is checked exhaustively. They agree only when k<sub>A</sub><sup>2</sup> + k<sub>A</sub>k<sub>B</sub> + k<sub>B</sub><sup>2</sup> &equiv; 0, which for n = 67 happens for 2 of every 66 choices of k<sub>B</sub>: an accident, not a rule anyone could build a multisig on.</div>\n</div>\n<h2 id=\"ecdsa-multisig-one-signature-per-key\" style=\"position:relative;\"><a href=\"#ecdsa-multisig-one-signature-per-key\" aria-label=\"ecdsa multisig one signature per key 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>ECDSA multisig: one signature per key</h2>\n<p>If you want to have five people be part of a transaction, and if you want all five to sign that transaction, and if the five people don't sign, then the transaction doesn't go through, to enable that sort of behaviour, you need multisignatures. For ECDSA, it's quite messy. For the ECDSA multisig setup, you have to first list out all the public keys that are part of the multisignature, P<sub>1</sub>, P<sub>2</sub>, all the way up to P<sub>u</sub>. And each of these will have its own signature: signature one, signature two, signature u.</p>\n<p>The problem with ECDSA is there's no easy way to combine these. It's not the case that signature one plus signature two is equal to their values added. It's not linear in that regard. So what the code has to do is verify each signature individually. First you would have to verify whether signature one came from P<sub>1</sub>, whether signature two came from P<sub>2</sub>, and then if all those verifications pass, then the multisignature passes. There's no one signature which you can run that just verifies everyone's signature altogether. You have to do it one by one.</p>\n<h2 id=\"schnorr-multisig-just-add\" style=\"position:relative;\"><a href=\"#schnorr-multisig-just-add\" aria-label=\"schnorr multisig just add 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>Schnorr multisig: just add</h2>\n<p>With Schnorr, suppose we have two people, and let's call them Alice and Bob. They both have a private key, d<sub>A</sub> and d<sub>B</sub>, and they both have a public key, P<sub>A</sub> and P<sub>B</sub>. With Schnorr, the aggregate of the public keys is P<sub>A</sub> + P<sub>B</sub>, and the nonces can also just be added, so the aggregate will be R<sub>A</sub> + R<sub>B</sub>. That's not the case for ECDSA.</p>\n<div class=\"dpw-formula\">P<sub>agg</sub> = P<sub>A</sub> + P<sub>B</sub> &nbsp;&nbsp;&nbsp; R<sub>agg</sub> = R<sub>A</sub> + R<sub>B</sub> &nbsp;&nbsp;&nbsp; c = H(P<sub>agg</sub> &#8214; R<sub>agg</sub> &#8214; m)</div>\n<p>So we have a challenge value c, which is found from the aggregate of the public keys of Alice and Bob and the aggregate of the random nonce values. Now they can compute their s values. This would be a step that each of them would have to do, because they both have their own private keys. Alice would have to calculate her own s, because only she knows her private key.</p>\n<div class=\"dpw-formula\">s<sub>A</sub> = k<sub>A</sub> + c&middot;d<sub>A</sub> &nbsp;&nbsp;&nbsp; s<sub>B</sub> = k<sub>B</sub> + c&middot;d<sub>B</sub></div>\n<p>And now we can even find a combined signature s, which is s<sub>A</sub> + s<sub>B</sub>. If I move things around, I can factor out the c:</p>\n<div class=\"dpw-formula\">s = s<sub>A</sub> + s<sub>B</sub> = (k<sub>A</sub> + k<sub>B</sub>) + c&middot;(d<sub>A</sub> + d<sub>B</sub>)</div>\n<p>If you notice this equation, and if you notice the regular equation, which is s = k + c·d, you can see that as we are adding people, Alice and Bob in this case, we can just add the k's, and we can just add the private keys too. And c is a shared challenge value between all the people who are doing the signatures. Here it does scale linearly. By linearly, I mean if this is two and this is two, then the final answer is four. With modular inverse, that's not true.</p>\n<p>How do we find the verification now? It's exactly the same as this verify. What we're verifying is if s·G is equal to R<sub>agg</sub> + c·P<sub>agg</sub>. If I isolate R, then R<sub>agg</sub> = s·G − c·P<sub>agg</sub>.</p>\n<div class=\"dpw-formula\">R<sub>agg</sub> = s&middot;G &minus; c&middot;P<sub>agg</sub></div>\n<div class=\"dpw\" id=\"cc11-add\">\n  <div class=\"dpw-q\">Add Alice's and Bob's signatures. Does the sum verify as one signature?</div>\n  <div class=\"dpw-detail-b\">Toy curve y<sup>2</sup> = x<sup>3</sup> + 7 over F<sub>79</sub>, the same equation as secp256k1. It has 67 points, a prime, so n = 67. The hash is a toy hash reduced mod n.</div>\n  <div class=\"dpw-toggle-row\" style=\"margin-top:12px\">\n    <button class=\"dpw-toggle\" id=\"cc11a-new\">new keys and nonces</button>\n    <label class=\"dpw-label\" style=\"display:flex;align-items:center;gap:8px\">message m\n      <input class=\"dpw-input\" id=\"cc11a-m\" type=\"number\" value=\"21\" /></label>\n  </div>\n  <table class=\"dpw-table\" style=\"margin-top:8px\">\n    <tr><th></th><th>Alice</th><th>Bob</th></tr>\n    <tr><td>private key d</td><td class=\"dpw-mono\" id=\"cc11a-da\"></td><td class=\"dpw-mono\" id=\"cc11a-db\"></td></tr>\n    <tr><td>public key P = d&middot;G</td><td class=\"dpw-mono\" id=\"cc11a-pa\"></td><td class=\"dpw-mono\" id=\"cc11a-pb\"></td></tr>\n    <tr><td>nonce k, R = k&middot;G</td><td class=\"dpw-mono\" id=\"cc11a-ra\"></td><td class=\"dpw-mono\" id=\"cc11a-rb\"></td></tr>\n  </table>\n  <div class=\"dpw-grid2\" style=\"margin-top:12px\">\n    <div>\n      <div class=\"dpw-cap\">Schnorr</div>\n      <div class=\"dpw-line\"><span>c = H(P<sub>agg</sub>, R<sub>agg</sub>, m)</span><span><b id=\"cc11a-sc\"></b></span></div>\n      <div class=\"dpw-line\"><span>s<sub>A</sub>, s<sub>B</sub></span><span><b id=\"cc11a-ss\"></b></span></div>\n      <div class=\"dpw-line\"><span>s = s<sub>A</sub> + s<sub>B</sub></span><span><b id=\"cc11a-s\"></b></span></div>\n      <div class=\"dpw-line\"><span>s&middot;G &minus; c&middot;P<sub>agg</sub></span><span><b id=\"cc11a-sr\"></b></span></div>\n      <div class=\"dpw-line\"><span>R<sub>agg</sub></span><span><b id=\"cc11a-sra\"></b></span></div>\n      <div class=\"dpw-verdict\" id=\"cc11a-sv\"></div>\n    </div>\n    <div>\n      <div class=\"dpw-cap\">ECDSA</div>\n      <div class=\"dpw-line\"><span>H(m)</span><span><b id=\"cc11a-ec\"></b></span></div>\n      <div class=\"dpw-line\"><span>s<sub>A</sub>, s<sub>B</sub> (each verifies alone)</span><span><b id=\"cc11a-es\"></b></span></div>\n      <div class=\"dpw-line\"><span>s = s<sub>A</sub> + s<sub>B</sub></span><span><b id=\"cc11a-e\"></b></span></div>\n      <div class=\"dpw-line\"><span>x of R&prime; from s, P<sub>agg</sub></span><span><b id=\"cc11a-er\"></b></span></div>\n      <div class=\"dpw-line\"><span>x of R<sub>agg</sub></span><span><b id=\"cc11a-era\"></b></span></div>\n      <div class=\"dpw-verdict\" id=\"cc11a-ev\"></div>\n    </div>\n  </div>\n  <div class=\"dpw-readout\">\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc11a-rs\">0 / 0</span><span class=\"dpw-cap\">Schnorr sums that verified</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc11a-re\">0 / 0</span><span class=\"dpw-cap\">ECDSA sums that verified</span></div>\n  </div>\n  <div class=\"dpw-hint\">Keep pressing \"new keys and nonces\". The Schnorr sum verifies every time. The ECDSA sum only passes when the x-coordinates collide by luck, about 1 time in 30 on this 67-point curve (each x-coordinate belongs to two points), and essentially never on secp256k1.</div>\n</div>\n<h2 id=\"doesnt-that-make-it-easier-for-the-attacker-too\" style=\"position:relative;\"><a href=\"#doesnt-that-make-it-easier-for-the-attacker-too\" aria-label=\"doesnt that make it easier for the attacker too 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>\"Doesn't that make it easier for the attacker too?\"</h2>\n<p>Someone asked: if we make verification easier by making it linear, don't we make it easier for an attacker as well, and which scheme is safer?</p>\n<p>What I have on the screen right now is not safe, and you are right to doubt it. With the Schnorr one, there's a very big problem here. If we have five people who are doing a multisignature, with this scheme right now, I could just disregard the signatures of all the other four, and I could be the only one providing signatures, and verification would pass. Let me first write this, otherwise people would think this is correct: this is not safe.</p>\n<p>How one signer does that, the rogue-key attack, and how MuSig2 keeps the addition while stopping it, is next week.</p>\n<style>\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 {\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; color: var(--ink);\n}\n.dpw * { box-sizing: border-box; }\n.dpw-q { font-family: 'Josefin Sans', sans-serif; font-size: 14px; text-transform: uppercase; letter-spacing: .04em;\n  color: var(--maroon-d); margin: 0 0 12px; line-height: 1.4; }\n.dpw-controls { margin-bottom: 14px; display: grid; gap: 12px; }\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-verdict.dpw-neutral { background: #e3ecf4; color: #3d566b; }\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 */\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: 6px; }\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-toggle:disabled { opacity: .45; cursor: default; }\n.dpw-detail { border: 1px solid var(--line); border-radius: 5px; padding: 13px 14px; margin-top: 10px; }\n.dpw-detail-h { font-family: 'Josefin Sans', sans-serif; font-size: 13px; text-transform: uppercase;\n  letter-spacing: .04em; color: var(--maroon-d); margin-bottom: 7px; }\n.dpw-detail-b { font-size: 13px; color: var(--ink2); line-height: 1.6; }\n.dpw-line { font-size: 13px; color: var(--ink2); margin: 9px 0; display: flex; justify-content: space-between;\n  align-items: baseline; gap: 10px; flex-wrap: wrap; }\n.dpw-line b { font-family: 'Inconsolata', monospace; font-size: 15px; color: var(--ink); font-weight: 700; }\n.dpw-mono { font-family: 'Inconsolata', monospace; }\n.dpw-input { font-family: 'Inconsolata', monospace; font-size: 14px; border: 1px solid var(--line); border-radius: 4px;\n  padding: 5px 8px; width: 80px; color: var(--ink); }\n.dpw-chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0; }\n.dpw-chip { font-family: 'Inconsolata', monospace; font-size: 12px; padding: 3px 7px; border-radius: 3px;\n  background: #f4f7fa; border: 1px solid var(--line); color: var(--ink); }\n.dpw-chip.dpw-chip-hot { background: #dcefe3; border-color: #b9dcc5; color: var(--green); }\n.dpw-chip.dpw-chip-bad { background: var(--rose); border-color: #e7b3b1; color: var(--maroon-d); }\n.dpw-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }\n.dpw-table { width: 100%; border-collapse: collapse; font-size: 13px; display: block; overflow-x: auto; }\n.dpw-table td, .dpw-table th { padding: 5px 6px; border-bottom: 1px solid #eef3f7; text-align: left; }\n/* table headers hold maths: f(3) must not become F(3) */\n.dpw-table th { font-size: 11px; color: var(--ink2); text-transform: none; letter-spacing: .04em; font-weight: 600; }\n.dpw-table td.dpw-mono { white-space: nowrap; }\n@media (max-width: 560px) { .dpw { padding: 14px; } .dpw-grid2 { 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('cc11-inv');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { 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  var $ = function (id) { return root.querySelector('#' + id); };\n  var N = 67;\n  function inv(a) { a = ((a % N) + N) % N; if (!a) return null; var r = 1, b = a, e = N - 2; while (e) { if (e & 1) r = r * b % N; b = b * b % N; e >>= 1; } return r; }\n  var agree = 0, total = 0;\n  for (var a = 1; a < N; a++) for (var b = 1; b < N; b++) {\n    if ((a + b) % N === 0) continue;\n    total++;\n    if (inv(a + b) === (inv(a) + inv(b)) % N) agree++;\n  }\n  $('cc11i-c').textContent = agree + ' of ' + total.toLocaleString();\n  function draw() {\n    var a = +$('cc11i-a').value, b = +$('cc11i-b').value;\n    $('cc11i-av').textContent = a; $('cc11i-bv').textContent = b;\n    var sum = (a + b) % N;\n    $('cc11i-s1').textContent = a + ' + ' + b + ' = ' + sum;\n    $('cc11i-s2').textContent = sum ? sum : '0 (degenerate)';\n    var i1 = inv(sum), i2 = (inv(a) + inv(b)) % N;\n    $('cc11i-e1').textContent = i1 === null ? 'undefined' : i1;\n    $('cc11i-e2').textContent = inv(a) + ' + ' + inv(b) + ' = ' + i2;\n    var v = $('cc11i-v');\n    if (i1 === i2) { v.className = 'dpw-verdict dpw-neutral'; v.innerHTML = 'They happen to agree here. Move a slider by one.'; }\n    else { v.className = 'dpw-verdict'; v.innerHTML = '' + (i1 === null ? 'undefined' : i1) + ' &ne; ' + i2 + ': inverses do not add'; }\n  }\n  on($('cc11i-a'), 'input', draw); on($('cc11i-b'), 'input', draw);\n  draw();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('cc11-add');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { 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  var $ = function (id) { return root.querySelector('#' + id); };\n  // y^2 = x^3 + 7 over F_79: 67 points (prime), so every non-identity point generates the group\n  var Pm = 79, N = 67;\n  function md(a, m) { a %= m; return a < 0 ? a + m : a; }\n  function pw(b, e, m) { b = md(b, m); var r = 1; while (e) { if (e & 1) r = r * b % m; b = b * b % m; e >>= 1; } return r; }\n  function inv(a, m) { return pw(a, m - 2, m); }\n  function add(A, B) {\n    if (!A) return B; if (!B) return A;\n    if (A[0] === B[0] && md(A[1] + B[1], Pm) === 0) return null;\n    var l = A[0] === B[0] ? md(3 * A[0] * A[0] * inv(2 * A[1], Pm), Pm) : md((B[1] - A[1]) * inv(md(B[0] - A[0], Pm), Pm), Pm);\n    var x = md(l * l - A[0] - B[0], Pm);\n    return [x, md(l * (A[0] - x) - A[1], Pm)];\n  }\n  function mul(k, A) { k = md(k, N); var R = null; while (k) { if (k & 1) R = add(R, A); A = add(A, A); k >>= 1; } return R; }\n  function neg(A) { return A ? [A[0], md(-A[1], Pm)] : null; }\n  var G = null;\n  for (var x = 0; x < Pm && !G; x++) for (var y = 1; y < Pm; y++) if (md(y * y - x * x * x - 7, Pm) === 0) { G = [x, y]; break; }\n  function H() { var s = Array.prototype.join.call(arguments, '|'), h = 2166136261; for (var i = 0; i < s.length; i++) { h ^= s.charCodeAt(i); h = Math.imul(h, 16777619) >>> 0; } return h % N; }\n  function fmt(A) { return A ? '(' + A[0] + ', ' + A[1] + ')' : 'O'; }\n  function r1() { return 1 + Math.floor(Math.random() * (N - 1)); }\n  var st, tally = { s: 0, e: 0, n: 0 };\n  function fresh() {\n    var k;\n    st = { da: r1(), db: r1(), ka: r1(), kb: r1() };\n    // ECDSA needs x_R != 0 mod n and s != 0; retry the rare bad draws\n    draw(true);\n  }\n  function draw(count) {\n    var m = Math.round(+$('cc11a-m').value) || 0;\n    var PA = mul(st.da, G), PB = mul(st.db, G), RA = mul(st.ka, G), RB = mul(st.kb, G);\n    var Pagg = add(PA, PB), Ragg = add(RA, RB);\n    if (!Pagg || !Ragg || !RA || !RB) { fresh(); return; }\n    $('cc11a-da').textContent = st.da; $('cc11a-db').textContent = st.db;\n    $('cc11a-pa').textContent = fmt(PA); $('cc11a-pb').textContent = fmt(PB);\n    $('cc11a-ra').textContent = st.ka + ', ' + fmt(RA); $('cc11a-rb').textContent = st.kb + ', ' + fmt(RB);\n    // Schnorr\n    var c = H(Pagg[0], Ragg[0], m);\n    var sA = md(st.ka + c * st.da, N), sB = md(st.kb + c * st.db, N), s = md(sA + sB, N);\n    var Rp = add(mul(s, G), neg(mul(c, Pagg)));\n    var okS = Rp && Rp[0] === Ragg[0] && Rp[1] === Ragg[1];\n    $('cc11a-sc').textContent = c; $('cc11a-ss').textContent = sA + ', ' + sB; $('cc11a-s').textContent = s;\n    $('cc11a-sr').textContent = fmt(Rp); $('cc11a-sra').textContent = fmt(Ragg);\n    var sv = $('cc11a-sv'); sv.className = okS ? 'dpw-verdict dpw-ok' : 'dpw-verdict';\n    sv.innerHTML = '' + (okS ? 'equal &rarr; one signature, accept' : 'reject') + '';\n    // ECDSA: each signs with its own key and nonce\n    var e = H(m), xa = md(RA[0], N), xb = md(RB[0], N);\n    var eA = md(inv(st.ka, N) * (e + xa * st.da), N), eB = md(inv(st.kb, N) * (e + xb * st.db), N);\n    if (!xa || !xb || !eA || !eB) { fresh(); return; }\n    var es = md(eA + eB, N);\n    $('cc11a-ec').textContent = e; $('cc11a-es').textContent = eA + ', ' + eB; $('cc11a-e').textContent = es;\n    var xr = md(Ragg[0], N), okE = false, txt = 's = 0, undefined';\n    if (es) {\n      var w = inv(es, N);\n      var Rq = add(mul(md(e * w, N), G), mul(md(xr * w, N), Pagg));\n      okE = !!Rq && md(Rq[0], N) === xr;\n      txt = Rq ? String(md(Rq[0], N)) : 'O';\n    }\n    $('cc11a-er').textContent = txt; $('cc11a-era').textContent = xr;\n    var ev = $('cc11a-ev'); ev.className = okE ? 'dpw-verdict dpw-neutral' : 'dpw-verdict';\n    ev.innerHTML = '' + (okE ? 'passed, by coincidence: this curve only has 67 points' : 'different &rarr; the sum is not a signature') + '';\n    if (count) { tally.n++; if (okS) tally.s++; if (okE) tally.e++; }\n    $('cc11a-rs').textContent = tally.s + ' / ' + tally.n; $('cc11a-re').textContent = tally.e + ' / ' + tally.n;\n  }\n  on($('cc11a-new'), 'click', fresh);\n  on($('cc11a-m'), 'input', function () { draw(false); });\n  fresh();\n})();\n</script>","headings":[{"value":"Schnorr","depth":2},{"value":"ECDSA","depth":2},{"value":"The modular inverse makes things hard","depth":2},{"value":"ECDSA multisig: one signature per key","depth":2},{"value":"Schnorr multisig: just add","depth":2},{"value":"\"Doesn't that make it easier for the attacker too?\"","depth":2}],"frontmatter":{"date_created":"2026-10-16","path":"/blog/crypto-club-why-schnorr-adds-up","tags":["Cryptography","Bitcoin","Digital Signatures"],"title":"Why Schnorr Signatures Add Up And ECDSA Signatures Do Not"}},"nextPost":{"html":"<p>Last week we talked about how, with ECDSA, it's not very obvious to do multi-signatures, but with Schnorr signatures it's very, very simple, as simple as adding. And we left off with a type of attack that was possible in a multi-signature setting if we construct multi-signatures in a naive way.</p>\n<p>Multi-signatures are a type of setting where a group of people would get together, and only when all of them have signed the transaction will the transaction be approved. Even if one person does not sign, the transaction will not be approved. This has many use cases. Suppose you want more accountability. You don't want one person to hold all the power, so you distribute the keys and you sign in a sort of consortium manner.</p>\n<h2 id=\"the-naive-way\" style=\"position:relative;\"><a href=\"#the-naive-way\" aria-label=\"the naive way 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 naive way</h2>\n<p>Let's say there are two people, Alice and Bob, and both of them need to take part in this multi-signature. Alice has a public key Y<sub>A</sub> = x<sub>A</sub>·G, Bob has the public key Y<sub>B</sub> = x<sub>B</sub>·G, and then the aggregate key Y<sub>agg</sub> is just Y<sub>A</sub> + Y<sub>B</sub>.</p>\n<div class=\"dpw-formula\">Y<sub>agg</sub> = Y<sub>A</sub> + Y<sub>B</sub> = (x<sub>A</sub> + x<sub>B</sub>)&middot;G</div>\n<p>This is the naive way of combining their individual public keys to create an aggregate public key, which now requires both Alice and Bob to sign in order to have successful verification.</p>\n<h2 id=\"the-rogue-key-attack\" style=\"position:relative;\"><a href=\"#the-rogue-key-attack\" aria-label=\"the rogue key attack 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 rogue-key attack</h2>\n<p>Alice outputs their public key like an honest participant. But Bob, now that they know Alice's public key, what they do to calculate their public key is not this regular equation. They just take their private key times G, minus the public key of Alice.</p>\n<div class=\"dpw-formula\">Y<sub>B,rogue</sub> = x<sub>B</sub>&middot;G &minus; Y<sub>A</sub></div>\n<p>So what happens now when we calculate Y<sub>agg</sub>? Y<sub>A</sub> stays the same, but Y<sub>B</sub> is x<sub>B</sub>·G − Y<sub>A</sub>, so the sum Y<sub>A</sub> + (x<sub>B</sub>·G − Y<sub>A</sub>) is equal to x<sub>B</sub>·G, because the two Y<sub>A</sub> terms cancel out. So Alice's involvement in the aggregate key has been completely cancelled out. And this is Bob's public key, which means that he knows the private key. So for any signature to happen, he doesn't need Alice's permission. He can just keep on signing things, and the multi-signature scheme is pretty much useless in that case.</p>\n<p>Let's say x<sub>A</sub> is five, just for example purposes, so Alice's public key is 5G, and Bob's is 2G. Alice would just say, \"Hey, my public key is 5G.\" But Bob, seeing Alice's public key, would be like, \"Actually, my public key is not 2G. It's 2G − 5G = −3G.\" So now Y<sub>agg</sub> is 5G + (−3G), which is equal to 2G. And we know that Bob's real public key is actually 2G, whose private key he knows. Bob knows the private key of Y<sub>agg</sub> and can sign anything now.</p>\n<div class=\"dpw\" id=\"cc12-rogue\">\n  <div class=\"dpw-q\">Can Bob sign for the pair on his own?</div>\n  <div class=\"dpw-detail-b\">Toy curve y<sup>2</sup> = x<sup>3</sup> + 7 over F<sub>79</sub> (67 points, so n = 67). Bob tries to sign a transaction alone with his own private key, as a normal single-key Schnorr signature against Y<sub>agg</sub>. The hash is a toy hash reduced mod n.</div>\n  <div class=\"dpw-toggle-row\" style=\"margin-top:12px\">\n    <span class=\"dpw-toggle-cap\">key aggregation</span>\n    <button class=\"dpw-toggle\" id=\"cc12r-naive\" data-on=\"true\">naive: Y<sub>A</sub> + Y<sub>B</sub></button>\n    <button class=\"dpw-toggle\" id=\"cc12r-musig\" data-on=\"false\">MuSig2: a<sub>A</sub>Y<sub>A</sub> + a<sub>B</sub>Y<sub>B</sub></button>\n  </div>\n  <div class=\"dpw-toggle-row\">\n    <span class=\"dpw-toggle-cap\">what Bob publishes</span>\n    <button class=\"dpw-toggle\" id=\"cc12r-honest\" data-on=\"false\">honest: x<sub>B</sub>&middot;G</button>\n    <button class=\"dpw-toggle\" id=\"cc12r-evil\" data-on=\"true\">rogue: x<sub>B</sub>&middot;G &minus; Y<sub>A</sub></button>\n    <button class=\"dpw-toggle\" id=\"cc12r-new\">new keys</button>\n  </div>\n  <div class=\"dpw-line\"><span>Alice's public key Y<sub>A</sub> (x<sub>A</sub> stays with Alice)</span><span><b id=\"cc12r-ya\"></b></span></div>\n  <div class=\"dpw-line\"><span>Bob's real key x<sub>B</sub>&middot;G</span><span><b id=\"cc12r-yb\"></b></span></div>\n  <div class=\"dpw-line\"><span>key Bob publishes</span><span><b id=\"cc12r-pub\"></b></span></div>\n  <div class=\"dpw-line\"><span>coefficients a<sub>A</sub>, a<sub>B</sub></span><span><b id=\"cc12r-co\"></b></span></div>\n  <div class=\"dpw-line\"><span>Y<sub>agg</sub></span><span><b id=\"cc12r-agg\"></b></span></div>\n  <div class=\"dpw-line\"><span>Bob's solo signature: s&middot;G vs R + c&middot;Y<sub>agg</sub></span><span><b id=\"cc12r-chk\"></b></span></div>\n  <div class=\"dpw-verdict\" id=\"cc12r-v\"></div>\n</div>\n<h2 id=\"how-do-we-prevent-this\" style=\"position:relative;\"><a href=\"#how-do-we-prevent-this\" aria-label=\"how do we prevent this 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 do we prevent this?</h2>\n<p>How can we still exploit this very nice property of addition that Schnorr signatures give us to do multi-signatures without falling prey to these types of rogue-key attacks? Are there any ideas?</p>\n<p>Two ideas came from the room: a coordinator who collects everyone's keys before anyone sees anyone else's, and a commitment to the public key sent before the key itself.</p>\n<p>A coordinator, that's a good thought. This is actually common in many protocols. Just one thing that comes to my head right now, without any research: it requires more rounds of communication. This coordinator has to be online when everyone is sharing their key. Basically, it requires more synchronous activity. We're also blocked in the sense that this person is not able to just calculate the aggregate themselves offline. They now have this guy as their gatekeeper, and they have to wait for them. Even with MuSig2, the upgrade from MuSig1: MuSig1 requires more rounds of communication, I think three rounds, and MuSig2 only requires two rounds of communication. And that's seen as a good thing. The less live interaction there is between all the participants, the better.</p>\n<p>Commitment makes a lot of sense. You have to first ask yourself, what are we trying to discourage? We're trying to discourage Bob from changing their public key once they see Alice's public key. If we're able to get Bob and Alice and anyone else to commit to some public key beforehand, then there's no way someone like Bob could change the key later on, once more information has become available to him, which would be everyone else's public keys.</p>\n<p>It's like a theme. You should try to take away this theme from this: what is a commitment solving? What is a hash function solving? It's helping preserve order, the order of steps. Because if we don't preserve the order, then malicious things like this can happen. Earlier we talked about what happens if order is not preserved: if c is calculated before R, then Alice, without even having a private key, can pass the verification. So the general theme is: the hash function will help with maintaining the order of operations.</p>\n<h2 id=\"musig2-key-aggregation\" style=\"position:relative;\"><a href=\"#musig2-key-aggregation\" aria-label=\"musig2 key aggregation 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>MuSig2 key aggregation</h2>\n<p>There's this signature scheme called MuSig2, which I think stands for multi-signature two, which prevents this attack. Instead of just adding the public keys like we did, both of them combine their keys into a list and hash it. So now we have this new variable called L, which is just a hash of the entire list of keys.</p>\n<div class=\"dpw-formula\">L = H(Y<sub>A</sub> &#8214; Y<sub>B</sub>)</div>\n<p>For Alice, this value we'll call a<sub>A</sub>. It's the hash of the list and Alice's public key. Remember, the list already contains both of their public keys. And for Bob, it's the same thing: a<sub>B</sub> is a hash of this list concatenated with his public key.</p>\n<div class=\"dpw-formula\">a<sub>A</sub> = H(L &#8214; Y<sub>A</sub>) &nbsp;&nbsp;&nbsp; a<sub>B</sub> = H(L &#8214; Y<sub>B</sub>)</div>\n<p>And now, how do we calculate Y<sub>agg</sub>? It would be Alice's coefficient times Alice's public key plus Bob's coefficient times Bob's public key. So the only difference is we do the same addition, Y<sub>A</sub> + Y<sub>B</sub>, but we multiply each of their public keys by some coefficient. You could generalise to say Y<sub>agg</sub> is the sum over participants of a<sub>i</sub>·Y<sub>i</sub>.</p>\n<div class=\"dpw-formula\">Y<sub>agg</sub> = a<sub>A</sub>&middot;Y<sub>A</sub> + a<sub>B</sub>&middot;Y<sub>B</sub> = &Sigma; a<sub>i</sub>&middot;Y<sub>i</sub></div>\n<h2 id=\"why-that-stops-bob\" style=\"position:relative;\"><a href=\"#why-that-stops-bob\" aria-label=\"why that stops bob 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 that stops Bob</h2>\n<p>We've added hashes in a bunch of places, but what is it actually doing? Take the same key examples: Y<sub>A</sub> was 5G and Y<sub>B</sub> was 2G. Here Bob is providing their actual public key, because they're just giving it to this list function. Suppose a<sub>A</sub> comes out to be three, and suppose a<sub>B</sub> comes out to be four. So now Y<sub>agg</sub> is going to be 3·5G + 4·2G = 15G + 8G = 23G.</p>\n<div class=\"dpw-formula\">Y<sub>agg</sub> = 3&middot;5G + 4&middot;2G = 23G</div>\n<p>Bob can only sign transactions that have a public key of 2G, because that's the only one he can actually sign individually, which contains his own private key. He would need this coefficient times 5G, even knowing Alice's public key, plus this coefficient times some value. This is what Bob wants to find: what can I put here so that after doing everything, Y<sub>agg</sub> is 2G?</p>\n<p>But the problem is he can't figure that out. Listen carefully: these two coefficients can only be calculated after Bob commits to a public key, and they reference that through this L. The intention is very similar to how the c value can only be calculated after k is calculated, because the hash function takes that as an input. We can't calculate the output of something if we don't even know the input, especially with hash functions, because they're one way. With hash functions, we know that they're very hard to reverse. So this is pretty much the trick that MuSig2 uses for key aggregation.</p>\n<div class=\"dpw\" id=\"cc12-grind\">\n  <div class=\"dpw-q\">If Bob keeps trying rogue keys under MuSig2, how many tries until one works?</div>\n  <div class=\"dpw-detail-b\">Bob's only move is trial and error: pick a candidate key Y<sub>B</sub>&prime; = x&middot;G &minus; u&middot;Y<sub>A</sub>, hash, and hope the coefficients come out with a<sub>A</sub> = u&middot;a<sub>B</sub>, which is the one case where Alice's key cancels. Each candidate changes L, so each try is a fresh roll of an n-sided die.</div>\n  <div class=\"dpw-toggle-row\" style=\"margin-top:12px\">\n    <button class=\"dpw-toggle\" id=\"cc12g-run\">let Bob grind on the toy curve</button>\n  </div>\n  <div class=\"dpw-readout\">\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc12g-t\">&ndash;</span><span class=\"dpw-cap\">tries this run</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc12g-avg\">&ndash;</span><span class=\"dpw-cap\">average over runs</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\">67</span><span class=\"dpw-cap\"><span class=\"dpw-var\">n</span> on the toy curve</span></div>\n  </div>\n  <div class=\"dpw-line\"><span>winning rogue key, and Bob's solo signature against Y<sub>agg</sub></span><span><b id=\"cc12g-w\">&ndash;</b></span></div>\n  <div class=\"dpw-controls\" style=\"margin-top:12px\">\n    <label class=\"dpw-label\">Bob's hashing speed (hashes per second) &nbsp; <span class=\"dpw-val\" id=\"cc12g-rv\"></span>\n      <input type=\"range\" id=\"cc12g-r\" min=\"6\" max=\"24\" value=\"12\" /></label>\n  </div>\n  <div class=\"dpw-line\"><span>expected time on secp256k1 (n &asymp; 2<sup>256</sup>)</span><span><b id=\"cc12g-y\"></b></span></div>\n  <div class=\"dpw-verdict dpw-ok\" id=\"cc12g-v\">On the toy curve he wins in about 67 tries. On the real curve the same plan needs about 2<sup>256</sup>.</div>\n  <div class=\"dpw-hint\">The toy curve is breakable precisely because n is tiny. The protection is not that the hash is clever, but that its output is unpredictable until Bob has committed, and there are 2<sup>256</sup> outputs to hit.</div>\n</div>\n<h2 id=\"signing\" style=\"position:relative;\"><a href=\"#signing\" aria-label=\"signing 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>Signing</h2>\n<p>Now that Y<sub>agg</sub> is calculated, what do we need next? We need an R value, the random nonce, and this must be generated by both Alice and Bob. But here we need to generate two random nonces each. I'm not going to go over it, but you're welcome to look at why this is the case. It's to prevent something called Wagner's birthday attack.</p>\n<p>So Alice will find k<sub>A1</sub> and k<sub>A2</sub>, both coming from a random distribution, and Bob will do the same thing, k<sub>B1</sub> and k<sub>B2</sub>. And then they both calculate the R values. Here we found just one k and one R, but now we have two k's, so we have two R's. R<sub>A1</sub> = k<sub>A1</sub>·G, R<sub>A2</sub> = k<sub>A2</sub>·G, and for Bob it's the same thing. And they both exchange these. This is all broadcast publicly. There's nothing secret about this.</p>\n<p>But now they combine everything and calculate a value b, which is a hash of pretty much everything they've seen so far: Y<sub>agg</sub>, R<sub>A1</sub>, R<sub>A2</sub>, R<sub>B1</sub>, R<sub>B2</sub> and the message.</p>\n<div class=\"dpw-formula\">b = H(Y<sub>agg</sub> &#8214; R<sub>A1</sub> &#8214; R<sub>A2</sub> &#8214; R<sub>B1</sub> &#8214; R<sub>B2</sub> &#8214; m)</div>\n<p>Similar to how we found Y<sub>agg</sub>, we have to find R<sub>agg</sub>, because ultimately the signature scheme only needs one public key and one random nonce. We're adding the first of both and multiplying, or scaling, the second one by b, which is our hash of everything we've seen so far. It has the same intuition. We want to commit things early on so that even the R<sub>agg</sub> value cannot be changed later. Although I'm not exactly sure what Wagner's birthday attack is doing.</p>\n<div class=\"dpw-formula\">R<sub>agg</sub> = (R<sub>A1</sub> + R<sub>B1</sub>) + b&middot;(R<sub>A2</sub> + R<sub>B2</sub>)</div>\n<p>Now we have to find c, which is the challenge. c here is the same thing as before, except we're using the aggregate values: R<sub>agg</sub>, Y<sub>agg</sub> and the message.</p>\n<div class=\"dpw-formula\">c = H(R<sub>agg</sub> &#8214; Y<sub>agg</sub> &#8214; m)</div>\n<p>The last step is calculating the signature equation. Both Alice and Bob will need to do this individually. The regular equation was s = k + c·x. Here, k is now k<sub>A1</sub> + b·k<sub>A2</sub>. Again, we're using these previously committed values. And what is the private key? It's not simply just x<sub>A</sub>. It's going to be a<sub>A</sub>·x<sub>A</sub>, with the coefficient from before. So this still corresponds to k, this still corresponds to x. We just have a few extra variables. Then Bob does the exact same thing, and the aggregate signature is just s = s<sub>A</sub> + s<sub>B</sub>.</p>\n<div class=\"dpw-formula\">s<sub>A</sub> = (k<sub>A1</sub> + b&middot;k<sub>A2</sub>) + c&middot;(a<sub>A</sub>&middot;x<sub>A</sub>) &nbsp;&nbsp;&nbsp; s = s<sub>A</sub> + s<sub>B</sub></div>\n<style>\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 {\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; color: var(--ink);\n}\n.dpw * { box-sizing: border-box; }\n.dpw-q { font-family: 'Josefin Sans', sans-serif; font-size: 14px; text-transform: uppercase; letter-spacing: .04em;\n  color: var(--maroon-d); margin: 0 0 12px; line-height: 1.4; }\n.dpw-controls { margin-bottom: 14px; display: grid; gap: 12px; }\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-verdict.dpw-neutral { background: #e3ecf4; color: #3d566b; }\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 */\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: 6px; }\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-toggle:disabled { opacity: .45; cursor: default; }\n.dpw-detail { border: 1px solid var(--line); border-radius: 5px; padding: 13px 14px; margin-top: 10px; }\n.dpw-detail-h { font-family: 'Josefin Sans', sans-serif; font-size: 13px; text-transform: uppercase;\n  letter-spacing: .04em; color: var(--maroon-d); margin-bottom: 7px; }\n.dpw-detail-b { font-size: 13px; color: var(--ink2); line-height: 1.6; }\n.dpw-line { font-size: 13px; color: var(--ink2); margin: 9px 0; display: flex; justify-content: space-between;\n  align-items: baseline; gap: 10px; flex-wrap: wrap; }\n.dpw-line b { font-family: 'Inconsolata', monospace; font-size: 15px; color: var(--ink); font-weight: 700; }\n.dpw-mono { font-family: 'Inconsolata', monospace; }\n.dpw-input { font-family: 'Inconsolata', monospace; font-size: 14px; border: 1px solid var(--line); border-radius: 4px;\n  padding: 5px 8px; width: 80px; color: var(--ink); }\n.dpw-chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0; }\n.dpw-chip { font-family: 'Inconsolata', monospace; font-size: 12px; padding: 3px 7px; border-radius: 3px;\n  background: #f4f7fa; border: 1px solid var(--line); color: var(--ink); }\n.dpw-chip.dpw-chip-hot { background: #dcefe3; border-color: #b9dcc5; color: var(--green); }\n.dpw-chip.dpw-chip-bad { background: var(--rose); border-color: #e7b3b1; color: var(--maroon-d); }\n.dpw-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }\n.dpw-table { width: 100%; border-collapse: collapse; font-size: 13px; display: block; overflow-x: auto; }\n.dpw-table td, .dpw-table th { padding: 5px 6px; border-bottom: 1px solid #eef3f7; text-align: left; }\n/* table headers hold maths: f(3) must not become F(3) */\n.dpw-table th { font-size: 11px; color: var(--ink2); text-transform: none; letter-spacing: .04em; font-weight: 600; }\n.dpw-table td.dpw-mono { white-space: nowrap; }\n@media (max-width: 560px) { .dpw { padding: 14px; } .dpw-grid2 { 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  // shared toy-curve helpers for this post: y^2 = x^3 + 7 over F_79, 67 points\n  var Pm = 79, N = 67;\n  function md(a, m) { a %= m; return a < 0 ? a + m : a; }\n  function pw(b, e, m) { b = md(b, m); var r = 1; while (e) { if (e & 1) r = r * b % m; b = b * b % m; e >>= 1; } return r; }\n  function inv(a, m) { return pw(a, m - 2, m); }\n  function add(A, B) {\n    if (!A) return B; if (!B) return A;\n    if (A[0] === B[0] && md(A[1] + B[1], Pm) === 0) return null;\n    var l = A[0] === B[0] ? md(3 * A[0] * A[0] * inv(2 * A[1], Pm), Pm) : md((B[1] - A[1]) * inv(md(B[0] - A[0], Pm), Pm), Pm);\n    var x = md(l * l - A[0] - B[0], Pm);\n    return [x, md(l * (A[0] - x) - A[1], Pm)];\n  }\n  function mul(k, A) { k = md(k, N); var R = null; while (k) { if (k & 1) R = add(R, A); A = add(A, A); k >>= 1; } return R; }\n  function neg(A) { return A ? [A[0], md(-A[1], Pm)] : null; }\n  function eq(A, B) { return (!A && !B) || (A && B && A[0] === B[0] && A[1] === B[1]); }\n  var G = null;\n  for (var x = 0; x < Pm && !G; x++) for (var y = 1; y < Pm; y++) if (md(y * y - x * x * x - 7, Pm) === 0) { G = [x, y]; break; }\n  function H() { var s = Array.prototype.map.call(arguments, function (a) { return Array.isArray(a) ? a.join(',') : String(a); }).join('|'), h = 2166136261;\n    for (var i = 0; i < s.length; i++) { h ^= s.charCodeAt(i); h = Math.imul(h, 16777619) >>> 0; } return 1 + h % (N - 1); }\n  function fmt(A) { return A ? '(' + A[0] + ', ' + A[1] + ')' : 'O'; }\n  function dlog(A) { for (var k = 0; k < N; k++) if (eq(mul(k, G), A)) return k; return -1; }\n  function r1() { return 1 + Math.floor(Math.random() * (N - 1)); }\n  // Bob signs alone with secret `sk` against public key `Y`; returns whether Schnorr verification passes\n  function soloSign(sk, Y, m) {\n    var k = r1(), R = mul(k, G), c = H(R, Y, m), s = md(k + c * sk, N);\n    return { ok: eq(mul(s, G), add(R, mul(c, Y))), lhs: mul(s, G), rhs: add(R, mul(c, Y)) };\n  }\n  window.__cc12 = { N: N, G: G, md: md, add: add, mul: mul, neg: neg, eq: eq, H: H, fmt: fmt, dlog: dlog, r1: r1, soloSign: soloSign };\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('cc12-rogue');\n  if (!root || !window.__cc12) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { 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  var Z = window.__cc12, $ = function (id) { return root.querySelector('#' + id); };\n  var musig = false, rogue = true, xa, xb;\n  function fresh() { do { xa = Z.r1(); xb = Z.r1(); } while (xa === xb); draw(); }\n  function draw() {\n    var YA = Z.mul(xa, Z.G), YBreal = Z.mul(xb, Z.G);\n    var YB = rogue ? Z.add(YBreal, Z.neg(YA)) : YBreal;\n    if (!YB) { fresh(); return; }\n    var aA = 1, aB = 1;\n    if (musig) { var Lh = Z.H(YA, YB); aA = Z.H(Lh, YA); aB = Z.H(Lh, YB); }\n    var Yagg = Z.add(Z.mul(aA, YA), Z.mul(aB, YB));\n    var sig = Z.soloSign(xb, Yagg, 'pay bob');\n    $('cc12r-ya').textContent = Z.fmt(YA);\n    $('cc12r-yb').textContent = xb + '&middot;G = '.replace('&middot;', '·') + Z.fmt(YBreal);\n    $('cc12r-pub').textContent = Z.fmt(YB);\n    $('cc12r-co').textContent = musig ? aA + ', ' + aB : '1, 1 (no coefficients)';\n    $('cc12r-agg').textContent = Z.fmt(Yagg) + (Z.eq(Yagg, YBreal) ? '  = Bob’s own key' : '');\n    $('cc12r-chk').textContent = Z.fmt(sig.lhs) + (sig.ok ? ' = ' : ' ≠ ') + Z.fmt(sig.rhs);\n    var v = $('cc12r-v');\n    if (sig.ok && rogue) { v.className = 'dpw-verdict'; v.innerHTML = 'Accepted. Alice was cancelled out and Bob signed for both of them.'; }\n    else if (sig.ok) { v.className = 'dpw-verdict dpw-neutral'; v.innerHTML = 'Accepted only by coincidence of the 67-point toy curve.'; }\n    else if (rogue) { v.className = 'dpw-verdict dpw-ok'; v.innerHTML = 'Rejected. Under MuSig2 the rogue key does not cancel Alice; Bob still needs her.'; }\n    else { v.className = 'dpw-verdict dpw-ok'; v.innerHTML = 'Rejected. With honest keys Bob cannot sign alone, as intended.'; }\n  }\n  function set(a, b, val) { $(a).setAttribute('data-on', String(val)); $(b).setAttribute('data-on', String(!val)); }\n  on($('cc12r-naive'), 'click', function () { musig = false; set('cc12r-naive', 'cc12r-musig', true); draw(); });\n  on($('cc12r-musig'), 'click', function () { musig = true; set('cc12r-naive', 'cc12r-musig', false); draw(); });\n  on($('cc12r-honest'), 'click', function () { rogue = false; set('cc12r-honest', 'cc12r-evil', true); draw(); });\n  on($('cc12r-evil'), 'click', function () { rogue = true; set('cc12r-honest', 'cc12r-evil', false); draw(); });\n  on($('cc12r-new'), 'click', fresh);\n  fresh();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('cc12-grind');\n  if (!root || !window.__cc12) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { 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  var Z = window.__cc12, $ = function (id) { return root.querySelector('#' + id); };\n  var runs = 0, total = 0;\n  function grind() {\n    var xa = Z.r1(), YA = Z.mul(xa, Z.G), tries = 0;\n    while (tries < 100000) {\n      tries++;\n      var x = Z.r1(), u = Z.r1();\n      var YB = Z.add(Z.mul(x, Z.G), Z.neg(Z.mul(u, YA)));    // Bob can build this without knowing x_A\n      if (!YB) continue;\n      var Lh = Z.H(YA, YB), aA = Z.H(Lh, YA), aB = Z.H(Lh, YB);\n      if (aA === Z.md(u * aB, Z.N)) {\n        // Y_agg = aA*YA + aB*(xG - u*YA) = aB*x*G, so Bob knows its private key\n        var Yagg = Z.add(Z.mul(aA, YA), Z.mul(aB, YB));\n        var sk = Z.md(aB * x, Z.N), sig = Z.soloSign(sk, Yagg, 'pay bob');\n        runs++; total += tries;\n        $('cc12g-t').textContent = tries;\n        $('cc12g-avg').textContent = (total / runs).toFixed(1);\n        $('cc12g-w').textContent = Z.fmt(YB) + ' → ' + (sig.ok ? 'accepted' : 'rejected');\n        return;\n      }\n    }\n  }\n  function drawRate() {\n    var r = +$('cc12g-r').value;\n    $('cc12g-rv').innerHTML = '10<sup>' + r + '</sup>';\n    var lyears = 256 * Math.log10(2) - r - Math.log10(3.156e7);\n    var ex = Math.floor(lyears);\n    $('cc12g-y').innerHTML = (Math.pow(10, lyears - ex)).toFixed(1) + ' &times; 10<sup>' + ex + '</sup> years';\n  }\n  on($('cc12g-run'), 'click', grind);\n  on($('cc12g-r'), 'input', drawRate);\n  drawRate();\n})();\n</script>","headings":[{"value":"The naive way","depth":2},{"value":"The rogue-key attack","depth":2},{"value":"How do we prevent this?","depth":2},{"value":"MuSig2 key aggregation","depth":2},{"value":"Why that stops Bob","depth":2},{"value":"Signing","depth":2}],"frontmatter":{"date_created":"2026-10-23","path":"/blog/crypto-club-rogue-keys-and-musig2","tags":["Cryptography","Bitcoin","Digital Signatures","MuSig2"],"title":"How Bob Steals A Multisig, And How MuSig2 Stops Him"}}},"pageContext":{"prevPostPath":"/blog/crypto-club-rewinding-the-prover","currPostPath":"/blog/crypto-club-why-schnorr-adds-up","nextPostPath":"/blog/crypto-club-rogue-keys-and-musig2"}},"staticQueryHashes":[]}