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