Try ALEX Bitcoin DeFi Now →
Blog
/
Main
Building an On-Chain BRC20 “Indexer of Indexers”
September 12, 2023

ALEX Bitcoin DeFi will soon ship the first on-chain indexer of BRC20 tokens. This hasn’t been a solo effort: we’ve been in collaboration with @domodata (creator of BRC20 and ALEX advisor), together with key existing off-chain indexers, such as BestinSlot, OKX, Hiro system, Unisat and others.

Our mission is to validate each BRC20 event and update the global state of balances on a decentralized, on-chain contract. The greater the immutability and censorship resistance of a global BRC20 ledger, the faster and broader BRC20 adoption will occur.

On-chain Indexer: Verifying L1 events with L2 Programmability

We’re collaborating with pioneers like Domo, as well as key existing off-chain indexers, such as BestinSlot, OKX, Hiro system, Unisat and others, to construct an “indexer of indexers.” This concept capitalizes on Stack layer’s unique attributes — programmability and reading the Bitcoin state — to lead the way toward decentralized consensus on BRC20 indexing.

The setup involves off-chain indexers submitting and validating events to the on-chain indexer, which then verifies each transaction through Stacks, either accepting or rejecting them. Wallets and decentralized applications can query this on-chain indexer for valid events, marking an exciting step in our mission to transform the face of Bitcoin DeFi.

The indexer does not implement an on-chain version of “indexing engine” itself, which, while theoretically possible, is computationally very expensive, but rather runs a federated model that relies on a consortium of off-chain indexers to validate and submit the latest BRC20 transactions to the on-chain smart contract written by ALEX, which keeps the validators in check by:

  1. Implementing a consensus mechanism
  2. Independently verifying that the purported Bitcoin transaction is indeed mined (which only a Bitcoin L2, such as Stacks, can read directly)

The consensus is reached when a minimum threshold (i.e. “m-of-n”) of indexers agree to a particular BRC20 event. The incentives for indexers to act honestly are monetary and reputational, much as they are now.

We are in discussions however, with those same indexers about moving towards a staking model where dishonest / malicious behavior by an indexer would be penalized with their stake being slashed.

The Need for On-Chain Indexing

The current BRC20 marketplace reliance on centralized off-chain indexers creates vulnerabilities that consensus and L2 verification can minimize. With individual indexers, errors can occur unintentionally due to poor performance or intentionally whether due to censorship or even malice. Our efforts are to reduce the “centralization risk” of off-chain indexer error or manipulation which may place user holdings at risk.

Here’s how, using an example: imagine a transaction exchanging 1 BTC for 1000 ORDI. If the BRC20 indexer is wrong and determines the satoshi you are including contains the UTXO for a valid transfer of 1000 ORDI, when actually it’s an valid transfer, the transaction will go through (Bitcoin for Bitcoin) and incorrect indexer data has resulted in the loss of user funds (@BobBodily).

source: https://twitter.com/BobBodily/status/1699464993543184725/photo/1

This is the reason that we, along with our partners and collaborations, consider the establishment of an on-chain, tamper-proof, and censorship-resistant indexer to be pivotal for greater BRC20 adoption. The aim of the current version of the on-chain indexer is to minimize reliance on any one single entity. The more we minimize trust the closer the immutability of the BRC20 tokens comes to Bitcoin itself.

What is Indexing and Why do Indexers Matter?

Although BRC20 inscriptions exist 100% on-chain, the Bitcoin L1 does not “read” the inscription data. There is no error message that pops up to prevent you from inscribing a transfer for more tokens than you hold. All the Bitcoin L1 “sees” are satoshi’s being sent and received, no different from any other Bitcoin transaction.

This is why indexers are critical to BRC20 infrastructure. If there isn’t on-chain code running that will create an “error: $ORDI already exists” then it is up to the indexer of a BRC20 marketplace to determine if $ORDI is authentic or a fake. Without indexing a BRC20 market isn’t possible, there’s just the chaos of nearly indistinguishable text files.

To enforce the token standard rules a number of off-chain indexers have been developed and are in use to address the constraints of the L1. This requires a database that does “read” and register all of the BRC20 transaction data to check which inscription was the first to “deploy” a new token name.

The indexer must keep track of which wallets minted the original token supply up to the maximum limit, where the cut off for minting occurred, and are the tokens being “transferred” in the secondary market traceable to these wallets. Although anyone can do the indexing themselves to verify the global state, it is vastly easier to simply consult a centralized indexer.

It is important to make clear that Bitcoin remains the ultimate source of truth. All indexers could go down and there would be no loss of funds as all data is on-chain and could be reconstructed deterministically by applying the rules of the BRC20 standard. Indexing should not be confused with mining; indexing just tracks transactions and does not involve validation or “appending” transaction data (@mattyTokenomics).

The Revolution Continues

Ordinals marked a paradigm shift in the history of crypto. Bitcoin became more than “sound money;” it was transformed into the ultimate data layer. For the first time satoshis weren’t sold just for their monetary value, but for the information inscribed onto them.

Bitcoin blockspace is the most secure, indestructible and valuable blockspace in crypto. In addition to Ordinals creating on-chain NFTs that are true “digital artifacts,” inscription data has enabled new use cases we are actively helping develop.

The most successful has been the BRC20 standard, created as an experiment by @domodata to test if fungible tokens could be created on a fundamentally non-fungible blockchain (as every satoshi is numbered). Although Bitcoin’s blockchain doesn’t enforce the token standard rules and token operations are relatively slow and inefficient, BRC20 has been massively popular, accounting for 24M out of 29M ordinals inscriptions to date.

Inscription rates have remained steady throughout the summer, despite a sideways crypto market and softer NFT prices. It is our expectation that the next bull market will bring surging growth and activity to Ordinals, BRC20 tokens and Bitcoin L2s having an on-chain “indexer of indexers” will help to amplify.

source: https://dune.com/dgtl_assets/bitcoin-ordinals-analysis

The significance of Ordinals to the Bitcoin ecosystem is hard to understate, with nearly half of all Bitcoin transactions in August consisting of inscriptions.

source: https://twitter.com/trustmachinesco/status/1697673566630658319?s=20

Conclusion

The DeFi landscape continues teeming with possibilities, and at the heart of it all, Bitcoin DeFi is set to take center stage. Ordinals have opened up new possibilities that at the start of 2023 were mere wishful thinking: we’ve witnessed NFTs and non-fungible tokens “come home” to Bitcoin enthusiastic community support.

Now we’re entering a new phase of the growing application of L2 solutions to overcome L1 scalability and programmability limitations. ALEX has already launched the B20 Orderbook and L1 Launchpad, functionalities that combine the best L1 / L2 features for optimal user experience. With the On-chain Indexer, it will be evident to an ever greater audience, how profound the advantages are of utilizing Bitcoin layers to remove the need for “trust” not only from BRC20 but countless new Bitcoin utilities on the horizon.