DCSG1 - Solidity Smart Contracts - Kennashka DeSilva
Transcript
Machine-transcribed by YouTube. Expect errors in names, commands and version numbers.
All right. So, once again, please join me in welcoming Kaneshka and Retro. Today, they will be delivering the talk titled Solidity Smart Contract Attacks. Without further ado, I'll be handing the time over to Kaneshka to kick off the talk. Please take it away.
>> Hello everyone. Welcome to our talk,
Solidity Smart Contract Attacks by Kaneshka De Silva and Retro. >> Hey guys, I'm Retro. I'm a security researcher for Coast. I'm working on the fixing blockchain protocols. Yeah, thank you. Let's move on. >> Perfect.
So, hello everyone again. I'm Kaneshka De Silva. So, I am a cybersecurity analyst and a Web3 hacker. I'm a part of Hack Miami, which is our local Def Con and Black Hat group, uh which is based in Miami, Florida, US. Um I'm a part of a group called Black Girls in Cyber as well, and I've served on the board for Women in Cybersecurity, other known as otherwise known as WiCyS Florida. So, this is my LinkedIn information if
you want to if you want to connect with me. And I'll leave that up on the screen for a little bit.
In case they want to connect.
So, disclaimer. I do have to give this disclaimer because, you know, we are at DEF CON.
So, this uh talk is for educational and ethical use only. This presentation is intended strictly for educational and research purposes, and all demonstration are conducted in control and isolated environments. Do not attempt these techniques on system that you do not own or have implicit permission to test, and
we offer no malicious intent. This content is designed to improve security awareness and uh defense. Techniques showed are based on public research, bug bounty report,
and real-world incidents. So, the goal is to understand attack to better prevent them. And if you are a black hat
hacker, please leave.
Okay. So, we're starting this agenda off
with some Immunify uh exploit patterns that we've seen, the trends that we've seen over the years, and some real-world attack breakdowns, and some 2026
uh mega hack use cases and case studies.
Simulation labs, researcher mindset, and
we're going to end it off with some Q&A.
All right. So, let's take a look at at the threat landscape as it relates to Solidity smart contract hacks that we've seen over the years as it relates to uh blockchain security. So, we've seen reentrancy attack, and I'll go into more in-depth on all of these topics uh for
some beginners who are just learning some of these concepts, Oracle manipulation, and some access control attacks as well as flash loan amplification and logic flaws.
So, the current attack surface that we've seen so far from a evolution standpoint from the past, we've seen a lot of smart contract hacks. Now, we have to look at the entire ecosystem kind of like as a whole. We have to look at the bridge attacks, Oracle validators, and governance
because in this case scenario, bridge can connect different blockchain allowing asset and data to flow and move across each ecosystem. So, a bridge attack basically is swapping from one ecosystem to another. So, basically if
you wanted to get Ethereum from Ethereum
to another network such as Solana, you would use typically a bridge to do that. Um same with swapping Bitcoin in general
from to another currency, you would typically need, you know, some kind of like solution if you want to get, you know, another currency in particular on the blockchain or layer two solution. So, a lot of those attacks do exist on the bridge. So, we also want to emphasize some of the Oracle attacks bringing some of the off-chain data on on chain. Things like price, weather, real-world events. The key risk here that we do have to think about it as a data integrity standpoint where, you
know, if the data is manipulated from a data integrity standpoint as it relates to price or uh if the price is not correct in particular, it can be pretty detrimental to the ecosystem. Validators, so validators are responsible for confirming the transaction and maintaining consensus. So if this is compromised, they can enable attacks like double spending. And chain and instability especially in smaller or less decentralized network. So governance, when we talk about governance, we're talking about ecosystems where we have a security councils involved or a doubt involved decentralized autonomous organization.
These are governance controls. They they control protocols that evolve over time usually through token based voting. The risk is that some governance attack allows someone to accumulate enough power to push through malicious proposal or drain funds in particular.
Okay, so let's talk about our first topic, the re-entrance key key failures.
So as we can see here on this diagram, we have a user who wants to withdraw funds to a vulnerable contract which is inherent inherently vulnerable.
And then going down to number two where they make an external call to basically send a currency which is Ethereum ETH.
Going down to number three, they can re-enter that withdrawal. Basically
because there's no controls in place for that. So essentially they make it a malicious smart contract. And then the state gets updated after everything has happened which is basically too late.
All right. So, after the the state updated after the external call, and there are no re-entrancy guard. So, some of how we can safeguard some of these attacks are by putting, you know, some of these safeguard in place for these particular attack. And on the screen here, I have some examples of what a vulnerable re-entrancy attack will basically look like. So, as you can see here in this Solidity program, we have a
vulnerable function, which is in a in it format. It makes call, as you can see here. It makes an external call first, which is dangerous because it has no essentially protection on that function call, as you can see.
The second thing where it went wrong is the state gets updated at a later time,
in general. So, let's move on to our next attack,
which is the Oracle manipulation diagram attack. Oracle manipulation attack. So, we're looking at a diagram here of how, you know, a Oracle attack happens, which can essentially be similar to a flash loan because in a Oracle attack,
it's basically a timestamp of, you know, how a transaction gets validated. So, let's say for instance, real world scenario where we have Bitcoin went from
uh 70,000 to maybe 60,000 in like 1 minute.
Let's say that happened. I hope it doesn't. So, if that happens, and then we have some kind of like Oracle attack where the timestamp doesn't reflect that it went down or that it went up. It can be very detrimental um in general. So, basically uh this is how every uh the diagram. So, from a Oracle attack can be
a flash loan. It could turn into like a flash loan where an attacker they take a large amount of a loan uh on-chain loan
and then they do a AMM swap. The attacker swaps the token on the MMA. So, let me take a step back a little bit for those of you who do not know what AMM is. It stands for an automated money an
automated marker uh markets uh maker. An automated market maker. So,
how many of you know what SushiSwap or Uniswap is by raise a hand?
Okay, so SushiSwap and Uniswap is basically what's used to swap into different currency in particular. So, uh
just to make everything uh much more simplified in general, it's basically a type of decentralized exchange mechanism that allows users to trade asset without a traditional order book. Uh instead of make uh matching buyers and sellers, it uses one a liquidity pool and two mathematical formulas to set these prices in particular. So, let's jump into the third uh diagram flow where the
price uh distortion happens uh which is basically coming from that word Oracle, right? So, the price distri- uh distortion happens when the swap kind of like distorts the market price what the original market price should be. So, let's say we have like a a big arbitrage here. So, the next step is the protocol does read the fake prices and then an over borrow can happen where it can drain the entire ecosystem, the funding the protocol funds in particular.
So, this is basically what
Oracle manipulation looks like in a solidity smart contract in particular. So, we have a couple different function and function calls that happens during this phase. So, as you can see,
just pay attention to the green in in the code for those of you who do not know or read code, I do, but for those of you who do not know or read code, just pay attention to the commenting, the the double slash the green. That will tell you exactly what is going on in the solidity smart contract. So, it makes a vulnerable lending protocol that uses the AMM spot price as the Oracle. And then we go down to the mapping and the address where they're putting up collateral to get the loan, but they do not have, you know, the correct collateral to get the loan that they're trying to basically borrow against.
So, 70% loan to value happens. And then if we go down all the way to the bottom, the transfer is borrowed and tokens to get get sent to the uh transfer borrowed tokens to the attacker. And then that's when everything happens basically. So, the protocol trusts
a manipulative AMM spot price
here where the attacker was able to distort the price of a flash loan and inflate the collateral and over borrow and drain and in return drain the funds.
All right, so let's go to the next topic here, which is access control failure. So in a a in in a in this scenario where
there is zero access control, this is probably one of the worst attack that can happen. So for those of you who understand the concept of like Linux or like computer
programming, uh that's like basically getting root access to someone's information by getting, you know, basically access control to the smart contracts. So look This diagram here is basically shows an attack flow example of how examples of a attack control vector can happen. So basically the attacker can make a function call uh as to a a sensitive function and then of course the smart contract is vulnerable. There is no access or check performed within this. And then they do get access to sensitive data or funds and this basically impacts in a big way leading to loss of trust within the ecosystem, financial damage, theft of funds or data
manipulation. Um so it can be a pretty big deal if, you know, the access control is basically not on point. Uh some of the common examples that we have here in the chart are unauthorized
unauthorized parameter changes, withdrawals as we mentioned before, uh
privilege escalation or abuse. Access to admin functions. So, some way of how we can prevent this from happen is to implement proper access control uh by using ownable or roles uh or in cybersecurity we would in regular cybersecurity we would say our back or a back uh which is uh basically a a way to, you know, or IAM, a way for uh implementing access control on a finer grain access level. Uh least privilege basically.
Um validating, so we want to follow that least privilege as I mentioned. Uh we want to also validate all the critical function calls as well and we want to regularly review and audit access control logic within any smart contract. So, for this access control failure, I don't know if you can see on your end but um we have on top the vulnerable uh smart contract and then on the bottom of how we can implement the fixes for this vulnerable smart contract in general. So, as you
can see here, there is no validation, there's no uh only owner. So, the difference between the top one and then the bottom one is that they have implemented checks to allow only the owner of this smart contract who created uh the smart contract or owns the smart contract to have access to the sensitive function within that function call nested as you can see here. So, always enforce access control, the key takeaway. And on sensitive function, never assume the caller is trustworthy.
Okay, so we have our another topic, which is a flash loan applica- amplification. Um so, I was in the previous talk for Oracle attack, it kind of like goes hand in hand because if you have a Oracle attack, it can lead to a flash loan attack. So, this is a way how attackers can basically amplify this attack in basically one call or one transaction. So, they basically will borrow the money without having the proper collateral to borrow the money. Like say for instance, I want to borrow $100, but I only have
$20 maybe uh for this transaction. They
are able to somehow manipulate the price Oracle, as I mentioned before in the previous slide, or they're able to manipulate the state. Uh this exploit can happen uh from this manipulated state or from the manipulated prices, and that can basically nest into a repay in the loan.
So, all of this is done basically in one transaction in one call. They are able to borrow the money at a very cheap cost, and then they're able to repay it back and then take the profit from that essentially. So, basically this is um what a flash loan amplification attack will look like. Again, just focus on the green part of this uh Solidity smart
contract. Um as to reiterate, the attacker, yes, they are uh borrowing a loan um for a a higher amount that they're willing to put up. And they're able to over-borrow against that inflated value and then repay the loan in one transaction.
All right, so let's go into um one of our uh one of our last topics uh here that we've analyzed within um Immunify reports for logic flaws. It's basically all of what we've covered previously before in general. So, what is considered a logic flaw? Any action, basically, the user that, you know, any action that the user perform and it does not allow the sufficient checks uh any the logic checks or misvalidation within that smart contract should go. If we are expecting that that's okay, but if we're not expecting that logic to happen, it can be extremely detrimental.
So, let's take a look um at some logic flaws that we can see here.
Logic flaws are basically trusting inputs without the validation, as we were mentioning. So, user control values, they're used uh directly. Uh Oracle, as we were mentioning before, data, they assume that they are correct. There is no checks or bounds. Incorrect order of operation. Um so, this effects
happen after the the um interaction. So,
before you can even um check for that um because of the the order of operation of how these flows are nested, it happens right after, so there's no way to basically check if it happened or not. And then uh critical checks that happen again too late or the state did not update before the execution. Um another one is missing the business logic or constraint. No caps on the borrow, mint, or withdraw functions. Uh no rate limits or uh uh cool downs.
No in- invariant uh enforcement and then
no uh over-reliance or uh external system, single oracle, single validator, no redundancy, uh blind trust, and off-chain data.
The next one. All right, so these are attacks that we know about, but within this 2026 landscape, it changed everything because we're going to talk about the most recent attack that just happened just um this month in general. So, the biggest attack happened just in this month of April in 2026. So, basically what happened was $292
million were drained from the Kelp DAO
uh decentralized um organization. So, the largest DeFi exploit happened in the 2026 so far um part of $600 million
of attack wave in the last 20 days. And it was not a Solidity bug, surprisingly. So, basically let's give
uh let me give you a round rundown of what exactly happened. So, on April 18th of 2026, attackers
attributed to the Lazarus Group, they stole approximately $290 million uh from
the Kelp DAO LayerZero bridge. Notably,
this was not a smart contract exploit, but it was a highly coordinated attack targeting off-chain infrastructure. Rather than breaking the contract itself, the attackers they did compromise internal RPC nodes and launch a a DDoS, a denial-of-service
attack against external nodes. And this allowed them to manipulate data being fed into a single point of failure verification system known as the uh
decentralized verifier network, DVN,
um which are independent and and they're off-chain entities uh validate messages and data integrity between different blocks primarily uh within the uh layer zero ecosystem. So, as a result, the Ethereum contract was deceived into releasing funds based on fabricated token burns event on
uh the source chain. So, because of all of this um happened and it appeared to be a a legitimate um traditional security tools failed to detect the attack. Identifying this class of exploit requires cross-chain invariant that we um spoke about. And I'm going to get more in-depth into what invariant monitoring means. Um ensuring basically that tokens
are minted or released on a designated chain strictly matches the amount burned
on the source chain. So, what happened in result? So, there was a swift response that happened measured that helped the the ecosystem limit the damage in the kept out. Um basically, they paused some of their contracts in time uh preventing the additional 95
million loss while the Arbitrum uh security council, they work alongside the law enforcement to successfully freeze more than 30,000 uh ETH tied to
the attacker's subsequent transaction.
Okay, so basically this is the attack flow that we're looking at here. The attacker, they basically compromise the verifier, which is the RPC remote procedure protocol, and they injected a fake message. The The bridge did did validate the false proof and the funds were released. Um so this is basically a step-by-step diagram flow of how this recent attack happened, and it's basically one of the largest to date.
Okay, so we just talked about the root cause. Basically, the single trusted verifier happened. That was one root cause, but there were many different failures that happened as we can see here. There were no redundancy, and the off-chain trust kind of failed. So, with with this being said, more specifically, um the bridge verifier was compromised if the cross-chain message was involved, and the trust model did fail because of that single point of failure that we saw there.
So, let's get more in-depth on why, you know, these defense failed. So, we thought that we were interacting with, you know, a smart contract that was not malicious, but we had a malicious actor. Um some of the inputs from that malicious actor were not being verified, and then there were no invariant checks.
So, the What is uh check or invariant testing in particular? An invariant testing check, it does check the conditions are always true, no matter what the consequences are, it should always be true and never false. So, this rule must never be broken, and if it does break at any point, you found a bug or potentially an
exploit. No matter what the functions are called, um mint, burn, or transaction, this must always hold true.
So, let's go more in-depth on some of the tooling that are based around Solidity smart contract. So, some of the tooling uh that I have listed here, they're ranging from uh SAS, uh static analysis tooling in particular. Um so,
they do check the code before they go into uh production mode. Um so, these
checks are extremely important before, you know, you're basically going on production. Um so, Foundry is one of the most popular one, then we have Slither. Uh then we have, I can never say this word, Echidna, Echidna. Uh and then we have Mythril.
Okay, so, let's get into some of the workflow. So, some of the workflow and some of the tools that we just mentioned, we we can use Foundry as a unit test in the development stage. Um
Slither, I believe, and Mythril, it will always it will always have to be also in the development stage as well. Uh that's where our static analysis tooling comes in because it does, you know, check the smart contract, and it does check all of these uh logic that we did spoke about and attacks before it goes into production mode in particular. Fuzz testing is one of the important one and then exploit simulation as well.
Okay, so some of these are some of the flows. I'm not going to get too in-depth, but these are some of the simulation flows that we're looking at. So, we deploy a smart contract, a test node obviously, and then we fund it and then attack the contract and then drain. Same for the Oracle. We would fork a mainnet and then inject liquidity, manipulate the price and then borrow against that. And then for cross-chain attack, we would mock the verifier, accept the fake proof and then mint the funds.
So, some of these simulation philosophy.
So, in different countries, obviously, there are different laws and I'm based in the US. We're in Singapore and in different areas, there are different laws as it relates to how you can test these smart contracts. Always obviously, always ask for permission and you know, check your local your local state law before you, you know, what interact with any of these tools or or perform any of these testing in particular. So,
we never want to use the mainnet. We always want to use a testnet. We always want to fork the code on our local environment, of course. And we always want to think like the attacker, safely, of course.
And this is if you're looking to implement a lab, this is how you would essentially set up a lab environment for some of these tools that we did talked about. So, as it relates to Foundry, you would basically forge for the test. And then the test and the script and then uh pass for the RPC interaction and then it has fast local Solidity workflow as well. And then there's another tool called Anvil. Uh basically, it's a fork it's a local fork of these blockchain mainnet. Particularly
Ethereum. You can basically fork a real chain state locally on your local device. And then it is safe for exploit simulation. Uh and then we have the mock contract, of course. So, you can mock basically how the tokens and or how the or how you interact with oracles and bridges.
And basically the goal is to reproduce these conditions safely without touching any mainnet, right? So, for advanced we're we're trying to think basically at a advanced researcher level or mindset.
So, with that with that being said, you know, you would want to work in a community of hackers. You want to build a community of hackers where you're able to link multiple bugs in in one attack pattern. And then you want to model the economics. So, basically learning about the blockchain ecosystem, learn, you know, how many tokens are within the ecosystem, how many you know, how much liquidity does that ecosystem has in general, and how much
profit or incentive does the ecosystem basically provide? So, for example, in a
BTC in Bitcoin ecosystem, we have uh
the uh >> What do you call them? You have the
>> uh miners. We have miners within the BTC ecosystem. They are used as a reward function. Um and I think it's pretty interesting because in the BTC ecosystem we're using kind of like the greed of the human to basically uh provide that security for the ecosystem in general. Um and then we're able Think thinking in
a advanced researcher mindset, you want to break any assumption that this contract is secure. Uh and then question every trust boundary and the invariants.
So, closing the next exploit would not be a mis- uh require- it would be a misplace trust.
So, we're going to With that being said, we're going to open it up for Q&A.
Any questions so far?
I guess there's no questions.
Oh, okay. Uh with that being said, uh there are no questions. We're going to go ahead and um end the session. Thank you, guys, so much for attending. And I'll see you in the next blockchain talk. And we're we're we're basically representing the uh cryptocurrency village. We're over here on this corner. So, if you want if you have any questions or want to follow up on any of the topics that we just have discussed, definitely come to the Crypto Village. We have some CTF happening at the same time, and we also have some prizes as well. So, thank you so much for attending. Thank you.





