Flextesa Sandboxes with Smart Optimistic Rollups

Phillip Saxton
The Aleph
Published in
5 min readJun 8, 2023

--

Flextesa’s latest feature, the smart optimistic rollup sandbox, simplifies experimentation with smart optimistic rollups in a local environment. This feature builds on our mission to create a more robust and accessible Tezos development ecosystem.

Introduced in the Mumbai upgrade, the smart optimistic rollup is a layer 2 solution which increases the scalability of Tezos by bundling several operations into one. See Tezos’ official documentation on smart rollups.

“layers and scale” by bobarcpics is licensed under CC BY 2.0.

This article will provide examples of running a smart rollup sandbox in a Docker container. The released image, oxheadalpha/flextesa:20230607, and included scripts (mumbaibox, narirobibox, alphabox) provide a straightforward setup process with two built-in commands for launching a smart rollup sandbox.

  • start_tx_smart_rollup
  • start_custom_smart_rollup

You can explore their implementations and documentation in the Flextesa repository.

Starting the TX Smart Rollup

The quickest way to interact with a smart rollup sandbox is with the start_tx_smart_rollup command.

The transaction optimistic rollup (tx rollup) is the “layer two” precursor to the smart optimistic rollup. It has been disabled since the Mumbai upgrade. The function of the transaction rollup is to execute batches of ticket transactions in the rollup.

The tx-kernel is an implementation of the transaction optimistic rollup in a smart optimistic rollup. You can run the “tx smart rollup” sandbox as follows.

$ docker run --rm --name my-sandbox --detach \
oxheadalpha/flextesa:20230607 mumbaibox start_tx_smart_rollup

This will start a container running a sandbox network. After a few moments Flextesa will originate the “TX” smart rollup along with a layer one smart contract for minting tickets and depositing them into an address on the rollup.

Included in the container is the tx-client, which can interact with the tx-smart-rollup. First, initialize the tx-client.

$ docker exec my-sandbox mumbaibox tx_client_init
$ docker exec my-sandbox mumbaibox tx_client_show_config
{
"config_file": "/tmp/mini-smart-rollup-box/tx-client/config.json",
"config": {
"tz_client": "/usr/bin/tz-client-for-tx-client.sh",
"tz_client_base_dir": "/tmp/mini-smart-rollup-box/Client-base-C-N000",
"tz_rollup_client": "/usr/bin/tz-rollup-client-for-tx-client.sh",
"forwarding_account": "alice",
"depositor_address": "KT1EX3joap58iygupJsbxhgGmhwVTWzHM3ky",
"rollup_address": "sr1KVTPm3NLuetrrPLGYnQrzMpoSmXFsNXwp",
"known_accounts": [],
"known_tickets": {}
},
}

Next, create a new address and send tickets to it via the mint_and_deposit_to_rollup contract. You may find it convenient to alias the tx-client call inside the container first.

$ alias tx_cli='docker exec my-sandbox tx-client \
--config-file /tmp/mini-smart-rollup-box/tx-client/config.json'
$ tx_cli gen-key bob
$ tx_cli mint-and-deposit \
--amount 10 \
--contents "hello world" \
--target bob \
--ticket-alias my_ticket

The command mint-and-deposit is a call to the contract’s default entrypoint. It sends a message to the smart rollup inbox with the “amount” of tickets minted, their “contents” and the “target” recipient account. The “ticket-alias” is an alias the tx-client assigns to the ticket-hash generated by the tx-kernel. Below is a truncated example of the calls output.

Node is bootstrapped.
Estimated gas: 4058.231 units (will add 100 for safety)
Estimated storage: 66 bytes added (will add 20 for safety)
Operation successfully injected in the node.
...
Internal operations:
Internal Transaction:
Amount: ꜩ0
From: KT1EX3joap58iygupJsbxhgGmhwVTWzHM3ky
To: sr1KVTPm3NLuetrrPLGYnQrzMpoSmXFsNXwp
Parameter: (Pair "5e87fcdd8c9bf5d80a58ec7c5e28c41bec64ae0a"
(Pair 0x01411c976a093fbd4964353e52a2470ed61d1148ef00 (Pair "hello world" 10)))
This transaction was successfully applied
Consumed gas: 1007.075
Ticket updates:
Ticketer: KT1EX3joap58iygupJsbxhgGmhwVTWzHM3ky
Content type: string
Content: "hello world"
Account updates:
sr1KVTPm3NLuetrrPLGYnQrzMpoSmXFsNXwp ... +10
...

Now check the balance for bob.

$ tx_cli get-balance --account bob --ticket my_ticket
bob holds 10 of my_ticket

Finally, transfer tickets between addresses on the tx-rollup.

$ tx_cli gen-key rick
$ tx_cli transfer --from bob --to rick --ticket my_ticket --amount 1
Estimated gas: 176.573 units (will add 100 for safety)
Estimated storage: no bytes added
Operation successfully injected in the node.
Operation hash is 'ooMGeL2QUJbA9ttPga2qMx4oKoGWXBNhpA4C7VTbppaYifaLqFe'
Waiting for the operation to be included...
Operation found in block: BKqeTvsntWhMGso53MiCCVMTaBpaU9nt132E47xF7uQ1zjJxhpX (pass: 3, offset: 0)
This sequence of operations was run:
Manager signed operations:
From: tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb
Fee to the baker: ꜩ0.000427
Expected counter: 4
Gas limit: 277
Storage limit: 0 bytes
Balance updates:
tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb ... -ꜩ0.000427
payload fees(the block proposer) ....... +ꜩ0.000427
Smart rollup messages submission:
This smart rollup messages submission was successfully applied
Consumed gas: 176.507

The operation has only been included 0 blocks ago.
We recommend to wait more.
Use command
octez-client wait for ooMGeL2QUJbA9ttPga2qMx4oKoGWXBNhpA4C7VTbppaYifaLqFe to be included --confirmations 1 --branch BKsmgWJMCsYcU8iEfmR7YapLjJULqiJSrAAVWEuxcbauTFzfadF
and/or an external block explorer.

Rick’s balance should now reflect the transferred amount.

$ tx_cli get-balance --account rick --ticket my_ticket
bob holds 1 of my_ticket

The TX smart rollup sandbox will be expanded as development of the transaction smart rollup progresses. To follow the development of the transaction smart rollup see the repositories for the tx-kernel and tx-client.

In the meantime, you can test your own kernel…

Starting a Smart Rollup Sandbox with a Custom Kernel

In this next example, you’ll provide your own custom kernel. First, you’ll need to prepare a directory containing your kernel files along with any michelson smart contracts that you want to make available to the container. This example will use the directory /rollup/files as the location of these files.

$ docker run --rm --detach --volume /rollup/files:/rollup \
--name my-sandbox oxheadalpha/flextesa:20230607 mumbaibox \
start_custom_smart_rollup $KIND $TYPE /rollup/my-kernel.wasm

This will start a container named my-sandbox. The --volume option mounts the /rollup/files directory to the container at /rollup. Replace $KIND and $TYPE with the values appropriate for your kernel. /rollup/my-kernel.wasm will be the location of your kernel within the container.

mumbaibox start_custom_smart_rollup will start a Flextesa sandbox running the Mumbai protocol. After a few moments, a rollup using the custom kernel you’ve provided will be originated.

The smart_rollup_info command will output the smart-rollup-node’s config file, which includes the sr1 address for the smart rollup.

$ docker exec my-sandbox mumbaibox smart_rollup_info
{
"smart_rollup_node_config": {
"smart-rollup-address": "sr1KVTPm3NLuetrrPLGYnQrzMpoSmXFsNXwp",
"smart-rollup-node-operator": {
"publish": "tz1SEQPRfF2JKz7XFF3rN2smFkmeAmws51nQ",
"add_messages": "tz1SEQPRfF2JKz7XFF3rN2smFkmeAmws51nQ",
"cement": "tz1SEQPRfF2JKz7XFF3rN2smFkmeAmws51nQ",
"refute": "tz1SEQPRfF2JKz7XFF3rN2smFkmeAmws51nQ"
},
"rpc-addr": "0.0.0.0",
"rpc-port": 20010,
"fee-parameters": {},
"mode": "operator"
},
}

Record the rpc-port. You’ll need it to configure the smart-rollup-client. The octez-smart-rollup-client-${protocol} binaries are available in the container. For convenience, alias the following.

$ alias srcli='docker exec my-sandbox octez-smart-rollup-client-PtMumbai -E http://localhost:20010'

Finally, use the octez-client included in the docker container to originate any smart contracts you’ve included in /rollup/files directory.

$ alias tcli='docker exec my-sandbox octez-client'
$ tcli originate contract my_contract_alias \
transferring 0 from alice running /rollup/my_contract.tz \
--burn-cap 1 --init "Unit"

This should get your custom smart rollup running.

The smart rollup sandbox is intended to simplify testing and development by allowing you to originate and experiment with rollups in a sandbox environment. For more information on Flextesa please visit the repository.

For more information on Smart Optimistic Rollups and kernel development see the Tezos documentation. You can find example kernels in the Smart Rollup Kernel Gallery.

--

--