DSS

DSS 2026 / Day 2 / Pearl Hall

From EVM bytecode to Solidity and back to bytecode

Gerard Persoon

15:25 · 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:01Yes, welcome everyone. I'm going to talk

0:04about something that I've been creating

0:06the last half year.

0:08And that's

0:10a way to get

0:12from EVM bytecode to Solidity. And when

0:15you compile the Solidity again, you get

0:18bytecode of course, but exactly the same

0:20bytecode. So you're 100% sure that you

0:23have a good representation and you can

0:25also verify that source.

0:29A little bit about me. I've been doing

0:32Solidity security reviews for the last

0:34couple of years, starting at Code Arena

0:37and currently at ConsenSys and Spearbit.

0:40And if you want to contact me, here's my

0:42Twitter handle which is at gpersone.

0:48Okay, why do I

0:51spend time

0:53on the Solidity decompiler?

0:56Well, there are several nice use cases

0:58for a decompiler.

1:00I'll show a couple of use cases later

1:03on. And when I started, at least there

1:05was no really good solution to decompile

1:08your contracts.

1:10But

1:11now there are better solutions also.

1:14And

1:17creating a decompiler that can fully

1:19round trip, that's a nice target to

1:21learn about LLMs. Because an LLM can

1:24then

1:26yeah, measure that it has the right

1:29correct answer by round tripping. So

1:31that's a perfect use case for an LLM.

1:34And it's also not too easy for an LLM.

1:37At least when I started, it was

1:39relatively difficult for an LLM to

1:42create a decompiler. But they've

1:44improved a lot, so now it's probably a

1:46lot easier, but at least then it was

1:48difficult.

1:51And also the LLMs currently are actually

1:53so good that they can already decompile

1:56a contract. So if you just put in uh

1:58bytecode in um frontier LLM and say

2:02decompile it and check that it round

2:04trips. It does that already.

2:07Um so you can say why are you going to

2:09create a decompiler anyway? It's not

2:11worth the trouble anymore.

2:13Um but if you use an LLM it takes a long

2:15time,

2:16uh uses a lot of tokens and times

2:18sometimes you get a refusal. So it's

2:21still there are still use cases

2:23uh for a decompiler.

2:27So I uh collected a couple of use cases

2:29what be would be useful or

2:32what would be the use for a decompiler?

2:35Of course what you can do is verify the

2:38contracts

2:39that are not verified yet and put all

2:42those sources in Sourcify.

2:44And then once you have that

2:47um all all the security tools or

2:49whatever can be used

2:51on those contracts.

2:53And you can of course use it to analyze

2:57uh hacks and whatever.

2:59Um and do all kinds of things like that.

3:03Um you can also if this works correctly

3:06you can even do live

3:09um transaction checks so in your wallet

3:12or maybe even on an L2 that before you

3:15do a transaction or before the

3:17transaction is

3:18admitted on the chain that you can do a

3:20check that there is no hacks or whatever

3:23going on.

3:24Um and then if you would have decompiled

3:27contracts that would be a lot easier

3:29than doing that right now.

3:32And you can of course create diagrams of

3:36how the transactions work or how the

3:38code work. So you can do all kinds of

3:40nice things.

3:42And one small detail but still

3:44interesting I think you can find

3:46compiler bugs. So I back tested that

3:49with a couple of contracts that I

3:51decompiled and

3:52um compared the the solidity that I

3:56decompiled to the one that was on

3:58Sourcify. And if there are a there there

4:02is something wrong. So it was able to

4:04find a couple of old bugs in the

4:07Solidity compiler that have already been

4:09solved, but it was nice to see that it

4:12is able to find those

4:14bugs.

4:17So what I did of of for this

4:19presentation, I've taken a

4:21random contract just to show some things

4:23and this one unverified contract

4:27which has a relatively high ETH balance,

4:29so that's interesting to take a look at.

4:32And if you look at

4:34on Etherscan and you look at there's no

4:37source there of course, but there's a

4:39decompilation option there. And if you

4:42look at that,

4:43it says decompilation didn't finish. So

4:45that's an example that's the

4:48the the decompiler over there isn't

4:52good enough actually.

4:55So I've been five coding the decompiler.

4:57I've been using an LLM and just set it

5:00set to it

5:02just create a decompiler.

5:05And this is a sort of high level what

5:07it's

5:08how it's created. So on top is the

5:11decompiler with a lot of faces in it.

5:15And

5:17below that I also

5:19sort of asked the decompiler to create

5:21code

5:22for when it cannot decompile the

5:24contract yet that it give a lot of

5:27information to improve the decompiler so

5:29that it can improve itself with the help

5:33of an LLM so it can decompile the next

5:35contract and then continue to improve

5:37itself until finally it can decompile

5:40all contracts.

5:43And what's

5:46relevant to know if you decompile

5:47contracts, of course you you cannot

5:49perfectly normally decompile all the the

5:52the variable names and the internal

5:54function names and all that kind of

5:56stuff. So it's maybe not super readable,

6:00but

6:01then I have another phase right behind

6:04it. If you just throw in the decompiled

6:07code into a random LLM, then it can make

6:10it a perfectly readable contract. It

6:13creates very nice variable names. It

6:16even adds

6:17comments to it.

6:18So then you get a very nice contract

6:21that you can easily read.

6:26So here are all the phases that the

6:28decompiler is doing.

6:30And I actually just five coded it. So I

6:33don't actually really know what

6:36it does, but it sounds very interesting

6:39what it's doing.

6:43Uh what of the things of course that's

6:44difficult

6:46when you're decompiling is that there

6:47are a lot of Solidity versions.

6:50So whatever like

6:52all of those. So the decompiler first

6:54has to figure out which decompiler

6:57Solidity version you are using. So the

7:00later Solidity versions have that

7:02encoded into the bytecode. So that's

7:04easy. And the older ones

7:07it can infer that from at looking at

7:09which

7:11yeah commands are used or which which

7:14instructions are being used. So it's

7:16able to infer all of that.

7:21One of the more difficult

7:24and interesting things is how do you get

7:26the the function name back from the the

7:29public functions? And that's where

7:32Sourcify comes in. So that's a super

7:34handy tool to use. So you take the

7:38selector that you

7:39want to

7:41reverse engineer. You put it in Sourcify

7:44and most of the time you get back the

7:46the the good function name.

7:49Of course first you have to infer the

7:51parameters because they're part

7:54of the hash which is put in the

7:55selector. So you have to make sure that

7:58you have the right parameters. Otherwise

8:00you get a wrong match.

8:02But that's possible to to get from the

8:04bytecode.

8:08But if you if it's not on Sourcify yet,

8:12then you can brute force it. And this

8:14can can actually be done in in two ways.

8:17You can try to find

8:19sort of the real name. So you use a

8:21dictionary and you try all kinds of

8:23words until you finally get a match.

8:26And that works quite often.

8:29But if that doesn't work, you can also

8:33brute force like a random name, so with

8:36a sequence number behind it.

8:38And it's important that you have

8:40a name that

8:42results in the exact selector. Otherwise

8:45you can never get a

8:48round tripping contracts. Then you would

8:50have a slightly different bytecode.

8:53So it's not perfect, but it is still

8:55round tripping.

9:00Okay, so this is an example of what a

9:02decompiler creates. So the left side is

9:04what it creates. So it infers the

9:08the right function name execute in this

9:10case.

9:11But for example, the the variable names

9:14that are just arg zero, arg one, etc.

9:17So if you have the left side, it's it's

9:20kind of difficult to read.

9:23So and then if you put this in an LLM,

9:25then it creates that outfit. And there

9:28you can see that

9:30all the internal names and the the

9:32argument names, whatever, they're

9:34readable and they actually make sense.

9:36So that's what an LLM can do.

9:43Now what I also did normally when I do

9:45security reviews, I always create a

9:47diagram of the code. So that helps me to

9:49understand the code and and easily

9:53yeah, verify it. And now LLMs are good

9:55enough to do that automatically. So I

9:58took the decompiled code and

10:00put it in an LLM to create a diagram.

10:04And then it automatically created this

10:06diagram.

10:07And this format is the format that I

10:10used myself. So I'm used to this format,

10:12but it could actually create any format

10:15that you want.

10:17So you could do

10:18for example build this into a wallet

10:21and then if you want to do a

10:22transaction, it could automatically

10:24create

10:26a diagram like this and you could

10:28interpret it

10:30if you're technical of course.

10:36Now the interesting thing is

10:39how fast is a decompiler compared to

10:41just doing it with an LLM because the

10:43LLM can do it also.

10:47If you take a large contract, so the the

10:49bottom layer, then an LLM takes about

10:52half an hour to reconstruct it.

10:57And more important, it would cost about

10:59$8 on LLM costs.

11:03So that's not a trivial amount.

11:06And if you do it with a decompiler, the

11:08decompiler itself of course it's that's

11:11just Python, so that's free.

11:14But if you do the post process part

11:16where you make it readable, you still

11:18need an LLM, but then compared to the

11:21other one, it's a lot less. So about 50

11:24cents worth of

11:26API calls.

11:28So that's a lot cheaper. And also you

11:30don't really need a front-end LLM, front

11:34frontier LLM. So although the the the

11:37local models can also easily do this.

11:40So

11:41that's actually the main advantage of

11:44the decompiler.

11:46So you can do that.

11:51Now of course when I was doing this, I

11:52had all kinds of interesting experiences

11:56with LLMs.

11:58One of the thing is reward hacking. So I

12:01asked it make something that can round

12:03trip and it said I'm ready, it's

12:06finished.

12:07And then it created this code.

12:09And if you compile this again, you get

12:11exactly the same bytecode out of it.

12:14So for an LLM, was perfectly happy with

12:17it.

12:18And then I had to explain to the LLM,

12:20yeah, this is reward hacking. I don't

12:22want this. Oh, oh, you don't want it. No

12:24problem.

12:25So it understands that I didn't want

12:27reward hacking.

12:30But lots of other things went wrong. In

12:32the beginning it made

12:33it used a lot of regular expressions for

12:36the decompilation and then they nested

12:38like 10 levels of

12:41regular expressions and finally it got

12:43so complicated that the LLM itself could

12:46not understand it anymore and could not

12:48make any progress on it anymore.

12:51So then I

12:53started like all over again. So I'm on

12:56the fifth generation now of my

12:58decompiler, so I had to do that a couple

13:00of times. Another time it created so

13:02many tests, like more than 10,000 tests

13:05and it took like three days to run all

13:08the tests. So it sort of never ended

13:12yeah, with the tests.

13:16So where am I now?

13:19So it's working quite good. I put in

13:22about 800 contracts to to decompile and

13:25it has now decompiled more or less

13:27random contracts and it has decompiled

13:29500 contracts about now

13:32like perfect bytecode.

13:34And if I just keep it running, it just

13:37gradually decompiles more. So I don't

13:40have to do anything

13:43for it, just let it run and it's

13:45continuously improving and and

13:47decompiling more

13:50bytecode.

13:52And but I also also noticed that the

13:54newer the LLM models are, the the better

13:56they are.

13:58So at this moment writing a decompiler

14:00is kind of straightforward, so anyone of

14:02you could also

14:04take a front tier LLM and just ask

14:07create a decompiler.

14:11Okay, but now I have this decompiler and

14:14now my question is yeah, basic to all of

14:16you help me think about what I should

14:18do.

14:19What should I do with the compiler? So

14:22if I just make it open source so

14:24everybody could use it or if I just

14:26decompile all contracts so maybe then I

14:30would enable a hack so I would decompile

14:32a contract that maybe has like a million

14:35dollar worth of value in it and there's

14:37a vulnerability in it and if I decompile

14:39it somebody can hack it and then

14:41the million dollars are gone

14:43and then it's not so difficult to trace

14:45back to me because they can watch this

14:47presentation

14:49and then they maybe can

14:51make me responsible for it.

14:53So I don't want that.

14:56So yeah my my open question to me and

14:59please come to me after the talk for

15:01what would be a good approach to use

15:04this.

15:05So what I

15:06want to do anyway is continue improving

15:08the decompiler

15:10and starts to verify sources on Sourcify

15:13initially with contracts that are

15:16yeah not important.

15:19So yeah this is my presentation. Thank

15:21you very much and we are out of time.

Source and accuracy details

Source export SHA256: c4135419cdaaa8261696ac6466636c2ab52ec3605ab83d2b5dd6e81589fbd8c9