# Smart Rollup Investigation Notes
## Introduction
Smart Rollups are Tezos' solution to scaling operations (permissionless) and throughput into the blockchain.
One of the existing use cases currently is to be able ***to do contract calls via a rollup node with the aid of messages***.
We will cover that example in this document.
## Prerequisites
Before starting your own rollup nodes, etc, you will need to have **Octez v16** installed.
You can either build from source, or use the Docker images that are relevant to the node you're pointing to here: https://teztnets.xyz/
## Starting up your rollup node
:::warning
Rollup nodes' L1 need to be running on archive mode
:::
### Operator address
An implicit address will be assigned as an 'operator' to originate the rollups with, and it needs to hold **at least** 10k tez. In this document we will start referring to the pkh of the operator as `${OPERATOR_ADDR}`
You should also run your own octez-node by running these 2 commands
```
octez-node config init --data-dir "${ONODE_DIR}" --network "${NETWORK}"
octez-node run --data-dir "${ONODE_DIR}" --network "${NETWORK}" --rpc-addr 127.0.0.1
```
- `ONODE_DIR` being a new directory you want to put your node configs in
- `NETWORK` being the octez network you want to join with, we use Dailynet: https://teztnets.xyz/dailynet-about
### Originating a Rollup
```
octez-client originate smart rollup from "${OPERATOR_ADDR}" \
of kind wasm_2_0_0 \
of type bytes \
with kernel "${KERNEL}" \
--burn-cap 999
```
- `KERNEL` value is given here for testing:
```
0061736d0100000001280760037f7f7f017f60027f7f017f60057f7f7f7f7f017f60017f0060017f017f60027f7f0060000002610311736d6172745f726f6c6c75705f636f72650a726561645f696e707574000011736d6172745f726f6c6c75705f636f72650c77726974655f6f7574707574000111736d6172745f726f6c6c75705f636f72650b73746f72655f77726974650002030504030405060503010001071402036d656d02000a6b65726e656c5f72756e00060aa401042a01027f41fa002f0100210120002f010021022001200247044041e4004112410041e400410010021a0b0b0800200041c4006b0b5001057f41fe002d0000210341fc002f0100210220002d0000210420002f0100210520011004210620042003460440200041016a200141016b10011a0520052002460440200041076a200610011a0b0b0b1d01017f41dc0141840241901c100021004184022000100541840210030b0b38050041e4000b122f6b65726e656c2f656e762f7265626f6f740041f8000b0200010041fa000b0200020041fc000b0200000041fe000b0101
```
### Create your rollup config
Before running your own rollup node, you will need to initialize your rollup config.
```
octez-smart-rollup-node-alpha \
init operator config for "${SOR_ADDR}" \
with operators "${OPERATOR_ADDR}" \
--data-dir "${ROLLUP_NODE_DIR}"
```
- `SOR_ADDR` is the Smart Optimistic Rollup Address that was fetched from the origination
- `OPERATOR_ADDR` is the pkh of the operator with 10k tez mentioned above
- `ROLUP_NODE_DIR` is a directory that holds the rollup configs (create empty dir if it does not exist yet)
### Run your rollup node
```
octez-smart-rollup-node-alpha run --data-dir ${ROLLUP_NODE_DIR}
```
## Sending a message
Now that your rollup node is running, you can send messages to your inbox.
### Originate the contract you want to call using the message
```
octez-client originate contract go transferring 1 from ${OPERATOR_ADDRESS} \
running 'parameter string; storage string; code {CAR; NIL operation; PAIR};' \
--init '""' --burn-cap 0.4
```
### Create your message
```
export MESSAGE='[{"destination": ${CONTRACT_ADDRESS}, "parameters": "\"Hello world\"" }]'
```
- `CONTRACT_ADDRESS` being the originated contract address from the previous step
### Encode your message
```
${EMESSAGE} = octez-smart-rollup-client-alpha encode outbox message "${MESSAGE}"
```
### Send your message with the encoded value
```
octez-client send smart rollup message "hex:[ \"${EMESSAGE}\" ]" from ${OPERATOR_ADDRESS}
```
### Now we wait
We have to wait for a certain number of blocks until the commitment gets cemented
## Executing/Claiming your message
Users can claim/execute messages back to L1 with these following steps:
```
octez-smart-rollup-client-alpha rpc get /global/block/cemented/outbox/${L}/messages
```
- `${L}` being the block level of when the message was sent, if the message was posted on block level 2154 in L1, the value of `${L}` will be 2154
Given that the message have been cemented, you should receive something like this:
```
[ { "outbox_level": ${L}, "message_index": "0",
"message":
{ "transactions":
[ { "parameters": { "string": "Hello world" },
"destination": "${CONTRACT}",
"entrypoint": "default" } ] } } ]
```
You can now generate a PROOF to claim your message with, to do so, run this command:
```
octez-smart-rollup-client-alpha get proof for message 0 \
of outbox at level "${L}" \
transferring "${MESSAGE}"
```
You should receive a response with the proof and commitment hash:
```
({
"proof" : "0x0300026718c9790f206c92de4b9e262835b54d05d9555fd1ddb59560d6aa6d3d1b77b36718c9790f206c92de4b9e262835b54d05d9555fd1ddb59560d6aa6d3d1b77b30005820764757261626c65d07eb5216be3fcfd8317136e559c80d1a5eeb8f7b684c2101e92efb2b1b9c5324603746167c00800000004536f6d650003c04e858f0b7d90b5eb9638d03957ec7782ff88c9f2c31a58621e82e78da513950b820576616c7565810370766d8107627566666572738205696e707574820468656164c00100066c656e677468c00100066f75747075740004820132810a6c6173745f6c6576656cc004000008a00133810f76616c69646974795f706572696f64c00400013b0082013181086f7574626f786573003cc0d018bfed73aad0110856bc38a05d2476bd52b6ec22e54a9afbc9c6c46526de570018c0c53a91b3554c14bb637e598daef53bdf41af156d948d5c441777b3b8eba59f34000d0006c045f09576f62db5b49f69c62930c21aee3d6af79a8f3f57df0686f9f872360444820432313531820468656164c00100066c656e677468c0010004323135340003810468656164c001008208636f6e74656e7473810130c03a000000360000000031010000000b48656c6c6f20776f726c6401cc9e352a850d7475bf9b6cf103aa17ca404bc9dd000000000764656661756c74066c656e677468c00101c03ceb40b770400da6f400316be3a8baefcbdd9da012a557aea56505e61a99163c0134810d6d6573736167655f6c696d6974c002a401047761736dd0ed4f88f12b7f1b89febb63882252041d1bd824f905dab029228b455992935d846718c9790f206c92de4b9e262835b54d05d9555fd1ddb59560d6aa6d3d1b77b30000086a000000000031010000000b48656c6c6f20776f726c6401cc9e352a850d7475bf9b6cf103aa17ca404bc9dd000000000764656661756c74",
"commitment_hash" : "src12phyxBfFaSwpaXStnEk9NNqh8vqDPy96SDxJwmZnKYDzh1Zzax"
})
```
With the proof and commitment_hash, you can now **execute** the message:
```
octez-client execute outbox message of smart rollup ${SMART_ROLLUP_ADDRESS} \
from ${OPERATOR_ADDRESS} for commitment hash ${COMMITMENT_HASH} \
and output proof ${PROOF}
```
## Conclusion and findings
- Messages being posted usually represent L1 contract calls. This use case might be expanded in the future
- The most common use case of a rollup node is that users can post messages from L1 to the rollup node (L2) to eventually be claimed back to L1; reducing the direct load on L1, allowing the chain to scale transactions
- To claim/execute a message, you first need to generate a proof and a commitment hash to verify that your messages are, in fact, correct and unrefuted
- The refutation period (challenge window) N is not the most number of blocks that someone needs to wait in order for a message to get cemented, it is actually more like `M+N`
- `M` being the `smart_rollup_commitment_period_in_blocks`
- `N` being the `smart_rollup_challenge_window_in_blocks`