DSS 2026 — The Queue Is the Protocol: Finding DeFi Liveness Bugs with Stateful Invariants Clément Moller Source video: https://www.youtube.com/watch?v=tkVU2Fy92PM Automatic captions — not human-reviewed. Complete spoken-audio coverage is unverified. Source language tag: en (English). Source export SHA256: abaac9bb878e97b37cc5bcc444bb8fbd4f4937248559bee08f8c2ccdab8eedb5 [0:00] Test test yeah. [0:03] Okay so everyone thanks a lot for being [0:05] there. I'm Clement Molaire I'm working [0:09] as a smart contract developer at Origin [0:11] Protocol for more than two years and [0:14] while writing smart contract I write the [0:15] invariant testing too and that's the [0:17] subject of the talk today. I will talk [0:19] you a bit how we [0:21] write smart contract at Origin and a [0:23] quick story about how we miss some bugs [0:25] sometimes on the smart contract [0:27] themselves. [0:29] So you take natives so Alice is a [0:31] liquidity provider in one of our vault [0:34] and she deposits money on this and now [0:36] she want to withdraw so she make a [0:38] request withdraw the request matures so [0:40] now she will [0:41] she will get out there is enough [0:43] liquidity on the vault the request is [0:45] mature everything is fine. [0:47] Alice click on the claim but the claim [0:49] reverts [0:50] so there is an issue. [0:51] We have all the invariant that are all [0:53] green 18 properties the balance are all [0:55] good the vault is still solvent there is [0:58] still 90 ETH on the vault so where is [1:00] the issue? That's the story of that's [1:02] that's [1:03] the purpose of this talk. [1:05] So [1:06] we have 18 properties 18 invariant [1:08] properties they are all green about [1:10] total supply total shares shares across [1:12] users the queue [1:14] the the fee the reserve liquidity [1:16] everything everything is all green. [1:18] But there is one issue is this is that [1:20] all the property here at what we call [1:22] safety properties. [1:23] A safety properties is here to say that [1:25] a value a number is correct and it still [1:27] makes sense at the moment that we are [1:29] checking it. It's the purpose of the [1:30] invariant but here we are missing one [1:32] thing we are missing the fact that an [1:35] action should be still possible and [1:36] that's what we call a liveness property [1:38] in different with the [1:40] in difference with the safety property. [1:42] A liveness property in this situation is [1:44] okay at any time when the request is [1:46] mature and there is enough liquidity on [1:47] the vault Alice can leave and that's the [1:50] subject that's what is missing here. [1:53] So what are we missing? [1:54] So this is the handler of the of the [1:57] invariant. [1:59] You have to know that origin, every time [2:01] we write smart contract and invariant, [2:03] we set the fail on revert set to true [2:05] every time. Uh fail on revert just say [2:07] that if there is one thing that reverts [2:08] on the on the transaction, or the whole [2:12] invariant will fail. [2:13] Okay. So this is the handler. And what [2:15] is the handler doing? So he is basically [2:17] checking if the vault can if if this is [2:19] claimable, and then we bypass if we have [2:22] this. And that's what our our that's why [2:25] we miss the test. We miss it, we miss [2:26] the issue on the test. Why do we have [2:28] this? [2:30] Uh yeah, because the test has the vault [2:32] if Alice could leave, and the vault say [2:33] no. But we are on the test, not on the [2:35] vault there. So why do we have this [2:38] uh this check? We have this check [2:40] because of the fail on revert. Because [2:41] we have to add a guard to avoid this [2:44] failing every time. So we add this [2:46] simple guard. But that's where we have [2:48] the problem. The guard should not be [2:49] from the vault on the view. [2:52] So how do we fix this? [2:54] You should have your own model, and you [2:56] should not rely on the vault model [2:57] itself. You should have your own model [2:59] based on the ghost variable. So the [3:01] ghost variable is really simple. It's [3:02] just something that tracks how much we [3:04] owe to Alice. [3:05] Uh that that tracks how much liquidity [3:07] we have free in this vault. And then at [3:10] after each call, you should have a look [3:12] at your own model, and your own model [3:14] should say, okay, Alice can can withdraw [3:17] now. [3:18] So yeah, our model should make now the [3:21] decision, not the vault anymore. And the [3:23] vault must now agree. That is the this [3:25] is the new uh [3:27] way that we are doing it. [3:29] The truth come from the from our model [3:31] now, not from the vault anymore. [3:34] Uh but I have to be honest, I almost [3:36] drop almost drop this talk last month [3:38] because I thought it was not relevant [3:39] anymore. AI is writing all the handlers [3:42] now and way faster than I do. [3:44] Uh but AI is still writing things like, [3:47] okay, skip is not claimable. [3:50] Be why? Because it is [3:52] really simple, it's idiomatic, it works [3:54] well, and it make the test pass. That's [3:56] all the AI like. [3:58] And [3:59] AI should not be the one that decide if [4:01] someone can leave the vault. AI should [4:04] not be the one that decide what is [4:05] liveness property. [4:07] So who may leave and when is the spec. [4:09] And the spec is still our job. [4:13] So for your next audit, if you have to [4:15] write invariant for a vault with an exit [4:18] queue, you can you can take a picture of [4:19] this of this one is the all the useful [4:22] properties that we check. All the first [4:24] the first four properties are properties [4:27] about [4:29] are safety properties. Most of the [4:31] protocol use this, we use this, but we [4:32] are missing some bugs sometimes. [4:35] The bugs stay on the fives and six. [4:39] Fives and six are the good ones to find [4:41] new bugs. [4:43] Fives should use the vault model, [4:46] not the not the vault model. The fives [4:48] should use your own model. And the last [4:51] advice is after every [4:53] call that you have made, make a bank [4:55] run. Make everyone with [4:57] run away from your vault and try to [4:58] withdraw. And this is how you secure [5:01] your smart contract. [5:03] Thanks a lot for your attention.