{"componentChunkName":"component---src-templates-post-js","path":"/blog/crypto-club-a-key-that-never-exists","result":{"data":{"prevPost":{"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"}},"currPost":{"html":"<p>Last week we started talking about Shamir secret sharing. So let's do a quick review of that, and then what we'll cover is answering a few questions, such as: what happens if the dealer is not honest, what happens if the dealer sends fake shares to parties, and also, how do we prevent the dealer from actually computing the secret?</p>\n<h2 id=\"shamir-secret-sharing-quickly\" style=\"position:relative;\"><a href=\"#shamir-secret-sharing-quickly\" aria-label=\"shamir secret sharing quickly 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>Shamir secret sharing, quickly</h2>\n<p>Last week we said we have this person called a dealer, who holds a secret value, and they are the owner of this secret value. They also compute a polynomial of degree t − 1. Let's call the secret S.</p>\n<div class=\"dpw-formula\">f(x) = S + a<sub>1</sub>x + a<sub>2</sub>x<sup>2</sup> + &hellip; + a<sub>t&minus;1</sub>x<sup>t&minus;1</sup> mod p</div>\n<p>The secret is this polynomial evaluated at zero, so the y-intercept. From this polynomial, the dealer distributes individual shares to people via a private channel. Each party gets a share, which is the function evaluated at their index. So this person gets f(1), this one gets the function evaluated at x = 2, which is f(2), and this one gets f(3). Imagine this equation as a graph. Everyone has gotten individual points on this graph. And we know from last time that you need t points to reconstruct a polynomial of degree t − 1.</p>\n<p>The first question I'll ask is, why do we need to keep this private? Why does the dealer need to send f(1) privately to P<sub>1</sub> and f(2) privately to P<sub>2</sub>? What if they just publicly broadcast: here's f(1), here's f(2), here's f(3), and any party can just come and pick what they want? It's not a complicated answer. If I broadcast all of these shares publicly, then anyone can just get together. They just need t of these points to reconstruct this polynomial, and then they can find f(0). So this is why the shares must be shared privately.</p>\n<p>How do they come together and reconstruct? We spoke about how they can reconstruct via Lagrange interpolation. You sum up all of the shares of the parties who came together, multiplied by the Lagrange coefficient evaluated at 0, because we're trying to find f(0). So t parties have to come together, and then they're able to reconstruct. This scheme is secure against up to t − 1 malicious parties. If t − 1 people decide to hack something, they will fail, because you need t people.</p>\n<p>How is this secure? The way we prove this is we design a simulator. A simulator is someone who doesn't have access to anything, and they're just trying to fake it. In their attempt to fake the answers, if the answers look the same as the real answers, then we say that it's secure. Even in the regular case, the dealer computes random points. So you have t − 1 random values that are coming from this field, mod p. And now you can think of this as: what is the next value? This next value can be literally anything. And it's because this value can be anything that the secret could be S, or S′, or S″, and so on. The polynomial could be f(x), or f′(x), or f″(x), where f′ and f″ are just other polynomials through the same points, not derivatives.</p>\n<div class=\"dpw\" id=\"cc15-hide\">\n  <div class=\"dpw-q\">You hold t &minus; 1 shares. How many secrets are still possible?</div>\n  <div class=\"dpw-detail-b\">Toy field: mod 11, threshold t = 3, so the dealer's polynomial is f(x) = S + a<sub>1</sub>x + a<sub>2</sub>x<sup>2</sup>. You are holding the shares of parties 1 and 2. For every candidate secret S, there is exactly one polynomial through (0, S) and your two points.</div>\n  <div class=\"dpw-toggle-row\" style=\"margin-top:12px\">\n    <button class=\"dpw-toggle\" id=\"cc15h-new\">new dealer</button>\n    <button class=\"dpw-toggle\" id=\"cc15h-third\" data-on=\"false\">add party 3&rsquo;s share (t shares)</button>\n  </div>\n  <div class=\"dpw-line\"><span>shares you hold</span><span><b id=\"cc15h-sh\"></b></span></div>\n  <table class=\"dpw-table\" id=\"cc15h-tab\"></table>\n  <div class=\"dpw-verdict dpw-ok\" id=\"cc15h-v\"></div>\n  <div class=\"dpw-hint\">With two shares, all 11 secrets fit a polynomial, so the shares say nothing about S. The third share rules out all but one. On secp256k1 the same table would have about 2<sup>256</sup> rows.</div>\n</div>\n<h2 id=\"problem-one-we-have-to-trust-the-dealer\" style=\"position:relative;\"><a href=\"#problem-one-we-have-to-trust-the-dealer\" aria-label=\"problem one we have to trust the dealer 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>Problem one: we have to trust the dealer</h2>\n<p>The question is, we have to trust the dealer. You're trusting the dealer that they gave you the correct shares. What's to say that this dealer, instead of giving party two f(2), gives them f(50)? It's very hard for party two to know that, because they don't know what the equation is. They just see one share.</p>\n<p>In the past, we've seen one way to fix this, via the proof of knowledge, where with a commitment we ensured that the order in which the prover does all of their steps is preserved. So we do something similar here. We tell the dealer to commit beforehand. This is known as verifiable secret sharing, where again the dealer computes their random coefficients, but they also commit to these values, so now they can't change it later.</p>\n<p>A commitment is pretty much something where we can't invert it. Because if we're able to invert the commitment, then we would be back at the same place, where we just invert all of the commitments, and now we can reconstruct the function and get the secret. So here, again, we rely on the discrete log assumption. The dealer raises a generator to each coefficient, mod p. This is the same as our regular y = g<sup>x</sup> mod p. By the way, it will be a little different for Bitcoin. It will be a scalar multiplication instead of exponentiation.</p>\n<div class=\"dpw-formula\">C<sub>0</sub> = g<sup>a<sub>0</sub></sup>, &nbsp; C<sub>1</sub> = g<sup>a<sub>1</sub></sup>, &nbsp; &hellip;, &nbsp; C<sub>t&minus;1</sub> = g<sup>a<sub>t&minus;1</sub></sup> mod p &nbsp;&nbsp; (a<sub>0</sub> = S)</div>\n<p>How do I, as a party, verify that I got the correct share from these commitments? Because obviously I can't invert this equation and check. We know that each party's share is the function evaluated at their index. Instead of x, I just wrote i. And there's also a<sub>0</sub>, which is going to be the secret.</p>\n<div class=\"dpw-formula\">f(i) = a<sub>0</sub> + a<sub>1</sub>i + a<sub>2</sub>i<sup>2</sup> + &hellip; + a<sub>t&minus;1</sub>i<sup>t&minus;1</sup></div>\n<p>And now what I can do is raise g to the power of this full equation, evaluated at my index. Someone caught that I first wrote plus on the second row, and it should be multiply. You're very right. When you add in the exponent, you multiply in the base. Now, g<sup>a<sub>0</sub></sup> is the same as C<sub>0</sub>, and g<sup>a<sub>1</sub></sup> is the same as C<sub>1</sub>, and so on and so forth. So we can rewrite this as C<sub>0</sub> times C<sub>1</sub><sup>i</sup>, times C<sub>2</sub><sup>i<sup>2</sup></sup>, and so on up to C<sub>t−1</sub><sup>i<sup>t−1</sup></sup>, mod p.</p>\n<div class=\"dpw-formula\">g<sup>f(i)</sup> = g<sup>a<sub>0</sub></sup> &middot; (g<sup>a<sub>1</sub></sup>)<sup>i</sup> &middot; (g<sup>a<sub>2</sub></sup>)<sup>i<sup>2</sup></sup> &middot; &hellip; = C<sub>0</sub> &middot; C<sub>1</sub><sup>i</sup> &middot; C<sub>2</sub><sup>i<sup>2</sup></sup> &middot; &hellip; &middot; C<sub>t&minus;1</sub><sup>i<sup>t&minus;1</sup></sup> mod p</div>\n<p>All of this is public now. We have these values, and we also know our own index. So pretty much what this verification means is, skipping all of these intermediate steps, we're just checking if g<sup>f(i)</sup>, which each party can compute on their own from the commitments, is equal to g<sup>s<sub>i</sub></sup>, where s<sub>i</sub> is the share they received. And that basically tells them if the dealer gave everyone valid shares. This is Feldman VSS.</p>\n<div class=\"dpw\" id=\"cc15-vss\">\n  <div class=\"dpw-q\">Party 2 sees only one point. Can it still tell its share is fake?</div>\n  <div class=\"dpw-detail-b\">Toy group: p = 2039, q = 1019, g = 4. The dealer picks a degree-2 polynomial mod q (t = 3), publishes C<sub>0</sub>, C<sub>1</sub>, C<sub>2</sub>, and sends each of five parties its share privately. Each party checks g<sup>s<sub>i</sub></sup> against C<sub>0</sub>&middot;C<sub>1</sub><sup>i</sup>&middot;C<sub>2</sub><sup>i<sup>2</sup></sup> on its own.</div>\n  <div class=\"dpw-toggle-row\" style=\"margin-top:12px\">\n    <button class=\"dpw-toggle\" id=\"cc15v-new\">new dealer</button>\n    <button class=\"dpw-toggle\" id=\"cc15v-cheat\" data-on=\"false\">dealer sends party 2 f(50) instead of f(2)</button>\n  </div>\n  <div class=\"dpw-line\"><span>public commitments C<sub>0</sub>, C<sub>1</sub>, C<sub>2</sub></span><span><b id=\"cc15v-c\"></b></span></div>\n  <table class=\"dpw-table\" id=\"cc15v-tab\"></table>\n  <div class=\"dpw-verdict dpw-ok\" id=\"cc15v-v\"></div>\n</div>\n<p>But what is the problem here? I can tell you that a<sub>0</sub> equals our secret. The commitments are actually public. So the problem here is that our secret key is exposed via commitment. That might not be a big problem, because to go from this commitment to the secret key, you have to break DLP. But based on this, there was another popular scheme that was invented, called Pedersen VSS. Instead of having one generator, you have two generators, and you're trying to use that second generator as a blinding factor. But we won't talk about that much, because Bitcoin uses this one. It uses Feldman VSS.</p>\n<h2 id=\"problem-two-the-dealer-still-knows-the-secret\" style=\"position:relative;\"><a href=\"#problem-two-the-dealer-still-knows-the-secret\" aria-label=\"problem two the dealer still knows the secret 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>Problem two: the dealer still knows the secret</h2>\n<p>The problem is this dealer still has the secret. They still calculated the S value, which is f(0). We're just double checking that they're giving us the shares properly, but they're still making the equations. They still have the secret. They're the ones who made the secret. So what we want to do is make sure that this dealer is not the one in control of the secret. And in order to do that, we need to make sure that the dealer is not the one making the equation, because whoever makes the degree t − 1 equation calculates the secret.</p>\n<p>So what we do is something called distributed key generation, where everyone is the dealer now. Everyone calculates their own equation, their own polynomial. Party one calculates a polynomial we can call f<sub>1</sub>(x), and then party three has f<sub>3</sub>(x) and party nine has f<sub>9</sub>(x).</p>\n<div class=\"dpw-formula\">f<sub>1</sub>(x) = a<sub>1,0</sub> + a<sub>1,1</sub>x + a<sub>1,2</sub>x<sup>2</sup> + &hellip; + a<sub>1,t&minus;1</sub>x<sup>t&minus;1</sup> mod p</div>\n<p>They also have their own commitments, similar to how the dealer published their commitments. So commitments for party one would be C<sub>1,0</sub>, C<sub>1,1</sub>, and so on. One participant summed it up: each participant works as an independent dealer, with the same protocol. Yes, exactly the same, but now everyone is the dealer. All of this is broadcast, and this type of verification happens.</p>\n<p>But what is being distributed? I think that's the main question. Party one is going to get every other party's share that is evaluated at one, so f<sub>3</sub>(1) and f<sub>9</sub>(1). Party three will get f<sub>1</sub>(3), f<sub>9</sub>(3); party nine, f<sub>1</sub>(9), f<sub>3</sub>(9). So everyone's getting their own shares, corresponding to their index.</p>\n<h2 id=\"the-public-key-and-the-private-key-nobody-has\" style=\"position:relative;\"><a href=\"#the-public-key-and-the-private-key-nobody-has\" aria-label=\"the public key and the private key nobody has 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 public key, and the private key nobody has</h2>\n<p>How do you combine this into a public and private key? Let's say this large F is the combined large polynomial of everyone's individual polynomials. If we evaluate this at zero, it's going to be f<sub>1</sub>(0) plus f<sub>3</sub>(0) plus f<sub>9</sub>(0), which is the same as a<sub>1,0</sub> plus a<sub>3,0</sub> plus a<sub>9,0</sub>.</p>\n<div class=\"dpw-formula\">F(0) = f<sub>1</sub>(0) + f<sub>3</sub>(0) + f<sub>9</sub>(0) = a<sub>1,0</sub> + a<sub>3,0</sub> + a<sub>9,0</sub></div>\n<p>What we can do is multiply both sides by the generator, because in this elliptic curve world we have a generator. If I multiply a<sub>1,0</sub> times G, I get the first commitment of the first party. And these commitments are public. So that will just be C<sub>1,0</sub> plus C<sub>3,0</sub> plus C<sub>9,0</sub>, and that's the public key. Why is that the public key? Because each C is equal to x·G, where x is that party's secret coefficient. So when we add everyone's commitment here, it's like a multisig at this point. We're just adding everyone's C value.</p>\n<div class=\"dpw-formula\">PK = G&middot;F(0) = C<sub>1,0</sub> + C<sub>3,0</sub> + C<sub>9,0</sub> = &Sigma;<sub>l</sub> C<sub>l,0</sub></div>\n<p>So here's the interesting thing. The private key doesn't exist anywhere. We have these shares, and in the actual protocol, they won't actually calculate the private key. You can verify without actually knowing the private key.</p>\n<div class=\"dpw\" id=\"cc15-dkg\">\n  <div class=\"dpw-q\">After distributed key generation, who holds the private key?</div>\n  <div class=\"dpw-detail-b\">Parties 1, 3 and 9, threshold t = 2, same toy group (p = 2039, q = 1019, g = 4, so multiplication of commitments here plays the role of adding points). Every party is a dealer of its own degree-1 polynomial. Rows are dealers, columns are the parties receiving.</div>\n  <div class=\"dpw-toggle-row\" style=\"margin-top:12px\">\n    <button class=\"dpw-toggle\" id=\"cc15d-new\">run DKG again</button>\n  </div>\n  <table class=\"dpw-table\" id=\"cc15d-tab\"></table>\n  <div class=\"dpw-line\"><span>public key PK = C<sub>1,0</sub>&middot;C<sub>3,0</sub>&middot;C<sub>9,0</sub> mod p</span><span><b id=\"cc15d-pk\"></b></span></div>\n  <div class=\"dpw-toggle-row\" style=\"margin-top:10px\">\n    <span class=\"dpw-toggle-cap\">Thought experiment only: pick t = 2 parties to pool their final shares with Lagrange interpolation</span>\n    <button class=\"dpw-toggle\" data-pair=\"1,3\">1 + 3</button>\n    <button class=\"dpw-toggle\" data-pair=\"1,9\">1 + 9</button>\n    <button class=\"dpw-toggle\" data-pair=\"3,9\">3 + 9</button>\n  </div>\n  <div class=\"dpw-line\"><span>reconstructed F(0), and g<sup>F(0)</sup></span><span><b id=\"cc15d-f\">&ndash;</b></span></div>\n  <div class=\"dpw-verdict dpw-neutral\" id=\"cc15d-v\">No single dealer's secret a<sub>l,0</sub> is the private key, and no party ever receives F(0).</div>\n  <div class=\"dpw-hint\">Each party's final share is the sum of the column it received. Any two of those shares interpolate to the same F(0), and g<sup>F(0)</sup> matches the public key that was built only from public commitments. In a real wallet the parties never pool their shares; they sign with them, which is what FROST does.</div>\n</div>\n<p>This part is also confusing, because now you have many dealers, and everyone has their own equation. But if you think of it as one dealer, just imagine you have one dealer. Whatever one dealer is doing, everyone is doing that simultaneously.</p>\n<p>We covered the basic Shamir secret sharing. And we talked about how we verify that they are giving the correct shares to everyone. Then we talked about how we ensure that the dealer is not the one calculating the secret, and the answer to that is everyone becomes a dealer.</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.cc15-hot td { background: #dcefe3; color: #3f8f5b; font-weight: 700; }\n.cc15-bad td { background: #f2cdcc; color: #6a1d1b; font-weight: 700; }\n.cc15-dim td { color: #94a6b8; }\n</style>\n<script>\n(function () {\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 md(a, m) { a %= m; return a < 0n ? a + m : a; }\n  function rnd(n) { return BigInt(Math.floor(Math.random() * Number(n))); }\n  function ev(co, x, m) { var r = 0n, xp = 1n; co.forEach(function (c) { r = md(r + c * xp, m); xp = xp * x % m; }); return r; }\n  window.__cc15 = { P: 2039n, Q: 1019n, G: 4n, mp: mp, md: md, rnd: rnd, ev: ev };\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('cc15-hide');\n  if (!root || !window.__cc15) 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.__cc15, $ = function (id) { return root.querySelector('#' + id); };\n  var M = 11n, co, third = false;\n  function fresh() { co = [Z.rnd(M), Z.rnd(M), 1n + Z.rnd(M - 1n)]; draw(); }\n  function draw() {\n    var s1 = Z.ev(co, 1n, M), s2 = Z.ev(co, 2n, M), s3 = Z.ev(co, 3n, M);\n    $('cc15h-sh').textContent = 'f(1) = ' + s1 + ', f(2) = ' + s2 + (third ? ', f(3) = ' + s3 : '');\n    var inv2 = Z.mp(2n, M - 2n, M);\n    var rows = '<tr><th>candidate S</th><th>the polynomial through (0,S), (1,' + s1 + '), (2,' + s2 + ')</th><th>f(3)</th></tr>';\n    var alive = 0;\n    for (var S = 0n; S < M; S++) {\n      // f(1) = S + a1 + a2, f(2) = S + 2a1 + 4a2  =>  a2 = (f2 - 2f1 + S)/2, a1 = f1 - S - a2\n      var a2 = Z.md((s2 - 2n * s1 + S) * inv2, M), a1 = Z.md(s1 - S - a2, M);\n      var f3 = Z.ev([S, a1, a2], 3n, M);\n      var ok = !third || f3 === s3;\n      if (ok) alive++;\n      rows += '<tr class=\"' + (third ? (ok ? 'cc15-hot' : 'cc15-dim') : '') + '\"><td class=\"dpw-mono\">' + S + '</td><td class=\"dpw-mono\">' + S + ' + ' + a1 + 'x + ' + a2 + 'x²</td><td class=\"dpw-mono\">' + f3 + '</td></tr>';\n    }\n    $('cc15h-tab').innerHTML = rows;\n    var v = $('cc15h-v');\n    v.className = third ? 'dpw-verdict' : 'dpw-verdict dpw-ok';\n    v.innerHTML = third ? 't shares: only S = ' + co[0] + ' survives. The secret is out.'\n      : 't &minus; 1 shares: all ' + alive + ' of 11 secrets are still possible, each with exactly one polynomial.';\n  }\n  on($('cc15h-new'), 'click', fresh);\n  on($('cc15h-third'), 'click', function () { third = !third; $('cc15h-third').setAttribute('data-on', String(third)); draw(); });\n  fresh();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('cc15-vss');\n  if (!root || !window.__cc15) 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.__cc15, $ = function (id) { return root.querySelector('#' + id); };\n  var co, C, cheat = false;\n  function fresh() { co = [1n + Z.rnd(Z.Q - 1n), Z.rnd(Z.Q), 1n + Z.rnd(Z.Q - 1n)]; C = co.map(function (a) { return Z.mp(Z.G, a, Z.P); }); draw(); }\n  function draw() {\n    $('cc15v-c').textContent = C.join(', ');\n    var rows = '<tr><th>party i</th><th>share s<sub>i</sub> received</th><th>g<sup>s<sub>i</sub></sup></th><th>C<sub>0</sub>&middot;C<sub>1</sub><sup>i</sup>&middot;C<sub>2</sub><sup>i&sup2;</sup></th><th></th></tr>';\n    var bad = 0;\n    for (var i = 1n; i <= 5n; i++) {\n      var s = Z.ev(co, cheat && i === 2n ? 50n : i, Z.Q);\n      var lhs = Z.mp(Z.G, s, Z.P);\n      var rhs = 1n;\n      C.forEach(function (c, j) { rhs = rhs * Z.mp(c, Z.mp(i, BigInt(j), Z.Q), Z.P) % Z.P; });\n      var ok = lhs === rhs; if (!ok) bad++;\n      rows += '<tr class=\"' + (ok ? '' : 'cc15-bad') + '\"><td class=\"dpw-mono\">' + i + '</td><td class=\"dpw-mono\">' + s + '</td><td class=\"dpw-mono\">' + lhs + '</td><td class=\"dpw-mono\">' + rhs + '</td><td>' + (ok ? '✓' : '✗ complain') + '</td></tr>';\n    }\n    $('cc15v-tab').innerHTML = rows;\n    var v = $('cc15v-v');\n    v.className = bad ? 'dpw-verdict' : 'dpw-verdict dpw-ok';\n    v.innerHTML = bad ? 'Party 2 catches it alone, without seeing anyone else&rsquo;s share or the polynomial.' : 'Every party verifies its own share against the public commitments.';\n  }\n  on($('cc15v-new'), 'click', fresh);\n  on($('cc15v-cheat'), 'click', function () { cheat = !cheat; $('cc15v-cheat').setAttribute('data-on', String(cheat)); draw(); });\n  fresh();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('cc15-dkg');\n  if (!root || !window.__cc15) 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.__cc15, $ = function (id) { return root.querySelector('#' + id); };\n  var IDS = [1n, 3n, 9n], polys, finals, PK;\n  var pairBtns = root.querySelectorAll('[data-pair]');\n  function fresh() {\n    polys = IDS.map(function () { return [1n + Z.rnd(Z.Q - 1n), 1n + Z.rnd(Z.Q - 1n)]; });\n    finals = IDS.map(function (i) { return polys.reduce(function (a, f) { return Z.md(a + Z.ev(f, i, Z.Q), Z.Q); }, 0n); });\n    PK = polys.reduce(function (a, f) { return a * Z.mp(Z.G, f[0], Z.P) % Z.P; }, 1n);\n    var rows = '<tr><th>dealer</th><th>own secret a<sub>l,0</sub></th><th>C<sub>l,0</sub></th>' +\n      IDS.map(function (i) { return '<th>to P' + i + '</th>'; }).join('') + '</tr>';\n    polys.forEach(function (f, li) {\n      rows += '<tr><td class=\"dpw-mono\">P' + IDS[li] + '</td><td class=\"dpw-mono\">' + f[0] + '</td><td class=\"dpw-mono\">' + Z.mp(Z.G, f[0], Z.P) + '</td>' +\n        IDS.map(function (i) { return '<td class=\"dpw-mono\">f<sub>' + IDS[li] + '</sub>(' + i + ') = ' + Z.ev(f, i, Z.Q) + '</td>'; }).join('') + '</tr>';\n    });\n    rows += '<tr class=\"cc15-hot\"><td colspan=\"3\">final share (column sum)</td>' + finals.map(function (s) { return '<td class=\"dpw-mono\">' + s + '</td>'; }).join('') + '</tr>';\n    $('cc15d-tab').innerHTML = rows;\n    $('cc15d-pk').textContent = String(PK);\n    $('cc15d-f').textContent = '–';\n    [].forEach.call(pairBtns, function (b) { b.setAttribute('data-on', 'false'); });\n    var v = $('cc15d-v'); v.className = 'dpw-verdict dpw-neutral';\n    v.innerHTML = 'No single dealer&rsquo;s secret a<sub>l,0</sub> is the private key, and no party ever receives F(0).';\n  }\n  function pool(b) {\n    var pr = b.getAttribute('data-pair').split(',').map(function (x) { return BigInt(x); });\n    var si = pr.map(function (i) { return finals[IDS.indexOf(i)]; });\n    // Lagrange at 0 for two points: L_a = b/(b-a), L_b = a/(a-b)\n    var a = pr[0], c = pr[1];\n    var La = Z.md(c * Z.mp(Z.md(c - a, Z.Q), Z.Q - 2n, Z.Q), Z.Q), Lc = Z.md(a * Z.mp(Z.md(a - c, Z.Q), Z.Q - 2n, Z.Q), Z.Q);\n    var F0 = Z.md(si[0] * La + si[1] * Lc, Z.Q), gF = Z.mp(Z.G, F0, Z.P);\n    var trueF0 = polys.reduce(function (x, f) { return Z.md(x + f[0], Z.Q); }, 0n);\n    [].forEach.call(pairBtns, function (o) { o.setAttribute('data-on', String(o === b)); });\n    $('cc15d-f').textContent = F0 + ', ' + gF;\n    var v = $('cc15d-v');\n    var ok = gF === PK && F0 === trueF0;\n    v.className = ok ? 'dpw-verdict' : 'dpw-verdict dpw-ok';\n    v.innerHTML = '' + (ok ? 'g<sup>F(0)</sup> = ' + gF + ' = PK. This button is the only place F(0) was ever computed.' : 'mismatch') + '';\n  }\n  on($('cc15d-new'), 'click', fresh);\n  [].forEach.call(pairBtns, function (b) { on(b, 'click', function () { pool(b); }); });\n  fresh();\n})();\n</script>","headings":[{"value":"Shamir secret sharing, quickly","depth":2},{"value":"Problem one: we have to trust the dealer","depth":2},{"value":"Problem two: the dealer still knows the secret","depth":2},{"value":"The public key, and the private key nobody has","depth":2}],"frontmatter":{"date_created":"2026-11-20","path":"/blog/crypto-club-a-key-that-never-exists","tags":["Cryptography","Bitcoin","Threshold Cryptography"],"title":"A Bitcoin Key That Never Exists"}},"nextPost":null},"pageContext":{"prevPostPath":"/blog/crypto-club-rogue-keys-and-musig2","currPostPath":"/blog/crypto-club-a-key-that-never-exists","nextPostPath":null}},"staticQueryHashes":[]}