DSS 2026 / Day 1 / Pearl Hall
Smart Contract Invariants Protect Against Cybercriminals
Sofia Bobadilla · Martin Monperrus
Source: YouTube automatic caption track · Exported 2026-11-16. Timestamps link to the source video. Cue end times were not supplied.
Transcript
0:01Thank you. So my name is Sophia Varia
0:04and I'm a thirdy year PhD student at KTH
0:07the Insty and my PhD topic is around
0:10smart contract security. Uh previously I
0:12work a bit on like patching smart
0:14contracts and exploit generation and
0:16today we we're looking at most effective
0:19protections that one can have in their
0:20code. But before our talk uh a bit of
0:23promotion we are coming from uh Sweden
0:26where we have this research group uh on
0:29blockchain security and cyber supply
0:31chain where our group leader it's here
0:33with me Martin who is a professor at
0:36KTH. So we will be switching between us.
0:40So uh yes smart contracting variance
0:44protects against cyber criminal. That's
0:46our claim and hope we convince you by
0:47the end of the talk.
0:50So before we continue, let's make like a
0:53clarification of the terminology we
0:56utilize throughout the talk and through
0:57the paper. So we often discuss about
1:01invariance, right? Like auditing varants
1:03and uh how to use them for auditing
1:06protocols and developing protocols. Uh
1:08here we define them as the specification
1:11of your code. So the overall logic that
1:14you want to apply on your protocol. For
1:16example, if it's a flash loan that
1:18you're trying to implement, one
1:20invariant will be money must come back
1:23at the end of the transaction. Now, if
1:26you have this specification, right, you
1:27have to be uh to you have to write it in
1:30the code otherwise it's just a
1:32documentation uh a natural language
1:34description and it's never enforced in
1:36your code. So to make this apply in your
1:38code, you have a programming variant in
1:40which you write this in your code in the
1:42state of a in a require statement or a
1:46modifier. And what this program will do
1:49is that if well defined every time
1:52someone interacts with your contract on
1:54chain on the transaction there will be a
1:56runtime check. So your required
1:58statement will be executed and will
2:00ensure that your condition is valid. In
2:03the case of flash loan, it it means that
2:06at the end of the transaction, there
2:07will be a piece of bytes that will
2:09ensure that the money came back to the
2:10protocol.
2:12So now way to see it for us is invarian
2:15is the overall rule. The perm invariant
2:17is the code condition that you write and
2:19the ring check will be the one that will
2:21revert when someone is trying to hack
2:23you in simple words.
2:27So building on this um as I said in our
2:30team we are a few PhD students and
2:32master students and Martin and we often
2:35go over the exploits of the week and we
2:39read the entire blog thread and Twitter
2:41and we're like okay what happened in
2:42this smart contract hack and here for
2:44scoping we're talking about smart
2:46contract hacks not general hacks so it's
2:48not about the compromised wallet it's
2:50about the code that was uh with a
2:53vulnerability
2:54and then we came to this hypothesis that
2:57a real attack or like a a smart contract
3:00attack came from a property that was
3:04declared from the protocol but never
3:05really enforced.
3:08So our belief is if we find those
3:10programming varants that should have
3:12been written we could have prevented
3:14this attack.
3:16So our expectation is the expected
3:18protocol property was missing a runtime
3:20check and that's what the hackers found
3:22and that's how they got the money.
3:26So we are software engineer research. So
3:29how do we apply science to evaluate
3:31this? So we started from our very good
3:34uh repository defi hacklabs which is a
3:37community contributions of trying to
3:40replicate exploits in the form of proof
3:42concepts and uh we have uh rich
3:45resources to understand the exploits and
3:47to trace which protocols which contracts
3:50on the protocol were involved and so on
3:52and then we also utilize uh the onchain
3:55evidence. So it's a real exploit. We
3:58have transactions to track. We have
3:59transactions that we know that are
4:01malicious and transactions that we know
4:02that were normal usage.
4:04And utilizing this we proposed the
4:08hardened version of the contract. So we
4:09kind of asked the question what would
4:11have happened if the missing variant was
4:13in the code and how that hardened
4:16contract would have survived against the
4:18PC against the attack transaction and
4:21how it it behaves on the onchain uh
4:24traffic.
4:26So we have two oracles here. The first
4:28one is the PC by the fihack labs and the
4:32other one is the uh onchain transaction
4:34replay which is we collect transactions
4:37and we try to reproduce them on the
4:39harder version that we very carefully uh
4:42wrote.
4:44So what does these oracles will tell us?
4:46So first the hacklabs will tell us and
4:49then the P will tell us whether the
4:51attack is being prevented but then the
4:53onchain transaction replay will tell us
4:55if we can prevent the malicious
4:58transactions and we can't uh preserve
5:00the normal traffic of the contract.
5:04So how how we managed to do this? So we
5:07had to build our own uh transaction
5:09replay tool and uh we built on sources
5:12of truth. So this is attacks already
5:15happened and we have all the resources
5:16that occur before. So here we hence we
5:18have a onchain trace that's the onchain
5:20trace that happened. So what we want is
5:22that for normal usage the onchain trace
5:26on the harden version has to stay the
5:28same and the uh the trace for the
5:31exploit has to defer with the um in
5:36harden version. So we collect the
5:38onchain trace which is O. And then since
5:40we are we are modifying the bite code of
5:43the contract. We want to ensure that our
5:45replay mechanis is sound. So we
5:47recompile the source code uh in the
5:49setup that we will do with the harden
5:51version. Just ensure that we are
5:53recompiling the correct way which if
5:54you're in this room you probably know
5:56that is not an easy task. And so if we
5:58can have some replay fidelity in our
6:00tool, then we go and we check our harder
6:04hardened version of the contract which
6:05is the contract but plus the missing
6:07environment. And here this included
6:10modification. It's targeted to this
6:12required statement. So we don't change
6:14the logic uh or the way the functions
6:16operate. It's mostly like what
6:18properties were the protocol saying that
6:21should be there but they were not
6:22enforced. So if R can replicate O then
6:27we check whether the harder version can
6:30have a similar trace as the recompile.
6:33So from here we will uh expect and
6:35analyze these two cases. So for the
6:38onchain um for for the transaction
6:40replay we will expect or we will look
6:43for in which cases we store is unchanged
6:45and here the hope is that we maintain
6:47the normal traffic of the contract and
6:50then we will look in which cases the
6:52story is not preserved. So this
6:53transaction that is it happened before
6:55and it passed why is it not passing
6:57right now and here we had two options.
7:00So either our invariant is operating
7:02correctly and that transaction was
7:04indeed malicious or we have a over
7:06restriction. So imagine for example it
7:08was a price oracle manipulation and we
7:10put a threshold that was too tight. And
7:13now Martin the floor is yours.
7:18>> Thank you Sophia.
7:20>> Um who has ever submitted a an academic
7:23paper in the room?
7:27Who has ever gotten a paper rejected in
7:29the room? Ah, you're a true scientist.
7:33So, so you know, Sophia could stop here
7:36because she has this the theory, right?
7:38Can I go back? I can. So, that's the
7:39theory. In theory, everything is
7:41perfect. You write an environment and
7:44the environment protects against cyber
7:46criminals and you're happy, right?
7:47There's nothing more to do. But then
7:49comes a reviewer and the reviewer say,
7:51"Yeah, Sophia, I can't accept your paper
7:53because you have to validate that. you
7:56have to show me for a year for real
7:57attacks
7:59that it actually works and this is where
8:01you spend another six months of your PhD
8:03or even a year you know just to walk and
8:05more and more and more and more to
8:08actually prove and that's what we show
8:09here. Uh so we took real attacks in defy
8:13hacklabs that's the environmental data
8:15sets. So you know they they are real in
8:18all possible sense in the sense that
8:19they are onchain sure but also in the
8:21sense that there are real money like
8:23there were real funs of losses here. So
8:26real attacks for which we identify the
8:29missing environment. We put the missing
8:30environments recompile and we check that
8:32the attack is blocked.
8:38That's perfect. In all cases, the attack
8:41uh is blocked. The the attacker cannot
8:44run with the funds. So far so good. So
8:47here we demonstrate that the invariant
8:49would block the attack. But you know the
8:51environment could say revert always.
8:54Then it also just freeze the contracts.
8:57So all those those attacks are on real
9:01contracts. So those real contracts are
9:02real transactions. Past transactions
9:04more than 100k. It's a lot of past
9:06transactions.
9:08So one by one we rerun all those
9:10transactions
9:12on the new contract with the new require
9:14statement and we check whether we have
9:17the same the same onchain semantics
9:19whether we have the same behavior. Is
9:22that the same? Is that the same? Yes.
9:23Yes. Yes. Yes. Yes. No. H interesting.
9:27Yes. Yes. 88 98% of of yes. So it's the
9:32exact same semantics. The environment
9:34doesn't break anything. No. Why do we
9:36have slightly not a perfect fully
9:38perfect solution? Uh this is where it
9:41becomes very interesting. Uh reason
9:43number one is uh is gas semantics. So
9:46you know etherm is the only primary
9:48language in the world where computation
9:51may depend on execution performance
9:52let's say and so there is semantics with
9:54gas and see we change a bit the gas with
9:56the environment. There are some obscure
9:59changes happening here.
10:01Sure. Uh but the most important
10:04interesting is actually what comes next.
10:07Uh so that's here a guy. It was one of
10:10the million tokens uh which was pumped
10:13and dumped at some point. Not even dump
10:15because it was hacked during the pump
10:18because of a missing authorization
10:20check. So most authorization are done.
10:24Yeah. So missing it's not here. That's
10:26the original code. You don't see it. So
10:28the high any any permissionless attacker
10:31could call this obscure family uh
10:33function here
10:36the fix the missing environment because
10:38smart contract environments protect
10:40against cyber criminals is this required
10:43statement here that it's a permission
10:45method so only the owner can can call
10:48this uh this method
10:50good uh there was some pumping on this
10:53token so we have you know a few
10:54thousands of of past transactions to
10:56look at so we delay the few thousand
10:58pass transactions
11:01pass pass pass pass pass pass pass pass
11:02pass pass pass pass pass pass pass pass
11:02pass pass pass pass pass pass pass pass
11:02pass pass pass pass pass pass pass pass
11:02pass pass pass pass pass pass pass pass
11:02pass pass pass pass pass pass pass pass
11:03pass pass pass pass pass pass pass pass
11:03pass pass pass pass pass pass pass pass
11:03pass pass pass pass pass pass pass pass
11:03pass pass pass pass pass pass pass pass
11:03pass pass pass pass pass pass pass pass
11:03pass pass pass pass pass pass pass pass
11:03pass pass pass pass pass pass pass pass
11:03pass pass pass pass pass pass pass pass
11:03pass pass pass pass pass pass pass pass
11:03pass pass pass pass pass pass pass pass
11:04pass pass pass pass pass pass pass pass
11:04pass pass pass pass pass pass pass pass
11:04pass pass pass pass pass pass pass pass
11:04pass pass pass pass pass pass pass pass
11:04pass pass pass pass pass pass pass pass
11:04pass pass pass pass pass pass pass pass
11:04pass pass pass pass pass pass it f f f f
11:05f f f f f f f f f f f f f f f f f f f f
11:05f f f f f f f f f f f f f f f fail
11:07we look at it and it's not the
11:09transaction that is in deflab it's a
11:11transaction that happened you know six
11:12hours before seven hours before so we
11:15what we actually detected in this case
11:17is that we we detected you know canary
11:18testing of the attack some people who
11:20tried the attack it was not the final
11:22attack with all the funds but they
11:23actually triggered the exact same
11:25violation of the security property
11:28onchain
11:30uh and we could detect it. So this fully
11:32validate the soundness of the approach
11:33because not only we detect the one big
11:35attack but you also detect all the
11:38canary test before by definition because
11:40they violate the same security
11:43environment.
11:46Um and that the beauty on on chain all
11:49canary tests can be seen uh including uh
11:52the Binance hack. you know there were
11:54some carrying test 23 minutes before the
11:56actual hack um
12:00which means you know people should do
12:01live monitoring uh but yeah I don't want
12:04to uh to digress here um another example
12:08is the why earn uh problem
12:12um so it was it was also a missing
12:16authorization check like this one and so
12:19you you make the the method the the
12:22function permission so So far so good.
12:24It blocks the attack. We're happy.
12:26Oracle number one is happy. Oracle
12:28number two is replaying the historical
12:30transactions. And we see, you know,
12:32quite a few of reverts. They all look
12:34the same
12:37and they look very legitimate. Um, and
12:40so in this case, it means the the the
12:42the reverted transactions were about the
12:47keeper transactions which are part of
12:48the protocol. the protocol add some
12:50permissionless methods to be called by
12:52keepers and in our manual analysis uh we
12:55missed that aspect of the protocol. So
12:57we wrote an environment which was too
12:59strict and by replaying on the
13:01historical transactions we detected that
13:03this environment was too strict.
13:07So it also validates you know the
13:08soundness of the full approach uh not in
13:11yes we did a mistake uh but it does
13:13validate the soundness of the approach.
13:17So
13:19to conclude, smart contracts
13:21environments are your best friends for
13:23sure. Uh and we know that in the
13:26community, you know, solidity is is
13:28perhaps the one language with the most
13:29the highest density of environments and
13:31that's good, but it's still still not
13:33perfect. Um and we demonstrated here
13:36that you know so that's many of of us
13:39are auditors here. when when you get an
13:42audit uh you know finding you might say
13:44okay what's missing is I should actually
13:47call if then else do something else not
13:50necessarily you know fixing a security
13:52problem doesn't mean necessarily being
13:53imperative in your fix it mean just
13:56restoring the security environment and
13:58then whatever goes wrong before that's a
13:59beauty environment whatever goes wrong
14:02it will still be caught by the security
14:04environment
14:05so you have to as as developers and as
14:08auditors we have to understand you know
14:10the core security properties how they
14:12are translated into into require
14:15statements and a require statement
14:17becomes something which is falsifiable.
14:19we can get it falsified on the PC. uh we
14:22can get it falsified on the real attack
14:26and
14:28when you have historical transactions
14:29you can replay the historical
14:30transactions
14:32and this is where you can say hey Martin
14:34yeah thank you very much uh for this
14:36research but uh you know for a new
14:38protocol we don't have historical
14:39transactions
14:41which is correct so this aspect of our
14:43work of the historical transactions is
14:44to validate the entire you know
14:46framework concept framework um in
14:49practice you don't have this but what we
14:51want
14:52to what we claim and what what
14:54developers, auditors, all of us in the
14:56security committee should do is that we
14:58should be obsessed you know days and
15:00night by identifying the missing
15:03environments
15:04uh with our you know poor brains and
15:08also with super intelligence artificial
15:10intelligence or I don't I don't know
15:12exactly but yeah we can you can you can
15:13use AI to find the missing environments
15:15to improve the environments and uh and
15:17to improve the overall security of of
15:19our protocols.
15:21Uh, thanks a lot Sophia. Thanks a lot
15:23for your attention. We can take a few
15:25questions. Thanks a lot.
15:30Questions.
15:41>> Thank you. uh the data and I just wanted
15:44to ask if you identify some family of
15:48varants that are commonly missed.
15:51>> Yes. So in the paper we proposed like a
15:54taxonomy h actually on this area there's
15:57a few related work and actually the
15:59first one was uh by the moit in storaa h
16:03so there are like um your classics
16:06access control your classes uh price um
16:10pricely page um
16:14there were approximately eight cases
16:16that we identify and a few of course are
16:18related to uh business logical designed
16:21but most of them could fall into these
16:23categories of uh admin roles,
16:26permissionless design, uh price
16:28manipulations and dependencies
16:32and related questions of the varants you
16:37if I correctly you went and manually
16:40like fixed the
16:42um how many of I forget the numbers that
16:46you were like 18 28
16:48>> 28
16:48>> yeah 28 how many of those invariants you
16:52wrote. Do you guess probably but how
16:56many of those do you think the team that
16:58wrote the code knew about the invariant
17:00and uh never checked it and how many of
17:04them are for example the invariants that
17:07don't check for an authority are just
17:09like they knew probably they just didn't
17:12put it but there are some complicated
17:14invariants that I think that's the main
17:16challenge here as you as you say so of
17:19those 28 How many would you classify as
17:22trivial? Maybe like Yeah, I forgot to
17:24put it. How many are actually complex
17:27environments that are probably hard for
17:28a human to think about?
17:32>> Um so I will say that um
17:35um we maybe it's not easy for me to
17:38answer these questions because I got all
17:40the resources right. I got sources
17:42afterwards. So I was not in the mind of
17:44the developer. H and it was not an easy
17:46task for us to you know abstract. We
17:49found some cases in which everything was
17:51completely wrong like all the accounting
17:53was completely wrong but then we were
17:54thinking okay what property should they
17:57have thought about and so for example
17:58the one of them was like only uh money
18:01from the account involved in this
18:03operation should be modified and with
18:05that you will have prevented uh I would
18:08say that um
18:11many of them 20 out of 28 were like uh
18:14very tough to identify but we are from
18:17the mind of the
18:18>> postmortm.
18:23>> Thanks.
Source and accuracy details
- Names, organizations, technical terms, code and numbers may be misrecognized.
- Source wording and disfluencies are preserved; no editorial corrections were applied.
- Export contains whole-second cue starts only; cue ends and subsecond timing are unavailable.
- A full caption-track export does not establish that every spoken word is represented.
- Automatic YouTube captions; not human-verified against the audio.
Source export SHA256: e9e099e08051f9754b3b52fe87253317e04daf451dc513d3756e2482e102d2ae