Layer 1 Tokens on Bitcoin SV

sCrypt
Coinmonks
Published in
3 min readMar 24, 2020

--

Bitcoin has been used to tokenize extrinsic assets since its early days. There are many tokenization protocols. In general, they attach extra protocol metadata to bitcoins¹ to represent these assets, e.g., in OP_RETURN. Token rules are validated at Layer 2, meaning off-chain and not by miners.

Different from all previous work, we show a mechanism to implement Layer 1 (aka, consensus layer, miner enforceable, “trustless”, “permissionless”) tokens in Bitcoin. With Layer 1 token, validation is done by miners. We implement an example token of two owners in sCrypt, a high-level language that compiles to native script.

Token Smart Contract

Token table as state

Using techniques in the previous article, we store the entire token table in the data part as state. The table is a map from each token owner (represented by his public key) to his balance.

Token table

The token contract code is shown below with comments inline.

Token contract

As in the previous article, Line 7 & 9 ensure the preimage is from the current transaction. Line 12 ensures only owner is authorized to transfer tokens. The rest follows the paradigm of state transition explained in the previous article.

Token issuance

Here is code to deploy the contract and transfer tokens back and forth. After the contract is deployed in transaction 1, we can see pk0 is 024c79d694ef7dfd53217de55f7fbf63d2381b18e31afc408b226bc88a6a3cb4f0 and pk1 038ad6e71978a3bcc2974b7106f91a61cf03b184189c67ceb1e34e4e7cc898c2aa. pk0’s initial balance is 100 (0x64 in hex), pk1's 0.

Token distribution after deployment

Token transfer

pk0 transfers 40 tokens to pk1 in transaction 2. As expected, pk0’s balance becomes 60 (0x3c in hex), pk1 40 (0x28).

Token distribution after first transfer

pk1 transfers 10 tokens back to pk0 in transaction 3. As expected, pk0’s balance becomes 70 (0x46), pk1 30 (0x1e).

Token distribution after second transfer

Conclusion

We only demonstrated how to issue and transfer a toy token of two users. By reading and parsing token table on the blockchain, other functions such as balance lookup can be trivially implemented. It is not hard to extend it in many ways to support, for example, multiple user tokens, non-fungible tokens, issuer permissioned tokens, legally compliant tokens, and SPV-compatible tokens.

Thanks to Bitcoin’s unbounded scalability, this extensible tokenization protocol allows any Layer 1 tokens in other blockchains to run on Bitcoin, at significantly lower cost. By complementing existing Layer 2 tokenization protocols on Bitcoin, it also enables atomically swapping bitcoin with other tokenized assets, which opens up a new frontier of countless possibilities.

Get Best Software Deals Directly In Your Inbox

[1] We use lower case bitcoin to denote the cryptocurrency and upper case Bitcoin, the network and protocol.

--

--

sCrypt
Coinmonks

sCrypt (https://scrypt.io) is a web3 development platform specialized in UTXO-blockchains like Bitcoin