# Saya Settlement This document describes the implementation of `Saya`, an addition to the Dojo toolchain, which serves to settle Katana sequencers to a settlement layer. The document consists of several phases, progressively extending the support for additional settlement chains and data availability providers. ![2023-11-28 12.09.32](https://hackmd.io/_uploads/S1WY5BQSp.jpg) ## Stage ### Generating the trace and state diff This initial task entails the scaffolding of the Saya service. A rust service that runs along side a Katana instance. Saya is responsible for pulling blocks from Katana, executing them and generating the corresponding execution trace and state diff. This should probably extend [the existing SNOS implementation](https://github.com/keep-starknet-strange/snos/tree/lucas/continue). In order to generate the execution trace and state diff, the [Starknet OS](https://hackmd.io/YCwgt6NwRTyKgqc5UcSNHA) needs to be executed. There is an existing effort to support this for Madara. It expects [the following input](https://github.com/keep-starknet-strange/snos/blob/f584818cfb3b4c58aa85b4a2879d248e553b6c29/src/io/mod.rs#L17-L34): ```rs pub struct StarknetOsInput { pub contract_state_commitment_info: CommitmentInfo, pub contract_class_commitment_info: CommitmentInfo, pub deprecated_compiled_classes: HashMap<Felt252, DeprecatedContractClass>, pub compiled_classes: HashMap<Felt252, Felt252>, pub contracts: HashMap<Felt252, ContractState>, pub class_hash_to_compiled_class_hash: HashMap<Felt252, Felt252>, pub general_config: StarknetGeneralConfig, pub transactions: Vec<InternalTransaction>, pub block_hash: Felt252, } ``` This information should be exposed from Katana as necessary, potentially implementing new RPC endpoints if needed. It is worth an intial exploration into how Madara is planning to export this data. Currently, there are some limitations with Cairo VM which requires the legacy python Cairo VM in order to execute the Starknet OS, namely, cairo-vm cannot execute two or more Cairo programs using the same memory. This is something the Lambda team is working on. ### Fact registration on Starknet As an incremental step, we would like to support settling facts to Starknet with verification left to future work. To do so, we should port the existing [Solidity Fact Registry](https://etherscan.deth.net/address/0x92043f243831a9b0aF379F0BED8513fABDAbE513#code) into Cairo, deploy it to Starknet / Testnet, and implement logic in Saya to register facts. ### Verification on Starknet Onchain verification on Starknet is blocked by the Cairo verifier implementation work, currently underway by the Heredotus team. ### Verification on EVM chains Redeploy the Fact Regsitry and verifier stack to EVM chains. Create a simple to do so inside the Dojo repo. Update Saya to support settlment to EVM chains.