<?xml version='1.0' encoding='UTF-8'?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
  <id>https://jonreyna.dev/</id>
  <title>Jon Reyna</title>
  <subtitle>Essays on AI infrastructure, distributed systems and the mathematics underneath them.</subtitle>
  <updated>2026-12-04T00:00:00Z</updated>
  <author>
    <name>Jon Reyna</name>
  </author>
  <link rel="self" type="application/atom+xml" href="https://jonreyna.dev/feed.xml" />
  <link rel="alternate" type="text/html" href="https://jonreyna.dev/writing" />
  <icon>https://jonreyna.dev/favicon.svg</icon>
  <rights>© Jon Reyna. Licensed under Creative Commons Attribution 4.0.</rights>
  <entry>
    <id>https://jonreyna.dev/writing/proving-bgpsieve</id>
    <title>Proving a rewrite against the C original</title>
    <link rel="alternate" type="text/html" href="https://jonreyna.dev/writing/proving-bgpsieve" />
    <published>2026-12-04T00:00:00Z</published>
    <updated>2026-12-04T00:00:00Z</updated>
    <summary>How I rewrote Alexandre Snarskii’s bgpq3 in Go and proved the CLI against the C binary on 200 test cases and 6 live queries.</summary>
    <content type="html">&lt;p class="abstract"&gt;
            A filter generator for BGP routers is the wrong place to guess whether a rewrite agrees with the original. I compiled C bgpq3 and ran it beside Go bgpsieve on 200 deterministic cases and 6 live queries. Along the way, the oracle caught a bug in the C code.
          &lt;/p&gt;
          &lt;section class="content"&gt;
            &lt;h2 id="why-an-oracle-not-unit-tests"&gt;
              &lt;span class="n"&gt;I.&lt;/span&gt;Why an oracle, not unit tests&lt;a class="anchor" href="https://jonreyna.dev/writing/proving-bgpsieve#why-an-oracle-not-unit-tests" aria-label="Link to section I"&gt;§&lt;/a&gt;
            &lt;/h2&gt;
            &lt;p&gt;
              Network engineers use &lt;a href="https://github.com/snar/bgpq3"&gt;&lt;code&gt;bgpq3&lt;/code&gt;&lt;/a&gt;, written and maintained by Alexandre Snarskii (2007–2026), to turn Internet Routing Registry (IRR) records into router prefix lists and AS-path filters.&lt;sup class="footnote-ref"&gt;&lt;a href="https://jonreyna.dev/writing/proving-bgpsieve#fn-bgpq3" id="fnref-bgpq3"&gt;1&lt;/a&gt;&lt;/sup&gt;
               A bad filter on a border router drops customer traffic or leaks a full table to a peer, so nobody swaps out a filter generator on faith.
            &lt;/p&gt;
            &lt;p&gt;
              When I rewrote &lt;code&gt;bgpq3&lt;/code&gt; in Go as &lt;a href="https://github.com/jonreyna/bgpsieve"&gt;&lt;code&gt;bgpsieve&lt;/code&gt;&lt;/a&gt;
               to get a standard-library Go package, concurrency safety, and an HTTP service (&lt;code&gt;bgpsieved&lt;/code&gt;), unit tests alone weren’t enough. Unit tests check what I 
              &lt;em&gt;think&lt;/em&gt; the spec says. For a drop-in command covering nine router formats and 39 short flags, the spec is 4,756 lines of C in 
              &lt;code&gt;bgpq3&lt;/code&gt; (&lt;code&gt;v0.1.38&lt;/code&gt;), four files of which (&lt;code&gt;bgpq3.c&lt;/code&gt;, &lt;code&gt;bgpq_expander.c&lt;/code&gt;, 
              &lt;code&gt;sx_prefix.c&lt;/code&gt;, and &lt;code&gt;bgpq3_printer.c&lt;/code&gt;) carry almost all of the behavior.
            &lt;/p&gt;
            &lt;p&gt;
              The cleanest proof is differential testing: compile the real C binary, put both commands in front of the same mock IRR server, feed them identical flags and fixtures, and fail if stdout or the exit status differs by a single byte.
            &lt;/p&gt;
            &lt;h2 id="what-exact-aggregation-has-to-preserve"&gt;
              &lt;span class="n"&gt;II.&lt;/span&gt;What exact aggregation has to preserve&lt;a class="anchor" href="https://jonreyna.dev/writing/proving-bgpsieve#what-exact-aggregation-has-to-preserve" aria-label="Link to section II"&gt;§&lt;/a&gt;
            &lt;/h2&gt;
            &lt;p&gt;
              The hardest part of &lt;code&gt;bgpq3&lt;/code&gt; to match isn’t the IRR wire protocol (&lt;code&gt;!i&lt;/code&gt;, &lt;code&gt;!g&lt;/code&gt;, 
              &lt;code&gt;!6&lt;/code&gt; over TCP port 43) or the vendor syntax.&lt;sup class="footnote-ref"&gt;&lt;a href="https://jonreyna.dev/writing/proving-bgpsieve#fn-irrd" id="fnref-irrd"&gt;2&lt;/a&gt;&lt;/sup&gt;
               It’s exact prefix-list aggregation (&lt;code&gt;-A&lt;/code&gt;), which shrinks a filter without changing which routes the router accepts.
            &lt;/p&gt;
            &lt;p&gt;
              Write &lt;math&gt;&lt;mrow&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt;
               for the set of IP addresses covered by a prefix &lt;math&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;/math&gt; of length &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;|&lt;/mo&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;|&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt;,&lt;/span&gt;
               and write &lt;math&gt;&lt;mrow&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;[&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;]&lt;/mo&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt;
               for a prefix-list entry that matches any prefix &lt;math&gt;&lt;mi&gt;q&lt;/mi&gt;&lt;/math&gt; with &lt;math&gt;&lt;mrow&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;&lt;mi&gt;q&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;&lt;mo&gt;⊆&lt;/mo&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt;
               and &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;≤&lt;/mo&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;|&lt;/mo&gt;&lt;mi&gt;q&lt;/mi&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;|&lt;/mo&gt;&lt;mo&gt;≤&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;/math&gt;.&lt;/span&gt;
               When two sibling prefixes &lt;math&gt;&lt;msub&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/msub&gt;&lt;/math&gt; and &lt;math&gt;&lt;msub&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;/math&gt;
               of length &lt;math&gt;&lt;mrow&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/math&gt; share a parent &lt;math&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;/math&gt;
               of length &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;/math&gt;,&lt;/span&gt; their address sets partition &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt;:&lt;/span&gt;
            &lt;/p&gt;
            &lt;div class="eq num" id="eq-1"&gt;
              &lt;math display="block"&gt;
                &lt;mrow&gt;
                  &lt;mi&gt;S&lt;/mi&gt;
                  &lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;
                  &lt;msub&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/msub&gt;
                  &lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;
                  &lt;mo&gt;∪&lt;/mo&gt;
                  &lt;mi&gt;S&lt;/mi&gt;
                  &lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;
                  &lt;msub&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;
                  &lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;
                  &lt;mo&gt;=&lt;/mo&gt;
                  &lt;mi&gt;S&lt;/mi&gt;
                  &lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;
                  &lt;mi&gt;p&lt;/mi&gt;
                  &lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;
                  &lt;mo&gt;,&lt;/mo&gt;
                  &lt;mspace width="2.0em"&gt;&lt;/mspace&gt;
                  &lt;mi&gt;S&lt;/mi&gt;
                  &lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;
                  &lt;msub&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/msub&gt;
                  &lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;
                  &lt;mo&gt;∩&lt;/mo&gt;
                  &lt;mi&gt;S&lt;/mi&gt;
                  &lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;
                  &lt;msub&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;
                  &lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;
                  &lt;mo&gt;=&lt;/mo&gt;
                  &lt;mi&gt;∅&lt;/mi&gt;
                  &lt;mi&gt;.&lt;/mi&gt;
                &lt;/mrow&gt;
              &lt;/math&gt;
              &lt;span class="no"&gt;(1)&lt;/span&gt;
            &lt;/div&gt;
            &lt;p&gt;
              Because of &lt;a href="https://jonreyna.dev/writing/proving-bgpsieve#eq-1"&gt;(1)&lt;/a&gt;, if a router’s filter permits both &lt;math&gt;&lt;mrow&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;[&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;]&lt;/mo&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt;
               and &lt;math&gt;&lt;mrow&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;[&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;]&lt;/mo&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt;
               with the same bounds &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;[&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;]&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt;,&lt;/span&gt;
               then replacing both entries with &lt;math&gt;&lt;mrow&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;[&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;]&lt;/mo&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt;
               matches the exact same set of routes. If &lt;math&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;/math&gt; itself was also in the input (and &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/math&gt;)&lt;/span&gt;, the combined range widens to 
              &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;[&lt;/mo&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;]&lt;/mo&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt;.&lt;/span&gt;
               What if &lt;math&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;/math&gt; is an exact entry and its children carry a disjoint range &lt;math&gt;&lt;mrow&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;[&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;]&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt;
               with &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;&amp;gt;&lt;/mo&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/math&gt;?&lt;/span&gt;
               Then &lt;math&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;/math&gt; stays exact, and the merged range attaches to &lt;math&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;/math&gt; as a secondary 
              &lt;code&gt;son&lt;/code&gt; entry so the printer emits both lines without inventing any intermediate lengths.
            &lt;/p&gt;
            &lt;div id="algorithm-a" class="algorithm" role="group" aria-label="Algorithm A"&gt;
              &lt;span class="lead"&gt;&lt;span class="name"&gt;Algorithm A&lt;/span&gt; (&lt;i&gt;Exact prefix-list aggregation&lt;/i&gt;). &lt;/span&gt;
              &lt;p&gt;
                Given the root node &lt;math&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/math&gt; of a binary Patricia radix tree of prefixes, this post-order pass compacts sibling entries into equivalent prefix-length ranges.
              &lt;/p&gt;
              &lt;ol&gt;
                
&lt;li id="step-a1"&gt;&lt;span class="step"&gt;A1.&lt;/span&gt;[Recurse.] &lt;p&gt;If &lt;math&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/math&gt; has a left child, run Algorithm A on &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mi&gt;.&lt;/mi&gt;&lt;mrow&gt;&lt;mi&gt;left&lt;/mi&gt;&lt;/mrow&gt;&lt;/mrow&gt;&lt;/math&gt;.&lt;/span&gt; If &lt;math&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/math&gt; has a right child, run Algorithm A on &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mi&gt;.&lt;/mi&gt;&lt;mrow&gt;&lt;mi&gt;right&lt;/mi&gt;&lt;/mrow&gt;&lt;/mrow&gt;&lt;/math&gt;.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li id="step-a2"&gt;&lt;span class="step"&gt;A2.&lt;/span&gt;[Check siblings.] &lt;p&gt;Let &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;|&lt;/mo&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mi&gt;.&lt;/mi&gt;&lt;mrow&gt;&lt;mi&gt;prefix&lt;/mi&gt;&lt;/mrow&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;|&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt;.&lt;/span&gt; If either child is missing, or if either child does not have prefix length &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/math&gt;,&lt;/span&gt; return.&lt;/p&gt;&lt;/li&gt;
&lt;li id="step-a3"&gt;&lt;span class="step"&gt;A3.&lt;/span&gt;[Merge exact children.] &lt;p&gt;If both children are active exact prefixes (neither glue nor aggregate), mark both children as glue and set &lt;math&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/math&gt; to an aggregate with upper bound &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/math&gt;.&lt;/span&gt; Set &lt;math&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/math&gt;’s lower bound to &lt;math&gt;&lt;mrow&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/math&gt; if &lt;math&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/math&gt; was glue, or to &lt;math&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;/math&gt; if &lt;math&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/math&gt; was already active. If both children also carry matching &lt;code&gt;son&lt;/code&gt; ranges, promote one copy to &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mi&gt;.&lt;/mi&gt;&lt;mrow&gt;&lt;mi&gt;son&lt;/mi&gt;&lt;/mrow&gt;&lt;/mrow&gt;&lt;/math&gt;.&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li id="step-a4"&gt;&lt;span class="step"&gt;A4.&lt;/span&gt;[Merge matching ranges.] &lt;p&gt;Otherwise, if both children (or one child and the other’s &lt;code&gt;son&lt;/code&gt;) are active aggregates with identical bounds &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;[&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;]&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt;,&lt;/span&gt; mark both as glue. If &lt;math&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/math&gt; is glue, copy &lt;math&gt;&lt;mrow&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;[&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;]&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt; onto &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/math&gt;;&lt;/span&gt; else if &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/math&gt;,&lt;/span&gt; promote &lt;math&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;/math&gt; to &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;[&lt;/mo&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;]&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt;;&lt;/span&gt; otherwise attach &lt;math&gt;&lt;mrow&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;[&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;]&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt; as &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mi&gt;.&lt;/mi&gt;&lt;mrow&gt;&lt;mi&gt;son&lt;/mi&gt;&lt;/mrow&gt;&lt;/mrow&gt;&lt;/math&gt;.&lt;/span&gt;&lt;/p&gt; &lt;span class="qed" aria-label="End of algorithm"&gt;▮&lt;/span&gt;&lt;/li&gt;

              &lt;/ol&gt;
            &lt;/div&gt;
            &lt;p&gt;
              In Go (&lt;code&gt;radix/tree_aggregate.go&lt;/code&gt;), &lt;a href="https://jonreyna.dev/writing/proving-bgpsieve#step-a2"&gt;step A2&lt;/a&gt; and the branch dispatch fit in one short function:
            &lt;/p&gt;
            &lt;pre&gt;&lt;code class="language-go"&gt;&lt;span class="kw"&gt;func&lt;/span&gt; &lt;span class="op"&gt;(&lt;/span&gt;t &lt;span class="op"&gt;*&lt;/span&gt;Tree&lt;span class="op"&gt;)&lt;/span&gt; aggregateNode&lt;span class="op"&gt;(&lt;/span&gt;n &lt;span class="op"&gt;*&lt;/span&gt;node&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;{&lt;/span&gt;
	&lt;span class="cf"&gt;if&lt;/span&gt; n&lt;span class="op"&gt;.&lt;/span&gt;left &lt;span class="op"&gt;!=&lt;/span&gt; &lt;span class="ot"&gt;nil&lt;/span&gt; &lt;span class="op"&gt;{&lt;/span&gt;
		t&lt;span class="op"&gt;.&lt;/span&gt;aggregateNode&lt;span class="op"&gt;(&lt;/span&gt;n&lt;span class="op"&gt;.&lt;/span&gt;left&lt;span class="op"&gt;)&lt;/span&gt;
	&lt;span class="op"&gt;}&lt;/span&gt;
	&lt;span class="cf"&gt;if&lt;/span&gt; n&lt;span class="op"&gt;.&lt;/span&gt;right &lt;span class="op"&gt;!=&lt;/span&gt; &lt;span class="ot"&gt;nil&lt;/span&gt; &lt;span class="op"&gt;{&lt;/span&gt;
		t&lt;span class="op"&gt;.&lt;/span&gt;aggregateNode&lt;span class="op"&gt;(&lt;/span&gt;n&lt;span class="op"&gt;.&lt;/span&gt;right&lt;span class="op"&gt;)&lt;/span&gt;
	&lt;span class="op"&gt;}&lt;/span&gt;
	&lt;span class="cf"&gt;if&lt;/span&gt; n&lt;span class="op"&gt;.&lt;/span&gt;left &lt;span class="op"&gt;==&lt;/span&gt; &lt;span class="ot"&gt;nil&lt;/span&gt; &lt;span class="op"&gt;||&lt;/span&gt; n&lt;span class="op"&gt;.&lt;/span&gt;right &lt;span class="op"&gt;==&lt;/span&gt; &lt;span class="ot"&gt;nil&lt;/span&gt; &lt;span class="op"&gt;{&lt;/span&gt;
		&lt;span class="cf"&gt;return&lt;/span&gt;
	&lt;span class="op"&gt;}&lt;/span&gt;
	nBits &lt;span class="op"&gt;:=&lt;/span&gt; &lt;span class="dt"&gt;uint8&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;n&lt;span class="op"&gt;.&lt;/span&gt;prefix&lt;span class="op"&gt;.&lt;/span&gt;Bits&lt;span class="op"&gt;())&lt;/span&gt;
	childBits &lt;span class="op"&gt;:=&lt;/span&gt; &lt;span class="dt"&gt;int&lt;/span&gt;&lt;span class="op"&gt;(&lt;/span&gt;nBits&lt;span class="op"&gt;)&lt;/span&gt; &lt;span class="op"&gt;+&lt;/span&gt; &lt;span class="dv"&gt;1&lt;/span&gt;
	l&lt;span class="op"&gt;,&lt;/span&gt; r &lt;span class="op"&gt;:=&lt;/span&gt; n&lt;span class="op"&gt;.&lt;/span&gt;left&lt;span class="op"&gt;,&lt;/span&gt; n&lt;span class="op"&gt;.&lt;/span&gt;right
	&lt;span class="cf"&gt;if&lt;/span&gt; l&lt;span class="op"&gt;.&lt;/span&gt;prefix&lt;span class="op"&gt;.&lt;/span&gt;Bits&lt;span class="op"&gt;()&lt;/span&gt; &lt;span class="op"&gt;!=&lt;/span&gt; childBits &lt;span class="op"&gt;||&lt;/span&gt;
		r&lt;span class="op"&gt;.&lt;/span&gt;prefix&lt;span class="op"&gt;.&lt;/span&gt;Bits&lt;span class="op"&gt;()&lt;/span&gt; &lt;span class="op"&gt;!=&lt;/span&gt; childBits &lt;span class="op"&gt;{&lt;/span&gt;
		&lt;span class="cf"&gt;return&lt;/span&gt;
	&lt;span class="op"&gt;}&lt;/span&gt;
	&lt;span class="co"&gt;// Merge exact siblings, matching ranges, or son chains.&lt;/span&gt;
	t&lt;span class="op"&gt;.&lt;/span&gt;mergeSiblings&lt;span class="op"&gt;(&lt;/span&gt;n&lt;span class="op"&gt;,&lt;/span&gt; l&lt;span class="op"&gt;,&lt;/span&gt; r&lt;span class="op"&gt;,&lt;/span&gt; nBits&lt;span class="op"&gt;)&lt;/span&gt;
&lt;span class="op"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
            &lt;p&gt;
              The second aggregation flag, &lt;code&gt;-H&lt;/code&gt; (hyper-aggregation), runs Algorithm A first and then makes a top-down pass that keeps only the highest active supernet on each path and discards every more-specific descendant. Unlike 
              &lt;code&gt;-A&lt;/code&gt;, &lt;code&gt;-H&lt;/code&gt; is intentionally lossy: it shrinks the list further by permitting sub-prefixes that were not registered individually.
            &lt;/p&gt;
            &lt;h2 id="wiring-the-c-binary-into-go-test"&gt;
              &lt;span class="n"&gt;III.&lt;/span&gt;Wiring the C binary into &lt;code&gt;go test&lt;/code&gt;&lt;a class="anchor" href="https://jonreyna.dev/writing/proving-bgpsieve#wiring-the-c-binary-into-go-test" aria-label="Link to section III"&gt;§&lt;/a&gt;
            &lt;/h2&gt;
            &lt;p&gt;
              The differential suite lives in &lt;code&gt;internal/oracle/diff_test.go&lt;/code&gt; and runs on every pull request in CI. A small build script compiles the pinned C 
              &lt;code&gt;bgpq3&lt;/code&gt; commit (&lt;code&gt;v0.1.38&lt;/code&gt;) into &lt;code&gt;.cache/bin/bgpq3&lt;/code&gt;, and &lt;code&gt;TestCOracleDifferentialSuite&lt;/code&gt;
               builds &lt;code&gt;cmd/bgpsieve&lt;/code&gt; into a temporary directory and starts an in-process mock IRRd server (&lt;code&gt;irrdtest.Server&lt;/code&gt;).
            &lt;/p&gt;
            &lt;p&gt;
              Both binaries talk to that same loopback TCP port with &lt;code&gt;-h 127.0.0.1:&amp;lt;port&amp;gt;&lt;/code&gt;. The mock fixtures cover nested AS-sets, circular references (&lt;code&gt;AS-CYC-A&lt;/code&gt;
               and &lt;code&gt;AS-CYC-B&lt;/code&gt;), &lt;code&gt;EXCEPT&lt;/code&gt; stoplists, &lt;code&gt;-L&lt;/code&gt; depth caps, multi-source shadowing (&lt;code&gt;RIPE&lt;/code&gt;
               vs. &lt;code&gt;RADB&lt;/code&gt;), 32-bit and special ASNs (&lt;code&gt;AS23456&lt;/code&gt;, &lt;code&gt;AS64512&lt;/code&gt;), route-sets with RPSL range operators (&lt;code&gt;^+&lt;/code&gt;, 
              &lt;code&gt;^-&lt;/code&gt;, &lt;code&gt;^25-26&lt;/code&gt;), and empty sets.
            &lt;/p&gt;
            &lt;pre&gt;&lt;code class="language-go"&gt;cOut&lt;span class="op"&gt;,&lt;/span&gt; cErr&lt;span class="op"&gt;,&lt;/span&gt; cCode &lt;span class="op"&gt;:=&lt;/span&gt; runCLI&lt;span class="op"&gt;(&lt;/span&gt;t&lt;span class="op"&gt;,&lt;/span&gt; cBin&lt;span class="op"&gt;,&lt;/span&gt; args&lt;span class="op"&gt;,&lt;/span&gt; tc&lt;span class="op"&gt;.&lt;/span&gt;env&lt;span class="op"&gt;)&lt;/span&gt;
goOut&lt;span class="op"&gt;,&lt;/span&gt; goErr&lt;span class="op"&gt;,&lt;/span&gt; goCode &lt;span class="op"&gt;:=&lt;/span&gt; runCLI&lt;span class="op"&gt;(&lt;/span&gt;t&lt;span class="op"&gt;,&lt;/span&gt; goBin&lt;span class="op"&gt;,&lt;/span&gt; args&lt;span class="op"&gt;,&lt;/span&gt; tc&lt;span class="op"&gt;.&lt;/span&gt;env&lt;span class="op"&gt;)&lt;/span&gt;

&lt;span class="cf"&gt;if&lt;/span&gt; tc&lt;span class="op"&gt;.&lt;/span&gt;expectFail &lt;span class="op"&gt;{&lt;/span&gt;
	&lt;span class="cf"&gt;if&lt;/span&gt; cCode &lt;span class="op"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="dv"&gt;0&lt;/span&gt; &lt;span class="op"&gt;||&lt;/span&gt; goCode &lt;span class="op"&gt;!=&lt;/span&gt; &lt;span class="dv"&gt;1&lt;/span&gt; &lt;span class="op"&gt;{&lt;/span&gt;
		t&lt;span class="op"&gt;.&lt;/span&gt;Fatalf&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;&amp;quot;exit mismatch: c=%d go=%d&amp;quot;&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt; cCode&lt;span class="op"&gt;,&lt;/span&gt; goCode&lt;span class="op"&gt;)&lt;/span&gt;
	&lt;span class="op"&gt;}&lt;/span&gt;
	&lt;span class="cf"&gt;return&lt;/span&gt;
&lt;span class="op"&gt;}&lt;/span&gt;
&lt;span class="cf"&gt;if&lt;/span&gt; tc&lt;span class="op"&gt;.&lt;/span&gt;jsonEqual &lt;span class="op"&gt;{&lt;/span&gt;
	assertJSONSemanticallyEqual&lt;span class="op"&gt;(&lt;/span&gt;t&lt;span class="op"&gt;,&lt;/span&gt; cOut&lt;span class="op"&gt;,&lt;/span&gt; goOut&lt;span class="op"&gt;)&lt;/span&gt;
	&lt;span class="cf"&gt;return&lt;/span&gt;
&lt;span class="op"&gt;}&lt;/span&gt;
&lt;span class="cf"&gt;if&lt;/span&gt; goOut &lt;span class="op"&gt;!=&lt;/span&gt; cOut &lt;span class="op"&gt;{&lt;/span&gt;
	t&lt;span class="op"&gt;.&lt;/span&gt;Fatalf&lt;span class="op"&gt;(&lt;/span&gt;&lt;span class="st"&gt;&amp;quot;mismatch for %v:&lt;/span&gt;&lt;span class="ch"&gt;\n&lt;/span&gt;&lt;span class="st"&gt;C:&lt;/span&gt;&lt;span class="ch"&gt;\n&lt;/span&gt;&lt;span class="st"&gt;%sGo:&lt;/span&gt;&lt;span class="ch"&gt;\n&lt;/span&gt;&lt;span class="st"&gt;%s&amp;quot;&lt;/span&gt;&lt;span class="op"&gt;,&lt;/span&gt;
		args&lt;span class="op"&gt;,&lt;/span&gt; cOut&lt;span class="op"&gt;,&lt;/span&gt; goOut&lt;span class="op"&gt;)&lt;/span&gt;
&lt;span class="op"&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
            &lt;p&gt;
              Table 1 summarizes the suite as it runs on every commit, alongside the polite live smoke suite (&lt;code&gt;test/integration/live_irrd_test.go&lt;/code&gt;) that runs six small queries against 
              &lt;code&gt;rr.ntt.net:43&lt;/code&gt;.
            &lt;/p&gt;
            &lt;p class="caption" id="table-1"&gt;
              &lt;span class="label"&gt;Table 1.&lt;/span&gt; &lt;em&gt;Differential checks between C bgpq3 (v0.1.38) and Go bgpsieve.&lt;/em&gt;
            &lt;/p&gt;
            &lt;div class="table-scroll"&gt;
              &lt;table&gt;
                &lt;thead&gt;&lt;tr&gt;&lt;th&gt;Suite&lt;/th&gt;&lt;th align="right"&gt;Cases&lt;/th&gt;&lt;th&gt;Comparison&lt;/th&gt;&lt;th&gt;Network&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;
                &lt;tbody&gt;
                  &lt;tr&gt;
                    &lt;td&gt;Router formats &amp;amp; flags&lt;/td&gt;
                    &lt;td align="right"&gt;171&lt;/td&gt;
                    &lt;td&gt;Exact byte-for-byte stdout&lt;/td&gt;
                    &lt;td&gt;103 via mock IRRd&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                    &lt;td&gt;JSON output (&lt;code&gt;-j&lt;/code&gt;)&lt;/td&gt;
                    &lt;td align="right"&gt;10&lt;/td&gt;
                    &lt;td&gt;Parsed JSON deep equality&lt;/td&gt;
                    &lt;td&gt;Mock IRRd / static&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;&lt;td&gt;Invalid flag combinations&lt;/td&gt;&lt;td align="right"&gt;19&lt;/td&gt;&lt;td&gt;Both exit non-zero&lt;/td&gt;&lt;td&gt;None&lt;/td&gt;&lt;/tr&gt;
                  &lt;tr&gt;
                    &lt;td&gt;Live IRRd smoke (&lt;code&gt;rr.ntt.net&lt;/code&gt;)&lt;/td&gt;
                    &lt;td align="right"&gt;6&lt;/td&gt;
                    &lt;td&gt;Exact byte-for-byte stdout&lt;/td&gt;
                    &lt;td&gt;Live TCP 43&lt;/td&gt;
                  &lt;/tr&gt;
                &lt;/tbody&gt;
              &lt;/table&gt;
            &lt;/div&gt;
            &lt;h2 id="when-the-oracle-itself-is-wrong"&gt;
              &lt;span class="n"&gt;IV.&lt;/span&gt;When the oracle itself is wrong&lt;a class="anchor" href="https://jonreyna.dev/writing/proving-bgpsieve#when-the-oracle-itself-is-wrong" aria-label="Link to section IV"&gt;§&lt;/a&gt;
            &lt;/h2&gt;
            &lt;p&gt;
              A differential test only tells you that two programs disagree; it doesn’t tell you which one is right. Early on, almost every diff pointed to a subtle detail I had missed in Go: an extra trailing space in a vendor’s empty-list fallback, how 
              &lt;code&gt;-a&lt;/code&gt; and &lt;code&gt;-f&lt;/code&gt; interact depending on flag order, or the exact regex grouping of Cisco and JunOS AS-path filters.
            &lt;/p&gt;
            &lt;p&gt;
              Eight times, though, reading the C source behind a diff showed a real bug in &lt;code&gt;bgpq3&lt;/code&gt; &lt;code&gt;v0.1.38&lt;/code&gt;. Rather than reproduce crashes or silent data loss, I documented and tested those eight divergences separately in 
              &lt;code&gt;TestIntentionalCBugFixes&lt;/code&gt;.
            &lt;/p&gt;
            &lt;p&gt;
              One of them turned up only because the oracle tested a combination I hadn’t thought to audit by hand. In mixed address-family mode (&lt;code&gt;-x&lt;/code&gt;, supported on JunOS, JSON, and 
              &lt;code&gt;-F&lt;/code&gt;), &lt;code&gt;bgpq3&lt;/code&gt; passed &lt;code&gt;maxlen = 0&lt;/code&gt; to &lt;code&gt;sx_prefix_range_parse&lt;/code&gt;
               when parsing IPv6 prefix ranges such as &lt;code&gt;2001:db8:2::/48^49-49&lt;/code&gt;. The parser clamped the upper bound to zero and silently dropped the route from the generated filter.
            &lt;/p&gt;
            &lt;p&gt;
              The other seven were just as concrete: an &lt;code&gt;/65535&lt;/code&gt; typo in the ASN table that mis-indexed 
              &lt;code&gt;AS65535&lt;/code&gt;; &lt;code&gt;-F&lt;/code&gt; reading before the format pointer on a trailing &lt;code&gt;\n&lt;/code&gt;; an uninitialized maximum length on single-length ranges like 
              &lt;code&gt;^25&lt;/code&gt;; Cisco and Huawei &lt;code&gt;-f 0&lt;/code&gt; emitting &lt;code&gt;deny .*&lt;/code&gt; for a single ASN; Cisco extended ACLs printing 
              &lt;code&gt;host 0.0.0.0&lt;/code&gt; instead of &lt;code&gt;host 255.255.255.255&lt;/code&gt; for a &lt;code&gt;/32&lt;/code&gt;; leading-zero IPv4 octets from RADB being parsed as octal (&lt;code&gt;010.0.0.0/24&lt;/code&gt;
               turning into &lt;code&gt;8.0.0.0/24&lt;/code&gt;); and Nokia classic &lt;code&gt;-NG&lt;/code&gt; omitting its closing &lt;code&gt;exit&lt;/code&gt;
               and &lt;code&gt;commit&lt;/code&gt;.
            &lt;/p&gt;
            &lt;h2 id="what-the-oracle-doesn-t-prove"&gt;
              &lt;span class="n"&gt;V.&lt;/span&gt;What the oracle doesn’t prove&lt;a class="anchor" href="https://jonreyna.dev/writing/proving-bgpsieve#what-the-oracle-doesn-t-prove" aria-label="Link to section V"&gt;§&lt;/a&gt;
            &lt;/h2&gt;
            &lt;p&gt;
              Matching a single-shot CLI proves the core math, expansion, and formatting, and it let me add features 
              &lt;code&gt;bgpq3&lt;/code&gt; never had (bogon stripping, prefix caps, Go templates, and a public HTTP demo at &lt;a href="https://bgpsieve.jonreyna.dev"&gt;&lt;code&gt;bgpsieve.jonreyna.dev&lt;/code&gt;&lt;/a&gt;) without drifting from the baseline.&lt;sup class="footnote-ref"&gt;&lt;a href="https://jonreyna.dev/writing/proving-bgpsieve#fn-demo" id="fnref-demo"&gt;3&lt;/a&gt;&lt;/sup&gt;
            &lt;/p&gt;
            &lt;p&gt;
              It does not prove that a long-lived HTTP server survives hostile traffic. Putting &lt;code&gt;bgpsieved&lt;/code&gt;
               on the internet took a separate round of fuzzing, race testing, and a security audit that caught memory-exhaustion paths, router-config injection in 
              &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;match&lt;/code&gt;, and per-IP rate-limit edge cases that a CLI tool never faces. The oracle gives you a floor for correctness; everything above the CLI still has to earn its keep on its own.
            &lt;/p&gt;
            &lt;h2 id="exercises" class="exercises"&gt;Exercises&lt;/h2&gt;
            &lt;ol class="ex"&gt;
              
&lt;li id="exercise-1"&gt;&lt;a class="no" aria-label="Exercise 1, see the answer" href="https://jonreyna.dev/writing/proving-bgpsieve#answer-1"&gt;1.&lt;/a&gt;&lt;span&gt;&lt;span class="rating"&gt;&lt;span class="b"&gt;[&lt;/span&gt;10&lt;span class="b"&gt;]&lt;/span&gt;&lt;/span&gt;&lt;p&gt;Why does the oracle compare &lt;code&gt;-j&lt;/code&gt; JSON output by unmarshaling both documents instead of checking &lt;code&gt;goOut == cOut&lt;/code&gt;, while every router-config vendor is compared byte for byte?&lt;/p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li id="exercise-2"&gt;&lt;span class="rec" aria-label="Recommended"&gt;▸&lt;/span&gt;&lt;a class="no" aria-label="Exercise 2, see the answer" href="https://jonreyna.dev/writing/proving-bgpsieve#answer-2"&gt;2.&lt;/a&gt;&lt;span&gt;&lt;span class="rating"&gt;&lt;span class="b"&gt;[&lt;/span&gt;M20&lt;span class="b"&gt;]&lt;/span&gt;&lt;/span&gt;&lt;p&gt;Prove that Algorithm A preserves the exact set of permitted prefixes, and give a two-prefix counterexample showing that hyper-aggregation (&lt;code&gt;-H&lt;/code&gt;) does not.&lt;/p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li id="exercise-3"&gt;&lt;a class="no" aria-label="Exercise 3, see the answer" href="https://jonreyna.dev/writing/proving-bgpsieve#answer-3"&gt;3.&lt;/a&gt;&lt;span&gt;&lt;span class="rating"&gt;&lt;span class="b"&gt;[&lt;/span&gt;25&lt;span class="b"&gt;]&lt;/span&gt;&lt;/span&gt;&lt;p&gt;Suppose you add a new vendor formatter or flag to a drop-in rewrite and generate your differential test cases automatically. What failure mode does a blind “record C’s stdout as golden” harness miss, and how does the &lt;code&gt;RS-MIXED-V6RANGE&lt;/code&gt; case illustrate it?&lt;/p&gt;&lt;/span&gt;&lt;/li&gt;

            &lt;/ol&gt;
            &lt;h2 id="answers" class="exercises"&gt;Answers to exercises&lt;/h2&gt;
            &lt;ol class="ex answers"&gt;
              
&lt;li id="answer-1"&gt;&lt;a class="no" aria-label="Back to exercise 1" href="https://jonreyna.dev/writing/proving-bgpsieve#exercise-1"&gt;1.&lt;/a&gt;&lt;span&gt;&lt;p&gt;JSON allows arbitrary insignificant whitespace and key ordering, so two encoders can emit different bytes for the same data structure; &lt;code&gt;reflect.DeepEqual&lt;/code&gt; on decoded values tests semantic equality without coupling the Go encoder to C’s formatting quirks. Router configs, by contrast, are often diffed line by line in GitOps pipelines or Ansible checks, so stray spaces or blank lines cause spurious config churn.&lt;/p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li id="answer-2"&gt;&lt;a class="no" aria-label="Back to exercise 2" href="https://jonreyna.dev/writing/proving-bgpsieve#exercise-2"&gt;2.&lt;/a&gt;&lt;span&gt;&lt;p&gt;Each step in Algorithm A merges only when two siblings of length &lt;math&gt;&lt;mrow&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/math&gt; cover both halves of their parent of length &lt;math&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;/math&gt; and carry the exact same length interval &lt;math&gt;&lt;mrow&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;[&lt;/mo&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;]&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt; (or both are exact &lt;math&gt;&lt;mrow&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/math&gt; prefixes, which is &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mrow&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;[&lt;/mo&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo&gt;,&lt;/mo&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;]&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt;)&lt;/span&gt;. By &lt;a href="https://jonreyna.dev/writing/proving-bgpsieve#eq-1"&gt;(1)&lt;/a&gt;, a route &lt;math&gt;&lt;mi&gt;q&lt;/mi&gt;&lt;/math&gt; has &lt;math&gt;&lt;mrow&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;&lt;mi&gt;q&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;&lt;mo&gt;⊆&lt;/mo&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt; with &lt;math&gt;&lt;mrow&gt;&lt;mi&gt;a&lt;/mi&gt;&lt;mo&gt;≤&lt;/mo&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;|&lt;/mo&gt;&lt;mi&gt;q&lt;/mi&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;|&lt;/mo&gt;&lt;mo&gt;≤&lt;/mo&gt;&lt;mi&gt;b&lt;/mi&gt;&lt;/mrow&gt;&lt;/math&gt; if and only if &lt;math&gt;&lt;mrow&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;&lt;mi&gt;q&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;&lt;mo&gt;⊆&lt;/mo&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mn&gt;0&lt;/mn&gt;&lt;/msub&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt; or &lt;math&gt;&lt;mrow&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;&lt;mi&gt;q&lt;/mi&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;&lt;mo&gt;⊆&lt;/mo&gt;&lt;mi&gt;S&lt;/mi&gt;&lt;mo form="prefix" stretchy="false" lspace="0" rspace="0"&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/msub&gt;&lt;mo form="postfix" stretchy="false" lspace="0" rspace="0"&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;/math&gt; with the same bounds (or &lt;math&gt;&lt;mrow&gt;&lt;mi&gt;q&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;/mrow&gt;&lt;/math&gt; when &lt;math&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;/math&gt; itself was active and the lower bound drops to &lt;span class="nowrap"&gt;&lt;math&gt;&lt;mi&gt;ℓ&lt;/mi&gt;&lt;/math&gt;)&lt;/span&gt;. For &lt;code&gt;-H&lt;/code&gt;, take the two prefixes &lt;code&gt;192.0.2.0/24&lt;/code&gt; and &lt;code&gt;192.0.2.0/25&lt;/code&gt;: &lt;code&gt;-A&lt;/code&gt; keeps them exact, whereas &lt;code&gt;-H&lt;/code&gt; collapses them to &lt;code&gt;192.0.2.0/24&lt;/code&gt; alone, dropping the &lt;code&gt;/25&lt;/code&gt; entry (or, with &lt;code&gt;192.0.2.0/25&lt;/code&gt; and &lt;code&gt;192.0.2.128/25&lt;/code&gt;, &lt;code&gt;-H&lt;/code&gt; emits &lt;code&gt;192.0.2.0/24&lt;/code&gt; which permits &lt;code&gt;/24&lt;/code&gt; even though only the two &lt;code&gt;/25&lt;/code&gt;s were in the input).&lt;/p&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li id="answer-3"&gt;&lt;a class="no" aria-label="Back to exercise 3" href="https://jonreyna.dev/writing/proving-bgpsieve#exercise-3"&gt;3.&lt;/a&gt;&lt;span&gt;&lt;p&gt;If you treat the C binary as infallible and auto-bless its output as ground truth, you faithfully clone its silent bugs too. In &lt;code&gt;RS-MIXED-V6RANGE&lt;/code&gt;, C &lt;code&gt;bgpq3 -x&lt;/code&gt; returned exit code 0 and valid JunOS config, simply omitting &lt;code&gt;2001:db8:2::/48^49-49&lt;/code&gt;. Catching that requires both independent assertions on expected prefixes and reading the C source whenever a diff appears.&lt;/p&gt;&lt;/span&gt;&lt;/li&gt;

            &lt;/ol&gt;
            &lt;p class="fleuron" aria-hidden="true"&gt;⁂&lt;/p&gt;
            &lt;section class="footnotes"&gt;
              &lt;ol&gt;
                &lt;li id="fn-bgpq3"&gt;
                  &lt;p&gt;Alexandre Snarskii, &lt;code&gt;bgpq3&lt;/code&gt; (&lt;code&gt;v0.1.38&lt;/code&gt;), BSD 2-Clause, at &lt;a href="https://github.com/snar/bgpq3"&gt;github.com/snar/bgpq3&lt;/a&gt;.
                     &lt;a href="https://jonreyna.dev/writing/proving-bgpsieve#fnref-bgpq3" class="footnote-backref" aria-label="Back to the text"&gt;↩&lt;/a&gt;&lt;/p&gt;
                &lt;/li&gt;
                &lt;li id="fn-irrd"&gt;
                  &lt;p&gt;IRRd’s persistent TCP mode starts with &lt;code&gt;!!&lt;/code&gt;, selects sources with &lt;code&gt;!s&lt;/code&gt;, expands AS-sets with 
                    &lt;code&gt;!i&amp;lt;set&amp;gt;,1&lt;/code&gt;, and fetches IPv4 and IPv6 routes with &lt;code&gt;!g&amp;lt;as&amp;gt;&lt;/code&gt; and &lt;code&gt;!6&amp;lt;as&amp;gt;&lt;/code&gt;.
                     &lt;a href="https://jonreyna.dev/writing/proving-bgpsieve#fnref-irrd" class="footnote-backref" aria-label="Back to the text"&gt;↩&lt;/a&gt;&lt;/p&gt;
                &lt;/li&gt;
                &lt;li id="fn-demo"&gt;
                  &lt;p&gt;The public demo at &lt;a href="https://bgpsieve.jonreyna.dev"&gt;bgpsieve.jonreyna.dev&lt;/a&gt; runs &lt;code&gt;bgpsieved&lt;/code&gt;
                     on a five-node Raspberry Pi k3s cluster managed with Flux, behind a Cloudflare Tunnel. &lt;a href="https://jonreyna.dev/writing/proving-bgpsieve#fnref-demo" class="footnote-backref" aria-label="Back to the text"&gt;↩&lt;/a&gt;&lt;/p&gt;
                &lt;/li&gt;
              &lt;/ol&gt;
            &lt;/section&gt;
          &lt;/section&gt;</content>
  </entry>
</feed>
