DSS 2026 — Formal Verification of Stake Pools: From General Design to a Real-World Application Kevin Lotz Source video: https://www.youtube.com/watch?v=hW406CR7Tnc Automatic captions — not human-reviewed. Complete spoken-audio coverage is unverified. Source language tag: en (English). Source export SHA256: 7e583abd9188723eb4a0490ab392a44bb18add0ef6738ec9caa5056ff1647adf [0:00] Okay. [0:01] Uh thanks for the introduction. Hi [0:03] everyone. My name is Kevin. [0:05] I work as a formal verification [0:06] researcher for Cetora and yeah, [0:09] as was introduced, [0:10] I want to talk in the next 15 minutes [0:12] about [0:13] formal verification of stake pools. [0:15] I'm keeping it fairly abstract, so I'm [0:17] starting with general design of what [0:19] stake pools are, so mental model of the [0:22] moving parts and of the one of the [0:25] arguably most important invariants that [0:27] stake pools should guarantee you. [0:30] From there on, I'm going to go to a [0:32] concrete implementation that we formally [0:33] verified at Cetora and the outcome of [0:36] this formal verification was that we [0:38] found [0:39] security bug, a high severity one that [0:41] was lingering around for a couple of [0:42] years and survived multiple audits. [0:46] Okay. [0:47] Let me Well, [0:49] okay, there we go. [0:51] Yeah, so first a quick primer on what's [0:53] what I mean by stake pools. I think the [0:55] concept is pretty simple. [0:57] So you have some assets and you want to [0:58] stake them, but you don't want to go to [1:00] a single validator directly, so you can [1:03] go to a stake pool and it much like [1:05] behaves like a [1:07] like a standard vault. So users deposit [1:10] their assets into the stake pool, they [1:11] lend in their reserve and the stake pool [1:14] means back shares proportional to [1:16] whatever you deposited into it. [1:19] But then on top of that, there's some [1:20] kind of operator that moves the funds [1:23] out of the pool to one or multiple [1:26] validators where they can experience [1:28] slashing, but hopefully they only earn [1:31] rewards. So at the later point in time, [1:33] users can redeem their shares and get [1:35] back hopefully more than what they put [1:37] into the pool in the first place. [1:40] So that's [1:41] that's the general idea of stake pools. [1:44] And whenever we see something that [1:46] resembles vaults in any shape, what we [1:49] tend to prove is or what we [1:51] try to verify is an invariant called [1:53] solvency. [1:55] So what this means basically is that the [1:57] shares that are issued at the moment [1:58] these are always less than or to the [2:00] extractable value and then the case of [2:02] stake that is [2:04] whatever is in cash in the reserve plus [2:06] the current value at the validators that [2:08] are staked so including the rewards. [2:11] We ignore [2:12] slashing because that's the only [2:14] exception that can break solvency so for [2:16] for that invariant we simply ignore it. [2:19] And so what this says is if everybody [2:21] was to redeem their shares at once now [2:24] at the same time then there would be [2:25] enough value in the pool to honor every [2:28] share. [2:29] We tend to prove this because it [2:32] it covers many classes of bugs at once. [2:34] For example if you mint too many shares [2:36] on on the deposit due to a rounding [2:39] issue or some kind of fee setup that is [2:41] that is not correct then you will [2:43] probably find this [2:45] violation to solvency. Same for paying [2:47] payouts or for a state that can where [2:50] the internal accounting can drift from [2:51] the on-chain state. [2:54] So we have this solvency the invariant [2:57] and invariant here means that we want to [2:58] make sure that the pool [3:01] satisfies this at every reachable state. [3:04] So the principle or the technique that [3:07] you can use to verify this is called [3:09] induction and [3:11] this thing doesn't work. Oh, there we [3:12] go. [3:14] So what you do is [3:17] okay you prove first that the solvency [3:20] invariant holds whenever you create a [3:22] new pool. So when a freshly created pool [3:25] solvency needs needs to hold and then [3:27] what you prove in the next step is for [3:28] every [3:29] state mutating function or operation or [3:32] outside event you take a solvent pool. [3:34] So you take any pool that is in a [3:35] solvent state. You execute that function [3:38] and you assert or you verify that the [3:40] the pool is still in a solvent state [3:41] afterwards. [3:42] If you can do this for any operation and [3:44] any outside state change so for example [3:47] airdrops [3:49] then you can be guaranteed that the pool [3:50] is [3:51] solvent in every state. [3:54] And you can use your favorite formal [3:55] verification framework of your liking to [3:58] prove this. For example you can use the [4:00] approach with NES that was described in [4:02] the talk before that. [4:04] You can also use fuzzing if you don't [4:06] want full guarantees. [4:07] In the example that I'm going to show [4:08] next, what we use is the [4:11] and in a nutshell, you give it the [4:13] invariant and the code and it comes out [4:15] with the logical formula that can either [4:17] be proven, making sure or guaranteeing [4:19] the property holds [4:20] or it gives you a counter example [4:22] telling you where solvency can be [4:24] violated. [4:26] Okay, so we proved this particular [4:28] invariant for the Solana stake pool [4:30] program. That's the standard stake pool [4:33] program on Solana. [4:35] It's running since 2021. [4:38] Two weeks ago, there were about 64 [4:40] active pools. [4:42] They together had 33.1 million SOL [4:45] locked and [4:47] there was roughly 3.4 billion [4:50] USD, so quite a lot. [4:52] And it was audited a couple of times [4:54] since it was deployed and last year we [4:56] also formally verified it. [5:00] So first, how does the Solana stake pool [5:02] program work? Okay. [5:06] Okay, there we go. [5:07] So it's more or less the same thing as [5:09] the general model. We have users that [5:11] deposit SOL into the stake pool. [5:14] So this was supposed to be an animation. [5:16] Now I see the whole thing now. [5:19] And the pool mints back what's called [5:21] pool tokens, which is nothing different [5:23] than the shares we saw on the general [5:24] model. [5:25] Then an operator, the staker comes into [5:28] play that takes [5:29] that takes tokens out of the SOL out of [5:31] the reserve, puts them to the [5:33] validators. They land first in the [5:34] transient stake. There's kind of a [5:35] buffer because on Solana, stake can only [5:38] enter validators upon epoch boundary. So [5:41] after an epoch ends, the stake is moved [5:43] to the validator's active stake where it [5:45] gains rewards. [5:46] If the users want to redeem their [5:48] shares, they go back to the pool. [5:52] They'll redeem their shares, they get [5:53] burned [5:54] and the stake pool [5:57] moves SOL back to the user [6:00] for whatever these shares are worth at [6:02] the moment. [6:04] What you have to care about is if the [6:05] reserve has less than some kind of set [6:07] minimum value. Um this is [6:10] kind of value that is never supposed to [6:11] be um um like uh it's always supposed to [6:14] be withheld in the reserve. [6:16] So if you if there are not enough funds [6:19] to fulfill a redemption, [6:20] uh then either you have to wait until [6:22] other users top up with the reserve or [6:24] the staker comes in and unstakes [6:25] something so the pool has enough funds [6:27] available at the next epoch. [6:30] So we tried to prove uh solvency on that [6:33] particular protocol. [6:36] And in that case it's simply like [6:39] restated that the pool tokens [6:41] are less than or equal to the [6:42] extractable value. So the pool tokens [6:44] are the shares and the extractable value [6:46] in that case is the whatever is in the [6:48] reserve minus this minimal balance that [6:51] I said cannot be touched. [6:53] Uh plus whatever is staked in the [6:54] validators including the reserve we have [6:57] already gotten uh the the rewards we [6:58] have already gotten plus what is in the [7:00] transient stake. [7:02] So we were able to prove this but there [7:03] was a catch uh that we had to assume [7:06] something about the reserve [7:08] which sounds a bit ridiculous at first [7:10] if you have never like got in touch with [7:12] the Solana um system [7:15] which is that the pool can actually move [7:16] around uh the soul that is in in the [7:19] accounts so in the reserve and in the [7:21] stake accounts. [7:23] Um what this is or why we need this is a [7:25] is like a peculiarity of the Solana [7:28] runtime [7:29] because on Solana [7:31] um every every account so every piece of [7:33] structured data um that is stored has [7:36] one owner program and that owner program [7:38] is the only one that can move actually [7:40] soul out of that account. [7:42] So in case of the stake pools uh the [7:45] reserve uh the owner program of that [7:47] reserve was not actually the pool itself [7:49] but it was what is called the stake [7:51] program which is a Solana native program [7:54] which is out of scope of the pools or [7:56] the pools are built on top of that. [7:59] But the users interact with the pool so [8:02] how does it work? Um the users go to the [8:05] pool and they [8:07] say they want to redeem some shares, [8:10] and the stake pool then goes to the [8:12] stake program, signs a request for the [8:15] stake program to move some SOL out of [8:17] the reserve, [8:18] and the stake program then checks the [8:20] authority, that's another field on that [8:22] account that is set to the address of [8:24] that stake pool program, and the stake [8:27] program checks who signed the request, [8:29] and if that is the stake pool program, [8:30] then that request is is carried out, so [8:33] it's granted. [8:35] Um yes, so this is why we needed this [8:37] assumption. So in other words, what we [8:40] needed to prove is [8:41] um that the pool at all times is the [8:44] authority of the reserve and the [8:45] validator and the transient stake. [8:48] Um if you look at the code, this looks [8:49] like a completely reasonable assumption [8:52] um because you know, the authority is [8:54] set once and then never touched, [8:56] but it is actually violated. We could [8:58] not verify this, and here's what could [9:00] happen. [9:02] So [9:04] this is going to be hard to explain now, [9:05] okay, because the animations don't work. [9:07] So um if the user wants to say you have [9:10] a reserve that has 20 SOL, uh so it now [9:13] shows zero point something something, so [9:15] it's supposed to be 20. [9:17] And the user there's some user that can [9:19] withdraw their 20 SOL because he has [9:21] enough pool tokens. So it goes to the [9:22] stake pool program um asking [9:25] to withdraw the the 20 SOL by giving it [9:28] the pool tokens. [9:29] And uh so the stake pool program goes to [9:32] the stake program, asking the stake [9:33] program to on behalf of the user move [9:35] out that 20 SOL and give that 20 SOL to [9:38] the user. [9:39] The stake program sees that the [9:40] authority is properly set to the stake [9:42] pool as it should be [9:44] uh presented here, but um yeah, the [9:47] stake program then moves the 20 SOL from [9:50] uh the stake program moves the 20 SOL [9:51] from the reserve to the user. [9:54] After that has happened, the reserve [9:56] technically drops to zero SOL, [9:58] and what the stake program then does is [10:01] it moves the states of the reserve to [10:03] uninitialized. So if whenever the stake [10:05] program sees a reserve dropping to zero, [10:08] it just moves it to an uninitialized [10:10] state. [10:12] And even worse, after the transaction [10:14] ended, so when it sets it to an [10:16] uninitialized state, at the same time [10:18] the authority is set to none. So the [10:20] stake pool is not the authority anymore [10:22] of that reserve. [10:24] And even worse, for an account that has [10:26] zero soul or has soul below a certain [10:28] rent minimum threshold, at the end of [10:30] the transaction that account gets [10:31] deleted from the runtime. So the reserve [10:34] completely vanishes and everything that [10:35] flows into that reserve by for example [10:37] unstaking from the validators cannot be [10:39] accessed anymore. [10:42] That in itself is is bad enough, but it [10:44] compounds with a different issue [10:46] which is that [10:48] the stake program can actually [10:49] reinitialize accounts before the [10:52] transaction ends. [10:53] So this is what this picture here [10:55] presents, because if we have a malicious [10:57] user, [10:58] the user itself can transfer a minimum [11:01] value, so a very small value back to the [11:03] reserve. [11:04] And [11:05] you know, then it's refunded, it won't [11:07] get deleted. And in the same transaction [11:08] go to the stake program asking the stake [11:11] program, hey, can you reinitialize that [11:13] account? [11:14] And the only thing that the stake [11:16] program does is check if it 's an [11:17] uninitialized account. [11:19] It sees the uninitialized account [11:20] because we withdraw all of the soul, so [11:22] the stake program will happily carry out [11:24] that request and the user can put [11:26] himself in place of the authority. So [11:28] now every funds funding every deposit [11:31] that goes into that reserve or [11:32] everything that goes from the validators [11:34] that gets unstaked into that reserve is [11:36] now under complete control of this user. [11:40] So that's a [11:41] very nasty state to be in. [11:44] Let's check why this happened. If you [11:46] remember back, I told you that there's [11:48] supposed to be some kind of minimum [11:50] value always kept in the reserve. [11:54] That was good intention, but it wasn't [11:56] properly enforced [11:58] because there was a check in place that [11:59] only checked if you withdraw something [12:01] that at that moment there is more than [12:03] that minimum balance in the vault. [12:06] What was not checked is that if you if [12:09] you withdraw something, then after you [12:11] carry out that withdrawal, [12:12] um there's still more than that minimum [12:14] balance left in the in the reserve. And [12:17] that minimum value, of course, needs to [12:18] be greater than zero. [12:20] So the fix was very simple, which was to [12:22] put back or put in that exact check that [12:24] if you redeem shares and you withdraw [12:26] the funds from the reserve, then there's [12:28] still more than that minimum minimum [12:30] minimum balance. [12:31] So once that fix was uh put in, which [12:34] was very like very few lines of code, uh [12:36] we could prove this invariant. So there [12:38] was no other counterexample to this [12:40] invariant, [12:42] uh meaning that it's is fully proven [12:43] now. [12:44] And all of the other assumptions that we [12:45] needed for solvency, which I left out in [12:47] this talk, were also proven, fully [12:49] verified, and solvency itself was [12:51] verified. And at that moment, we were [12:53] guaranteed that um or we have verified [12:55] that solvency [12:57] holds for this Solana stake pool [12:59] program. [13:01] So quick recap [13:02] quick recap what we what we've seen is [13:04] that we found uh high severity security [13:07] bug that allowed the user to completely [13:08] take over the funds of a stake pool [13:11] um just by violating an implicit [13:14] assumption that the um account or that [13:17] the pool itself could always move the [13:19] funds around. [13:21] And the cause was fixed or the issue was [13:23] fixed by a very simple missing check on [13:26] the minimum balance. [13:28] So um the key takeaways that I you know [13:31] think this this shows is that [13:33] check your implicit assumptions because [13:35] if you looked at the code base, you [13:37] wouldn't see that this thing that [13:39] account removal dropping to zero, this [13:41] doesn't this does happen outside of the [13:43] code base of the of the stake pools and [13:45] within uh the runtime itself. [13:48] And also ideally um do complement your [13:51] audits with formal verification because [13:53] formal verification makes you [13:56] or forces you to make your implicit [13:57] assumptions explicit because you have to [13:59] list them in order to prove other [14:01] invariants. So once you do that, you [14:03] wonder oh is this really true? And you [14:05] can also like we did in this case uh [14:07] verify those assumptions uh [14:11] individually independently. [14:12] And you know in some some cases like in [14:15] this one you get um unexpected results. [14:18] Um yeah, this is all I have. Uh thank [14:21] you. I don't think we have time for [14:22] questions, but you can catch me [14:24] afterwards. Thanks.