
{"id":24166,"date":"2024-11-28T07:20:24","date_gmt":"2024-11-28T07:20:24","guid":{"rendered":"https:\/\/mycryptomania.com\/?p=24166"},"modified":"2024-11-28T07:20:24","modified_gmt":"2024-11-28T07:20:24","slug":"cross-chain-bridges-101-how-do-tokens-flow-between-blockchains","status":"publish","type":"post","link":"https:\/\/mycryptomania.com\/?p=24166","title":{"rendered":"Cross-Chain Bridges 101\u200a\u2014\u200aHow do tokens flow between blockchains?"},"content":{"rendered":"<h3>Cross-Chain Bridges 101\u200a\u2014\u200aHow do tokens flow between blockchains?<\/h3>\n<p><em>This article belongs to a <\/em><a href=\"https:\/\/medium.com\/@andre.aa\"><em>series<\/em><\/a><em> analyzing monitoring and security analysis of cross-chain protocols.<\/em><\/p>\n<p><strong>Access the paper<\/strong> below\ud83d\udc47\ud83d\udc47\ud83d\udc47<\/p>\n<p><a href=\"https:\/\/arxiv.org\/abs\/2410.02029\">XChainWatcher: Monitoring and Identifying Attacks in Cross-Chain Bridges<\/a><\/p>\n<p>Photo by <a href=\"https:\/\/unsplash.com\/@francisco_legarreta?utm_source=medium&amp;utm_medium=referral\">Francisco De Legarreta C.<\/a> on\u00a0<a href=\"https:\/\/unsplash.com\/?utm_source=medium&amp;utm_medium=referral\">Unsplash<\/a><\/p>\n<h3>TL;DR<\/h3>\n<p>Cross-chain bridges enable blockchains to communicate and transfer assets across different networks, addressing the fragmentation in DeFi and unlocking new use cases. <strong>This post breaks down how these bridges work, using the Ronin Bridge as an example.<\/strong> It covers the deposit and withdrawal processes, key components, and the role of Validators in relaying transactions. Understanding the mechanics behind cross-chain bridges is crucial for enhancing blockchain interoperability and building more connected decentralized applications (dApps).<\/p>\n<h3>Why cross-chain bridges?<\/h3>\n<p>Cross-chain bridges unlock the full potential of blockchains by enabling communication between different networks, addressing liquidity fragmentation in DeFi protocols, and supporting new use cases where multiple blockchains\u2019 features are crucial for a single\u00a0dApp.<\/p>\n<p><strong>Users may choose to transfer their tokens to other blockchains for various\u00a0reasons:<\/strong><\/p>\n<p><strong>taking advantage<\/strong> of unique properties such as <strong>lower transaction fees<\/strong> or f<strong>aster processing speeds<\/strong>.<strong>seek access to other protocols<\/strong> available on alternative blockchains<strong>ensure consistency across the same protocol deployed in multiple blockchains<\/strong>, making them consistent governance-wise (i.e., decisions enforced in one blockchain are also propagated to the\u00a0other)<\/p>\n<p>Unlike most DeFi applications that operate on a single chain, these dApps facilitate interoperability across two or more blockchains. Check the article below, where I explore the key reasons why cross-chain protocols are vital for the future of blockchain technology.<\/p>\n<p><a href=\"https:\/\/medium.com\/@andre.aa\/the-importance-of-cross-chain-protocols-in-web3-2024-7e5b598a17d7\">The Importance of Cross-Chain Protocols in Web3 [2024]<\/a><\/p>\n<h3>How do they\u00a0work?<\/h3>\n<p>The figure below illustrates the components of a cross-chain bridge, showing a source chain (S in blue) and a target chain (T in green) with a one-way flow for token deposits. A deposit represents the transfer of tokens from a source blockchain (S) to a target blockchain (T). On the contrary, transferring tokens from the target blockchain (T) back to the source blockchain (S) is called a Withdrawal. In this figure, we abstract the architecture of the <em>\u201cValidators\u201d\u200a\u2014\u200a<\/em>an off-chain component that relays data between networks (<a href=\"https:\/\/medium.com\/@andre.aa\/on-the-security-of-cross-chain-protocols-0f5da1632da5\">check our previous article discussing different architectures and their security guarantees<\/a>).<\/p>\n<p>The flow of data through the components of a cross-chain bridge for the deposit of\u00a0tokens<\/p>\n<p>The cross-chain process begins with the <em>sender<\/em> issuing a Deposit transaction on S (1), where user funds are escrowed. The escrow is enforced by transferring tokens to a bridge contract (2). This triggers the emission of events by the respective token contract (3) and the bridge contract (4). Then, the <em>Validators<\/em> issue the corresponding Deposit transaction on T (5). Depending on the inner mechanics of the bridge, the contract validates a set of signatures by validators (e.g., a multi-signature), or a cryptographic proof (e.g., a Merkle or Zero-Knowledge proof) in (6). If valid, this transaction triggers the unlocking or minting of tokens in T (7), generating events in each contract (8) and (9). The <em>beneficiary<\/em> can then use these funds in the destination blockchain.<\/p>\n<p>GIF\u200a\u2014\u200aA token bridge employing a lock-mint paradigm (the original tokens are kept locked in the source chain and the equivalent amount is minted in the destination). Note that the number of entities was simplified for demonstration purposes.<\/p>\n<p>The process for withdrawing tokens is similar, though with some additional caveats. Usually, validators fetch the events from the target blockchain and generate signatures, but the users are the ones who issue the transaction to S to withdraw the tokens as a way to avoid increasing the operational cost of the protocol. This process is usually managed using the UI of each bridge. Below, there is the flow for the withdrawal of\u00a0tokens.<\/p>\n<p>The flow of data through the components of a cross-chain bridge for the withdrawal of\u00a0tokens<\/p>\n<p><em>[Note that there may be slight changes in the processes involving the validators (step 5 in both images) depending on the validator architecture and proving systems. Also, the emission of events in a Token Contract may not happen when dealing with native tokens (e.g., ETH in Ethereum)].<\/em><\/p>\n<h3>Let\u2019s look at a real example (Ronin\u00a0Bridge)<\/h3>\n<p>To analyze transactions of cross-chain bridges, we need to analyze transactions on multiple blockchains. <strong>Let me give you an example based on older data from the Ronin Bridge<\/strong>. The Ronin Bridge connects Ethereum (S) and the Ronin blockchain (T). To analyze an example of a cross-chain transaction, we will leverage the block explorers of both blockchains to decode the information.<\/p>\n<h4>Deposit of\u00a0Tokens<\/h4>\n<p>The <em>sender <\/em>issues a first <a href=\"https:\/\/etherscan.io\/tx\/0x2561e6a5dcddb4a721172603588de5811c4c93100481487d3d81fdaece4a638d\">deposit transaction<\/a> to the bridge contract in Ethereum. Let\u2019s take a look at the decoded input data for that transaction:<\/p>\n<p>Function: depositERC20For(address _user, address _token, uint256 _amount)<\/p>\n<p>Arguments:<br \/>_user 0xd1a6f4c55C50d8d775D1007A1EcD2C263d7570A31<br \/>_token 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB482 (USDC)<br \/>_amount 5000000000 (5000 USDC because the USDC token uses six decimal places)<\/p>\n<p>So, the above transaction was issued by the user (<em>sender)<\/em> to the Ronin Bridge Contract, calling the <em>depositERC20For<\/em> function. The data used in the function call instructs the bridge to transfer 5000 USDC to the Ronin blockchain. We can see that the transaction was successful. Let\u2019s also look at the <a href=\"https:\/\/etherscan.io\/tx\/0x2561e6a5dcddb4a721172603588de5811c4c93100481487d3d81fdaece4a638d#eventlog\">execution logs<\/a>. We see that the first event was emitted by the token contract (<a href=\"https:\/\/etherscan.io\/address\/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48\">0xa0b869<\/a>9\u2026\u200a\u2014\u200aUSDC), transferring the 5000 tokens to the bridge contract (<a href=\"https:\/\/etherscan.io\/address\/0x1a2a1c938ce3ec39b6d47113c7955baa9dd454f2\">0x1a2a1c<\/a>\u2026). Finally, there is a <em>TokenDeposited<\/em> event emitted by the bridge contract with the following data:<\/p>\n<p>_depositId:        1985750<br \/>_owner:            0xd1a6f4c55C50d8d775D1007A1EcD2C263d7570A3 (beneficiary)<br \/>_tokenAddress:     0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 (USDC)<br \/>_sidechainAddress: 0x0B7007c13325C48911F73A2daD5FA5dCBf808aDc (USDC in the Ronin blockchain)<br \/>_standard:         20 (ERC20)<br \/>_tokenNumber:      5000000000 (5000)<\/p>\n<p>From this moment onwards, the tokens have been transferred to the bridge contract on the source chain, and the off-chain entities are responsible for relaying information to the target chain. Around 3 minutes later, there is a <a href=\"https:\/\/app.roninchain.com\/tx\/0x8e49b9c186efa51186e34c870c1746206312086242879029984a9b6208b87577\">transaction issued<\/a> in the Ronin blockchain by a <em>Validator<\/em> depositing tokens to the beneficiary address with the following input\u00a0data:<\/p>\n<p>Function: batchDepositERCTokenFor(uint256[],address[],address[],uint32[],uint256[])<\/p>\n<p>Arguments:<br \/>_depositIds:   1985750<br \/>_owners:       0xd1a6f4c55C50d8d775D1007A1EcD2C263d7570A3 (beneficiary)<br \/>_tokens:       0x0B7007c13325C48911F73A2daD5FA5dCBf808aDc (USDC)<br \/>_standards:    20 (ERC20)<br \/>_tokenNumbers: 5000000000 (5000)<\/p>\n<p>We can then again look at the <a href=\"https:\/\/app.roninchain.com\/tx\/0x8e49b9c186efa51186e34c870c1746206312086242879029984a9b6208b87577?t=logs\">execution logs<\/a> and check the events emitted by each contract. Again, we have an event emitted by the USDC token contract transferring tokens from the bridge contract (0xe35d62) to the <em>beneficiary,<\/em> followed by an event emitted by the bridge contract. You may also check that the deposit IDs of the transactions on both chains\u00a0match.<\/p>\n<h4>Withdrawal of\u00a0Tokens<\/h4>\n<p>The withdrawal of tokens follows roughly the same scheme but in the opposite direction. Consider a <a href=\"https:\/\/app.roninchain.com\/tx\/0x9c84c43dcc00e3d72cdd59e67249d89a895e00a255f3fea818c142e7d870e09f\">transaction<\/a> in the Ronin blockchain with the following input\u00a0data:<\/p>\n<p>Function: withdrawERC20For(address,address,uint256)<\/p>\n<p>Arguments:<br \/>_owner:  0x1391C4C4e845d0E5aE0f80d7072389B4D1d8B064 (beneficiary)<br \/>_token:  0x97a9107C1793BC407d6F527b77e7fff4D812bece (AXS in Ronin)<br \/>_amount: 113138226530558651754 (113.13 AXS &#8212; the AXS token uses sixteen decimal places)<\/p>\n<p>This transaction, issued by the <em>sender,<\/em> instructs the bridge to withdraw 113 AXS to the <em>beneficiary<\/em> in Ethereum. The off-chain <em>Validators <\/em>listen<em> <\/em>to the events emitted by the bridge contracts and generate digital signatures. A couple of minutes later, the user issues a <a href=\"https:\/\/etherscan.io\/tx\/0xdbc7319a9973f418f41ddbdc00111933fc751c1d836c1d99c84ddd4d1c374610\">transaction<\/a> on Ethereum to complete the withdrawal process. Based on the same logic for deposits, check the <a href=\"https:\/\/etherscan.io\/tx\/0xdbc7319a9973f418f41ddbdc00111933fc751c1d836c1d99c84ddd4d1c374610#eventlog\">execution logs<\/a> and match the information on both chains. Note that the input data below for this transaction contains the signatures collected from <em>Validators<\/em> according to the security mechanism used by the bridge. The set of signatures is verified within the bridge smart contract.<\/p>\n<p>Function: withdrawERC20For(uint256 _withdrawalId, address _user, address _token, uint256 _amount, bytes _signatures)<\/p>\n<p>_withdrawalId 1056606<br \/>_user         0x1391C4C4e845d0E5aE0f80d7072389B4D1d8B064 (beneficiary)<br \/>_token        0xBB0E17EF65F82Ab018d8EDd776e8DD940327B28b (AXS in Ethereum)<br \/>_amount       113138226530558651754<br \/>_signatures   0x01c775e08ec07cdfe7151724ae9894080b369276&#8230;&#8230;<\/p>\n<h3>What\u2019s Next?<\/h3>\n<p>Now that you\u2019ve grasped the foundational concepts of cross-chain bridges and how transactions are mapped across different blockchains, there\u2019s much more to explore. <strong>In the upcoming post<\/strong>, we\u2019ll dive deeper into the performance of cross-chain bridges and security vulnerabilities that have affected them in the past. Stay tuned for some fascinating insights!<\/p>\n<p><em>A special thanks to <\/em><a href=\"https:\/\/rafaelbelchior.medium.com\/\"><em>Rafael Belchior<\/em><\/a><em> for reviewing and making suggestions that improved this\u00a0post.<\/em><\/p>\n<p><strong><em>Additional relevant resources:<\/em><\/strong><\/p>\n<p><a href=\"https:\/\/medium.com\/@andre.aa\/what-have-we-learned-after-3-2-billion-usd-was-stolen-from-cross-chain-bridges-90b5e385f70e\">What have we learned after 3.2 billion USD was stolen from cross-chain bridges?<\/a><a href=\"https:\/\/medium.com\/@andre.aa\/exploring-open-challenges-and-future-research-avenues-in-cross-chain-2024-31a171013121\">Exploring Open Challenges and Future Research Avenues in Cross-Chain [2024]<\/a><a href=\"https:\/\/medium.com\/media\/458abc358a707ec2e292e941416a5029\/href\">https:\/\/medium.com\/media\/458abc358a707ec2e292e941416a5029\/href<\/a><\/p>\n<p><a href=\"https:\/\/medium.com\/coinmonks\/cross-chain-bridges-101-how-do-tokens-flow-between-blockchains-fd3615a879fb\">Cross-Chain Bridges 101\u200a\u2014\u200aHow do tokens flow between blockchains?<\/a> was originally published in <a href=\"https:\/\/medium.com\/coinmonks\">Coinmonks<\/a> on Medium, where people are continuing the conversation by highlighting and responding to this story.<\/p>","protected":false},"excerpt":{"rendered":"<p>Cross-Chain Bridges 101\u200a\u2014\u200aHow do tokens flow between blockchains? This article belongs to a series analyzing monitoring and security analysis of cross-chain protocols. Access the paper below\ud83d\udc47\ud83d\udc47\ud83d\udc47 XChainWatcher: Monitoring and Identifying Attacks in Cross-Chain Bridges Photo by Francisco De Legarreta C. on\u00a0Unsplash TL;DR Cross-chain bridges enable blockchains to communicate and transfer assets across different networks, addressing [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-24166","post","type-post","status-publish","format-standard","hentry","category-interesting"],"_links":{"self":[{"href":"https:\/\/mycryptomania.com\/index.php?rest_route=\/wp\/v2\/posts\/24166"}],"collection":[{"href":"https:\/\/mycryptomania.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mycryptomania.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/mycryptomania.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=24166"}],"version-history":[{"count":0,"href":"https:\/\/mycryptomania.com\/index.php?rest_route=\/wp\/v2\/posts\/24166\/revisions"}],"wp:attachment":[{"href":"https:\/\/mycryptomania.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=24166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mycryptomania.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=24166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mycryptomania.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=24166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}