Opens profile photo
Follow
Click to Follow naddison
Nick Addison
@naddison
Sydneygithub.com/naddison36Joined March 2009

Nick Addison’s Tweets

It will work against any chain with an Etherscan-like explorer. eg Goerli, Sepolia, Polygon, Arbitrum, Avalanche, BSC and Optimistic Here's an example from Polygon sol2uml -n polygon diff 0x4f59cb6db6020c5553a5c856aba0a7e477aad1ee 0x25D1e7f9B306fb6502D3748490cfCBe0CCB546E7
1
3
Show this thread
A great list of smart contract tools and techniques. And not just because sol2uml and tx2uml are on the list 🙂
Quote Tweet
I have made a list of Smart contract tools and techniques that can be utilized by both smart contract auditors and developers for secure smart contracts development and analysis. github.com/shantanhunt/Sm #tools #smartcontract #cybersecurity #web3 #blockchain #blockchainsecurity
5
Once we have a fair price we can reduce it by a slippage factor which is currently configured to be 1%. This adjusted fair price is used to calculate the minimum number of Curve Metapool LP tokens (musd3Crv) that can be received when adding 3Crv liquidity to the pool.
1
2
Show this thread
For the deposit into mStable’s vaults, we need to price the Metapool LP tokens in Curve’s 3Pool LP token (3Crv) as that’s the asset we are using in the vault. To do that we get the 3Pool virtual price and divide it by the Metapool LP token price.
Image
1
1
Show this thread
It does this by calculating the pool's invariant which is the USD value of the tokens in the pool divided by the token’s total supply. As the balance of the tokens in the pool does not affect the pool’s invariant or USD value, the virtual price is safe from sandwich attack.
Image
1
1
Show this thread
The way mStable’s Vaults get a fair Metapool LP token price is to use the virtual prices of the Curve Metapool and Curve 3Pool. The `get_virtual_price` function returns the price of the pool’s liquidity provider token in USD.
2
1
Show this thread
So the problem remains, the EIP-4626 function has no way to pass in a minimum amount. Breaking the standard to add this is not an option and using oracles is also suboptimal. We need an on-chain method.
1
2
Show this thread
This can not be used to prevent a sandwich attack though. If a prior transaction has already been run to imbalance the pool, the `calc_token_amount` function will just return the now unfair LP token amount.
1
1
Show this thread
But with the standard EIP-4626 deposit function there is no parameter defined to specify the minimum amount and therefore we can not pass in a fair amount of Metapool LP tokens that were calculated off-chain.
1
1
Show this thread
This means the amount of Metapool LP tokens received in the vulnerable add liquidity transaction is much less than what it should be. In the third transaction, the attacker returns the mUSD removed in the first transaction and pockets the gains.
1
1
Show this thread
Attackers watch the Mempool for transactions that can be exploited before they are included in a block. To exploit a transaction, they bribe block producers to include their transaction in front of and after the exploitable transaction.
1
1
Show this thread
For example, if Curve’s mUSD Metapool had 2m mUSD, 6m 3Crv and 100k of 3Crv were added, 100,068 LP tokens (musd3Crv) will be received. If the Metapool had 6m mUSD, 2m 3Crv and 100k of 3Crv were added, 100,892 LP tokens (musd3Crv) will be received.
1
1
Show this thread
As the vault is only adding one of the two pool tokens, the amount of Metapool LP tokens it receives will depend on the balance of mUSD and 3Crv in the Metapool. The more 3Crv that is in the pool the fewer LP tokens will be returned when adding just 3Crv to the Metapool.
1
1
Show this thread
A technical challenge when developing the vaults was how we set the min amount of expected liquidity provider tokens. Just setting the `min_mint_amount` to zero is not good enough as it allows any deposit transaction to be sandwich attacked.
1
1
Show this thread
For the mUSD Metapool, the amounts are a two-item array. The first is the amount of mUSD, the second is the amount of 3Crv. The 3Crv Convex vaults are only depositing 3Crv so the first item of the amount array will be zero.
Image
1
1
Show this thread
When you add liquidity to a Curve Metapool or any other pool, you specify the amount of assets you want to deposit and the minimum amount of the LP tokens you are willing to receive in return (commonly: minimum out).
1
1
Show this thread
The 3Crv is added to the Curve mUSD Metapool and the resulting LP token (musd3Crv) is then deposited into the Convex mUSD pool which invests in the Curve mUSD gauge with boosted rewards. A technical challenge in this process is how to protect against sandwich attacks.
Image
1
1
Show this thread
A consequence of the EIP-4626 standard is that the deposit and mint functions don’t provide a way to specify a minimum share or asset amounts in return - commonly used to prevent high slippage or sandwich attacks.
1
2
Show this thread
EIP-4626 provides a standard way to invest a token into an investment pool, which is commonly called a vault. When you deposit your assets, which is an ERC-20 token, you receive a share token that represents your portion of the assets in the vault.
1
1
Show this thread