<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tanishk Goyal on Medium]]></title>
        <description><![CDATA[Stories by Tanishk Goyal on Medium]]></description>
        <link>https://medium.com/@0xtanishk?source=rss-573371351e54------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ov1sm5hF7mMbheRVlSw6-A.png</url>
            <title>Stories by Tanishk Goyal on Medium</title>
            <link>https://medium.com/@0xtanishk?source=rss-573371351e54------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 15:24:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@0xtanishk/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Why DeFi just won’t work]]></title>
            <link>https://0xtanishk.medium.com/why-defi-just-wont-work-1b8a6bb3e211?source=rss-573371351e54------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b8a6bb3e211</guid>
            <category><![CDATA[defi]]></category>
            <category><![CDATA[uniswap]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[amm]]></category>
            <dc:creator><![CDATA[Tanishk Goyal]]></dc:creator>
            <pubDate>Sun, 12 Jan 2025 19:54:53 GMT</pubDate>
            <atom:updated>2025-01-12T20:02:47.075Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve spent the last three years of my life building cutting-edge DeFi protocols alongside some of the top teams in the space.</p><p>My biggest learning from this experience has been — that the protocols we’re building today just won’t work in the real world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*iGmjQ2VBK6ihjjyK.jpg" /></figure><p>There are a few fundamental aspects of how people interact with their finances that have led me to this conclusion.</p><h3>1. Everyone gets Greedy</h3><p>There’s a reason why NASDAQ lists only a small fraction of the companies in the world, and it’s not about censorship. In fact, most TradFi businesses would love to sell you as many things as possible.</p><p>The real reason is that a nation’s economy depends on the efficiency of capital allocation.<br>And most retail investors simply don’t have the time, skills, or discipline to thoroughly research companies and make productive investment decisions.</p><p>In a completely open market, capital tends to flow to the companies with the best marketing, not necessarily the ones building the most valuable or productive things for society.</p><p>Unfortunately, there is an adverse selection of bad actors when you allocate capital by who does the best marketing.</p><p>A snake oil salesman, after all, will always out-sell the nerd quietly working on electric vehicles.</p><p>Giving the average person unrestricted access to every financial instrument is like handing them unlimited drugs and expecting them to use them responsibly.</p><h3>2. Everyone makes mistakes</h3><p>Completely permissionless DeFi is brutally unforgiving when it comes to mistakes.</p><p>The average user regularly loses the password to most of their accounts.</p><p>The average user regularly downloads malicious software from the internet.</p><p>The average user regularly gets scammed in all sorts of ways.</p><p>A user could irreversibly lose all of their net worth with a single mistake. For most users, this level of vulnerability makes permissionless DeFi a non-starter.</p><p>On top of that, the risks of trying out a new DeFi protocol far outweigh those of depositing money in a traditional financial institution.</p><p>Just compare the numbers: the percentage of people losing funds to DeFi hacks is significantly higher than those affected by bank fraud.</p><h3>3. Everyone cannot beat the market</h3><p>LPing in DEXes is essentially market-making.</p><p>In the long run, it’s nearly impossible to be profitable using a simple, on-chain, passive market-making strategy (like the CPMM curve), especially when that strategy is open for everyone to trade against.</p><p>The problem is that if everyone can see your strategy, they can easily develop adversarial strategies to exploit it.</p><p>This issue extends to almost any composable trading strategy you run on-chain, whether it’s using AI bots, self-rebalancing Uniswap positions, or a new DEX that claims to beat LVR on-chain.</p><p>It is a commonly known fact now that most DeFi LPs are not profitable against HODL.</p><blockquote><strong>Note</strong>: My critique of AMMs applies mainly to short-tail assets. I believe AMMs have significant utility in long-tail markets and should be seen as a 0 to 1 innovation in this space.</blockquote><h3>4. Everyone does not have Collateral</h3><p>The biggest problem that DeFi lending has is that it always needs to be overcollateralized.</p><p>This is because DeFi is permissionless and pseudonymous — so you can not put <em>0xdeadbeef</em> in jail if they don’t pay back the loan they took from you.</p><p>This means that the only utility of DeFi lending is <em>leverage</em>.</p><p>You cannot take out a loan to buy a car.</p><p>You cannot take out a loan to start a business.</p><p>You can only lend your ETH, borrow some USDC, and buy more ETH with that borrowed USDC.</p><h4>So, the one line answer to why DeFi doesn’t work?</h4><p><em>Any algorithm you run on-chain can, and will, be done better off-chain.</em></p><p>I think DeFi is starting to realize this, and it is evolving in a very similar fashion as everything else in blokchain</p><p><em>Offchain computation, onchain settlement</em></p><p>Just like with Layer 2s or Proposer-Builder Separation, DeFi protocols are shifting all the complex tasks to off-chain ( sometimes even tradFi ) entities, while keeping the settlement on-chain.</p><p>You can see this trend in the latest set of modern protocols:</p><ul><li><strong>Morpho</strong>: A Lending primitive, that allows risk handlers to create their own vaults.</li><li><strong>Uni</strong> <strong>V4</strong>: Aims to be a DEX primitive, around which people can build more complicated DEXes using Hooks. Most of this innovation will happen offchain.</li><li><strong>Cowswap: </strong>Sophisticated solvers do all the complicated routing offchain, and settle the users’ intents onchain.</li></ul><p>More about what this future of DeFi will look like in the next article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b8a6bb3e211" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to win the Searchers of Nottingham CTF]]></title>
            <link>https://0xtanishk.medium.com/how-to-win-the-searchers-of-nottingham-ctf-688b4deed6f3?source=rss-573371351e54------2</link>
            <guid isPermaLink="false">https://medium.com/p/688b4deed6f3</guid>
            <category><![CDATA[mev]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[amm]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[solidity]]></category>
            <dc:creator><![CDATA[Tanishk Goyal]]></dc:creator>
            <pubDate>Mon, 08 Jul 2024 22:31:16 GMT</pubDate>
            <atom:updated>2024-07-08T22:31:16.338Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently Dragonfly hosted a unique CTF event for MEV and AMM nerds, called “Searchers of Nottingham”. <br>The game was meant to replicate a simple builder market, where the only form of MEV is sandwiching.</p><p>The bot described below was one of the winners.</p><p>While going through the write-up, hopefully, you will be able to get some intuition on how builder auctions devolve very quickly into sophisticated value-extracting competitions, with most of the value accruing to the proposer layer.</p><h4><strong>Problem Statement</strong></h4><p>There is an N-dimensional AMM with N-1 commodity tokens, and 1 special good called “gold”. Gold is comparable to Eth in PBS markets, as it is used to bid for the rights to construct the next block.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vE_UW8TEzQb5u4bCNOZphg.png" /><figcaption>A Day in the Markets of Nottingham</figcaption></figure><p>The game is played in rounds. In each round, your submitted agent has to do 2 things —</p><ol><li>Submit an atomic bundle of swaps.</li><li>Bid for the rights to become the block builder in this round.</li></ol><p>The block builder has to abide by the following invariants —</p><ol><li>All bundles submitted by all other players should be settled.</li><li>Builders have the right to insert arbitrary swaps in the block.</li><li>All bundles must be settled atomically, i.e a builder cannot insert or remove swaps from between a bundle.</li></ol><p>These properties might remind you of the kind of guarantees you get as a searcher submitting a bundle through the Flashbots relay.</p><p>For each Market Day, the game ends when either 32 rounds are reached, or some player accumulates 64 units of some token.</p><p>To readers familiar with Ethereum PBS markets, this should already start looking like a simple MEV market, where the only source of arbitrage profits is sandwiching user swaps.</p><p>Since the AMM is the primary and only source of commodity pricing, no top-of-the-block arbitrage exists in this world.</p><h4>Fundamental Principles</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5SDuRMB52f_xVFlh51csBw.png" /><figcaption>Match Graph</figcaption></figure><p><strong><em>Gold-maxxing</em></strong></p><p>In the absence of secondary markets, it is fair to assume that all standard commodities in the game are valued equally except gold.</p><p>Gold is deflationary and useful, as it can be used to bid for block builder rights, and the winning bid is burned.</p><p>So, the first fundamental principle of the winning agent is gold-maxxing. This means that at the end of each round, the agent tries to convert all the assets it has to gold.</p><p><strong><em>Negative EV Bundles</em></strong></p><p>Any swap an agent makes in the standard mempool will be sandwiched with as many tokens as the block builder has. This means that it never makes sense to make any swap as a standard bundle. There is a small caveat here, which we will discuss in more detail in the bid pricing section.</p><p><strong><em>Bid Pricing</em></strong></p><p>Note that the competition had a lot of trial market days before the main tournament called the Grand faire. The results for each trial market day were published with nice graphics, so most agents were able to learn from each other’s strategies very easily.</p><p>Most agents realized the first 2 points very quickly and started running their own strategies accordingly. Everyone was gold-maxxing, and only a small number of agents were actually sending any swaps in a bundle.</p><p>This meant that at the very end, the only thing proprietary about your bot was the algorithm which you were using to price the bids for the block.<br>This is where an important realization made the bot listed below win the competition.</p><p>Before we discuss this realization, let’s solidify the strategy we have till now —</p><ol><li>Never send any bundles in the standard mempool.</li><li>If the agent is a block builder, then first convert all assets to gold. Then, sandwich all bundles.</li></ol><p>The standard way to price bids would be to calculate the total profits earned from sandwiching the bundles and then bid 99% of those profits.</p><p>But there is a small nuance here. Although determining the long-term price of an asset in this game is impossible for standard commodity tokens, it is always fair to assume that the price of Gold will increase over time.<br>This is because it is the theoretically optimal strategy to buy and hold gold. So, it is fair to assume that rational agents will realize this and also try to hoard as much gold as they can when it is cheap.</p><p>Therefore, the actual profit you make from building the block consists of the profits you made from sandwiching everyone + the improvement in the price you get from being able to buy gold at the beginning of the block as compared to the end of the block.</p><p>Now, it is time to take a look at some code!</p><h4>Create Bundle</h4><p>The strategy already recognizes that it is never worth sending a real bundle in the mempool, as any swap will get sandwiched with the full force of the builder’s assets.</p><p>But that doesn’t stop us from having fun and trying to get other builder’s bids to fail.</p><p>The create bundle function tries to randomly send 4 different types of salmonella bundles aimed at causing reverts in other agents&#39; codes.</p><p><strong>Salmonella Strategies</strong></p><ol><li>Revert the createBundle function</li><li>Try to sell more assets than reserves</li><li>Send a bundle with an invalid asset index</li><li>Create a bunch of meaningless swaps to bait sandwich algorithms to miscalculate block profitability</li></ol><pre>    function createBundle(<br>        uint8 builderIdx<br>    ) public virtual override returns (PlayerBundle memory bundle) {<br>        // Randomly create 4 different types of salmonella bundles<br>        if (builderIdx % 4 == 0) {<br>            // Revert, so that an empty bundle is returned to the builder<br>            require(false, &quot;I have no bundle&quot;);<br>        } else if (builderIdx % 4 == 1) {<br>            // Create a bundle with an amount greater than player reserves<br>            bundle = PlayerBundle({swaps: new SwapSell[](1)});<br>            bundle.swaps[0] = SwapSell({<br>                fromAssetIdx: GOLD_IDX,<br>                toAssetIdx: FIRST_GOOD_IDX,<br>                fromAmount: GAME.balanceOf(PLAYER_IDX, GOLD_IDX) + 1000<br>            });<br>        } else if (builderIdx % 4 == 2) {<br>            // Create a bundle with an invalid asset index<br>            bundle = PlayerBundle({swaps: new SwapSell[](1)});<br>            bundle.swaps[0] = SwapSell({<br>                fromAssetIdx: GOLD_IDX,<br>                toAssetIdx: 100,<br>                fromAmount: GAME.balanceOf(PLAYER_IDX, GOLD_IDX)<br>            });<br>        } else {<br>            // Create a bundle with a lot of meaningless swaps, to bait builders into miscalculating profits<br>            uint8 first = FIRST_GOOD_IDX;<br>            uint8 second = FIRST_GOOD_IDX + 1;<br><br>            uint256 initialFirst = GAME.balanceOf(PLAYER_IDX, first);<br>            uint256 initialSecond = GAME.balanceOf(PLAYER_IDX, second);<br><br>            bundle = PlayerBundle({swaps: new SwapSell[](12)});<br><br>            for (uint256 i; i &lt; bundle.swaps.length; i++) {<br>                bundle.swaps[i] = SwapSell({<br>                    fromAssetIdx: i % 2 == 0 ? first : second,<br>                    toAssetIdx: i % 2 == 0 ? second : first,<br>                    fromAmount: GAME.balanceOf(<br>                        PLAYER_IDX,<br>                        i % 2 == 0 ? first : second<br>                    )<br>                });<br>            }<br><br>            require(<br>                initialFirst &lt;= GAME.balanceOf(PLAYER_IDX, first) &amp;&amp;<br>                    initialSecond &lt;= GAME.balanceOf(PLAYER_IDX, second),<br>                &quot;Loss&quot;<br>            );<br>        }<br>    }</pre><h4>Build Block</h4><p>All of the juicy parts of the strategy lie inside the block-building functions.</p><p>In this section, we will only discuss high-level details. You can find the complete source code here.</p><blockquote>Readers interested in the CTF, could also find it interesting to go through the “SandwichCheap” agent, which is much more sophisticated than the one that we describe below.</blockquote><p><a href="https://github.com/legion2002/searchers-of-nottingham">GitHub - legion2002/searchers-of-nottingham</a></p><p><strong>Basic Strategy</strong></p><ul><li>Sell all assets for gold at the beginning of the block.</li><li>Calculate the net amount of assets bought for each bundle and sandwich the bundle using this asset.</li><li>After sandwiching each bundle, sell everything back for gold.</li></ul><p><strong>Simulation Framework</strong></p><p>To calculate the total profit earned from buying gold at the beginning of the block as compared to the end of the block, we need to create a framework for being able to simulate a series of swaps without actually committing to the state changes that occur from them.</p><p>We do this by running our own asset market in parallel, which loads the reserves from the actual game, but we are able to simulate buy and sell on this market without having an actual impact on the game.</p><p><strong>Win condition</strong></p><p>After completing all the sandwiches, we try to win the round by buying 64 units of the cheapest asset available.</p><p>If we are able to buy 64 units of any asset, then we bid all of the remaining gold to immediately win the game. Otherwise, we bid 99% of the profits we made in this block, and keep all our assets in gold.</p><pre>    function buildBlock(<br>        PlayerBundle[] calldata bundles<br>    ) public virtual override returns (uint256 goldBid) {<br>        uint256 bidAmount = 0;<br>        uint256 goldReceivedIfFirst = 0;<br><br>        _storeReserves(GAME.marketState());<br><br>        uint256[] memory initialPlayerReserves = new uint256[](ASSET_COUNT);<br><br>        // 1. Sell everything we have first for gold<br>        for (uint8 i; i &lt; GOODS_COUNT; ++i) {<br>            initialPlayerReserves[FIRST_GOOD_IDX + i] = GAME.balanceOf(<br>                PLAYER_IDX,<br>                FIRST_GOOD_IDX + i<br>            );<br><br>            goldReceivedIfFirst += GAME.sell(<br>                FIRST_GOOD_IDX + i,<br>                GOLD_IDX,<br>                GAME.balanceOf(PLAYER_IDX, FIRST_GOOD_IDX + i)<br>            );<br>        }<br><br>        uint256 initialGold = GAME.balanceOf(PLAYER_IDX, GOLD_IDX);<br><br>        // 2. Settle everyone else&#39;s bundles with sandwiches<br>        for (uint8 playerIdx = 0; playerIdx &lt; bundles.length; ++playerIdx) {<br>            if (playerIdx == PLAYER_IDX) {<br>                // Skip our bundle.<br>                continue;<br>            }<br>            sandwichBundleWithGold(playerIdx, bundles[playerIdx]);<br>        }<br><br>        // Check if at the end of the block we can win<br>        (uint8 assetIndexMax, uint256 assetAmount) = _getCheapestAsset();<br><br>        // 3. If enough gold to win then bid everything else, and win<br>        if (assetAmount &gt;= 64e18) {<br>            GAME.buy(GOLD_IDX, assetIndexMax, 64e18);<br>            bidAmount = GAME.balanceOf(PLAYER_IDX, GOLD_IDX);<br>        } else {<br>            uint256 totalProfit = GAME.balanceOf(PLAYER_IDX, GOLD_IDX) &gt;<br>                initialGold<br>                ? GAME.balanceOf(PLAYER_IDX, GOLD_IDX) - initialGold<br>                : 0;<br><br>            uint256 goldReceivedIfLast = 0;<br><br>            for (uint8 i; i &lt; GOODS_COUNT; ++i) {<br>                goldReceivedIfLast += _sell(<br>                    FIRST_GOOD_IDX + i,<br>                    GOLD_IDX,<br>                    initialPlayerReserves[FIRST_GOOD_IDX + i]<br>                );<br>            }<br><br>            totalProfit += goldReceivedIfFirst &gt; goldReceivedIfLast<br>                ? goldReceivedIfFirst - goldReceivedIfLast<br>                : 0;<br><br>            if (totalProfit == 0) {<br>                bidAmount = 1 * 10 ** 16;<br>            } else if (GAME.round() == 32) {<br>                GAME.sell(<br>                    GOLD_IDX,<br>                    assetIndexMax,<br>                    (GAME.balanceOf(PLAYER_IDX, GOLD_IDX) * 9) / 10<br>                );<br>                bidAmount = GAME.balanceOf(PLAYER_IDX, GOLD_IDX);<br>            } else {<br>                // Bid 99% of all the profits<br>                bidAmount = (totalProfit * 99) / 100;<br>            }<br>        }<br><br>        return bidAmount;<br>    }</pre><h4>Conclusion</h4><p>The game got very cut-throat by the end of the second season. The bots got super specialized, and the margins for victory were thin. So much so that new market dynamics needed to be introduced in the next season just to keep the game interesting.</p><p>Going through the motions taught you a lot about the psychology of builder markets. Bots started off using simple strategies like buying the cheapest asset possible, but eventually got into this race of building complex simulation frameworks and salmonella bundles to get every tiny edge they could over their competitors.</p><p>The most fascinating part of this was that by the end of the competition, all agents were bidding almost all the profit they made. A small reassurance that the builder markets on Ethereum will always accrue most of the value to the proposers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=688b4deed6f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>