Originating a Smart Rollup

Now that the Kernel Gallery has been introduced, it’s time to build and originate one of the example.

This blog post will assume that you have access to the octez-smart-rollup-client-PtMumbai and the octez-client binaries, you can install them by following this documentation.

Building the Kernel Gallery

The Kernel Gallery is a set of kernels written in Rust, so you will need to install Rust on your computer:

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Then you can clone the Kernel Gallery on your computer.

$ git clone git@gitlab.com:tezos/kernel-gallery.git

You will notice a file rust-toolchain that forces the rust to use the version 1.66.0. To make sure you have the correct installed Rust version you can use this command:

$ rustup --version
> rustup 1.26.0 (5af9b9484 2023-04-05)
> info: This is the version for the rustup toolchain manager, not the rustc compiler.
> info: The currently active `rustc` version is `rustc 1.66.0 (69f9c33d7 2022-12-12)

The kernels are compile to Wasm, to compile some Rust code to Wasm you need to add the wasm32-unknown-unknown to the Rust compiler

$ rustup target add wasm32-unknown-unknown
> info: downloading component 'rust-std' for 'wasm32-unknown-unknown'
> info: installing component 'rust-std' for 'wasm32-unknown-unknown'

To make sure everything is working you can compile all the kernel of the Kernel Gallery:

$ cargo build --target wasm32-unknown-unknown
> ...
> Finished dev [unoptimized + debuginfo] target(s) in 8.61s

On Macos you may have some troubles when compiling the Kernel Gallery, so we added a section in the readme of the Kernel Gallery to help you solve the issue

Originate a small Smart Rollup

Let’s try to originate the debug kernel that only display “Hello from kernel!” on each new Tezos block level.

This kernel is simple to originate because when built, its size is smaller than 24KB.

First step: let’s build it.

If you want to learn more about this announcement, please read our blog post on Marigold website
:point_right: Originating a Smart Rollup

1 Like

I am wondering, is it possible to originate a Smart Rollup in another language than Rust? Like Javascript for example?

It depends, if you want to use another language, this language will have to compile to Wasm. And unfortunately it’s not possible with Javascript.
Note that there is lot of work because one has to implement the functions provided by the Rust SDK. This might be quite easy in Go or C/C++.

Oh I thought it was possible. I am not a pro so maybe I got it wrong. But for example this blogpost describes how to compile Javascript into WebAssembly: JavaScript and WASI - Wasm Builders 🧱

And shopify explains here how to run JavaScript via Wasm: Bringing Javascript to WebAssembly for Shopify Functions (2023)

So is this some “hack” that cannot be applied for smart rollups? Can you shed some light into this? Thanks! :slight_smile:

Javy can compile Javascript to Wasm, but it seems javy includes float instructions inside the wasm binary. Because it’s not derminist the Smart Rollup won’t run it.

If you like the Javascript/Typescript syntax, I recommend to have a look to https://www.assemblyscript.org/

If you want to have a try here is a hello world in assembly script:

// Define a custom abort function 
// (don't know what it is, but it has to be defined)
const abort = (): void => {}

// Define the write_output host function
@external("smart_rollup_core", "write_debug")
export declare function write_output(pointer: i32, length: i32): void;

const log = (msg: string): void => {
  let bytes = String.UTF8.encode(msg); // transform the string into some bytes
  const ptr = changetype<i32>(bytes); // convert the array to a pointer
  write_output(ptr, bytes.byteLength); // call the extern function

// The kernel run function
export function kernel_run(): void {
  log("Hello AssemblyScript\n")

The code was compile with:

asc assembly/index.ts --target release --use abort=assembly/index/abort

Then if you execute the generated Wasm file (located under /build/release.wasm with the octez-smart-rollup-wasm-debugger with some inputs you should see “Hello AssemblyScript” :tada:

But keep in mind, that even if you use another language than Rust you will have to implement all the bindings and a SDK, that can represent a lot of work :grimacing: