# IOTA L1 Smart Contract/Scripting Report ## Introduction IOTA Tangle is based on an UTXO model: this report aims to analyze pros and cons of some L1 solutions for scripting/smart contract. Here we use this definition: - **scripting solution** as the possibility to express business logic within Input/Output of UTXO model to add expressivity, - **smart contract** as code held in global store that allows to express additional logic both local or global. The study was conducted analyzing three different solutions: - [Bitcoin Script](https://hackmd.io/@4ePtNleDTa6ZvI0XsjLGTw/HyFmLKRa9): a custom opcode based language and a stack machine able to process them (inspired to Bitcoin Script): PoC written in Go; - [WASM](https://hackmd.io/@4ePtNleDTa6ZvI0XsjLGTw/r1aM2S5Ji): smart contracts written in WASM (from language like Rust, Go, Javascript) processed in a WASM runtime like Wasmer or Wasmtime; - [Move](https://hackmd.io/@4ePtNleDTa6ZvI0XsjLGTw/ry5JdsS-o): a smart contract language created at Facebook with an increasing number of adopters. In the following sections we will brifly go over main aspects that are interesting for IOTA implementation of its L1 solution. # Popularity/Compatibility - **Bitcoin Script**: this is a custom solution, no support nor ecosystem; language is based on opcodes and stack: the usage of an higher level language needs the creation of a custom compiler (that convert an high level language into opcodes). - **WASM**: growing adoption and ecosystem of runtimes and client languages (Go, Rust, Javascript between the most famous), lack of stadards for runtime interoperability: a interoperability lib need to be developed (e.g. [WASP lib](https://github.com/iotaledger/wasp/tree/master/packages/wasmvm/wasmlib)) - **Move**: Developed at Facebook, early adopters are Sui, Aptos, Solana, DFinance; lacking of plug and play solutions (aka MoveVM), no many smart contract written in Move; ecosystem and code are written in Rust. # Runtime | <p style="text-align: center">Bitcoin Script</p> | | -------- | | ![](https://i.imgur.com/MaXSZLn.png) | | Memory stack based, possibility to easy access UTXO context | | <p style="text-align: center">WASM</p> | | -------- | | ![](https://i.imgur.com/ONIr3hl.png) | | Linear memory shared with the runtime. Hard integration with external runtime (for security/sandboxing reasons) | | <p style="text-align: center">Move</p> | | -------- | | ![](https://i.imgur.com/U79AwBv.png) | | Data schema, values and contracts/libs can be associated to addresses | # Features || Bitcoin Script | WASM | Move Lang | | -------- | -------- | -------- | -------- | | Computation | Simple computation | Turing Complete | Turing Complete | | Termination | Fee Based (to be implemented) | Fee Based (only Wasmtime runtime) | Fee Based | | Security | - | WASM linear memory as sandbox space to isolate WASM from external interaction | Rust-based borrow checker, prover, optimizer | | Occupation of Binary | Few bytes based on opcodes | tenths of Kbyte based on runtime support (TinyGo was the smallest in the analysis) | ? | # Development Each solution has a different impact in terms of development effort or in learning curve to approach a given technology: here we briefly discuss about it: || Bitcoin Script | WASM | Move Lang | | -------- | -------- | -------- | -------- | | Development Effort | [custom language and compiler](https://hackmd.io/O9WtXjlQSXGzetXEnNsAJg#Implementation) | [library + wrappers](https://hackmd.io/ChbPI6gHQ9qDNE9H7KgdaA#Wasp-solution) | [stdlib + wrappers](https://hackmd.io/DSOTQouTQZiCF_nMLyxDDA#How-to-implement-IOTA-scripting-with-Move) | | Learning | - | [Understanding different WASM produced](https://hackmd.io/ChbPI6gHQ9qDNE9H7KgdaA#Compilers-differences) | [Rust-based](https://move-language.github.io/move/) |