DSS 2026 / Day 2 / Amber Hall
The Callback Window
Jochen Hoenicke
Source: YouTube automatic caption track · Exported 2026-11-16. Timestamps link to the source video. Cue end times were not supplied.
Transcript
0:00corresponding market.
0:02And important here is losses are
0:04isolated to a market. There can be it's
0:06a lending protocol if one token
0:09loses value,
0:10then there are losses and you want to
0:14um keep them
0:16in the market.
0:19So
0:21one important property that we wanted to
0:23verify is that you cannot put yourself
0:25into debt
0:27without putting collateral in there. So
0:29what we first did is we defined what is
0:32the maximum debt that you can put in
0:33there,
0:35which is collateral times the price and
0:37then you have to account for over
0:39collateralization, which is the LTV, the
0:41ratio at which liquidation starts. And
0:44if you put in less debt than the maximum
0:47debt, then you are healthy.
0:49And you can only be liquidated if you
0:51are not healthy or past maturity.
0:56And uh yeah, as long as you are healthy,
0:58there can be also no shortfall.
1:01Uh so there can't be bad debt because
1:03the collateral is worth more.
1:07And the guarantee that we want to give
1:09in the protocol is if you are healthy at
1:11some point and you
1:13do any trans uh action on the market,
1:15you're still healthy afterwards.
1:18So you can't
1:19for example make a debt uh without
1:22putting in collateral.
1:24And also other people cannot
1:26um make your position liquidatable.
1:30What we really want is that you that
1:33there is no bad with debt without sudden
1:35price movements. So the invariant is of
1:38course not a real invariant. It can
1:40happen that you get unhealthy by price
1:42movement.
1:43So the assumption that we use to prove
1:45this property is that the prices don't
1:47change.
1:49So
1:50here's how the protocol
1:53the take function
1:55works. It's a very simply
1:57fied version.
1:58So they use the fry P pattern, you can
2:01say is check, act, interact, and check
2:04again.
2:05So at the beginning, you check that all
2:07the preconditions are true, that the
2:10offer is still valid. Then you do the
2:13actions. You change the credit and the
2:14debt.
2:15Then there is interaction with other
2:17protocols, so you transfer the tokens
2:21and you can all There's also some
2:22callbacks because this is an order book.
2:25And the
2:27other person, the maker, could
2:29have put the order long ago, and he
2:31didn't put in the collateral because he
2:33didn't put the debt.
2:35So this is the time where the
2:39where the maker can react to your taking
2:42offer and
2:43actually put in the collateral.
2:46So in the on-sell,
2:48this is important in this talk. You can
2:50add the collateral.
2:51And
2:53yeah, you can even use the cash
2:55that you get from selling your loan.
2:59And in the end, you check that the
3:00protocol is healthy. So this is a
3:03pipe part of the fry-p-pattern. You
3:05check again.
3:07And you only check the healthiness at
3:09the end.
3:11And this is
3:13safe because
3:15you can't
3:16go over this check. It's like a flash
3:18loan. If you
3:19don't be healthy at the end, then
3:23the transaction reverts and you never
3:24got the money in the first place.
3:27So during the on-sell, the borrower has
3:29the cash, the debt, but he cannot run
3:32with the cash because he has to exit
3:35this function normally.
3:39So how do we prove health? We write an
3:41invariant.
3:42So invariant means it suits all the
3:44time.
3:45This is only true under the assumption
3:47that the Oracle prices don't change.
3:50And what you write is invariant, and
3:51what the prover checks is if the
3:54user is healthy before any operation on
3:58the contract, and you do the operation,
4:00then the user is healthy afterwards.
4:03And if prove this, you know that after
4:04every transaction the user is healthy.
4:08However, if you have these callbacks,
4:11you also want to be reentrancy safe. So
4:13what you also check is whether the
4:16invariant holds at the callback time.
4:19And you do this by adding another
4:20keyboard strong.
4:22And then the invariant is also checked
4:25when you do an external call and the
4:27external call is now uh checking the
4:30healthiness, then it models basically
4:32any interaction with the contract
4:34by saying this havoc. This means every
4:36variable can change and then you require
4:39that uh the
4:40protocol is healthy again with this
4:42assumption that you only can interact
4:45with the pro uh with with the contract
4:47in a way that you stay healthy. So this
4:50is an inductive argument that this
4:51holds.
4:53So the strong invariant checks also at
4:56the on by and the on cell time. And if
4:59we check this with the Satori prover, we
5:01get a contact sample.
5:03And uh the contact sample is basically
5:05you make a loan.
5:07Your
5:08on cell
5:09is called
5:11and the healthiness check is violated.
5:16So
5:17this is by design of the protocol.
5:20So in the on cell callback you want to
5:23be unhealthy because this is the time
5:24where you put in the collateral to
5:27fulfill the healthiness check at the
5:28end.
5:29So this is clearly spec is too strong.
5:33So we thought about this, what do we
5:35need to change to actually prove the
5:37contract still correct?
5:40And it turned out after thinking about
5:42this,
5:43the thing that you need to avoid is that
5:46bad debt happened now at this point.
5:49And this led me to the question, what
5:51happens if you liquidate at this point?
5:53And I asked this on the channel, can you
5:56liquidate yourself in the callback and
5:59create debt bad debt for the protocol?
6:01And afterwards, when the bad debt is
6:04created,
6:05you make yourself healthy again and then
6:07everything is fine. The transaction
6:09doesn't revert
6:11and you have the money and
6:14your bad debt was written off.
6:19And yeah, there was
6:2115 minutes later I got the answer. Yes,
6:24it's indeed a problem of the protocol.
6:27So yeah,
6:29they liked this finding. They didn't
6:31expect this. It's a critical bug. You
6:34can basically make a loan for free.
6:37And it basically also put the whole fry
6:40p pattern into question if this
6:45yeah, you can't just use it. You have to
6:47argue why it's safe and in this case it
6:49wasn't safe.
6:51So the conclusion is this counter
6:52example that we found is not spurious.
6:56So yeah, and we found this before the
6:58first audit, seven weeks before the
7:00first audit. So
7:02it was time enough to fix this for the
7:04audit.
7:07So what how does this attack look? So
7:09you have a an evil borrower and he wants
7:12to attack the protocol. So he takes a
7:15loan. Let's say he just chooses one of
7:17the offerings of $1 million.
7:20And then he yeah, takes the loan. The
7:23protocol sends the money without the
7:25interest.
7:27And
7:28then the on sale callback is called
7:30where the attacker should now
7:33put in the collateral. But instead of
7:35putting in the collateral,
7:37the callback would just call the
7:39liquidate function and liquidate
7:42the
7:43caller himself.
7:45And what happens now is that the bad
7:47debt is written off and the
7:50caller of liquidate needs to pay for the
7:52collateral.
7:53But since there is no collateral, he
7:55doesn't pay anything. He pays zero and
7:59the full bad debt is written off.
8:03The callback succeeds.
8:05Now the user's healthy. He doesn't have
8:07any debt anymore, the attacker.
8:10So he's healthy, the transaction
8:12succeeds.
8:13And what happens is 960k USDC is sent to
8:18the attacker. He didn't put any
8:19collateral
8:21and uh the debt is already written off
8:24and the people that are hurt are the
8:26other lenders who now get less money out
8:29of the contract.
8:33So
8:35we thought about this, how can we close
8:37this protocol? Uh how can we close this
8:40callback window? And there were three
8:43possible solution.
8:45One is you book the debt after the
8:47callback.
8:48This is a kind of a trick um by
8:52not updating the debt before the
8:54callback, you don't have debt during the
8:56callback, so you are healthy.
8:59And uh this would in principle work,
9:03but it has some problems because yeah it
9:07it doesn't match the pattern. You want
9:08to do all the modification before the
9:11callback.
9:12And also it's the talk to means time of
9:16check versus time of use. If you do all
9:19the checks before the callback, then you
9:21do the callback, then the callback may
9:23invalidate all your checks. So you have
9:26to do the checks again and it was kind
9:28of messy. So
9:30um we implemented this but decided in
9:33the end to not go this way.
9:35Instead what we did is use liquidation
9:38locks.
9:40And there was a possibility of doing it
9:42globally or per position and in the end
9:44we decided to do it per position because
9:47it's uh least restrictive.
9:50And what we how this looks is in the
9:53take function
9:54you surround this interaction phase
9:57by putting a lock on the position.
10:02And after the wards you unlock again
10:06unless it wasn't locked before, so you
10:08keep the lock as it is and the uh
10:12the protocol invariant also changes
10:14because now if you are locked, you don't
10:17need to be healthy because you can't be
10:19liquidated.
10:22And the lock is in transient storage, so
10:25it's only visible during the
10:27transaction.
10:28And the other change which is not on the
10:30slide is the liquidate function. You
10:32check that the position is not locked
10:34and if it's locked you revert. So if you
10:36play back the same attack here,
10:39the liquidate function would just say
10:40it's not liquidatable revert and then
10:43the whole transaction reverts.
10:47So you can't write off bad debt.
10:50So
10:52yeah, the next question is can we now
10:54prove that the protocol doesn't have
10:57this problem anymore?
11:00And so we reproved the property and
11:02instead of having the invariant, the
11:04strong invariant is healthy, we now have
11:07a weaker invariant. It's either
11:10healthy or locked.
11:12And this invariant also holds during the
11:14callbacks.
11:16And this strong invariant is
11:19weaker than is healthy, but it's strong
11:21enough to prove that there is no bad
11:23debt because there are two cases
11:26basically if the position is healthy,
11:28there is no bad debt because of over
11:30collateralization.
11:32And if the position is locked,
11:34then the liquidate function reverts
11:36immediately, so it cannot
11:39put any bad debt in there.
11:42And we prove both properties formally
11:45with our prover.
11:46And now we know that there is no bad
11:48debt.
11:50Of course, there could be another
11:52problem here, namely
11:55the locking could prevent liquidations
11:58that that are necessary. So you
12:00want also to show
12:02that the lock is
12:05never leaking out of the transaction.
12:09And so for this we proved a weak
12:10invariant and the weak invariant only
12:12holds at the beginning and the end. It's
12:15basically without the strong keyword,
12:17but we also have the weak keyword to
12:19clarify this.
12:21And so outside the transaction we now
12:23have the invariant not locked.
12:25And with this weak invariant we can
12:28actually also prove that the user is
12:30healthy after every transaction.
12:35And to prove this weak invariant we
12:37needed another property
12:40to formally prove it. And this was that
12:44the lock status never changes during a
12:46transaction.
12:47So for this we wrote another rule
12:51which proves that if you take the lock
12:53status before it
12:55any operation then you do any operation
12:57of the contract
12:59the lock status stays the same.
13:01And using this rule you can assume
13:05that the callbacks the callback summary
13:08where we havoc
13:09will also ensure this property that the
13:11lock status never changes.
13:13And then you can argue by induction
13:16that this is now
13:18a sound reasoning that the contract is
13:20locked after the transaction.
13:25So
13:26this is one of the property that we
13:28showed this is healthiness, but we
13:31actually proved many more properties in
13:33the end. So another important property
13:36is solvency.
13:38This consists of two parts. First, there
13:40are enough tokens in the contract to
13:43cover all the collateral and other
13:46obligations, the fees and
13:48the already
13:50repaid loans.
13:52And then you have the other solvency
13:54which basically says that the debt
13:57should cover the credits. So if you are
14:00borrowing money there should be another
14:02person owing you money.
14:04So the debt plus was was already paid
14:07back, the withdrawable should be greater
14:09equal than the total credit.
14:12And
14:13these are the important solvency
14:15invariants we proved. Another invariant
14:17we proved is isolation. So if you have
14:20multiple markets, then and one market
14:23suffers losses, then it doesn't affect
14:25any other market. And this is basically
14:28shown by locality.
14:31And then we have liquidation properties
14:34that you can always liquidate positions
14:37which also uses the fact that you are
14:41not locked outside the transaction. So
14:43it's always possible to liquidate an
14:45unhealthy
14:47transaction. So all in all, Morpho
14:51together with us
14:53worked on the spec and it's over 50 spec
14:56files, over 300 rules.
15:00So
15:02and we also looked into other protocols
15:05when we found this bug to figure out if
15:07they have this similar problems.
15:09And it turns out
15:11they all don't have any problems,
15:14but for different reasons.
15:17So Uniswap before is of course not a
15:20lending protocol, but it also has this
15:22feature that you can
15:25basically swap before putting in the
15:28tokens. And you want to be sure that
15:30it's good at the end.
15:32And their invariant
15:35they have a protocol invariant basically
15:38that
15:40there should be no debt outside of
15:42transaction. So the only broken
15:44invariant during the callback is that
15:47there is a temporary debt.
15:49And so it's like a flash loan and
15:51nothing can forgive the debt and it's
15:53checked at the end similar to the take
15:55function.
15:56And Morpho Blue
15:58the same problem didn't happen because
16:00they do it the other way around. You
16:02first put in the collateral and then you
16:04have a callback where you can make the
16:06debt using the collateral.
16:08But the collateral is only put in after
16:11the callback. So you don't
16:13use you can still make the debt without
16:17putting the collateral first.
16:19But it's like a flash loan.
16:21And Aave V3 also has the flash loan
16:23feature, and they actually update the
16:26debt
16:27after the callback.
16:29So if you don't repay the flash loan,
16:31they update the debt and it's similar to
16:33the solution A.
16:35So for them this solution was the one
16:37they chose.
16:39For Aave V4 I think they decided to not
16:41use any flash loans because they
16:44yeah were not happy with other protocols
16:47being exploited by their flash loans, so
16:49they just disabled this feature.
16:52And for Euler V2 it's very similar to
16:55Morpho Midnight.
16:56There is the broken invariant that the
16:59account is unhealthy during all the
17:01callbacks, but they also have a lock for
17:03the vault. So if the vault is currently
17:06in operation then you can't liquidate
17:09it.
17:11So yeah all in all the callback window
17:13is safe if you care for
17:17this and if you make sure that the
17:18broken state is repaid at the end and if
17:21you don't allow any permanent losses.
17:24And this was the problem here that
17:27writing off the debt is permanent.
17:30So takeaways.
17:34First this
17:35cannot be used as is. This is basically
17:38what was in the chat message. You have
17:40to think about your protocol invariant
17:43if they are just
17:45necessary at the end of your transaction
17:48or if other functions that you can call
17:50from the callback rely on these
17:52invariants. So in this case the problem
17:54was that the liquidate function relies
17:57on the healthiness property. If you're
17:59not healthy then
18:00bad debt is written off immediately and
18:02so you must prevent this reentrancy into
18:05the liquidate function.
18:07And in this this case we did it by a
18:09lock.
18:12Yeah in general you should always check
18:14invariants where control leaves. So
18:18yeah
18:19in this case we found problem because we
18:22checked the strong invariant is healthy
18:24and figured out it was broken and then
18:27we
18:28thought
18:29can we still prove that the protocol is
18:32correct and then we found out that there
18:34is a bug. So if we would just have
18:36stopped at the weak invariant, we
18:38wouldn't have found the bug. So it's
18:39important to use these strong invariants
18:42and check them every time you have an
18:44interaction.
18:46And
18:48yeah, if you change the spec,
18:50you also need new proofs.
18:53For example, if you
18:57yeah,
18:58to prove that liquidation does not
19:00revert, which is an important property
19:02of the protocol, you need to show that
19:05your position is not locked.
19:08And to prove that your position is not
19:10locked, you need to prove these other
19:12rule that any function doesn't change
19:16the lock status.
19:18And if you do all this, then you have an
19:21inductive proof, formal proof that your
19:24protocol is correct.
19:27And never ignore a counter example
19:30because they seem to be the spec seems
19:33to be too strong.
19:35Think about it, why is the protocol
19:37still correct?
19:39And if you think have any doubt, ask the
19:42developers. And yeah, we asked the
19:44developers, we
19:47figured out there is a bug and we could
19:49fix it before even before the first
19:51audit.
19:55Yeah, I want to say
19:57thank you
19:59and want to say this is also a team
20:01effort. So
20:03I didn't do all the roots myself, so
20:06Morpho
20:09has several people working on formal
20:11verification. There's also Mati and
20:14Adrien who worked on fixing this bug in
20:17the Solidity part and
20:20Quentin Bagard and Anty
20:23wrote the
20:25part of the formal verification rules.
20:28And from the Setora side, Lilyong was
20:30working on it.
20:32So here is
20:34yeah, the link to the repository if you
20:36want to see the full formal
20:38verification.
20:40Yeah, thank you for your attention.
20:43>> [applause]
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: 2b02fb589c4c9f48df4df3cf18f198f7b9dd3b20e7bb1aa2c9fee0354fd0230f