Hura-Hura !!! Finally I finished @PatrickAlphaC Foundry Solidity course 🫡🫡🫡 It took me 4 months , 3 days and 236 hours 😱 . I studied everyday and now ready for @cyfrinupdraft security course 😍
Thank U Patrick for this great opportunity !!!
If you are into Bitcoin, you should be running a small lottery miner.
WHY?
They cost anywhere from $35 to $400. And most of them only cost $1-6 a month in electricity to operate.
If you hit a Bitcoin block, you earn 3.125 BTC worth around $250,000+ today.
You receive that straight to your Bitcoin wallet instantly, no questions asked.
The chances of doing this are extremely low... but they are not ZERO.
Your chances are only zero if you don't try. 20+ solo blocks where hit in the last year. With many of those on machines no more powerful than the one below.
And unlike the actual state lottery, which is a one-and-done, where if you don't win, that's the end, these repeat the lottery chances every 10 minutes FOREVER (or as long as you run the machine).
Plus, as a Bitcoiner and now miner, you support the network and have a great conversation starter.
I see no reason why you shouldn't do this.
I lost a significant amount of money due to a silent, zero-interaction dev environment exploit.
No wallet connection.
No signing.
No running the app.
Just cloning a repo and opening it in VS Code.
Malicious .vscode/tasks.json hooks can execute automatically on folder open once you trust the workspace, hidden, background execution. This is actively abused by DPRK Interview groups.
I work in Web3 and thought I was careful. This one is genuinely scary and unheard of for most devs.
Please treat untrusted repos like malware. Open in restricted mode. Inspect .vscode/ before trusting anything. 🙏
5 checks for upgradeable smart contracts:
1. `_authorizeUpgrade` is added with proper access control
2. Constructor has `_disableInitializers()`
3. `initialize` has the `initializer` modifier
4. Other `initialize` functions inside the main `initialize` are marked with `onlyInitializing`
5. `DEFAULT_ADMIN_ROLE` is given to someone or role hierarchy is set up (someone can grant/revoke roles)
yETH Exploit Deep Dive
After spending some time exploring the recent yETH exploit, I quickly realized that it's easily one of the most sophisticated attacks I've ever seen. In fact, it was so complicated that every writeup I read misunderstood at least some part of the attack. This complexity provides for some serious alpha to developers and security researchers who can thoroughly understand the attack, so don't just bookmark this, let's dive in.
Hybrid AMM Curve
To understand this exploit, we first need to understand the underlying mechanism of the protocol. The yETH pool uses an invariant which is a hybrid between constant product and constant sum. If you're familiar with the inner workings of Uniswap, you should be familiar with the constant product behavior, essentially it just adjusts the price according to the reserves. Whereas constant sum results in a constant price between the tokens, regardless of reserves. The yETH hybrid curve behaves like a constant sum when the token reserves are balanced, keeping the price constant, and behaves like a constant product curve when the reserves are imbalanced. This behavior is valuable for pools of assets which have the same value due to the fact that the price is much less sensitive to reserve changes.
Below we have a graph [1] of these different curves. Red: constant product, green: constant sum, blue: hybrid used by the yETH pool.
The First Bug: Breaking The Invariant
Let's zoom in on the `_calc_supply` function. This function uses an iterative approximation to converge to a new supply and constant product term at each iteration, ending the loop once sufficient precision is achieved.
The constant product term (r) is recomputed at each iteration as the current value multiplied by the new supply, divided by the previous supply (`r * sp / s`). Effectively, it scales at the same rate as the supply.
The bug: if the decrease in supply of any given iteration of the solver is large enough, the constant product term can round down to zero. There is no revert to handle this case and once it occurs, each following iteration will remain zero since `0 * x / y = 0`.
Now that we have a zero constant product term, we no longer have a hybrid constant product/constant sum curve, instead we effectively just have a constant sum curve. To understand why this is a problem we have to go back and look at the curves. In the below graph [2], we have the intended curve (red) and the constant sum curve (purple) which is the result of the zero product term.
As we adjust the supply (see desmos graph [2] linked in reply) of these two curves (D), we can see that the reserves increase by the same amount in the middle, where the reserves are balanced, but by different amounts on the outside, where the reserves are imbalanced. This means that as we add/remove liquidity with imbalanced reserves, these two curves will mint/burn a different amount of LP tokens.
Understanding this behavior, the attacker systemically switched between these curves by triggering the zero constant product term when adding liquidity with unbalanced reserves to receive more LP tokens than intended. They then resolved the constant product term back to normal during liquidity removal to receive the correct amount of tokens provided for burning the inflated amount of LP tokens they received. This allowed the attacker to withdraw more tokens than they deposited, which they repeated until the pool was drained of its reserves for a profit of about ~$8m.
The Second Bug: Unexpected Underflow
You thought we were done? Nope, there's yet another bug that the attacker exploited to steal even more funds after already completely draining the pool.
Now that the pool is empty, and variables used for accounting are in such an unusual state, there is a significant side effect which occurs when we attempt to deposit certain dust amounts. Again, looking in the `_calc_supply` function, when we iteratively recompute the supply, we compute it with the following line (`(l - s * r) / d`):
Since we use unchecked math here and the accounting is in a highly irregular state, it's unexpectedly possible for `s * r > l`, resulting in the computed supply underflowing. The attacker exploits this underflow by depositing the following amounts: `[1, 1, 1, 1, 1, 1, 1, 9]`, resulting in them being minted `~2.6*10^56` yETH LP tokens. The attacker then makes a swap on the curve yETH/WETH pool, draining the pool of its WETH, for a profit of ~$1m.
Conclusion
Not only did this attack include a highly sophisticated AMM invariant exploit, but it also exploited an underflow which is likely only possible due to the existence of the invariant exploit. This combination of exploits allowed the attacker to not only drain the yETH pool, but also another pool containing the LP token. Both attacks, and even tornado cash deposits were all made in the same transaction, preventing any chance at rescue.
In my research, every writeup I came across misunderstood this attack in some way. Clearly, it's extremely rare to understand such a sophisticated exploit, providing for some serious alpha to developers and security researchers to fully wrap their heads around this.
If you want to explore some past exploits, this is a goldmine: @DeFiHackLabs repo with reproducible PoCs for hundreds of real-world hacks using Foundry. Perfect for learning vulnerabilities hands-on!🫡
Check it out: https://t.co/LZMHnWdgJl
On Ethereum, smart contracts can be deployed in one of 3 ways:
1. An EOA trx with no recipient `to = null` and the contract’s code in `data` (the payload).
2. A contract calls the `CREATE` opcode.
3. A contract calls the CREATE2 opcode (lets you pre-compute the address).
Get your Beannad SBT NFT
I've partnered with @Bean_DEX to give away:
- 20 free Sprout Beannad SBT WL seats
- Benefits:
$BEAN TGE Airdrop
Bean Point multiplier
incentives, revenue sharing
exclusive Bean Passport
To join:
1) Follow @byArtoCrypto@BeannadSBT
2) Like and retweet
3) Tag two friends and leave your wallet
In 12 hours, I'll determine the winners and send you your SBT wallets 😇
#Monad
1/ The best time to use HaHa Wallet was from 19th February...
The second best time is now.
HaHa Wallet is launching a token.
Introducing $HAHA - your ticket to something big on @monad.
And your Karma points matter.