Smart COntracts and Computations on BSV

Bitcoin SV opens its doors to Ethereum developers

Getting your Trinity Audio player ready...

https://youtu.be/c_zAlkImgTU

One of the big announcements from the newly rebranded BSV Global Blockchain Convention that was held in Dubai last week was the introduction of a smart contract transpiler, which has the ability to port code written in Ethereum’s Solidity into Bitcoin sCrypt. sCrypt is the language that most developers of smart contracts on BSV use as it compiles directly into Bitcoin low-level script. 

What this tool promises is the potential for ETH developers interested in experimenting with BSV to easily port their smart contract code written in Solidity over to BSV and have 80% of the work of porting their application mostly done for them.  

Batteries not included

Smart Contracts and Computation on BSV

While this may sound like a magic bullet solution that will result in thousands of ETH projects flooding over to the cheap and plentiful transaction environment of BSV overnight, this is not true. While doing a good job converting most of the code over to sCrypt in a workable form, the tool has some notable niggles that require a bit of developer manual hacking. These differences are not due to issues with the transpiler, but more to do with the fact that ETH and BSV are just two different models of blockchain, each with its own unique way of doing things, which cannot be ‘auto-converted.’ One such exception is how each system handles loops. On ETH, loops can be unbounded, and the limit is implied by the gas limit set on the contract. On BSV, all loops must be of an explicit number of iterations.

Other points in incompatibility arise between certain ETH-specific data structure types like its mapping type, struct type, and other contracts which do not translate over to a UTXO model of processing such as the one that BSV uses. (Such as inheritance, exception handling, and functions that call functions on other contracts)

This means that while using the transpiler will likely work for 90% of a library like smart contract code, more complex code that requires complex callbacks, fallbacks, event emitting, functions visibility, any notion of inheritance, and exception handling will have to be re-written. Though it is my suspicion that most developers may find that they won’t need to use all those features anymore in such a rewrite.  

Smart Contracts and Computation on BSV

The analogy I would draw is when converting an OOP program to one written in a functional style. 

At first, you find out that functional programming languages rarely have any notion of a loop construct, and this seems restrictive, but then you realize that loops are just a basic form of a higher-order concept of Map/Reduce, which removes the need for explicit loops. The same can be said about the immutable data in FP, which throws many people off when they first get started in functional programming. Much of the fancy Solidity features just won’t make any sense in Bitcoin. (For instance, what would it mean for a smart contract in BSV to throw an exception? It is meaningless. The contract will just return FALSE as every bitcoin script must always return a predicate true/false).

A lot of what ETH added to its EVM to make smart contract development feel more like traditional development adds to its appeal to newcomers to blockchain development, but it is exactly these convenience features that make the EVM difficult to scale globally due to the amount of complex computation each EVM has to do to process one smart contract function call. Doing away with all this extra baggage is key to how Bitcoin can scale to millions of transactions per second while processing in a parallel fashion necessary for a global system.

Conclusion

Smart Contracts and Computation on BSV

As a jumpstart dev tool for ETH developers looking to explore writing smart contracts on BSV, this tool is indispensable. It will likely be very popular as a ‘first dip in the pool’ for many developers who started their careers writing programs in ETH, but if people are looking for a ‘black box solution,’ then they may be disappointed. This is just a learning tool to help experienced programmers to get their heads thinking in a ‘Bitcoin way,’ and not a way to just auto-convert all their programs over as a transpiler normally would. In that sense, it would be better to call this tool a syntax converter, and for that, it does a pretty good job.

/Jerry Chan

Watch the BSV Global Blockchain Convention Dubai 2022 Day 1 here:

https://www.youtube.com/watch?v=ggbZ8YedpBE

Watch the BSV Global Blockchain Convention Dubai 2022 Day 2 here:

https://www.youtube.com/watch?v=RzJsCRb6zt8

Watch the BSV Global Blockchain Convention Dubai 2022 Day 3 here:

https://www.youtube.com/watch?v=RzSCrXf1Ywc

New to blockchain? Check out CoinGeek’s Blockchain for Beginners section, the ultimate resource guide to learn more about blockchain technology.