<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Heuss on Medium]]></title>
        <description><![CDATA[Stories by Heuss on Medium]]></description>
        <link>https://medium.com/@Heuss?source=rss-6e94977858c7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Fq71eT4kLS99wLhDaUozmg.jpeg</url>
            <title>Stories by Heuss on Medium</title>
            <link>https://medium.com/@Heuss?source=rss-6e94977858c7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 12:48:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Heuss/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[LayerZero’s Cross-Chain Messaging Vulnerability]]></title>
            <link>https://medium.com/@Heuss/layerzeros-cross-chain-messaging-vulnerability-e5ef48c5ccec?source=rss-6e94977858c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5ef48c5ccec</guid>
            <category><![CDATA[smart-contract-security]]></category>
            <category><![CDATA[bug-hunting]]></category>
            <category><![CDATA[smart-contract-auditing]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[smart-contract-blockchain]]></category>
            <dc:creator><![CDATA[Heuss]]></dc:creator>
            <pubDate>Thu, 09 Nov 2023 18:19:07 GMT</pubDate>
            <atom:updated>2023-11-09T18:19:07.181Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>LayerZero is a revolutionary protocol for cross-chain communication who also offers the world’s largest bounty for a critical, a maximum of 15 000 000$ and i recently found a critical vulnerability in it… or i thought so. When i first reported it, it was indeed a critical since i found a way to definitively brick the messaging process for almost all application using LayerZero, but the team had a way to manually force any stuck message to go trough ( you will understand later why it matters), making the brick only temporary, vulnerability was then rightly lowered to a medium.</p><p>The vulnerability has been introduced with a fix for a previous bug found by a whitehat colleague and you should first read about it :</p><p><a href="https://medium.com/@blockian/blackboxing-layerzero-labs-off-chain-relayer-954aecab0f62">https://medium.com/@blockian/blackboxing-layerzero-labs-off-chain-relayer-954aecab0f62</a></p><p>I will try to give a brief description of his finding first but i still recommend reading his article.</p><h3>Part I: The First Vulnerability</h3><p>The vulnerability found by Blockian is the fact that User Applications (UAs, more information <a href="https://layerzero.gitbook.io/docs/faq/glossary">here</a>) can manipulate Oracle and Relayer fees, allowing them to send messages without incurring any costs. This vulnerability centers around the fee calculation process in the send function of the default LayerZero node, UltraLightNodeV2.sol.</p><p>The Vulnerability :</p><p>Within the LayerZero UltraLightNodeV2.sol contract, the send function is responsible for fetching fees for message transmission and ensuring that UAs have attached adequate tokens to cover these fees :</p><pre> function send(address _ua, uint64, uint16 _dstChainId, bytes calldata _path, bytes calldata _payload, address payable _refundAddress, address _zroPaymentAddress, bytes calldata _adapterParams) external payable override onlyEndpoint {<br>        address ua = _ua;<br>        uint16 dstChainId = _dstChainId;<br>        require(ulnLookup[dstChainId] != bytes32(0), &quot;LayerZero: dstChainId does not exist&quot;);<br><br>        bytes memory dstAddress;<br>        uint64 nonce;<br>        // code block for solving &#39;Stack Too Deep&#39;<br>        {<br>            uint chainAddressSize = chainAddressSizeMap[dstChainId];<br>            // path = remoteAddress + localAddress<br>            require(chainAddressSize != 0 &amp;&amp; _path.length == 20 + chainAddressSize, &quot;LayerZero: incorrect remote address size&quot;);<br>            address srcInPath;<br>            bytes memory path = _path; // copy to memory<br>            assembly {<br>                srcInPath := mload(add(add(path, 20), chainAddressSize)) // chainAddressSize + 20<br>            }<br>            require(ua == srcInPath, &quot;LayerZero: wrong path data&quot;);<br>            dstAddress = _path[0:chainAddressSize];<br>            nonce = nonceContract.increment(dstChainId, ua, path);<br>        }<br><br>        bytes memory payload = _payload;<br>        ApplicationConfiguration memory uaConfig = _getAppConfig(dstChainId, ua);<br><br>        // compute all the fees<br>        uint relayerFee = _handleRelayer(dstChainId, uaConfig, ua, payload.length, _adapterParams);<br>        uint oracleFee = _handleOracle(dstChainId, uaConfig, ua);<br>        uint nativeProtocolFee = _handleProtocolFee(relayerFee, oracleFee, ua, _zroPaymentAddress);<br><br>        // total native fee, does not include ZRO protocol fee<br>        uint totalNativeFee = relayerFee.add(oracleFee).add(nativeProtocolFee);<br><br>        // assert the user has attached enough native token for this address<br>        require(totalNativeFee &lt;= msg.value, &quot;LayerZero: not enough native for fees&quot;);<br>        // refund if they send too much<br>        uint amount = msg.value.sub(totalNativeFee);<br>        if (amount &gt; 0) {<br>            (bool success, ) = _refundAddress.call{value: amount}(&quot;&quot;);<br>            require(success, &quot;LayerZero: failed to refund&quot;);<br>        }<br><br>        // emit the data packet<br>        bytes memory encodedPayload = abi.encodePacked(nonce, localChainId, ua, dstChainId, dstAddress, payload);<br>        emit Packet(encodedPayload);<br>    }</pre><p>Fee Calculation: The send function fetch three types of fees: the Relayer fee, the Oracle fee, and the native protocol fee. These fees are pivotal for the proper operation of the LayerZero network and are directly calculated inside the Relayer and Oracle contract implementation.</p><p>UA Control: The vulnerability arises because UAs can customize their Oracle and Relayer configurations and still get relayed by the default relayer/oracle of LayerZero. This customization extends to setting their fees to zero. In essence, UAs can change their default LayerZero Oracle and Relayer to custom,malicious versions that don’t charge any fees andthen comeback to the default relayer/oracle</p><p>Insufficient Event Data: The issue intensifies because the Packet event emitted by the send function lacks essential information about the Relayer used. This omission is significant as it leaves no way to track or verify the Relayer being utilized for a specific message.</p><p>Exploiting the Vulnerability</p><p>Here’s how UAs can exploit this vulnerability:</p><p>Customization: UAs can configure their Oracle and Relayer to custom, malicious versions that return zero fees. These configurations are designed to bypass the fee calculation process entirely.</p><p>Message Sending: The UA initiates the message sending process while their Oracle and Relayer configurations are set to the custom, fee-less versions. Consequently, the fee calculation for the message yields zero fees.</p><p>Reverting to Default: After sending the message, the UA can promptly revert their Oracle and Relayer configurations back to the default LayerZero settings, all within the same transaction.</p><p>The consequence of this manipulation is that UAs manage to send messages without incurring any fees. The LayerZero network is effectively tricked into processing messages for free, courtesy of the custom, malicious Oracle and Relayer configurations.</p><h3>Part II: The Unintended Consequence</h3><p>The second vulnerability arises from an attempt to address the initial issue. In the process, a modification was made to the LayerZero protocol. This alteration introduced a critical flaw in the network’s architecture.</p><p>What was the Fix :</p><p>When setConfig, the function used to change the oracle/relayer of a UA, is called in the same transaction a message is sent, the relayer should refrain from relaying the message,the relayer check this by listening to emitted event during the transaction. This adjustment seemed like a reasonable security enhancement.</p><pre>function setConfig(uint16 _remoteChainId, address _ua, uint _configType, bytes calldata _config) external override onlyEndpoint {<br>        ApplicationConfiguration storage uaConfig = appConfig[_ua][_remoteChainId];<br>        if (_configType == CONFIG_TYPE_INBOUND_PROOF_LIBRARY_VERSION) {<br>            uint16 inboundProofLibraryVersion = abi.decode(_config, (uint16));<br>            require(inboundProofLibraryVersion &lt;= maxInboundProofLibrary[_remoteChainId], &quot;LayerZero: invalid inbound proof library version&quot;);<br>            uaConfig.inboundProofLibraryVersion = inboundProofLibraryVersion;<br>        } else if (_configType == CONFIG_TYPE_INBOUND_BLOCK_CONFIRMATIONS) {<br>            uint64 blockConfirmations = abi.decode(_config, (uint64));<br>            uaConfig.inboundBlockConfirmations = blockConfirmations;<br>        } else if (_configType == CONFIG_TYPE_RELAYER) {<br>            address relayer = abi.decode(_config, (address));<br>            uaConfig.relayer = relayer;<br>        } else if (_configType == CONFIG_TYPE_OUTBOUND_PROOF_TYPE) {<br>            uint16 outboundProofType = abi.decode(_config, (uint16));<br>            require(supportedOutboundProof[_remoteChainId][outboundProofType] || outboundProofType == 0, &quot;LayerZero: invalid outbound proof type&quot;);<br>            uaConfig.outboundProofType = outboundProofType;<br>        } else if (_configType == CONFIG_TYPE_OUTBOUND_BLOCK_CONFIRMATIONS) {<br>            uint64 blockConfirmations = abi.decode(_config, (uint64));<br>            uaConfig.outboundBlockConfirmations = blockConfirmations;<br>        } else if (_configType == CONFIG_TYPE_ORACLE) {<br>            address oracle = abi.decode(_config, (address));<br>            uaConfig.oracle = oracle;<br>        } else {<br>            revert(&quot;LayerZero: Invalid config type&quot;);<br>        }<br>        // the setConfig event the relayer will listen to<br>        emit AppConfigUpdated(_ua, _configType, _config);<br>    }</pre><p>Note that The setConfig function will only change the configuration of the calling msg.sender, wich mean only an UA can change his configuration, the relayer check this by listening to emitted event. The setConfig function can only be called trough the Endpoint.sol contract that will enforce _ua == msg.sender.</p><pre>function setConfig(uint16 _version, uint16 _chainId, uint _configType, bytes calldata _config) external override validVersion(_version) {<br>        if (_version == DEFAULT_VERSION) {<br>            require(defaultSendVersion == defaultReceiveVersion, &quot;LayerZero: can not set Config during DEFAULT migration&quot;);<br>            _version = defaultSendVersion;<br>        }<br>        require(_version != BLOCK_VERSION, &quot;LayerZero: can not set config for BLOCK_VERSION&quot;);<br>        libraryLookup[_version].setConfig(_chainId, msg.sender, _configType, _config);<br>    }</pre><p>The Vulnerability:</p><p>Unfortunately, the code adjustment did not account for a critical factor. It failed to check whether the UA changing its configuration is the same UA sending a message. Consequently, a vulnerability emerges where an attacker can send a message through a legitimate UA, such as the Stargate bridge from LayerZero, and simultaneously call the setConfig function from a malicious UA within the same transaction, the relayer will notice a setConfig event in the transaction without checking if it was from a different UA, and wont relay the message. The legitimate message sent via the authentic UA is indeed,sent but is never relayed.</p><p>Why it is a problem :</p><p>The consequences of this oversight are severe. In LayerZero, the outbound nonce is incremented each time a message is sent, and the inbound nonce increases every time a message is received. There is a strict requirement that enforces the integrity of this nonce path when receiving a message. This requirement is crucial to maintain the network’s reliability.</p><pre>function receivePayload(uint16 _srcChainId, bytes calldata _srcAddress, address _dstAddress, uint64 _nonce, uint _gasLimit, bytes calldata _payload) external override receiveNonReentrant {<br>        // assert and increment the nonce. no message shuffling strict requirement<br>        require(_nonce == ++inboundNonce[_srcChainId][_srcAddress], &quot;LayerZero: wrong nonce&quot;);<br><br>        LibraryConfig storage uaConfig = uaConfigLookup[_dstAddress];<br><br>        // authentication to prevent cross-version message validation<br>        // protects against a malicious library from passing arbitrary data<br>        if (uaConfig.receiveVersion == DEFAULT_VERSION) {<br>            require(defaultReceiveLibraryAddress == msg.sender, &quot;LayerZero: invalid default library&quot;);<br>        } else {<br>            require(uaConfig.receiveLibraryAddress == msg.sender, &quot;LayerZero: invalid library&quot;);<br>        }<br><br>        // block if any message blocking<br>        StoredPayload storage sp = storedPayload[_srcChainId][_srcAddress];<br>        require(sp.payloadHash == bytes32(0), &quot;LayerZero: in message blocking&quot;);<br><br>        try ILayerZeroReceiver(_dstAddress).lzReceive{gas: _gasLimit}(_srcChainId, _srcAddress, _nonce, _payload) {<br>            // success, do nothing, end of the message delivery<br>        } catch (bytes memory reason) {<br>            // revert nonce if any uncaught errors/exceptions if the ua chooses the blocking mode<br>            storedPayload[_srcChainId][_srcAddress] = StoredPayload(uint64(_payload.length), _dstAddress, keccak256(_payload));<br>            emit PayloadStored(_srcChainId, _srcAddress, _dstAddress, _nonce, _payload, reason);<br>        }<br>    }</pre><p>If a message is sent but never relayed, the outbound nonce(_nonce in the code here) is increased while the inbound nonce remains stagnant, effectively breaking the nonce path and if the nonce path is broken no more message can go trough LayerZero. For exemple, the Stargate bridge would be unable to send any further messages.</p><h3>Conclusion</h3><p>The Layer Zero team quickly fixed the bug by making the relayer check which UA called setConfig in the transaction before blocking the message, and if the UA is different then the message is relayed. As i explained at the beginning, the LayerZero team can manually force the stuck message that wasnt relayed to go trough, fixing the broken nonce path and lowering the severity from a critical to a medium ( rightly).</p><p>I hope this writeup isn’t too mediocre, it’s a bit complicated to explain this bug because it’s protocol-specific and requires an understanding of how LayerZero works, so if you’re having trouble understanding this article, I can only recommend that you take a look at the code and who knows, maybe you’ll find THE critical worth 15 million. After reporting my finding, I was sure it was a critical and I went to sleep with the idea in my head that I would wake up a millionaire the next day,and still i didnt sleep well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5ef48c5ccec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unprotected Swap() Function: A ERC777 Reentrancy Vulnerability]]></title>
            <link>https://medium.com/@Heuss/unprotected-swap-function-a-erc777-reentrancy-vulnerability-81aaeaa75a2a?source=rss-6e94977858c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/81aaeaa75a2a</guid>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[smart-contract-auditing]]></category>
            <category><![CDATA[smart-contract-security]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <dc:creator><![CDATA[Heuss]]></dc:creator>
            <pubDate>Wed, 09 Aug 2023 14:22:54 GMT</pubDate>
            <atom:updated>2023-08-09T14:22:54.120Z</atom:updated>
            <content:encoded><![CDATA[<p>This article sheds light on a critical vulnerability associated with the swap() function in a bridge/DEX. This vulnerability exposes a potential reentrancy attack vector that could lead to unauthorized balance inflation. This is actually my very first finding when i started bug hunting, 1 year ago.</p><p><strong>The Vulnerability</strong></p><p>The vulnerability allows an attacker to re-enter this swap() function, leveraging the ERC777 token&#39;s callback mechanism before the balances are updated in the transferFrom() function. By exploiting this callback, the attacker could artificially inflate their balance and manipulate the outcome of the swap. Consequently, the attacker could swap tokens for a larger amount than they initially provided, leading to financial gains at the expense of the protocol and other users, <strong>I would like to point out that this bug is only true for </strong><a href="https://docs.openzeppelin.com/contracts/3.x/erc777"><strong>ERC777</strong></a><strong> tokens.</strong></p><pre> function swap(uint8 tokenIndexFrom, uint8 tokenIndexTo, uint256 dx, uint256 minDy, uint256 deadline) external ensure(deadline) returns (uint256) {<br>        require(dx &lt;= coins[tokenIndexFrom].balanceOf(msg.sender), &quot;O3SwapPool: INSUFFICIENT_BALANCE&quot;);<br><br>        uint256 balanceBefore = coins[tokenIndexFrom].balanceOf(address(this));<br>        coins[tokenIndexFrom].safeTransferFrom(msg.sender, address(this), dx);<br>        uint256 transferredDx = coins[tokenIndexFrom].balanceOf(address(this)) - balanceBefore;<br><br>        (uint256 dy, uint256 dyFee) = _calculateSwap(tokenIndexFrom, tokenIndexTo, transferredDx);<br>        require(dy &gt;= minDy, &quot;O3SwapPool: INSUFFICIENT_OUTPUT_AMOUNT&quot;);<br><br>        uint256 dyAdminFee = dyFee * adminFee / FEE_DENOMINATOR / tokenPrecisionMultipliers[tokenIndexTo];<br><br>        balances[tokenIndexFrom] += transferredDx;<br>        balances[tokenIndexTo] -= dy + dyAdminFee;<br><br>        coins[tokenIndexTo].safeTransfer(msg.sender, dy);<br><br>        emit TokenSwap(msg.sender, transferredDx, dy, tokenIndexFrom, tokenIndexTo);<br><br>        return dy;<br>    }</pre><p><strong>Risk Breakdown</strong></p><ol><li>The attacker initiates a swap with the minimum amount (dx).</li><li>Before the safetransferfrom() function is executed, the attacker&#39;s code exploits the _callTokensToSend() hook in the ERC777 token.</li><li>This re-entrancy allows the attacker to re-enter the swap() function, this time with a larger dx value.</li><li>The transaction concludes the second swap, inflating the ending balance.</li><li>The attacker successfully swaps a larger amount of tokens while only using the minimal amount authorized in the first transaction.</li></ol><p>To understand this vulnerability conceptually, consider this quick scenario :</p><ol><li>Initiate swap with dx = 1.</li><li>Re-enter swap with dx = 1000 using tokensToSend( an ERC777 ) hook.</li><li>Complete second swap, inflating the ending balance.</li><li>Successfully swap a larger amount of tokens in the first swap, while using minimal amount authorized initially.</li></ol><p>To mitigate this vulnerability, it is essential to add a reentrancy guard to the swap() function. By including proper checks and locks to prevent multiple re-entrances within a single transaction, it is also advisable to follow good practice and check that the final balance corresponds to the expected balance.</p><p>This bug is way more classic than the previous ones and the chances of finding a bug of this kind in a project listed on immunefi are now rather low. But this is still something to keep in mind while auditing contracts, if the project accepts all tokens, check how the functions react to the different types of existing tokens .Here is a short list of tokens with “weird” behavior :</p><p><a href="https://github.com/d-xo/weird-erc20#revert-on-zero-value-transfers">https://github.com/d-xo/weird-erc20#revert-on-zero-value-transfers</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81aaeaa75a2a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Critical NFT Bridge Vulnerability : Potential Theft of Deposited NFTs]]></title>
            <link>https://medium.com/@Heuss/critical-nft-bridge-vulnerability-potential-theft-of-deposited-nfts-f5b26a7776eb?source=rss-6e94977858c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5b26a7776eb</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[smart-contract-security]]></category>
            <category><![CDATA[immunefi]]></category>
            <category><![CDATA[blockchain-security]]></category>
            <category><![CDATA[smart-contract-auditing]]></category>
            <dc:creator><![CDATA[Heuss]]></dc:creator>
            <pubDate>Thu, 27 Jul 2023 12:49:19 GMT</pubDate>
            <atom:updated>2023-07-27T12:49:19.295Z</atom:updated>
            <content:encoded><![CDATA[<h3>Critical NFT Bridge Vulnerability : Potential Theft of Deposited NFTs</h3><p>Already back with my second post, this vulnerability will be easier to explain (and also was easier to catch as I reported it the same day the project got listed on Immunefi). Again, I will try to keep it as short as possible and only talk about what’s needed to understand the bug.</p><p>This time I will present you with a critical vulnerability in an NFT bridge contract between Layer 1 (L1) and Layer 2 (L2) using optimistic rollup. The vulnerability allows attackers to exploit the bridge’s withdrawal process and steal any deposited NFT within the L1ERC721Bridge contract.</p><p>Vulnerability Description:</p><p>The vulnerability arises from inadequate verification in both L1ERC721Bridge.sol and L2ERC721Bridge.sol contracts. In L1ERC721Bridge.sol, the function finalizeERC721Withdrawal does not verify if the _l1Token corresponds to the _l2Token when finalizing a withdrawal from L2. The transfer happens with no check whatsoever (beside the function being called by an authorized address).</p><pre>function finalizeERC721Withdrawal(<br>        address _l1Token,<br>        address _l2Token,<br>        address _from,<br>        address _to,<br>        uint256 _tokenId,<br>        bytes calldata _data<br>    ) external onlyFromCrossDomainAccount(l2ERC721Bridge) {<br>        // When a withdrawal is finalized on L1, the L1 Bridge transfers the funds to the withdrawer<br>        // slither-disable-next-line reentrancy-events<br>        IERC721(_l1Token).transferFrom(address(this), _to, _tokenId);<br><br>        // slither-disable-next-line reentrancy-events<br>        emit ERC721WithdrawalFinalized(_l1Token, _l2Token, _from, _to, _tokenId, _data);<br>    }</pre><p>In L2ERC721Bridge.sol, the function _initiateWithdrawal blindly trusts the L2 token and fetches _l2Token.l1Token() without verifying if the L2 token is legitimate and really corresponds to the L1 token. This opens up an opportunity for an attacker to use a worthless L2 token and a valid _tokenId (a tokenId that will correspond to the targeted NFT in L1ERC721Bridge) to make the contract return a valid L1 token that can be withdrawn in L1ERC721Bridge.sol.</p><pre>function _initiateWithdrawal(<br>        address _l2Token,<br>        address _from,<br>        address _to,<br>        uint256 _tokenId,<br>        uint32 _l1Gas,<br>        bytes calldata _data<br>    ) internal {<br>      <br>        //here an attacker can just give a worthless l2token and a worthless _tokenId that he made.<br>        IL2StandardERC721(_l2Token).burn(msg.sender, _tokenId);<br><br>        //No check of what the _l2token is, we just blindly trust it as long as it implements the interface<br><br>        address l1Token = IL2StandardERC721(_l2Token).l1Token();<br>        bytes memory message;<br><br>        message = abi.encodeWithSelector(<br>            IL1ERC721Bridge.finalizeERC721Withdrawal.selector,<br>            l1Token,<br>            _l2Token,<br>            _from,<br>            _to,<br>            _tokenId,<br>            _data<br>        );<br><br>        // Send message up to L1 bridge<br>        // slither-disable-next-line reentrancy-events<br>        sendCrossDomainMessage(l1ERC721Bridge, _l1Gas, message);<br><br>        // slither-disable-next-line reentrancy-events<br>        emit WithdrawalInitiated(l1Token, _l2Token, msg.sender, _to, _tokenId, _data);<br>    }</pre><p>Exploitation Scenario:</p><p>An attacker can initiate the exploit by providing a worthless L2 token that they created and a valid _tokenId. They can then call the WithdrawTo() function in L2ERC721Bridge.sol that will just burn the fake token. This action triggers the finalizeERC721Withdrawal function in L1ERC721Bridge.sol, which will not perform proper validation of the L2 token. As a result, the attacker can steal any deposited NFT in the L1ERC721Bridge contract.</p><pre>function withdrawTo(<br>        address _l2Token,<br>        address _to,<br>        uint256 _tokenId,<br>        uint32 _l1Gas,<br>        bytes calldata _data<br>    ) external virtual {<br>        _initiateWithdrawal(_l2Token, msg.sender, _to, _tokenId, _l1Gas, _data);<br>    }</pre><p>Proposed Fix:</p><p>To address the vulnerability, I recommended implementing a mapping in the L1ERC721Bridge.sol contract to keep track of valid deposits. The mapping will store the count of deposits for each _l1Token and their corresponding _l2Token. When a valid deposit is made, the count for the corresponding mapping entry should be incremented. During withdrawal finalization, the count should be decremented.</p><p>In the depositERC721() function increment it :</p><pre>deposits[_l1Token][_l2Token] = deposits[_l1Token][_l2Token] + 1;</pre><p>And in the finalizeERC721Withdrawal() decrement it :</p><pre>deposits[_l1Token][_l2Token] = deposits[_l1Token][_l2Token] - 1;</pre><p>The risks associated with cross-chain bridges in the blockchain ecosystem underscore the critical importance of security measures. As bridges facilitate the transfer of assets and data between different blockchain networks, they become highly attractive targets for attackers seeking to exploit vulnerabilities and compromise user funds. The complexities involved in messaging between chains add another layer of risk, making security even more crucial.</p><p>I specialized in auditing bridges because I feel like breaking them requires more creativity than most of the other types of protocols (well, maybe not for this bug, but my previous post kinda shows what I mean), and I love the challenge it presents. So, if your project includes a cross-chain messaging logic, you can contact me on my Twitter, and I’d be glad to audit it.</p><p>My twitter : <a href="https://twitter.com/UnoHeuss">https://twitter.com/UnoHeuss</a></p><p>My previous post : <a href="https://medium.com/@Heuss/exploiting-signature-verification-vulnerabilities-in-smart-contracts-f4eb64cd3b23">https://medium.com/@Heuss/exploiting-signature-verification-vulnerabilities-in-smart-contracts-f4eb64cd3b23</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5b26a7776eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>