Launch app
Cover: Fix the invariant, not the instance

Fix the invariant, not the instance

Why does a class of problem call for one fix, not one fix per occurrence?

A correction is written as a property that closes the whole class, with a test over the class and its own mutant. The shape of such a fix, shown on one invariant that many routes share.

Known formally as Fix the invariant, not the instance in the BlazePhoenix whitepaper.

BlazePhoenix Engineering · article updated 2026-11-16 · site dataset through 2026-11-30 · 6 min · written from the deployed bytecode

By Mitra (@Sigmacrit) — anonymous developer of the BlazePhoenix protocol. The code is the résumé.

Abstract in 15 languages · resumo · resumen · 摘要 · 要旨 · ملخص

English — The instance is not the finding: the finding is the invariant that failed to hold, and the instance is one place it failed. A fix that states the invariant, puts the guard where every instance of the class passes, and arrives with a test over the class and its own mutant resolves many instances with one fix and refuses the next one by construction.

Português — A ocorrência não é o achado: o achado é o invariante que deixou de se verificar, e a ocorrência é um sítio onde falhou. Uma correção que enuncia o invariante, coloca o guarda onde passa toda a ocorrência da classe e chega com um teste sobre a classe e o seu próprio mutante resolve muitas ocorrências com uma só correção e recusa a seguinte por construção.

Español — La instancia no es el hallazgo: el hallazgo es el invariante que dejó de cumplirse, y la instancia es un lugar donde falló. Una corrección que enuncia el invariante, coloca el guarda donde pasa toda instancia de la clase y llega con una prueba sobre la clase y su propio mutante resuelve muchas instancias con una sola corrección y rechaza la siguiente por construcción.

Français — L'instance n'est pas la trouvaille : la trouvaille est l'invariant qui a cessé de tenir, et l'instance n'est qu'un endroit où il a failli. Un correctif qui énonce l'invariant, place le garde là où passe toute instance de la classe et arrive avec un test sur la classe et son propre mutant résout de nombreuses instances avec un seul correctif et refuse la suivante par construction.

Deutsch — Die Instanz ist nicht der Befund: Der Befund ist die Invariante, die nicht gehalten hat, und die Instanz ist eine Stelle, an der sie versagt hat. Ein Fix, der die Invariante formuliert, den Guard dort platziert, wo jede Instanz der Klasse durchläuft, und mit einem Test über die Klasse und einem eigenen Mutanten kommt, löst viele Instanzen mit einem Fix und weist die nächste konstruktionsbedingt zurück.

Русский — Экземпляр — не находка: находка — это инвариант, который перестал выполняться, а экземпляр — лишь одно место, где он нарушился. Исправление, которое формулирует инвариант, ставит защиту там, где проходят все экземпляры класса, и приходит с тестом на весь класс и собственным мутантом, закрывает множество экземпляров одним исправлением и по построению отклоняет следующий.

Türkçe — Örnek bulgunun kendisi değildir: bulgu tutmayan değişmezdir (invariant), örnek ise onun bozulduğu bir yerdir. Değişmezi ifade eden, korumayı sınıfın her örneğinin geçtiği yere koyan ve sınıfı kapsayan bir testle ve kendi mutantıyla gelen bir düzeltme, birçok örneği tek düzeltmeyle çözer ve bir sonrakini yapısı gereği reddeder.

العربية — الحالة المفردة ليست هي الاكتشاف: الاكتشاف هو الـ invariant الذي لم يصمد، والحالة المفردة مجرد موضع واحد فشل فيه. والإصلاح الذي يصوغ الـ invariant، ويضع الحارس (guard) حيث تمر كل حالة من الفئة، ويأتي باختبار على الفئة كلها وبـ mutant خاص به، يعالج حالات كثيرة بإصلاح واحد ويرفض الحالة التالية بحكم البناء.

हिन्दी — उदाहरण खोज नहीं है: खोज वह invariant है जो टिक नहीं पाया, और उदाहरण बस वह एक जगह है जहाँ वह टूटा। जो फ़िक्स invariant को कहता है, गार्ड वहाँ रखता है जहाँ से उस वर्ग का हर उदाहरण गुज़रता है, और पूरे वर्ग पर टेस्ट तथा अपने म्यूटेंट के साथ आता है, वह एक ही फ़िक्स से कई उदाहरण सुलझा देता है और अगले को बनावट से ही अस्वीकार कर देता है।

日本語 — 個々の事例は発見そのものではない。発見とは成り立たなかった不変条件であり、事例はそれが破れた一か所にすぎない。不変条件を明示し、そのクラスのすべての事例が通る場所にガードを置き、クラス全体を対象としたテストと専用のミュータントを伴う修正は、一つの修正で多数の事例を解決し、次の事例を構造上拒否する。

中文 — 个别实例不是发现本身:发现是未能成立的不变量,实例只是它失效的其中一处。一个修复若陈述该不变量,把守卫放在该类别所有实例的必经之处,并附带覆盖整个类别的测试和专属的变异体,就能用一个修复解决许多实例,并从构造上拒绝下一个实例。

한국어 — 개별 사례는 발견 자체가 아닙니다. 발견은 성립하지 못한 불변식이고, 사례는 그것이 깨진 한 곳일 뿐입니다. 불변식을 명시하고, 그 부류의 모든 사례가 지나가는 곳에 가드를 두며, 부류 전체에 대한 테스트와 전용 뮤턴트를 함께 내놓는 수정은 하나의 수정으로 많은 사례를 해결하고 다음 사례를 구조적으로 거부합니다.

Bahasa Indonesia — Kejadian tunggal bukanlah temuannya: temuannya adalah invarian yang gagal bertahan, dan kejadian itu hanyalah satu tempat ia gagal. Perbaikan yang menyatakan invarian, menaruh guard di tempat semua kejadian dalam kelas itu lewat, dan datang bersama tes atas seluruh kelas serta mutannya sendiri, menyelesaikan banyak kejadian dengan satu perbaikan dan menolak kejadian berikutnya secara konstruksi.

বাংলা — একটি ঘটনা আবিষ্কার নয়: আবিষ্কার হলো যে invariant টিকে থাকেনি, আর ঘটনাটি কেবল সেই এক জায়গা যেখানে সেটি ভেঙেছে। যে ফিক্স invariant-টি বলে দেয়, গার্ড সেখানে বসায় যেখান দিয়ে ওই শ্রেণির প্রতিটি ঘটনা যায়, এবং পুরো শ্রেণির ওপর টেস্ট ও নিজস্ব মিউট্যান্টসহ আসে, সেটি একটি ফিক্সে বহু ঘটনার সমাধান করে এবং পরেরটিকে গঠনগতভাবেই প্রত্যাখ্যান করে।

Filipino — Ang kaso ay hindi ang natuklasan: ang natuklasan ay ang invariant na hindi nanatili, at ang kaso ay isang lugar lang kung saan ito nabigo. Ang fix na nagsasaad ng invariant, naglalagay ng guard kung saan dumaraan ang bawat kaso ng klase, at dumarating na may test sa buong klase at sariling mutant, ay nilulutas ang maraming kaso sa isang fix at tinatanggihan ang susunod sa pamamagitan ng disenyo.

The short answer

Because the instance is not the finding. The finding is the invariant that failed to hold, and the instance is one place it failed. A patch to the instance restores that place and leaves every other place the same class can occur. A fix that states the invariant, puts the guard where every instance of the class passes through it, and arrives with a test over the class resolves N instances with one fix, one test and one watcher, and refuses the next instance by construction.

The shape of a class-level fix

  1. State the invariant that failed, as a property that holds in every reachable state.
  2. Place the guard where every instance of the class passes, not where the first one was seen.
  3. Write the test over the class: a fuzz or invariant campaign, not a fixture for the one input that exposed it.
  4. Name in the test header the commit at which it was red, so red-before-green is checkable from the history.
  5. Give the guard its mutant: the one-line change that must turn the test red (see the article on guards that cannot fire).

One invariant, many routes

Take a property every route must keep: the Router holds nothing when a swap ends. A fix written per route would need a separate check for each shape. The repository states it once as an invariant and exercises it over every shape of route.

Route shape exercisedInvariantFile (under test/)Line
The Router's own invariant suiteinvariant_RouterHoldsNothingBlazePhoenixRouter.invariant.t.sol402
Adversarial single routeinvariant_routerHoldsNothingRouterAdversarialInvariantFromV1.t.sol328
Adversarial multi-hopinvariant_routerHoldsNothingRouterAdversarialMultiHopFromV1.t.sol128
Adversarial V4invariant_routerHoldsNothingRouterAdversarialV4FromV1.t.sol287
Multi-hopinvariant_routerHoldsNothingRouterMultiHopInvariantFromV1.t.sol131
Split across legsinvariant_routerHoldsNothingRouterSplitInvariantFromV1.t.sol121
Stranded-money regimeinvariant_HoldsNothingBeyondTheSeedStrandedRegime.invariant.t.sol315

Source: Project facts sheet 2026-11-16 (DEX at 969bcc6)

What this method does not do

It does not turn an invariant into a proof of the whole contract; an invariant covers the class it states, and its register of mutants says which changes it notices. The method is a way of making each correction cover more than the place it was found, and of making that coverage checkable.

Check it yourself

  1. Check out Blaze-Phoenix-Dex at 969bcc6 and run git grep -n -i "holdsnothing" -- test.
  2. Open two of the files in the table and compare how each reaches the same property through a different route shape.
  3. Read the header of a test and find the commit it names.
  4. Read section 2.8 of the whitepaper and compare it with the file you opened.

Do not trust this page — reproduce it

Every claim above is checkable against the chain. Start here:

In a clean checkout of Blaze-Phoenix-Dex at 969bcc6: git grep -n -i "holdsnothing" -- test (the files and lines in the table, among them test/BlazePhoenixRouter.invariant.t.sol line 402); forge test --match-test invariant_ --fuzz-seed 0xb1a2ef00 (the stateful campaigns, Appendix C). Whitepaper 2.4: section 2.8.
Cite this article

Licensed CC BY-NC-ND 4.0: quote and cite it with attribution and a link. Commercial use and derivative versions need written permission from BlazePhoenix; translations are made by BlazePhoenix. Copy a ready-made citation:

BlazePhoenix (2026). Fix the invariant, not the instance. BlazePhoenix Engineering. https://blazephoenix.xyz/learn/fix-the-invariant-not-the-instance/
@misc{blazephoenix_fix_the_invariant_not_the_instance,
  title  = {Fix the invariant, not the instance},
  author = {BlazePhoenix},
  year   = {2026},
  url    = {https://blazephoenix.xyz/learn/fix-the-invariant-not-the-instance/},
  note   = {Accessed: reproduce the claim with the command above}
}

Writing an answer, a wiki entry or a paper? The claim above is reproducible against the chain before you quote it — which is the only sound basis for citing a technical source at all.

Contracts are verified on every chain we deploy to — addresses in the protocol manifest. Deeper formal treatment: the whitepaper (PDF).

Related engineering

Next in Invariants & security · 1 / 18
EIP-1153 transient storage: route context that cannot outlive the transaction ›Where BlazePhoenix uses transient storage (TSTORE/TLOAD): reentrancy locks and fee-on-transfer flags that the EVM clears at transaction end, and that the Router also resets itself before a later call in the same transaction can read them.5 min

Questions, a partnership or a bug to report? Contact us or email contact@blazephoenix.xyz

Go to APP