Cross-Chain Bridging with Yacht x Lit Swap

Cross-Chain Bridging with Yacht x Lit Swap


Video Demonstration of Yacht Lit Swap App

Cryptographic Proof:

PKP from video on Ethereum PKP from video on Polygon

At Yacht Labs, our focus is on building decentralized products that are as easy to use and as feature rich as centralized ones. For instance, moving liquidity between different chains is still hard to do without relying on a centralized custodian. Right now the easiest way to swap assets between chains is to send your coins to a centralized exchange and take advantage of their deep liquidity on a variety of chains and tokens. Although this might be easy from a user experience perspective, it sacrifices the decentralized security and anonymity inherent in blockchain technology. You have to relinquish control of your assets with no technical guarantee that they can ever be returned, and your funds are regularly locked up while you complete long KYC verifications.

To help solve the issue of decentralized cross chain asset exchanges, we’ve been working with Lit Protocol and their decentralized key management network. It’s 2023, and transferring assets across chains should be trustless, verifiable, and instantaneous. Fortunately, Lit Protocol’s Programmable Key Pairs and Lit Actions bring us one step closer to that goal.

Lit Protocol uses threshold cryptography to generate private key shares amongst the nodes in its network, with each node having no knowledge of the others’ data. These private keys function just like the ones we’re used to and can be used to generate public addresses on the blockchain and sign any transaction, whether that be sending tokens or interacting with a smart contract. The nodes in the Lit network can recombine their shares to sign a transaction without ever coordinating to learn each others’ shares. But how does threshold cryptography and multiparty computation (MPC) enable cross chain interactions?

Lit has actually developed public and private key pairs that can execute JavaScript code, aptly named Programmable Key Pairs (PKPs). Lit nodes can run some code, check to see if arbitrary conditions are passed, and then use the private key to sign a transaction. This combination of JavaScript code and Lit Protocol key pairs is called a Lit Action. The end result feels like a cross chain smart contract that can read data on any Lit enabled chain or from the traditional web and take action based on that data. In one use case of Lit Actions, we can link immutable code with a key pair, just as we can with traditional smart contracts.

Given that we can verify data on-chain and use a Lit key pair to sign transactions, we open up a world of possibilities when it comes to cross chain interactions. If we generate a PKP and write some code to check the balance of its public address, we can develop an escrow service where two parties both send assets to the PKP address. Then the Lit network can generate two transactions sending the respective tokens to each counterparty. This becomes a trustless, decentralized and near instantaneous swap of assets between chains. The moment that the PKP verifies that it has the required balance of the two tokens on both chains, the swap can be completed. No more waiting for optimistic rollups or hoping your exchange’s KYC goes through. Just decide on a price, send your assets to the PKP, and you’re good to go.

Figure 1: Swap Schematic

To create and use a PKP, a user first writes the Lit Action JavaScript code that will be associated with the key pair. I encourage you to check out the Lit Actions documentation to see what’s possible! Once you’ve written and tested your code, you can upload it to IPFS to create a decentralized record of the code you want to allow the Lit network to execute with your key pair.

Now that we have our code on IPFS, we can mint a PKP. Under the hood, PKPs are actually key pairs managed by NFTs that can be traded between addresses. Whoever owns the NFT has the power to sign transactions using the key. In our case though, we only want the PKP to sign a transaction when a certain set of conditions are met, and we don’t want anybody to be able to change what those conditions are. Fortunately, Lit Protocol enables this with the mint-grant-burn functionality, which mints a PKP NFT, associates the key pair with an immutable JavaScript function, and then burns the PKP. Now, the PKP has no owner, can’t run arbitrary JavaScript, and is bound to function exactly as it says it should.

So how is this trustless and verifiable? If someone sends you the Javascript code that they say is associated with a PKP and can enable the cross chain exchange, you can verify with Lit’s API that only that Javascript code, and nothing else, can be run by this key pair. You can also verify that no other code has been associated with this key pair. Then, once you verify that the PKP has been “burned” and has no owner, you have proven that this key pair has one function: to exchange assets between chains.

We have developed an open source SDK that makes it possible to integrate these exchanges within an application: https://github.com/Yacht-Labs/yacht-lit-sdk.

Check out our documentation which gives an overview of the technology and describes our logic for determining whether or not users have sent their tokens to the PKP address and for ideas on implementing it within your own application.

Currently, you’ll need to know who the other counterparty is before you create the Lit Action code to generate the swap transactions. In a future iteration, it would be possible to develop a cross chain orderbook, with users creating bids for tokens to swap for. A liquidity provider could take bids and facilitate the exchanges, enabling users to not have to find a counterparty themselves.

We’re also very excited about the possibility of adding Bitcoin support to the Lit network. With Bitcoin MPC signing, we enable a rare, instantaneous bridge between BTC, EVM, and Cosmos chains. Stay tuned for more developments!

We’re always looking for new technologies that can make users’ interactions with blockchains more secure and easier to use. Follow us at @yacht_labs on Twitter and check out our website at www.yachtlabs.io

Originally posted on Yacht Labs' blog on February 17, 2023.