project screenshot 1
project screenshot 2
project screenshot 3

Chaindouble

Chain Double is a backwards-compatible protocol that combines IPFS and cross-chain message passing to trustlessly expose on L1 NFTs the result of actions taken on L2.

Chaindouble

Created At

HackFS 2022

Winner of

3️⃣5️⃣ IPFS/Filecoin — Storage Mage

Project Description

Preface

Before getting into the paper, I want to clarify three important points:

  1. This paper assumes a basic understanding of concepts like NFTs, their storage and their metadata. It also assumes a basic understanding of Solidity code and cross-chain communication principles.
  2. When I talk about dynamic NFTs, I am referring to NFTs that use fully on-chain metadata storage.
  3. Finally, I ignored any centralised solutions as they are irreconcilable with the ethos of my work and the crypto space as a whole.

Intro

Dynamic NFTs have proven to be an incredible ground for creativity. Milestone projects like Loot, Brotchain and UniswapV3 have shown us just a glimpse of what’s possible when data lives completely on-chain.

However, storing data on-chain is notoriously expensive and developers must either play a game of gas golf to optimise any WEI of gas or venture into L2 solutions where NFT markets are comparatively minuscule.

NFT trade volume per blockchain. Source.

NFT trade volume per blockchain. Source.

The adoption of L2 solutions becomes even more imperative for NFTs that offer some kind of on-chain interactivity like customisations, breeding, staking and such. Having these interactions on L1 can be so expensive that users would just renounce even trying.

For the past months, I have obsessively researched new decentralised solutions to overcome these limitations, until the idea of a Chain Double came along**.**

Chain Double is a backwards-compatible protocol that combines IPFS and cross-chain message passing to trustlessly expose on L1 NFTs the result of actions taken on L2.

Untitled

But first...why Chain Double?

Movies are the OG artists of deception; it’s often a lower-paid stunt double who takes the most risks, whilst our Hollywood-paid actors reap all the glory on the big screen.

Quentin Tarantino put it wonderfully in his latest masterpiece:

https://youtu.be/JDzMm1uarUU?t=44

The concept behind Chain Double is not far. Just like stunt doubles, our cheap L2 token will do all the heavy lifting, for our valuable L1 token to always look amazing ✨.

Chain Double in details

Two simple ingredients

1. Deterministic IPFS CIDs

IPFS is the most widely adopted storage solution for NFTs metadata, in IPFS’ own words:

IPFS is a distributed system for storing and accessing files, websites, applications, and data.

Anyone can freely upload data to the network that is catalogued using unique CIDs (Content Identifiers). If you haven’t seen one, they look something like ipfs://QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR.

Don’t let them fool you: IPFS CIDs are not randomly assigned. Instead, they are deterministically computed from the data they represent, before that data is even uploaded.

This simple concept is at the base of a powerful realisation: if all we need is data, then not just Alice and Bob can derive a CID, but a smart contract can do that too! As long as they all have access to the same data, the result will stay identical.

Untitled

Virtually all dynamic NFTs expose a view function (usually the tokenURI) that returns the metadata JSON object. If a contract can generate its metadata JSON object on-chain it computes its unique IPFS CID too! If an exact copy of that metadata exists on the IPFS network, its CID is all we need to retrieve it.

The attentive reader can already imply a powerful implication of this.

Le’s imagine two NFT smart contracts where Contract A uses IPFS pointers and Contract B uses only on-chain metadata. Every time Contract B metadata is updated, it computes the new CID and updates the IPFS pointer on Contract A. As long as someone uploads the new metadata object on IPFS, the two NFTs will look completely indistinguishable.

<aside> 🟢 IPFS data is completely trustless. Anyone can upload it while the CID guarantees immutability and integrity. </aside>

Two separated contracts, whose metadata is trustlessly kept in sync… Very interesting! But let’s bring this up a notch with the last piece of our puzzle.

2. Cross-chain message passing

Cross-chain message passing is a technology securing the circulation of billions of dollars in assets across multiple chains. It allows different blockchains to exchange arbitrary messages to cover any use case, with the most common use case being token bridging. If you have ever bridged tokens across chains, you have used cross-chain message passing!

Discussing the intricacies of cross-chain messaging is out of the scope of this paper, but knowing that contracts can trustlessly receive messages from contracts deployed in other chains is all we need.

In the previous section, we saw how Contract B can send a message to Contract A to update its IPFS pointer. But what if this message is passed across chains? Our Contract A can live on Ethereum and get notified every time the Polygon Contract B metadata is updated! The two tokens will still look absolutely indistinguishable. The IPFS pointer will resolve to a metadata JSON object that is identical as if we were to read it directly from Contract B.

In fact, from the point of view of an external observer, Contract A is just a contract like any other NFT that uses IPFS pointers!

Use cases

💅 Customisable tokens

This is possibly the biggest gap from web2 experiences. With some rare L2 exceptions (e.g. Aavegotchi), NFTs are static in their look and have a take it or leave it approach with the buyers. To remain static makes perfect sense for art NFTs, but not for many others. For example, a player might want to add new skins to its character or update the stats as new levels are completed.

With Chain Double, players can bridge their tokens to L2 for all the time they want to spend playing. Once they are ready to return to L1, their token will also be bridged, carrying the latest metadata changes!

🤝 Provably fair token drops

As buyers, we have almost zero power to measure how fairly some traits have been distributed in an NFT collection. Usually, devs pre-bake all the metadata JSON objects and upload them on IPFS — or god forbid in centralised APIs — and just attach them to the NFTs.

With Chain Double, we can keep all the NFT traits on-chain so that, for every newly purchased token, we can recombine them using a Chainlink VRF. Once the new token is minted, it can be bridged to L1 with its new shiny traits!

💎 Truly permanent IPFS storage

Contrary to common believe, IPFS storage is not permanent. Nodes have full discretion over which files to keep and which to flush away. Files in the network are accessible for as long as at least one node is willing to store them. Most nodes keep all files for free but delete them once no client requires them for a while.

To keep the files permanently, offer to keep files permanently for a fee — a service called pinning.

With Chain Double, we don’t risk anymore losing our un-pinned files because, even if no copy is left in the network, they can still re-broadcast it at any time. Just fetch if from chain.

A new paradigm

I strongly believe that we just started to scratch the surface of what is possible with cross-chain communication and I expect many other use cases to be found by our amazing community.

In the opening intro, we have discussed how it can be difficult for developers to choose the right chain for their NFT: big fees/big market vs small fees/small market.

Chain Double is a landmark opportunity to break this vicious circle. Now, all tokens can live on Ethereum to enjoy its vivid market, whilst their metadata is trustlessly stored on L2. Suddenly we don’t have any more limitations on how much we need to store on-chain, because the answer is: everything.

It’s hard to overstate the importance of calling out any NFT project still using centralised APIs, putting at risk the assets of unknowing investors. Until now, they have weakly tried to justify themselves calling this a need to offer interactivity at a low cost. Their last defence has now fallen too.

Making on-chain data the standard will open for a new era of NFT composability, auditability and fairness that our nascent industry so much needs.

Conclusion

Whilst it’s hard to like how gas costs can be a burden on projects, it’s important to realise that constraints are often the best ground for creativity. An incredible amount of brainpower is spent to invent innovations that push the limits of blockchain always further. Layer 2, ZK-SNARKS, and state channels, just to name a few.

With the Chain Double, I want to turn the ratchet one click more. I am beyond excited about the innovation that this solution can bring — every time technology is made more accessible, creativity flourishes.

How it's Made

Chaindouble is made possible by:

  • convert arbitrary data into its unique IPFS CID using a view function in the smart contract.
  • send the IPFS CID via any arbitrary cross-chain messaging system (I used LayerZero for this hackadon, but any alternative will do) in order to indicate where to fetch the current state of the L2 chain on the IPFS network.

Thanks to IPFS being permissionless, anyone can upload the data that originated the CID stored on L1, making the whole system completely trustless (assuming we use a trustless messaging system).

background image mobile

Join the mailing list

Get the latest news and updates