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