XRPLF / xrpl-dev-portal

Source code for xrpl.org including developer documentation
https://xrpl.org
Other
528 stars 1.02k forks source link

Concept explaining XRPL's place/position re:smart contracts #2607

Open mDuo13 opened 4 months ago

mDuo13 commented 4 months ago

A major differentiator across blockchains is the chain's potential for "smart contracts", and XRPL occupies an unusual place in the market in that regard. It would be great to have a concept page on the docs site explaining this.

Background / Draft info

Bitcoin is close to one extreme, with very minimal non-payments functionality on-chain. On the other end, Ethereum has Solidity / EVM which supports fully turing-complete smart contracts.

The XRPL (mainnet) is in the middle, with a variety of transaction types that provide more complex functionality pre-defined to implement some of the more common categories of smart contracts—stuff like issuing tokens, managing the DEX, etc—but does not provide unbounded on-chain capabilities. This was an intentional choice because smart contracts are error-prone and deploying/upgrading/debugging them is quite challenging.

It was commonly stated with smart contracts in the early days that "code is law" but the DAO hack of 2016 proved that in practice this does not work. When the DAO's code did not match the intent of the developers, and allowed a clever user to drain money out of it in unintended ways, the Ethereum network mostly rallied around a hardfork that rolled back those transactions even though those transactions were legitimate according to the "law" laid down by the original code.

Having smart contracts operating entirely on-chain also creates issues with scalability and processing since every node in the network has to execute all the code that runs on-chain, in parallel with each other; this is a major factor ETH gas fees are higher than XRPL's transaction costs even after Ethereum moved to Proof of Stake.

The XRPL's smart transactors are intended to provide many of the benefits of smart contracts with less overhead and less risk. Instead of having users create and re-create common functionality like custom tokens or DEXes, the functions for those things are built into the blockchain's core code once and thoroughly tested and debugged. If users want to do a lot more and different things, they have to run off-chain infrastructure to do it, but if they want to do common things they can just use the existing built-in functionality rather than learning Solidity and coding it up themselves.

Xahau and its Hooks place it closer to Ethereum though it still—intentionally—does not support fully turing-complete arbitrary on-chain programming. The idea is that small, limited on-chain custom code in the form of hooks provide most of the benefit of a full virtual machine while being easier to debug and reason about, requiring less work to get started with, and hopefully operating more efficiently in terms of the computing work they require from the blockchain infrastructure.