Biggest Hacks of 2023 (So Far)

DeFi Security Summit 2023 · 16 Jul 2023 · 8:31

Zeeshan Meghji walks through the largest hacks of 2023 so far by root cause. Missing health checks caused the Euler Finance and Platypus losses, misconfigured markets enabled attacks on LendHub, Hundred Finance and Yearn, unvalidated external contract and function parameters were exploited on Dexible and SushiSwap, and read-only reentrancy hit Midas and others through manipulated Curve LP token prices. For each class he gives a fix, such as negative tests, invariant testing and fuzzing, deployment script tests on a mainnet fork, strict parameter validation and reentrancy guards.

Speakers

Topics

From DeFi Security Summit 2023, hosted by DeFi Security Summit.

Transcript

okay um so today we'll be talking about uh the largest hacks of 2023 so far uh specifically in the context of their root causes now any protocol that maintains collateral has to ensure that the user's collateral is sufficient to support their debt and so this is done by calculating a health Factor if this health Factor drops too low then the position can be liquidated so it's essential for all the appropriate protocol actions to um ensure that um that uh this check is in place in these functions or the position will become liquidatable leading to unexpected States unfortunately some

protocols do forget to implement these checks in certain functions and so far this has led already to a loss of over 206 million this year so far the largest hack of 2023 so far is still the Euler Finance hack and um the Euler Euler Finance is a lending protocol which supports liquidation which is very profitable in fact a liquidator gets a 20 discount when purchasing the collateral of a liquidated position also Euler Finance has a function called donate to reserves and this allows the user to donate their collateral to the

protocol unfortunately this function was missing a health check at the time of the hack and so this allowed the attacker to create a liquidatable position at will and then when they did this they could immediately self-liquidate taking advantage of that 20 discount and making a profit at the expense of the protocol and by repeating the step several times they were able to drain this protocol the root cause of the Platypus hack which also happened this year was very similar in this case the protocol was exploited through the emergency withdrawal function which was lacking this health check in the correct spot so the protocol did not check the health of

The Possession after deducting the collateral to be withdrawn and so this allowed the attacker to withdraw as much collateral as they wanted to and essentially steal funds from the protocol um so you can avoid missing health checks by writing tests for all the appropriate functions in the protocol these tests can attempt to bring the position below the liquidatable threshold and you should assert in these tests that this attempt should revert or fail it can also use invariant testing or fuzzing to when uh to find specific cases where this threshold can be reached um now uh most D5 protocols require some type of configuration and when

misconfigured this can lead to devastating consequences um just this year we've already seen 25 million loss just due to a misconfigured markets now one of the first large hacks of 2023 was on the Len Hub protocol a lendhub is a compound fork and it has L tokens instead of C tokens so what happened here was that there were two lbsv markets there was the new and current one and then there was the deprecated one the new lbsv market referenced the new comptroller and the old lbs free market referenced the old controller so this allowed the attacker to deposit their collateral in the Old Market take a loan from the new market and then immediately withdraw their collateral

from the Old Market without repaying any of the loan the root cause of the 100 Finance hack also this year was very similar and it's also a compound fork in this case the Comptroller was listing two different hwbtc contracts the one that was used by normal users of the protocol and then this duplicate Mt Market which had been completely unused and the hacker exploited this to steal funds from a protocol here's another type of hack due to a misconfiguration which happened on yearn Finance this is actually a pretty old contract but the hack happened this year so the problem here was that instead of listing the fulcrum market for usdt it

listed the fulcrum market for usdc this allowed the hacker to manipulate the reserves and steal approximately 11 million dollars worth of assets from this contract now Market misconfiguration can be prevented by writing tests for your deployment script and this can be done on a localized mainnet Fork before you actually deploy to mainnet so you should not only assert the correct state of the contract but you also should have negative test cases such as checking for these duplicate or empty markets because as we've seen they can lead to very serious hacks and auditing firms can also help to ensure the correctness of this state now some D5 protocols allow their users

to pass in parameters which represent external contracts to be called and some protocols even let you specify the function to be called on this external contract when these parameters are not validated this can lead to some serious hacks and this has happened several times this year uh so a great example is the hack which happened on daxable decibel is a DEX aggregator and it actually allows the user to specify the contract address of the decks as well as the function the swap function to call on that text and so what the hacker did in this case is rather than specifying a deck's address they specified a token address and rather than using a swap function they use a transfer function this

effectively allowed the hacker to manipulate decibel into transferring its users tokens directly to the Hacker's account and this was possible because the users approved ductable to transfer their tokens a very similar hack happened on Sushi Swap this year in this case the hacker was able to pass an invalid pool contract into the sushi swap router function and this allowed them to take advantage of approvals given to this router by various users and they were able to perform a very similar hack to the dexable hack now these types of vulnerabilities can be prevented by performing very strict validation on these types of parameters these external contract addresses and

call data and um you can um you can also consider redesigning the protocol so that such flexible parameters are not required this would greatly reduce the attack surface uh so another huge Trend we've seen in 2023 is the rise of read-only re-entrancy hacks and we've seen at least four major hacks um happen due to this vulnerability um the first one that happened this year this year was on the Midas protocol and so Midas is a lending protocol which allows um curve LP tokens as collateral and the way it determines the price of this collateral token is it uses this virtual price function on the curve pool the guide virtual price function depends

on the total supply of the lp token so the attacker removes a large amount of liquidity from curve and then this results in a large amount of LP tokens being burned resulting in the supply decreasing considerably so this in turn affects the value returned by the get virtual price function which is now going to return a very inflated price and when the Callback function on the attack contract is called it's able to take this huge loan from Midas which Midas allows because it thinks that the attack contract has a lot more collateral value than it really does and there's been a couple of variations of this style of hack on D4 switch use liquidation instead of borrowing and then on sentiment and sturdy which use

balancer LP tokens instead of curve LP tokens now this type of vulnerability can be prevented by using some type of function before some type of function with a re-entrancy guard before retrieving the price or by using a library such as balancers Vault re-entrancy lib also generally speaking we should be really cautious with LP token price calculations so this brings us to the end thank you so much for listening thanks for the talk [Applause]