# Cartesi research
# Summary
Cartesi 是一個 Modular Execution Layer,主打以下特點
- App-sepecific
- Linux runtime (RISC-V) ,可以做到 CPU 的完全運算,不用與他人競爭算力(可預測且穩定的 Fee)
- 可以採用各種不同的語言來實作 Dapp
- Cartesi 捨棄掉了 Global consensus
- 由利益相關方來進行 Dapp 相關的密集運算(建立專屬節點?)
- 每個驗證者可以只去驗證你所關心的部分
- https://www.youtube.com/watch?v=2kWeNZD9uf0
# Architecture
## Dapp
一個 Dapp 的組成有 frontend 跟 backend
整個流程就是前端向 base layer 的 `InputBox` 傳送 bytes 訊息,後端會去讀取 bytes 訊息,後端透過 HTTPs 讀取,並將讀取到的狀態在後端做更新
- `InputBox` 接受 Generic 的 input,其他 asset 的轉移要通過 `portal`


### Backend
Backend 的背後是 Cartesi Machine,由 RISC-V 組成,就像一般的 Linux 電腦一樣,負責跟 base layer 的 smart contract 互動(嚴格來說,與鏈上互動是由 Cartesi Node 處理)
功能如下:
- advance -> 改變後端狀態
- inspect -> 前端 query 資料
### Frontend
- Frontend 負責傳送 advanced request 給 base layer,用於更新狀態
- 從後端讀取資料
簡而言之,**寫入資料到鏈上,讀取資料從鏈下 (Cartesi Rollup Node)**
## Node
ref: https://github.com/cartesi/rollups-node?tab=readme-ov-file
### Inspect / Advance

上圖為 Node 架構圖 (advance flow),Cartesi Rollup Node 是一層 on-chain 與 off-chain 的中間層,負責監聽鏈上資訊,以及回傳資訊給位於 Cartesi Machine 之中的 backend
### Validate

在每個 epoch 結束時,node 會將 claim (proof) 上傳到 on-chain contract,接著前端可以去驗證這個 proof
> note: 注意,現在的 proof 提交沒辦法進行 dispute,這是未來會增加的功能,用來保證 proof 的正確性
demo : https://github.com/LI-YONG-QI/cartesi-ts-dapp
---
# 個人想法(問題)
架構概念有趣,跳脫一般 VM 的限制,來達到更多計算能力跟功能的擴充,類似於鏈上鏈下混合架構,有點像是 Farcaster 的 p2p 網路,但是跟鏈上的整合度更高,這種架構的設計,有利於未來高吞吐量的應用,例如 on-chain game / social platform
缺點是後端改變狀態的 function,需要透過前端的合約去觸發,如果用來觸發的交易遲遲沒有被打包,那麼後端也不會有所改變,也就是說,後端還是跟 base layer 的吞吐量有所關係,並沒有官方講的 full-compute power 那麼美好
## Questions
- 為什麼 Ethereum 會需要彼此競爭運算能力?
- 因為 Ethereum 需要將每筆交易都放到節點中運算,如果有某筆交易的運算量特別大,那麼可能就會導致網路堵塞
- Cartesi 如何具體解決以上問題?
- Cartesi 的節點沒有全域的驗證概念,每個節點只需要負責維護該 Dapp 的狀態
- Cartesi Rollup framework 是什麼?
- 一個包含 backend / Cartesi Machine / Rollup HTTP server 的框架
- Cartesi Machine 包含了 backend logic
- Cartesi 推測還是有一層執行層在,但這樣與一般的 L2 哪裡不同?
- 這個執行層可以想像是一個只服務特定 Dapp 的 Node 組成 (backend),不像一般的 L2 Node 需要服務給整個 L2 上的交易
- 如果 advance 需要送 input 給 base layer,等於說 backend 還是會被這筆 input 交易接受速度影響嗎?那這樣官方強調的速度跟運算能力是不是不完全對?
- 是的,官方回覆 
- 如果挑選的 base layer 遲遲不接受 `addInput`的交易,那麼後端也不會更新狀態
- 也就是說 **blockchain** 本身的阻塞還是會影響到 Cartesi
- Cartesi Rollups Node 可以是很多個嗎?且多個 node 之間的 verify 就是 optimistic
- 官方回答 
- 在未來計畫,現在還沒實作
- Validate 當中提到的 epoch 是什麼?
---
# Highlight

# Overview | Cartesi Documentation
Welcome to Cartesi Rollups, where decentralized application development meets unprecedented flexibility. With a foundation built on the Linux operating system, Cartesi Rollups offers modular stacks that allow developers to tailor consensus, data availability, and settlement layers according to their project requirements.
🌐 https://docs.cartesi.io/cartesi-rollups/1.3/
🔗 https://app.web-highlights.com/page/66994e9893a2a63e66acf6ab
**Tags**: -
**Highlights & Notes**
> Cartesi Rollup executes the Cartesi Machine - a robust RISCV deterministic emulator running Linux OS - fueled by ordered inputs and custom application code.
> Inputs sourced from the data availability layer are read by the Cartesi Node
> The Cartesi Rollup framework is application-specific, assigning each dApp its rollup app chain and CPU while linking its optimistic rollups' consensus directly to the base layer
> . Transactions are directed to specific smart contracts where DApp code is executed to produce outputs on the base layer after a verification period.
> all inputs sent to the base layer trigger an "advance_state" request, which alters the state of the Cartesi Machine and consequently the Rollup
---

# cartesi/rollups-node: Reference implementation of the Cartesi Rollups Node
🌐 https://github.com/cartesi/rollups-node
🔗 https://app.web-highlights.com/page/66a88986eb18eb4099048e60
**Tags**: -
**Highlights & Notes**
> Cartesi Rollups Node is the middleware that connects the Rollups smart contracts, the application back-end running inside the Cartesi Machine,
> the Node reads the advance-state inputs from the smart contracts, sends those inputs to the Cartesi Machine, and stores the computation outputs in a database
> . Since the Node only supports the Authority consensus mechanism, it is up to the Node to decide when it should close an epoch.
> Only the validator can submit a claim to the Rollups smart contracts.
指定 Validator