<!---
In this blog post we will demonstrate how to originate a kernel bigger than 24kb. We will discover the kernel installer developped by the Tezos core dev and how to use it. At the end of this tutorial you will no longer be limited by the size of your kernel.
--->
# How to deploy a kernel bigger than 24kb
If you started developing some kernels, you may have already reached the size limit of 24kb and have been facing a wall: your Tezos operation is too big to be executed. In this blog post, we will demonstrate how to deploy a kernel bigger than 24kb.
There are four steps to do so:
- reducing the size of your kernel
- splitting your kernel into chunks of 4kb
- setting up the kernel installer developed by the Tezos core developer
- deploying the installer and your kernel
## Prerequisites :pencil:
In this tutorial, I will assume you have read the [previous tutorial](https://www.marigold.dev/post/how-to-write-a-rollup-kernel) and have all the prerequisites of it.
To sum up, you will need to:
- know how to [compile tezos](https://tezos.gitlab.io/introduction/howtoget.html) tezos
- know how to [compile a kernel](https://www.marigold.dev/post/how-to-write-a-rollup-kernel)
## Let's reduce the size of your kernel!
This step is not required, but higly recommended. There is a tool named [wasm-strip](https://github.com/WebAssembly/wabt) that can drastically reduce the size of your kernel.
Let's assume for this tutorial that you have your `kernel.wasm` in the current directory.
```bash
$ wasm-strip kernel.wasm
```
> Be careful, the wasm-strip command does not create a new file but instead replaces the original one.
Just after this command, your kernel should be smaller. You can verify the size of your kernel with `ls`:
```bash
ls -lh
```
If your kernel is smaller than 24kb you are ready to go and you can originate your kernel as a normal one. Otherwise, you can continue reading this post.
## Let's split it
Why do we need to split the kernel into many 4kb chunks?
A kernel can update itself, to do so, the kernel has to update some specific files located under some specific locations in the durable storage.
That is exactly what the kernel installer does. It's a kernel that will read some data (your split kernel) from the data reveal directory and update the kernel code with it.
The data stored in the data reveal directory should be less than 4kb to have a still working refutation game.
To split the data, we will use the DAC with the legacy execution mode. The legacy version of the DAC is a http server which accepts data, splits them into chunks, saves them to a directory, and gives you a reveal hash.
If you compiled Tezos, you should have the `octez-dac-node` binary in the Tezos root directory.
Before starting the DAC, we need to configure it.
```bash
$ mkdir dac
$ octez-dac-node init-config # Init the config of the DAC
$ octez-dac-node set dac parameters --reveal-data-dir dac # The directory where your splitted kernel will be
```
And then you should be able to run the DAC node.
```bash
$ octez-dac-node run
```
Now that the DAC is started you can submit some bytes to it. In our case, it will be the hexadecimal representation of our kernel.
You will have to send your kernel as hexadecimal. To convert your Wasm binary file, you can use the command `xxd`.
```bash
$ KERNEL=$(xxd -ps -c 0 kernel.wasm | tr -d '\n')
```
Only the Merkle tree scheme is compatible with the kernel installer. It will divide your kernel into 4kb pages and order them in a Merkle tree.
```bash
curl --header "Content-Type: application/json" -X POST -d "{\"payload\":\"$KERNEL\", \"pagination_scheme\":\"Merkle_tree_V0\" }" http://localhost:10832/store_preimage
```
The DAC should have answered you with a `root_hash`. Please save it for later. Then you can stop the DAC execution.
## Using the kernel installer
As described before, the kernel installer will read the reveal data directory of the rollup and update some specific files in the durable state to update its code.
To have a working installer, we will need to change its code to specify the correct root_hash (the root_hash of our kernel generated by the DAC).
First, let's clone the kernel.
```bash
$ git clone git@gitlab.com:tezos/kernel.git
$ cd kernel
```
To make sure everything is working, let's try to compile it.
```bash
$ cargo make wasm-preimage-installer
```
Then you will need to replace the value of the `ROOT_PREIMAGE_HASH` with the `root_hash` generated by the DAC.
```rust
// installer_kernel/src/lib.rs
// located in the preimage_installer module
// line ~41
pub const ROOT_PREIMAGE_HASH: &[u8; PREIMAGE_HASH_SIZE * 2] =
b"00e746d31ec0c255edfef1948bf77ea11025f5751ecbcb4d288947d3f91002b20a";
```
Finally, you can compile the installer with the updated value.
```bash
$ cargo make wasm-preimage-installer
```
Even if the purpose of the kernel installer is to install a bigger kernel, the kernel installer itself is too big to be originated, which is ironic. As you would do for a normal kernel, you can use `wasm-strip` to reduce its size.
```bash
$ wasm-strip target/wasm32-unknown-unknown/release/tezos_rollup_installer_kernel.wasm
$ KERNEL_INSTALLER=$(xxd -ps -c 0 target/wasm32-unknown-unknown/release/tezos_rollup_installer_kernel.wasm | tr -d '\n')
$ cd ../
```
# Deploying your kernel :rocket:
At this step, you should have:
- the files generated by the DAC (your split kernel)
- the kernel installer compiled with your `root_hash` generated by the DAC
Before starting your rollup node, you will need to setup its data directory.
Let's create a data directory for your kernel `rollup-data`.
```bash
$ mkdir rollup-data
```
Then you will need to populate the reveal data directory with the different chunks generated by the DAC.
```bash
$ mkdir rollup-data/wasm_2_0_0 # The name is important and has to be this one
$ mv dac/* ./rollup-data/wasm_2_0_0/
```
You can use `ls` to verify if all your files have been correctly moved. You should notice a file with the same name as your `root_hash`.
Now the following steps will be the same as deploying a normal kernel:
First, we need to originate the smart rollup in Tezos:
```bash
$ octez-client originate smart rollup from "bob" \
of kind wasm_2_0_0 \
of type bytes \
with kernel "${KERNEL_INSTALLER}" \
--burn-cap 999
```
> Replace "bob" with your account alias.
> Bob should have enough tez to deploy the rollup.
Remember the address of your rollup. You can save it in a variable.
```bash
SOR_ADDR=sr1732roAk1iHKDsdp5jmyJpbyAAngvufAEp # please update with your rollup address
```
Now you can initialize the data directory of your rollup.
```bash
octez-smart-rollup-node-alpha \
init operator config for "${SOR_ADDR}" \
with operators "bob" \
--data-dir "rollup-data"
```
Then you can start your rollup as you would for a normal one:
```bash
$ octez-smart-rollup-node-alpha run --data-dir "rollup-data"
```
After one Tezos block, your kernel will be installed by the installer and ready to be used.
From this step, your rollup is like a normal one, you can stop it, restart it, submit operations to the inbox, etc...
# Voilà :tada:
And that's all folks. In this blog post, you have learned how to originate a kernel bigger than 24kb on Tezos. I really hope that this blog post has been useful for you. In a next blog post we will demonstrate how to send operations from the rollup to a Tezos smart contract.