Solidity to sCrypt

Introducing Solidity to sCrypt transpiler: Run Ethereum smart contracts on Bitcoin

This post was first published on Medium.

Why is it needed?

sCrypt is Bitcoin’s native smart contract language. Ideally, everyone shall just develop smart contracts in sCrypt, leveraging the most scalable blockchain. In practice, we also understand that many projects and developers have invested plenty of time and money into developing their current Solidity codebases.

The transpiler facilitates developers to migrate their applications onto the Bitcoin network from Ethereum and other Solidity/EVM-compatible blockchains, without writing code from scratch. It reduces their migration cost enormously, especially if their codebase contains thousands of lines of code or more.

In addition, existing Solidity libraries and codebase can be converted and used in sCrypt contracts.

Lastly, it can also be used for Solidity developers to learn sCrypt quickly, by observing the similarity, as well as difference, between Solidity code and its sCrypt counterpart.

How does it work?

It is no easy task since Ethereum smart contract is account-based, while Bitcoin is based on UTXO.

At high level, we use a single UTXO to represent a snapshot of an Ethereum contract and map each contract account to a starting UTXO, with equivalent code and data storage, representing the contract’s initial state. We use Stateful Smart Contracts to map function calls that change a contract’s state. Whenever the state of the contract changes, a new transaction is generated that spends the current UTXO of the contract and generates another UTXO with the new state. The latest state of the original contract is always in the lastest UTXO.

The transpiler converts the contract’s solidity code to its equivalent counterpart in sCrypt. For more details, please refer to this.

Introducing Solidity to sCrypt transpiler: Run Ethereum smart contracts on Bitcoin
Map an Ethereum contract to a Bitcoin stateful contract

Where to use it?

We have developed a playground for the transpiler. With one single click, you can magically convert your contract written in Solidity to its sCrypt equivalent.

We show a simple counter contract example below.

Introducing Solidity to sCrypt transpiler: Run Ethereum smart contracts on Bitcoin

You can see there is almost a one-to-one correspondence between the Solidity code on the left and the sCrypt code it transpiles to on the right. Each Solidity state and function are mapped to an sCrypt state and function. The extra code in sCrypt is boilerplate code for propagating the contract state to the next UTXO and is virtually identical for any contract.

Acknowledgements

We thank Vaionex for developing the web UI and the Bitcoin Association for sponsoring the project.

Watch: The BSV Global Blockchain Convention presentation, Smart Contracts and Computation on BSV

New to Bitcoin? Check out CoinGeek’s Bitcoin for Beginners section, the ultimate resource guide to learn more about Bitcoin—as originally envisioned by Satoshi Nakamoto—and blockchain.

[id^="_form"]
[id^="_form"]
[id$="_submit"]
[id$="_submit"]
[^;]
[^;]
[?&]
[?&]
[^&#]
[^&#]
[(d+)]
[(d+)]
[elem.name]
[elem.name]
[+_a-z0-9-'&=]
[+_a-z0-9-'&=]
[+_a-z0-9-']
[+_a-z0-9-']
[a-z0-9-]
[a-z0-9-]
[a-z]
[a-z]
[el.name]
[el.name]
[id^="_form"]
[id^="_form"]
[id$="_submit"]
[id$="_submit"]
[^;]
[^;]
[?&]
[?&]
[^&#]
[^&#]
[(d+)]
[(d+)]
[elem.name]
[elem.name]
[+_a-z0-9-'&=]
[+_a-z0-9-'&=]
[+_a-z0-9-']
[+_a-z0-9-']
[a-z0-9-]
[a-z0-9-]
[a-z]
[a-z]
[el.name]
[el.name]