DSS 2026 — Glamsterdam Hard Fork: When Spent Gas Comes Back Ioannis Sachinoglou Source video: https://www.youtube.com/watch?v=e3tlnLDI-5s Automatic captions — not human-reviewed. Complete spoken-audio coverage is unverified. Source language tag: en (English). Source export SHA256: e335621c9656955c7b07746267ebb8706593a0a6400452488a3dec5d8f921c35 [0:03] Thank you. [0:05] Welcome to my talk. I know it's late, [0:07] but I find the topic quite interesting. [0:11] So I'll be talking about Glamsterdam [0:12] hard fork and how the changes in the gas [0:16] accounting introduced some bugs that [0:19] were not anticipated actually. [0:21] And actually this led to the delay of [0:25] Glamsterdam as it won't be [0:28] postponed soon on Hoodie. [0:31] But before I dive into the technical [0:33] details, let me give a little bit of [0:34] background about Chain Security. So we [0:37] are one of the OGs in the audit [0:41] space. We've been auditing smart [0:43] contracts since 2017 and as a matter of [0:46] fact we have audited some of the most [0:48] important DeFi protocols. And it's not [0:52] actually the first time that we are [0:54] delaying a hard fork. The same thing [0:56] happened in 2019 [0:58] when we found a bug [1:01] in the Constantinople hard fork. [1:05] So this is not [1:08] my work. [1:09] It should be credited to Tongi and [1:12] Hubert who are two colleagues of mine [1:14] who had the idea to flip the question [1:18] that [1:19] people asked before. [1:21] So the question was [1:24] the original question was [1:27] how does the Glamsterdam break some of [1:30] the honest work [1:33] on the blockchain? So the EF was already [1:37] aware that some of the transactions [1:39] would break in the way that I'll explain [1:42] later, but then [1:44] my colleagues asked, okay, [1:47] does the Glamsterdam hard fork introduce [1:50] some behaviors that allow for evil evil [1:53] work that was not possible before? [1:58] And actually this the [2:01] to this question turned out to be quite [2:03] interesting and that's why we'll we are [2:05] collaborating with the Ethereum [2:07] Foundation and we have found [2:10] a lot of instances [2:12] of issues [2:14] and we are in the process of [2:16] responsibly disclosing those issues. [2:20] So before I start explaining [2:24] the details, let me give you a little [2:26] bit of an intro. [2:28] So as you might know there [2:31] some smart contracts have the need to [2:33] continue executing after a failure has [2:36] happened. [2:38] So if we want to introduce an attacker [2:40] model [2:42] what [2:43] we are looking for is essentially a [2:45] permissionless function that can be [2:47] front run by an attacker with lower gas. [2:51] Why do we need lower gas? We need this [2:53] because when gas runs low all these [2:57] weird behaviors the unexpected behaviors [2:59] become [3:00] more apparent and then [3:03] funky things can happen. [3:05] And actually there are a lot of smart [3:07] contracts that allow [3:10] our attackers model to to exist. For [3:13] example you can look at bridges or meta [3:15] transactions. [3:17] Um [3:20] we're talking about external calls, [3:22] right? And [3:24] we need to think and we need to remind [3:26] ourselves first of all how gas works [3:28] with external calls. Here I'm over [3:30] simpli I'm simplifying. I hope I'm not [3:32] over simplifying. [3:35] But essentially when we make an external [3:37] call we forward some gas. [3:40] The default value is 63 over 64 as [3:43] defined by the EIP 150. [3:46] When the call terminates we are sort of [3:49] guaranteed that at least one over 64 of [3:52] the gas we initially sent to the call is [3:54] left. So naively we can assume that if [3:59] the call ran out of gas then [4:02] when call returns, we still have one [4:05] over 64 of the available gas to continue [4:08] executing. [4:11] So [4:12] to introduce [4:14] the first feature of 8037 [4:19] so 8037 introduces this idea of cost per [4:22] state byte and they actually price this [4:25] at 1,500 per byte. So if you want to [4:28] consider called a store [4:31] to a fresh slot, then under Osaka the [4:35] the current [4:37] version of [4:38] Ethereum you one would pay something [4:40] around 22,000 [4:42] but under Amsterdam [4:45] one pays [4:46] more than 100,000 right around 100 [4:49] and 10,000 and the term at least the [4:53] 97,000 comes exactly from this cost [4:57] the gas per byte right because it slot [5:00] on Ethereum is 64 bytes. [5:03] I'll dive deeper into the the other term [5:05] later but yeah just to be precise [5:10] 8037 has a brother the 8038 and some [5:15] some of the pricing is defined there but [5:17] I'll be mostly focusing on 8037. [5:21] And this brings me already to the first [5:23] issue. [5:26] So as I said [5:28] when the idea of [5:31] this EAP was introduced it became [5:34] apparent that some smart contracts will [5:36] break because the cost [5:39] of the operation increases. [5:42] So there are a lot of smart contracts [5:44] out there as you can see in the in the [5:47] first example which define [5:50] some gas some budget on the gas and of [5:53] course this fails. [5:56] This is fine. The interesting thing is [5:58] to to kind of [6:00] reverse [6:01] the view here. [6:03] If [6:04] there is more gas [6:06] required to execute a call, this means [6:10] that a call can fail out of gas [6:14] when we supply even higher gas, right? [6:17] So this means [6:18] when the call returns from an out of gas [6:21] failure, we will still have 164 but [6:24] since [6:26] since the gas we supplied is higher, [6:28] this means that now the gas we have is [6:31] also higher. [6:32] So this means in the second example down [6:34] here [6:37] if if [6:38] I call [6:40] a token I make a low level call and I [6:43] consume a lot of gas [6:46] the implicit assumption up to Osaka was [6:50] that if the call runs out of gas then it [6:52] won't have enough gas [6:55] when it returns to emit an event, but [6:58] this assumption now breaks. So now [7:00] people are able [7:02] if they are able to front run of course [7:04] the call and provide the correct amount [7:07] of gas to spoof the emission of some [7:10] events. And here you can see that things [7:13] that look kind of straightforward start [7:15] to break a little bit. [7:18] To execute the to to explain the second [7:21] issue, we first need to to dive a little [7:23] bit deeper [7:25] into the 8037. [7:28] So [7:29] 8037 [7:31] allows [7:33] users to [7:34] specify higher gas for the transaction [7:38] that actually exceeds the TX max gas [7:40] limit that was introduced before. [7:44] So any additional [7:46] gas that exceeds this cap is accounted [7:49] for this reservoir. So this is another [7:52] pool where we can [7:53] draw gas from [7:56] and I'll explain later how this is used. [8:01] So the reservoir doesn't behave exactly [8:03] the same way as the normal gas left, [8:07] which is the part of the gas below the [8:13] gas left behaves still behaves exactly [8:15] as it used to, [8:16] but the reservoir is fully forwarded [8:20] during the external call. [8:22] And interestingly, [8:25] the gas [8:27] opcode, the one that returns gas left, [8:29] only gives us the gas [8:31] left part of the gas we're using, not [8:34] the reservoir. [8:36] This will become very interesting later. [8:40] So [8:41] how do we use the reservoir? [8:43] The EIP starts to differentiate between [8:47] the execution gas and the state gas. [8:50] The execution gas is charged by gas [8:52] left. It's what we are we are [8:56] all already familiar with. [8:59] However, now whenever we create [9:03] state, first state, [9:06] we first try to charge the reservoir. If [9:10] the reservoir is not enough to cover for [9:12] the [9:14] state creation expenses, [9:16] then [9:17] there is a spillover [9:19] which essentially subtracts gas from gas [9:22] left. And in this case, we increase a [9:25] variable called state gas from gas left. [9:28] Again, to make things clear, we only [9:31] care about freshly created storage. What [9:35] this means is that we care about slots [9:38] that were zero at the beginning of the [9:39] transaction [9:40] and [9:42] during the transaction we touch them and [9:44] we try to write on them. [9:48] So to give you an example, [9:52] let's consider two operations only, [9:55] addition and an SStore to a first [9:58] variable. Unfortunately, it doesn't [9:59] render very well. In my slides, it was [10:02] better. [10:04] But anyways, so [10:07] the addition doesn't touch any state, [10:09] right? So it only consume execution gas. [10:13] The store on a fresh storage touch [10:16] touches state, the state gas, right? So [10:19] now we differentiate and we consume [10:22] 100,000 from the state gas and 10,000 [10:26] from the execution gas. Of course, all [10:28] these numbers are not precise. I'm just [10:30] using them [10:32] for my example. [10:34] So [10:35] if we were to run a series of [10:38] operations, if we were to do an [10:40] addition, we know that the addition only [10:42] costs three gas, so we consume it from [10:44] gas left. Then the first S store on a [10:47] fresh lot we encounter, we can [10:52] we can consume it from state gas, the [10:55] 100,000 part, and then because the S [10:58] store has an execution part, we consume [11:01] it from [11:02] we deduct it from the gas left. [11:05] Now, if we have [11:07] a second operation, a S store operation [11:10] on another slot, [11:12] then the reservoir is not enough to [11:14] cover for the state gas. So we consume [11:17] as much we can from the reservoir and [11:19] the rest we consume [11:23] out of the gas left. [11:26] And because we spend gas to create [11:30] storage out of gas left, we increase [11:32] this state gas from gas left variable to [11:35] 50,000 because we consumed 50,000 from [11:38] the reservoir and then the rest we [11:39] consume from the gas left. [11:44] And now I think we are able to [11:46] understand the second issue. [11:49] Assume we are trying to execute an [11:51] operation of a specific ID as long as [11:54] this operation is not settled. [11:57] Then we execute [11:59] a low-level call and we forward 63/64 [12:03] of the gas. [12:06] And [12:07] we have defined we have given enough [12:09] gas, so there there is a lot of the [12:11] reservoir, right? [12:13] Pre [12:14] pre Amsterdam, [12:18] there are only two cases that are [12:19] possible. [12:21] The call either succeeds and we set it [12:24] to done or it fails due to some logic [12:28] error [12:29] and we set it to failed. [12:33] However, now there is a third [12:35] possibility. [12:37] The implicit assumption before Amsterdam [12:39] was that we don't have enough gas to [12:42] execute [12:44] a write if the external call ran out of [12:47] gas. [12:48] However, now [12:50] the execution gas cost [12:52] of operation of operations is lower, [12:55] right? We can [12:58] consume the big part of the operation [13:01] taking gas from the reservoir and the [13:03] reservoir the limit is way higher. So we [13:06] can have a lot of reservoir. We can [13:09] make an external call that doesn't [13:10] consume a lot of this [13:13] reservoir and then we end up in a [13:15] situation where we have enough gas to [13:18] execute [13:20] a write to storage where beforehand it [13:22] was not expected. [13:25] This might be a little bit confusing [13:27] especially if you [13:29] managed to pay attention because I know [13:31] everyone is very tired. [13:33] But it might be a little bit confusing [13:34] if you consider the previous issue [13:36] because previously I said [13:39] operations are very expensive and I'm [13:41] telling you [13:42] operations are cheap. Here you need to [13:45] understand that I'm talking about the [13:46] execution gas part of the operation, not [13:49] the [13:50] state part of the operation. [13:56] To go to the next issue, we need to [13:58] understand a little bit the mechanism [14:00] of refills. [14:02] So remember we have a fresh [14:04] slot. [14:05] We have written to it and then because [14:09] the price is very high, the intention is [14:12] to allow more transactions [14:15] more transactions and bigger to execute. [14:17] So we cannot be very aggressive with how [14:19] we consume gas. So the idea [14:22] is that we reset [14:24] so if a a fresh slot is reset, is set to [14:26] zero again, then we refill [14:29] the reservoir and the gas left. [14:32] And we essentially do the opposite of [14:36] what we did before. So if we refill [14:41] a storage variable and there is some [14:43] state gas from gas left available, then [14:45] we will use this to to refill the gas [14:48] left and otherwise we will refill the [14:50] reservoir. So following up on my [14:52] previous example [14:55] if we set the the the a slot, which was [14:59] a fresh [15:01] slot [15:02] back, the first thing we see is that we [15:05] realize [15:07] that the state state gas from gas left [15:09] is 50,000. So we know that we need we [15:13] owe to gas left 50,000. So we increase [15:16] gas left [15:18] and then because the whole operation is [15:20] 100,000, the rest 50,000 we [15:24] refill we use it to refill the [15:26] reservoir. [15:27] The the second storage set is simpler [15:31] because we don't owe anything to gas [15:33] left, so we simply increase the [15:35] reservoir. Here [15:37] on purpose I omitted this 100 [15:41] execution gas that the reset would cost. [15:45] But what I want to draw your attention [15:47] on is [15:49] the reason why I have it in red is [15:52] that the first reset actually increases [15:57] gas left. [15:59] And this [16:01] is something we were not aware of. So [16:05] it turns out for the very first time [16:07] that gas left doesn't always [16:10] monotonically decrease, but actually [16:13] there are cases [16:16] where it increases. [16:18] So, if we revisit the previous example a [16:22] little bit more [16:24] extended, [16:26] if we use [16:30] if we use a lock variable, which is [16:32] initially set to zero, so it's fresh for [16:35] us. [16:36] If we set the lock variable to [16:39] to true, then execute [16:41] the external call. The external call we [16:44] forward 63 over 64. The external call [16:47] fails or doesn't fail, maybe doesn't [16:49] matter. It matters for the issue, but [16:52] not for for the example currently. [16:54] Once we come back, [16:56] we reset the lock and at this point, if [16:59] the reservoir is not enough and the [17:01] state [17:03] state gas from gas, I don't remember [17:04] what it's called, [17:06] is is positive, then this ends up [17:09] increasing [17:11] gas left. So, in the actual attack, [17:14] if we have a failure in the external [17:17] call, [17:18] then of course the boolean will be [17:20] wrong, [17:21] it will be false, [17:23] but the refill will increase [17:26] gas left. So now, if we try to to [17:30] perform this check to to understand [17:32] whether the failure was caused by a [17:34] logic error or it was caused because we [17:37] ran out of gas, we [17:40] we will end up in with a wrong [17:41] conclusion. [17:43] And this is actually quite interesting [17:44] and it appears quite often. [17:47] And it all [17:49] comes down to the monotonicity of gas [17:50] left. [17:54] So, [17:56] the next part is even more complex, but [17:59] I think it gets quite simpler [18:02] if you think [18:04] failures as resets. [18:07] When we have a revert, a state change is [18:10] not committed. So, following the same [18:13] logic as before, we should refill [18:17] gas left or the reservoir. So, if we [18:20] have a failure, we know how much of the [18:22] gas [18:24] left we consumed, [18:25] because we have [18:27] uh we have added it to the to the state [18:29] gas from gas left. [18:31] And we simply [18:33] upon failure reset the reservoir to the [18:36] value it had beforehand. [18:39] And this brings me to I think the most [18:43] complex and I think one of the most [18:45] common attacks. [18:47] So, yeah, bear with me. [18:50] Let's assume we have [18:52] a contract, right? Our contract that [18:54] makes a call to an intermediary [18:57] contract, [18:58] and this intermediary contract creates [19:01] some state. [19:03] Now, this intermediary contract makes [19:05] another call to a target contract. [19:08] What happens if we provide just enough [19:12] gas so the target contract, the [19:14] execution of the target contract runs [19:16] out of gas? [19:17] At this point, the target contract [19:19] returns the control to the intermediary [19:21] contract, and the intermediary contract [19:23] may see the failure [19:26] and want to bubble it up. And what it's [19:29] going to do is simply return [19:31] uh revert, sorry. [19:34] When the call reverts, [19:37] the state that was created [19:40] uh is not committed, right? So, it gets [19:44] the the gas we paid gets refilled. [19:47] So, now we return back to our original [19:50] contract [19:52] that has way more gas than it originally [19:55] expected, right? Because all the the [19:57] refills all the crates creation all the [20:00] state creation [20:01] we did before [20:03] was never committed. [20:04] So, now if we were to run [20:07] a check like the previous one trying to [20:10] figure out whether we ran out of gas or [20:12] whether there is a logic error, [20:16] we will most likely [20:18] end up with the wrong conclusion. [20:24] So, [20:26] I'm trying to be fast everyone [20:29] kind of relax a little bit. [20:32] So, [20:34] what it means in general for us? [20:38] The EIP 8037 and 8038 [20:43] introduce [20:44] introduces some features that make [20:48] malicious transactions [20:50] malicious actions possible. [20:53] It increases the required gas, right? [20:56] So, the residual gas also increases even [20:59] in the case of an out of gas execution. [21:04] However, it decreases the execution [21:08] gas consumed. So, now we might end up [21:13] revert and end up in a situation where [21:15] we have more gas than we expected [21:17] because our reservoir is pretty full. [21:20] It breaks the monotonicity [21:22] of gas left [21:25] and it also [21:27] through the way it handles failure [21:30] returns gas [21:33] in places where [21:34] the developers when writing the [21:37] contracts before Glamster assumed [21:41] that the gas has been consumed. [21:45] So, if you are a developer or if you are [21:48] an auditor [21:50] you might be wondering what you should [21:51] be [21:52] looking out for. [21:54] And I think the answer is again in in [21:58] the issues, right? So, [22:00] if you find contracts [22:03] with a [22:04] fixed budget [22:05] rethink [22:06] how the budget requirements change after [22:10] Glamster dam. [22:12] Think how reverts [22:17] how reverts affect your code. This is [22:19] twofold, right? [22:21] One might assume that [22:23] if I have an out of gas execution. [22:26] Re- [22:27] the the transaction will revert and [22:29] therefore I won't have enough gas to [22:32] perform more actions, but this is as I [22:34] showed you [22:35] is wrong. [22:37] And also you need to be thinking about [22:39] refills all the time now because as soon [22:42] as you [22:44] reset a variable you get more gas back [22:47] that can be used for other operations [22:49] later and can be used to trick checks [22:53] that you have in place. [22:56] And this touches on the on the my last [22:58] point which is [23:00] you need to think how you you handle [23:04] the failure. [23:07] So if you found this stock interesting [23:10] and if you have questions feel free [23:13] to contact us at [23:14] glamsterdam@chainsecurity. [23:16] If you want to read [23:17] again about [23:19] this issue [23:21] feel free to to read our blog. [23:24] And otherwise thank you very much for [23:25] your attention and happy to take [23:27] questions. [23:28] [applause] [23:32] Do you need microphone? [23:35] >> Hi, Mohamed from Dido. [23:38] Thank you for the talk. [23:40] Just one question. Why why did [23:43] why don't we have the protocol more or [23:46] the the fork or the change more backward [23:49] compatible in the sense that [23:52] there is a does not cannot refill the [23:55] gas left stuff and then it needs a [23:58] special instruction to do this and in [24:01] that case everything existing now will [24:03] not be affected and then everyone is [24:05] deploying a new code would be able to [24:07] control this and do secure code instead [24:09] of getting into the hazard of finding [24:12] the bugs. [24:13] >> Yeah, [24:14] that's a good question. [24:15] I guess the answer is that you want to [24:17] have [24:18] some kind of backwards compatibility [24:20] maybe or actually you don't want to [24:22] touch Solidity. So because this is a [24:24] change on the on the execution layer [24:27] uh, [24:28] they have people thought that they [24:30] shouldn't try to to change solidity, [24:33] right? [24:34] Uh, so I think [24:36] that's the simple answer. I mean, there [24:37] are many ways to mitigate the issue if [24:40] you if you revisit the spec, but because [24:44] the spec is live, this is a little bit [24:46] out of question currently. [24:49] Thank you very much.