<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Pradyun N.'s Writings</title>
<description>Some of my longer and shorter thoughts, all faithfully written in Org Mode.</description>
<generator>Emacs webfeeder.el</generator>
<link>https://pradyun.net</link>
<atom:link href="https://pradyun.net/rss.xml" rel="self" type="application/rss+xml"/>
<lastBuildDate>Sun, 08 Nov 2026 01:55:13 +0000</lastBuildDate>
<item>
  <title>Avy, Not-Zettelkasten, Pictures, and Other Stuff</title>
  <description><![CDATA[<div id="content" class="content">

 <p>
There's a smattering of things I've wanted to write about, but they're all fairly small updates or thoughts over the last couple of months. I figured I'd just lump them into a single stream-of-thought, and I'll let you (the reader) decide which parts are interesting to you.
</p>


 <div id="outline-container-org0831b90" class="outline-2">
 <h2 id="org0831b90">Trying out Avy</h2>
 <div class="outline-text-2" id="text-org0831b90">
 <p>
For the last two weeks I've disabled  <a href="https://gitlab.com/pradyun/athena/commit/561dcc829322e0390a00265e861328c577020e20">line numbers in Emacs</a> and instead moved to using  <a href="https://github.com/abo-abo/avy.git">Avy</a>, by indirect recommendation from  <a href="https://irreal.org/blog/?p=11507">Irreal</a>.
</p>

 <p>
Worth it! I was subconsciously abusing Consult to jump within buffers anyway, but more often than not i just want to jump to a specific word that's already on-screen. So avy fills that need pretty well. I especially like the fact that there's a pre-highlight of where a jump will take me, whereas using Consult doesn't have any visual indication of where the match is, even if it's in the window.
</p>

 <p>
There are some actions that I will probably try to add to the dispatch to make life easier – particularly a "roll" command. The idea being that I can select a new point for the cursor as usual, but "roll" it such that the current cursor position spatially within a window is retained. Almost like a more powerful version of  <code>zt</code> or  <code>zz</code> in Vim.
</p>

 <p>
Karthinks has a  <a href="https://karthinks.com/software/avy-can-do-anything/#adc2ee">pretty great post</a> on more complex actions with Avy, for example by using Embark. I haven't dabbled with that too much, as the basic functionality of jumping has been enough for me. Realistically if I can work with some simple tools that get the job done, why make it more complex?
</p>
</div>
</div>
 <div id="outline-container-orgd4afb7d" class="outline-2">
 <h2 id="orgd4afb7d">My Not-Zettelkasten</h2>
 <div class="outline-text-2" id="text-orgd4afb7d">
 <p>
I read  <a href="https://www.amazon.com/How-Take-Smart-Notes-Nonfiction/dp/1542866502">How to Take Smart Notes</a> over the summer. From what I can tell it's basically turned into the standard form of propaganda for Zettelkasten users, and it was  <i>fairly</i> successful in making me at least want to try it! 
</p>

 <blockquote>
 <p>
 <b>TL;DR</b>: Organize your notes in thoughts in a way that you can later on traverse them easily for recall or ideas. That requires your note structure reflecting some sense of interconnection of ideas, and each note being atomic enough that you can accommodate complex interconnection of ideas. You can do that with Zettelkasten, yippee!
</p>
</blockquote>

 <p>
There's some nice asides on more meta-advice of doing research, learning and thinking about life that I also quite enjoyed. The book is written by a sociologist, so it's not  <i>perfectly</i> transferable to the engineering realm – several of our notes are basically information dumps or documentation, whereas that is maybe not as relevant for a sociologist. But the core concepts are pretty good nonetheless.
</p>

 <p>
I modified the Zettelkasten methods pushed by the book and rabid Obsidian users a bit to suit my own needs a bit better. Specifically, I keep a separate out-of-zettel folder for project-specific notes, documentation, and draft-writing. I have heard of Obsidian users that choose to lump it all together, but I felt like meeting agendas and stuff would cause cruft to accumulate throughout the core Zettelkasten graph.
</p>

 <p>
Combining Zettelkasten with some of my older Org notes via the  <a href="https://github.com/org-roam/org-roam">org-roam</a> package has been fairly ergonomic, and combining it with the  <a href="https://github.com/org-roam/org-roam-ui">org-roam-ui</a> package leads to nice graph views like the one here.
</p>


 <div id="org3afa1ac" class="figure">
 <p> <img src="../images/org-roam-graph.png" alt="org-roam-graph.png" class="eightywimg"></img></p>
</div>

 <p>
It also gives some structure to my pre-existing habit of writing out my notes and thoughts on legal pads. I usually end up keeping a bunch of those legal pad/memo pad ages on my desk for weeks at a time for reference, but long-term the ideas have nowhere to go or be filed. So this helps.
</p>

 <p>
The  <i>problems</i> here are that filing away notes takes time… a  <i>lot</i> of it actually. In "smooth sailing" times it's not too bad and I can get through the 2-3 memo pad pages that I've filled with ideas, questions, and notes. And if I've been to class on a particular day, those can be filed away in relevant sub-nodes as basically a transcription pass.
</p>

 <p>
But it's not always smooth sailing. Especially when research gets rough, there is straight up not enough time or energy at the end of the day to spend about an hour going through and logging all of these notes somewhere. And even worse, when I transcribe my notes and thoughts it's not just verbatim, I usually try to engage with the ideas as I type them out. I enjoy that part of the process, so it's not a downside, but it does cause pretty high time overheads. Some days I put out a lot more than 3 memo pad pages, and it becomes rather infeasible to get it all typed out in a single shot. As we speak, I have quite the backlog of memo pad pages  <sup> <a id="fnr.backlog" class="footref" href="#fn.backlog" role="doc-backlink">1</a></sup> that I didn't log into Roam because of a paper deadline (which has now been met!! First paper submitted!!).
</p>

 <p>
Another professor in the department also uses legal pads extensively for ideas and scratch notes, but relies more on physical filing folders to keep track of them rather than any sort of digital ingest. That feels easier at filing-time, but I have my concerns long-term w.r.t accessibility.
</p>
</div>
</div>
 <div id="outline-container-orgcd668ed" class="outline-2">
 <h2 id="orgcd668ed">Low-Slop Routes to the Interwebz</h2>
 <div class="outline-text-2" id="text-orgcd668ed">
 <p>
I've been trying to treat my relation with the internet more consciously lately, half to improve productivity and half to just feel like I'm less fried by the fire-hose of information these days. 
</p>

 <p>
While I do enjoy Substack blogs (Irrational Analysis, Chips and Cheese, and SemiAnalysis are all gems) the main feed has gotten pretty bloated with random suggestions, and that's kind of what I'm trying to avoid? So I've moved pretty much all my regularly consumed blogs into an RSS feed, which I now read through Emacs. I feel like I've spent a lot less time getting sucked into random recommended posts as a result, with the side benefit that I'm much more up to date with the goings-on of Planet Emacs.
</p>

 <p>
Somewhat related, but less so:
</p>

 <ol class="org-ol"> <li>I am now on  <a href="https://discuss.systems/@pgn">Mastodon</a>, and have found some very cool individuals through it! I especially appreciate the lack of a "curated feed", a la Instagram or Twitter.</li>
 <li>I've kind of stopped looking at Hacker News and exclusively stalk  <a href="https://lobste.rs">lobste.rs</a>. HN has gotten really inundated with AI-written slop posts and that sort of rhetoric. It's important to stay updated with the big moves in AI, sure, but I really hate how fabricated and attention-hungry the whole forum has gotten. Communication is an inherently human thing, and I want to read things that were… written by people? I have far more ranting to do on this topic, but that's for another time.</li>
</ol> <p>
The time I've bought back has, of course, been partially spent on additional side questing. Some of that has been the Emacsen mentioned here (and some not), and some has been  <a href="#orgba7eb8e">reading</a>.
</p>
</div>
</div>
 <div id="outline-container-orgba7eb8e" class="outline-2">
 <h2 id="orgba7eb8e">I started reading again</h2>
 <div class="outline-text-2" id="text-orgba7eb8e">
 <p>
Well I guess I was reading blogs the whole time, but I've started getting back into reading books for leisure, which has been nice. In addition to the funny Zettelkasten book, I've gotten through  <a href="https://ia801402.us.archive.org/24/items/on_the_shortness_of_life_Better_life_publication/on_the_shortness_of_life_.pdf">Seneca on the shortness of life</a>, part of  <a href="https://craftinginterpreters.com/">Crafting Interpreters</a>, and am currently reading  <a href="https://www.goodreads.com/book/show/785396.The_Pentium_Chronicles">The Pentium Chronicles</a>.
</p>

 <p>
I stopped reading Crafting Interpreters about halfway through the  <code>jlox</code> implementation because I realized I wanted something more theory-flavored. Picked up a copy of the Dragon Book from the university library, and plan to start reading it soon. I've enjoyed the Pentium Chronicles so far, I feel like anyone who's vaguely interested in the goings-on of computer architecture would too!
</p>
</div>
</div>
 <div id="outline-container-org180ae39" class="outline-2">
 <h2 id="org180ae39">Miscellaneous Photos</h2>
 <div class="outline-text-2" id="text-org180ae39">
 <p>
I said I would post more pictures from around campus when I posted about my  <a href="../blog/new_camera.html">first experiences with the X-Pro 3</a>, but never got around to it! 
</p>

 <p>
So here are some pictures over the last 3 months that I thought were pretty decent. Reading the manual and generally having more time to get used to the quirks of the X-Pro has helped picture quality, and I'm having less difficulty with blown-out highlights and issues of that sort. There is some biasing towards pictures from July/August, I got pretty busy in September with research and PhD applications.
</p>

 <p>
Everything is SOOC as always – some of these could probably use a good crop or lighting corrections, but I'm not a huge fan of editing in post.
</p>


 <div id="org6cec42e" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/DSCF9774-1920.webp" alt="DSCF9774-1920.webp" class="eightywimg"></img></p>
</div>


 <div id="org327e0ea" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/DSCF9819-1920.webp" alt="DSCF9819-1920.webp" class="eightywimg"></img></p>
</div>


 <div id="orgce02eb0" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/DSCF9971-1920.webp" alt="DSCF9971-1920.webp" class="eightywimg"></img></p>
</div>


 <div id="orgc088032" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/DSCF1061-1920.webp" alt="DSCF1061-1920.webp" class="eightywimg"></img></p>
</div>


 <div id="org2ef9299" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/DSCF1079-1920.webp" alt="DSCF1079-1920.webp" class="eightywimg"></img></p>
</div>


 <div id="org42db04d" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/DSCF1151-1920.webp" alt="DSCF1151-1920.webp" class="halfwimg"></img></p>
</div>
</div>
</div>
 <div id="outline-container-org9f3f4e7" class="outline-2">
 <h2 id="org9f3f4e7">Conclusion</h2>
 <div class="outline-text-2" id="text-org9f3f4e7">
 <p>
I have been alive! I have been doing things!
</p>
</div>
</div>
 <div id="footnotes">
 <h2 class="footnotes">Footnotes: </h2>
 <div id="text-footnotes">

 <div class="footdef"> <sup> <a id="fn.backlog" class="footnum" href="#fnr.backlog" role="doc-backlink">1</a></sup> <div class="footpara" role="doc-footnote"> <p class="footpara">
A quick tally comes out to 24 sheets, half of which are double-sided… Not looking forward to clearing the backlog, but it must be done at some point.
</p></div></div>


</div>
</div></div>]]></description>
  <link>https://pradyun.net/blog/avy_and_other_things.html</link>
  <guid isPermaLink="false">https://pradyun.net/blog/avy_and_other_things.html</guid>
  <pubDate>Sat, 03 Oct 2026 00:00:00 +0000</pubDate>
</item>
<item>
  <title>Of Course Emacs has an MPD client</title>
  <description><![CDATA[<div id="content" class="content">

 <p>
I recently started getting back into listening to my offline music library as a way to improve focus – my long-forgotten Linux ricing neurons immediately whispered "install you must, MPD"  <sup> <a id="fnr.1" class="footref" href="#fn.1" role="doc-backlink">1</a></sup>. MPD is a fairly lightweight music player daemon, with plenty of frontends designed for it over the years.  <a href="https://github.com/ncmpcpp/ncmpcpp">ncmpcpp</a> and  <a href="https://rmpc.mierak.dev/">rmpc</a> are fairly good examples of such frontends. There's also a command-line utility for managing MPD called  <a href="https://musicpd.org/clients/mpc/">mpc</a>.
</p>

 <p>
At some point I was trying to use  <code>mpc</code> to update my library and forgot to type in the subcommand… but I did so in  <code>eshell</code>. Normally, you would expect to see MPD status when that happens.
</p>


 <div id="orgc1fcbf9" class="figure">
 <p> <img src="../images/actual_mpc.png" alt="actual_mpc.png" class="eightwimg"></img></p>
</div>

 <p>
I instead furrowed my brow rather quickly, as my Emacs window turned into a window layout I hadn't seen before.
</p>


 <div id="orga35fab4" class="figure">
 <p> <img src="../images/emacs_mpc.png" alt="emacs_mpc.png" class="halfwimg"></img></p>
</div>

 <p>
Turns out that Emacs  <a href="https://github.com/typester/emacs/blob/master/lisp/mpc.el">ships with an MPD frontend</a>, also called  <code>mpc</code>. Since  <code>eshell</code> prioritizes lisp functions over underlying shell commands, any  <code>mpc</code> commands will route into  <code>(mpc)</code> instead.
</p>

 <p>
I couldn't find much documentation or mention of people's experiences with  <code>mpc</code> online, save for this  <a href="https://www.reddit.com/r/emacs/comments/qnuiv5/control_mpd_with_emacs/">Reddit thread</a> that points to a dead article. There is an  <a href="https://www.emacswiki.org/emacs/Mpc">EmacsWiki page</a> about MPC, but it gets buried by other  <code>MCP</code>-related results for any query of the form "Emacs MPD client" or "Emacs MPC client", which is unfortunate.
</p>

 <p>
I've been using  <code>mpc</code> in Emacs as my main frontend for MPD for a couple months, and it's been fairly good. I don't need to open up a new terminal to queue/skip songs and I can add keybinds pointing to  <code>mpc</code> internal functions to do common actions.
</p>

 <p>
This blog post was originally intended to be something of a "guide", but I wasn't aware of the EmacsWiki page at that time! So consider this more of a PSA than anything. And happy September!
</p>
 <div id="footnotes">
 <h2 class="footnotes">Footnotes: </h2>
 <div id="text-footnotes">

 <div class="footdef"> <sup> <a id="fn.1" class="footnum" href="#fnr.1" role="doc-backlink">1</a></sup> <div class="footpara" role="doc-footnote"> <p class="footpara">
For narrative purposes, this part of my brain speaks like a deranged tiled-window-managing version of Yoda.
</p></div></div>


</div>
</div></div>]]></description>
  <link>https://pradyun.net/notes/emacs_mpc.html</link>
  <guid isPermaLink="false">https://pradyun.net/notes/emacs_mpc.html</guid>
  <pubDate>Tue, 08 Sep 2026 00:00:00 +0000</pubDate>
</item>
<item>
  <title>Reverse Engineering a Chip (or well, a GDS)</title>
  <description><![CDATA[<div id="content" class="content">

 <style>
.fullwimg {
  max-width: min(100%, 52rem);
}
</style> <p>
I've been waiting a couple of weeks to publish this!! Jane Street put out a  <a href="https://blog.janestreet.com/can-you-reverse-engineer-an-asic/">GDS reverse engineering challenge</a> in early August which looked pretty fun, so I jumped on it pretty much immediately. They did, however, embargo solutions until the deadline of September 4th, hence why this is getting posted so late.
</p>
 <div id="outline-container-org7a14924" class="outline-2">
 <h2 id="org7a14924">Background</h2>
 <div class="outline-text-2" id="text-org7a14924">
 <p>
To briefly summarize the problem statement:
</p>

 <blockquote>
 <p>
Here's a GDSII layout file. If we sent this to a fab, they'd etch it into silicon and make a chip.
</p>

 <p>
Figure out what the proposed chip does, and what input sequence makes the  <code>success</code> output toggle high. Then report the ASCII string associated with that solution.
</p>
</blockquote>

 <p>
The ASCII generator wasn't considered part of the "interesting" circuit, which is why you'll see it mostly ignored in the journey below. I also gloss over the top-level IO throughout the writeup, but it's really quite bare:
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #531ab6;">module</span>  <span style="color: #721045;">puzzle</span> (
     <span style="color: #005f5f;">input</span>  <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">rst_n</span>,
     <span style="color: #005f5f;">input</span>  <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">clk</span>,
     <span style="color: #005f5f;">input</span>  <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">I</span>,
     <span style="color: #005f5f;">input</span>  <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">enable</span>,
     <span style="color: #005f5f;">output</span>  <span style="color: #005f5f;">logic</span>  <span style="color: #005e8b;">success</span>
);
</pre>
</div>

 <p>
AI was used throughout the process to do some of the ickier things that were considered legal – investigating open-source tools and writing throwaway scripts for the most part. There were two cases where an underspecified prompt caused AI to go a little too far in the solving, but those "discoveries" were promptly wiped (off the hard disk and from my memory), and I continued solving the puzzle on my own. I've noted where the AI made such oversteps and as I hope you will agree, I don't think it compromises the authenticity of my solution too much!
</p>

 <p>
The first bit of my solve involved generating a Verilog netlist from the input GDS file – this provides conectivity of all the low-level standard cells ( <code>NAND</code>,  <code>OR</code>,  <code>MUX</code>,  <code>FF</code>) used in the design, and can be used in simulation tools to test correctness. My input pattern was mostly determined by manually observing/rewriting the netlist and running test-simulations to figure out what each of the individual sections of the GDS did, and how they would affect  <code>success</code>. The observed behaviors were used to compile a set of rules the input stimulus would have to obey, which was then used to construct a simple state-space exploration model.
</p>

 <p>
I made a fairly critical oversight early in the process that you could just use  <a href="https://yosyshq.readthedocs.io/projects/yosys/en/0.40/cmd/sat.html">Yosys' sat tool</a> on an elaborated netlist to pull out the final solution. As a result, this is a  <i>significantly</i> more manual solution than most of the other ones that I've seen people online post (ahead-of-embargo) as well as the methods AI has suggested during an after-solve postmortem. However, it has the neat side effect that I pretty much know exactly what every hardware structure and comb chain in the GDS is, to enough of a degree that I think the reverse-engineering here could be used to write behavioral HDL yielding an equivalent post-synth netlist.
</p>

 <p>
The rest of this writeup was actually the e-journal I used to reason about the puzzle as I solved it, as well as a bunch of screenshots and relevant snippets I collected to document the journey. As a result, there's definitely a lot of jumping-between-ideas and backtracking, nor is the prose necessarily that of a "polished postmortem". I would read the rest of this blog post as more of a novel than as a "solution document" as a result (or fast-forward to  <a href="#orga898031">the end</a>). Enjoy!
</p>
</div>
</div>
 <div id="outline-container-org3204f52" class="outline-2">
 <h2 id="org3204f52">Making Sense of the Thing</h2>
 <div class="outline-text-2" id="text-org3204f52">
 <p>
I first pulled up the GDS in KLayout. It's a bit dense, so I toggled out the upper regions and hid all the tap/via/internal cells. Left with a much nicer view! Approximately equivalent to the image shown in the repo, actually.
</p>


 <div id="orgc9c23b7" class="figure">
 <p> <img src="../images/gds_reverse/simplayout.png" alt="simplayout.png" class="halfwimg"></img></p>
</div>

 <p>
Now want to identify block boundaries and reverse-engineer them by hand. Makes life easier, and we can look at smaller parts of the design one-by-one. Manually enumerated those in the table below. Little slog-y, but should return dividends later.
</p>
</div>
 <div id="outline-container-org1a23168" class="outline-3">
 <h3 id="org1a23168">Regions of Interest</h3>
 <div class="outline-text-3" id="text-org1a23168">
 <p>
Here are the bounding boxes of all the distinctly observed islands in the layout.
</p>

 <table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"> <colgroup> <col class="org-right"></col> <col class="org-left"></col> <col class="org-left"></col> <col class="org-left"></col></colgroup> <thead> <tr> <th scope="col" class="org-right">No.</th>
 <th scope="col" class="org-left">Thing</th>
 <th scope="col" class="org-left">Coord 1</th>
 <th scope="col" class="org-left">Coord 2</th>
</tr></thead> <tbody> <tr> <td class="org-right">~</td>
 <td class="org-left">Funny coord box</td>
 <td class="org-left">(0, -48)</td>
 <td class="org-left">(200, -54)</td>
</tr> <tr> <td class="org-right">1</td>
 <td class="org-left">Top Left Flop</td>
 <td class="org-left">(29, 207)</td>
 <td class="org-left">(41, 195)</td>
</tr> <tr> <td class="org-right">2</td>
 <td class="org-left">Upper Behemoth</td>
 <td class="org-left">(100, 289)</td>
 <td class="org-left">(132, 179)</td>
</tr> <tr> <td class="org-right">3</td>
 <td class="org-left">Top Right</td>
 <td class="org-left">(164, 290)</td>
 <td class="org-left">(184, 262)</td>
</tr> <tr> <td class="org-right">4</td>
 <td class="org-left">Middle Left</td>
 <td class="org-left">(17.93, 168)</td>
 <td class="org-left">(44, 140)</td>
</tr> <tr> <td class="org-right">5</td>
 <td class="org-left">Middle Right</td>
 <td class="org-left">(54.88, 170)</td>
 <td class="org-left">(101, 130)</td>
</tr> <tr> <td class="org-right">6</td>
 <td class="org-left">Lower Middle Left</td>
 <td class="org-left">(24, 113.5)</td>
 <td class="org-left">(44, 89)</td>
</tr> <tr> <td class="org-right">7</td>
 <td class="org-left">Lower Middle Right</td>
 <td class="org-left">(70, 116)</td>
 <td class="org-left">(93, 91)</td>
</tr> <tr> <td class="org-right">8</td>
 <td class="org-left">Lower Behemoth</td>
 <td class="org-left">(106, 154)</td>
 <td class="org-left">(135, 41)</td>
</tr> <tr> <td class="org-right">9</td>
 <td class="org-left">Bottom Left</td>
 <td class="org-left">(65, 64.3)</td>
 <td class="org-left">(96, 18)</td>
</tr> <tr> <td class="org-right">10</td>
 <td class="org-left">Bottom Right</td>
 <td class="org-left">(150, 60)</td>
 <td class="org-left">(195, 10)</td>
</tr></tbody></table></div>
</div>
</div>
 <div id="outline-container-org64357bb" class="outline-2">
 <h2 id="org64357bb">Easter Egg 1</h2>
 <div class="outline-text-2" id="text-org64357bb">
 <p>
The internal boxes at the bottom of the layout looked pretty weird. This was what I called "Funny coord box" above.
</p>


 <div id="org72f3f68" class="figure">
 <p> <img src="../images/gds_reverse/internalboxes.png" alt="internalboxes.png" class="eightywimg"></img></p>
</div>

 <p>
At first I thought it was spelling something out in ASCII, and thought I'd do some coordinate division later on when I had a GDS parser written. I ended up hiding the cells for some reason and saw the same region again anew.
</p>


 <div id="org5f10a23" class="figure">
 <p> <img src="../images/gds_reverse/morse.png" alt="morse.png" class="eightywimg"></img></p>
</div>

 <p>
That looks… almost  <i>suspiciously</i> like morse code. There were three different spacings I spotted – tiny, sub-1-box-medium, and greater-than-two-boxes. So symbol, letter, word spacings, I suppose? Can't hurt to dump it into an online translator.
</p>


 <div id="orga974d83" class="figure">
 <p> <img src="../images/gds_reverse/morse_transl.png" alt="morse_transl.png" class="eightywimg"></img></p>
</div>

 <p>
Honestly I thought it was gibberish or that I was typing it in wrong until I saw the  <code>ad</code>. At that point I was pretty sure it was Latin. Sure enough:
</p>

 <blockquote>
 <p>
 <i>Through the sand to the stars.</i>
</p>
</blockquote>

 <p>
Very fitting for silicon! Though I would have expected it from SpaceX, not JS.
</p>
</div>
</div>
 <div id="outline-container-orgbd06cd8" class="outline-2">
 <h2 id="orgbd06cd8">Python-ing to Look at Cells</h2>
 <div class="outline-text-2" id="text-orgbd06cd8">
 <p>
Okay bounding boxes have been constructed. Python time. Sub-block elaboration may be overkill, but it seems like the easiest way for me to write out a behavioral equivalent for analysis by inspection.
</p>

 <p>
I'd been using AI to search for tools and how to set up SKY130-type stuff, but I now used it to vibe-code a small script that uses the  <code>klayout</code> python library to parse the GDS file. Did some basic accounting to make sure that the boxes I'd be inspecting didn't have overlapping cells, and that only non-trivial cells (no clkbuf, tap, via, etc.) would be recorded. I also specifically wanted to see what cells were not captured by the boxes. Looking at the output of said script:
</p>

 <div class="org-src-container">
 <pre class="src src-bash">$ ./polygons.py  <span style="color: #595959;"># </span> <span style="color: #595959;">done this way bc venv in eshell is hard
</span>sky130_fd_sc_hd__clkbuf_4 r0 97.52,70.72
sky130_fd_sc_hd__clkbuf_8 r180 102.58,76.16
sky130_fd_sc_hd__clkbuf_4 r0 146.28,174.08
sky130_fd_sc_hd__clkbuf_16 r0 104.88,163.2
sky130_fd_sc_hd__clkbuf_8 m90 91.08,76.16
sky130_fd_sc_hd__clkbuf_4 r0 83.26,76.16
</pre>
</div>

 <p>
Okay, only clock buffers were ignored. Splendid!
</p>

 <p>
I updated the script to also dump all the cell names. A lot of these look like familiar formulations from intro to VLSI, but I did notice that I hadn't accounted for diodes in my ignore list.
</p>

 <div class="org-src-container">
 <pre class="src src-nil">sky130_fd_sc_hd__diode_2: 9
</pre>
</div>

 <p>
Again for functional modeling reasons, I'm going to map this down as a passthrough or an ignore. Additionally, I didn't see any tristate buffers or other non-bistate cells, so going forwards I assume this is a "well-behaved" digital circuit, without any odd  <code>inout</code>-like properties.
</p>

 <p>
At this point, the hopeful approach is that given the functional descriptions of each cell, which we can find in the library files, and identifying net connectivity, we can form some sort of high-level netlist to reverse-engineer.
</p>

 <p>
At this point it appears that there are 494 cells in the mystery components of the layout. That seems fairly tractable to create a basic netlist of, and then try to make sense of the netlist directly. I suspect adders will be the most annoying primitive to identify by inspection.
</p>
</div>
</div>
 <div id="outline-container-orgd16e7ff" class="outline-2">
 <h2 id="orgd16e7ff">Assembling Sub-Block Connectivity</h2>
 <div class="outline-text-2" id="text-orgd16e7ff">
 <p>
So turns out the GDS doesn't actually record net connectivity, which makes sense, it's basically just a shape database. The authors did retain the cell instances and pin labels though, which is  <i>very</i> kind of them. This makes life a little bit easier.
</p>

 <p>
So the hope is this: we basically harvest the PDK connectivity rules to "flatten" nets, dump a really verbose netlist, and expand our script to flatten it for us iteratively.
</p>

 <p>
When initially prompting GPT to ask it about the capabilities of the KLayout library to accomplish the net flattening task, it somehow figured out the mappings from layer names to metal layers and via layers? Not too sure how, I guess it did it by looking at the PDK files that I had in the same directory?
</p>

 <p>
Turns out that it found a conveniently provided  <code>gds_layers.csv</code> in the skywater PDK which shows exactly what the mapping is from semantic names to numerical names. So we can now start to form nets since we know what the metal and connectivity layers are in the GDS. 
</p>

 <p>
So  <code>gds_layers.csv</code> shows that the Skywater PDK has exactly 5 metal layers. Looking at KLayout, it seems like Metals 4 and 5 are mostly used for routing  <code>VDD</code> and  <code>GND</code> (they are forming power stripes).
</p>


 <div id="orgcd3b4ac" class="figure">
 <p> <img src="../images/gds_reverse/stripes.png" alt="stripes.png" class="halfwimg"></img></p>
</div>

 <p>
The  <code>li1</code> layer is for local interconnect, so I assume that to be within the cell. Which means only metals 1-3 and the vias connecting them together need to be traced for net connectivity, with some floating checks done afterwards to fill in gaps.
</p>

 <p>
Additionally, we can treat "funny" instances (clkbuf, diode) as passthroughs/net retention blocks for our behavioral equivalent. GPT has been proompted to get an initial connectivity/net tracing script. I've requested that it treat clock buffers and diodes as "pass-through" points, so the net is retained through them.
</p>

 <p>
I found some KLayout SKY130 collateral  <a href="https://github.com/laurentc2/SKY130_for_KLayout">on github</a> which was pretty useful, it almost single-handedly allows me to probe nets in KLayout now since it provides the layer connectivity descriptions.
</p>

 <p>
Turns out when I asked GPT to do net tracing it started trying to build its own netlist/connectivity extractor from the PDK files which is maybe another reason to not let AI run on its own for too long…
</p>
</div>
 <div id="outline-container-org0a4c17d" class="outline-3">
 <h3 id="org0a4c17d">Round 2</h3>
 <div class="outline-text-3" id="text-org0a4c17d">
 <p>
Pivoted a little bit. Turns out that KLayout has this nifty feature that lets you export netlist connectivity in a file format called L2N, and Klayout's PyPi package has support for reading that in directly (rather than reforming connectivity in Python). So now (~9:14PM) new approach is reading in that L2N and correlating it with the GDS we read in via a Python script.
</p>

 <p>
The initial script prototype is done at 9:27 after some back-and-forth! New script clocks in at only 270 lines, vs. the ~900 that GPT tried to write over the previous pass (yikes). But it's pretty useful – given one of our boxes, we can now see this handy breakdown:
</p>

 <div class="org-src-container">
 <pre class="src src-nil">$ ./simple_nettrace.py --box 1
Box 1 (29, 195, 41, 207)
3 netlist instances (+1 contracted), 8 signal nets: 1 internal, 7 boundary

Instances:
  $4180 sky130_fd_sc_hd__dfrtp_2 .RESET_B(rst_n), .Q($563),
    .CLK(clk [physical $421]), .D($573)
  $4600 sky130_fd_sc_hd__a31o_2 .X($573), .A3($193),
    .A2($284), .A1($289), .B1($563)
  $4716 sky130_fd_sc_hd__and2b_2 .A_N($563), .B(enable), .X($193)

Contracted/omitted physical-only instances:
  $4713 sky130_fd_sc_hd__diode_2 (diode-load)

Internal nets:
  $573: $4180.D, $4600.X

Boundary nets:
  [input] rst_n: $4180.RESET_B; top-level port rst_n; boxes 2 (22 endpoints),
        3 (3 endpoints), 4 (4 endpoints), 5 (13 endpoints), 6 (4 endpoints),
        7 (3 endpoints), 8 (22 endpoints), 9 (8 endpoints); obox (8 endpoints)
  [input] clk: $4180.CLK; top-level port clk; boxes 2 (22 endpoints),
        3 (3 endpoints), 4 (4 endpoints), 5 (13 endpoints), 6 (4 endpoints),
        7 (3 endpoints), 8 (22 endpoints), 9 (8 endpoints);
  [output] $193: $4600.A3, $4716.X; boxes 2 (18 endpoints),...
  ...
</pre>
</div>

 <p>
Inputs and outputs can be determined for a block by checking the PDK to see if any connected pins of instances within the box is an output. This makes it a lot easier to build up Verilog-esque modules.
</p>
</div>
</div>
 <div id="outline-container-org498300d" class="outline-3">
 <h3 id="org498300d">Back-Corrections</h3>
 <div class="outline-text-3" id="text-org498300d">
 <p>
After digging a little more, I found  <a href="https://github.com/efabless/sky130_klayout_pdk">this package</a> from Efabless that provides SKY130 support for KLayout, and seems to be more recently maintained. KLayout immediately becomes much better labeled and more usable by installing it.
</p>

 <p>
There is a mild annoyance in that pins are no longer annotated with their name on cells, so I had to go back and correct the script to map pin numbers onto pin names and look at direction from that. But I guess that's not all too bad, in the grand scheme of things (especially when AI helps the process along).
</p>
</div>
</div>
</div>
 <div id="outline-container-org5d23fd1" class="outline-2">
 <h2 id="org5d23fd1">Verilog Emission</h2>
 <div class="outline-text-2" id="text-org5d23fd1">
 <p>
The end of the GDS-to-verilog reverse engineering is in sight! We can use the boundary net annotation, instance list, and internal nets emitted by  <code>simple_nettrace.py</code> to emit Verilog netlists pretty easily. When asked to generate a python script that does this, GPT was able to do it in under 2 minutes. Here is Box 1 (Top Left Flop),  as an example:
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #a0132f;">`default_nettype</span> none
 <span style="color: #595959;">// </span> <span style="color: #595959;">Source: /vault/asic-puzzle-2026/efabless.l2n
</span> <span style="color: #595959;">// </span> <span style="color: #595959;">Box: (29, 195, 41, 207)
</span> <span style="color: #531ab6;">module</span>  <span style="color: #721045;">box_1</span> (
     <span style="color: #005f5f;">input</span>  <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">rst_n</span>,
     <span style="color: #005f5f;">input</span>  <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">clk</span>,
     <span style="color: #005f5f;">input</span>  <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">net285</span>,
     <span style="color: #005f5f;">input</span>  <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">net290</span>,
     <span style="color: #005f5f;">input</span>  <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">enable</span>,
     <span style="color: #005f5f;">output</span>  <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">net193</span>,
     <span style="color: #005f5f;">output</span>  <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">net569</span>
);

     <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">net579</span>;

    sky130_fd_sc_hd__dfrtp_2  <span style="color: #721045;">u4180</span> (
        . <span style="color: #721045;">RESET_B</span>(rst_n),
        . <span style="color: #721045;">Q</span>(net569),
        . <span style="color: #721045;">CLK</span>(clk),
        . <span style="color: #721045;">D</span>(net579)
    );

    sky130_fd_sc_hd__a31o_2  <span style="color: #721045;">u4640</span> (
        . <span style="color: #721045;">X</span>(net579),
        . <span style="color: #721045;">A3</span>(net193),
        . <span style="color: #721045;">A2</span>(net285),
        . <span style="color: #721045;">A1</span>(net290),
        . <span style="color: #721045;">B1</span>(net569)
    );

    sky130_fd_sc_hd__and2b_2  <span style="color: #721045;">u4756</span> (
        . <span style="color: #721045;">A_N</span>(net569),
        . <span style="color: #721045;">B</span>(enable),
        . <span style="color: #721045;">X</span>(net193)
    );

 <span style="color: #531ab6;">endmodule</span>
 <span style="color: #a0132f;">`default_nettype</span>  <span style="color: #005f5f;">wire</span>
</pre>
</div>

 <p>
For readability's sake, I did want to make the output a bit more human-friendly. Using the reset conditions and documentation in Liberty files and the PDK resources, we can elaborate common gates and blocks (resettable DFFs, AND/OR/XOR) into proper verilog directives with  <code>assign</code> statements or  <code>always_ff</code> statements. Typically I would err towards having the DFF block as an instantiation (habits from past work), but I'm not used to the terminology being used here to denote the DFF types. So the same simple block from before will look like this instead:
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #a0132f;">`default_nettype</span> none
 <span style="color: #595959;">// </span> <span style="color: #595959;">Source: /vault/asic-puzzle-2026/efabless.l2n
</span> <span style="color: #595959;">// </span> <span style="color: #595959;">Box: (29, 195, 41, 207)
</span> <span style="color: #531ab6;">module</span>  <span style="color: #721045;">box_1</span> (
     <span style="color: #005f5f;">input</span>  <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">rst_n</span>,
     <span style="color: #005f5f;">input</span>  <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">clk</span>,
     <span style="color: #005f5f;">input</span>  <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">net285</span>,
     <span style="color: #005f5f;">input</span>  <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">net290</span>,
     <span style="color: #005f5f;">input</span>  <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">enable</span>,
     <span style="color: #005f5f;">output</span>  <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">net193</span>,
     <span style="color: #005f5f;">output</span>  <span style="color: #005f5f;">logic</span>  <span style="color: #005e8b;">net569</span>
);

     <span style="color: #005f5f;">wire</span>  <span style="color: #005e8b;">net579</span>;

     <span style="color: #595959;">// </span> <span style="color: #595959;">$4180 sky130_fd_sc_hd__dfrtp_2
</span>     <span style="color: #531ab6;">always_ff</span>  <span style="color: #005f5f;">@</span>( <span style="color: #531ab6;">posedge</span> clk  <span style="color: #005f5f;">or</span>  <span style="color: #531ab6;">negedge</span> rst_n)  <span style="color: #005f5f;">begin</span> : ff_u4180
         <span style="color: #531ab6;">if</span> (!rst_n)
            net569 <= 1'b0;
         <span style="color: #531ab6;">else</span>
            net569 <= net579;
     <span style="color: #005f5f;">end</span>

    sky130_fd_sc_hd__a31o_2  <span style="color: #721045;">u4640</span> (
        . <span style="color: #721045;">X</span>(net579),
        . <span style="color: #721045;">A3</span>(net193),
        . <span style="color: #721045;">A2</span>(net285),
        . <span style="color: #721045;">A1</span>(net290),
        . <span style="color: #721045;">B1</span>(net569)
    );

     <span style="color: #595959;">// </span> <span style="color: #595959;">$4756 sky130_fd_sc_hd__and2b_2
</span>     <span style="color: #531ab6;">assign</span> net193 = (~(net569) & enable);

 <span style="color: #531ab6;">endmodule</span>
 <span style="color: #a0132f;">`default_nettype</span>  <span style="color: #005f5f;">wire</span>
</pre>
</div>

 <p>
At this point, we've done enough for readability that we can start working on actually deciphering some boxes! Though I do reserve the right to go back and add more optimization passes/lowering for readability should anything be  <i>too</i> complex.
</p>
</div>
</div>
 <div id="outline-container-org7c1693c" class="outline-2">
 <h2 id="org7c1693c">E2E Verification Pass</h2>
 <div class="outline-text-2" id="text-org7c1693c">
 <p>
As a sanity/correctness check, the tooling used to generate Verilog netlists was also used on the warmup exercise, then compared with the reference netlists provided. Since the design is smaller and the source is already available (hence the goal is comparison, less-so optimizing for decipherability), I did so in a single shot rather than selecting regions of interest. Cell count matched, resets matched the original source, but the file being 450 lines of mixed instantiations and behavioral verilog made it less than ideal to debug. 
</p>

 <p>
The largest box in our design (Upper Behemoth) seems to be even longer in line length than the export of warmup, so we may need to do some similarity analysis for the large blocks to help our line of attack.
</p>
</div>
</div>
 <div id="outline-container-org23ee5c1" class="outline-2">
 <h2 id="org23ee5c1">Deciphering: Pass 1</h2>
 <div class="outline-text-2" id="text-org23ee5c1">
 <p>
I figure this is best done by looking at each box, and trying to figure out how they relate?
</p>

 <p>
Box 1, the upper left flop, is fairly simple. The entire module was shown earlier!
</p>

 <p>
There is a single flip flop that resets to 0, with an update function described as the  <code>AND</code> of 3 inputs from other boxes  <i>or</i> the value of the flop itself. The design pattern here suggests some sort of flag, I imagine? Since one of the  <code>AND</code> inputs is simply the flop not being set yet and  <code>enable</code> being high, the set condition relies on the two middle-left blocks, both of which are on the smaller end in area.  The two salient outputs from this module are:
</p>

 <ul class="org-ul"> <li> <code>flag</code> ( <code>net569</code>)</li>
 <li> <code>active_flagn</code> ( <code>net193</code>), which indicates that the flag is not raised but the module is active</li>
</ul> <p>
At this point, I think that there's enough Verilog and enough opaque signals that a partial rewriting approach may be prudent. That is to say, renaming signals to more semantically readable counterparts as a way to understand the logic better.
</p>
</div>
</div>
 <div id="outline-container-org6b19ea5" class="outline-2">
 <h2 id="org6b19ea5">Shift Register Search</h2>
 <div class="outline-text-2" id="text-org6b19ea5">
 <p>
I noticed that the warmup had utilized a shift register. Searching for the same graph pattern in the netlist, it turned out that Box 5 had a set of chained flops with the same control inputs. Go figure! Honestly this was one of those things where I just had an idea and had GPT write throwaway scripts to confirm it.
</p>

 <p>
This reduces down Box 5 to a 12-bit shift register logging past values of  <code>I</code>, with the select logic to advance based on  <code>active_flagn</code> and some lean surrounding logic. Mapping it down to a known construct immediately accounts for 12/80 FFs in the design, which is good headway!
</p>

 <p>
Box 5's only outputs are to Box 3, which emits  <code>success</code>, so my best guess at this time is that the logic here implements some check for a "win condition", so to speak.
</p>
</div>
</div>
 <div id="outline-container-orged2a722" class="outline-2">
 <h2 id="orged2a722">Pass 2: More Verilog Reading/Rewriting</h2>
 <div class="outline-text-2" id="text-orged2a722">
 <p>
With the simplifications performed, the only other flop in Box 5 ( <code>$5342</code>) seems to be another flag with a set condition based on the input being high and a compound gate. This flag's output path is  <i>also</i> an inversion of its flop value, so probably another fulfillment condition. Tracing the assert terms of the set condition back:
</p>

 <div class="org-src-container">
 <pre class="src src-nil">(I & (SR[10] | (SR[9] & n330) | (n326 & (SR[11] | SR[0]))
</pre>
</div>

 <p>
Both nets still in this expression are from Box 7, so there's no perfect closed form here. Both nets, unfortunately, are long compound expressions:
</p>

 <div class="org-src-container">
 <pre class="src src-nil">assign net330 = (net73 | net90 | ~(net177) | ~(net8));
assign net326 = (net73 | net90 | net177 | net8 );
</pre>
</div>

 <p>
The expressions here are dangerously close though, so I guess this is something else input-dependent.
</p>

 <p>
I started by looking at net73, which is a flip-flop in Box 4. With some DeMorgan's law and rewriting, we end up with this:
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #595959;">// </span> <span style="color: #595959;">$4861 sky130_fd_sc_hd__dfrtp_2
</span> <span style="color: #531ab6;">always_ff</span>  <span style="color: #005f5f;">@</span>( <span style="color: #531ab6;">posedge</span> clk  <span style="color: #005f5f;">or</span>  <span style="color: #531ab6;">negedge</span> rst_n)  <span style="color: #005f5f;">begin</span> : ff_u4861
     <span style="color: #531ab6;">if</span> (!rst_n)
        net73 <= 1'b0;
     <span style="color: #531ab6;">else</span>
        net73 <= ~net290 & (net73 ^ active_flagn);
 <span style="color: #005f5f;">end</span>
</pre>
</div>

 <p>
This ends up looking a bit odd, since depending on the value of  <code>net290</code> this value could be oscillatory?
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #531ab6;">assign</span> net290 = (~(net73) & ~(net90) & net177 & net8);
</pre>
</div>

 <p>
I guess part of the reason this net is a bit odd is because there is fanout to other boxes?
</p>
</div>
</div>
 <div id="outline-container-org2f7f0d2" class="outline-2">
 <h2 id="org2f7f0d2">FF Arrays</h2>
 <div class="outline-text-2" id="text-org2f7f0d2">
 <p>
FF arrays are pretty common, so I was curious if there were any big ones that had shared enables, similar to the shift register. Outside of the SR we already found, Boxes 2 and 8 each contain 22 different flops that all have the same clock, reset, and enable condition – I guess that at least partially explains why they're so large!
</p>

 <p>
Starting with Box 2, there's a group of 7 sticky flops that all share a similar setup condition. For now, we can group them as a module array for simplification's sake.
</p>

 <div class="org-src-container">
 <pre class="src src-verilog">sky130_fd_sc_hd__a31o_2 u_a31o_array_660 [6:0] (
    . <span style="color: #721045;">X</span>(a31o_array_660),
    . <span style="color: #721045;">A3</span>({net551, net624, net721, net710, net682, net683, net655}),
    . <span style="color: #721045;">A2</span>({7{active_flagn}}),
    . <span style="color: #721045;">A1</span>({7{I}}),
    . <span style="color: #721045;">B1</span>(ff_array_667)
);

sky130_fd_sc_hd__o21a_2 u_o21a_array_667 [6:0] (
    . <span style="color: #721045;">X</span>(ff_array_667_d),
    . <span style="color: #721045;">B1</span>(a31o_array_660),
    . <span style="color: #721045;">A2</span>({net528, net623, net722, net706, net690, net670, net658}),
    . <span style="color: #721045;">A1</span>({net527, net619, net718, net701, net686, net669, net652})
);

 <span style="color: #531ab6;">always_ff</span>  <span style="color: #005f5f;">@</span>( <span style="color: #531ab6;">posedge</span> clk  <span style="color: #005f5f;">or</span>  <span style="color: #531ab6;">negedge</span> rst_n)  <span style="color: #005f5f;">begin</span> : ff_array_667_regs
     <span style="color: #531ab6;">if</span> (!rst_n)
        ff_array_667 <= '0;
     <span style="color: #531ab6;">else</span>
        ff_array_667 <= ff_array_667_d;
 <span style="color: #005f5f;">end</span>
</pre>
</div>

 <p>
This rewrite pares down what  <i>was</i> a 600 line file down to ~400. Simplification!
</p>

 <p>
Looking at the array of inputs on A3 of  <code>u_a31o_array_660</code> in particular, every signal seems to be  a transformation of 4 nets:
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #531ab6;">assign</span> net721 = (~(net73) & ~(net90) & net177 & net8);
 <span style="color: #531ab6;">assign</span> net551 = ~(net8 | net73 | net177 | net90);
</pre>
</div>

 <p>
 <code>net73</code> is the flag from Box 4.  <code>net90</code> is another FF from Box 4.
</p>
</div>
</div>
 <div id="outline-container-orga4b6c37" class="outline-2">
 <h2 id="orga4b6c37">Working Backwards</h2>
 <div class="outline-text-2" id="text-orga4b6c37">
 <p>
I needed a change of pace/new approach since the FF arrays were messing with me, so I wanted to trace back what the exact conditions for success raising were, and maybe do some brute-forcing on the underlying conditions. Some rewriting gets you to this much nicer expression of the success flag.
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #595959;">// </span> <span style="color: #595959;">$218 sky130_fd_sc_hd__dfrtp_2
</span> <span style="color: #595959;">// </span> <span style="color: #595959;">asserts on flag raise when net79 and net469 go both high
</span> <span style="color: #531ab6;">always_ff</span>  <span style="color: #005f5f;">@</span>( <span style="color: #531ab6;">posedge</span> clk  <span style="color: #005f5f;">or</span>  <span style="color: #531ab6;">negedge</span> rst_n)  <span style="color: #005f5f;">begin</span> : ff_u218
     <span style="color: #531ab6;">if</span> (!rst_n)
        success <= 1'b0;
     <span style="color: #531ab6;">else</span>
        success <= success | (flag & ~flag_r & net79 & net469);
 <span style="color: #005f5f;">end</span>
</pre>
</div>

 <p>
The problem is that if you go into Box 9 in the bottom right, where  <code>net79</code> comes from, you end up with this mess of an expression, at least when flattened.
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #595959;">// </span> <span style="color: #595959;">$6768 sky130_fd_sc_hd__and3_2
</span> <span style="color: #531ab6;">assign</span> net79 = ((net62 & net71 & net61 & net60) &
                (net82 & net98 & net97 & net96) &
                (net226 & net77 & net118));
</pre>
</div>

 <p>
Though for  what it's worth, each of the intermediate signals were not consumed elsewhere. So I'm inclined to suspect some sort of reduction tree operation here (equality check?). Especially since it's on 11 inputs, which is our magic array number!
</p>

 <p>
Even more specifically, this particular reduction is actually an  <code>AND</code> across 11 distinct inputs from Box 8, which contained an FF array. My spidey senses say that the FF array is probably tracking part of the win condition as status flags, so to speak.
</p>

 <p>
Box 5, the source of  <code>net469</code> actually has its own version of this same reduction network.
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #595959;">// </span> <span style="color: #595959;">$5002 sky130_fd_sc_hd__and3_2
</span> <span style="color: #595959;">// </span> <span style="color: #595959;">rename to "box_2_reduction".
</span> <span style="color: #531ab6;">assign</span> net469 = ((net663 & net443 & net463 & net461) &
                 (net591 & net449 & net465 & net462) &
                 (net459 & net457 & net441));
</pre>
</div>

 <p>
The inputs of this are all out of Box 2, from what I can tell.
</p>

 <p>
So at this point my hypothesis is that the "behemoths" are two control state bitmasks which are then  <code>AND</code>-reduced by boxes 9 and 5. Those reductions are then  <code>AND</code>-ed again to form the final success condition.
</p>

 <p>
So either by static analysis or comb-testing, we now need to figure out how to force the 11-bit vectors coming out of Boxes 2 and 8 to go high.
</p>

 <p>
Additionally, this rewrite of the reduction tree actually gets Box 5 down to only 2 concrete components.
</p>

 <ol class="org-ol"> <li>The shift register from earlier.</li>
 <li>The reduction tree for the status flops in Box 8 (Lower Behemoth).</li>
</ol> <p>
So we have a much better idea now of the purposes of Box 5 and Box 3 (the success determinant). Things are taking shape!
</p>
</div>
</div>
 <div id="outline-container-org137205e" class="outline-2">
 <h2 id="org137205e">Analyzing Box 2 to Box 5</h2>
 <div class="outline-text-2" id="text-org137205e">
 <p>
Clearly individual boxes aren't giving us perfect functional separation, so I want to instead focus on the signal paths now. In this case, how the 11-signal-array in Box 8 is being generated and passed to Box 5.
</p>

 <p>
Looking at the array FF breakdown we generated earlier, it doesn't immediately seem like the flop signals are being directly passed into the output ports. There's some weird indirection happening between different sets of FLOPs.
</p>

 <p>
With some rewriting, I was able to restructure the group of 4-input NANDs from before as this expression instead.
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #531ab6;">assign</span> ff_array_667_transform  = {
    ~(net8 | net73 | net90 | net177),
    (net8 & ~(net73) & ~(net90) & net177),
    (~(net8) & net73 & ~(net90) & net177),
    (net8 & net73 & ~(net90) & ~(net177)),
    (net8 & ~(net73) & net90 & ~(net177)),
    (~(net8) & net73 & net90 & ~(net177)),
    (net8 & net73 & net90 & ~(net177))
};
</pre>
</div>

 <p>
7/16 combinations have been enumerated of 4 outputs from Box 4, so my next point of investigation if this is fruitful will probably be going to figure out what these mean semantically (or what inputs can impact them).
</p>

 <p>
Anyway, turns out that this transform directly pipes into  <i>another</i> array NAND4s:
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #531ab6;">assign</span> ff_array_667_nand =
    ~({7{I & active_flagn}} & ff_array_667 & ff_array_667_transform );
</pre>
</div>

 <p>
Each of the signals in this array, is used in one place and one place only… and that is to "set" an array of flags. The array of flags we identified earlier. Full circle!!
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #531ab6;">always_ff</span>  <span style="color: #005f5f;">@</span>( <span style="color: #531ab6;">posedge</span> clk  <span style="color: #005f5f;">or</span>  <span style="color: #531ab6;">negedge</span> rst_n)  <span style="color: #005f5f;">begin</span> : ff_array_667_nand_r_regs
     <span style="color: #531ab6;">if</span> (!rst_n)
        ff_array_667_nand_r <= '0;
     <span style="color: #531ab6;">else</span>
        ff_array_667_nand_r <=
            ff_array_667_nand_r | ~ff_array_667_nand;
 <span style="color: #005f5f;">end</span>
</pre>
</div>

 <p>
There are now a number of nets that follow the form:
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #595959;">// </span> <span style="color: #595959;">$1255 sky130_fd_sc_hd__and2b_2
</span> <span style="color: #531ab6;">assign</span> net459 = (~(ff_array_667[3]) & ff_array_667_nand_r[3]);
</pre>
</div>

 <p>
These comprise 7/11 nets that are being passed into Box 5 for the  <code>AND</code> reduction. Another bitmask computation!
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #595959;">// </span> <span style="color: #595959;">box 2
</span> <span style="color: #531ab6;">assign</span> ff_array_667_to_box5 = ~ff_array_667 & ff_array_667_nand_r;

 <span style="color: #595959;">// </span> <span style="color: #595959;">box 5
</span> <span style="color: #531ab6;">assign</span> box2_reduction =
      (&ff_array_667_to_box5) & net443 & net457 & net462 & net591;
</pre>
</div>

 <p>
This gets our upper behemoth down from an original 600 lines down to only 280!
</p>

 <p>
Looking at other points in the file, turns out that there are  <i>other</i>  <code>NAND4</code> gates computing another 4 combinations of the 4 Box 4 inputs. There are also  <i>duplicate nets</i> – 4 different computations of  <code>~(I & active_flagn)</code>. We can compute another transform bitmask!
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #531ab6;">assign</span> ff_array_575_common = ~(I & active_flagn);
 <span style="color: #531ab6;">assign</span> ff_array_575_transform = {
    (~(net8) | net73 | net90 | net177),
    (net8 | net73 | ~(net90) | net177),
    (net8 | net73 | net90 | ~(net177)),
    (net8 | ~(net73) | net90 | net177)
};
 <span style="color: #531ab6;">assign</span> ff_array_575_condition =
    ff_array_575_transform | {4{ff_array_575_common}};
</pre>
</div>

 <p>
This ends up piping into an array of 4 FFs, albeit a little indirectly. I didn't actually spot it myself, when I asked GPT to help run a truth table on the above transformation it found the following rewrite of the 4-flop-array we grouped earlier.
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #531ab6;">assign</span> ff_array_575_o21a_a2 = ~ff_array_575_condition;
 <span style="color: #531ab6;">assign</span> ff_array_575_o21a_b1 =
    {net597, net641, net699, net576} |
    ~ff_array_575 | ff_array_575_condition;

sky130_fd_sc_hd__o21a_2 u_o21a_array_575 [3:0] (
    . <span style="color: #721045;">X</span>(ff_array_575_d),
    . <span style="color: #721045;">B1</span>(ff_array_575_o21a_b1),
    . <span style="color: #721045;">A2</span>(ff_array_575_o21a_a2),
    . <span style="color: #721045;">A1</span>(ff_array_575)
);

 <span style="color: #531ab6;">always_ff</span>  <span style="color: #005f5f;">@</span>( <span style="color: #531ab6;">posedge</span> clk  <span style="color: #005f5f;">or</span>  <span style="color: #531ab6;">negedge</span> rst_n)  <span style="color: #005f5f;">begin</span> : ff_array_575_regs
     <span style="color: #531ab6;">if</span> (!rst_n)
        ff_array_575 <= '0;
     <span style="color: #531ab6;">else</span>
        ff_array_575 <= ff_array_575_d;
 <span style="color: #005f5f;">end</span>
</pre>
</div>

 <p>
Looking at the 4 signals that are still not vectorized, those turn out to be a sticky array as well. Their "set" condition actually inherits from the same one used here. So we can get rid of some more individual signals in this module!
</p>
</div>
</div>
 <div id="outline-container-orgc6eea5c" class="outline-2">
 <h2 id="orgc6eea5c">Box 4's Weird Quartet</h2>
 <div class="outline-text-2" id="text-orgc6eea5c">
 <p>
At this point we have a set of sticky flops that are triggering on combinations of 4 specific signals coming out of Box 4. On intuition, this feels like comparison with a set of numbers? Like indices, almost. So I'd first like to check if we can consider the 4 signals in Box 4 to be a  <i>counter</i> of some sort.
</p>

 <p>
On inspection, the 4 nets are in fact flops! I created a small submodule that pulls out  <i>only</i> the nets attached to them, and that treats  <code>active_flagn</code> as a simple input. This should isolate them enough that we can see what their update logic is.
</p>

 <p>
On  <i>another</i> inspection, it turns out that Box 4 has… exactly one input, and outputs its FFs to a couple of other modules. So the test harness is approximately equivalent to the box itself. And upon observing a waveform, we see that Box 4 is, in fact, a counter. The 4 outputs form a counter that is mod-11, which would explain why we see 11-flop-arrays being special in Boxes 2 and 8.
</p>


 <div id="org66d3b84" class="figure">
 <p> <img src="../images/gds_reverse/counter.png" alt="counter.png" class="eightywimg"></img></p>
</div>

 <p>
In retrospect it's a  <i>little</i> unfortunate that we didn't just simulate some random data through the top-level as soon as we had Verilog emitted into submodules, as we probably would have seen the counter advancing! Though without the context that these are interrelated, I'm not sure I would have spotted it in real-time with ungrouped flip-flops.
</p>

 <p>
Importantly, we now know the correct order of the outputs of Box 4 – this in turn means that we can much more easily group relevant logic and comparators in other blocks!
</p>

 <p>
Additionally,  <code>net290</code>, which used to be cryptic:
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #595959;">// </span> <span style="color: #595959;">$4657 sky130_fd_sc_hd__and4bb_2
</span> <span style="color: #531ab6;">assign</span> net290 = (~(net73) & ~(net90) & net177 & net8);
</pre>
</div>

 <p>
This is just checking if the counter has hit 10! Similar comparisons and simplifications can be made across the design as a result. The transform arrays in box 2 can be converted to fairly simple constant-comparisons with counter!
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #531ab6;">assign</span> ff_array_667_transform = {
    (counter == 4'd0),
    (counter == 4'd10),
    (counter == 4'd9),
    (counter == 4'd3),
    (counter == 4'd6),
    (counter == 4'd5),
    (counter == 4'd7)
};

 <span style="color: #531ab6;">assign</span> ff_array_575_transform = {
    ~(counter == 4'd2),
    ~(counter == 4'd4),
    ~(counter == 4'd8),
    ~(counter == 4'd1)
};
</pre>
</div>

 <p>
We now also have enough information about the I/O that we can actually simulate  <code>box_4</code> and  <code>box_2</code> connected to each other, albeit while supplying some dummy information.
</p>
</div>
</div>
 <div id="outline-container-orgcbc2418" class="outline-2">
 <h2 id="orgcbc2418">Analysis of Box 2 from Simulation+Rewriting</h2>
 <div class="outline-text-2" id="text-orgcbc2418">
 <p>
After some additional rewriting, Upper Behemoth is now down to under 140 lines. Importantly, turns out that the weird cascaded register structure for 667 encodes whether a given mod-11 position in the input stream sees the value  <code>1</code> more than once. The other register array tracks whether the position has seen a 1-bit once or more than twice. Hence the transmitted data to box 5 is actually:
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #595959;">// </span> <span style="color: #595959;">you have seen 2 "1" bits in a given position
</span> <span style="color: #531ab6;">assign</span> ff_array_667_to_box5 =
    ~ff_array_667 & ff_array_667_nand_r;
</pre>
</div>

 <p>
The 575 array does the same thing, though it seems to have been optimized differently. So overall, Box 2 (Upper Behemoth) is  <i>performing a check on if there is a total of 2 ones across the mod-11 indices of the bitstring</i>. This was confirmed experimentally in simulation.
</p>


 <div id="orgee4c693" class="figure">
 <p> <img src="../images/gds_reverse/double_check.png" alt="double_check.png" class="fullwimg"></img></p>
</div>

 <p>
Going back up to Box 5, there is another success component we have not yet debugged, which is  <code>net421</code>. It needs to be low for success to fire. It is yet another sticky FF, set by the following chain: 
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #531ab6;">assign</span> set_421 = net442 & active_flagn & I;

sky130_fd_sc_hd__a22o_2  <span style="color: #721045;">u4991</span> (
    . <span style="color: #721045;">B1</span>(net326),
    . <span style="color: #721045;">B2</span>(shift_reg[11]),
    . <span style="color: #721045;">A1</span>(net326),
    . <span style="color: #721045;">A2</span>(shift_reg[0]),
    . <span style="color: #721045;">X</span>(net423)
);
sky130_fd_sc_hd__a221o_2  <span style="color: #721045;">u5198</span> (
    . <span style="color: #721045;">B2</span>(shift_reg[10]),
    . <span style="color: #721045;">C1</span>(net423),
    . <span style="color: #721045;">B1</span>(1'b1),
    . <span style="color: #721045;">A1</span>(net330),
    . <span style="color: #721045;">A2</span>(shift_reg[9]),
    . <span style="color: #721045;">X</span>(net442)
);
</pre>
</div>

 <p>
 <code>net326</code> and  <code>net330</code> used to be a bit obscure, but we can now see a very simple representation of them!
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #595959;">// </span> <span style="color: #595959;">is counter nonzero?
</span> <span style="color: #531ab6;">assign</span> net326 = (counter[0] | counter[1] | counter[2] | counter[3]);

 <span style="color: #595959;">// </span> <span style="color: #595959;">Is counter not 10?
</span> <span style="color: #531ab6;">assign</span> net330 = (counter[0] | counter[2] | ~(counter[3]) | ~(counter[1]));
</pre>
</div>

 <p>
Flattening the logic a bit:
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #531ab6;">assign</span> net423 = (|counter) & (shift_reg[11] | shift_reg[0]);
 <span style="color: #531ab6;">assign</span> net442 = net423 | shift_reg[10] | (counter != 4'd10 & shift_reg[9]);
</pre>
</div>

 <p>
We now have the three things we do  not want to see in our sequence, particularly when we see a new 1 in the stream.
</p>
 <ul class="org-ul"> <li>1 should not be in the 0th/11th position, unless we are on a clean cycle</li>
 <li>1 can only be in the 9th position when the counter has also shifted in exactly 10 bits</li>
 <li>You cannot shift in a 1 when there is already a 1 in position 10
 <ul class="org-ul"> <li>Read: Cannot have two 1s exactly 10 bits apart</li>
</ul></li>
</ul> <p>
This is a bit hard to formulate into some understandable property of input data, at least naively, so I'm going to come back to this… For now, I'll treat it as an explicit constraint to solve against for my input data later. Maybe this gains more relevance once we know the expected input length(s)?
</p>
</div>
</div>
 <div id="outline-container-org29d7e52" class="outline-2">
 <h2 id="org29d7e52">Analyzing the Lower Behemoth's Inputs</h2>
 <div class="outline-text-2" id="text-org29d7e52">
 <p>
The next step of our puzzle is figuring out what pattern is being verified by Lower Behemoth. From our previous exploration, we found that the unexplored chain from Lower Behemoth is as follows:
</p>

 <div class="org-src-container">
 <pre class="src src-nil">Box 6 -> Box 10 -> Box 8 -> Box 9 -> Box 3
</pre>
</div>

 <p>
Looking at Box 10, which seems to act as a controller for LB, it's  <i>purely</i> combinational. Everything it does is a transform on  <code>counter</code> and some outputs from Box 6, which we can now try to characterize.
</p>

 <p>
Box 6 also seems oddly simple in terms of inputs – it takes only the active tracker from Box 1 and the modulo sentinel from Box 4. The box contains 4 FFs, all of which are exported as outputs. There also seems to be some chaining, so if it looks like a counter…
</p>


 <div id="org99dfb8f" class="figure">
 <p> <img src="../images/gds_reverse/another_counter.png" alt="another_counter.png" class="eightywimg"></img></p>
</div>

 <p>
I guess it talks like a counter too! Box 6 consists of a 4-bit counter that counts the number of times the mod-11 counter has looped around while active. It increments on cycles where  <code>counter_hit_10</code> is set out of Box 4. Just like the original counter,  <code>epoch_counter</code> is also modulo-11. It's possible that there's some 11-by-11 grid abstraction at play, but I'm not too sure yet.
</p>

 <p>
Additionally, something we can see in the waveform and confirm analytically is that  <code>net285</code> is checking whether the epoch counter has hit 10.
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #595959;">// </span> <span style="color: #595959;">$6467 sky130_fd_sc_hd__nand3b_2
</span> <span style="color: #531ab6;">assign</span> net286 = ~(~(net101) & net88 & net87);  <span style="color: #595959;">// </span> <span style="color: #595959;">three flops!
</span>
 <span style="color: #595959;">// </span> <span style="color: #595959;">$6606 sky130_fd_sc_hd__nor2_2
</span> <span style="color: #531ab6;">assign</span> net285 = ~(net74 | net286);
</pre>
</div>

 <p>
So  <code>net285</code> is effectively an  <code>epoch_counter_hit_10</code> signal. We didn't rewrite Box 6 as much as some of the previous signals, but we've effectively characterized the outputs, and can consider this one solved. This signal is only sent to Box 1, so we can go back and try to reason about it again.
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #595959;">// </span> <span style="color: #595959;">$4180 sky130_fd_sc_hd__dfrtp_2
</span> <span style="color: #531ab6;">always_ff</span>  <span style="color: #005f5f;">@</span>( <span style="color: #531ab6;">posedge</span> clk  <span style="color: #005f5f;">or</span>  <span style="color: #531ab6;">negedge</span> rst_n)  <span style="color: #005f5f;">begin</span> : ff_u4180
     <span style="color: #531ab6;">if</span> (!rst_n)
        flag <= 1'b0;
     <span style="color: #531ab6;">else</span>
        flag <= net579;
 <span style="color: #005f5f;">end</span>

sky130_fd_sc_hd__a31o_2  <span style="color: #721045;">u4640</span> (
    . <span style="color: #721045;">X</span>(net579),
    . <span style="color: #721045;">A3</span>(active_flagn),
    . <span style="color: #721045;">A2</span>(epoch_counter_hit_10),
    . <span style="color: #721045;">A1</span>(counter_hit_10),
    . <span style="color: #721045;">B1</span>(flag)
);

 <span style="color: #595959;">// </span> <span style="color: #595959;">$4756 sky130_fd_sc_hd__and2b_2
</span> <span style="color: #531ab6;">assign</span> active_flagn = (~(flag) & enable);
</pre>
</div>

 <p>
Box 1 has now been mostly populated with legible signal names! It should now be clear that the flag is set after both counters have hit 10, meaning that 121 input elements were processed. This also better contextualizes one of the expressions we wanted to solve in Box 3!
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #595959;">// </span> <span style="color: #595959;">$433 sky130_fd_sc_hd__and4b_2
</span> <span style="color: #531ab6;">assign</span> net708 = (~(flag_r) & flag & box8_reduction & box2_reduction);
</pre>
</div>

 <p>
This signal is checking for the cycle after the 121st element is registered, and that the reduction checks from Box 8 and Box 2 are both fulfilled. Nice!
</p>
</div>
</div>
 <div id="outline-container-orgc2119be" class="outline-2">
 <h2 id="orgc2119be">Box 7's Last Output</h2>
 <div class="outline-text-2" id="text-orgc2119be">
 <p>
Since Box 3 is mostly solved, the main blocker on it (outside the weird condition) is actually just figuring out what the last output out of Box 7 was. After some staring at the verilog, I realized that  <code>{net310, net329}</code> formed a saturating counter of the number of high inputs collected over a cycle of  <code>counter</code>.
</p>


 <div id="orgf2fdafa" class="figure">
 <p> <img src="../images/gds_reverse/sat_counter.png" alt="sat_counter.png" class="eightywimg"></img></p>
</div>

 <p>
The output condition is the inversion of a sticky flop, and after some rearranging I was able to get a much nicer set of expressions for its assert condition.
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #531ab6;">assign</span> set_condition = (active_flagn & counter_hit_10 & net323);
 <span style="color: #531ab6;">assign</span> net323 = sat_counter[1] ? net325 : net315;
 <span style="color: #531ab6;">assign</span> net325 = (sat_counter[0] | I);
 <span style="color: #531ab6;">assign</span> net315 = ~(sat_counter[0] & I);
</pre>
</div>

 <p>
Keep in mind that this flop constitutes an error condition! Thus, an explicit rule we must follow is that  <i>each group of 11 bits has no more than 2 ones</i>. I was able to confirm this error condition by running some groups-of-11-bits through simulation and observing the assertion behavior. Together with the constraint from Box 5, this provides fairly strong row/column constraints.
</p>
</div>
</div>
 <div id="outline-container-org488209b" class="outline-2">
 <h2 id="org488209b">Box 10 Index Mapping (and Easter Egg 2)</h2>
 <div class="outline-text-2" id="text-org488209b">
 <p>
Box 10 ends up being a static transformation on the values of  <code>counter</code> and  <code>epoch_counter</code> – sadly I could not figure out by visual analysis what the meaning of the 4 outputs were in a waveform. That said, I did notice that the utilization pattern of the 4 signals in LB is fairly similar to the enumeration that was happening with the index-matching in upper behemoth!
</p>


 <div id="org9d857ed" class="figure">
 <p> <img src="../images/gds_reverse/weird_indices.png" alt="weird_indices.png" class="eightywimg"></img></p>
</div>

 <p>
Based on Box 2, the vector indices probably only go up to 10. So by process of elimination we can figure out which bit belongs in which bit position. We have the following constraints:
</p>

 <ul class="org-ul"> <li>The MSB will only be  <code>1</code> in cycles where there is at most another bit high (as 9/10 have two hot bits)</li>
 <li>The bit at position 2 is mutually exclusive with the bit we determine to be the MSB, as we max out at 10</li>
 <li>Guess-and-check for the ordering of the 2 LSBs (search space is down from 24 combinations to 2!)</li>
</ul> <p>
I asked AI to write a python script to convert the values of the relevant signals in a VCD dump into a CSV file so I could do this experiment. Writing a Python check to track maximum non-position one-bits on that data gives us the following:
</p>

 <div class="org-src-container">
 <pre class="src src-nil">net159: 2
net214: 1
net205: 2
net180: 2
</pre>
</div>

 <p>
Okay, so  <code>net214</code> is the MSB. Now for the mutex check, below is the output of an overlap accumulation (e.g when MSB is high, the corresponding index is also high).
</p>

 <div class="org-src-container">
 <pre class="src src-nil">net159, net214, net205, net180
[28, 55, 0, 6]
</pre>
</div>

 <p>
So the implication here is that  <code>net205</code> is most likely at position 2! At this point since there are only two possible bit-orderings, we can just plot an 11x11 grid with both possible orderings, and pick whichever makes more sense.
</p>


 <div id="orga6a0ad9" class="figure">
 <p> <img src="../images/gds_reverse/number_profiling.png" alt="number_profiling.png" class="eightywimg"></img></p>
</div>

 <p>
Jane Street Capital – very cool! Both mappings look about the same, so for no good reason I chose the alphanumerically ordered one.
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #531ab6;">assign</span> magic_index = {net214, net205, net180, net159};
</pre>
</div>

 <p>
Note that under both schemes, we see that the assembled numbers encompass the range 0-10, meaning our index range assumptions for Box 8 should hold.
</p>
</div>
</div>
 <div id="outline-container-org591cde2" class="outline-2">
 <h2 id="org591cde2">Attacking the Lower Behemoth</h2>
 <div class="outline-text-2" id="text-org591cde2">
 <p>
Based on the reduction and how upper behemoth shook out, it's likely that each index has  <i>independent</i> tracking logic, with state updates not crossing across indices. Thus if we can reason about the constraints tracked set in  <i>one</i> state FF, we should be able to generalize it to the other ones.
</p>

 <p>
I picked an arbitrary select signal, and grouped together all its downstream gates into one region. I then did some mild rewriting, and stopped once I hit this point:
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #595959;">// </span> <span style="color: #595959;">$2563 sky130_fd_sc_hd__and4bb_2
</span> <span style="color: #595959;">// </span> <span style="color: #595959;">select signal
</span> <span style="color: #531ab6;">assign</span> net399 = (~(magic_index[0]) & ~(magic_index[2]) &
                   magic_index[3] & magic_index[1]);

 <span style="color: #595959;">// </span> <span style="color: #595959;">$2285 sky130_fd_sc_hd__dfrtp_2
</span> <span style="color: #531ab6;">always_ff</span>  <span style="color: #005f5f;">@</span>( <span style="color: #531ab6;">posedge</span> clk  <span style="color: #005f5f;">or</span>  <span style="color: #531ab6;">negedge</span> rst_n)  <span style="color: #005f5f;">begin</span> : ff_u2285
     <span style="color: #531ab6;">if</span> (!rst_n)
        net412 <= 1'b0;
     <span style="color: #531ab6;">else</span>
        net412 <= net412 | (active_cond & net408);
 <span style="color: #005f5f;">end</span>

 <span style="color: #595959;">// </span> <span style="color: #595959;">$2572 sky130_fd_sc_hd__nand2b_2
</span> <span style="color: #531ab6;">assign</span> net418 = ~(~(net412) & net425);

 <span style="color: #005f5f;">logic</span>  <span style="color: #005e8b;">active_cond</span>;
 <span style="color: #531ab6;">assign</span> active_cond = I & active_flagn & net399;

 <span style="color: #595959;">// </span> <span style="color: #595959;">$2603 sky130_fd_sc_hd__nand4_2
</span> <span style="color: #531ab6;">assign</span> net425 = ~(active_cond & net408);

 <span style="color: #595959;">// </span> <span style="color: #595959;">$2561 sky130_fd_sc_hd__dfrtp_2
</span> <span style="color: #531ab6;">always_ff</span>  <span style="color: #005f5f;">@</span>( <span style="color: #531ab6;">posedge</span> clk  <span style="color: #005f5f;">or</span>  <span style="color: #531ab6;">negedge</span> rst_n)  <span style="color: #005f5f;">begin</span> : ff_u2561
     <span style="color: #531ab6;">if</span> (!rst_n)
        net408 <= 1'b0;
     <span style="color: #531ab6;">else</span>
        net408 <= (net412 | net425) & (active_cond | net408);
 <span style="color: #005f5f;">end</span>
</pre>
</div>

 <p>
This looks remarkably similar to the saturating counter we saw in Box 2! However instead of incrementing based on position in the group of 11, the position is based on the stencil that we found earlier. I generated some test stimulus that placed 1s only when  <code>magic_index</code> was set to 10, and was able to verify the sat counter behavior in simulation.
</p>


 <div id="orgaddbebf" class="figure">
 <p> <img src="../images/gds_reverse/another_sat_counter.png" alt="another_sat_counter.png" class="eightywimg"></img></p>
</div>

 <p>
Now that we have the state machine behavior, we just need to figure out what the output behavior is from these FFs. The condition used this time is a little different than what was done in upper behemoth.
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #531ab6;">assign</span> net118 = (~(net408) & net412);
</pre>
</div>

 <p>
So it seems like the 11 outputs of Box 8 are tracking whether specifically two indices per "magic index" are set to 1. We've successfully characterized Box 8, and with significantly less rewriting! We should now be able to return to Box 9 to figure out how the reduction pattern works.
</p>
</div>
</div>
 <div id="outline-container-orgaa5ec1f" class="outline-2">
 <h2 id="orgaa5ec1f">Returning to Box 9</h2>
 <div class="outline-text-2" id="text-orgaa5ec1f">
 <p>
We should first take another look at the reduction we pulled out earlier.
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #595959;">// </span> <span style="color: #595959;">$6768 sky130_fd_sc_hd__and3_2
</span> <span style="color: #531ab6;">assign</span> box8_reduction = ((net60 & net61 & net62 & net71) &
                (net82 & net96 & net97 & net98) &
                (net77 & net118 & net226));
</pre>
</div>

 <p>
It's a direct pass-in of each of the outputs from Box 8, so we don't need to do much more characterization on this path. The only loose end in the Box 8 chain is that of  <code>net156</code>, Box 9's other output to Box 3 (the success generator)
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #595959;">// </span> <span style="color: #595959;">$6297 sky130_fd_sc_hd__and4_2
</span> <span style="color: #531ab6;">assign</span> net156 = (net145 & net146 & net130 & net154);
</pre>
</div>

 <p>
This block has 8 registers in total, and they all seem to eventually funnel into this net. The inputs from Box 8 are only used for the reduction, and ignored in the rest of the module. So seems like that part of the equation has been nicely wrapped up in a bow.
</p>

 <p>
The remaining inputs are just whether the module is active or not and the input… maybe there's another counter? To test, we can just spam 1s into the module and see what happens to the registers.
</p>


 <div id="orged6c548" class="figure">
 <p> <img src="../images/gds_reverse/adder.png" alt="adder.png" class="eightywimg"></img></p>
</div>

 <p>
That instinct seems to have paid off! So the final output from this box is checking that the overall number of 1s in the input string has hit some target. We can rename signals to make the expressions more readable then unroll them. The waveform shows that the condition is looking for the counter to hit 22 (so solution has 22 nonzeros), but we should confirm this analytically as well.
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #595959;">// </span> <span style="color: #595959;">$6297 sky130_fd_sc_hd__and4_2
</span> <span style="color: #531ab6;">assign</span> net156 = (bit_counter[1] & bit_counter[2] & bit_counter[4] & net154);

 <span style="color: #595959;">// </span> <span style="color: #595959;">$5612 sky130_fd_sc_hd__nor3_2
</span> <span style="color: #531ab6;">assign</span> net154 = ~(bit_counter[5] | bit_counter[6] | net223);

 <span style="color: #595959;">// </span> <span style="color: #595959;">$5608 sky130_fd_sc_hd__or3_2
</span> <span style="color: #531ab6;">assign</span> net223 = (bit_counter[0] | bit_counter[3] | bit_counter[7]);
</pre>
</div>

 <p>
Solved by  <code>8'b00010110 = 8'd22</code>. Very cool!
</p>
</div>
</div>
 <div id="outline-container-orgeca3f3f" class="outline-2">
 <h2 id="orgeca3f3f">Revisiting Box 5's Odd Constraint</h2>
 <div class="outline-text-2" id="text-orgeca3f3f">
 <p>
The only win condition we haven't actually semantically deciphered yet is  <code>net421</code> in Box 5. However, knowing that the solution is a 2D grid helps make sense of the weird equations from before.
</p>

 <div class="org-src-container">
 <pre class="src src-verilog"> <span style="color: #531ab6;">assign</span> net423 = (|counter) & (shift_reg[11] | shift_reg[0]);
                              <span style="color: #595959;">// </span> <span style="color: #595959;">^ purple
</span> <span style="color: #531ab6;">assign</span> net442 = net423 | shift_reg[10] | (counter != 4'd10 & shift_reg[9]);
                          <span style="color: #595959;">// </span> <span style="color: #595959;">^ red        // ^ yellow</span>
</pre>
</div>

 <p>
Since the comparison only occurs when  <code>I</code> is high, we can consider this to be restrictions on where a 1 is allowed to be placed relative to other elements that came before it and in the previous row. First we should take a look at the "banned" elements when counter is nonzero. I'll lump  <code>shift_reg[9]</code> into the graphic for visualization's sake. The black element is the current position of  <code>I</code> in the grid, while the gray elements represent the window in the shift register. Illegal elements are color-coded as described in the block above.
</p>


 <div id="org3f9d344" class="figure">
 <p> <img src="../images/gds_reverse/restrictions.png" alt="restrictions.png" class="halfwimg"></img></p>
</div>

 <p>
So all in all those constraints effectively create an adjacency rule. The nonzero counter bound is to make sure that elements that clip off to the left don't accidentally get flagged, and the restriction on  <code>shift_reg[9]</code> is intended to prevent clipping off the right side.
</p>
</div>
</div>
 <div id="outline-container-orga898031" class="outline-2">
 <h2 id="orga898031">Generating a Solution</h2>
 <div class="outline-text-2" id="text-orga898031">
 <p>
So at this point I'm not totally sure exactly what the functional purpose of this chip is supposed to be architecturally speaking, but we can make some clear claims about what it's looking for and how we can provide that.
</p>

 <ul class="org-ul"> <li>The solution is a stream of 121 bits, containing 22 ones</li>
 <li>Each column needs to have two ones</li>
 <li>Each row needs to have two ones</li>
 <li>There is a stencil pattern requiring that each of its buckets is given two ones</li>
 <li>A "pixel" or element cannot be directly adjacent to another in the 2D plane</li>
</ul> <p>
The stencil pattern is probably going to be the weirdest part of the output generation. So first things first, I want to generate a stimulus that will fulfill one of the behemoth's conditions – the column one is probably easiest. I wrote out a fairly simple map on paper of a pattern that has 2 nonzeros per column and 2 nonzeros per row.
</p>


 <div id="org0ecdf40" class="figure">
 <p> <img src="../images/gds_reverse/test_plot.png" alt="test_plot.png" class="halfwimg"></img></p>
</div>

 <p>
At this point we also know enough about the chip that we can start using a monolithic netlist of the entire design rather than submodule simulation. The simulation stack is the same, but the top-level harness changes to instantiate the monolithic netlist instead, including the output generator. A small python shim is used to serialize the stimulus array into a vector which is passed into Verilator via a CLI argument.
</p>

 <p>
When run through Verilator, we see that the condition associated with Box 5 does go high – so at least some of our assumptions are correct! 
</p>


 <div id="orgc26b409" class="figure">
 <p> <img src="../images/gds_reverse/flat_testcase.png" alt="flat_testcase.png" class="eightywimg"></img></p>
</div>

 <p>
At this point we can try to construct a more complete solution that fulfills all the constraints. I decided to go with a DFS state space solver, where various board configurations were considered state. Not the most elegant solution, but it works well enough. I did attempt a greedy approach at first, but couldn't figure out a good heuristic, and ended up with a fair number of local minima issues.
</p>

 <p>
This spits out the following solution, annotated with stencil group numbers for clarity:
</p>


 <div id="org465ea21" class="figure">
 <p> <img src="../images/gds_reverse/solution.png" alt="solution.png" class="halfwimg"></img></p>
</div>

 <p>
Lo and behold, it simulates correctly on the full design!!!
</p>


 <div id="orga1b8303" class="figure">
 <p> <img src="../images/gds_reverse/success.png" alt="success.png" class="eightywimg"></img></p>
</div>

 <div class="org-center">
 <p>
 <code>(* TWO STARS *)</code>
</p>
</div>
</div>
</div>
 <div id="outline-container-orga71b80d" class="outline-2">
 <h2 id="orga71b80d">Time Tracking</h2>
 <div class="outline-text-2" id="text-orga71b80d">
 <ul class="org-ul"> <li> <b>Start</b>: 5:30PM, 08/06</li>
 <li> <b>Netlist Extraction</b>: 10:30PM, 08/06</li>
 <li> <b>Verilog Emission</b>: 11:16PM, 08/06</li>
 <li> <b>5/10 Blocks Solved</b>: 6AM, 08/07</li>
 <li> <b>Done with Reverse Engineering</b>: 4PM, 08/07</li>
 <li> <b>State Space Solver/Full Solution</b>: 5:10PM, 08/07</li>
</ul> <p>
End-to-end, about 24 hours.
</p>
</div>
</div>
 <div id="outline-container-orgfa3bdf7" class="outline-2">
 <h2 id="orgfa3bdf7">Hindsight is 20/20</h2>
 <div class="outline-text-2" id="text-orgfa3bdf7">
 <p>
I was hoping that keeping the gates intact would help with parsability, but I do think that some genuine logical optimization or flattening in the initial Verilog emission phase would have helped speed up the analysis and rewriting portions of the reverse engineering.
</p>

 <p>
It's probably apparent that I realized this as the challenge went on, but at some point I started to rely on simulation a lot more for reverse engineering, and that ended up being the right move. The 8-bit counter, for example, is probably not something that I would have been able to hand-flatten or identify by observation. Breaking down the GDS into submodules was probably the right move though, as it made looking at all of the data easier. Fuzzing the submodules or giving them random data to pull out "connected" flip-flops in simulation rather than doing it analytically likely would have saved me a lot of time. I'm not sure it would have contributed to a full semantic reverse engineering as quickly, but it definitely would have produced a viable output faster.
</p>
</div>
</div>
 <div id="outline-container-orgc565ef5" class="outline-2">
 <h2 id="orgc565ef5">Acknowledgements</h2>
 <div class="outline-text-2" id="text-orgc565ef5">
 <p>
Thank you to Tianchen "Jerry" Wang for a number of good suggestions when first trying to figure out how to recover Verilog from the provided GDS. Additionally, a huge thank you to the Jane Street team for putting this challenge together! I had an amazing time solving it. Good puzzles are hard to come by, and this is absolutely one of them.
</p>

 <p>
And thank you, the reader, if you've made it this far! Enjoy a  <a href="../images/gds_reverse/emacs.png">meme</a>, free of charge.
</p>
</div>
</div>
</div>]]></description>
  <link>https://pradyun.net/blog/reverse_engineering.html</link>
  <guid isPermaLink="false">https://pradyun.net/blog/reverse_engineering.html</guid>
  <pubDate>Fri, 04 Sep 2026 00:00:00 +0000</pubDate>
</item>
<item>
  <title>I Like Typos</title>
  <description><![CDATA[<div id="content" class="content">

 <p>
Something I enjoy doing, for both time-pass and "broadening my horizons" so to speak, is reading a variety of blog posts. I source a number of them from  <a href="https://lobste.rs">lobste.rs</a> and end up branching out by keeping a reading list of referred blog posts that also look interesting.
</p>

 <p>
Anyway. While catching up on a number of entries in my reading list, particularly those that were published in 2025 or earlier, I found quite a few typos in them. Nothing flabbergasting, but definitely not something you'd expect in 2026 and the age of LLMs. 
</p>

 <p>
I'm not sure when, but at some point I started actually  <i>enjoying</i> reading typos and grammatical errors in blog posts and other discourse. It's nice to know that someone on the other side of the screen spent the time to write about a topic that seems at least plausibly interesting, and cared enough about the details in it (examples, images, etc.) to make sure they're there. Output production is far cheaper in effort now that  <a href="https://johnstone.substack.com/p/friction-was-the-feature">friction is less of a feature</a>, so seeing the human touch here and there helps me feel like the work before me isn't some vibe-[verb]'d copy-paste. AI is indubitably an important tool, but if I wanted its thoughts on topic \(X\), I'd prompt it myself!
</p>

 <p>
Perhaps this is also some underlying explanation on my own tendency to submit school assignments with typos in them? Though for completeness sake, I do encourage the reader (including myself!) to thoroughloy proofread any text they submit in a professional context.
</p>
</div>]]></description>
  <link>https://pradyun.net/notes/typos.html</link>
  <guid isPermaLink="false">https://pradyun.net/notes/typos.html</guid>
  <pubDate>Thu, 06 Aug 2026 00:00:00 +0000</pubDate>
</item>
<item>
  <title>Gallivanting Around With a Rangefinder</title>
  <description><![CDATA[<div id="content" class="content">

 <blockquote>
 <p>
 <b>Note</b>: You can fast-forward to the pictures  <a href="#org8986a7f">here</a>.
</p>
</blockquote>

 <p>
Earlier this month I went camping in the  <a href="https://en.wikipedia.org/wiki/North_Cascades_National_Park">North Cascades</a> with my undergraduate roommates. Extremely, extremely happy with how that trip turned out – basically ~3 days of not worrying about research and resetting my brain, and it's been fairly positive for my productivity and mental health since I've gotten back.
</p>

 <p>
We visited a camera store to get a tripod as part of the preparations for that trip. Lo and behold, I came across a used Fujifilm X-Pro 3 that cost an arm instead of an arm  <i>and</i> a leg. I'd been eyeing the body as an upgrade from my X-T20 for well over a year at this point, and this felt like the exact kind of trip I'd wanted the camera for. So caution went to the wind, and I walked out with a 15$ tripod and a new camera!
</p>

 <p>
Call it shiny object syndrome, but I've been extremely happy with the body since I've gotten it. I know that having to flip out the back screen is a source of annoyance for many people, but I've honestly enjoyed it? I had a phase in junior/senior year where I enjoyed shooting film on a Minolta XG-1, and really fell in love with the idea of "shooting and moving on" without the option of "chimping" shots through the back screen. 
</p>

 <p>
Sadly, the main drawbacks of film for me were the things most people  <i>love</i> about it (development time, inflexibility w.r.t ISO and white balance). The fact that you can't see the screen of the X-Pro 3 by default pretty strongly deters chimping, and while you can absolutely achieve the same effect with other cameras through discipline and willpower, it's definitely increased the immersion I feel when shooting. I do flip out the screen from time to time to play with film simulations and white balance, but I've been enjoying the practice of coming home with very little idea of how my shots turned out and going through it on my computer as a wind-down routine.
</p>

 <p>
The hybrid OVF/EVF rangefinder is also  <i>killer</i> – I can see why people pay so much for it on the X100VI! Whether I think the price is proportional to the value on that camera is a different question (I do not think so), but it's nice to be able to both preview what my shot will look like while having the option to see what "slice" of my FoV I'm capturing. I have a fairly bad habit of getting very sucked into the EVF and missing the forest for the trees, so swapping into the OVF when first composing a shot has helped. There's been more than a couple of times that I've realized that I want to clip something off that was at the fringe of the frame, or that there's something slightly out-of-frame that I'd prefer to re-compose with. 
</p>

 <p>
I do know that some people have issues with the rangefinder feeling a little odd ergonomically, but I've actually preferred it to the X-T20, as my arms feel a little less crammed into my chest. Though that is also probably partially due to the camera being wider. That does come with some additional heft (plus the fact that the construction is now titanium instead of plastic), but it hasn't been prohibitively heavy. I made it through   <a href="https://www.alltrails.com/trail/us/washington/maple-pass-trail">a fairly strenuous hike</a> (by my standards, at least) while carrying this camera and a spare lens, and have also been fairly comfortable walking around campus with it slung around my neck.
</p>

 <p>
So yeah, overall, very  <i>very</i> happy with this camera. I've been making more of an active effort to get out and go on photo-walks while campus is deserted (and social anxiety is slightly lower), and it's been an absolute joy to shoot on this thing. 
</p>

 <p>
For the record – do I think that I  <i>wouldn't</i> have enjoyed shooting on my old X-T20? Absolutely not. I do think that there are some shots where it would have been harder to shoot on it by virtue of the fact that I might have gotten too absorbed into the EVF, but that's not really an indictment of the camera. Photography in general is enjoyable more because of the creative process than the gear, and the X-T20 doesn't really limit that process in any meaningful way. Most modern cameras (post-2012, I want to say?) are capable of getting out shots with sufficient pixel density and color accuracy, so you might as well get whatever the cheapest camera is that you enjoy shooting with. But there's also something to be said for having a camera that makes you  <i>want</i> to get up and take pictures with it, and for a variety of reasons the X-Pro 3 evokes a fairly strong feeling of that from me.
</p>

 <p>
Anyway, I also wanted to share some highlights from the camera roll from our trip (the main reason this is categorized Long and not Short). Enjoy my show-and-tell into the internet void! Most shots below were taken on my beloved XF35mm F1.4, with some additional landscape shots taken on the Sigma 18-50mm F2.8. Everything is SOOC, so a crop-n-tilt and color adjustments may be due in the future.
</p>
 <div id="outline-container-org8986a7f" class="outline-2">
 <h2 id="org8986a7f">North Cascades Pictures</h2>
 <div class="outline-text-2" id="text-org8986a7f">
 <p>
I was the designated cameraman <sup>™</sup> for the roommates' Seattle trip (largely through self-imposition, for the record). We went camping for three days – the first was spent packing/road-tripping to the campsite, the second was spent hiking, and the third was spent kayaking. I mostly took pictures on the second day because I was too scared to take a new camera into the middle of a lake, and the pool of water in my kayak asserted that to be a good decision. I did get some fun shots on our way into the national park though.
</p>


 <div id="orgee295e2" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/XSB79421-1920.webp" alt="XSB79421-1920.webp" class="halfwimg"></img></p>
</div>

 <p>
Amateur tip: sitting shotgun and setting shutter speed to 1/2000 or higher can get you some really nice pictures on scenic road trips, clean windshield permitting.
</p>


 <div id="org4cf1e2c" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/XSB79448-1920.webp" alt="XSB79448-1920.webp" class="halfwimg"></img></p>
</div>

 <p>
I was pretty shocked when we hit our first viewpoint on the drive in. Apparently water can turn this tealish-green color because of glacial sediment – the more you know!
</p>


 <div id="orgcbac541" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/XSB79455-1920.webp" alt="XSB79455-1920.webp" class="eightywimg"></img></p>
</div>

 <p>
This was also the closest I'd been to a snow-capped mountain in a long time, so I spent a solid amount of time staring up at those.
</p>

 <p>
The main event was a loop of the  <a href="https://www.alltrails.com/trail/us/washington/maple-pass-trail">Maple Pass trail</a>. The route is absolutely beautiful, albeit a bit steep for sedentary grad students (I wonder who that could be?). I started feeling a solid amount of struggle about a third in, but the first lookout was a much-needed shot in the arm.
</p>


 <div id="org9ccddc7" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/XSB79490-1920.webp" alt="XSB79490-1920.webp" class="halfwimg"></img></p>
</div>

 <p>
This picture is somewhat emblematic of some of the struggles I had taking pictures throughout the hike. I wanted to get as much of the landscape as possible, which is inherently a very  <i>deep</i> thing to shoot, so I resorted to vertical shots a lot. At the same time, properly exposing the snow, greenery, and rock faces all at once was a tall task, and not one I'd read the manual enough at the time to tackle. So there are quite a few ethereally blown-out snowcaps and clouds.
</p>

 <p>
I did, however, get this shot of my friends taking a break which I thought was pretty cool. You can once again see that exposure was a challenge.
</p>


 <div id="org504436a" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/XSB79492-1920.webp" alt="XSB79492-1920.webp" class="eightywimg"></img></p>
</div>

 <p>
It's not super clear from the pictures because I wasn't taking a lot of them initially and didn't want to hold up my friends, but the first part of our hike was through a really twisty forest section. At some point we broke out of the forest and entered a section I lovingly referred to as "Lord of the Rings" because of the way the greenery and lighting looked. At this point I also received reassurance that it was okay if I hung back a little and took my time taking pictures, so I got some decent shots of the terrain while we hiked.
</p>


 <div id="org0d60e22" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/XSB79510-1920.webp" alt="XSB79510-1920.webp" class="eightywimg"></img></p>
</div>


 <div id="org8f20bc2" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/XSB79520-1920.webp" alt="XSB79520-1920.webp" class="eightywimg"></img></p>
</div>

 <p>
A little farther into lord-of-the-rings, and we started to see some pretty huge rock faces.
</p>


 <div id="org22cb5b2" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/XSB79538-1920.webp" alt="XSB79538-1920.webp" class="eightywimg"></img></p>
</div>

 <p>
We didn't realize it at the time, but we hit the best lookout/vantage point a little bit after that. It's a little hard to recollect exactly how I felt seeing this with my own two eyes, but quite a few "holy shits" and "oh my gods" were muttered while sitting on a rock.
</p>


 <div id="org22a4b2b" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/XSB79593-1920.webp" alt="XSB79593-1920.webp" class="eightywimg"></img></p>
</div>


 <div id="org05e4088" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/XSB79598-1920.webp" alt="XSB79598-1920.webp" class="eightywimg"></img></p>
</div>

 <p>
This was also about the point that we realized that we still had about half the hike to go (a little more upwards then the entire downclimb), so we all picked up the pace a little at that point. As a result, the number of pictures taken declined rather rapidly, but there are a couple shots that I'm glad I took during the hurry.
</p>


 <div id="org434a027" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/XSB79680-1920.webp" alt="XSB79680-1920.webp" class="halfwimg"></img></p>
</div>

 <p>
As an aside, we'd mostly been hiking through in tshirts and pants by this point. So staring at what seemed to be a scene straight out of an Indian movie's Europe shooting while wearing my standard work attire was pretty crazy.
</p>


 <div id="orgff744b6" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/XSB79692-1920.webp" alt="XSB79692-1920.webp" class="halfwimg"></img></p>
</div>

 <p>
This shot has a snakey leading line going through it that I liked. Plus my friend using his hiking stick as a golf club was kinda funny.
</p>

 <p>
And arguably my favorite shot from this trip:
</p>


 <div id="org81dcf40" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/XSB79695-1920.webp" alt="XSB79695-1920.webp" class="eightywimg"></img></p>
</div>

 <p>
In hindsight I might have cropped off a little more of the sky, but it gives the people some breathing room, which I kind of like. Coincidentally this was also the  <i>last</i> decent shot I took of our hike, since the footing was quite unstable during the downclimb and we were  <i>really</i> trying to beat the light at that point. Case in point, here's a weirdly exposed shot of the sunset light before we'd even made it back into the forest.
</p>


 <div id="org4dc5f83" class="figure">
 <p> <img src="https://pub-b14bb3b617884985afa3a39f74640d0f.r2.dev/images/XSB79710-1920.webp" alt="XSB79710-1920.webp" class="halfwimg"></img></p>
</div>
</div>
</div>
 <div id="outline-container-orgfe31884" class="outline-2">
 <h2 id="orgfe31884">Closing Thoughts</h2>
 <div class="outline-text-2" id="text-orgfe31884">
 <p>
If it wasn't already apparent, we made it back before dark, and no major issues were had getting back to our campsite. The kayaking trip the next day was just as enjoyable, if a little less picturesque, though there are fewer visual records of that excursion.
</p>

 <p>
If I were to summarize this post so far:
</p>

 <blockquote>
 <p>
 <b>TL;DR:</b> X-Pro 3 good, did not know how to use it fully during the trip so pictures were less than ideal, North Cascades are absolutely beautiful.
</p>
</blockquote>

 <p>
I'd actually bought the camera right before we started driving, so I didn't have a ton of time to figure out the features of it that were different than my X-T20 and generally didn't have a great feel for how to best take advantage of it. The weekend after I got home, I finally sat down and read through the entire manual, configuring all the settings in a way that felt intuitive to me. This helped feel more comfortable when I went out on photowalks, and I've been taking pictures around campus that I'm much more satisfied with from a quality perspective.
</p>

 <p>
This post was initially intended to be a super-cut of all the pictures I'd enjoyed taking this month, including the improved ones from when I got back to campus, but the hike section ended up being way longer than I'd initially anticipated! Plus it's kinda fun recounting the experiences and thoughts that came along with the shots.
</p>

 <p>
I'm hoping to make a second post sometime in the next few weeks about the pictures I've taken since coming back to campus, since I had a bit more creative freedom when taking those to play with framing and whatnot.
</p>

 <p>
In the meantime, I hope this post was some mixture of informative and entertaining. It's a beautiful world out there, and we ought to take more pictures of it!
</p>
</div>
</div>
</div>]]></description>
  <link>https://pradyun.net/blog/new_camera.html</link>
  <guid isPermaLink="false">https://pradyun.net/blog/new_camera.html</guid>
  <pubDate>Tue, 28 Jul 2026 00:00:00 +0000</pubDate>
</item>
<item>
  <title>Studying Linux Schedulers, and Why Metrics Matter</title>
  <description><![CDATA[<div id="content" class="content">

 <p>
Last semester, I took  <a href="https://courses.grainger.illinois.edu/cs533/sp2026/">Parallel Computer Architectures</a> at UIUC. For a term project, I (with the help of  <a href="https://screamingpigeon.net/">smart</a>  <a href="https://atmospheal.com/">friends</a>) set out to investigate exactly how much scheduling decisions mattered in the Linux Scheduler, specifically as it related to picking between different cores available in a CPU (or multiple sockets). 
</p>
 <div id="outline-container-org06e6d3e" class="outline-2">
 <h2 id="org06e6d3e">Background</h2>
 <div class="outline-text-2" id="text-org06e6d3e">
 <p>
The classical advice goes that you prefer to keep processes on the same core for as long as possible (without inducing unfairness) so that you can keep their data warm in the caches, and Linux's EEVDF scheduler does a pretty good job of that. What  <i>isn't</i> taken into account is making sure processes are arranged across the CPU(s) in such a way that you minimize the number of levels in the cache hierarchy you have to traverse to service accesses to shared memory.
</p>

 <p>
As an illustrative example – consider a dual-socket Xeon system (which was our testing configuration). If a process makes an access to shared memory, let's be pessimistic and suppose that  <i>another</i> process has recently accessed this memory as well, has performed a write, and that the dirty data is still in the cache hierarchy. What are the possible coherence actions that could occur? It depends on where the process was scheduled:
</p>

 <ol class="org-ol"> <li>If the process was running on the  <i>same</i> core (in a separate scheduling quantum), nothing! We have the data! Yippee!  We will find it somewhere in our L1/L2 private cache hierarchy, and require no coherence actions.</li>
 <li>If the process ran on  <i>another</i> core, then on modern Xeon systems there are two ways this can pan out.
 <ol class="org-ol"> <li>The process was scheduled onto another core in  <i>our</i> socket. This means that we will force a write-back from the other core's private cache hierarchy into the fully-shared L3, and either pull data from DRAM or directly from the other core's private cache hierarchy via the coherency fabric.</li>
 <li>The process was scheduled on the  <i>other</i> socket. This is the worst-case, as the other socket's L3 will need to transfer data across the chipset (or we go to DRAM), at which point we can pull the data all the way through our own cache hierarchy to use it… yikes!</li>
</ol></li>
</ol> <p>
As we can see, there is a fairly asymmetric penalty here to service a cache miss when dealing with multi-threaded programs. So really, our goal is to minimize the number of times we have to deal with case 2.2. If we were only read-sharing across cores, everything would be hunky-dory since data is much more likely to stay cache-resident. It's really this pessimistic write-sharing behavior that starts to be annoying. Ideally, we generally prefer to trigger case 2.1 in this situation, since it balances cache miss penalties with scheduling flexibility and maximizing available compute. 
</p>

 <p>
The granularity of this decision tree will inevitably change depending on the CPU/configuration we are using. Zen 1 and 2, for example, would have a third branch here, as some SKUs contained separated L3 caches per CCX, so you could get away with faster access times if you managed to schedule your data-sharing processes on the same CCX. 
</p>

 <p>
So with some fairly strict caveats – no sub-NUMA clustering, ignoring memory residency, etc. – we set out to answer three questions:
</p>
 <ol class="org-ol"> <li>How much of a benefit is there from successfully scheduling multi-threaded processes fully within one LLC domain?</li>
 <li>Do current schedulers do a good job of ensuring that this happens?</li>
 <li>How can they be improved to actually make this happen?</li>
</ol> <p>
Our study mostly focused on points 1 and 2, with 3 being a "we hope this can happen", until we realized that  <a href="https://lore.kernel.org/lkml/cover.1775065312.git.tim.c.chen@linux.intel.com/">CAS</a> was starting to address point 3. So at this point we thought, "what if we just test CAS and EEVDF and find the gaps?". Okay, fair enough. But then we realized that we couldn't actually do that on shared lab resources and instead pivoted to profiling  <a href="https://lpc.events/event/19/contributions/2099/attachments/1875/4020/lpc-2025-lavd-meta.pdf">LAVD</a>. It obviously exhibits very different behaviors and priorities, but the hope was that the  <i>second-order</i> effects of LAVD would emulate that of CAS. I'm not totally sure how accurate that hypothesis ended up being, but EOTD we needed  <i>some</i> testing methodology so this would have to do.
</p>

 <p>
There's a lot more background about the internals of these schedulers about how various Linux schedulers work and our evaluation methods, but I'll fast forward to the mishaps in the next section for (relative) brevity. More fine-grained details can be found in our final report, either in  <a href="../static/scheduler_profiling.pdf">PDF</a> or  <a href="./scheduler_profiling.html">web</a> format.
</p>
</div>
</div>
 <div id="outline-container-org176f2c7" class="outline-2">
 <h2 id="org176f2c7">A Cascade of Mistakes</h2>
 <div class="outline-text-2" id="text-org176f2c7">
 <p>
So at this point, our study is clear! We want to characterize how performance is impacted by scheduling threads auto-magically with the default Linux scheduler, with a "cache-optimized" scheduler, and with manual restriction of thread positions. 
</p>

 <p>
As many school projects go, we started a little close to the deadline, and followed a fairly linear train of thought to start testing right away. Our experimental setup was to track coherence actions (via read-for-ownership requests sent across the socket) and to track latency figures with the various configurations, and try to drill down exactly what aspect of runtime changing had contributed to performance increases/decreases. Since our benchmarks were all run with a thread count at/under the capacity of a single socket, our proxy for an "idealized" placement across cores was to simply restrict benchmarks to a single socket via  <code>numactl</code> as a control.
</p>

 <p>
This led to one of the most striking results of our entire study: both the standard Linux scheduler and specialized LAVD scheduler perform approximately the same on our benchmarks, but using  <code>numactl</code> to restrict thread scheduling to a single socket improved runtime by as much as 3x!
</p>


 <div id="org002b721" class="figure">
 <p> <img src="../images/scheduler/runtime_speedup_vs_eevdf_2s.png" alt="runtime_speedup_vs_eevdf_2s.png" width="80%"></img></p>
 <p> <span class="figure-number">Figure 1: </span>Normalized Speedup of Benchmark Runtime</p>
</div>

 <p>
So I guess if any of you are currently using a multi-socketed machine to run workloads in an under-subscribed fashion, I would recommend at least trying to use  <code>numactl</code> to pin workloads to a single LLC domain or a set of cores – you can gain  <i>extreme</i> speedup in multi-threaded shared-memory programs. This is mostly due to the fact that the Linux load balancer will try to ensure that all sockets are approximately equally loaded as thread count permits, even if that actively disadvantages the host program.
</p>

 <p>
The salient exception to this observation was the  <code>mediawiki</code> benchmark, which we sourced from DCPerf – how had the runtime barely moved at all? Maybe it was the fact that cache hitrates hadn't really improved? 
</p>

 <p>
Okay, we can check whether that's true. Let's take a look at if the number of read-for-ownership misses (e.g L3 wants to write to something but it doesn't have the data, so it asks the other core to let it own data) has changed. When we have strong write sharing, we expect that number to go up since shared cachelines should bounce between the two sockets' L3 caches.
</p>


 <div id="org9fbe128" class="figure">
 <p> <img src="../images/scheduler/l3_rfo_mpki_newdata.png" alt="l3_rfo_mpki_newdata.png" width="80%"></img></p>
 <p> <span class="figure-number">Figure 2: </span>L3 Cache Read-for-Ownership Misses (per Kilo-Instruction)</p>
</div>

 <p>
Whelp. Now we have  <i>two</i> mysteries.
</p>

 <ol class="org-ol"> <li>How has  <code>mediawiki</code> not sped up at all, even with an improvement in L3 RFOs?</li>
 <li>What the hell is going on with  <code>perlbench</code>? What is making it speed up so much?</li>
</ol> <p>
We didn't end up being able to answer either of these questions prior to the deadline unfortunately – in fact, we found this relationship the day our paper was due! So with a severe sleep deficit and copious amounts of caffeine in our bloodstreams, we wrote that we hadn't been able to pin down the issue in our final report, and continued slogging through more graphs and writing. We ended up finishing the report at exactly 11:45PM, scampered over to Siebel and slid the report under our professor's door as fast as possible. And I don't think any of us really gave it another thought after submission.
</p>

 <p>
Cut to a couple weeks after end-of-semester, and I was cleaning up the traces we'd used for this project. And for some reason I have since forgotten, I was curious what the MIPS was for each of these benchmarks.
</p>


 <div id="orgf196090" class="figure">
 <p> <img src="../images/scheduler/mips_newdata.png" alt="mips_newdata.png" width="80%"></img></p>
 <p> <span class="figure-number">Figure 3: </span>Throughput Measured as Millions-of-Instructions per Second (MIPS)</p>
</div>

 <p>
Well that makes… no sense. Throughput has gone up significantly but runtime hasn't changed?? What command did we use to run the benchmark?
</p>

 <div class="org-src-container">
 <pre class="src src-bash"> <span style="color: #8f0075;">cd</span> /home/pradyun/pg_work/dcperf/
sudo ./perf_collect_mw  <span style="color: #3548cf;">"$JOBNAME"</span> ./benchpress_cli.py run oss_performance_mediawiki_mlp  <span style="color: #3548cf;">\</span>
    -i  <span style="color: #3548cf;">'{"scale_out": 1, "client_threads": 32, "duration": "10m"}'</span> &
</pre>
</div>

 <p>
… Oh boy. Duration was fixed to 10 minutes. This directive was buried so deeply in our testing infrastructure, and reused  <i>so</i> many times over the course of this project that we'd completely forgotten about it.
</p>

 <p>
So in one shot, several mistakes have been made. Speedup was calculated with the assumption that instructions have been held constant, which was not the case for this benchmark. And not only have we accidentally reported another single-socket speedup as having been a phantom "no-change", we've also somehow  <i>masked the one datapoint that made LAVD look better</i>. For the latter bit, my theory is that the nature of  <code>mediawiki</code> suits the chain-of-tasks model that LAVD was designed for.
</p>

 <blockquote>
 <p>
 <i>Side Note</i>: LAVD was designed and optimized for the Steam Deck by Changwoo Min and the great folks over at  <a href="https://www.igalia.com/">Igalia</a>. He had a pretty great talk about LAVD at OSPM25 which you can find  <a href="https://www.youtube.com/watch?v=pHX-KgBCjwQ">here</a>, would recommend watching!
</p>
</blockquote>
</div>
</div>
 <div id="outline-container-orgeb9dbe3" class="outline-2">
 <h2 id="orgeb9dbe3">Conclusions</h2>
 <div class="outline-text-2" id="text-orgeb9dbe3">
 <p>
So that was… long-winded. I hope it was at the very least entertaining! Regardless, this is one of those experiences that I hope sticks with me. For one, I hope it teaches me to stop procrastinating schoolwork so much sometimes, but also that the choice of metrics can very easily disguise results as something they're not. That can both be in the negative direction (this study) but also the positive direction. Both of these directions can be pretty dangerous, especially in environments where you fix the benchmarks and tests early on and forget about them going forwards (e.g performance engineering CI pipelines). I guess the long and short of what I'm trying to say is this:
</p>

 <blockquote>
 <p>
Picking good metrics to communicate your results helps not only present findings better, but also lets your work be resilient to mistakes or oversights made in experimental design.
</p>
</blockquote>

 <p>
At a more meta-level, I feel kind of obligated to take more care with experimental methodology in future profiling studies. This was really the first time I'd profiled anything on a computer without pre-rolled tooling to do it (e.g NVIDIA's SoL tools), and it definitely showed in some of the rougher edges of our evaluation. But at the very least, I'm glad that this saga occurred within the confines of a school project rather than an actual research paper, and that I can carry the lessons here into future research.
</p>

 <p>
If you're interested in some of the finer-grain details of our evaluation methodology, more performance counters from our testing, or a fairly long expository section about how LAVD and EEVDF work in Linux, I'd recommend reading our  <a href="./scheduler_profiling.html">final report</a>. It's not the most well-refined study ever, but we all learned a lot from it!
</p>

 <blockquote>
 <p>
 <b>AI Disclosure</b>: This post was written by hand and then later proofread/fact-checked with the help of an LLM. I have been an abuser of  <code>--</code> for longer than I can remember, and I will continue to use it – unfortunately, it gets converted into an em-dash by my Org export engine! It's truly unfortunate that hyphenation has been broadly conflated with "AI slop", yet I will continue to use it at will.
</p>
</blockquote>
</div>
</div>
</div>]]></description>
  <link>https://pradyun.net/blog/metrics_matter.html</link>
  <guid isPermaLink="false">https://pradyun.net/blog/metrics_matter.html</guid>
  <pubDate>Sat, 18 Jul 2026 00:00:00 +0000</pubDate>
</item>
<item>
  <title>Use It or Lose It</title>
  <description><![CDATA[<div id="content" class="content">

 <p>
In Spring 2024, I took  <a href="https://courses.grainger.illinois.edu/ece513/sp2024/index.html">ECE 513</a>. To this day, I consider it the hardest class I've ever taken, and also the most rewarding in many ways. I'd always wanted to take a hard math class, and somewhat romanticized the notion of agonizing over  a difficult problem set. Rest assured, I no longer romanticize math classes as such, and am indebted to the (very) smart classmates that endured  <i>many</i> nights of me confusing myself. Though in retrospect, I did quite enjoy the puzzle nature of solving difficult problems, and hope to take another math class in grad school (most likely some form of abstract algebra).
</p>

 <p>
Despite the trials of ECE 513, I seem to have utterly forgotten most of the formulas and theorems we learned in the class a mere 2 years later! Reading my old homeworks, I can  <i>vaguely</i> understand the language and concepts at play, but if you asked me to derive the solutions again, I probably wouldn't have the foggiest idea how to do so! Some high-level concepts and a general familiarity with linear algebra have stuck with me though, and those are arguably  <i>very</i> nice skills to have in the AI era.
</p>

 <p>
Obviously abstract linear algebra and DSP are not my fields of research/work, but I apparently also forgot the chain rule at some point? Which I found out while trying to learn about how backpropagation works. And calculus fundamentals feel like a fairly important thing to retain for general knowledge purposes.
</p>

 <p>
This note isn't really supposed to have any grand meaning, but some thoughts:
</p>

 <ol class="org-ol"> <li>I'm (now even more) incredibly awed by the professors and grad students in my life who seem to have an almost eidetic recall of the coursework and papers they've studied in the past.</li>
 <li>What is the "correct" amount of effort to spend reviewing or reinforcing content learned in past courses without impeding current work or research?</li>
 <li>I wonder if limited recall is somehow attributable to the proliferation of search engines and online databases? Something something "incentivizing  <i>finding</i> information repeatedly instead of recalling information long-term".</li>
</ol> <p>
Can't imagine LLMs are doing anything to help point 3… 
</p>
</div>]]></description>
  <link>https://pradyun.net/notes/use_it.html</link>
  <guid isPermaLink="false">https://pradyun.net/notes/use_it.html</guid>
  <pubDate>Fri, 19 Jun 2026 00:00:00 +0000</pubDate>
</item>
<item>
  <title>A Brief Review of the Kobo Libra Color</title>
  <description><![CDATA[<div id="content" class="content">

 <blockquote>
 <p>
TL;DR I'm a fan! It's light, it's got a nice screen, it's got good battery life, and it reads EPUBs natively.
</p>
</blockquote>

 <p>
More details below, in case the hyper-descriptive summary above wasn't enough for you.
</p>

 <p>
Screen size/resolution hasn't been a huge issue for me, though that may be because I'm fairly partial to small font sizes. Kobo's operating system also natively supports uploading and using custom fonts, which is rather kind of them – I've opted to use Crimson Font, as I usually do for serif typefaces. I've read through some longer books ( <a href="https://www.kobo.com/us/en/ebook/how-to-build-a-car-the-autobiography-of-the-world-s-greatest-formula-1-designer?sId=efc0a036-89ff-4e9f-95c8-219b60b8c4cc">How to Build a Car</a>,  <a href="https://www.kobo.com/ww/en/ebook/the-song-of-achilles">The Song of Achilles</a>) without issue, and it's been fairly enjoyable to read with my Kobo in one hand and a cup of coffee in the other.
</p>

 <p>
The buttons on the side are likely a design decision lifted from the Kindle Oasis, and I'm totally okay with that. I had my eyes on the Kindle Oasis for years but never thought I was reading ebooks enough to justify the upgrade from my Paperwhite. Sadly Amazon has gone in a  <i>different</i> direction these days so the Oasis was discontinued. Regardless, the Libra Color is fairly similar in spirit, and has the benefit of using a color panel at a cheaper price than what Amazon charges for the Colorsoft. Some semi-evangelical forum members (cough cough, Reddit) claim that color panels can lead to meaningful loss in DPI and screen clarity, but I have noted no such issues personally speaking.
</p>

 <p>
There's also been some active communities that have worked on modding and adding extensions to the Kobo Libra – NickelMenu being a prolific example – but I haven't actually found significant utility from any of them. I was hoping to find a way to read PDFs comfortably on the Libra, but that hasn't been very fruitful given the smaller screen size and fixed-layout properties of PDF. There doesn't seem to be any (recent) software that can convert PDFs into EPUB fairly accurately, so in the meantime I've been sticking to using Zotero on my desktop or iPad for paper-reading. This is also probably the more defensible way to do it long-term, purely from a perspective of managing annotations. 
</p>

 <p>
Would I buy it again? Definitely. Should you buy it? Debatable. Will you regret it? Assuming you actually read on it, I'd find it unlikely.
</p>
</div>]]></description>
  <link>https://pradyun.net/notes/kobo.html</link>
  <guid isPermaLink="false">https://pradyun.net/notes/kobo.html</guid>
  <pubDate>Sun, 31 May 2026 00:00:00 +0000</pubDate>
</item>
<item>
  <title>Installing Vivado on NixOS</title>
  <description><![CDATA[<div id="content" class="content">

 <p>
This note started out in May 2025, when I first tried to install Vivado on my NixOS machine. I'd tried all sorts of random things. Below you will see some bullet points from the  <i>original</i> draft of this post, which was intended to be much longer, as a triumphant victory after wrangling the mess of scripts and dependencies that is Xilinx packaging.
</p>

 <hr></hr> <ul class="org-ul"> <li>Dump installation image with web installer (SFD not supported post-2025.2)
 <ul class="org-ul"> <li>Make an FHS to launch web installer, scripts are broken for  <code>nix-ld</code></li>
</ul></li>
 <li>Add dependencies to nix-ld</li>
 <li>Fix shebangs in scripts in  <code>bin</code></li>
</ul> <hr></hr> <p>
After about 4 days of agony I stumbled upon  <a href="https://gitlab.com/doronbehar/nix-xilinx">this repo</a> for porting Xilinx to Nix… even the author had given up and switched to Ubuntu! By his recommendation I threw in the towel and created a  <a href="https://gitlab.com/pradyun/nix/-/blob/master/containers/vivadobox.ini?ref_type=heads">distrobox container</a> for my Vivado install, which has worked flawlessly, carrying me through synthesis of fairly large designs for the VCU118 during my chip tapeout. I'll write about that experience in the future (I hope), but in the meantime the moral of the story is:
</p>

 <blockquote>
 <p>
NixOS is pretty cool, until you use EDA software, at which point you might as well just use Ubuntu.
</p>
</blockquote>
</div>]]></description>
  <link>https://pradyun.net/notes/vivado_nixos.html</link>
  <guid isPermaLink="false">https://pradyun.net/notes/vivado_nixos.html</guid>
  <pubDate>Sat, 18 Apr 2026 00:00:00 +0000</pubDate>
</item>
<item>
  <title>A Primer on Oblivious RAM</title>
  <description><![CDATA[<div id="content" class="content">

 <div class="abstract" id="org673ede7">
 <p>
We discuss the motivations and principles underpinning Oblivious RAM (ORAM) and the naive construction of one. We then transition to a more in-depth review of the drawbacks of older ORAM constructions, and how modern implementations like Path ORAM and Ring ORAM address them. Finally, we close on applications of these more efficient implementations, and their relevance to modern research in computer science and cryptography.
</p>

</div>

 <blockquote>
 <p>
 <b>Note</b>: This was a paper I wrote for Cryptography (ECE407) over the span of about 3 days straight. The literary quality dips in places and it's not my greatest work, but the topic overall is quite interesting. Hopefully you learn something new! 
</p>
</blockquote>


 <div id="outline-container-orgc4e18b4" class="outline-2">
 <h2 id="orgc4e18b4">Revisions</h2>
 <div class="outline-text-2" id="text-orgc4e18b4">
 <ul class="org-ul"> <li> <i>05/22</i>: Client-side space overhead for Square Root ORAM was incorrectly characterized as \(O(N\log N)\)</li>
</ul></div>
</div>
 <div id="outline-container-org098d8c5" class="outline-2">
 <h2 id="org098d8c5">Introduction</h2>
 <div class="outline-text-2" id="text-org098d8c5">
 <p>
Oblivious computation research dates back as far as 1979. Pippenger et al.  <a href="#citeproc_bib_item_1">[1]</a> explored the idea of an "oblivious Turing Machine", in which the motion of a Turing Machine's head on its tape lent no information about the underlying program. That is to say, you could make no useful conclusions regarding the input program by observing the head position - its movement was  <i>indistinguishable</i> for any two input programs of similar length. This paper not only laid out the foundations for a functional OTM, but it also was the first paper to discuss the notion of  <i>oblivious computing</i>. Computation in which the observable accesses and movements of a machine lent no information about the underlying operations.
</p>

 <p>
In their seminal 1987 papers (later reunited as a journal paper in  <a href="#citeproc_bib_item_2">[2]</a>), Goldreich and Ostrovsky extended the idea of oblivious computing to an off-CPU RAM that stored some sort of software. However, their motivation had more to do with software piracy. Since programs on a RAM were still just a sequence of bits, they could easily be copied and distributed by an adversary.
</p>

 <p>
The knee-jerk solution to this problem would likely be to simply encrypt the data going in and out of the RAM. However, it's important to note that  <i>where</i> and  <i>how</i> memory is accessed can lend important information about the underlying program, especially when paired with a high-level description of what the program does (which you get by buying the software). For example - repeated reads of a cluster of adjacent RAM blocks could indicate some sort of loop structure within the program itself. This is obviously subject to some architectural decisions on the CPU's memory subsystem, but the point should stand as a motivating example. Thus, a system allowing for oblivious memory access should be able to mask not only  <i>what</i> the data is, but  <i>where</i> the data is and  <i>how</i> the data was accessed.
</p>

 <p>
Today's compute landscape presents other scenarios requiring security when accessing a RAM, outside of the initial goal of piracy-prevention. A large motivating factor, as outlined in  <a href="#citeproc_bib_item_3">[3]</a> by Stefanov et al., is the advent of  <i>cloud compute</i>. Many clients store secure data (tax forms, legal documents, etc.) on remote servers that are considered "untrusted". We also heavily rely on cloud compute for many modern services, many of which will inevitably require some amount of confidential information from the user.
</p>

 <p>
In a naive security model where the client and cloud use symmetric encryption to prevent data from being leaked to eavesdroppers, the access pattern can still lend information regarding the type of actions that the client is engaging in with remote storage. Furthermore, the  <i>server</i> has knowledge of the physical memory locations that the client accesses, which inherently lends insights into the off-server actions of the client. Thus, in the early 2010s there was a renewed interest in devising secure memory schemes enabling oblivious compute with untrusted remote servers.
</p>

 <p>
 <a href="#citeproc_bib_item_2">[2]</a> was seminal for many reasons. Today, we recognize it as the paper that  <i>defined</i> the security model of  <b>Oblivious RAM</b>, and outlined the basic schemes of implementing it that motivated future ORAM schemes for nearly 2 decades.
</p>
</div>
 <div id="outline-container-org63b36d5" class="outline-3">
 <h3 id="org63b36d5">Problem Definition</h3>
 <div class="outline-text-3" id="text-org63b36d5">
 <p>
The ORAM problem was first presented as two separate definitions in  <a href="#citeproc_bib_item_2">[2]</a>, found in sections 2.3.1 and 2.3.2. These refer to the definition of an ORAM to guarantee access pattern indistinguishability, then outline the definition of an ORAM "simulating" RAM as a way to prove correctness of the ORAM scheme. The aforementioned definitions are relatively obfuscated for the purposes of this primer (entrenched in Turing Machine models and whatnot), but there are some important takeaways to note.
</p>

 <ol class="org-ol"> <li>An ORAM system consists of a  <i>traditional</i> RAM block and an ORAM protocol being run on the attached CPU. The RAM itself doesn't do any of the "obliviation", so to speak. This makes ORAM a bit of a misnomer, as it describes the  <i>perceived function</i> of the RAM, not necessarily the function of the RAM itself.</li>
 <li>In any ORAM system, the client or CPU is considered  <i>secure</i>. Memories inside of the client (registers, caches) and internal operations of the client cannot be determined by an adversary – they can only see the traffic between the client and the memory, and the data stored directly inside of the memory.</li>
 <li>To avoid leaking information through deterministic encryption or decision-making over multiple runs of the same program, any CPU involved in a feasible ORAM system must include some sort of  random function and be able to make decisions based on it. In practice, this can be implemented as a PRF or PRG, with a randomly generated key or nonce used to vary the encryption of identical plaintext over different iterations.</li>
</ol> <p>
Modern papers like  <a href="#citeproc_bib_item_3">[3]</a>,  <a href="#citeproc_bib_item_4">[4]</a> prefer a simpler definition of the ORAM problem, and this is the one that we use going forwards.
</p>

 <blockquote>
 <p>
Consider a sequence of memory accesses \(\vec{y}\), defined below, where \(| \vec{y} | = M\).
</p>

 <p>
\[
\vec{y} = ((op_M, addr_M, data_M), ..., (op_1, addr_1, data_1))
\]
</p>

 <p>
\(op_i\) denotes whether the i-th access is a read or write, \(addr_i\) denotes the address of the i-th memory access, and \(data_i\) is the data written into the RAM for a write access.
</p>

 <p>
Given an ORAM algorithm, a sequence of logical client-server or CPU-RAM accesses \(\vec{y}\) is transformed into an observed access sequence \(\mathsf{ORAM}(\vec{y})\). ORAM protocols will guarantee that for any two access sequences \(\vec{y}, \vec{z}\) where \(|\vec{y}| = |\vec{z}|\), \(\mathsf{ORAM}(\vec{y}) \stackrel{c}{\approx} \mathsf{ORAM}(\vec{z})\). Furthermore, the data returned by \(\mathsf{ORAM}(\vec{y})\) must, with overwhelming probability, be consistent with the data returned by \(\vec{y}\) without the presence of ORAM (e.g "correct").
</p>
</blockquote>

 <p>
Throughout the rest of this primer, we refer to data in units of a single memory access, which we call a  <b>block</b>. We also, for brevity, embrace a "client-memory" terminology to encompass all possible systems that may implement an ORAM scheme. While it is possible to have multiple clients share data access while employing an ORAM scheme (see  <a href="#orgfce87e1">Applications</a>), a single-client model is adopted in this primer to simplify discussion of encryption and client-side state.
</p>
</div>
</div>
 <div id="outline-container-org0da1144" class="outline-3">
 <h3 id="org0da1144">Implied Constraints of an ORAM</h3>
 <div class="outline-text-3" id="text-org0da1144">
 <p>
Given our earlier definition, we can start to determine some of the properties of what an ORAM should look like. The following section skims some of the high-level analyses in  <a href="#citeproc_bib_item_2">[2]</a>, and some personal understandings from reading various papers in the field. For starters, we can separate adversaries into two types.
</p>

 <ol class="org-ol"> <li> <i>Non-Tampering Adversaries</i>: Eavesdrops on the transactions happening between the client and the memory.</li>
 <li> <i>Tampering Adversaries</i>: Can actively write bad data into the ORAM, and do everything that a non-tampering adversary might.</li>
</ol> <p>
Combating the additional actions of the Tampering adversary can be done via some sort of digital signature generated by the client that is stored with the data block. Reading a block with a bad signature could trigger some sort of error correction protocol. As a result, as alluded to earlier, the  <i>eavesdropping</i> problem becomes the more difficult one to solve efficiently.
</p>

 <p>
The indistinguishability criterion set forth earlier necessitates homogeneity of memory access pattern regardless of whether it is a read or write. Inherently, this means that every memory access will  <i>always</i> have to read something out of the ORAM. Block writes would need to be batched and deferred to some later event, or you would need to always write back blocks (even on read operations). At a high level, regardless of the access type made, the actions being taken by the client should  <i>look</i> identical.
</p>

 <p>
There is also the problem of masking repeated accesses to the same data block – if the blocks are naively read/written to the same location between accesses, then it becomes easy to detect data reuse. As a result, any practical ORAM protocol will need to relocate or shuffle data blocks over execution.
</p>

 <p>
Finally, since an ORAM breaks the implicit mapping of a block address or tag being used as a RAM index, we must attach additional metadata to each block in the ORAM to identify it after decryption. This metadata can include the block tag (encrypted with the block to avoid leaking mappings), a nonce used to randomize the encryption function, and any other properties that the ORAM protocol in question requires for correctness. It is generally assumed that any metadata required or suggested by a protocol is a fixed constant negligible to the size of the data block.
</p>

 <p>
Inherently, each of the above properties requires access redundancy or additional computation over a naive RAM. The goal of the ORAM implementations presented in this primer is to maintain them while maintaining computational feasibility and ensuring a negligible failure probability.
</p>
</div>
</div>
</div>
 <div id="outline-container-orgbf2eaa6" class="outline-2">
 <h2 id="orgbf2eaa6">An Early ORAM Construction</h2>
 <div class="outline-text-2" id="text-orgbf2eaa6">
 <p>
With the above objectives, one can think of some basic implementations of ORAM. An especially trivial one would be "brute force" – regardless of the memory access, you can read every block in the memory into CPU registers, optionally modify it, re-encrypt it with a new nonce, then write it back into the same location of the RAM. If a block needs to be reused later, it can be kept in the CPU for operation even after linear scan.
</p>

 <p>
This scheme isn't all bad. For one, it doesn't require any special state about block mappings on the CPU – every block is exactly where you'd expect it to be, it's just that the server doesn't know which one you actually meant to use. However, the linear scan requires \(O(N)\) memory accesses given an N-block memory, and requires \(O(N)\) bandwidth. Any practical system would rattle to a halt. This motivated early research into devising an ORAM algorithm that was  <i>bandwidth-efficient</i> (and, as a corollary, memory-access-efficient).
</p>

 <p>
As if it weren't enough to design a security definition and objective for Oblivious RAM, Goldreich and Ostrovsky outlined early optimized ORAM schemes in  <a href="#citeproc_bib_item_2">[2]</a>. We discuss their initial proposal of a  <i>Square Root ORAM</i> and its pitfalls.
</p>
</div>
 <div id="outline-container-orgce4e482" class="outline-3">
 <h3 id="orgce4e482">Square Root ORAM</h3>
 <div class="outline-text-3" id="text-orgce4e482">
 <p>
This construction simulates an N-block RAM by using \(N + 2\sqrt{N}\) real memory blocks – an overhead of \(O(\sqrt{N})\) extra memory capacity (and the source of its name). Instead of brute-forcing the entire memory to hide its accesses, it  <i>permuted</i> the order of its blocks and periodically reshuffled them to prevent information leakage through repeated access.
</p>


 <div id="org5ee638b" class="figure">
 <p> <img src="../images/sqrt-oram.png" alt="sqrt-oram.png" height="100pt"></img></p>
 <p> <span class="figure-number">Figure 1: </span>Memory Separation in Square Root ORAM</p>
</div>

 <p>
As shown in figure  <a href="#org5ee638b">1</a>, the memory used for this scheme separates into three sections – the real blocks reserved for the actual data in the RAM, a shelter that acts like a "working memory", and dummy blocks (assume these are just set to 0) that help mask accesses when working with the shelter. At initialization, the shelter blocks are also assumed to be populated as dummy blocks.
</p>

 <p>
Square Root ORAM works in "epochs" of \(\sqrt{N}\) memory accesses – over this duration, blocks are taken out of the real blocks and placed into the shelter. After an epoch, in the worst case, all of the blocks in the shelter will have been filled up by legitimate blocks with potentially updated data. The overall algorithm for a single epoch is as follows.
</p>

 <ol class="org-ol"> <li>Using the random function, map each logical and dummy block index onto a random tag via a random oracle \(\pi\). Tags are assumed to be on the range \([1, \frac{n^2}{\epsilon}]\), where \(\epsilon\) determines our collision probability.</li>
 <li>Make a single pass over all the permuted blocks to update their tag values. It is assumed that there is either an inverse mapping available from the previous epoch's tags, or the blocks are given encrypted metadata that identify their intended logical index.</li>
 <li>Implement Batcher's Sorting Network (a binary tournament sorting algorithm) to sort the permuted blocks by tag value.
 <ul class="org-ul"> <li>This network is used since its access pattern is identical irrespective of input data. We call such sorting algorithms an  <i>oblivious sort</i>.</li>
</ul></li>
 <li>Simulate \(\sqrt{N}\) memory accesses.</li>
 <li>Implement Batcher's Sorting Network over the  <i>entire</i> memory, by the key \((v, \sigma)\). \(v\) is the index into the logical RAM (\(\infty\) for dummy blocks) and \(\sigma\) is 0 for permuted blocks, 1 for shelter blocks.</li>
 <li>Make a reverse scan through the ORAM, and mark each duplicate block as a dummy (e.g \(\sigma = 0\) for this block, but we saw \(\sigma=1\) the previous iteration).</li>
</ol> <p>
The final sort is a bit ambiguous, but it works since we assume that the dummy blocks  <i>always</i> have a tag \(\infty\). After step 5, these dummy blocks all end up in the final \(\sqrt{N}\) blocks – therefore any block with a valid tag must have been placed into the permuted blocks, effectively evicting the shelter. We also assume that the shelter will have at maximum one copy of each block (this will be clearer after explaining the access protocol), so after our sort we will find exactly one or two copies of each real block (hence \(\sigma\) allowing for a strict ordering).
</p>

 <p>
Each access \((op_i, addr_i, data_i)\) of step 4 is performed as follows, where \(i \in [1, \sqrt{N}]\).
</p>

 <ol class="org-ol"> <li>Iterate over all \(\sqrt{N}\) blocks in the shelter.
 <ul class="org-ul"> <li>Read each block into the CPU.</li>
 <li>Update it to \(data_i\) if \(addr_i\) matches the block's metadata and \(op_i\) is a write.</li>
 <li>Re-encrypt the block and write back into the shelter.</li>
</ul></li>
 <li>Select which block to read out of the permuted blocks.
 <ul class="org-ul"> <li>If the block was found in the shelter, we target \(tag_i = \pi(N + i)\) (the i-th dummy block).</li>
 <li>If we could not find it, we look for the real block by targeting \(tag_i = \pi(addr_i)\).</li>
</ul></li>
 <li>Since we sorted the permuted blocks in step 3 of the epoch, we can perform an oblivious binary search to read out the block with \(tag_i\).
 <ul class="org-ul"> <li>The blocks are permuted every epoch, and each permuted block is accessed once per epoch.</li>
 <li>No information can be leaked about whether a dummy or real block was read, or reused.</li>
</ul></li>
 <li>If the block was not found in the shelter and \(op_i\) is a write, update block data to \(data_i\). We then re-encrypt the block and write it into real block \(N + \sqrt{N} + i\) – e.g the i-th block of the shelter.</li>
</ol> <p>
At a high level, we can outlined scheme fulfills some of the basic properties we desire from an ORAM. Both access types and block reuse cannot be leaked to an adversary, as every memory access uses an observably identical protocol. The reshuffling of permuted blocks further guarantees that we do not leak any information regarding data locality.
</p>

 <p>
Furthermore, we can also see an improvement from our initial brute force scheme. The old scheme would have incurred a bandwidth of \(O(N\sqrt{N})\) per epoch. By incurring an additional client-side space overhead and a memory overhead of \(O(\sqrt{N})\), we reduce the per-epoch bandwidth to \(O(N\log^2N)\), which is dominated by the accesses required for Batcher's Search Network in steps 3 and 5 of each epoch.
</p>
</div>
</div>
 <div id="outline-container-org42f034d" class="outline-3">
 <h3 id="org42f034d">Drawbacks</h3>
 <div class="outline-text-3" id="text-org42f034d">
 <p>
Despite being described as a "naive" solution by  <a href="#citeproc_bib_item_2">[2]</a>, this scheme presents some of the issues that plagued many ORAM schemes, the foremost one being  <i>complexity</i>. It is difficult to intuitively reason about the correctness and operation of this scheme, and becomes even harder so when  <a href="#citeproc_bib_item_2">[2]</a> later adapts it to a hierarchical solution.
</p>

 <p>
There is also the non-trivial performance overhead - as explained earlier, this scheme requires significant storage overhead in the memory of an ORAM system, and the per-access latency (\(\approx \log^2N\)) does not scale well with memory sizes. Goldreich and Ostrovsky argue in section 6 of their paper that there must be a lower bound of \(\Omega(t\log{t})\)  <sup> <a id="fnr.ackshually" class="footref" href="#fn.ackshually" role="doc-backlink">1</a></sup> real memory accesses to simulate \(t\) logical memory accesses on an ORAM.
</p>
</div>
</div>
</div>
 <div id="outline-container-orgd6f263c" class="outline-2">
 <h2 id="orgd6f263c">Efficient Tree-Based ORAMs</h2>
 <div class="outline-text-2" id="text-orgd6f263c">
 <p>
Throughout the early 2000s, many ORAM schemes were devised to cut per-access bandwidth closer to this boundary. Efficient ORAM constructions like Pinkas-Reimann  <a href="#citeproc_bib_item_5">[5]</a> and Goodrich-Mitzenmacher  <a href="#citeproc_bib_item_6">[6]</a> still inherited from a hierarchical RAM scheme presented in section 5 of  <a href="#citeproc_bib_item_2">[2]</a> and relied on oblivious sorting mechanisms. This meant that while amortized per-access ORAM latency approached logarithmic/polylogarithmic functions of N, worst-case latency was still on the order of \(\Omega(N)\) in  <a href="#citeproc_bib_item_6">[6]</a> or \(\Omega(N\log N)\) in  <a href="#citeproc_bib_item_5">[5]</a>. Altogether, this amounted in a performance overhead that ranged from 1400 to over  <i>80000</i> times the number of operations required for the same access pattern with a transparent memory device  <a href="#citeproc_bib_item_3">[3]</a> .
</p>

 <p>
While some ORAM schemes around this time, like the SSS construction in  <a href="#citeproc_bib_item_3">[3]</a> and Shi et al.'s \(\log^3\) ORAM  <a href="#citeproc_bib_item_7">[7]</a>, presented schemes that helped reduce the worst-case performance to polylogarithmic functions and reduce client/storage cost in doing so, tree-based constructions are currently the most popular category of ORAM. This is largely due to the innovations that came with the Path ORAM construction by Stefanov et al.  <a href="#citeproc_bib_item_8">[8]</a>.
</p>
</div>
 <div id="outline-container-orga3ac7b2" class="outline-3">
 <h3 id="orga3ac7b2">Path ORAM</h3>
 <div class="outline-text-3" id="text-orga3ac7b2">
 <p>
The general Path ORAM construction demonstrated in  <a href="#citeproc_bib_item_8">[8]</a> inherits heavily from the previous work done by Shi et al. in  <a href="#citeproc_bib_item_7">[7]</a>, particularly in its usage of bucket-based storage trees with oblivious eviction.
</p>


 <div id="org56f8eeb" class="figure">
 <p> <img src="../images/path-oram.png" alt="path-oram.png" height="250pt"></img></p>
 <p> <span class="figure-number">Figure 2: </span>Path ORAM Memory Structure for \(Z=4, L=2\)</p>
</div>


 <p>
On the server side, storage is interpreted as an N-ary tree (typically  <i>binary</i>) of \(L\) levels, where each node is a 'bucket' storing up to \(Z\) real memory blocks. Buckets with less than \(Z\) blocks will be padded with dummy blocks. An example of such a tree is laid out in figure  <a href="#org56f8eeb">2</a>. In the memory, these buckets would be laid out serially so they can still be accessed via a normal external indexing scheme. 
</p>

 <p>
Path ORAM, like most high-performance ORAM schemes, is also stateful on the client side. The client side must maintain a  <b>position map</b> (\(\pi\)) to help it find a desired block inside the memory, as well as a  <b>stash</b> (\(S\)) to store blocks in the client during runtime (more on this later). The position map is constructed such that indexing it with a block ID will return a leaf node in the memory's tree. The Path ORAM algorithm guarantees that when it traverses the tree to reach this leaf node, the desired block will be found in one of the buckets along this path (hence the algorithm's name).
</p>

 <p>
It is assumed that at initialization, the client's stash is empty, the server only contains dummy blocks, and the position map is filled with uniformly random numbers corresponding to various leaf node indices. With this in mind, we outline the Path ORAM algorithm below for a single memory access \(\vec{y}_i\). We adopt the notation \(P(x)\) to denote the path from the root node to leaf node \(x\), and \(P(x, i)\) to denote the i-th node on this path.
</p>

 <ol class="org-ol"> <li>Load \(\pi(addr_i)\) into \(leaf_i\), then reassign \(\pi(addr_i)\) to a random leaf node.</li>
 <li>Load each of the buckets along \(P(leaf_i)\).</li>
 <li>Add the desired block \(addr_i\) to the stash \(S\).</li>
 <li>If \(op_i\) is a write, then update block \(addr_i\) to contain \(data_i\) in \(S\).</li>
 <li>Iterate backwards along the path that was traversed (leaf node upwards, e.g \(P(leaf_i, L)\) to \(P(leaf_i, 0)\)).
 <ul class="org-ul"> <li>At each bucket, select up to \(Z\) blocks from the stash that have this bucket  <i>somewhere</i> on their path (per \(P(\pi(a))\) for some block \(a\)). Write them into the bucket.</li>
 <li>If we cannot find \(Z\) suitable blocks, write dummy blocks until the bucket is at capacity.</li>
 <li>Remove any blocks written to the bucket from our stash.</li>
</ul></li>
</ol> <p>
Like the Square Root ORAM  <a href="#citeproc_bib_item_2">[2]</a> and our initial brute-force solution, every access using this algorithm looks identical for any observer. \(Z(L+1)\) blocks are read out of the memory and \(Z(L+1)\) blocks are written into it along some randomly selected path. Since the blocks are, in effect, evicted from the tree when read out and later relocated to a random location, we incur no risk of leaking data locality.
</p>

 <p>
An interesting feature of this algorithm is the approach it takes to filling in the bucket tree at the end of each access. By taking a bottom-up traversion and pushing blocks as far down the tree as possible, buckets with fewer potential candidates are populated first. This in turn minimizes stash usage.
</p>
</div>
 <div id="outline-container-org7737fcc" class="outline-4">
 <h4 id="org7737fcc">Performance and Usability Implications</h4>
 <div class="outline-text-4" id="text-org7737fcc">
 <p>
As every access for Path ORAM is algorithmically identical, there is no need to calculate amortized latency. Since \(L\) is set to \(\log_2 N\) in a binary tree and \(Z\) is a fixed constant, the algorithm practically achieves  <i>logarithmic bandwidth</i> \(O(\log N)\), even in the worst-case, for any practical block size. This surpassed the previous standard of \(O(\frac{\log^2 N}{\log(\log N)})\) for small-client-storage oblivious RAMs, a cuckoo hashing scheme set forth by Kushilevitz et al. in  <a href="#citeproc_bib_item_9">[9]</a>. We only mention asymptotic results for now, as experimental results were only found for a construction in section  <a href="#orgdc968f3">Recursive Path ORAM</a>. 
</p>

 <p>
On a related note, the failure probability of this algorithm is solely determined by potential path collisions when updating \(\pi\). If too many blocks are mapped to the same path, then a fixed-size stash \(S\) can potentially overflow. Accordingly, Stefanov et al.  <a href="#citeproc_bib_item_8">[8]</a> constructed a novel proof structure characterizing the likelihood of stash overflow during the Path ORAM algorithm – this proof structure later became popular among other tree-based ORAM constructions. They were able to show that even at large security parameters (\(\lambda = 128\)) a stash of 147 blocks was sufficient for bucket size \(Z=4\). Notably, stash size is purely a function of \(Z, \lambda\), with no dependence on memory size \(N\). This made Path ORAM uniquely scalable to large memory sizes even with fixed client-side storage constraints. In practice, the paper experimentally found \(Z=4\) to be minimum required bucket parameter in order to prevent excessive stash accumulation, while stating that  <i>theoretically</i> \(Z=5\) might be a better candidate.
</p>

 <p>
There is also the benefit of  <i>usability</i> – Path ORAM, despite being a hyper-efficient algorithm, is significantly easy to describe and construct when compared to older oblivious sorting and cuckoo hashing schemes (like the one in section  <a href="#orgce4e482">Square Root ORAM</a>). This made ORAM a much more  <i>feasible</i> tool for not just cryptographers, but engineers and system architects to design secure systems.
</p>
</div>
</div>
</div>
 <div id="outline-container-orgdc968f3" class="outline-3">
 <h3 id="orgdc968f3">Recursive Path ORAM</h3>
 <div class="outline-text-3" id="text-orgdc968f3">
 <p>
Despite the stash being invariant of memory size, the mapping table \(\pi\) inherently must be. For large \(N\), it becomes infeasible to store this on a client with limited storage.
</p>

 <p>
Path ORAM borrows from ideas in  <a href="#citeproc_bib_item_3">[3]</a> and  <a href="#citeproc_bib_item_7">[7]</a>, specifically with regards to moving mapping tables off-client via recursive ORAMs. To put it informally:
</p>

 <blockquote>
 <p>
The 'big' ORAM's mapping table becomes an ORAM. Then that ORAM's mapping table becomes an ORAM. And then  <i>that</i> ORAM's mapping table…
</p>
</blockquote>

 <p>
This procedure keeps going until a client requires suitably low amounts of storage to initiate an ORAM access. While this seems like it would pollute bandwidth, as indicated by a higher worst-case bandwidth \(O(\log^2 N)\), in practice Recursive Path ORAM still achieves R/W bandwidth of \(O(\log N)\). For a given access sequence \(\vec{y}\), this was experimentally determined by  <a href="#citeproc_bib_item_4">[4]</a> to be approximately 160x the bandwidth of simply using an insecure memory. While this isn't directly comparable to the results on older schemes collected by  <a href="#citeproc_bib_item_3">[3]</a>, which were done using 64KB block sizes, there is a massive order of magnitude difference compared to older ORAM schemes. While this is less performant than the SSS construction in the same work, the relative simplicity and better client memory efficiency of Path ORAM made it significantly easier to iterate upon and implement in hardware-centric applications.
</p>
</div>
</div>
 <div id="outline-container-org2045c97" class="outline-3">
 <h3 id="org2045c97">Ring ORAM</h3>
 <div class="outline-text-3" id="text-org2045c97">
 <p>
Ring ORAM, like Recursive Path ORAM, isn't so much a new algorithm altogether so much as it is a set of improvements to Path ORAM proposed by Ren et al.  <a href="#citeproc_bib_item_4">[4]</a>.
</p>

 <p>
Ring ORAM's first goal was to reduce the amount of  <i>online bandwidth</i>, which we can understand to be the required (non-amortized) bandwidth per access. To do so, they store additional encrypted metadata with each bucket containing a  <i>permutation</i> – e.g which block is stored in each position of the bucket. This means that instead of loading every bucket along the path \(P(leaf_i)\), two accesses are made per bucket - one to query the metadata, and one to load the appropriate block afterwards.
</p>

 <p>
A corollary of this approach is that we can no longer have an in-place eviction, as we'd be evicting many blocks out of each bucket prematurely (counter to the goal of reducing per-access bandwidth). Like the construction in section  <a href="#orgce4e482">Square Root ORAM</a>, Ring ORAM opts to periodically evict blocks in its lookaside storage (in this case, the stash instead of the shelter) back into the primary storage (buckets) and reshuffle when doing so.
</p>

 <p>
Between the initial access and the reshuffle, the block is  <i>invalidated</i> in the memory. To ensure we still read some block on every path traversion, a dummy block is read out in any case that the requested block address is not found in a bucket. To facilitate the dummy-pulling while employing a periodic eviction strategy, Ring ORAM makes a couple of modifications to Path ORAM's data model.
</p>

 <ol class="org-ol"> <li>Ring ORAM will store \(Z\) real blocks and \(S\) dummy blocks per bucket after each reshuffle. We retain the standard definition of a dummy block.</li>
 <li>An eviction is carried out  <i>either</i> every \(A\) accesses (a tunable parameter) or when a single bucket is accessed \(S\) times without eviction (this is tracked via a counter). This latter condition is in place so that an argument regarding a block  <i>having</i> to be real cannot be made per the pigeonhole principle prior to a bucket eviction.</li>
</ol> <p>
With the above changes in place, we can make an additional optimization via an  <i>XOR</i>. Since the requested block can only be found  <i>once</i> on the traversion path, we can guarantee that we will either pull out \(L+1\) dummy blocks or \(L\) dummies and the requested block. Since dummies are assumed to always have a plaintext known to the client, we can assume that provided the nonces associated with each dummy, the client can generate the expected ciphertext for each dummy.
</p>

 <p>
By returning an  <code>XOR</code> of all the pulled data blocks from the memory, and then performing an  <code>XOR</code> on the client side between this block and each of the locally generated dummy ciphertexts, we can still pull out the expected ciphertext of the  <i>real</i> block. In doing so, the memory will only have to send back  <i>one</i> effective data block on each path traversal, regardless of tree depth. In short, the per-access bandwidth becomes  <i>negligibly conditional on bucket size and tree depth</i>. This is perhaps the biggest contribution of Ring ORAM – an online access bandwidth that is  <i>approximately identical</i> to the expected bandwidth with insecure memory access.
</p>

 <p>
As a whole, the improvements proposed by Ring ORAM reduce the bandwidth required for a single access  <i>without</i> eviction from the tree to constant overhead. However since evictions are still required, the asymptotic amortized bandwidth (e.g average bandwidth over many accesses) is still \(O(\log (\frac{N}{A}))\), a logarithmic bound.
</p>

 <p>
That said, this still translates to a practical performance improvement. Testing results in  <a href="#citeproc_bib_item_4">[4]</a> showed that under the same 4KB testing scheme referred to in section  <a href="#org7737fcc">Performance and Usability Implications</a>, Ring ORAM with the XOR trick were able to bring overall bandwidth to only  <i>60x</i> the bandwidth required for insecure memory accesses. This is a little over \(\frac{1}{3}\) the bandwidth required for a recursive Path ORAM in the same scenario.
</p>
</div>
</div>
</div>
 <div id="outline-container-orgd90183b" class="outline-2">
 <h2 id="orgd90183b">Related Research</h2>
 <div class="outline-text-2" id="text-orgd90183b">
 <p>
In this section we, at a high level, discuss a variety of adjacent research endeavors that can leverage ORAM mechanisms as a facet of their system architecture or attempt to iterate on the construction of modern ORAM schemes.
</p>
</div>
 <div id="outline-container-orgfce87e1" class="outline-3">
 <h3 id="orgfce87e1">Applications</h3>
 <div class="outline-text-3" id="text-orgfce87e1">
 <p>
While most of this primer discusses ORAM in a single-party context, the reality is that remote computation is rarely a single-client system anymore. In scenarios where a group of trusted users require concurrent and secure access to some remote memory, many single-client ORAM schemes can encounter  <i>coherency issues</i>. As a minimum motivating example, we can look at the basic Path ORAM construction - there are possible scenarios where if you have 2 clients with stashes that contain real blocks, client A may unable to access a block that is temporarily held in client B's stash.
</p>

 <p>
Anticipating this coherency problem, Goodrich et al. proposed a stateless ORAM mechanism for secure group data access  <a href="#citeproc_bib_item_10">[10]</a>. Importantly, this mechanism requires that any client state be downloaded and re-uploaded to the remote when a client performs a memory access. As a result, any state maintained by the ORAM protocol should be  <i>lean</i> to prevent bandwidth pollution. While constructions like SSS  <a href="#citeproc_bib_item_3">[3]</a> may not be well-suited to this landscape due to high client storage requirements, a construction like Recursive Path ORAM  <a href="#citeproc_bib_item_8">[8]</a> is better suited to this task. Its position map and stash can be maintained with only \(O(\log N)\) client storage and \(O(\log^2 N)\) bandwidth.
</p>

 <p>
Another field with direct applications for ORAM is in secure processors. While there is a plethora of ongoing research regarding encrypted compute in enclaves and secure processors, we focus more on the utility of ORAM to mask program locality and memory access behavior. These architectures, approach memory interactions with a similar lens to the original Goldreich-Ostrovsky ORAM constructions  <a href="#citeproc_bib_item_2">[2]</a>, trying to mask information about the underlying program instructions that a secure processor is fetching out of RAM.
</p>

 <p>
Simpler, more bandwidth-efficient constructions like Path ORAM that eschew in-memory sorts and shuffles lend themselves to better hardware representations. Hardware design generally benefits from eschewing large fully-associative structures and maintaining small fixed-bound iterations for anything repetitive. Both of these criteria are fulfilled by the Path ORAM model  <a href="#citeproc_bib_item_8">[8]</a>. This is best embodied by some of the work done by Fletcher et al. in  <a href="#citeproc_bib_item_11">[11]</a>,  <a href="#citeproc_bib_item_12">[12]</a>. 
</p>
</div>
</div>
 <div id="outline-container-orge7dfc6c" class="outline-3">
 <h3 id="orge7dfc6c">Theoretic</h3>
 <div class="outline-text-3" id="text-orge7dfc6c">
 <p>
We mentioned in section  <a href="#org42f034d">Drawbacks</a> that  <a href="#citeproc_bib_item_2">[2]</a> proved a lower bound on bandwidth of the form \(\Omega(t \log t)\) for \(t\) accesses. Notably, this bound is invariant of client memory size or block size.
</p>

 <p>
However, this bound assumed an ORAM scheme  <i>based on oblivious sorting</i>. Later papers like  <a href="#citeproc_bib_item_13">[13]</a> showed that if a construction eschews this mechanism (like Path/Ring ORAM), a system can bring this bandwidth bound down to \(\Omega(t\log(\frac{tr}{c}))\) for \(t\) accesses, where \(r\) is the size of each block in an N-block memory and \(c\) is the size of client memory. This conclusion is much more in line with the optimizations that schemes like SSS in  <a href="#citeproc_bib_item_3">[3]</a> make for large client memory sizes, and presents a harder target for novel ORAM schemes to pursue.
</p>

 <p>
At the same time, many newer ORAM constructions were published after the Path and Ring ORAM papers that continued to optimize bandwidth under low client-side storage constraints, or relaxed other assumptions underpinning amortization of these schemes. A good example is OptORAMa  <a href="#citeproc_bib_item_14">[14]</a>, which achieved \(O(\log N)\) access bandwidth overhead for small memory word sizes and limited client-side memory. This improves upon the \(O(\log^2 N)\) overhead of prior constructions like Path ORAM in similar regimes. This improvement stemmed from Intersperse-based shuffling and more efficient hashing schemes (BigHT, SmallHT) used during reshuffling.
</p>

 <p>
While modern constructions discussed in this primer are efficient enough to be used in real-world systems, future research will need to approach ORAM not just as a generic algorithmic tool but as something specialized to specific use cases. For example, future ORAM schemes with minimized eviction and shuffling and small stash sizes are likely to be more suitable for hardware implementation – a frontier that sees more relevance than ever in today's compute landscape.
</p>
</div>
</div>
</div>
 <div id="outline-container-org0398b94" class="outline-2">
 <h2 id="org0398b94">References</h2>
 <div class="outline-text-2" id="text-org0398b94">
 <style>.csl-left-margin{float: left; padding-right: 0em;}
 .csl-right-inline{margin: 0 0 0 2em;}</style> <div class="csl-bib-body">
   <div class="csl-entry"> <a id="citeproc_bib_item_1"></a>
     <div class="csl-left-margin">[1]</div> <div class="csl-right-inline">N. Pippenger and M. J. Fischer, “Relations among complexity measures,”  <i>J. acm</i>, vol. 26, no. 2, pp. 361–381, Apr. 1979, doi:  <a href="https://doi.org/10.1145/322123.322138">10.1145/322123.322138</a>.</div>
  </div>
   <div class="csl-entry"> <a id="citeproc_bib_item_2"></a>
     <div class="csl-left-margin">[2]</div> <div class="csl-right-inline">O. Goldreich and R. Ostrovsky, “Software protection and simulation on oblivious rams,”  <i>J. acm</i>, vol. 43, no. 3, pp. 431–473, May 1996, doi:  <a href="https://doi.org/10.1145/233551.233553">10.1145/233551.233553</a>.</div>
  </div>
   <div class="csl-entry"> <a id="citeproc_bib_item_3"></a>
     <div class="csl-left-margin">[3]</div> <div class="csl-right-inline">E. Stefanov, E. Shi, and D. Song, “Towards practical oblivious ram,” Feb. 2012. Available:  <a href="https://www.ndss-symposium.org/ndss2012/towards-practical-oblivious-ram/">https://www.ndss-symposium.org/ndss2012/towards-practical-oblivious-ram/</a></div>
  </div>
   <div class="csl-entry"> <a id="citeproc_bib_item_4"></a>
     <div class="csl-left-margin">[4]</div> <div class="csl-right-inline">L. Ren  <i>et al.</i>, “Constants count: Practical improvements to oblivious ram,” in  <i>Proceedings of the 24th usenix conference on security symposium</i>, in Sec’15. Washington, D.C.: USENIX Association, 2015, pp. 415–430.</div>
  </div>
   <div class="csl-entry"> <a id="citeproc_bib_item_5"></a>
     <div class="csl-left-margin">[5]</div> <div class="csl-right-inline">B. Pinkas and T. Reinman, “Oblivious ram revisited,” in  <i>Proceedings of the 30th annual conference on advances in cryptology</i>, in Crypto’10. Santa Barbara, CA, USA: Springer-Verlag, 2010, pp. 502–519.</div>
  </div>
   <div class="csl-entry"> <a id="citeproc_bib_item_6"></a>
     <div class="csl-left-margin">[6]</div> <div class="csl-right-inline">M. T. Goodrich and M. Mitzenmacher, “Mapreduce parallel cuckoo hashing and oblivious RAM simulations,”  <i>Corr</i>, vol. abs/1007.1259, 2010, Available:  <a href="http://arxiv.org/abs/1007.1259">http://arxiv.org/abs/1007.1259</a></div>
  </div>
   <div class="csl-entry"> <a id="citeproc_bib_item_7"></a>
     <div class="csl-left-margin">[7]</div> <div class="csl-right-inline">E. Shi, T. .-H. H. Chan, E. Stefanov, and M. Li, “Oblivious ram with o((logn)3) worst-case cost,” in  <i>Advances in cryptology – asiacrypt 2011</i>, D. H. Lee and X. Wang, Eds., Berlin, Heidelberg: Springer Berlin Heidelberg, 2011, pp. 197–214.</div>
  </div>
   <div class="csl-entry"> <a id="citeproc_bib_item_8"></a>
     <div class="csl-left-margin">[8]</div> <div class="csl-right-inline">E. Stefanov  <i>et al.</i>, “Path oram: An extremely simple oblivious ram protocol,”  <i>J. acm</i>, vol. 65, no. 4, Apr. 2018, doi:  <a href="https://doi.org/10.1145/3177872">10.1145/3177872</a>.</div>
  </div>
   <div class="csl-entry"> <a id="citeproc_bib_item_9"></a>
     <div class="csl-left-margin">[9]</div> <div class="csl-right-inline">E. Kushilevitz, S. Lu, and R. Ostrovsky, “On the (in)security of hash-based oblivious ram and a new balancing scheme,” in  <i>Proceedings of the twenty-third annual acm-siam symposium on discrete algorithms</i>, in Soda ’12. Kyoto, Japan: Society for Industrial and Applied Mathematics, 2012, pp. 143–156.</div>
  </div>
   <div class="csl-entry"> <a id="citeproc_bib_item_10"></a>
     <div class="csl-left-margin">[10]</div> <div class="csl-right-inline">M. T. Goodrich, M. Mitzenmacher, O. Ohrimenko, and R. Tamassia, “Privacy-preserving group data access via stateless oblivious ram simulation,” in  <i>Proceedings of the twenty-third annual acm-siam symposium on discrete algorithms</i>, in Soda ’12. Kyoto, Japan: Society for Industrial and Applied Mathematics, 2012, pp. 157–167.</div>
  </div>
   <div class="csl-entry"> <a id="citeproc_bib_item_11"></a>
     <div class="csl-left-margin">[11]</div> <div class="csl-right-inline">C. W. Fletcher, M. v. Dijk, and S. Devadas, “A secure processor architecture for encrypted computation on untrusted programs,” in  <i>Proceedings of the seventh acm workshop on scalable trusted computing</i>, in Stc ’12. Raleigh, North Carolina, USA: Association for Computing Machinery, 2012, pp. 3–8. doi:  <a href="https://doi.org/10.1145/2382536.2382540">10.1145/2382536.2382540</a>.</div>
  </div>
   <div class="csl-entry"> <a id="citeproc_bib_item_12"></a>
     <div class="csl-left-margin">[12]</div> <div class="csl-right-inline">L. Ren, X. Yu, C. W. Fletcher, M. van Dijk, and S. Devadas, “Design space exploration and optimization of path oblivious ram in secure processors,”  <i>Sigarch comput. archit. news</i>, vol. 41, no. 3, pp. 571–582, Jun. 2013, doi:  <a href="https://doi.org/10.1145/2508148.2485971">10.1145/2508148.2485971</a>.</div>
  </div>
   <div class="csl-entry"> <a id="citeproc_bib_item_13"></a>
     <div class="csl-left-margin">[13]</div> <div class="csl-right-inline">K. G. Larsen and J. B. Nielsen, “Yes, there is an oblivious ram lower bound!,” in  <i>Advances in cryptology – crypto 2018: 38th annual international cryptology conference, santa barbara, ca, usa, august 19–23, 2018, proceedings, part ii</i>, Santa Barbara, CA, USA: Springer-Verlag, 2018, pp. 523–542. doi:  <a href="https://doi.org/10.1007/978-3-319-96881-0_18">10.1007/978-3-319-96881-0_18</a>.</div>
  </div>
   <div class="csl-entry"> <a id="citeproc_bib_item_14"></a>
     <div class="csl-left-margin">[14]</div> <div class="csl-right-inline">G. Asharov, I. Komargodski, W.-K. Lin, K. Nayak, E. Peserico, and E. Shi, “Optorama: Optimal oblivious ram,”  <i>J. acm</i>, vol. 70, no. 1, Dec. 2022, doi:  <a href="https://doi.org/10.1145/3566049">10.1145/3566049</a>.</div>
  </div>
</div>
</div>
</div>
 <div id="footnotes">
 <h2 class="footnotes">Footnotes: </h2>
 <div id="text-footnotes">

 <div class="footdef"> <sup> <a id="fn.ackshually" class="footnum" href="#fnr.ackshually" role="doc-backlink">1</a></sup> <div class="footpara" role="doc-footnote"> <p class="footpara">
This assumes that the input program is large enough that \(\log t > 1\).
</p></div></div>


</div>
</div></div>]]></description>
  <link>https://pradyun.net/blog/intro_to_oram.html</link>
  <guid isPermaLink="false">https://pradyun.net/blog/intro_to_oram.html</guid>
  <pubDate>Sat, 10 May 2025 00:00:00 +0000</pubDate>
</item>
<item>
  <title>Semi-Objectively Judging (Indian) Movies</title>
  <description><![CDATA[<div id="content" class="content">

 <p>
I tend to be rather outspoken about my opinion on any movie, but particularly Indian movies. Indian movies (primarily Telugu) have been my primary source of media consumpion for most of my life. As a result, it's one of the few things that I feel comfortable forming relatively well-based opinions about. It's 2AM and I'm waiting for my bedsheets to dry, so here's a dump on how I like to judge movies.
</p>

 <p>
Indian movies tend to suffer from either hyperinflated or unfairly-deflated ratings when viewed from the lens of someone more accustomed to western cinema (as their primary source of entertainment). I'm sure we've all encountered some occurence of 'well what moron would believe that you could hit a guy and he would fly back 6 feet'. Aside from the over-the-top action scenes, there tends to be criticism on the primarily "hero-centric" plot of many "masala" movies, and the rather formulaic storylines of "love at first sight" and an almost  <a href="https://en.wikipedia.org/wiki/Tsundere">tsundere</a> romance plot from the perspective of the heroine. Maybe I'm just desensitized to it, but I do think that those are facets inherent to the art form, and I tend to not factor it too much into how I judge a movie (unless the handling of either the action or romance in a movie is especially egregious).
</p>

 <p>
However as it is with most debates on "whether something is good", there tends to be a decent amount of personal opinion involved, so  <i>some</i> methodology of analysis generally helps to cast discussion over the quality of a movie into a more objective (or healthy) discussion. Of course there's always the option to simply  <i>not</i> discuss what you think of the quality of the movie, but what's the fun in that?
</p>
 <div id="outline-container-orgc98097d" class="outline-2">
 <h2 id="orgc98097d">Detailing a  Somewhat Sane Methodology</h2>
 <div class="outline-text-2" id="text-orgc98097d">
 <p>
First things first, I like to separate the  <i>vision</i> of a movie from its  <i>execution</i>. Poor execution might be the result of low budget, uncooperative cast/crew, and all other manner of factors. But a poor  <i>vision</i> can make for a bad movie from start to finish, regardless of how well you dress it up. This is the difference between a movie like  <i>RRR</i> and  <i>1 Nenokkadine</i>. RRR tends to be publicly touted as "one of India's cinematic masterpieces", but I'd argue it's a perfect example of perfect  <i>execution</i> of a poor  <i>vision</i>.
</p>

 <p>
The best way to see that might be to imagine what RRR would be if we  <i>remove</i> some of the "hallmark" scenes. NTR's clash with Ramcharan with all the animals and water hoses, the final fight with the two against the King, and some of the other more "extravagant" fight scenes. I feel like if you do this (which may be unfair to the film genre, by some people's opinion) then the movie immediately begins to fall flat - the plot is rather lackluster, and the movie overall attempts to justify itself by doubling down on nationalist sentiment. Overall, the vision of RRR is likely a "patriotic  <i>spectacle</i>", and it achieves that well, but I don't know if it makes for a  <i>good movie</i>, at least by my preference for either good plot or abundant comedy. Definitely makes for good press and eye-candy though.
</p>

 <p>
By contrast, 1 Nenokkadine is a movie where some of the execution is a  <i>disservice</i> to the vision. The plot overall is an amazing concept - a schizophrenic musician kills off his parents' murderers, only to realize he hallucinated the murders. The rest of the movie unfolds as he struggles to differentiate what parts of an elaborate conspiracy are fact or fiction. Mahesh Babu puts forward one of his career best performances in the movie, playing the tormented musician. However, the impact of the movie overall is dulled by two big things - poor pacing and plot direction in the latter half of the movie, as well as an overall lack of refinement in the way villain encounters are handled.
</p>

 <p>
Some exceptions are there. The pre-interval scene shows our protagonist kill a primary antagonist thinking it to be a hallucination, only to find out he has killed the culprit in real life.  <i>Peak</i> cinema when shown in context. But by contrast, the film is chock-full of dead space like half-baked yacht fight and bridge fight scenes. They act as a filler that don't satisfy the critic, nor the masala-loving filmgoer. The combination of the two factors above are, at least in my opinion, why the movie didn't fare well in the box office. If I were to remake a movie, 1 Nenokkadine would definitely be a top choice on my list of candidates.
</p>

 <p>
As a side note, something that's been irking me about newer movies is a lack of continuous character development or screenplay. One of the bigger examples of this for me recently has been Kamal Haasan's portrayal of Vikram. He has a great performance and the fight scenes are beautiful - the main reasons why the movie fared so well - but his motivation as a character effectively unravels towards the end. We witness the narrative from the perspective of a man attempting to avenge the unjust murder of his son, only to encounter a climax monologue about a drug-free society and no mention of the dead son. The disconnect, especially since it was towards the end, left a sour taste in my mouth, and gave me a negative final opinion on the movie.
</p>

 <p>
Vidaamuyarchi suffered from an opposite problem - it spends about 40 minutes on exposition of why a husband and wife met, married, grew apart, then divorced. This time is all spent incessantly cutting between different flashbacks, in a seemingly random order. I feel that giving these flashbacks in a more orderly manner - for example, recounting the circumstances of their relationship to a divorce lawyer as a conversation - would have made for a much more linear narrative, cutting this exposition to only 25 or 30 minutes. The remaining time could have been used to pace the final stages of the movie better, which felt extremely rushed in the chosen screenplay.
</p>

 <p>
This leads me to believe that the  <i>writing</i> and  <i>screenplay</i> for movies has been weakening, while the idea and plots still have some originality or quality to them. Though that's just my opinion as a tired amateur - I'm sure experts have done much more in-depth analysis of these things.
</p>
</div>
</div>
</div>]]></description>
  <link>https://pradyun.net/blog/film_evaluations.html</link>
  <guid isPermaLink="false">https://pradyun.net/blog/film_evaluations.html</guid>
  <pubDate>Thu, 06 Feb 2025 00:00:00 +0000</pubDate>
</item>
<item>
  <title>[In]sane Default Formatting</title>
  <description><![CDATA[<div id="content" class="content">

 <p>
For some inane reason, nearly every editor and formatter out there defaults to 4-space indents. Which is fine if you're a psychopath, I suppose? I mean look at the difference between the same snippet with 4 spaces and 2 spaces.
</p>

 <div class="org-src-container">
 <pre class="src src-rust"> <span style="color: #531ab6;">for</span>  <span style="color: #005e8b;">stream</span>  <span style="color: #531ab6;">in</span> listener.incoming() {
     <span style="color: #531ab6;">let</span>  <span style="color: #531ab6;">mut</span>  <span style="color: #005e8b;">newconn</span>:  <span style="color: #005f5f;">MyConn</span>;

     <span style="color: #531ab6;">match</span> stream {
         <span style="color: #005f5f;">Ok</span>(s) => {
            newconn =  <span style="color: #005f5f;">MyConn</span>{
                 <span style="color: #005e8b;">stream</span>: s,
                 <span style="color: #005e8b;">name</span>:  <span style="color: #005f5f;">String</span>::new()
            };
        },

         <span style="color: #005f5f;">Err</span>( <span style="color: #531ab6;">ref</span>  <span style="color: #005e8b;">e</span>)
             <span style="color: #531ab6;">if</span> e.kind() ==  <span style="color: #005f5f;">ErrorKind</span>:: <span style="color: #005f5f;">WouldBlock</span>
                => { <span style="color: #531ab6;">break</span>;},

         <span style="color: #005f5f;">Err</span>(e) =>  <span style="color: #a0132f;">panic!</span>( <span style="color: #3548cf;">"conn err: {e}"</span>),
    }
</pre>
</div>

 <div class="org-src-container">
 <pre class="src src-rust"> <span style="color: #531ab6;">for</span>  <span style="color: #005e8b;">stream</span>  <span style="color: #531ab6;">in</span> listener.incoming() {
   <span style="color: #531ab6;">let</span>  <span style="color: #531ab6;">mut</span>  <span style="color: #005e8b;">newconn</span>:  <span style="color: #005f5f;">MyConn</span>;

   <span style="color: #531ab6;">match</span> stream {
     <span style="color: #005f5f;">Ok</span>(s) => {
      newconn =  <span style="color: #005f5f;">MyConn</span>{
         <span style="color: #005e8b;">stream</span>: s,
         <span style="color: #005e8b;">name</span>:  <span style="color: #005f5f;">String</span>::new()
      };
    },

     <span style="color: #005f5f;">Err</span>( <span style="color: #531ab6;">ref</span>  <span style="color: #005e8b;">e</span>)
       <span style="color: #531ab6;">if</span> e.kind() ==  <span style="color: #005f5f;">ErrorKind</span>:: <span style="color: #005f5f;">WouldBlock</span>
        => { <span style="color: #531ab6;">break</span>;},

     <span style="color: #005f5f;">Err</span>(e) =>  <span style="color: #a0132f;">panic!</span>( <span style="color: #3548cf;">"conn err: {e}"</span>),
  }
</pre>
</div>

 <p>
Night and day.
</p>

 <p>
I guess it's fine if the tab width is  <i>defaulted</i> to four spaces and I could override it to the  <i>obviously better option</i> of two spaces without putting my leg behind my neck, but of course not. Case in point, this is the snippet of my Emacs configuration required just to make  <i>Verilog</i> indentation default to 2 spaces.
</p>

 <div class="org-src-container">
 <pre class="src src-emacs-lisp">( <span style="color: #531ab6;">use-package</span> verilog-ts-mode
   <span style="color: #8f0075;">:defer</span> t
   <span style="color: #8f0075;">:custom</span>
  (verilog-case-indent 2)
  (verilog-cexp-indent 2)
  (verilog-indent-level 2)
  (verilog-indent-level-module 2)
  (verilog-indent-level-directive 2)
  (verilog-indent-level-declaration 2)
  (verilog-ts-indent-level 2))
</pre>
</div>

 <p>
Sorry about the lack of syntax highlighting in the above snippets. Website is still getting sorted out/setup, I'll try to get something sorted.
</p>

 <p>
Regardless. Either editors and tooling need to default to the superior standard of 2 space indents or they need to make my life easier when changing it to 2 spaces. However, I doubt either of those will happen before the heat death of the universe.
</p>

 <blockquote>
 <p>
 <b>Note:</b> After discussion with a friend (and some casual scripting last weekend) it comes to mind that Python would look utterly horrid with a 2-space indent structure. I do still think that the general viewpoint of this post is accurate, albeit with the caveat that it only holds for  <i>sane</i> languages that utilize some sort of delimiter to indicate discrete semantic sections. Python using whitespace to describe code structure has always left an odd impression on me, and it's hard to generalize the formatting recommendations made here to it as such.
</p>
</blockquote>
</div>]]></description>
  <link>https://pradyun.net/notes/fourspaces.html</link>
  <guid isPermaLink="false">https://pradyun.net/notes/fourspaces.html</guid>
  <pubDate>Thu, 30 Jan 2025 00:00:00 +0000</pubDate>
</item>
<item>
  <title>Standardized Typography</title>
  <description><![CDATA[<div id="content" class="content">

 <p>
Over the years one of my pet peeves has been seeing different fonts across my system. Feels jarring almost, especially considering the lengths I went to to make my system colors  <a href="https://github.com/pradyungn/Mountain">coherent</a>. This has led me to attempt to standardize typography across the different applications and documents that I maintain.
</p>

 <p>
Usually I like to use Outfit for headlines and title text, Crimson Text for any serif/prose, and a custom build of Iosevka (Myosevka) for any code. Myosevka is of my own selection, and is simply a low-weight condensed version of Iosevka.
</p>

 <p>
Unfortunately that standardization can break, this website (for now) being an example of this. At the same time I have been attempting to get PragmataPro to play nice with Emacs for a long time to no avail - something to do with Iosevka having sufficient font hinting, but PragmataPro not? Regardless, despite the font looking  <i>great</i>, it looks like a blurry turd in Emacs. Thus PragmataPro lives in my terminal, while Myosevka lives on an interim basis.
</p>

 <p>
This is one of those things where I think it's a "once you start noticing it, it gets hard to ignore it" situation. I used to be rather permissive with fonts, but nowadays writing code in any non-condensed font gives me the heebie-jeebies. Same with writing documents in a sans-serif font (god forbid), with the exception of Google Docs (a necessary evil in life).
</p>

 <blockquote>
 <p>
 <b>Note</b>: As early as  May 1st, I got a license of PragmataPro VF to play cleanly with Emacs on both Mac OS and Linux! TL;DR, font sizes are  <i>not</i> readable at the same intervals on PragmataPro that they are on Iosevka. Linux also has some issues with its default hinting settings not playing well with PragPro. Regardless, my default monospace font is now PragmataPro, with no salient exceptions.
</p>
</blockquote>
</div>]]></description>
  <link>https://pradyun.net/notes/typography.html</link>
  <guid isPermaLink="false">https://pradyun.net/notes/typography.html</guid>
  <pubDate>Tue, 28 Jan 2025 00:00:00 +0000</pubDate>
</item>
</channel>
</rss>
