Posting Through the Singularity: Hacking the Law
I was sitting in a classroom at Yale University when I saw the Future.
The class was called Security, Law and Logic, which I co-taught with Ruzica Piskac, a computer science professor at Yale. Piskac was lecturing that day on theorem provers and model checkers, tools that put mathematical logic to work. She explained how computer scientists use them to verify the safety and security of software.
Remember the “Blue Screen of Death”? You’d be working on your computer, minding your own business, when suddenly the screen turned blue, Windows crashed, and everything you hadn’t saved was gone. One culprit was faulty device drivers, the software that allows Windows to communicate with hardware such as printers and graphics cards. Microsoft began using a model checker to catch these bugs before the drivers shipped. Instead of just FAFO, Microsoft had the checker search systematically for ways the driver could violate the rules for interacting with Windows. The idea was to find the crash before the crash found you.
But what if you used the same tools to test the safety and security of rules themselves, not just computer code that implements them? Suppose everyone responsible for following the rules followed them exactly. Could an attacker still produce an outcome the rules were designed to prevent? If so, the bug isn’t in the software. It’s in the rules themselves.
Piskac went on to describe how David Basin at ETH Zurich and his colleagues did precisely this with EMV (Europay, Mastercard, and Visa), the protocol that governs chip and contactless credit-card payments. Its specification runs to more than 2,000 pages. Basin’s group built a formal model of the protocol and used Tamarin, a model checker designed for security protocols, to ask whether, with the card, the terminal, and the bank all following EMV’s rules, an attacker could still produce a transaction that EMV was supposed to prevent.
Guess what? They could.
The Tamarin checker found, among other things, that an attacker could use someone else’s Visa contactless card to make a purchase large enough to require a PIN, without knowing the PIN. The attack changed information passing between the card and the terminal so that the terminal falsely believed the cardholder had already verified their identity on their own device. Basin’s team built the attack into an Android app and tried it on real payment terminals. It worked.
I was thunderstruck, although I have never had much interest in stealing things with other people’s credit cards. What got my attention was how the attack had been found.
The checker had not cracked the cryptography. It had not guessed a password or discovered that somebody had left “admin123” lying around. It had found the flaw by taking the rules more seriously than their authors had. The vulnerability arose because the rules allowed the terminal to trust information that an attacker could alter.
Model checkers and theorem provers work differently, but they share a basic idea: Express the rules in logic and let the machine determine what follows. That’s what we did with Z3, the theorem prover discussed in my latest column, where it outscored GPT-5.5 on the computational portion of an actuarial exam.
Somewhere during Piskac’s explanation, however, I stopped thinking about credit cards.
My mind had turned to khaki pants.
J.Screw
J.Crew’s lawyers had discovered the legal equivalent of the EMV vulnerability: an opening in a set of rules that the people who wrote them never intended to leave open.
In 2016, J.Crew wanted to use its trademarks to restructure more than half a billion dollars of other debt. Unfortunately, it had already promised those trademarks to someone else. Its lenders held the trademarks as collateral, and the credit agreement barred J.Crew from giving that collateral away. But the agreement had exceptions, which finance lawyers call “baskets.” Two baskets let J.Crew invest up to $250 million in subsidiaries that did not guarantee the loan. A third basket allowed those subsidiaries to invest in “unrestricted” subsidiaries, beyond the agreement’s reach, using the “proceeds” of other permitted investments. So J.Crew moved a $250 million stake in its trademarks to a non-guarantor subsidiary in the Cayman Islands, which passed it along to an unrestricted one. Nothing in the agreement said the proceeds had to be cash, so J.Crew treated the trademarks themselves as proceeds that it was free to move around.
The maneuver became known as the J.Crew trap door, or more colloquially, the J.Screw. The name is apt. Nobody had written a provision into the agreement saying that J.Crew could take $250 million in trademarks securing its lenders, move them beyond the lenders’ reach, and use them to support other debt. J.Crew’s lawyers had found the path nonetheless. Perhaps unsurprisingly, their lenders were unpleasantly surprised.
The dispute ended without a definitive judicial ruling on the maneuver’s legality, after J.Crew offered to pay down $150 million of the term loan at par if the lenders dropped the litigation. The episode became sufficiently notorious that lenders began inserting provisions into new credit agreements known as “J.Crew blockers,” designed to prevent borrowers from pulling the same trick. (Lenders now bar moving material intellectual property to unrestricted subsidiaries.)
A lawyer could read each of the three baskets, understand it perfectly, and never notice what happened when they were combined. The loophole existed in the relationships among the rules.
Of course, lawyers have been finding loopholes for centuries. The interesting question is what happens when computers can find them too. A complicated contract might contain hundreds of operative provisions and definitions. A statute might contain thousands. Some possible paths require combining rules separated by hundreds of pages. A human lawyer searches some of those paths. A solver can systematically search the paths represented in its formal model, including paths that no human lawyer ever thought to explore.
Tax Exploitation
In my latest column, I described how we used our lab’s system, Leibniz, to translate insurance regulations into formal logic and then let the Z3 prover apply them. This is what we might call compliance. An insurer has a certain amount of overdue reinsurance. A taxpayer has a certain income and number of dependents. A company sent a notice on Tuesday instead of Monday. Facts in, legal consequences out.
But Basin and J.Crew were doing something different. They started with the outcome they wanted and worked backward. They wanted to know whether the rules left open some sequence of steps that would get them where they wanted to go. Call this exploitation. Instead of asking whether a particular situation complies with the rules, you ask what situations the rules allow you to create. You specify the destination and search for a path. Sometimes the path leads somewhere the designers of the rules never imagined.
Security researchers call such a path an attack. Lawyers call it a loophole. Either way, the same mathematical machinery can now find these paths.
I realize I have made exploitation sound sinister—and often it is. There is an enormous literature, and many expensive lawyers, devoted to deciding when clever use of legal rules stops being clever and becomes impermissible. Take one notorious example: When is the Office of Legal Counsel defining the reasonable boundaries of executive branch conduct under the law, and when is it justifying torture?
But exploitation, in the sense I am using the term, need not be bad at all. Nobody goes to a tax lawyer and says, “Please arrange my affairs so that I pay the maximum amount of tax legally possible.” Taxpayers contribute to retirement accounts, claim deductions, make elections, decide when to realize income, and structure businesses precisely because the tax code allows different choices to produce different tax bills. Lawyers call this tax planning (“tax exploitation” tested poorly with the IRS). The same is true of estate planning.
Now imagine doing this with a theorem prover. First, we translate the relevant provisions of the Internal Revenue Code into mathematical formalism known as first-order logic. Once the tax rules have been translated, we can use them for ordinary compliance. But Z3 can also optimize. The direction of reasoning can be reversed.
Instead of asking: Here are my facts. What tax do I owe?
You ask: Here are the facts I can’t change. What should I do about the rest?
The most interesting answers look like J.Crew’s in miniature. A deductible retirement contribution, for example, can pull your adjusted gross income below a threshold at which a tax credit shrinks or disappears, so that the contribution saves far more than the deduction alone would. Neither provision tells you that. You find it only by putting them together.
To be sure, tax law has its own defenses against exploitation. For example, under the economic substance doctrine, which Congress codified in 2010, a transaction that changes nothing meaningful apart from your tax bill can lose its tax benefits. Doctrines like this exist to catch some of the paths a solver might find. We could translate the economic substance doctrine into logic and tell the solver to enforce it. The problem is that the solver cannot independently determine whether a transaction has economic substance. That requires judgments about the real world that logic alone cannot supply.
But these anti-abuse doctrines are aimed at engineered transactions—things like tax shelters—not at the choices the tax code openly invites, like whether to file jointly or how much to put in a retirement account. Those choices are governed by rules all the way down. So, naturally, we formalized the rules and fed them to a solver.
The app opens with a sample household, a federal national-security lawyer married to a law professor, so you can just click “Find my minimum” and watch it work.
Ordinary tax software mostly calculates what you owe based on the choices you’ve already made. This app, by contrast, looks for choices you might not have considered. Your figures go to our server only to run the solver; we do not store them. The results aren’t legal advice. The solver applies the rules we have translated and searches for the best arrangement they allow.
Which brings me back to Piskac’s classroom, and the Future. Exploitation has a mirror image. Instead of asking the solver to find a path to an outcome, you ask it to prove that no path exists. Call this verification. Microsoft eventually stopped waiting for drivers to crash Windows and started checking them against the rules before they shipped. Basin’s group showed the same thing could be done for credit card protocols. Their paper is titled “The EMV Standard: Break, Fix, Verify.” After finding the attacks, they proposed fixes and proved that, in their model, the repaired protocol met every security property they checked, against any attacker.
Lenders did it the old-fashioned way: They nailed the trap door shut after having fallen through. But nothing stops the people who write rules, whether legislators, regulators, or the lawyers who draft credit agreements, from running the solver first and finding the trap doors before others fall through. Pioneering work in this direction has been done by Sarah Lawsky and by Denis Merigoux and his colleagues on the Catala project. But such efforts remain rare. The rules still get debugged the way Windows drivers once were: by waiting for the Grim Reaper to turn your screen blue or for $250 million in collateral to disappear.
In the meantime, you might as well have some fun and find a few exploits of your own.
