{"componentChunkName":"component---src-templates-post-js","path":"/blog/crypto-club-multiplying-with-a-parabola","result":{"data":{"prevPost":{"html":"<p>Last week, we left off talking about this thing called the discrete log problem, DLP.</p>\n<div class=\"dpw-formula\">f(x) = g<sup>x</sup> mod p</div>\n<p>p is a large prime, and g is a number that comes from our Z<sub>p</sub><sup>∗</sup> group.</p>\n<h2 id=\"the-group-we-are-working-in\" style=\"position:relative;\"><a href=\"#the-group-we-are-working-in\" aria-label=\"the group we are working in permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The group we are working in</h2>\n<p>Z<sub>p</sub><sup>∗</sup> is a set. It goes from one all the way up to p − 1. If I say something like Z<sub>7</sub><sup>∗</sup>, it's going to be 1, 2, 3, 4, 5, 6. Instead of us calling it Z<sub>p</sub><sup>∗</sup> every time, we're going to call this a multiplicative group, because that's what it is.</p>\n<p>We can't just call any set a group. For a set to be a group, it needs to satisfy four conditions.</p>\n<ol>\n<li>The first is closure, which means if we choose two elements in the group, a · b is also in Z<sub>p</sub><sup>∗</sup>. For example, 2 · 6 = 12, and now if we mod this by 7, 12 mod 7 is 5. You can also verify that 5 is in Z<sub>7</sub><sup>∗</sup>.</li>\n<li>The second is associativity. If we choose a, b and c in Z<sub>p</sub><sup>∗</sup>, it should follow the associative property: (a · b) · c = a · (b · c).</li>\n<li>The third property that a group has to have is the identity element, which pretty much means that if we choose any integer a in Z<sub>p</sub><sup>∗</sup>, a · e and e · a should both equal a, where e is the identity element. In the case of Z<sub>p</sub><sup>∗</sup>, the identity element is 1, because a · 1 = 1 · a = a. If we multiply it by 0, we would not get a. So 0 is not the identity element of Z<sub>p</sub><sup>∗</sup>. It's only 1.</li>\n<li>The fourth thing is the inverse element. If we choose a in Z<sub>p</sub><sup>∗</sup>, there should be an inverse in Z<sub>p</sub><sup>∗</sup> such that a · a<sup>−1</sup> = a<sup>−1</sup> · a = 1, the identity element. Suppose a = 2. What can we multiply 2 with to get 1 mod 7? 2 · 2 = 4. 2 · 3 = 6. 2 · 4 = 8, and 8 mod 7 is 1. So the inverse of 2 is 4.</li>\n</ol>\n<p>These four properties must be true for each integer in Z<sub>p</sub><sup>∗</sup>, and that's what we call a group. Basically, what it's saying is we can do multiplication in the set without things breaking.</p>\n<h2 id=\"the-generator\" style=\"position:relative;\"><a href=\"#the-generator\" aria-label=\"the generator permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The generator</h2>\n<p>We can call a group cyclic if there exists a generator g in that group. It's not exactly a random number. It's a special number, where if we raise it to the powers 1 up to p − 1, we get the set back. The value you will get is all the elements in the original Z<sub>p</sub><sup>∗</sup>. This is all mod p.</p>\n<p>In Z<sub>p</sub><sup>∗</sup>, we already know, through proofs that have already been proven, that there is at least one generator that generates the entire group.</p>\n<p>For Z<sub>7</sub><sup>∗</sup>, the generator is three. Let's see what happens when we multiply this generator by itself p − 1 times: g<sup>1</sup>, g<sup>2</sup>, g<sup>3</sup>, g<sup>4</sup>, g<sup>5</sup> and g<sup>6</sup>. We have to do all of these multiplications mod p.</p>\n<div class=\"dpw-formula\">3<sup>1</sup> = 3 &nbsp;&nbsp; 3<sup>2</sup> = 9 &equiv; 2 &nbsp;&nbsp; 3<sup>3</sup> = 27 &equiv; 6 &nbsp;&nbsp; 3<sup>4</sup> &equiv; 4 &nbsp;&nbsp; 3<sup>5</sup> &equiv; 5 &nbsp;&nbsp; 3<sup>6</sup> &equiv; 1 &nbsp;&nbsp; (mod 7)</div>\n<p>What we notice now is that we have one, two, three, four, five, and six. All the elements appear only once. So there are no duplicates. There are no collisions, in other words.</p>\n<p>Someone asked how I knew the generator is three. To be honest, I'm not sure. I think for small numbers, it's easy. But for large numbers, I'm not sure how the generator is picked. My guess is there's some trial and error algorithm, or there's a math proof where you could do it very quickly.</p>\n<p>While you were talking, I just tried g = 2, and we already found a duplicate. 2<sup>1</sup> = 2, and 2<sup>2</sup> = 4. Then 2<sup>3</sup> = 8, and 8 mod 7 is 1. And 2<sup>4</sup> = 16, and 16 mod 7 is 2, which we have already seen. So this is not a generator. I should also specify: generate the entire group once.</p>\n<p>So which numbers generate the whole group, and how many of them are there? Pick a prime, then a base.</p>\n<div class=\"dpw\" id=\"cc4-gen\">\n  <div class=\"dpw-toggle-row\">\n    <span class=\"dpw-toggle-cap\">Prime p</span>\n    <button class=\"dpw-toggle\" data-p=\"7\" data-on=\"true\">7</button>\n    <button class=\"dpw-toggle\" data-p=\"11\" data-on=\"false\">11</button>\n    <button class=\"dpw-toggle\" data-p=\"13\" data-on=\"false\">13</button>\n    <button class=\"dpw-toggle\" data-p=\"17\" data-on=\"false\">17</button>\n    <button class=\"dpw-toggle\" data-p=\"23\" data-on=\"false\">23</button>\n  </div>\n  <div class=\"dpw-toggle-row\" id=\"cc4-bases\">\n    <span class=\"dpw-toggle-cap\">Base g <span class=\"dpw-inflate\">(filled chips are generators)</span></span>\n  </div>\n  <div class=\"dpw-toggle-cap\" id=\"cc4-powcap\">&ndash;</div>\n  <div class=\"cc4-cells\" id=\"cc4-cells\"></div>\n  <div class=\"dpw-readout\">\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc4-hit\">&ndash;</span><span class=\"dpw-cap\">elements reached</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc4-rep\">&ndash;</span><span class=\"dpw-cap\">powers before it repeats</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc4-count\">&ndash;</span><span class=\"dpw-cap\">generators in this group</span></div>\n  </div>\n  <div class=\"dpw-verdict\" id=\"cc4-gv\">&ndash;</div>\n  <div class=\"dpw-hint\">Each cell is g<sup>k</sup> mod p for k = 1 up to p &minus; 1. Once a power comes back to 1 the list starts over, so everything after that is a duplicate and is shown faded.</div>\n</div>\n<p>For p = 7 only 3 and 5 generate the group. The guess in the session is how it is done in practice: you try candidates, and the test is cheap, because g is a generator exactly when g<sup>(p−1)/q</sup> is not 1 for every prime q that divides p − 1.</p>\n<p>Everyone is using a fixed generator when wallet addresses are being generated. As far as I know, there's a specific number that everyone uses as a generator. If you were to change that number, then you could have one private key mapped to two public keys, or something like that. So that's why the generator is a fixed, global and public variable. Everyone knows this, even attackers.</p>\n<h2 id=\"the-hard-direction\" style=\"position:relative;\"><a href=\"#the-hard-direction\" aria-label=\"the hard direction permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The hard direction</h2>\n<p>We said that doing this calculation, g<sup>x</sup> mod p, is very easy. What is hard is when you're given f(x), which is the answer to this, and you're given the generator, which is also public, and you're given the prime value, finding the x.</p>\n<div class=\"dpw-formula\">given y, g, p: &nbsp; find x such that &nbsp; y &equiv; g<sup>x</sup> (mod p)</div>\n<p>By the way, I'm using three lines here. That's just a way of showing it's congruent. 27 was the same as 6 mod 7.</p>\n<p>Go back to the simple example. Given this number 4, and also g = 3 and p = 7, finding x is hard. As the person who calculated this equation, I know x is four. But what the attacker sees is not that top part of the screen. They're only given this.</p>\n<p>Obviously, for small groups like this, you could just brute force it. You could just run this function seven times, and you will find it. But where p values are very large, it is very hard to find that x, and that is actually what's called the discrete log problem. This is why we also call this a one-way function, or a candidate one-way function, because we assume that it's secure.</p>\n<div class=\"dpw-formula\">DLP assumption: no PPT algorithm computes x = log<sub>g</sub> y (mod p) with non-negligible probability</div>\n<p>People have tried to disprove it. People have tried to create algorithms to break it, to find that x. But the closest people have come is sub-exponential. You can bypass this type of attack by increasing your security parameter.</p>\n<p>Bitcoin is not using this equation. Some of it has to do with the fact that people can break it in sub-exponential time. To bypass, you increase key size, and that increase leads to more storage costs. Things are just now larger for no reason.</p>\n<h2 id=\"the-easy-direction\" style=\"position:relative;\"><a href=\"#the-easy-direction\" aria-label=\"the easy direction permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>The easy direction</h2>\n<p>Was anyone able to figure out why this calculation is easy? It doesn't matter what p is. Imagine p is 256 bits, 512 bits, 1024 bits, whatever. By the way, x is your private key here, your secret key, because the attacker is trying to guess this x.</p>\n<p>Someone suggested building it up one step at a time: g<sup>2</sup> is g · g, g<sup>3</sup> is g<sup>2</sup> · g, and so on. You're getting the point, but there are still some things we can optimize. The question I'll ask is, why do we even care about g<sup>3</sup>? If we've already calculated g<sup>2</sup>, why not just skip to g<sup>4</sup>, which is g<sup>2</sup> · g<sup>2</sup>? That saves us one multiplication. So I do g<sup>2</sup>, then I calculate g<sup>4</sup>, then g<sup>8</sup>, then g<sup>16</sup>.</p>\n<p>We don't need to take every single step. We can just start hopping, in a way. It's much easier if I just square this, because I'm moving closer to my number this way, if I do repeated squaring, versus if I only add 1 each time. It's called exponentiation by squaring.</p>\n<p>If we have, say, x = 5, what we should do first is convert this to the binary representation. 2<sup>0</sup>, 2<sup>1</sup>, 2<sup>2</sup>: that's 1, 2, 4. 4 + 1 = 5, so it's going to be 1, 0, 1. That's the binary representation of 5. We know that this number is something we need, and this number is something we need. We do not need this one. This is not part of the active bits, we could say.</p>\n<p>Let's just take p = 7. 3<sup>1</sup> = 3 mod 7. For the next value, we square this: 3<sup>2</sup> = 9, which is 2 mod 7. For 3<sup>4</sup>, we just have to square that again, because we know that the last value is 3<sup>2</sup>. So we just have to do 2<sup>2</sup>, which is equal to 4 mod 7.</p>\n<p>So now we have these values: 3, 2, and 4. If I take my bit representation of the secret value, 1, 0, 1, I know that this is an active bit, so we take this 3. This is an inactive bit, so it's 0. And this is an active bit, so we take the 4. Now we have to multiply these, 4 · 3 only. We're not taking the 0.</p>\n<div class=\"dpw-formula\">3<sup>5</sup> &equiv; 4 &times; 3 = 12 &equiv; 5 (mod 7)</div>\n<p>That is the answer for g<sup>5</sup> mod 7, instead of doing 3 · 3 · 3 · 3 · 3. That's 243, I calculated it, which is 238 with a remainder of 5. So if you check it, it's the same answer.</p>\n<p>Someone asked what the active bits mean. If you change this to 1, then what are you actually doing? 5 in binary is 1, 0, 1, but if you take this as an active bit too, this becomes 4 + 2 + 1, which is 7. So then you're actually finding it for x = 7.</p>\n<p>Here is the same board for any exponent. Which squares get multiplied in, and how many multiplications does it take compared with multiplying g by itself x times?</p>\n<div class=\"dpw\" id=\"cc4-sqm\">\n  <div class=\"dpw-toggle-row\">\n    <span class=\"dpw-toggle-cap\">Prime p &nbsp;<span class=\"dpw-inflate\">(g is 3)</span></span>\n    <button class=\"dpw-toggle\" data-p=\"7\" data-on=\"true\">7</button>\n    <button class=\"dpw-toggle\" data-p=\"23\" data-on=\"false\">23</button>\n    <button class=\"dpw-toggle\" data-p=\"101\" data-on=\"false\">101</button>\n  </div>\n  <div class=\"dpw-controls\">\n    <label class=\"dpw-label\">Exponent x &nbsp; <span class=\"dpw-val\" id=\"cc4-x\">5</span> &nbsp;=&nbsp; <span class=\"dpw-val\" id=\"cc4-bin\">101</span> in binary\n      <input type=\"range\" id=\"cc4-xr\" min=\"1\" max=\"255\" step=\"1\" value=\"5\" />\n    </label>\n  </div>\n  <div class=\"cc4-table\" id=\"cc4-table\"></div>\n  <div class=\"dpw-formula\" id=\"cc4-prod\">&ndash;</div>\n  <div class=\"dpw-readout\">\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc4-fast\">&ndash;</span><span class=\"dpw-cap\">multiplications, by squaring</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc4-naive\">&ndash;</span><span class=\"dpw-cap\">multiplications, one at a time</span></div>\n  </div>\n  <div class=\"dpw-verdict dpw-ok\" id=\"cc4-check\">&ndash;</div>\n  <div class=\"dpw-hint\">Each row squares the row above it. Rows whose bit is 1 are multiplied into the answer. The count by squaring is one multiplication per row after the first, plus one for each extra active bit. The check at the bottom recomputes the answer the slow way.</div>\n</div>\n<h2 id=\"how-much-work-is-that\" style=\"position:relative;\"><a href=\"#how-much-work-is-that\" aria-label=\"how much work is that permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How much work is that?</h2>\n<p>Multiplying one at a time first. The time complexity of this is easy to guess: 2<sup>n</sup>, where n is the number of bits in x. As the value of our input increases, the number of computations we have to do increases exponentially.</p>\n<p>Now repeated squaring. In the worst case, if we think of the value 1, 1, 1, everything is active. So this is n, and then you would have to multiply each active bit, so that would be another n, which adds up to 2n, which, if you drop the constant, is n.</p>\n<p>This is also something I learned later on. If we convert a number into its binary representation, we can convert a calculation like this from an exponential time complexity algorithm to a linear complexity algorithm, just by converting it to binary and then doing that repeated squaring.</p>\n<p>What does that difference look like at the size of a real key? Slide the number of bits in x.</p>\n<div class=\"dpw\" id=\"cc4-scale\">\n  <div class=\"dpw-controls\">\n    <label class=\"dpw-label\">Bits in x, n &nbsp; <span class=\"dpw-val\" id=\"cc4-n\">256</span>\n      <input type=\"range\" id=\"cc4-nr\" min=\"2\" max=\"256\" step=\"1\" value=\"256\" />\n    </label>\n  </div>\n  <div class=\"cc4-bars\">\n    <div class=\"cc4-bar-row\"><span class=\"cc4-bar-cap\">one at a time</span><span class=\"cc4-bar-track\"><i id=\"cc4-b1\" class=\"cc4-bar cc4-bar-bad\"></i></span></div>\n    <div class=\"cc4-bar-row\"><span class=\"cc4-bar-cap\">by squaring</span><span class=\"cc4-bar-track\"><i id=\"cc4-b2\" class=\"cc4-bar\"></i></span></div>\n  </div>\n  <div class=\"dpw-readout\">\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc4-sn\">&ndash;</span><span class=\"dpw-cap\">multiplications, one at a time</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc4-sf\">&ndash;</span><span class=\"dpw-cap\">multiplications, by squaring</span></div>\n  </div>\n  <div class=\"dpw-verdict dpw-ok\" id=\"cc4-sv\">&ndash;</div>\n  <div class=\"dpw-hint\">Worst case for an n-bit exponent with every bit active: 2<sup>n</sup> &minus; 2 multiplications one at a time, against 2n &minus; 2 by squaring. The bars are on a log scale, so each step to the right is a doubling.</div>\n</div>\n<p>Someone pointed out that since g is fixed, the table of squares could be computed once and stored. Yeah, of course. And then that would just be even easier. The whole point is that this should be an easy equation to compute. If you store these values somewhere, it just becomes easier, and now you have more space complexity. That's the trade-off.</p>\n<p>This is very fast anyway. It doesn't grow exponentially with the size of the input. That's the main point. But this DLP assumption is saying that reversing that whole thing is extremely hard.</p>\n<h2 id=\"where-this-goes-next\" style=\"position:relative;\"><a href=\"#where-this-goes-next\" aria-label=\"where this goes next permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Where this goes next</h2>\n<p>What Bitcoin uses is the elliptic curve discrete log problem. Bitcoin has its own equation, and they have a generator as well, a generator G, which is a point on this curve. The public key and secret key, at least the raw parts, are derived from this curve using a generator, which is well known. It's a public parameter. We'll talk about this next week.</p>\n<style>\n.dpw {\n  --ink: #1b2228; --ink2: #5b7085; --line: #dae4ed;\n  --maroon: #a72e2b; --maroon-d: #6a1d1b; --rose: #f2cdcc; --green: #3f8f5b; --slate: #8ba2b8;\n  border: 1px solid var(--line); border-radius: 6px; padding: 20px;\n  margin: 32px 0; background: #fff; font-family: 'Open Sans', sans-serif;\n}\n.dpw * { box-sizing: border-box; }\n/* index.scss sets font on every span directly; let class-less spans inherit from the widget instead */\n.dpw span:not([class]) { font-size: inherit; line-height: inherit; font-family: inherit; }\n.dpw-formula { text-align: center; font-family: 'Inconsolata', monospace; font-size: 17px;\n  color: #1b2228; margin: 22px 0; letter-spacing: .01em; line-height: 1.6; overflow-x: auto; }\n.dpw-formula sup, .dpw-formula sub { font-size: 11px; }\n.dpw-controls { margin-bottom: 14px; }\n.dpw-label { display: block; font-size: 13px; color: var(--ink2); }\n.dpw-label input[type=range] { display: block; width: 100%; margin: 8px 0 0; accent-color: var(--maroon); }\n.dpw-val { color: var(--maroon-d); font-family: 'Inconsolata', monospace; font-weight: 700; }\n.dpw-hint { font-size: 12px; color: var(--ink2); margin-top: 10px; font-style: italic; line-height: 1.55; }\n.dpw-verdict { margin: 10px 0 4px; padding: 8px 12px; border-radius: 4px; font-size: 13px; font-weight: 700;\n  background: var(--rose); color: var(--maroon-d); text-align: center; font-family: 'Inconsolata', monospace; }\n.dpw-verdict.dpw-ok { background: #dcefe3; color: var(--green); }\n.dpw-readout { display: flex; gap: 24px; margin-top: 12px; flex-wrap: wrap; }\n.dpw-stat { display: flex; flex-direction: column; }\n.dpw-num { font-family: 'Josefin Sans', sans-serif; font-size: 23px; color: var(--maroon-d); line-height: 1.15; }\n.dpw-cap { font-size: 11px; color: var(--ink2); text-transform: uppercase; letter-spacing: .04em; }\n.dpw-toggle-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }\n.dpw-toggle-cap { width: 100%; margin-bottom: 3px; font-size: 12px; color: var(--ink2); }\n.dpw-toggle { font-family: 'Inconsolata', monospace; font-size: 12px; border: 1px solid var(--line);\n  background: #fff; color: var(--ink2); padding: 5px 9px; border-radius: 4px; cursor: pointer; transition: all .15s; }\n.dpw-toggle[data-on=true] { background: var(--maroon); color: #fff; border-color: var(--maroon); }\n.dpw-inflate { font-size: 11px; color: #94a6b8; }\n.cc4-chip { font-family: 'Inconsolata', monospace; font-size: 12px; min-width: 30px; text-align: center;\n  border: 1px solid var(--line); background: #fff; color: var(--ink2); padding: 5px 6px; border-radius: 4px; cursor: pointer; }\n.cc4-chip[data-gen=true] { background: #dcefe3; color: var(--green); border-color: #b9dcc6; }\n.cc4-chip[data-on=true] { outline: 2px solid var(--maroon); outline-offset: 1px; }\n.cc4-cells { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 6px; }\n.cc4-cell { font-family: 'Inconsolata', monospace; width: 40px; padding: 4px 0 5px; text-align: center;\n  border: 1px solid var(--line); border-radius: 4px; background: #fbfcfe; line-height: 1.2; }\n.cc4-cell small { display: block; font-size: 10px; color: #94a6b8; }\n.cc4-cell b { font-size: 15px; color: var(--ink); font-weight: 700; }\n.cc4-cell.cc4-dup { opacity: .35; }\n.cc4-cell.cc4-one { border-color: var(--maroon); }\n.cc4-table { border: 1px solid var(--line); border-radius: 5px; overflow: hidden; font-family: 'Inconsolata', monospace; font-size: 13px; }\n.cc4-tr { display: grid; grid-template-columns: 44px 1fr 44px 76px; gap: 8px; align-items: center;\n  padding: 7px 12px; border-bottom: 1px solid #eef3f7; color: var(--ink2); }\n.cc4-tr:last-child { border-bottom: 0; }\n.cc4-tr.cc4-th { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; background: #fbfcfe; font-family: 'Open Sans', sans-serif; }\n.cc4-tr[data-on=true] { background: #f6faf7; color: var(--ink); }\n.cc4-tr[data-on=false]:not(.cc4-th) { opacity: .5; }\n.cc4-tag { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; padding: 2px 6px; border-radius: 3px;\n  text-align: center; font-family: 'Josefin Sans', sans-serif; background: #eef3f7; color: var(--ink2); }\n.cc4-tr[data-on=true] .cc4-tag { background: #dcefe3; color: var(--green); }\n.cc4-bars { margin: 6px 0 4px; }\n.cc4-bar-row { display: grid; grid-template-columns: 96px 1fr; gap: 10px; align-items: center; margin: 8px 0; }\n.cc4-bar-cap { font-size: 12px; color: var(--ink2); }\n.cc4-bar-track { display: block; height: 14px; background: #eef3f7; border-radius: 3px; overflow: hidden; }\n.cc4-bar { display: block; height: 100%; width: 0; background: var(--green); border-radius: 3px; transition: width .15s; }\n.cc4-bar.cc4-bar-bad { background: var(--maroon); }\n@media (max-width: 520px) {\n  .dpw-readout { gap: 16px; }\n  .cc4-tr { grid-template-columns: 42px 1fr 24px 56px; gap: 6px; padding: 7px 8px; font-size: 12px; }\n  .cc4-bar-row { grid-template-columns: 1fr; gap: 3px; }\n}\n@media (prefers-reduced-motion: reduce) { .dpw * { transition: none !important; } }\n</style>\n<script>\n(function () {\n  var root = document.getElementById('cc4-gen');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var p = 7, g = 3;\n  var bases = root.querySelector('#cc4-bases'), cells = root.querySelector('#cc4-cells');\n  var CAP = '<span class=\"dpw-toggle-cap\">Base g <span class=\"dpw-inflate\">(filled chips are generators)</span></span>';\n\n  // multiplicative order of a mod p: the first k with a^k = 1\n  function order(a) { var v = a % p, k = 1; while (v !== 1) { v = (v * a) % p; k++; } return k; }\n\n  function buildBases() {\n    bases.innerHTML = CAP;\n    for (var a = 1; a < p; a++) (function (a) {\n      var b = document.createElement('button');\n      b.className = 'cc4-chip'; b.textContent = a;\n      b.setAttribute('data-g', a);\n      b.setAttribute('data-gen', String(order(a) === p - 1));\n      on(b, 'click', function () { g = a; draw(); });\n      bases.appendChild(b);\n    })(a);\n  }\n\n  function draw() {\n    var ord = order(g), html = '', v = 1, gens = 0;\n    for (var k = 1; k < p; k++) {\n      v = (v * g) % p;\n      html += '<span class=\"cc4-cell' + (k > ord ? ' cc4-dup' : '') + (v === 1 && k <= ord ? ' cc4-one' : '') +\n        '\"><small>' + g + '<sup>' + k + '</sup></small><b>' + v + '</b></span>';\n    }\n    cells.innerHTML = html;\n    for (var a = 1; a < p; a++) if (order(a) === p - 1) gens++;\n    [].forEach.call(bases.querySelectorAll('.cc4-chip'), function (c) { c.setAttribute('data-on', String(+c.getAttribute('data-g') === g)); });\n    root.querySelector('#cc4-powcap').textContent = 'Powers of ' + g + ' mod ' + p;\n    root.querySelector('#cc4-hit').textContent = ord + ' of ' + (p - 1);\n    root.querySelector('#cc4-rep').textContent = ord;\n    root.querySelector('#cc4-count').textContent = gens + ' of ' + (p - 1);\n    var gv = root.querySelector('#cc4-gv');\n    if (ord === p - 1) { gv.className = 'dpw-verdict dpw-ok'; gv.textContent = g + ' is a generator: every element appears exactly once'; }\n    else { gv.className = 'dpw-verdict'; gv.textContent = g + ' is not a generator: it comes back to 1 after ' + ord + (ord === 1 ? ' power' : ' powers'); }\n  }\n\n  [].forEach.call(root.querySelectorAll('[data-p]'), function (b) {\n    on(b, 'click', function () {\n      p = +b.getAttribute('data-p');\n      [].forEach.call(root.querySelectorAll('[data-p]'), function (o) { o.setAttribute('data-on', String(o === b)); });\n      if (g >= p) g = 3;\n      buildBases(); draw();\n    });\n  });\n  buildBases(); draw();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('cc4-sqm');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var G = 3, p = 7;\n  var xr = root.querySelector('#cc4-xr'), table = root.querySelector('#cc4-table');\n\n  function draw() {\n    var x = +xr.value, bin = x.toString(2), n = bin.length;\n    root.querySelector('#cc4-x').textContent = x;\n    root.querySelector('#cc4-bin').textContent = bin;\n\n    var html = '<div class=\"cc4-tr cc4-th\"><span>power</span><span>value mod ' + p + '</span><span>bit</span><span></span></div>';\n    var sq = G % p, prev = null, picked = [], result = 1;\n    for (var i = 0; i < n; i++) {\n      if (i > 0) { prev = sq; sq = (sq * sq) % p; }\n      var bit = (x >> i) & 1;\n      if (bit) { picked.push(sq); result = (result * sq) % p; }\n      html += '<div class=\"cc4-tr\" data-on=\"' + (bit ? 'true' : 'false') + '\"><span>' + G + '<sup>' + (1 << i) + '</sup></span>' +\n        '<span>' + (i === 0 ? sq : prev + '² = ' + (prev * prev) + ' ≡ ' + sq) + '</span>' +\n        '<span>' + bit + '</span><span class=\"cc4-tag\">' + (bit ? 'take' : 'skip') + '</span></div>';\n    }\n    table.innerHTML = html;\n\n    var raw = 1; picked.forEach(function (v) { raw *= v; });       // product before the final mod (stays small for these p)\n    var shown = picked.slice().reverse().join(' × ');\n    root.querySelector('#cc4-prod').innerHTML = G + '<sup>' + x + '</sup> ≡ ' +\n      (picked.length > 1 && raw < 1e15 ? shown + ' = ' + raw + ' ≡ ' : picked.length > 1 ? shown + ' ≡ ' : '') + result + ' (mod ' + p + ')';\n\n    var fast = (n - 1) + (picked.length - 1), naive = x - 1;\n    root.querySelector('#cc4-fast').textContent = fast;\n    root.querySelector('#cc4-naive').textContent = naive;\n\n    // independent check: multiply by g one step at a time, with no squaring\n    var slow = 1; for (var k = 0; k < x; k++) slow = (slow * G) % p;\n    var c = root.querySelector('#cc4-check');\n    var exact = x <= 20 ? G + '^' + x + ' = ' + Math.pow(G, x).toLocaleString('en-US') + ' ≡ ' : 'one step at a time also gives ';\n    if (slow === result) { c.className = 'dpw-verdict dpw-ok'; c.textContent = 'check: ' + exact + slow + ' (mod ' + p + ')'; }\n    else { c.className = 'dpw-verdict'; c.textContent = 'mismatch: squaring gave ' + result + ', one step at a time gave ' + slow; }\n  }\n\n  [].forEach.call(root.querySelectorAll('[data-p]'), function (b) {\n    on(b, 'click', function () {\n      p = +b.getAttribute('data-p');\n      [].forEach.call(root.querySelectorAll('[data-p]'), function (o) { o.setAttribute('data-on', String(o === b)); });\n      draw();\n    });\n  });\n  on(xr, 'input', draw);\n  draw();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('cc4-scale');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var nr = root.querySelector('#cc4-nr');\n  var SUP = { '-': '⁻', 0: '⁰', 1: '¹', 2: '²', 3: '³', 4: '⁴', 5: '⁵', 6: '⁶', 7: '⁷', 8: '⁸', 9: '⁹' };\n  function sup(e) { return String(e).split('').map(function (c) { return SUP[c]; }).join(''); }\n  function fmt(v) { // BigInt -> readable\n    var s = v.toString();\n    if (s.length <= 15) return Number(s).toLocaleString('en-US');\n    var e = s.length - 1, m = Math.round(Number(s.slice(0, 3)) / 10) / 10;\n    if (m >= 10) { m = 1; e += 1; }\n    return m.toFixed(1) + '×10' + sup(e);\n  }\n  function log2big(v) { var s = v.toString(2); return s.length - 1; }\n\n  function draw() {\n    var n = +nr.value;\n    var naive = (1n << BigInt(n)) - 2n, fast = BigInt(2 * n - 2);\n    root.querySelector('#cc4-n').textContent = n;\n    root.querySelector('#cc4-sn').textContent = fmt(naive);\n    root.querySelector('#cc4-sf').textContent = fmt(fast);\n    root.querySelector('#cc4-b1').style.width = Math.max(1, (log2big(naive) / 256) * 100) + '%';\n    root.querySelector('#cc4-b2').style.width = Math.max(1, (log2big(fast) / 256) * 100) + '%';\n    // small n: exact decimal ratio; large n: BigInt ratio (Number would overflow past 2^1024 and loses digits long before)\n    var times = n <= 40 ? (Number(naive) / Number(fast)) : null;\n    var shown = times !== null ? (times < 10 ? times.toFixed(1) : Math.round(times).toLocaleString('en-US')) : fmt(naive / fast);\n    root.querySelector('#cc4-sv').textContent = naive <= fast\n      ? 'at ' + n + ' bits both ways take ' + fmt(fast) + ' multiplications'\n      : 'at ' + n + ' bits, squaring is about ' + shown + ' times less work';\n  }\n  on(nr, 'input', draw);\n  draw();\n})();\n</script>","headings":[{"value":"The group we are working in","depth":2},{"value":"The generator","depth":2},{"value":"The hard direction","depth":2},{"value":"The easy direction","depth":2},{"value":"How much work is that?","depth":2},{"value":"Where this goes next","depth":2}],"frontmatter":{"date_created":"2026-08-28","path":"/blog/crypto-club-square-and-multiply","tags":["Cryptography","Bitcoin"],"title":"Why Computing g To The x Is Easy"}},"currPost":{"html":"<p>Just for a recap, the discrete log problem is the fact that if we have an equation like this, where g is a generator of the group Z<sub>p</sub><sup>∗</sup>, and x is your private key, calculating f(x) is easy with binary exponentiation. But given g, f(x), and p, finding x is hard.</p>\n<div class=\"dpw-formula\">f(x) = g<sup>x</sup> mod p</div>\n<p>From here, I want to move on to talking about elliptic curve cryptography, or ECC. This is a different candidate one-way function, which works over a different group.</p>\n<h2 id=\"a-different-kind-of-group\" style=\"position:relative;\"><a href=\"#a-different-kind-of-group\" aria-label=\"a different kind of group permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>A different kind of group</h2>\n<p>In the discrete log problem, we were working over the multiplicative group, and the multiplicative group has a few properties that it must satisfy. The first one was closure. The second was associativity. The third was an identity element. And the fourth was an inverse.</p>\n<p>The elliptic curve works over a different group. Here, we are talking about additive groups. A standard elliptic curve equation is this:</p>\n<div class=\"dpw-formula\">y<sup>2</sup> = x<sup>3</sup> + ax + b</div>\n<p>At the x-axis, it's reflected. The exact same thing is being shown here, but it's negative.</p>\n<p>An additive group has a different set of properties that it must fulfill. An identity element exists. The inverse must exist. We must also have point addition defined. And lastly, we should have point doubling also defined. What do all of these mean?</p>\n<p>The identity element. In an additive group, we have this special abstract point. You can just call it big O. It's just an abstract point, which is called the point of infinity. To be honest, I don't think it's that easy to visualize these things. With integers, it's very easy to just visualize things, but when we start moving into these graph-based groups, things become more abstract. Its purpose is that if we have a point P on this curve, P + O should equal P. Nothing should happen to it. I can't just say zero here, because I think with the curve properties, that might not be true.</p>\n<p>The inverse. We have this point, which is just coordinates on an xy coordinate plane. There also exists −P, whose coordinates are (x, −y). In an elliptic curve, the top half is just a reflection of the bottom half, because of this y<sup>2</sup>. For every point P, there's also a negative of that point, which should mean that when you add that original point with that inverse point, you should get the identity element. This is very similar language to our multiplicative group: when we have our original element and we multiply it by the inverse of that element, we get the identity element, which in that case was one.</p>\n<div class=\"dpw-formula\">P = (x, y) &nbsp;&nbsp;&nbsp; &minus;P = (x, &minus;y) &nbsp;&nbsp;&nbsp; P + (&minus;P) = O</div>\n<p>Point addition. If you draw a straight line through P and Q, by the nature of this graph you are bound to intersect one more point, which we can call R. The negative of that R, which is −R, is P + Q.</p>\n<div class=\"dpw-formula\">P + Q = &minus;R</div>\n<p>Point doubling. We have a point P, and we want to find 2P, which is the same as P + P. There's only one P, so you can't draw a line between two points. But if I draw the tangent line, the line which just touches the curve at P, and extend it until it hits the graph again, I get one more point. We're able to double a point by drawing the tangent line through it and then reflecting it across the x-axis. And that gives us the double of that point.</p>\n<h2 id=\"why-−r\" style=\"position:relative;\"><a href=\"#why-%E2%88%92r\" aria-label=\"why −r permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Why −R?</h2>\n<p>Someone asked the obvious question: the line meets the curve at R, so why is the answer −R and not R? This is the property of the graph. In an elliptic curve, if you take P and Q, two random points on the curve, and you draw a line through them, it's guaranteed to intersect one more point on that curve, and the negative of that point is the answer to P + Q. The exact concept, I'm not sure where the math is coming from there. For this lesson specifically, proving the definition of an additive group is not the scope of this session. It might be a good exercise: prove this. But for now, I'm just trusting the literature.</p>\n<p>Someone in the room suggested it might simply be a convention, and that is close. The group law is set up so that three points on one line add up to the identity, P + Q + R = O. Move R to the other side and you get P + Q = −R.</p>\n<p>That's why I was also saying it's hard to visualize this. Let's take a step back.</p>\n<h2 id=\"multiplication-on-a-parabola\" style=\"position:relative;\"><a href=\"#multiplication-on-a-parabola\" aria-label=\"multiplication on a parabola permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Multiplication on a parabola</h2>\n<p>Let's look at a parabola, which is simple. Everyone can visualize this easily. The equation is y = x<sup>2</sup>. The idea is that within this graph, we're able to do operations. That's the idea you should get from even this elliptic curve. In this case, the operations are addition. In a parabola, we are able to do multiplication.</p>\n<p>If I want to do a × b, what I'm going to do in a parabola is pick P and pick Q, which are (−a, a<sup>2</sup>) and (b, b<sup>2</sup>). In this case, it's going to be 3 × 4, which is 12. We pick these two points: (−3, 9) and (4, 16). And the line through them crosses the y-axis at 12 as well.</p>\n<div class=\"dpw-formula\">P = (&minus;3, 9) &nbsp;&nbsp;&nbsp; Q = (4, 16) &nbsp;&nbsp;&nbsp; the line through them crosses the y-axis at 12 = 3 &times; 4</div>\n<p>Does that work for any two numbers, or was 3 and 4 a lucky pick? Move a and b and watch where the line crosses.</p>\n<div class=\"dpw\" id=\"cc5-par\">\n  <div class=\"dpw-controls\">\n    <label class=\"dpw-label\">a &nbsp; <span class=\"dpw-val\" id=\"cc5-a\">3</span>\n      <input type=\"range\" id=\"cc5-ar\" min=\"0.5\" max=\"6\" step=\"0.5\" value=\"3\" />\n    </label>\n    <label class=\"dpw-label\" style=\"margin-top:12px\">b &nbsp; <span class=\"dpw-val\" id=\"cc5-b\">4</span>\n      <input type=\"range\" id=\"cc5-br\" min=\"0.5\" max=\"6\" step=\"0.5\" value=\"4\" />\n    </label>\n  </div>\n  <svg id=\"cc5-psvg\" viewBox=\"0 0 480 300\" class=\"dpw-svg\" role=\"img\" aria-label=\"The parabola y equals x squared with a line through two points\"></svg>\n  <div class=\"dpw-readout\">\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc5-c\">&ndash;</span><span class=\"dpw-cap\">where the line crosses the y-axis</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc5-ab\">&ndash;</span><span class=\"dpw-cap\"><span class=\"dpw-var\">a</span> &times; <span class=\"dpw-var\">b</span></span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc5-m\">&ndash;</span><span class=\"dpw-cap\">slope of the line</span></div>\n  </div>\n  <div class=\"dpw-verdict dpw-ok\" id=\"cc5-pv\">&ndash;</div>\n  <div class=\"dpw-hint\">The crossing point is measured from the two points, P = (&minus;a, a<sup>2</sup>) and Q = (b, b<sup>2</sup>), and is not computed as a &times; b. The two numbers are then compared.</div>\n</div>\n<p>A fact of parabolas is that our line, y = mx + c, intersects the y-axis at c, and a × b is also equal to c. For parabolas, I can just show you very quickly why it's true. We have two points, (−a, a<sup>2</sup>) and (b, b<sup>2</sup>). If I substitute them into y = mx + c, I get a<sup>2</sup> = −ma + c and b<sup>2</sup> = mb + c. We will try to solve for c.</p>\n<div class=\"dpw-formula\">a<sup>2</sup> = &minus;ma + c &nbsp;&nbsp;&nbsp;&nbsp; b<sup>2</sup> = mb + c &nbsp;&nbsp;&rArr;&nbsp;&nbsp; m = (b<sup>2</sup> &minus; c) / b</div>\n<div class=\"dpw-formula\">a<sup>2</sup>b &minus; bc = ac &minus; ab<sup>2</sup> &nbsp;&nbsp;&rArr;&nbsp;&nbsp; a<sup>2</sup>b + ab<sup>2</sup> = c(a + b) &nbsp;&nbsp;&rArr;&nbsp;&nbsp; ab(a + b) / (a + b) = c &nbsp;&nbsp;&rArr;&nbsp;&nbsp; a &middot; b = c</div>\n<p>So the (a + b) cancels. In this case, I chose three and four. I choose the points in this form, and then I draw a straight line through them, and where it crosses the y-axis is going to be a × b. And for that, this is a proof.</p>\n<h2 id=\"back-to-the-curve\" style=\"position:relative;\"><a href=\"#back-to-the-curve\" aria-label=\"back to the curve permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Back to the curve</h2>\n<p>For an elliptic curve, there's also something similar. The intuition you should understand is that we're able to do operations on a curve to get the answers of those operations. Here we were multiplying. Here we're doing addition, pretty much. That's it. And doubling is pretty much the same as point addition. Here we just have two P's, so it's P + P.</p>\n<p>I have a visual here, maybe to help understand things better. The curve is y<sup>2</sup> = x<sup>3</sup> − 2x + 2. P is (1, 1) and Q is (2, 2.45). We drew a line through them. The green dot, which is R, the reflection of that across the x-axis is the value of P + Q. As I shift my point, we're just reflecting that point, and that's giving us the addition of those two points. Now, if I just have one point, which is P, you can see that the tangent line at P hits the curve at one more point, which is the green dot, and the reflection of that is the doubling of that point P. If I move that point, we're just creating a different tangent line, and then the value of R changes.</p>\n<p>Here is that visual. Where does P + Q land when you move the points, when Q is the same point as P, and when Q is the mirror image of P?</p>\n<div class=\"dpw\" id=\"cc5-add\">\n  <div class=\"dpw-controls\">\n    <label class=\"dpw-label\">x of P &nbsp; <span class=\"dpw-val\" id=\"cc5-xp\">1.00</span>\n      <input type=\"range\" id=\"cc5-xpr\" min=\"-1.75\" max=\"3.5\" step=\"0.05\" value=\"1\" />\n    </label>\n    <label class=\"dpw-label\" style=\"margin-top:12px\">x of Q &nbsp; <span class=\"dpw-val\" id=\"cc5-xq\">2.00</span>\n      <input type=\"range\" id=\"cc5-xqr\" min=\"-1.75\" max=\"3.5\" step=\"0.05\" value=\"2\" />\n    </label>\n  </div>\n  <div class=\"dpw-toggle-row\">\n    <span class=\"dpw-toggle-cap\">Which half of the curve</span>\n    <button class=\"dpw-toggle\" id=\"cc5-pb\" data-on=\"true\">P on top</button>\n    <button class=\"dpw-toggle\" id=\"cc5-qb\" data-on=\"true\">Q on top</button>\n    <button class=\"dpw-toggle\" id=\"cc5-dbl\" data-on=\"false\">set Q = P</button>\n    <button class=\"dpw-toggle\" id=\"cc5-neg\" data-on=\"false\">set Q = &minus;P</button>\n  </div>\n  <svg id=\"cc5-asvg\" viewBox=\"0 0 480 360\" class=\"dpw-svg\" role=\"img\" aria-label=\"An elliptic curve with the line through P and Q, the third point R and its reflection\"></svg>\n  <div class=\"dpw-readout\">\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc5-r\">&ndash;</span><span class=\"dpw-cap\">R, where the line hits again</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"cc5-sum\">&ndash;</span><span class=\"dpw-cap\">P + Q = &minus;R</span></div>\n  </div>\n  <div class=\"dpw-verdict dpw-ok\" id=\"cc5-av\">&ndash;</div>\n  <div class=\"dpw-hint\">The curve is y<sup>2</sup> = x<sup>3</sup> &minus; 2x + 2, the one from the session, drawn over the real numbers. The line is solved for its third crossing, and the result is checked against the curve equation each time.</div>\n</div>\n<p>When Q is the mirror image of P the line is vertical and never meets the curve a third time. That is the case the point at infinity exists for: P + (−P) = O.</p>\n<h2 id=\"from-the-group-law-to-bitcoins-keys\" style=\"position:relative;\"><a href=\"#from-the-group-law-to-bitcoins-keys\" aria-label=\"from the group law to bitcoins keys permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>From the group law to Bitcoin's keys</h2>\n<p>Knowing that the elliptic curve has these properties of an additive group, we can now look at the elliptic curve discrete log problem. Similar to how we talked about the discrete log problem, the equation is just this:</p>\n<div class=\"dpw-formula\">Q = k &middot; G</div>\n<p>Q is going to be your public key. Remember that Q is a coordinate point. It's not an integer. So it's going to be in the form (x, y). G is a generator. And k would be your private key. In the case of the discrete log problem, x was your private key. Similarly, k is your private key, and the public key is what the output will be, which, again, is a point on an elliptic curve.</p>\n<p>If you want to talk about Bitcoin specifically: the standard elliptic curve equation has x and y, that's all good, but what are these constants, a and b? Different equations can change this constant value, and then it generates a new curve. If I remember correctly, for Bitcoin, a is zero and b is seven. In that case, the equation becomes y<sup>2</sup> = x<sup>3</sup> + 7. For Bitcoin, this is the elliptic curve that they use to pick points on the curve and generate public and private keys.</p>\n<div class=\"dpw-formula\">secp256k1: &nbsp; y<sup>2</sup> = x<sup>3</sup> + 7</div>\n<p>Calculating Q = k · G is easy, given point addition and point doubling. The generator is a point on this curve, and you add it k times, where k is generated randomly. You can do point doubling and point addition for that.</p>\n<p>Two people corrected me here. k is not a point on the curve. It is a number, a 256-bit random number, and the generator is the point, added k times. In an additive group we cannot multiply two points. Yeah, I also think that makes more sense, to be honest.</p>\n<p>I drew this graph here, but for a lot of curves, there's not even a graph. You have random points scattered across the graph, and they're part of the curve, but the curve is not continuous.</p>\n<p>So it looks something like this: just random points. G is fixed. You can Google it. The upper bound of k is also fixed: a large prime, close to 2<sup>256</sup>. We start at G, and we jump around k times. It's very hard to predict how many times we jumped. Let's say it was here. This is now our Q. Given these two points that are public, it's very hard to trace these random steps that we took to find that k value. This is the intuition I understand around ECDLP.</p>\n<p>This is how Bitcoin generates its raw public keys and raw private key. I don't know what it does after generating these points. I think it compresses them and does a bunch of other stuff. But the raw points that come out from this curve are, in a sense, the raw values of your public and private key.</p>\n<h2 id=\"why-any-point-is-a-generator\" style=\"position:relative;\"><a href=\"#why-any-point-is-a-generator\" aria-label=\"why any point is a generator permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Why any point is a generator</h2>\n<p>For this specific curve, any point other than the point at infinity is a valid generator. What I understood about why that's the case: in Z<sub>p</sub><sup>∗</sup>, I said that there is at least one generator, and that's true. It's also true that not every element is a generator. We can't choose any number within this range and expect it to generate this entire range again.</p>\n<p>That is because of the fact that the order of Z<sub>p</sub><sup>∗</sup> is p − 1, because it has p − 1 elements, which means that it's composite. p is a prime, so p − 1 is even, which makes it composite. If the order of a group is composite, you can't have every element be a generator. This is a hand-wavy explanation, I guess, but you might get stuck. If you're trying to generate g<sup>1</sup>, g<sup>2</sup>, g<sup>3</sup>, and you end up at an element that you've already seen before, then you're going to start that loop again. That can exist for groups which have a size of a composite number, because they have many factors.</p>\n<p>In the case of this curve, the order of this group is prime. It has a prime number of elements inside. So if we choose any random point inside this group, we are not expected to accidentally start this loop, where we keep repeating the same numbers and the other numbers are missed out. That's the hand-wavy explanation I'll give, and the best that I understand, for why, in the case of Bitcoin, any point is a valid generator.</p>\n<style>\n.dpw {\n  --ink: #1b2228; --ink2: #5b7085; --line: #dae4ed;\n  --maroon: #a72e2b; --maroon-d: #6a1d1b; --rose: #f2cdcc; --green: #3f8f5b; --slate: #8ba2b8;\n  border: 1px solid var(--line); border-radius: 6px; padding: 20px;\n  margin: 32px 0; background: #fff; font-family: 'Open Sans', sans-serif;\n}\n.dpw * { box-sizing: border-box; }\n/* index.scss sets font on every span directly; let class-less spans inherit from the widget instead */\n.dpw span:not([class]) { font-size: inherit; line-height: inherit; font-family: inherit; }\n.dpw-formula { text-align: center; font-family: 'Inconsolata', monospace; font-size: 17px;\n  color: #1b2228; margin: 22px 0; letter-spacing: .01em; line-height: 1.6; overflow-x: auto; }\n.dpw-formula sup, .dpw-formula sub { font-size: 11px; }\n.dpw-controls { margin-bottom: 14px; }\n.dpw-label { display: block; font-size: 13px; color: var(--ink2); }\n.dpw-label input[type=range] { display: block; width: 100%; margin: 8px 0 0; accent-color: var(--maroon); }\n.dpw-val { color: var(--maroon-d); font-family: 'Inconsolata', monospace; font-weight: 700; }\n.dpw-hint { font-size: 12px; color: var(--ink2); margin-top: 10px; font-style: italic; line-height: 1.55; }\n.dpw-svg { width: 100%; height: auto; display: block; margin: 6px 0 4px;\n  background: linear-gradient(180deg, #fbfcfe, #f4f7fa); border-radius: 4px; }\n.dpw-verdict { margin: 10px 0 4px; padding: 8px 12px; border-radius: 4px; font-size: 13px; font-weight: 700;\n  background: var(--rose); color: var(--maroon-d); text-align: center; font-family: 'Inconsolata', monospace; }\n.dpw-verdict.dpw-ok { background: #dcefe3; color: var(--green); }\n.dpw-readout { display: flex; gap: 24px; margin-top: 12px; flex-wrap: wrap; }\n.dpw-stat { display: flex; flex-direction: column; }\n.dpw-num { font-family: 'Josefin Sans', sans-serif; font-size: 23px; color: var(--maroon-d); line-height: 1.15; }\n.dpw-cap { font-size: 11px; color: var(--ink2); text-transform: uppercase; letter-spacing: .04em; }\n/* variable names keep their case inside the upper-cased captions (k is a number, G is a point) */\n.dpw-cap .dpw-var { text-transform: none; font-size: inherit; line-height: inherit; font-family: inherit; }\n.dpw-toggle-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }\n.dpw-toggle-cap { width: 100%; margin-bottom: 3px; font-size: 12px; color: var(--ink2); }\n.dpw-toggle { font-family: 'Inconsolata', monospace; font-size: 12px; border: 1px solid var(--line);\n  background: #fff; color: var(--ink2); padding: 5px 9px; border-radius: 4px; cursor: pointer; transition: all .15s; }\n.dpw-toggle[data-on=true] { background: var(--maroon); color: #fff; border-color: var(--maroon); }\n@media (max-width: 520px) { .dpw-readout { gap: 16px; } .dpw-num { font-size: 19px; } }\n@media (prefers-reduced-motion: reduce) { .dpw * { transition: none !important; } }\n</style>\n<script>\n(function () {\n  var root = document.getElementById('cc5-par');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var SVG = 'http://www.w3.org/2000/svg', svg = root.querySelector('#cc5-psvg');\n  var ar = root.querySelector('#cc5-ar'), br = root.querySelector('#cc5-br');\n  var W = 480, H = 300, XMIN = -7, XMAX = 7, YMIN = -3, YMAX = 40;\n  function el(n, at, txt) { var e = document.createElementNS(SVG, n); for (var k in at) e.setAttribute(k, at[k]); if (txt !== undefined) e.textContent = txt; return e; }\n  function sx(x) { return (x - XMIN) / (XMAX - XMIN) * W; }\n  function sy(y) { return H - (y - YMIN) / (YMAX - YMIN) * H; }\n  function num(v) { return (Math.round(v * 100) / 100).toString(); }\n\n  function draw() {\n    var a = +ar.value, b = +br.value;\n    root.querySelector('#cc5-a').textContent = num(a);\n    root.querySelector('#cc5-b').textContent = num(b);\n    var x1 = -a, y1 = a * a, x2 = b, y2 = b * b;\n    var m = (y2 - y1) / (x2 - x1);          // slope from the two points\n    var c = y1 - m * x1;                    // where that line meets x = 0\n    var FS = Math.min(20, 12 * (W / (svg.getBoundingClientRect().width || W)));\n\n    while (svg.firstChild) svg.removeChild(svg.firstChild);\n    svg.appendChild(el('line', { x1: 0, x2: W, y1: sy(0), y2: sy(0), stroke: '#dae4ed' }));\n    svg.appendChild(el('line', { x1: sx(0), x2: sx(0), y1: 0, y2: H, stroke: '#dae4ed' }));\n    var d = '';\n    for (var x = XMIN; x <= XMAX + 1e-9; x += 0.1) d += (d ? 'L' : 'M') + sx(x).toFixed(1) + ' ' + sy(x * x).toFixed(1);\n    svg.appendChild(el('path', { d: d, fill: 'none', stroke: '#8ba2b8', 'stroke-width': 1.5 }));\n    svg.appendChild(el('line', { x1: sx(XMIN), y1: sy(m * XMIN + c), x2: sx(XMAX), y2: sy(m * XMAX + c), stroke: '#a72e2b', 'stroke-width': 1.5 }));\n    // labels sit outside the two points, but flip inwards when a point is close to the edge of the chart\n    var pIn = sx(x1) < 130, qIn = sx(x2) > W - 130;\n    [[x1, y1, 'P', pIn ? 'start' : 'end', pIn ? 8 : -8], [x2, y2, 'Q', qIn ? 'end' : 'start', qIn ? -8 : 8]].forEach(function (p) {\n      svg.appendChild(el('circle', { cx: sx(p[0]), cy: sy(p[1]), r: 5, fill: '#6a1d1b' }));\n      svg.appendChild(el('text', { x: sx(p[0]) + p[4], y: sy(p[1]) - 6, 'text-anchor': p[3], 'font-size': FS, fill: '#1b2228', 'font-family': 'Inconsolata, monospace' }, p[2] + ' (' + num(p[0]) + ', ' + num(p[1]) + ')'));\n    });\n    svg.appendChild(el('circle', { cx: sx(0), cy: sy(c), r: 6, fill: '#3f8f5b' }));\n    svg.appendChild(el('text', { x: sx(0) + 10, y: sy(c) + FS * 1.1, 'font-size': FS, fill: '#3f8f5b', 'font-family': 'Inconsolata, monospace' }, 'c = ' + num(c)));\n\n    root.querySelector('#cc5-c').textContent = num(c);\n    root.querySelector('#cc5-ab').textContent = num(a * b);\n    root.querySelector('#cc5-m').textContent = num(m);\n    var v = root.querySelector('#cc5-pv'), same = Math.abs(c - a * b) < 1e-9;\n    v.className = 'dpw-verdict' + (same ? ' dpw-ok' : '');\n    v.textContent = same ? 'the line crosses at ' + num(c) + ', which is ' + num(a) + ' × ' + num(b)\n                         : 'crossing ' + num(c) + ' does not match ' + num(a) + ' × ' + num(b);\n  }\n  on(ar, 'input', draw); on(br, 'input', draw); on(window, 'resize', draw);\n  draw();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('cc5-add');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var SVG = 'http://www.w3.org/2000/svg', svg = root.querySelector('#cc5-asvg');\n  var xpr = root.querySelector('#cc5-xpr'), xqr = root.querySelector('#cc5-xqr');\n  var pb = root.querySelector('#cc5-pb'), qb = root.querySelector('#cc5-qb');\n  var A = -2, B = 2;                                   // y^2 = x^3 - 2x + 2\n  var W = 480, H = 360, XMIN = -2.6, XMAX = 5, YMIN = -10, YMAX = 10;\n  var pTop = true, qTop = true;\n  function f(x) { return x * x * x + A * x + B; }\n  function el(n, at, txt) { var e = document.createElementNS(SVG, n); for (var k in at) e.setAttribute(k, at[k]); if (txt !== undefined) e.textContent = txt; return e; }\n  function sx(x) { return (x - XMIN) / (XMAX - XMIN) * W; }\n  function sy(y) { return H - (y - YMIN) / (YMAX - YMIN) * H; }\n  function num(v) { return (Math.round(v * 100) / 100).toFixed(2); }\n  function pt(p) { return '(' + num(p[0]) + ', ' + num(p[1]) + ')'; }\n  // leftmost point of the curve: the real root of x^3 - 2x + 2\n  var ROOT = (function () { var lo = -3, hi = 0; for (var i = 0; i < 60; i++) { var mid = (lo + hi) / 2; if (f(mid) < 0) lo = mid; else hi = mid; } return hi; })();\n  function onCurve(x, top) { var v = Math.max(0, f(Math.max(x, ROOT))); return [Math.max(x, ROOT), (top ? 1 : -1) * Math.sqrt(v)]; }\n\n  function draw() {\n    var P = onCurve(+xpr.value, pTop), Q = onCurve(+xqr.value, qTop);\n    root.querySelector('#cc5-xp').textContent = num(P[0]);\n    root.querySelector('#cc5-xq').textContent = num(Q[0]);\n    pb.textContent = pTop ? 'P on top' : 'P on bottom'; pb.setAttribute('data-on', String(pTop));\n    qb.textContent = qTop ? 'Q on top' : 'Q on bottom'; qb.setAttribute('data-on', String(qTop));\n    var FS = Math.min(20, 12 * (W / (svg.getBoundingClientRect().width || W)));\n\n    var sameX = Math.abs(P[0] - Q[0]) < 1e-9, sameY = Math.abs(P[1] - Q[1]) < 1e-9;\n    var mode = sameX && sameY ? (Math.abs(P[1]) < 1e-9 ? 'inf' : 'double') : sameX ? 'inf' : 'add';\n    var m = null, R = null, S = null;\n    if (mode === 'add') m = (Q[1] - P[1]) / (Q[0] - P[0]);\n    if (mode === 'double') m = (3 * P[0] * P[0] + A) / (2 * P[1]);\n    if (m !== null) {\n      var x3 = m * m - P[0] - Q[0];                    // third crossing of the line with the curve\n      var yR = m * (x3 - P[0]) + P[1];\n      R = [x3, yR]; S = [x3, -yR];                     // P + Q is R reflected across the x-axis\n    }\n\n    while (svg.firstChild) svg.removeChild(svg.firstChild);\n    svg.appendChild(el('line', { x1: 0, x2: W, y1: sy(0), y2: sy(0), stroke: '#dae4ed' }));\n    svg.appendChild(el('line', { x1: sx(0), x2: sx(0), y1: 0, y2: H, stroke: '#dae4ed' }));\n    var up = [], dn = [];\n    for (var i = 0; i <= 400; i++) { var x = ROOT + (XMAX - ROOT) * (i / 400) * (i / 400), y = Math.sqrt(Math.max(0, f(x))); up.push(sx(x).toFixed(1) + ' ' + sy(y).toFixed(1)); dn.push(sx(x).toFixed(1) + ' ' + sy(-y).toFixed(1)); }\n    svg.appendChild(el('path', { d: 'M' + up.reverse().join('L') + 'L' + dn.join('L'), fill: 'none', stroke: '#8ba2b8', 'stroke-width': 1.5 }));\n\n    if (m !== null) {\n      svg.appendChild(el('line', { x1: sx(XMIN), y1: sy(m * (XMIN - P[0]) + P[1]), x2: sx(XMAX), y2: sy(m * (XMAX - P[0]) + P[1]), stroke: '#a72e2b', 'stroke-width': 1.5 }));\n      svg.appendChild(el('line', { x1: sx(R[0]), y1: sy(R[1]), x2: sx(S[0]), y2: sy(S[1]), stroke: '#3f8f5b', 'stroke-width': 1, 'stroke-dasharray': '4 4' }));\n    } else {\n      svg.appendChild(el('line', { x1: sx(P[0]), y1: 0, x2: sx(P[0]), y2: H, stroke: '#a72e2b', 'stroke-width': 1.5 }));\n    }\n    function dot(p, label, fill, dx, anchor) {\n      svg.appendChild(el('circle', { cx: sx(p[0]), cy: sy(p[1]), r: 5, fill: fill }));\n      svg.appendChild(el('text', { x: sx(p[0]) + dx, y: sy(p[1]) - 7, 'text-anchor': anchor, 'font-size': FS, fill: '#1b2228', 'font-family': 'Inconsolata, monospace' }, label));\n    }\n    dot(P, mode === 'double' ? 'P = Q' : 'P', '#6a1d1b', -8, 'end');\n    if (mode !== 'double') dot(Q, 'Q', '#6a1d1b', 8, 'start');\n    if (R) { dot(R, 'R', '#3f8f5b', 8, 'start'); dot(S, mode === 'double' ? '2P' : 'P + Q', '#1b2228', 8, 'start'); }\n\n    var v = root.querySelector('#cc5-av');\n    root.querySelector('#cc5-dbl').setAttribute('data-on', String(mode === 'double'));\n    root.querySelector('#cc5-neg').setAttribute('data-on', String(mode === 'inf'));\n    if (!R) {\n      root.querySelector('#cc5-r').textContent = 'none';\n      root.querySelector('#cc5-sum').textContent = 'O';\n      v.className = 'dpw-verdict dpw-ok';\n      v.textContent = 'vertical line: P + (−P) = O, the point at infinity';\n      return;\n    }\n    root.querySelector('#cc5-r').textContent = pt(R);\n    root.querySelector('#cc5-sum').textContent = pt(S);\n    // independent check: the result has to satisfy y^2 = x^3 - 2x + 2\n    var lhs = S[1] * S[1], rhs = f(S[0]), okCurve = Math.abs(lhs - rhs) <= 1e-6 * Math.max(1, Math.abs(rhs));\n    var off = R[0] > XMAX || Math.abs(R[1]) > YMAX ? ' (off the chart)' : '';\n    v.className = 'dpw-verdict' + (okCurve ? ' dpw-ok' : '');\n    v.textContent = okCurve\n      ? (mode === 'double' ? 'tangent at P: 2P = ' : 'P + Q = ') + pt(S) + ', and it is on the curve' + off\n      : 'result ' + pt(S) + ' is not on the curve';\n  }\n\n  on(xpr, 'input', draw); on(xqr, 'input', draw); on(window, 'resize', draw);\n  on(pb, 'click', function () { pTop = !pTop; draw(); });\n  on(qb, 'click', function () { qTop = !qTop; draw(); });\n  on(root.querySelector('#cc5-dbl'), 'click', function () { xqr.value = xpr.value; qTop = pTop; draw(); });\n  on(root.querySelector('#cc5-neg'), 'click', function () { xqr.value = xpr.value; qTop = !pTop; draw(); });\n  draw();\n})();\n</script>","headings":[{"value":"A different kind of group","depth":2},{"value":"Why −R?","depth":2},{"value":"Multiplication on a parabola","depth":2},{"value":"Back to the curve","depth":2},{"value":"From the group law to Bitcoin's keys","depth":2},{"value":"Why any point is a generator","depth":2}],"frontmatter":{"date_created":"2026-09-04","path":"/blog/crypto-club-multiplying-with-a-parabola","tags":["Cryptography","Bitcoin","Elliptic Curves"],"title":"Multiplying With A Parabola"}},"nextPost":{"html":"<p>On 21 March 2025 I finished reading SecureNN and wrote down five questions, one observation, and a postscript claiming the paper had a typo that broke security. This is that review, checked.</p>\n<p><strong>The version I read</strong> was <a href=\"https://eprint.iacr.org/archive/2018/442/1526310365.pdf\">eprint 2018/442, revision of 14 May 2018</a>, titled <em>SecureNN: Efficient and Private Neural Network Training</em>, by Wagh, Gupta and Chandran.</p>\n<p><strong>The current version</strong> is <a href=\"https://eprint.iacr.org/2018/442.pdf\">the revision of 8 March 2019</a>, which appeared at PETS 2019 and was retitled <em>SecureNN: 3-Party Secure Computation for Neural Network Training</em>. Three of my seven points were addressed in it. Four were not. I also checked everything against the <a href=\"https://github.com/snwagh/securenn-public\">reference implementation</a>, which settled three things the paper alone could not.</p>\n<p>Here is where each point landed. Click a row.</p>\n<div class=\"dpw\" id=\"score\" data-initialised=\"false\">\n  <div class=\"snn-board\" id=\"sc-board\"></div>\n  <div class=\"dpw-detail\" id=\"sc-detail\">\n    <div class=\"dpw-detail-h\">Pick a row</div>\n    <div class=\"dpw-detail-b\">Seven points from the March 2025 review, each checked against the 2018 version I read, the 2019 revision, and the C++ implementation.</div>\n  </div>\n</div>\n<h2 id=\"question-1-the-cost-of-fresh-shares\" style=\"position:relative;\"><a href=\"#question-1-the-cost-of-fresh-shares\" aria-label=\"question 1 the cost of fresh shares 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>Question 1: the cost of \"fresh\" shares</h2>\n<blockquote>\n<p>How many bits of extra randomness are required to maintain this privilege? Is it cheaper (in terms of maintaining information-theoretic security) to group some protocols together?</p>\n</blockquote>\n<p>The first half is just counting. Freshness is maintained by adding a pre-shared sharing of zero to each protocol's output. Walk one scalar ReLU and count them: one in Π<sub>SC</sub>, one in Π<sub>MSB</sub>, one in the 1×1 Π<sub>MatMul</sub> inside Π<sub>MSB</sub>, one in Π<sub>DReLU</sub>, one in the Π<sub>MatMul</sub> inside Π<sub>ReLU</sub>, and one in Π<sub>ReLU</sub> itself. Six, at ℓ bits each.</p>\n<div class=\"dpw-formula\">6&ell; &nbsp;=&nbsp; 384 bits per scalar ReLU &nbsp;&mdash;&nbsp; 6.8% of the 704 bytes it sends</div>\n<p>So the invariant is cheap. What is not cheap is the rest of the correlated randomness, and it is not the freshness masks: Π<sub>PC</sub> needs ℓ multipliers s<sub>i</sub> from <strong>Z</strong><sub>67</sub><sup>∗</sup>, ℓ more values u<sub>i</sub> for a corner case, and a common permutation of 64 elements. That permutation alone is 296 bits, and Π<sub>PC</sub> runs twice per DReLU. Add it up and one scalar ReLU consumes about 332 bytes of correlated randomness against 704 bytes on the wire.</p>\n<p>Now the second half, which is where the question was better than I knew. I asked whether grouping is cheaper <em>for information-theoretic security</em>. That assumes these bits are information-theoretic. In the version I read, so did the paper, the abstract promised \"three-party and four-party <strong>information-theoretically secure</strong> protocols,\" and Section 2.1 said \"the adversary is not restricted to run in polynomial time (i.e., we provide information-theoretic security).\"</p>\n<p>The 2019 revision says something different. Section 3.4 now spells out how the zero-shares are made:</p>\n<blockquote>\n<p>the two parties exchange a PRF key, k, and one party sets its share to z<sub>0</sub> = PRF<sub>k</sub>(ctr), while the other sets its share to z<sub>1</sub> = −PRF<sub>k</sub>(ctr)</p>\n</blockquote>\n<p>and Section 1.1 adds a sentence that is not in the 2018 version at all:</p>\n<blockquote>\n<p>All our protocols are fundamentally information-theoretically secure … <strong>However, in practice, we use pseudorandom functions to generate shared randomness</strong> as well as point-to-point secure channels between all pairs of parties thereby relying on computational assumptions for the implementation.</p>\n</blockquote>\n<p>So the answer is: <strong>zero bits.</strong> The implementation spends PRF output, not randomness, and a PRF-keyed protocol is computationally secure however uniform its transcript looks. The 2018 abstract's distinction against SecureML, they are computationally secure, we are information-theoretic, does not reach the code, and the 2019 revision is the one that says so.</p>\n<p>That also answers the grouping half. Merging protocols would drop the interior masks and save 4ℓ of the 6ℓ, about 4.5% of ReLU's communication, in exchange for the composition theorem that lets you build arbitrary networks from these pieces. Not worth it. There is a good reason to merge Π<sub>SC</sub> and Π<sub>MSB</sub>, but it is the one in Question 5, not this one.</p>\n<p>One thing did get cheaper. The same PRF now generates the Beaver triples, and the 2019 table adds a row for it: matrix multiplication drops from 2(2mn + 2nv + mv)ℓ to (2mn + 2nv + mv)ℓ, exactly half. ReLU falls from about 96ℓ to 88ℓ.</p>\n<h2 id=\"question-2-the-excluded-range\" style=\"position:relative;\"><a href=\"#question-2-the-excluded-range\" aria-label=\"question 2 the excluded range 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>Question 2: the excluded range</h2>\n<blockquote>\n<p>What is done when the value of a is in the excluded range? Do you clip the data into the very narrow range or do you abort training?</p>\n</blockquote>\n<p>Neither. There is no clipping and no abort, and I checked the C++: the only assertions in <code class=\"language-text\">Functionalities.cpp</code> are about which party is calling and what the dimensions are. Nothing anywhere tests whether a value is in range.</p>\n<p>I said \"almost 100% of our integer a is excluded,\" which is arithmetically right, the safe set has 2<sup>k+1</sup> of 2<sup>64</sup> elements. But I was treating a as if it were uniform on <strong>Z</strong><sub>L</sub>, and it never is. It is a fixed-point number with thirteen fractional bits, so |a| &#x3C; 2<sup>k</sup> is really a bound of 2<sup>k−13</sup> on the <em>real</em> value.</p>\n<p>The part I missed is that this range is not SecureNN's, and it is not really about DReLU. It is Theorem 1 of SecureML, which SecureNN cites for its truncation:</p>\n<blockquote>\n<p>In field <strong>Z</strong><sub>2<sup>l</sup></sub>, let x ∈ [0, 2<sup>l<sub>x</sub></sup>] ∪ [2<sup>l</sup> − 2<sup>l<sub>x</sub></sup>, 2<sup>l</sup>), where l > l<sub>x</sub> + 1 … Then with probability 1 − 2<sup>l<sub>x</sub>+1−l</sup>, Rec<sub>A</sub>(⌊x⌋<sub>0</sub>, ⌊x⌋<sub>1</sub>) ∈ {⌊x⌋ − 1, ⌊x⌋, ⌊x⌋ + 1}.</p>\n</blockquote>\n<p>Same set, same shape, same condition l > l<sub>x</sub> + 1 that SecureNN writes as k &#x3C; ℓ − 1. Every fixed-point multiply in the network already needs a value in that set or the local truncation of the shares fails, and it fails by roughly the size of the ring, not by one bit. DReLU inherits a constraint the arithmetic layer was already carrying, which is why nobody added a check for it.</p>\n<p>So the range comes with a failure probability, and that is the number worth looking at. Below, the circle is <strong>Z</strong><sub>2<sup>64</sup></sub> with zero at the top and the safe arcs shaded.</p>\n<div class=\"dpw\" id=\"range\" data-initialised=\"false\">\n  <div class=\"dpw-controls\">\n    <label class=\"dpw-label\">Magnitude bound k &nbsp; <span class=\"dpw-val\" id=\"rg-k\">24</span>\n      <input type=\"range\" id=\"rg-slider\" min=\"13\" max=\"62\" step=\"1\" value=\"24\" />\n    </label>\n  </div>\n  <div class=\"snn-split\">\n    <svg id=\"rg-svg\" viewBox=\"0 0 200 200\" class=\"dpw-svg snn-dial\" role=\"img\" aria-label=\"The ring Z_2^64 drawn as a circle with the safe arcs shaded\"></svg>\n    <div class=\"snn-side\">\n      <div class=\"dpw-line\"><span>safe fraction of the ring</span><span><b id=\"rg-frac\">1.8e-12</b></span></div>\n      <div class=\"dpw-line\"><span>largest real value it admits<br /><span class=\"dpw-inflate\">at 13 fractional bits</span></span><span><b id=\"rg-real\">2,048</b></span></div>\n      <div class=\"dpw-line\"><span>truncation failure, per multiply</span><span><b id=\"rg-p\">1.8e-12</b></span></div>\n      <div class=\"dpw-line\"><span>expected failures, one Network A run<br /><span class=\"dpw-inflate\">over 2.1e9 truncations</span></span><span><b id=\"rg-fail\">0.004</b></span></div>\n    </div>\n  </div>\n  <div class=\"dpw-verdict dpw-ok\" id=\"rg-verdict\">clean: a truncation failure anywhere in the run is unlikely</div>\n  <div class=\"dpw-hint\">The arcs you can see are the dangerous ones. Network A is 784&ndash;128&ndash;128&ndash;10 at batch 128 for 7,000 iterations; the truncation count assumes one truncation per output element of every forward, backward, gradient and update matrix. It is an estimate of the exponent, not a measurement.</div>\n</div>\n<p>At k = 24 the safe arcs are invisible slivers and the expected number of failures across a whole training run is 0.004. At k = 62, where the arcs cover half the circle and the picture looks reassuring, every second multiply corrupts.</p>\n<p>So ℓ = 64 is doing the work I thought it was, but for the truncation and not for DReLU. Union-bounding over the roughly 2.1 billion truncations in one Network A run pins k at 32 or below, a real-valued bound of about half a million. Comfortable for MNIST, and comfortable is the whole answer.</p>\n<p>The 2019 revision did tighten the statement. Where the version I read wrote closed intervals, [0, 2<sup>k</sup>] ∪ [2<sup>ℓ</sup> − 2<sup>k</sup>, 2<sup>ℓ</sup> − 1], the current one writes them half-open: [0, 2<sup>k</sup>) ∪ (2<sup>ℓ</sup> − 2<sup>k</sup>, 2<sup>ℓ</sup> − 1]. That is a real correction to the endpoints and it changes nothing about the size of the set. What is still missing in both is a stated bound on activations, or an assertion, or a sentence telling an implementer how much headroom they have. Anyone porting this to a domain with a wider dynamic range gets no warning.</p>\n<h2 id=\"question-3-fft-or-ntt-beaver-triples\" style=\"position:relative;\"><a href=\"#question-3-fft-or-ntt-beaver-triples\" aria-label=\"question 3 fft or ntt beaver triples 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>Question 3: FFT or NTT Beaver triples</h2>\n<blockquote>\n<p>I would be curious to hear if your team experimented with using discrete Fast Fourier Transform (FFT)-based Beaver's Triplets (or NTT since we start/end with shares of input/output values over a ring) for computing secure linear functions (matrix multiplications). Your C++ implementation uses the <em>Eigen</em> library.</p>\n</blockquote>\n<p>They could not have, and the reason is the ring. An NTT of length n needs a primitive n-th root of unity, and it needs n to be invertible. The unit group of <strong>Z</strong><sub>2<sup>64</sup></sub> is a 2-group:</p>\n<div class=\"dpw-formula\">(<b>Z</b>/2<sup>64</sup>)<sup>&lowast;</sup> &nbsp;&cong;&nbsp; <b>Z</b><sub>2</sub> &times; <b>Z</b><sub>2<sup>62</sup></sub> &nbsp;&nbsp;&rArr;&nbsp;&nbsp; no primitive n-th root of unity for n &gt; 2</div>\n<p>Any n with an odd factor has no root of unity to use; any n that is a power of two is not invertible. There is no transform. You can work around it, Schönhage–Strassen uses <strong>Z</strong><sub>2<sup>m</sup>+1</sub>, or you CRT across NTT-friendly primes, but both land you in a ring where the modulo is not free, which is the property the whole design exists to keep. The question and Question 4 have the same answer.</p>\n<p>And a free transform would not have moved the number that matters anyway. Beaver's protocol communicates the openings of E = X − A and F = Y − B, which is set by the matrix dimensions, not by how you compute the products. The paper's own microbenchmarks show arithmetic is not the constraint: the 1×100×1 matrix multiplication does essentially no arithmetic and still costs 25.2 ms on the WAN against 0.33 ms on the LAN. That 25 ms is latency and nothing else. A faster multiply optimises the 0.33.</p>\n<p>Where a transform would genuinely pay is convolutions, which SecureNN lowers to a much larger matrix multiplication by unrolling patches, that unrolling is why Conv2d costs (2m<sup>2</sup>f<sup>2</sup>i + 2f<sup>2</sup>oi + m<sup>2</sup>o)ℓ. A convolution theorem would attack communication, not just compute. But it needs a transform-friendly ring, and picking one costs the free modulo, which costs the GEMM.</p>\n<h2 id=\"question-4-was-shareconvert-forced-by-the-ring\" style=\"position:relative;\"><a href=\"#question-4-was-shareconvert-forced-by-the-ring\" aria-label=\"question 4 was shareconvert forced by the ring 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>Question 4: was ShareConvert forced by the ring?</h2>\n<blockquote>\n<p>Was F<sub>SC</sub> only created because you are fixed on operating over the ring <strong>Z</strong><sub>2<sup>64</sup></sub> (due to the practical optimizations C++ libraries make over rings of this size + you get modulo operations for FREE)?</p>\n</blockquote>\n<p>Yes, and the paper says so almost in those words. From the version I read:</p>\n<blockquote>\n<p>The ring size is set to <strong>Z</strong><sub>2<sup>64</sup></sub> and we use the <code class=\"language-text\">uint64_t</code> native C++ datatype for all variables. As noted in [SecureML], compared to using a field … this has the benefit of implementing modulo operations for free.</p>\n</blockquote>\n<p>and from Section 2 of the current one:</p>\n<blockquote>\n<p>we could execute our protocol over the ring <strong>Z</strong><sub>N</sub> with N being odd. However doing so is fairly inefficient as matrix multiplication over the ring <strong>Z</strong><sub>2<sup>64</sup></sub> … is much faster … Hence, we provide a protocol that converts values (≠ L − 1) that are secret shared over <strong>Z</strong><sub>L</sub> into shares over <strong>Z</strong><sub>L−1</sub>.</p>\n</blockquote>\n<p>That is the whole reason Π<sub>SC</sub> exists. The comparison trick needs MSB(a) = LSB(2a), which holds only over an odd ring, so the parties have to leave <strong>Z</strong><sub>2<sup>64</sup></sub> and come back. Here is what the round trip costs.</p>\n<div class=\"dpw\" id=\"cost\" data-initialised=\"false\">\n  <div class=\"dpw-toggle-row\">\n    <span class=\"dpw-toggle-cap\">Where DReLU's bytes go</span>\n    <button class=\"dpw-toggle\" id=\"ct-built\" data-on=\"true\">as built, over Z<sub>2<sup>64</sup></sub></button>\n    <button class=\"dpw-toggle\" id=\"ct-odd\">if the ring were odd throughout</button>\n  </div>\n  <svg id=\"ct-svg\" viewBox=\"0 0 480 130\" class=\"dpw-svg\" role=\"img\" aria-label=\"Communication breakdown of the DReLU protocol by sub-protocol\"></svg>\n  <div class=\"dpw-readout\">\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"ct-tot\">664 B</span><span class=\"dpw-cap\">per scalar DReLU</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"ct-rnd\">8</span><span class=\"dpw-cap\">rounds</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"ct-sc\">45.8%</span><span class=\"dpw-cap\">spent on ShareConvert</span></div>\n    <div class=\"dpw-stat\"><span class=\"dpw-num\" id=\"ct-zp\">77.1%</span><span class=\"dpw-cap\">spent on Z<sub>p</sub> bit material</span></div>\n  </div>\n  <div class=\"dpw-hint\" id=\"ct-hint\">Hover a segment. ShareConvert is 4&ell;&thinsp;log&thinsp;p + 6&ell; and ComputeMSB is 4&ell;&thinsp;log&thinsp;p + 13&ell;; together they are exactly DReLU's 8&ell;&thinsp;log&thinsp;p + 19&ell;, because the sign flip is local.</div>\n</div>\n<p><strong>304 of 664 bytes, and four of eight rounds.</strong> In the version I read the split was the same, 304 of 688. Either way, the ring choice costs about 45% of the operation that dominates the workload, the paper's own microbenchmarks put a 128×128 DReLU at 109.8 ms and 10.88 MB against 9.7 ms and 1.69 MB for their largest benchmarked matrix multiplication.</p>\n<p>Neither version prints the counterfactual, and I think it should. Running everything over <strong>Z</strong><sub>2<sup>64</sup>−1</sub> costs you Eigen's native path, but reduction modulo a Mersenne number is a fold-and-add rather than a division, so what you lose is the vectorised library call, not the modulo. SecureNN optimised the layer that was already cheap and paid for it in the layer that was not. That trade is a day of work to measure and it has not been measured.</p>\n<h2 id=\"question-5-why-is-shareconvert-its-own-function\" style=\"position:relative;\"><a href=\"#question-5-why-is-shareconvert-its-own-function\" aria-label=\"question 5 why is shareconvert its own function 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>Question 5: why is ShareConvert its own function?</h2>\n<blockquote>\n<p>Can you comment on why F<sub>SC</sub> was made into its own function? Wouldn't it be cleaner to have it be part of F<sub>MSB</sub> which would now take inputs of secret shares over ⟨a⟩<sup>L</sup> and output secret shares over ⟨a⟩<sup>L</sup> also.</p>\n</blockquote>\n<p>The premise checks out completely, and it checks out in the code too. In the paper, Π<sub>SC</sub> is invoked exactly once, at step 2 of Algorithm 6, and Π<sub>MSB</sub> exactly once, at step 3. Algorithm 6 is DReLU. There is no other caller of either, anywhere. In the implementation they sit in one function body with nothing between them:</p>\n<div class=\"gatsby-highlight\" data-language=\"cpp\"><pre class=\"language-cpp\"><code class=\"language-cpp\"><span class=\"token keyword\">void</span> <span class=\"token function\">funcRELUPrime3PC</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> vector<span class=\"token operator\">&lt;</span>myType<span class=\"token operator\">></span> <span class=\"token operator\">&amp;</span>a<span class=\"token punctuation\">,</span> vector<span class=\"token operator\">&lt;</span>myType<span class=\"token operator\">></span> <span class=\"token operator\">&amp;</span>b<span class=\"token punctuation\">,</span> size_t size<span class=\"token punctuation\">)</span>\n<span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span>size_t i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&lt;</span> size<span class=\"token punctuation\">;</span> <span class=\"token operator\">++</span>i<span class=\"token punctuation\">)</span>\n        twoA<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>a<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span> <span class=\"token operator\">&lt;&lt;</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n    <span class=\"token function\">funcShareConvertMPC</span><span class=\"token punctuation\">(</span>twoA<span class=\"token punctuation\">,</span> size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">funcComputeMSB3PC</span><span class=\"token punctuation\">(</span>twoA<span class=\"token punctuation\">,</span> b<span class=\"token punctuation\">,</span> size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span><span class=\"token punctuation\">.</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>That is the whole case. Two functionalities, one caller each, the same caller, back to back, and the intermediate value <code class=\"language-text\">twoA</code> is never used for anything else.</p>\n<div class=\"dpw\" id=\"pipe\" data-initialised=\"false\">\n  <div class=\"snn-callers\">\n    <span class=\"snn-caller-cap\">DReLU is called by</span>\n    <span class=\"snn-caller\">ReLU &nbsp;&times;1</span>\n    <span class=\"snn-caller\">Maxpool<sub>n</sub> &nbsp;&times;(n&minus;1)</span>\n    <span class=\"snn-caller\">DIV / NORM &nbsp;&times;l<sub>D</sub></span>\n  </div>\n  <svg id=\"pp-svg\" viewBox=\"0 0 480 172\" class=\"dpw-svg\" role=\"img\" aria-label=\"The DReLU pipeline, showing which ring the shares live in at each boundary\"></svg>\n  <div class=\"dpw-legend\">\n    <span class=\"dpw-key\"><i style=\"background:#3f8f5b\"></i>shares over Z<sub>L</sub>, L = 2<sup>64</sup></span>\n    <span class=\"dpw-key\"><i style=\"background:#a72e2b\"></i>shares over Z<sub>L&minus;1</sub>, the odd ring</span>\n    <span class=\"dpw-key\"><i style=\"background:#8ba2b8\"></i>bit shares over Z<sub>p</sub>, p = 67</span>\n  </div>\n  <div class=\"dpw-detail\" id=\"pp-detail\">\n    <div class=\"dpw-detail-h\">Pick a stage</div>\n    <div class=\"dpw-detail-b\">The paper declares an invariant: every main protocol takes fresh shares over Z<sub>L</sub> and returns fresh shares over Z<sub>L</sub>. These are the only two functionalities that break it, and they break it only to hand shares to each other.</div>\n  </div>\n</div>\n<p>You were right that Π<sub>MSB</sub> is the only sub-protocol expecting <strong>Z</strong><sub>L−1</sub>, and right that the two are always used together. What I would add is <em>why</em> it matters, beyond tidiness. The paper's counter-argument is one clause, Π<sub>SC</sub> \"may be of independent interest\", and that is fine for a reader but not for the analysis, because the seam is what creates the range condition in Question 2. DReLU has to compute c = 2a to satisfy Π<sub>SC</sub>'s a ≠ L − 1, and the doubling is what forces a into [0, 2<sup>k</sup>) ∪ (2<sup>ℓ</sup> − 2<sup>k</sup>, 2<sup>ℓ</sup> − 1]. That condition is proved in DReLU's lemma and then never restated: the ReLU lemma is given in the (F<sub>DReLU</sub>, F<sub>MATMUL</sub>)-hybrid model with no range condition attached, and Maxpool and Division do not mention it either.</p>\n<p>Division shows what that costs. Algorithm 8 loops i from ℓ−1 down to 0 and calls DReLU on ⟨x⟩ − ⟨u<sub>i+1</sub>⟩ − 2<sup>i</sup>⟨y⟩. At i = 63 that term has wrapped <strong>Z</strong><sub>2<sup>64</sup></sub> for any y ≥ 2, so the value handed to DReLU no longer means what the comparison needs it to mean. The implementation does not do this. It runs <code class=\"language-text\">for (looper = 1; looper &lt; FLOAT_PRECISION+1; ++looper)</code>, thirteen iterations, not sixty-four, and it scales the divisor <em>down</em> with <code class=\"language-text\">funcTruncate2PC</code> instead of scaling it up, which never overflows. The cost table agrees with the code, at 10 l<sub>D</sub> rounds. So this is the pseudocode being wrong rather than the system being broken, and it is exactly the kind of wrong you get when a precondition is proved at one level and not carried to its callers.</p>\n<p>Fold the two together, give the result the signature ⟨a⟩<sup>L</sup> → ⟨MSB(a)⟩<sup>L</sup>, and the doubling and its range condition become internal to one functionality, stated once, where they can be enforced.</p>\n<h2 id=\"the-thought-a-communication-budget\" style=\"position:relative;\"><a href=\"#the-thought-a-communication-budget\" aria-label=\"the thought a communication budget 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 thought: a communication budget</h2>\n<blockquote>\n<p>I guess the real benefits (in communication efficiency) come from achieving better accuracies with fewer epochs since we do the same number of secure operations per epoch. Network A stood out to me because it was an outlier in that it did not achieve good accuracy at lower epochs. The \"communication budget\" is something we should keep track of.</p>\n</blockquote>\n<p>Network A is an outlier and the paper says so: it is left out of the epoch sweep because it \"does not achieve good accuracy for smaller epochs.\" But putting the two training tables next to each other turns up something better than that. Epochs are the wrong knob.</p>\n<div class=\"dpw\" id=\"front\" data-initialised=\"false\">\n  <div class=\"dpw-toggle-row\">\n    <span class=\"dpw-toggle-cap\">Setting</span>\n    <button class=\"dpw-toggle\" id=\"fr-lan\" data-on=\"true\">LAN</button>\n    <button class=\"dpw-toggle\" id=\"fr-wan\">WAN</button>\n  </div>\n  <svg id=\"fr-svg\" viewBox=\"0 0 480 268\" class=\"dpw-svg\" role=\"img\" aria-label=\"Inference accuracy against secure training time for every configuration in the paper\"></svg>\n  <div class=\"dpw-legend\">\n    <span class=\"dpw-key\"><i class=\"snn-sq\" style=\"background:#a72e2b\"></i>epochs varied, batch 128</span>\n    <span class=\"dpw-key\"><i class=\"snn-sq\" style=\"background:#3f8f5b\"></i>batch size varied, 5 epochs</span>\n    <span class=\"dpw-key\"><i class=\"snn-sq\" style=\"background:#8ba2b8\"></i>Network A</span>\n  </div>\n  <div class=\"dpw-detail\" id=\"fr-detail\">\n    <div class=\"dpw-detail-h\">Hover a point</div>\n    <div class=\"dpw-detail-b\">Every secure training run in the paper, from Tables 3 and 4 of the current version. Two of them land on exactly 99.15%.</div>\n  </div>\n</div>\n<p>Two runs hit exactly 99.15%. Network C at fifteen epochs and batch 128 takes 29.95 LAN hours. Network B at five epochs and batch 4 takes 9.98. Same accuracy, <strong>3.0× the budget</strong>, and the two numbers sit in different tables so the comparison is never made.</p>\n<p>The marginal rates say it too. On Network B, tripling the epochs buys 0.83 accuracy points for 11.6 LAN hours, 0.072 points per hour. Dropping the batch from 128 to 4 buys 1.21 points for 4.18 hours, 0.289, four times better. On Network C it is 0.050 against 0.275.</p>\n<p>Then switch to WAN and the ranking flips. Network B at batch 4 costs 112.71 WAN hours against Network C's 91.99, because a smaller batch means more iterations and every iteration pays the round complexity of every protocol in it against a 58 ms ping. So the budget has two dimensions. Bytes per epoch are fixed by the architecture, so on a LAN you buy accuracy with batch size, Network B from batch 128 to 4 costs 1.7× the time. Rounds per epoch scale with iteration count, so on a WAN that identical purchase costs 6.3×.</p>\n<p>Neither version tracks this. The 2019 revision actually made it harder to see: it dropped the cleartext-baseline and 4PC columns, so the two tables now share fewer axes than they did in the version I read.</p>\n<h2 id=\"ps-the-four-party-typo\" style=\"position:relative;\"><a href=\"#ps-the-four-party-typo\" aria-label=\"ps the four party typo 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>P.S.: the four-party typo</h2>\n<blockquote>\n<p><strong>This totally breaks security!</strong> It should be P<sub>1</sub> sends ⟨Y⟩<sup>L</sup><sub>1</sub> to P<sub>2</sub> and ⟨X⟩<sup>L</sup><sub>1</sub> to P<sub>3</sub> (shown correctly in Algorithm 6).</p>\n</blockquote>\n<p>Correct, and confirmed three ways.</p>\n<p>Section 3.2 of the version I read says P<sub>0</sub> sends ⟨X⟩<sub>0</sub> to P<sub>2</sub> and ⟨Y⟩<sub>0</sub> to P<sub>3</sub>, \"similarly, P<sub>1</sub> sends ⟨X⟩<sub>1</sub> to P<sub>2</sub> and ⟨Y⟩<sub>1</sub> to P<sub>3</sub>.\" Algorithm 6, fourteen lines below, says P<sub>1</sub> sends ⟨Y⟩<sub>1</sub> to P<sub>2</sub> and ⟨X⟩<sub>1</sub> to P<sub>3</sub>, your correction, verbatim.</p>\n<div class=\"dpw\" id=\"four\" data-initialised=\"false\">\n  <div class=\"dpw-toggle-row\">\n    <span class=\"dpw-toggle-cap\">Message routing</span>\n    <button class=\"dpw-toggle\" id=\"fo-prose\" data-on=\"true\">the prose, Section 3.2</button>\n    <button class=\"dpw-toggle\" id=\"fo-algo\">Algorithm 6</button>\n  </div>\n  <svg id=\"fo-svg\" viewBox=\"0 0 480 210\" class=\"dpw-svg\" role=\"img\" aria-label=\"Four-party matrix multiplication, showing which share each helper party receives\"></svg>\n  <div class=\"dpw-verdict\" id=\"fo-verdict\">P₂ holds both shares of X and reconstructs it in the clear</div>\n  <div class=\"dpw-hint\" id=\"fo-hint\">P₂ and P₃ each need one share of X and one share of Y to form a cross term. Under the prose each of them gets both shares of a single matrix instead, which is not a protocol at all: no cross term can be formed, and the two matrices are simply revealed.</div>\n</div>\n<p>Two things break, not one. Under the prose P<sub>2</sub> holds ⟨X⟩<sub>0</sub> and ⟨X⟩<sub>1</sub>, whose sum is X, and P<sub>3</sub> reconstructs Y the same way, so security against a single semi-honest corruption, the entire threat model, is gone without anyone deviating. But the prose also cannot compute anything: P<sub>2</sub> needs ⟨X⟩<sub>0</sub>·⟨Y⟩<sub>1</sub> and P<sub>3</sub> needs ⟨X⟩<sub>1</sub>·⟨Y⟩<sub>0</sub> for the four terms to sum to XY, and neither can build a cross term out of two shares of the same matrix.</p>\n<p>The code agrees with you rather than with the prose, and it names the swap. In <code class=\"language-text\">funcMatMulMPC</code>, the 4PC branch sends X in <code class=\"language-text\">&quot;NATURAL&quot;</code> order and Y in <code class=\"language-text\">&quot;UNNATURAL&quot;</code> order, and <code class=\"language-text\">&quot;UNNATURAL&quot;</code> is defined as exactly the crossover:</p>\n<div class=\"gatsby-highlight\" data-language=\"cpp\"><pre class=\"language-cpp\"><code class=\"language-cpp\"><span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>partyNum <span class=\"token operator\">==</span> PARTY_A<span class=\"token punctuation\">)</span>  sendVector<span class=\"token operator\">&lt;</span>T<span class=\"token operator\">></span><span class=\"token punctuation\">(</span>vec<span class=\"token punctuation\">,</span> PARTY_D<span class=\"token punctuation\">,</span> size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>partyNum <span class=\"token operator\">==</span> PARTY_B<span class=\"token punctuation\">)</span>  sendVector<span class=\"token operator\">&lt;</span>T<span class=\"token operator\">></span><span class=\"token punctuation\">(</span>vec<span class=\"token punctuation\">,</span> PARTY_C<span class=\"token punctuation\">,</span> size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>With <code class=\"language-text\">partner(PARTY_A) = PARTY_C</code>, P<sub>2</sub> ends up with ⟨X⟩<sub>0</sub> and ⟨Y⟩<sub>1</sub> and P<sub>3</sub> with ⟨X⟩<sub>1</sub> and ⟨Y⟩<sub>0</sub>. Algorithm 6, exactly.</p>\n<p>The typo is gone from the current version, but only because the four-party construction went with it. The 2019 revision drops the 4PC protocols, the 4PC complexity table, and the 4PC columns from every experimental table, and the phrase \"four-party\" does not appear in it once. The 2018 revision is still served by the archive and still cited.</p>\n<h2 id=\"what-ties-it-together\" style=\"position:relative;\"><a href=\"#what-ties-it-together\" aria-label=\"what ties it together permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What ties it together</h2>\n<p>Four of the five questions turn out to be the same question, which is Question 4.</p>\n<p><strong>Z</strong><sub>2<sup>64</sup></sub> was chosen for the linear layers, where the cost is 9.7 ms and 1.69 MB. It forced Π<sub>SC</sub> into existence, which is 45.8% of DReLU, where the cost is 109.8 ms and 10.88 MB. It put a seam between two functionalities that have one caller each and it is the same caller. It created a range condition that is proved in DReLU and never propagated. And it ruled out the transform-domain idea in Question 3, since a 2-group has no roots of unity to build one from.</p>\n<p>None of that makes the choice wrong. It makes it unpriced. The paper argues for the ring in one paragraph about GEMM performance and then pays for it in four places without totalling the bill, and the counterfactual, everything over <strong>Z</strong><sub>2<sup>64</sup>−1</sub>, no Π<sub>SC</sub>, one functionality with a clean signature, is still not in either version.</p>\n<p><em>Questions written 21 March 2025 against the May 2018 revision. Verified September 2026 against both published revisions and the reference implementation at commit <code class=\"language-text\">5496fd5</code> (2022-10-08). Every number here is recomputed from those sources, so it can be checked or contradicted.</em></p>\n<style>\n.dpw {\n  --ink: #1b2228; --ink2: #5b7085; --line: #dae4ed;\n  --maroon: #a72e2b; --maroon-d: #6a1d1b; --rose: #f2cdcc; --green: #3f8f5b; --slate: #8ba2b8;\n  border: 1px solid var(--line); border-radius: 6px; padding: 20px;\n  margin: 32px 0; background: #fff; font-family: 'Open Sans', sans-serif;\n}\n.dpw * { box-sizing: border-box; }\n.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; }\n.dpw-formula sup, .dpw-formula sub { font-size: 11px; }\n.dpw-controls { margin-bottom: 14px; }\n.dpw-label { display: block; font-size: 13px; color: var(--ink2); }\n.dpw-label input[type=range] { display: block; width: 100%; margin: 8px 0 0; accent-color: var(--maroon); }\n.dpw-val { color: var(--maroon-d); font-family: 'Inconsolata', monospace; font-weight: 700; }\n.dpw-hint { font-size: 12px; color: var(--ink2); margin-top: 10px; font-style: italic; line-height: 1.55; }\n.dpw-svg { width: 100%; height: auto; display: block; margin: 6px 0 4px;\n  background: linear-gradient(180deg, #fbfcfe, #f4f7fa); border-radius: 4px; }\n.dpw-verdict { margin: 10px 0 4px; padding: 8px 12px; border-radius: 4px; font-size: 13px; font-weight: 700;\n  background: var(--rose); color: var(--maroon-d); text-align: center; font-family: 'Inconsolata', monospace; }\n.dpw-verdict.dpw-ok { background: #dcefe3; color: var(--green); }\n.dpw-readout { display: flex; gap: 24px; margin-top: 12px; flex-wrap: wrap; }\n.dpw-stat { display: flex; flex-direction: column; }\n.dpw-num { font-family: 'Josefin Sans', sans-serif; font-size: 23px; color: var(--maroon-d); line-height: 1.15; }\n.dpw-cap { font-size: 11px; color: var(--ink2); text-transform: uppercase; letter-spacing: .04em; }\n.dpw-cap sub, .dpw-cap sup { text-transform: none; }\n.dpw-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; }\n.dpw-key { font-size: 12px; color: var(--ink2); display: flex; align-items: center; gap: 6px; }\n.dpw-key i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; flex: none; }\n.dpw-key i.snn-sq { width: 9px; height: 9px; border-radius: 50%; }\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-detail { border: 1px solid var(--line); border-radius: 5px; padding: 13px 14px; margin-top: 10px; min-height: 92px; }\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: 16px; color: var(--ink); }\n.dpw-inflate { font-size: 11px; color: #94a6b8; }\n\n.snn-callers { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }\n.snn-caller-cap { font-size: 11px; color: var(--ink2); text-transform: uppercase; letter-spacing: .04em; }\n.snn-caller { font-family: 'Inconsolata', monospace; font-size: 12px; color: var(--ink2);\n  border: 1px solid var(--line); border-radius: 3px; padding: 3px 8px; background: #fbfcfe; }\n.snn-split { display: grid; grid-template-columns: 200px 1fr; gap: 20px; align-items: center; }\n.snn-dial { background: none; }\n.snn-side { min-width: 0; }\n.snn-sig { border: 1px solid #dae4ed; border-radius: 6px; margin: 26px 0; overflow: hidden;\n  font-family: 'Open Sans', sans-serif; }\n.snn-sig-row { display: grid; grid-template-columns: 74px 1fr auto; gap: 12px; align-items: center;\n  padding: 11px 14px; border-bottom: 1px solid #eef3f7; }\n.snn-sig-row:last-child { border-bottom: 0; }\n.snn-sig-sum { background: #f6faf7; }\n.snn-sig-n { font-family: 'Inconsolata', monospace; font-size: 14px; color: #1b2228; }\n.snn-sig-t { font-family: 'Inconsolata', monospace; font-size: 14px; color: #5b7085; }\n.snn-sig-b { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; padding: 3px 8px;\n  border-radius: 3px; white-space: nowrap; }\n.snn-bad { background: #f2cdcc; color: #6a1d1b; }\n.snn-ok { background: #dcefe3; color: #3f8f5b; }\n@media (max-width: 520px) {\n  .snn-split { grid-template-columns: 1fr; }\n  .snn-dial { max-width: 200px; margin: 0 auto; }\n  .snn-sig-row { grid-template-columns: 1fr; gap: 4px; }\n  .dpw-readout { gap: 16px; }\n}\n@media (prefers-reduced-motion: reduce) { .dpw * { transition: none !important; } }\n.snn-board { border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }\n.snn-row { display: grid; grid-template-columns: 20px 1fr 128px; gap: 12px; align-items: center;\n  padding: 10px 13px; border-bottom: 1px solid #eef3f7; cursor: pointer; transition: background .12s; }\n.snn-row:last-child { border-bottom: 0; }\n.snn-row:hover { background: #fbfcfe; }\n.snn-row[data-on=true] { background: #f4f7fa; }\n.snn-row-n { font-family: 'Inconsolata', monospace; font-size: 12px; color: #94a6b8; }\n.snn-row-q { font-size: 13px; color: var(--ink); line-height: 1.45; }\n.snn-row-s { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; padding: 4px 8px;\n  border-radius: 3px; text-align: center; font-family: 'Josefin Sans', sans-serif; }\n.snn-s-fixed { background: #dcefe3; color: #3f8f5b; }\n.snn-s-clar { background: #e3ecf4; color: #3d566b; }\n.snn-s-gone { background: #ede4f2; color: #6b4a80; }\n.snn-s-open { background: #f2cdcc; color: #6a1d1b; }\n@media (max-width: 520px) {\n  .snn-row { grid-template-columns: 20px 1fr; }\n  .snn-row-s { grid-column: 2; justify-self: start; }\n}\n</style>\n<script>\n(function () {\n  var root = document.getElementById('score');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var ROWS = [\n    { n: '1', q: 'How many bits of extra randomness does the “fresh shares” invariant cost, and is grouping cheaper for information-theoretic security?',\n      s: 'clarified', cls: 'snn-s-clar',\n      h: 'Answered, and the premise was corrected',\n      b: '<b>2018:</b> the abstract claims “information-theoretically secure” with no qualification. ' +\n         '<b>2019:</b> Section 3.4 specifies the zero-shares as PRF output, and Section 1.1 adds a new sentence conceding ' +\n         '“we rely on computational assumptions for the implementation.” <b>Answer:</b> 6ℓ = 384 bits per scalar ReLU, ' +\n         '6.8% of what it sends, but zero of them are information-theoretic, because the implementation uses a PRF. ' +\n         'The same PRF halved matrix-multiplication communication in the 2019 tables.' },\n    { n: '2', q: 'What happens when a lands in the excluded range, do you clip, or abort training?',\n      s: 'edge case fixed', cls: 'snn-s-fixed',\n      h: 'Neither. Nothing checks.',\n      b: 'There is no clipping and no abort, and no range assertion anywhere in the C++. The range is not SecureNN’s: ' +\n         'it is Theorem 1 of SecureML, already required by every fixed-point truncation. <b>2019 fix:</b> the intervals were ' +\n         'tightened from closed, [0, 2ᵏ] ∪ [2ˡ − 2ᵏ, 2ˡ − 1], to half-open, [0, 2ᵏ) ∪ (2ˡ − 2ᵏ, 2ˡ − 1]. Correct endpoints, ' +\n         'same size of set, still no guidance for an implementer.' },\n    { n: '3', q: 'Did you try FFT- or NTT-based Beaver triples for the linear layers?',\n      s: 'not addressed', cls: 'snn-s-open',\n      h: 'They could not have',\n      b: '(Z/2⁶⁴)* ≅ Z₂ × Z₂⁶², a 2-group, so there is no primitive n-th root of unity for n > 2 and no transform to use. ' +\n         'Working around it means leaving the ring, which costs the free modulo. Unaddressed in both versions, and it would ' +\n         'not have moved the bottleneck anyway: the 1×100×1 matmul does no real arithmetic and still costs 25.2 ms on the WAN.' },\n    { n: '4', q: 'Was 𝓕_SC only created because you are fixed on operating over Z₂⁶⁴?',\n      s: 'unchanged', cls: 'snn-s-open',\n      h: 'Yes, the paper says so in both versions',\n      b: '“Matrix multiplication over the ring Z₂⁶⁴ is much faster … hence, we provide a protocol that converts values … ' +\n         'into shares over Z_{L−1}.” The round trip costs 304 of DReLU’s 664 bytes and four of its eight rounds. ' +\n         'Unchanged between versions, and the counterfactual is still not benchmarked.' },\n    { n: '5', q: 'Why is 𝓕_SC its own function rather than part of 𝓕_MSB?',\n      s: 'unchanged', cls: 'snn-s-open',\n      h: 'The premise holds in the paper and in the code',\n      b: 'Π_SC is called once, at step 2 of Algorithm 6. Π_MSB is called once, at step 3. Algorithm 6 is DReLU, and in the ' +\n         'implementation the two calls sit in one function body with nothing between them. They are the only two ' +\n         'functionalities that break the paper’s stated invariant, and they break it only to feed each other. ' +\n         'Unchanged in 2019.' },\n    { n: ', ', q: 'The thought: track a communication budget, not a headline number.',\n      s: 'not addressed', cls: 'snn-s-open',\n      h: 'Sharper than it looked',\n      b: 'Two runs reach exactly 99.15%, twenty LAN hours apart, in two tables that are never compared. Batch size buys ' +\n         'about four times more accuracy per LAN hour than epochs do, and the ranking inverts on the WAN. ' +\n         'The 2019 revision made this <i>harder</i> to see by dropping the cleartext and 4PC columns.' },\n    { n: 'P.S.', q: 'The Section 3.2 routing hands P₂ both shares of X. “This totally breaks security!”',\n      s: 'section removed', cls: 'snn-s-gone',\n      h: 'Correct, and confirmed three ways',\n      b: 'The prose contradicts Algorithm 6 in the same paper; it is also non-computable, since neither helper could form ' +\n         'a cross term; and the implementation routes the shares the way Algorithm 6 does, via a mode it literally calls ' +\n         '“UNNATURAL”. <b>2019:</b> the entire four-party construction was deleted, taking the typo with it. The 2018 ' +\n         'revision is still served by the archive and still cited.' }\n  ];\n\n  var board = root.querySelector('#sc-board'), detail = root.querySelector('#sc-detail');\n  var sel = null;\n  // The post template re-executes every script on client-side navigation, so this\n  // has to rebuild from empty rather than append a second set of rows.\n  var base = '<div class=\"dpw-detail-h\">Pick a row</div><div class=\"dpw-detail-b\">Seven points from the ' +\n    'March 2025 review, each checked against the 2018 version I read, the 2019 revision, and the C++ implementation.</div>';\n  board.innerHTML = '';\n  detail.innerHTML = base;\n\n  ROWS.forEach(function (r, i) {\n    var d = document.createElement('div');\n    d.className = 'snn-row';\n    d.setAttribute('data-on', 'false');\n    d.innerHTML = '<span class=\"snn-row-n\">' + r.n + '</span>' +\n      '<span class=\"snn-row-q\">' + r.q + '</span>' +\n      '<span class=\"snn-row-s ' + r.cls + '\">' + r.s + '</span>';\n    on(d, 'click', function () {\n      sel = sel === i ? null : i;\n      [].forEach.call(board.children, function (c, j) { c.setAttribute('data-on', String(j === sel)); });\n      detail.innerHTML = sel === null ? base\n        : '<div class=\"dpw-detail-h\">' + r.h + '</div><div class=\"dpw-detail-b\">' + r.b + '</div>';\n    });\n    board.appendChild(d);\n  });\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('pipe');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var SVG = 'http://www.w3.org/2000/svg';\n  var svg = root.querySelector('#pp-svg');\n  var GREEN = '#3f8f5b', MAROON = '#a72e2b', SLATE = '#8ba2b8', LINE = '#dae4ed', INK2 = '#5b7085';\n\n  // ring of the shares entering each stage, and of the shares leaving it\n  var stages = [\n    { id: 'dbl', label: '× 2', sub: 'local', x: 18, w: 62, ring: 'L', out: 'L', local: true,\n      h: 'Local doubling, no communication',\n      b: 'Both parties multiply their own share by two. Free, and the only reason it is here is that the odd-ring identity needs 2a rather than a. The requirement that MSB(a) = MSB(2a) is what creates the excluded range.' },\n    { id: 'sc', label: 'Π SC', sub: '4 rounds · 304 B', x: 96, w: 108, ring: 'L', out: 'L-1',\n      h: 'Π ShareConvert · ⟨a⟩ᴸ → ⟨a⟩ᴸ⁻¹',\n      b: 'Converts shares over Z_L into shares of the same value over the odd ring Z_{L-1}, so that the MSB-as-LSB identity becomes available. Requires a ≠ L−1. Costs 4ℓ log p + 6ℓ = 304 bytes and calls PrivateCompare once. It exists only because the linear layers wanted Z_2^64. This stage breaks the paper’s stated invariant.' },\n    { id: 'msb', label: 'Π MSB', sub: '5 rounds · 360 B', x: 220, w: 108, ring: 'L-1', out: 'L',\n      h: 'Π ComputeMSB · ⟨a⟩ᴸ⁻¹ → ⟨MSB(a)⟩ᴸ',\n      b: 'Over an odd ring MSB(a) = LSB(2a), so P₂ masks the doubled value, the parties open r, and one PrivateCompare settles the wrap bit. Costs 4ℓ log p + 13ℓ = 360 bytes. It is the only sub-protocol in the paper that expects inputs over Z_{L−1}, and its sole caller is the stage to its left. This stage also breaks the invariant, in the other direction.' },\n    { id: 'flip', label: '1 − α', sub: 'local', x: 344, w: 62, ring: 'L', out: 'L', local: true,\n      h: 'Local sign flip, no communication',\n      b: 'DReLU(a) = 1 ⊕ MSB(a). One party subtracts, both re-randomise with a pre-shared zero, and the result is a fresh share over Z_L. The invariant is restored here, at the end, having been broken twice in the middle.' },\n    { id: 'pc', label: 'Π PC', sub: 'called twice · 128 B each', x: 150, w: 180, ring: 'p', out: 'p', y: 118,\n      h: 'Π PrivateCompare · bit shares over Z₆₇',\n      b: 'The comparison itself, run over the 67-element field so that re-randomising by a random multiplier is safe. Both ShareConvert and ComputeMSB call it once. Together with the bit shares P₂ must hand out to feed it, Z_p material is 512 of DReLU’s 664 bytes.' }\n  ];\n\n  var sel = null;\n\n  function el(n, at, txt) {\n    var e = document.createElementNS(SVG, n);\n    for (var k in at) e.setAttribute(k, at[k]);\n    if (txt !== undefined) e.textContent = txt;\n    return e;\n  }\n  function ringColor(r) { return r === 'L' ? GREEN : r === 'L-1' ? MAROON : SLATE; }\n  function ringLabel(r) { return r === 'L' ? '⟨·⟩ᴸ' : r === 'L-1' ? '⟨·⟩ᴸ⁻¹' : '⟨·⟩ᵖ'; }\n\n  function draw() {\n    while (svg.firstChild) svg.removeChild(svg.firstChild);\n    var yTop = 34, hBox = 40;\n\n    // the ring bar running under the four main stages\n    var segs = [\n      { x0: 8, x1: 96, r: 'L' }, { x0: 96, x1: 204, r: 'L' },\n      { x0: 204, x1: 328, r: 'L-1' }, { x0: 328, x1: 472, r: 'L' }\n    ];\n    segs.forEach(function (s) {\n      svg.appendChild(el('rect', { x: s.x0, y: yTop + hBox + 12, width: s.x1 - s.x0, height: 4,\n        fill: ringColor(s.r), opacity: 0.85 }));\n    });\n    [{ x: 52, r: 'L' }, { x: 204, r: 'L' }, { x: 266, r: 'L-1' }, { x: 400, r: 'L' }].forEach(function (t) {\n      svg.appendChild(el('text', { x: t.x, y: yTop + hBox + 30, 'text-anchor': 'middle', 'font-size': 10.5,\n        fill: ringColor(t.r), 'font-family': 'Inconsolata, monospace' }, ringLabel(t.r)));\n    });\n\n    svg.appendChild(el('text', { x: 8, y: 16, 'font-size': 10.5, fill: INK2,\n      'font-family': 'Inconsolata, monospace' }, 'fresh ⟨a⟩ᴸ in'));\n    svg.appendChild(el('text', { x: 472, y: 16, 'text-anchor': 'end', 'font-size': 10.5, fill: INK2,\n      'font-family': 'Inconsolata, monospace' }, 'fresh ⟨DReLU(a)⟩ᴸ out'));\n\n    stages.forEach(function (s) {\n      var y = s.y !== undefined ? s.y : yTop;\n      var h = s.y !== undefined ? 34 : hBox;\n      var g = el('g', { style: 'cursor:pointer' });\n      var isSel = sel === s.id;\n      var breaks = s.ring !== s.out || s.ring === 'p';\n      g.appendChild(el('rect', { x: s.x, y: y, width: s.w, height: h, rx: 4,\n        fill: isSel ? (breaks ? '#f7dedd' : '#e6f2ea') : '#fff',\n        stroke: breaks ? (s.ring === 'p' ? SLATE : MAROON) : GREEN,\n        'stroke-width': isSel ? 2 : (s.local ? 1 : 1.6),\n        'stroke-dasharray': s.local ? '3 3' : '' }));\n      g.appendChild(el('text', { x: s.x + s.w / 2, y: y + (s.y !== undefined ? 15 : 20), 'text-anchor': 'middle',\n        'font-size': 13, fill: '#1b2228', 'font-family': 'Inconsolata, monospace' }, s.label));\n      g.appendChild(el('text', { x: s.x + s.w / 2, y: y + (s.y !== undefined ? 27 : 33), 'text-anchor': 'middle',\n        'font-size': 9.5, fill: INK2, 'font-family': 'Inconsolata, monospace' }, s.sub));\n      on(g, 'click', function () { sel = s.id; draw(); detail(s); });\n      svg.appendChild(g);\n    });\n\n    // dashed calls down into PrivateCompare\n    [[150, 96 + 54], [150, 220 + 54]].forEach(function (p, i) {\n      var fromX = i === 0 ? 150 : 274;\n      svg.appendChild(el('path', { d: 'M' + fromX + ' 74 L' + fromX + ' 118', fill: 'none',\n        stroke: SLATE, 'stroke-width': 1, 'stroke-dasharray': '3 3' }));\n    });\n    svg.appendChild(el('text', { x: 8, y: 138, 'font-size': 10, fill: INK2,\n      'font-family': 'Inconsolata, monospace' }, 'both'));\n    svg.appendChild(el('text', { x: 8, y: 150, 'font-size': 10, fill: INK2,\n      'font-family': 'Inconsolata, monospace' }, 'call'));\n\n    // the two stages that break the invariant, bracketed\n    svg.appendChild(el('path', { d: 'M96 26 L96 20 L328 20 L328 26', fill: 'none', stroke: MAROON, 'stroke-width': 1 }));\n    svg.appendChild(el('text', { x: 212, y: 15, 'text-anchor': 'middle', 'font-size': 10, fill: MAROON,\n      'font-family': 'Inconsolata, monospace' }, 'one caller each, and it is the same caller'));\n  }\n\n  function detail(s) {\n    root.querySelector('#pp-detail').innerHTML =\n      '<div class=\"dpw-detail-h\">' + s.h + '</div><div class=\"dpw-detail-b\">' + s.b + '</div>';\n  }\n\n  draw();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('cost');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var SVG = 'http://www.w3.org/2000/svg';\n  var svg = root.querySelector('#ct-svg');\n  var W = 480, P = { l: 12, r: 12, t: 42, b: 14 }, BAR = 44;\n\n  // l = 64, log p = 8.  SC = 4l·logp + 6l = 304 B.  MSB = 4l·logp + 13l = 360 B.\n  var BUILT = [\n    { k: 'sc-bits', p: 'ShareConvert', n: 'P₂ hands out ℓ bit shares over Z₆₇, to each party', b: 128, c: '#6a1d1b' },\n    { k: 'sc-pc', p: 'ShareConvert', n: 'PrivateCompare, 2ℓ log p', b: 128, c: '#a72e2b' },\n    { k: 'sc-ring', p: 'ShareConvert', n: '⟨ã⟩ to P₂, then ⟨δ⟩ and ⟨η′⟩ back, 6ℓ', b: 48, c: '#c9605d' },\n    { k: 'msb-bits', p: 'ComputeMSB', n: 'P₂ hands out ℓ bit shares over Z₆₇, to each party', b: 128, c: '#3d566b' },\n    { k: 'msb-pc', p: 'ComputeMSB', n: 'PrivateCompare, 2ℓ log p', b: 128, c: '#5b7085' },\n    { k: 'msb-ring', p: 'ComputeMSB', n: '⟨x⟩, ⟨x[0]⟩, opening r, ⟨β′⟩ and a 1×1 MatMul, 13ℓ', b: 104, c: '#8ba2b8' }\n  ];\n  var ODD = BUILT.slice(3);\n  var mode = 'built', hover = null;\n\n  function el(n, at, txt) {\n    var e = document.createElementNS(SVG, n);\n    for (var k in at) e.setAttribute(k, at[k]);\n    if (txt !== undefined) e.textContent = txt;\n    return e;\n  }\n\n  function draw() {\n    var segs = mode === 'built' ? BUILT : ODD;\n    var tot = segs.reduce(function (a, s) { return a + s.b; }, 0);\n    var full = 664;                                  // always scale against the shipped protocol\n    while (svg.firstChild) svg.removeChild(svg.firstChild);\n    var w = W - P.l - P.r, x = P.l;\n\n    // ghost of the shipped total, so the counterfactual visibly shrinks\n    svg.appendChild(el('rect', { x: P.l, y: P.t, width: w, height: BAR, rx: 3,\n      fill: 'none', stroke: '#dae4ed', 'stroke-width': 1, 'stroke-dasharray': '4 4' }));\n\n    segs.forEach(function (s) {\n      var sw = s.b / full * w;\n      var g = el('g', { style: 'cursor:default' });\n      g.appendChild(el('rect', { x: x, y: P.t, width: sw, height: BAR, fill: s.c,\n        opacity: hover && hover !== s.k ? 0.4 : 1 }));\n      if (sw > 30) {\n        g.appendChild(el('text', { x: x + sw / 2, y: P.t + BAR / 2 + 4, 'text-anchor': 'middle',\n          'font-size': 11, fill: '#fff', 'font-family': 'Inconsolata, monospace' }, s.b + ' B'));\n      }\n      on(g, 'mouseenter', function () { hover = s.k; draw(); say(s); });\n      on(g, 'mouseleave', function () { hover = null; draw(); say(null); });\n      svg.appendChild(g);\n      x += sw;\n    });\n\n    // group brackets above\n    var groups = mode === 'built'\n      ? [{ n: 'Π ShareConvert · 304 B', a: 0, z: 3, c: '#a72e2b' }, { n: 'Π ComputeMSB · 360 B', a: 3, z: 6, c: '#5b7085' }]\n      : [{ n: 'Π ComputeMSB · 360 B', a: 0, z: 3, c: '#5b7085' }];\n    groups.forEach(function (gr) {\n      var x0 = P.l, x1 = P.l;\n      segs.forEach(function (s, i) {\n        var sw = s.b / full * w;\n        if (i < gr.a) x0 += sw;\n        if (i < gr.z) x1 += sw;\n      });\n      svg.appendChild(el('path', { d: 'M' + x0 + ' ' + (P.t - 6) + ' L' + x0 + ' ' + (P.t - 12) +\n        ' L' + x1 + ' ' + (P.t - 12) + ' L' + x1 + ' ' + (P.t - 6), fill: 'none', stroke: gr.c, 'stroke-width': 1 }));\n      svg.appendChild(el('text', { x: (x0 + x1) / 2, y: P.t - 17, 'text-anchor': 'middle', 'font-size': 11,\n        fill: gr.c, 'font-family': 'Inconsolata, monospace' }, gr.n));\n    });\n\n    if (mode === 'odd') {\n      svg.appendChild(el('text', { x: P.l + w - 4, y: P.t + BAR + 12, 'text-anchor': 'end', 'font-size': 10.5,\n        fill: '#3f8f5b', 'font-family': 'Inconsolata, monospace' }, '304 B and 4 rounds no longer spent'));\n    }\n\n    var q = function (id) { return root.querySelector(id); };\n    q('#ct-tot').textContent = tot + ' B';\n    q('#ct-rnd').textContent = mode === 'built' ? '8' : '5';\n    q('#ct-sc').textContent = mode === 'built' ? '45.8%' : '0%';\n    var zp = segs.reduce(function (a, s) { return a + (/bits|pc/.test(s.k) ? s.b : 0); }, 0);\n    q('#ct-zp').textContent = (zp / tot * 100).toFixed(1) + '%';\n    q('#ct-built').setAttribute('data-on', mode === 'built');\n    q('#ct-odd').setAttribute('data-on', mode === 'odd');\n  }\n\n  var BASE = root.querySelector('#ct-hint').innerHTML;\n  function say(s) {\n    root.querySelector('#ct-hint').innerHTML = s\n      ? '<b>' + s.p + '</b>, ' + s.n + '. <b>' + s.b + ' bytes.</b>'\n      : BASE;\n  }\n\n  on(root.querySelector('#ct-built'), 'click', function () { mode = 'built'; hover = null; draw(); say(null); });\n  on(root.querySelector('#ct-odd'), 'click', function () { mode = 'odd'; hover = null; draw(); say(null); });\n  draw();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('range');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var SVG = 'http://www.w3.org/2000/svg';\n  var svg = root.querySelector('#rg-svg');\n  var ELL = 64, LD = 13, TRUNC = 2.129e9;      // Network A, batch 128, 7000 iterations\n  var CX = 100, CY = 100, R = 74;\n\n  function el(n, at, txt) {\n    var e = document.createElementNS(SVG, n);\n    for (var k in at) e.setAttribute(k, at[k]);\n    if (txt !== undefined) e.textContent = txt;\n    return e;\n  }\n  function pt(frac, r) {                        // 0 at top, clockwise\n    var a = frac * 2 * Math.PI - Math.PI / 2;\n    return [CX + r * Math.cos(a), CY + r * Math.sin(a)];\n  }\n  function arc(f0, f1, r) {\n    var a = pt(f0, r), b = pt(f1, r);\n    var large = (f1 - f0) > 0.5 ? 1 : 0;\n    return 'M' + CX + ' ' + CY + ' L' + a[0].toFixed(2) + ' ' + a[1].toFixed(2) +\n      ' A' + r + ' ' + r + ' 0 ' + large + ' 1 ' + b[0].toFixed(2) + ' ' + b[1].toFixed(2) + ' Z';\n  }\n  function sci(v) {\n    if (v === 0) return '0';\n    if (v >= 0.001) {\n      var t = v.toPrecision(3);\n      return t.indexOf('.') < 0 ? t : t.replace(/0+$/, '').replace(/\\.$/, '');\n    }\n    var e = Math.floor(Math.log10(v));\n    return (v / Math.pow(10, e)).toFixed(1) + 'e' + e;\n  }\n\n  function draw() {\n    var k = parseInt(root.querySelector('#rg-slider').value, 10);\n    var half = Math.pow(2, k - ELL);            // each arc, as a fraction of the ring\n    var frac = 2 * half;\n    var pFail = Math.pow(2, k + 1 - ELL);\n    var expected = TRUNC * pFail;\n\n    while (svg.firstChild) svg.removeChild(svg.firstChild);\n    svg.appendChild(el('circle', { cx: CX, cy: CY, r: R, fill: '#f4f7fa', stroke: '#dae4ed', 'stroke-width': 1 }));\n\n    // the two safe arcs meet at 0, so draw them as one wedge straddling the top\n    var visible = Math.max(half, 0.0022);       // floor so a sliver stays perceptible\n    svg.appendChild(el('path', { d: arc(1 - visible, 1, R), fill: '#3f8f5b', opacity: 0.82 }));\n    svg.appendChild(el('path', { d: arc(0, visible, R), fill: '#3f8f5b', opacity: 0.82 }));\n    if (half < 0.0022) {\n      svg.appendChild(el('text', { x: CX, y: 12, 'text-anchor': 'middle', 'font-size': 9, fill: '#3f8f5b',\n        'font-family': 'Inconsolata, monospace' }, 'drawn wider than it is'));\n    }\n    svg.appendChild(el('circle', { cx: CX, cy: CY, r: R * 0.52, fill: '#fff' }));\n    svg.appendChild(el('text', { x: CX, y: CY - 4, 'text-anchor': 'middle', 'font-size': 12, fill: '#5b7085',\n      'font-family': 'Inconsolata, monospace' }, 'Z' ));\n    svg.appendChild(el('text', { x: CX, y: CY + 12, 'text-anchor': 'middle', 'font-size': 11, fill: '#5b7085',\n      'font-family': 'Inconsolata, monospace' }, '2⁶⁴'));\n    svg.appendChild(el('text', { x: CX, y: CY + 26, 'text-anchor': 'middle', 'font-size': 9.5, fill: '#3f8f5b',\n      'font-family': 'Inconsolata, monospace' }, 'safe: |a| < 2^' + k));\n    svg.appendChild(el('line', { x1: CX, y1: CY - R - 5, x2: CX, y2: CY - R + 5, stroke: '#5b7085', 'stroke-width': 1 }));\n    svg.appendChild(el('text', { x: CX + 6, y: CY - R + 2, 'font-size': 9, fill: '#8ba2b8',\n      'font-family': 'Inconsolata, monospace' }, '0'));\n\n    var q = function (id) { return root.querySelector(id); };\n    q('#rg-k').textContent = k;\n    q('#rg-frac').textContent = sci(frac);\n    q('#rg-real').textContent = Math.pow(2, k - LD) >= 1e12\n      ? sci(Math.pow(2, k - LD)) : Math.round(Math.pow(2, k - LD)).toLocaleString();\n    q('#rg-p').textContent = sci(pFail);\n    q('#rg-fail').textContent = expected < 0.1 ? sci(expected) :\n      expected < 1e4 ? Math.round(expected * 100) / 100 >= 1\n        ? Math.round(expected).toLocaleString() : expected.toFixed(2)\n      : sci(expected);\n    var v = q('#rg-verdict');\n    if (expected < 0.1) {\n      v.className = 'dpw-verdict dpw-ok';\n      v.textContent = 'clean: a truncation failure anywhere in the run is unlikely';\n    } else if (expected < 1) {\n      v.className = 'dpw-verdict';\n      v.textContent = 'marginal: ' + expected.toFixed(2) + ' failures expected, so about ' +\n        Math.round((1 - Math.exp(-expected)) * 100) + ' training runs in 100 are corrupted somewhere';\n    } else if (expected < 1e4) {\n      v.className = 'dpw-verdict';\n      v.textContent = 'roughly ' + Math.round(expected).toLocaleString() + ' truncations blow up during training';\n    } else {\n      v.className = 'dpw-verdict';\n      v.textContent = 'the ring eats the gradients: ' + sci(expected) + ' failed truncations';\n    }\n  }\n\n  on(root.querySelector('#rg-slider'), 'input', draw);\n  draw();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('front');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var SVG = 'http://www.w3.org/2000/svg';\n  var svg = root.querySelector('#fr-svg');\n  var W = 480, H = 268, P = { l: 44, r: 16, t: 16, b: 42 };\n\n  // PETS 2019, Table 3 (epochs, batch 128) and Table 4 (batch size, 5 epochs)\n  var RUNS = [\n    { n: 'A', d: '15 epochs, batch 128', a: 93.40, lan: 1.03, wan: 7.83, g: 'a' },\n    { n: 'B', d: '5 epochs, batch 128', a: 97.94, lan: 5.80, wan: 17.99, g: 'ep', both: true },\n    { n: 'B', d: '10 epochs, batch 128', a: 98.05, lan: 11.60, wan: 35.99, g: 'ep' },\n    { n: 'B', d: '15 epochs, batch 128', a: 98.77, lan: 17.40, wan: 53.98, g: 'ep' },\n    { n: 'C', d: '5 epochs, batch 128', a: 98.15, lan: 9.98, wan: 30.66, g: 'ep', both: true },\n    { n: 'C', d: '10 epochs, batch 128', a: 98.43, lan: 19.96, wan: 61.33, g: 'ep' },\n    { n: 'C', d: '15 epochs, batch 128', a: 99.15, lan: 29.95, wan: 91.99, g: 'ep' },\n    { n: 'B', d: '5 epochs, batch 16', a: 98.99, lan: 8.34, wan: 36.46, g: 'bs' },\n    { n: 'B', d: '5 epochs, batch 4', a: 99.15, lan: 9.98, wan: 112.71, g: 'bs' },\n    { n: 'C', d: '5 epochs, batch 16', a: 99.10, lan: 13.43, wan: 46.20, g: 'bs' },\n    { n: 'C', d: '5 epochs, batch 4', a: 99.01, lan: 18.31, wan: 123.96, g: 'bs' }\n  ];\n  var COL = { a: '#8ba2b8', ep: '#a72e2b', bs: '#3f8f5b' };\n  var net = 'lan', hover = null;\n\n  function el(n, at, txt) {\n    var e = document.createElementNS(SVG, n);\n    for (var k in at) e.setAttribute(k, at[k]);\n    if (txt !== undefined) e.textContent = txt;\n    return e;\n  }\n  var XMAX = function () { return net === 'lan' ? 32 : 130; };\n  function X(h) { return P.l + h / XMAX() * (W - P.l - P.r); }\n  function Y(a) { return P.t + (99.5 - a) / (99.5 - 93.0) * (H - P.t - P.b); }\n\n  function draw() {\n    while (svg.firstChild) svg.removeChild(svg.firstChild);\n\n    [93, 95, 97, 98, 99].forEach(function (a) {\n      svg.appendChild(el('line', { x1: P.l, y1: Y(a), x2: W - P.r, y2: Y(a), stroke: '#dae4ed', 'stroke-width': 1 }));\n      svg.appendChild(el('text', { x: P.l - 6, y: Y(a) + 3, 'text-anchor': 'end', 'font-size': 10,\n        fill: '#5b7085', 'font-family': 'Inconsolata, monospace' }, a + '%'));\n    });\n    var ticks = net === 'lan' ? [0, 8, 16, 24, 32] : [0, 30, 60, 90, 120];\n    ticks.forEach(function (h) {\n      svg.appendChild(el('line', { x1: X(h), y1: P.t, x2: X(h), y2: H - P.b, stroke: '#eef3f7', 'stroke-width': 1 }));\n      svg.appendChild(el('text', { x: X(h), y: H - P.b + 15, 'text-anchor': 'middle', 'font-size': 10,\n        fill: '#5b7085', 'font-family': 'Inconsolata, monospace' }, h + 'h'));\n    });\n    svg.appendChild(el('text', { x: (W + P.l) / 2, y: H - 8, 'text-anchor': 'middle', 'font-size': 11,\n      fill: '#5b7085' }, 'secure training time, ' + net.toUpperCase() + ' (hours)'));\n\n    // the two runs that tie at 99.15%\n    svg.appendChild(el('line', { x1: P.l, y1: Y(99.15), x2: W - P.r, y2: Y(99.15), stroke: '#6a1d1b',\n      'stroke-width': 1, 'stroke-dasharray': '3 3' }));\n    svg.appendChild(el('text', { x: W - P.r - 2, y: Y(99.15) - 5, 'text-anchor': 'end', 'font-size': 10,\n      fill: '#6a1d1b', 'font-family': 'Inconsolata, monospace' }, 'two runs tie here, at 99.15%'));\n\n    RUNS.forEach(function (r, i) {\n      var h = net === 'lan' ? r.lan : r.wan;\n      var g = el('g', { style: 'cursor:default' });\n      var on99 = Math.abs(r.a - 99.15) < 0.001;\n      g.appendChild(el('circle', { cx: X(h), cy: Y(r.a), r: hover === i ? 7 : (on99 ? 6 : 4.5),\n        fill: COL[r.g], stroke: '#fff', 'stroke-width': 1.4,\n        opacity: hover === null || hover === i ? 1 : 0.45 }));\n      g.appendChild(el('text', { x: X(h), y: Y(r.a) - 9, 'text-anchor': 'middle', 'font-size': 9.5,\n        fill: '#5b7085', 'font-family': 'Inconsolata, monospace',\n        opacity: hover === null || hover === i ? 1 : 0.3 }, r.n));\n      on(g, 'mouseenter', function () { hover = i; draw(); say(r); });\n      on(g, 'mouseleave', function () { hover = null; draw(); say(null); });\n      svg.appendChild(g);\n    });\n\n    root.querySelector('#fr-lan').setAttribute('data-on', net === 'lan');\n    root.querySelector('#fr-wan').setAttribute('data-on', net === 'wan');\n  }\n\n  var BASE = root.querySelector('#fr-detail').innerHTML;\n  function say(r) {\n    var d = root.querySelector('#fr-detail');\n    if (!r) { d.innerHTML = BASE; return; }\n    var h = net === 'lan' ? r.lan : r.wan, o = net === 'lan' ? r.wan : r.lan;\n    d.innerHTML = '<div class=\"dpw-detail-h\">Network ' + r.n + ' · ' + r.d + '</div><div class=\"dpw-detail-b\">' +\n      r.a.toFixed(2) + '% inference accuracy for <b>' + h.toFixed(2) + ' ' + net.toUpperCase() + ' hours</b>, ' +\n      'against ' + o.toFixed(2) + ' on ' + (net === 'lan' ? 'the WAN' : 'the LAN') +\n      ', a ratio of ' + (Math.max(r.lan, r.wan) / Math.min(r.lan, r.wan)).toFixed(1) + '×.' +\n      (r.both ? ' This run is the shared row of both training tables.' : '') + '</div>';\n  }\n\n  on(root.querySelector('#fr-lan'), 'click', function () { net = 'lan'; hover = null; draw(); say(null); });\n  on(root.querySelector('#fr-wan'), 'click', function () { net = 'wan'; hover = null; draw(); say(null); });\n  draw();\n})();\n</script>\n<script>\n(function () {\n  var root = document.getElementById('four');\n  if (!root) return;\n  if (root._cleanup) root._cleanup();\n  var L = [];\n  function on(el, ev, fn) { if (!el) return; el.addEventListener(ev, fn); L.push([el, ev, fn]); }\n  root._cleanup = function () { L.forEach(function (x) { x[0].removeEventListener(x[1], x[2]); }); };\n\n  var SVG = 'http://www.w3.org/2000/svg';\n  var svg = root.querySelector('#fo-svg');\n  var GREEN = '#3f8f5b', MAROON = '#a72e2b', DARK = '#6a1d1b', INK2 = '#5b7085';\n  var mode = 'prose';\n\n  var NODES = {\n    P0: { x: 40, y: 22, w: 150, h: 44, t: 'P₀', s: 'holds ⟨X⟩₀ and ⟨Y⟩₀' },\n    P1: { x: 290, y: 22, w: 150, h: 44, t: 'P₁', s: 'holds ⟨X⟩₁ and ⟨Y⟩₁' },\n    P2: { x: 40, y: 140, w: 150, h: 50, t: 'P₂', s: '' },\n    P3: { x: 290, y: 140, w: 150, h: 50, t: 'P₃', s: '' }\n  };\n  // [from, to, label, curve offset]\n  var WIRE = {\n    prose: [['P0', 'P2', '⟨X⟩₀', 0], ['P0', 'P3', '⟨Y⟩₀', 1], ['P1', 'P2', '⟨X⟩₁', -1], ['P1', 'P3', '⟨Y⟩₁', 0]],\n    algo:  [['P0', 'P2', '⟨X⟩₀', 0], ['P0', 'P3', '⟨Y⟩₀', 1], ['P1', 'P2', '⟨Y⟩₁', -1], ['P1', 'P3', '⟨X⟩₁', 0]]\n  };\n  var HELPER = {\n    prose: { P2: ['⟨X⟩₀ + ⟨X⟩₁  =  X', true], P3: ['⟨Y⟩₀ + ⟨Y⟩₁  =  Y', true] },\n    algo:  { P2: ['⟨X⟩₀ · ⟨Y⟩₁ + V₀', false], P3: ['⟨X⟩₁ · ⟨Y⟩₀ + V₁', false] }\n  };\n\n  function el(n, at, txt) {\n    var e = document.createElementNS(SVG, n);\n    for (var k in at) e.setAttribute(k, at[k]);\n    if (txt !== undefined) e.textContent = txt;\n    return e;\n  }\n\n  function draw() {\n    while (svg.firstChild) svg.removeChild(svg.firstChild);\n    var bad = mode === 'prose';\n\n    var m = el('marker', { id: 'fo-ar-' + mode, viewBox: '0 0 8 8', refX: 7, refY: 4,\n      markerWidth: 6, markerHeight: 6, orient: 'auto-start-reverse' });\n    m.appendChild(el('path', { d: 'M0 0 L8 4 L0 8 z', fill: bad ? MAROON : INK2 }));\n    var defs = el('defs', {});\n    defs.appendChild(m);\n    svg.appendChild(defs);\n\n    WIRE[mode].forEach(function (w) {\n      var a = NODES[w[0]], b = NODES[w[1]];\n      var x0 = a.x + a.w / 2, y0 = a.y + a.h, x1 = b.x + b.w / 2, y1 = b.y;\n      var mx = (x0 + x1) / 2 + w[3] * 34, my = (y0 + y1) / 2;\n      svg.appendChild(el('path', { d: 'M' + x0 + ' ' + y0 + ' Q' + mx + ' ' + my + ' ' + x1 + ' ' + y1,\n        fill: 'none', stroke: bad ? MAROON : INK2, 'stroke-width': 1.3,\n        'marker-end': 'url(#fo-ar-' + mode + ')', opacity: 0.85 }));\n      svg.appendChild(el('text', { x: mx + (w[3] === 0 ? 6 : w[3] * 6), y: my + 4, 'text-anchor': 'middle',\n        'font-size': 11, fill: bad ? DARK : INK2, 'font-family': 'Inconsolata, monospace' }, w[2]));\n    });\n\n    Object.keys(NODES).forEach(function (k) {\n      var n = NODES[k], helper = HELPER[mode][k];\n      var danger = helper && helper[1];\n      svg.appendChild(el('rect', { x: n.x, y: n.y, width: n.w, height: n.h, rx: 4,\n        fill: danger ? '#f7dedd' : '#fff', stroke: danger ? MAROON : (helper ? GREEN : '#dae4ed'),\n        'stroke-width': danger ? 2 : 1.3 }));\n      svg.appendChild(el('text', { x: n.x + 12, y: n.y + 20, 'font-size': 14, fill: '#1b2228',\n        'font-family': 'Inconsolata, monospace' }, n.t));\n      var sub = helper ? helper[0] : n.s;\n      svg.appendChild(el('text', { x: n.x + 12, y: n.y + (helper ? 38 : 34), 'font-size': 11,\n        fill: danger ? DARK : INK2, 'font-family': 'Inconsolata, monospace' }, sub));\n      if (helper) {\n        svg.appendChild(el('text', { x: n.x + n.w - 10, y: n.y + 20, 'text-anchor': 'end', 'font-size': 9.5,\n          fill: danger ? MAROON : GREEN, 'font-family': 'Inconsolata, monospace' },\n          danger ? 'PLAINTEXT' : 'cross term'));\n      }\n    });\n\n    svg.appendChild(el('text', { x: 240, y: 108, 'text-anchor': 'middle', 'font-size': 10.5, fill: INK2,\n      'font-family': 'Inconsolata, monospace' },\n      bad ? 'each helper receives both shares of one matrix' : 'each helper receives one share of each matrix'));\n\n    var v = root.querySelector('#fo-verdict');\n    v.className = bad ? 'dpw-verdict' : 'dpw-verdict dpw-ok';\n    v.textContent = bad\n      ? 'P₂ holds both shares of X and reconstructs it in the clear'\n      : 'the four terms sum to X · Y and no party sees more than one share of either matrix';\n    root.querySelector('#fo-prose').setAttribute('data-on', bad);\n    root.querySelector('#fo-algo').setAttribute('data-on', !bad);\n  }\n\n  on(root.querySelector('#fo-prose'), 'click', function () { mode = 'prose'; draw(); });\n  on(root.querySelector('#fo-algo'), 'click', function () { mode = 'algo'; draw(); });\n  draw();\n})();\n</script>","headings":[{"value":"Question 1: the cost of \"fresh\" shares","depth":2},{"value":"Question 2: the excluded range","depth":2},{"value":"Question 3: FFT or NTT Beaver triples","depth":2},{"value":"Question 4: was ShareConvert forced by the ring?","depth":2},{"value":"Question 5: why is ShareConvert its own function?","depth":2},{"value":"The thought: a communication budget","depth":2},{"value":"P.S.: the four-party typo","depth":2},{"value":"What ties it together","depth":2}],"frontmatter":{"date_created":"2026-09-08","path":"/blog/securenn-ring-choice","tags":["Secure Multi-Party Computation","Protocol Review","Privacy Preserving Machine Learning"],"title":"Protocol Review of SecureNN"}}},"pageContext":{"prevPostPath":"/blog/crypto-club-square-and-multiply","currPostPath":"/blog/crypto-club-multiplying-with-a-parabola","nextPostPath":"/blog/securenn-ring-choice"}},"staticQueryHashes":[]}