DSS

DSS 2026 / Day 2 / Amber Hall

Glamsterdam Hard Fork: When Spent Gas Comes Back

Ioannis Sachinoglou

24:52 · Recording

Watch on YouTube ↗Open recording viewerOriginal programme entry
Download plain textDownload timestamped JSON

Source: YouTube automatic caption track · Exported 2026-11-16. Timestamps link to the source video. Cue end times were not supplied.

Transcript

0:03Thank you.

0:05Welcome to my talk. I know it's late,

0:07but I find the topic quite interesting.

0:11So I'll be talking about Glamsterdam

0:12hard fork and how the changes in the gas

0:16accounting introduced some bugs that

0:19were not anticipated actually.

0:21And actually this led to the delay of

0:25Glamsterdam as it won't be

0:28postponed soon on Hoodie.

0:31But before I dive into the technical

0:33details, let me give a little bit of

0:34background about Chain Security. So we

0:37are one of the OGs in the audit

0:41space. We've been auditing smart

0:43contracts since 2017 and as a matter of

0:46fact we have audited some of the most

0:48important DeFi protocols. And it's not

0:52actually the first time that we are

0:54delaying a hard fork. The same thing

0:56happened in 2019

0:58when we found a bug

1:01in the Constantinople hard fork.

1:05So this is not

1:08my work.

1:09It should be credited to Tongi and

1:12Hubert who are two colleagues of mine

1:14who had the idea to flip the question

1:18that

1:19people asked before.

1:21So the question was

1:24the original question was

1:27how does the Glamsterdam break some of

1:30the honest work

1:33on the blockchain? So the EF was already

1:37aware that some of the transactions

1:39would break in the way that I'll explain

1:42later, but then

1:44my colleagues asked, okay,

1:47does the Glamsterdam hard fork introduce

1:50some behaviors that allow for evil evil

1:53work that was not possible before?

1:58And actually this the

2:01to this question turned out to be quite

2:03interesting and that's why we'll we are

2:05collaborating with the Ethereum

2:07Foundation and we have found

2:10a lot of instances

2:12of issues

2:14and we are in the process of

2:16responsibly disclosing those issues.

2:20So before I start explaining

2:24the details, let me give you a little

2:26bit of an intro.

2:28So as you might know there

2:31some smart contracts have the need to

2:33continue executing after a failure has

2:36happened.

2:38So if we want to introduce an attacker

2:40model

2:42what

2:43we are looking for is essentially a

2:45permissionless function that can be

2:47front run by an attacker with lower gas.

2:51Why do we need lower gas? We need this

2:53because when gas runs low all these

2:57weird behaviors the unexpected behaviors

2:59become

3:00more apparent and then

3:03funky things can happen.

3:05And actually there are a lot of smart

3:07contracts that allow

3:10our attackers model to to exist. For

3:13example you can look at bridges or meta

3:15transactions.

3:17Um

3:20we're talking about external calls,

3:22right? And

3:24we need to think and we need to remind

3:26ourselves first of all how gas works

3:28with external calls. Here I'm over

3:30simpli I'm simplifying. I hope I'm not

3:32over simplifying.

3:35But essentially when we make an external

3:37call we forward some gas.

3:40The default value is 63 over 64 as

3:43defined by the EIP 150.

3:46When the call terminates we are sort of

3:49guaranteed that at least one over 64 of

3:52the gas we initially sent to the call is

3:54left. So naively we can assume that if

3:59the call ran out of gas then

4:02when call returns, we still have one

4:05over 64 of the available gas to continue

4:08executing.

4:11So

4:12to introduce

4:14the first feature of 8037

4:19so 8037 introduces this idea of cost per

4:22state byte and they actually price this

4:25at 1,500 per byte. So if you want to

4:28consider called a store

4:31to a fresh slot, then under Osaka the

4:35the current

4:37version of

4:38Ethereum you one would pay something

4:40around 22,000

4:42but under Amsterdam

4:45one pays

4:46more than 100,000 right around 100

4:49and 10,000 and the term at least the

4:5397,000 comes exactly from this cost

4:57the gas per byte right because it slot

5:00on Ethereum is 64 bytes.

5:03I'll dive deeper into the the other term

5:05later but yeah just to be precise

5:108037 has a brother the 8038 and some

5:15some of the pricing is defined there but

5:17I'll be mostly focusing on 8037.

5:21And this brings me already to the first

5:23issue.

5:26So as I said

5:28when the idea of

5:31this EAP was introduced it became

5:34apparent that some smart contracts will

5:36break because the cost

5:39of the operation increases.

5:42So there are a lot of smart contracts

5:44out there as you can see in the in the

5:47first example which define

5:50some gas some budget on the gas and of

5:53course this fails.

5:56This is fine. The interesting thing is

5:58to to kind of

6:00reverse

6:01the view here.

6:03If

6:04there is more gas

6:06required to execute a call, this means

6:10that a call can fail out of gas

6:14when we supply even higher gas, right?

6:17So this means

6:18when the call returns from an out of gas

6:21failure, we will still have 164 but

6:24since

6:26since the gas we supplied is higher,

6:28this means that now the gas we have is

6:31also higher.

6:32So this means in the second example down

6:34here

6:37if if

6:38I call

6:40a token I make a low level call and I

6:43consume a lot of gas

6:46the implicit assumption up to Osaka was

6:50that if the call runs out of gas then it

6:52won't have enough gas

6:55when it returns to emit an event, but

6:58this assumption now breaks. So now

7:00people are able

7:02if they are able to front run of course

7:04the call and provide the correct amount

7:07of gas to spoof the emission of some

7:10events. And here you can see that things

7:13that look kind of straightforward start

7:15to break a little bit.

7:18To execute the to to explain the second

7:21issue, we first need to to dive a little

7:23bit deeper

7:25into the 8037.

7:28So

7:298037

7:31allows

7:33users to

7:34specify higher gas for the transaction

7:38that actually exceeds the TX max gas

7:40limit that was introduced before.

7:44So any additional

7:46gas that exceeds this cap is accounted

7:49for this reservoir. So this is another

7:52pool where we can

7:53draw gas from

7:56and I'll explain later how this is used.

8:01So the reservoir doesn't behave exactly

8:03the same way as the normal gas left,

8:07which is the part of the gas below the

8:13gas left behaves still behaves exactly

8:15as it used to,

8:16but the reservoir is fully forwarded

8:20during the external call.

8:22And interestingly,

8:25the gas

8:27opcode, the one that returns gas left,

8:29only gives us the gas

8:31left part of the gas we're using, not

8:34the reservoir.

8:36This will become very interesting later.

8:40So

8:41how do we use the reservoir?

8:43The EIP starts to differentiate between

8:47the execution gas and the state gas.

8:50The execution gas is charged by gas

8:52left. It's what we are we are

8:56all already familiar with.

8:59However, now whenever we create

9:03state, first state,

9:06we first try to charge the reservoir. If

9:10the reservoir is not enough to cover for

9:12the

9:14state creation expenses,

9:16then

9:17there is a spillover

9:19which essentially subtracts gas from gas

9:22left. And in this case, we increase a

9:25variable called state gas from gas left.

9:28Again, to make things clear, we only

9:31care about freshly created storage. What

9:35this means is that we care about slots

9:38that were zero at the beginning of the

9:39transaction

9:40and

9:42during the transaction we touch them and

9:44we try to write on them.

9:48So to give you an example,

9:52let's consider two operations only,

9:55addition and an SStore to a first

9:58variable. Unfortunately, it doesn't

9:59render very well. In my slides, it was

10:02better.

10:04But anyways, so

10:07the addition doesn't touch any state,

10:09right? So it only consume execution gas.

10:13The store on a fresh storage touch

10:16touches state, the state gas, right? So

10:19now we differentiate and we consume

10:22100,000 from the state gas and 10,000

10:26from the execution gas. Of course, all

10:28these numbers are not precise. I'm just

10:30using them

10:32for my example.

10:34So

10:35if we were to run a series of

10:38operations, if we were to do an

10:40addition, we know that the addition only

10:42costs three gas, so we consume it from

10:44gas left. Then the first S store on a

10:47fresh lot we encounter, we can

10:52we can consume it from state gas, the

10:55100,000 part, and then because the S

10:58store has an execution part, we consume

11:01it from

11:02we deduct it from the gas left.

11:05Now, if we have

11:07a second operation, a S store operation

11:10on another slot,

11:12then the reservoir is not enough to

11:14cover for the state gas. So we consume

11:17as much we can from the reservoir and

11:19the rest we consume

11:23out of the gas left.

11:26And because we spend gas to create

11:30storage out of gas left, we increase

11:32this state gas from gas left variable to

11:3550,000 because we consumed 50,000 from

11:38the reservoir and then the rest we

11:39consume from the gas left.

11:44And now I think we are able to

11:46understand the second issue.

11:49Assume we are trying to execute an

11:51operation of a specific ID as long as

11:54this operation is not settled.

11:57Then we execute

11:59a low-level call and we forward 63/64

12:03of the gas.

12:06And

12:07we have defined we have given enough

12:09gas, so there there is a lot of the

12:11reservoir, right?

12:13Pre

12:14pre Amsterdam,

12:18there are only two cases that are

12:19possible.

12:21The call either succeeds and we set it

12:24to done or it fails due to some logic

12:28error

12:29and we set it to failed.

12:33However, now there is a third

12:35possibility.

12:37The implicit assumption before Amsterdam

12:39was that we don't have enough gas to

12:42execute

12:44a write if the external call ran out of

12:47gas.

12:48However, now

12:50the execution gas cost

12:52of operation of operations is lower,

12:55right? We can

12:58consume the big part of the operation

13:01taking gas from the reservoir and the

13:03reservoir the limit is way higher. So we

13:06can have a lot of reservoir. We can

13:09make an external call that doesn't

13:10consume a lot of this

13:13reservoir and then we end up in a

13:15situation where we have enough gas to

13:18execute

13:20a write to storage where beforehand it

13:22was not expected.

13:25This might be a little bit confusing

13:27especially if you

13:29managed to pay attention because I know

13:31everyone is very tired.

13:33But it might be a little bit confusing

13:34if you consider the previous issue

13:36because previously I said

13:39operations are very expensive and I'm

13:41telling you

13:42operations are cheap. Here you need to

13:45understand that I'm talking about the

13:46execution gas part of the operation, not

13:49the

13:50state part of the operation.

13:56To go to the next issue, we need to

13:58understand a little bit the mechanism

14:00of refills.

14:02So remember we have a fresh

14:04slot.

14:05We have written to it and then because

14:09the price is very high, the intention is

14:12to allow more transactions

14:15more transactions and bigger to execute.

14:17So we cannot be very aggressive with how

14:19we consume gas. So the idea

14:22is that we reset

14:24so if a a fresh slot is reset, is set to

14:26zero again, then we refill

14:29the reservoir and the gas left.

14:32And we essentially do the opposite of

14:36what we did before. So if we refill

14:41a storage variable and there is some

14:43state gas from gas left available, then

14:45we will use this to to refill the gas

14:48left and otherwise we will refill the

14:50reservoir. So following up on my

14:52previous example

14:55if we set the the the a slot, which was

14:59a fresh

15:01slot

15:02back, the first thing we see is that we

15:05realize

15:07that the state state gas from gas left

15:09is 50,000. So we know that we need we

15:13owe to gas left 50,000. So we increase

15:16gas left

15:18and then because the whole operation is

15:20100,000, the rest 50,000 we

15:24refill we use it to refill the

15:26reservoir.

15:27The the second storage set is simpler

15:31because we don't owe anything to gas

15:33left, so we simply increase the

15:35reservoir. Here

15:37on purpose I omitted this 100

15:41execution gas that the reset would cost.

15:45But what I want to draw your attention

15:47on is

15:49the reason why I have it in red is

15:52that the first reset actually increases

15:57gas left.

15:59And this

16:01is something we were not aware of. So

16:05it turns out for the very first time

16:07that gas left doesn't always

16:10monotonically decrease, but actually

16:13there are cases

16:16where it increases.

16:18So, if we revisit the previous example a

16:22little bit more

16:24extended,

16:26if we use

16:30if we use a lock variable, which is

16:32initially set to zero, so it's fresh for

16:35us.

16:36If we set the lock variable to

16:39to true, then execute

16:41the external call. The external call we

16:44forward 63 over 64. The external call

16:47fails or doesn't fail, maybe doesn't

16:49matter. It matters for the issue, but

16:52not for for the example currently.

16:54Once we come back,

16:56we reset the lock and at this point, if

16:59the reservoir is not enough and the

17:01state

17:03state gas from gas, I don't remember

17:04what it's called,

17:06is is positive, then this ends up

17:09increasing

17:11gas left. So, in the actual attack,

17:14if we have a failure in the external

17:17call,

17:18then of course the boolean will be

17:20wrong,

17:21it will be false,

17:23but the refill will increase

17:26gas left. So now, if we try to to

17:30perform this check to to understand

17:32whether the failure was caused by a

17:34logic error or it was caused because we

17:37ran out of gas, we

17:40we will end up in with a wrong

17:41conclusion.

17:43And this is actually quite interesting

17:44and it appears quite often.

17:47And it all

17:49comes down to the monotonicity of gas

17:50left.

17:54So,

17:56the next part is even more complex, but

17:59I think it gets quite simpler

18:02if you think

18:04failures as resets.

18:07When we have a revert, a state change is

18:10not committed. So, following the same

18:13logic as before, we should refill

18:17gas left or the reservoir. So, if we

18:20have a failure, we know how much of the

18:22gas

18:24left we consumed,

18:25because we have

18:27uh we have added it to the to the state

18:29gas from gas left.

18:31And we simply

18:33upon failure reset the reservoir to the

18:36value it had beforehand.

18:39And this brings me to I think the most

18:43complex and I think one of the most

18:45common attacks.

18:47So, yeah, bear with me.

18:50Let's assume we have

18:52a contract, right? Our contract that

18:54makes a call to an intermediary

18:57contract,

18:58and this intermediary contract creates

19:01some state.

19:03Now, this intermediary contract makes

19:05another call to a target contract.

19:08What happens if we provide just enough

19:12gas so the target contract, the

19:14execution of the target contract runs

19:16out of gas?

19:17At this point, the target contract

19:19returns the control to the intermediary

19:21contract, and the intermediary contract

19:23may see the failure

19:26and want to bubble it up. And what it's

19:29going to do is simply return

19:31uh revert, sorry.

19:34When the call reverts,

19:37the state that was created

19:40uh is not committed, right? So, it gets

19:44the the gas we paid gets refilled.

19:47So, now we return back to our original

19:50contract

19:52that has way more gas than it originally

19:55expected, right? Because all the the

19:57refills all the crates creation all the

20:00state creation

20:01we did before

20:03was never committed.

20:04So, now if we were to run

20:07a check like the previous one trying to

20:10figure out whether we ran out of gas or

20:12whether there is a logic error,

20:16we will most likely

20:18end up with the wrong conclusion.

20:24So,

20:26I'm trying to be fast everyone

20:29kind of relax a little bit.

20:32So,

20:34what it means in general for us?

20:38The EIP 8037 and 8038

20:43introduce

20:44introduces some features that make

20:48malicious transactions

20:50malicious actions possible.

20:53It increases the required gas, right?

20:56So, the residual gas also increases even

20:59in the case of an out of gas execution.

21:04However, it decreases the execution

21:08gas consumed. So, now we might end up

21:13revert and end up in a situation where

21:15we have more gas than we expected

21:17because our reservoir is pretty full.

21:20It breaks the monotonicity

21:22of gas left

21:25and it also

21:27through the way it handles failure

21:30returns gas

21:33in places where

21:34the developers when writing the

21:37contracts before Glamster assumed

21:41that the gas has been consumed.

21:45So, if you are a developer or if you are

21:48an auditor

21:50you might be wondering what you should

21:51be

21:52looking out for.

21:54And I think the answer is again in in

21:58the issues, right? So,

22:00if you find contracts

22:03with a

22:04fixed budget

22:05rethink

22:06how the budget requirements change after

22:10Glamster dam.

22:12Think how reverts

22:17how reverts affect your code. This is

22:19twofold, right?

22:21One might assume that

22:23if I have an out of gas execution.

22:26Re-

22:27the the transaction will revert and

22:29therefore I won't have enough gas to

22:32perform more actions, but this is as I

22:34showed you

22:35is wrong.

22:37And also you need to be thinking about

22:39refills all the time now because as soon

22:42as you

22:44reset a variable you get more gas back

22:47that can be used for other operations

22:49later and can be used to trick checks

22:53that you have in place.

22:56And this touches on the on the my last

22:58point which is

23:00you need to think how you you handle

23:04the failure.

23:07So if you found this stock interesting

23:10and if you have questions feel free

23:13to contact us at

23:14glamsterdam@chainsecurity.

23:16If you want to read

23:17again about

23:19this issue

23:21feel free to to read our blog.

23:24And otherwise thank you very much for

23:25your attention and happy to take

23:27questions.

23:28[applause]

23:32Do you need microphone?

23:35>> Hi, Mohamed from Dido.

23:38Thank you for the talk.

23:40Just one question. Why why did

23:43why don't we have the protocol more or

23:46the the fork or the change more backward

23:49compatible in the sense that

23:52there is a does not cannot refill the

23:55gas left stuff and then it needs a

23:58special instruction to do this and in

24:01that case everything existing now will

24:03not be affected and then everyone is

24:05deploying a new code would be able to

24:07control this and do secure code instead

24:09of getting into the hazard of finding

24:12the bugs.

24:13>> Yeah,

24:14that's a good question.

24:15I guess the answer is that you want to

24:17have

24:18some kind of backwards compatibility

24:20maybe or actually you don't want to

24:22touch Solidity. So because this is a

24:24change on the on the execution layer

24:27uh,

24:28they have people thought that they

24:30shouldn't try to to change solidity,

24:33right?

24:34Uh, so I think

24:36that's the simple answer. I mean, there

24:37are many ways to mitigate the issue if

24:40you if you revisit the spec, but because

24:44the spec is live, this is a little bit

24:46out of question currently.

24:49Thank you very much.

Source and accuracy details

Source export SHA256: e335621c9656955c7b07746267ebb8706593a0a6400452488a3dec5d8f921c35