Memlayer lifts BTC runes to EVM sidechain erc20 tokens directly from BTC mempool. This is a submission for the Bitcoin Games 2024 hackathon - sidechain category. Check our demo video.
Memlayer makes BTC mempool TXs, blocks, and runes data accessible by smart contracts on EVM sidechains. For example, when a user deposits BTC runes to a BTC address, Memlayer lifts this TX to Rootstack, Alys, or other EVM chains so that the user can further utilize this rune as an ERC-20 token. Memlayer is built based on the Cross-Chain Interoperability Protocol (CCIP) as CCIP-read gateways on top of a BTC mempool and block data (e.g., a BTC full node). For BTC runes with TURBO flags (set to true
) using Alys Testnet, Memlayer instantly lifts the rune amount and distributes the ERC-20 amount but with a transfer limit till L1 deposit confirmation. For BTC runes paired with Rootstock Testnet, users can see deposit balance appeared instantly in Memlayer dashboard because of the integrated CCIP-read gateway and users can claim ERC20 tokens after 1-confirmation for the BTC L1 deposit. Rootstock Testnet users can initate BTC L1 rune withdraw TXs if they want the rune balance sent back to their deposit address.
-
BTC runes unlocked a new way of using Bitcoin since the 4th-halving block 840000. We were planning to integrate runes into our web3 game prototype. However, adding utilities to BTC runes on Bitcoin L1 is hard. What if there is an easy, fast, and secure way for rune-related projects to utilize BTC runes on any EVM chains where they'd like to build further usages?
-
BTC mempool has all the real-time info for the upcoming blocks. What if EVM chains can utilize mempool to provide utilities for TXs in the mempool? How can EVM smart contracts securely access BTC mempool TXs?
-
What if there is a shared layer to serve and connect both Bitcoin and EVM chains? Cross-Chain Interoperability Protocol (CCIP) is a way to provide a signed data availability service for smart contracts. What if we combine a CCIP-read gateway with a BTC full node to utilize mempool TXs from smart contract calls?
We created an easy and fast way to lift BTC runes to any EVM chains. Here are steps to use Memlayer:
-
A user who'd like to send some of his/her BTC runes to an EVM chain.
-
S/he will pair their BTC and ETH addresses by signing in both BTC and ETH wallets.
- The user will see a list of available BTC runes and a BTC rune deposit address.
- The user sends the supported BTC runes to the BTC deposit address. As soon as this TX enters the mempool, Memlayer server picks it up and sends out ERC20 rune tokens. After few seconds, ERC20 rune tokens arrived in user's ETH wallet. However, these tokens cannot be transferred until the BTC L1 rune deposit TX is confirmed (enforced by smart contracts).
Memlayer addresses the following challenges:
-
Scalable Payment Solutions Challenge - Using BTC runes for payments, games, or royalty rewards is not easy on the BTC L1 mainnet compared to using ERC-20 on EVM chains. Solving the utility problem of runes with sidechains can fuel growth for the whole BTC ecosystem. Memlayer makes lifting BTC runes to sidechains easy so more utilities can be built using EVM smart contracts.
-
Interoperability Tools Challenge - Cross-chain interoperability is critical because there will be more sidechains. What would be the minimalist approach to have a protocol supporting multiple sidechains simultaneously? Memlayer supports smart contracts from multiple EVM sidechains for accessing BTC data with a single gateway server.
-
Smart Contract Platforms Challenge - How to use Bitcoin block data or mempool data in EVM sidechains? We combine a CCIP-read server with a BTC full node to make BTC data accessible to smart contracts. We focus on rune TXs first, but we can make more BTC data available on the CCIP-read gateway.
-
Loyalty Applications Challenge - Distributing royalties on L1 may not be ideal but settling and withdrawing on L1 is essential. BTC rune usages have been surging and can be a great royalty infrastructure on L1. We enable users to deposit and withdraw runes with EVM sidechains with a simple CCIP-read solution.
-
High-Throughput Data Oracles Challenge - We combine a BTC full node with a CCIP-read server to enable BTC block data and mempool data read-only access via smart contracts. We currently focus on rune-related transactions for ERC-20 contracts on sidechains.
-
Gaming and NFTs - Players can deposit BTC runes and receive ERC-20 as balances and credentials in EVM web3 games. In addition, BTC runes can also serve as rewards, scores, and consumables in typical EVM web3 games.
The core part is to enable BTC rune TXs directly lifted to EVM sidechains and allow smart contracts to access signed BTC TXs via the CCIP-read gateway. Memlayer consists of the following parts:
This ERC-20 rune contract MemlayerToken.sol
works with the CCIP-read gateway server to process BTC rune deposit TXs from mempool. Unconfirmed rune deposits cannot be transferred and will be reverted. This ERC-20 contract is designed for serving lifted tokens with a rune-lifting, balance-checking, and transfer-locking mechanism. ERC-20 Memlayer token contracts will be deployed to sidechains and served as ERC-20 rune tokens written in Solidity, hardhat, and javascript.
This CCIP-read gateway server (deployed on AWS) picks up mempool TXs and lifts runes to EVM chains via app.ts
. We attempted two ways to pick up BTC TXs (i.e., using btc-worker scripts on a full node and using mempool.space websocket API
on the gateway server). The gateway server signs the BTC data with the same private key that deploys the ERC-20 rune contracts for authenticity. This gateway server does not store any user or TX data.
This is the front-end one-pager website MainPage.jsx
for checking unconfirmed/confirmed balances and manually claiming/withdrawing BTC or ERC-20 runes. On this page, users pair their BTC and ETH addresses and start the rune-deposit process. They will see a list of rune info about the unconfirmed/confirmed balances. Users can also initiate withdrawal requests to burn the ERC-20 runes and the BTC worker script will send out runes to users' deposit addresses.
These serverless functions index.js
extend the gateway server by handling TXs and storing TX-related data on Firebase's real-time database. We store BTC and ETH address pairs so Memlayer can correctly send tokens to their designated addresses.
There are worker scripts directly interacting with a BTC full-node with ord 0.19.0
for picking up deposit TXs using depositWorker.js
and sending out withdraw TXs using withdrawWorker.py
. BTC worker scripts were written in javascript to decode BTC rune deposit TXs and in python to send out the rune withdraw requests.
-
We had to prioritize ease-of-use and speed for this hackathon, and then enhance the security aspect for future extensions.
-
The current Memlayer cannot be deployed using a single script (yet). Currently, it is a multi-part system (i.e., AWS CCIP-read gateway server, Firebase serverless functions, smart contracts, ord scripts and BTC full node) that needs to work nicely all together.
-
Permissionless deposit/withdraw needs to be explored. The current BTC rune depositing and withdrawing process is still too centralized.
It is magical to see BTC runes lifted to EVM chains in seconds using Memlayer. This may bring BTC liquidity to EVM sidechain apps for more consumer-level experiences.
-
Memlayer can be a great self-hosting middle layer between BTC L1 and EVM sidechains when using CCIP-read on a BTC full node. This is an interesting direction that is worthy of future investigation.
-
There are still ways we have not explored for improving the speed of the deposit on the system level.
-
The UX part of using CCIP-read gateway server to move balances among BTC and EVM chains can be explored more.
-
Have security reviews to plan paths for decentralizing more parts and refactor the code base
-
Improve the performance of the dashboard
-
Add more real-time TX indicators to better showcase the speed as part of the UX
-
Work with chain partners to integrate Memlayer for public demos
-
Make CCIP-read gateway more generic to access more BTC block data and mempool TXs
-
Extend ERC-20 runes with points and gamification
-
Explorer cross-chain hopping/swapping for locked (unconfirmed) balances
-
Explore cross-chain liquidity features since EVM rune liquidity may be too fragmented
- setup
.env
in the root folder based on.env-project
- compile and deploy EVM contracts
- setup firebase functions and hosting
- setup ccip-read server
- setup a BTC full node with ord running (guide) and run btc workers
- CCIP-read gateway sample https://github.com/smartcontractkit/
- ERC-3668 CCIP-read https://eips.ethereum.org/EIPS/eip-3668
- BTC ordinals https://docs.ordinals.com/
- BTC whitepaper https://bitcoin.org/bitcoin.pdf
- follow us at https://x.com/memlayer
- submit BTC rune and EVM chain pairing requests https://forms.gle/M7andtTA1pJ1QzxW6