Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
Following two significant attacks on lending protocol bZx, what are the potential ramifications for the DeFi sector?
Earlier this week, the decentralized lending protocol bZx was exploited in back-to-back âflash loanâ attacks. While the two exploits were distinct, the end results remained the same. In total, $954,000 was gleaned from the platform. But what exactly happened? Was it an exploit, a simple case of arbitrage or a malicious attack? And where does decentralized finance go from here?
It hasnât been a good PR week for the DeFi sector. For some, the movement promising an alternative to the legacy financial system is starting to look like a failed experiment. For others, the attacks amounted to little more than being caught on the wrong side of a trade. But regardless of semantics, whether these attacks transpired from a legitimate loophole or were the result of a premeditated attack, faith in DeFi is truly being tested.
The first attack
On Feb. 14, the first exploit occurred. In a post-mortem compiled since the incident, bZx co-founder Kyle Kistner describes the exact moment the attack occurred. The bZx team was out for the ETHDenver conference â an Ethereum soiree that ironically celebrates the best of DeFi. Alarm bells started ringing when the team received information about a âsuspiciousâ transaction. âWe immediately returned home from the tBTC happy hour,â writes Kistner.
Kistner notified the members of the companyâs Telegram group, explaining that an âexploitâ had been executed on a bZx contract â which was promptly paused â and that a âportion of ETHâ was lost. The actual amount harvested in the first incident totaled 1,193 Ether (ETH). Echoing the words of Binance boss Changpeng Zhao, bZx affirmed that user funds were âSAFU.â
Fortunately for its users, bZx operates on a failsafe â collecting 10% of all interest earned by lenders and aggregating it into an insurance fund. Consequently, the losses to bZx users are nominal. For the bZx platform, however, the attack came with a hefty reputational cost.Â
Pulling the heist
But how did the attacker succeed in materializing a profit of 1,193 ETH from nothing? To use a somewhat reductive explanation, the attacker devised a network of transactions to execute a âpump and dump.â
Hereâs how it went down:
First, the attacker took out a 10,000-ETH loan on the DeFi lending platform dYdX. They then split the loan between bZx and another lending platform known as Compound. The ETH sent to Compound was used to collateralize another loan for 112 wrapped Bitcoin (WBTC). Meanwhile, the 1,300 ETH assigned to bZx was used to short ETH in favor of WBTC.
Harnessing the low liquidity of a decentralized exchange known as Uniswap, which shares price data with bZx via DeFi network Kyber, the attacker managed to pump the price of WBTC on Uniswap through the WBTC short placed on bZx.Â
The antagonist then dumped the WBTC borrowed from Compound on Uniswap, taking advantage of the inflated market rate. With profits in hand, the attacker paid back the original loan from dYdX in full and pocketed a cool profit of 1,193 ETH leaving bZx with an undercollateralized loan.
But hereâs the kicker: Everything detailed above was executed in a single transaction â accomplished through a DeFi product known as a âflash loan.â
Flash loans and contract bugs
Flash loans allow traders to take out a loan without any backing â i.e., they remove the need for collateral. Theyâre able to do this because the loan is paid back immediately. Arbitrageurs use flash loans in conjunction with smart contracts, which they code to carry out calculated arbitrage trades: the simultaneous buying and selling of assets in different markets.
Executed atomically, flash loans are marketed as ârisk-freeâ as the Ethereum network rectifies any failure to pay back the loan by reverting the original transaction. As a result of their atomic nature, no party was able to intercept the flash loan attack while it was happening. Zhuoxun Yin, head of operations at dYdX â the exchange where the flash loan was borrowed â told Cointelegraph:
âWe were not aware of anything officially until it all transpired. These transactions are all atomic, meaning the whole thing executes or fails.âÂ
However, it wasnât just flash loans at the attackerâs disposal. They also took advantage of vulnerabilities within the bZx smart contract. Kistner explained to Cointelegraph how the initial attack was allowed to occur:
âThe first attack was fairly simple in that they made a large trade that ate into the funds of lenders. A flag was set higher up in the stack that allowed the trade to bypass a check on whether or not they were putting lender funds in danger.â
The bypassed check Kistner mentioned is the very same that former Google engineer Korantin Auguste refers to in his detailed analysis of the attack: âThe attacker exploited a bug in bZx that caused it to trade a huge amount on Uniswap at a 3x inflated price.â
As it turns out, a crucial function to verify whether market slippage had occurred didnât trigger. If it had, it would have nullified the attackerâs bZx position â rendering the trade ineffective. Instead, the attacker was allowed to continue unimpeded.
Round two
Four days later, on Feb. 18, bZx fell victim to yet another attack, forcing yet another protocol suspension. Similarly to the first, flash loans were used to facilitate a pump and dump on Uniswap â this time resulting in the attacker netting 2,378 ETH.
This time around, the attacker took out a flash loan of 7,500 ETH on bZx, trading 3,517 ETH for 940,000 Synthetix USD (sUSD) â a stable coin pegged one-to-one with the United States dollar. Next, the attacker used 900 ETH to purchase another round of sUSD on Kyber and Uniswap, pumping the price of sUSD on to over 2.5 times the market rate.
Then, using the now-inflated sUSD borrowed from Synthetix as collateral, the attacker took out a loan of 6,796 ETH on bZx. Using the freshly borrowed ETH and the ETH left over from the original loan, the attacker paid back the 7,500 ETH flash loan and once again skimmed a profit, this time to the tune of 2,378 ETH.Â
This left bZx with yet another under-collateralized loan. Luckily, this was covered by the insurance fund.
Blaming the oracle
Rather than a repeat of the original bug, which was patched following the first attack, round two was apparently the result of oracle manipulation.Â
Oracles are blockchain-based intermediaries that feed external data into smart contracts. In this case, bZxâs price oracle relayed the inflated sUSD price without a verification, leading bZx to believe the loan of 6,769 ETH was fully collateralized. An analysis from PeckShield, a blockchain security firm, summarized the oracle exploit as follows:
âThe oracle manipulation substantially drives up the price of the affected token, i.e., sUSD, and makes it extremely valuable in the bZx lending system. The attacker can then simply deposit earlier-purchased or hoarded sUSD as collateral to borrow WETH for profit (instead of selling or dumping).âÂ
Yin notes that using Kyber (and by proxy, Uniswap) as a price oracle, bZx may have been asking for trouble: âProtocols should be using high-quality oracles, not on-chain DEXs directly as price oracles. Oracles that are powered by off-chain reporters would be safer.â He also pointed the finger at DEXs that support low liquidity assets:
âMany DEXs support assets that are very illiquid. Illiquidity means the markets can be moved a lot more easily. Liquidity needs to improve, which I'm confident will happen over time â there are technical and market factors that need to be overcome.â
Volatility coupled with low liquidity can prove to be a treacherous mix. In this instance, market slippage was inevitable, and the attacker knew it. Fortunately, since the incident, bZx has taken the decision to partner up with decentralized oracle network Chainlink and has made use of its price data.
Hack, attack or legitimate arbitrage?
For some, these cases amount to little more than a proficient arbitrage trade. However, the reality isnât that simple. The attacker abused several vulnerabilities within bZxâs protocols, taking advantage of low liquidity markets and employing blatant manipulation tactics. Kistner, co-founder of bZx, told Cointelegraph that itâs a cut-and-dried case:
âItâs an attack because it used our code in a way that it wasnât designed to produce an unexpected outcome that created liabilities for third parties.â
Sharing a similar opinion, Auguste maintains that no matter how you look at it, these were malicious attacks:
âIn both cases, there were bugs exploited in the bZx code, so these were definitely attacks and cannot qualify as a clever arbitrage or something legitimate.â
Cointelegraph also reached out to Thomas Glucksmann, vice president of global business development at blockchain analytics firm Merkle Science. Much like the others, Glucksmann classified the incident as a hack, suggesting that it follows the same principles as theft by any other means.
However, he was quick to turn the spotlight back on bZx, insinuating that any attack vectors should have been patched sooner, especially given the lessons learned from the decentralized autonomous organization hack in 2016.
âDevelopers can typically avoid such scenarios by ensuring a thorough smart contract auditing process. Itâs amazing that some teams still did not learn from the consequences of The DAO debacle and demonstrates the current fragility of DeFi services.â
Glucksmann didnât write bZx off altogether, though. In terms of damage control, he says both the post mortem and the insurance fund go a long way to soften the blow.Â
What about DeFi as a whole now?
Following the last bZx attack, the DeFi sector reported a significant loss in locked-up assets, falling approximately $140 million from a peak of $1.2 billion on Feb. 18. Just weeks prior to the attacks, DeFi boasted a milestone $1 billion in total locked-up assets. This deterioration was especially prevalent in locked Ether where losses totaled around 200,000 ETH, according to data from analytics site Defipulse.com.
Nevertheless, Kistner doesnât see these exploits as DeFiâs death knell. Instead, he suggests that itâs merely part and parcel of ecosystem development:
âNASA didnât hire people who all wrote perfect code to launch space shuttles. What they had were rigorous processes in place throughout the entire development cycle of the code. We need to treat launching a DeFi DApp like we treat launching a shuttle into space.â
While DeFi is still in its infancy, the once-niche market continues to mature, clambering to the forefront of mainstream attention. However, the sector is operating without an adequate sandbox â an omission that is bound to provoke further hiccups.Â
Related: DeFi Begins to Move From a Niche Market to Mainstream Finance
For Glucksmann, while a greater emphasis needs to be placed on âbattle testingâ protocols before launch, discussions on appropriate regulation also need to be held. So, it is too early to write off the sector:
âTo date, the only profitable business models in the crypto space were mining, exchanges and liquidity provision. DeFi services such as lending could be the next. A lack of regulation covering DeFi in many jurisdictions presents opportunities as well as risks, so users of DeFi services need to be willing to accept this for the time being.â
Arguably, due diligence procedures such as Know Your Customer and Anti-Money Laundering checks would go some way to disincentivizing bad actors. Though, given the inherently decentralized nature of DeFi, its proponents would likely revolt at the very idea.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.