Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update to katana-compatible snos #6

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
741 changes: 395 additions & 346 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ hex = { version = "0.4.3", default-features = false }
integrity = { version = "0.1.0", default-features = false, features = ["recursive_with_poseidon", "keccak_160_lsb", "stone6"] }
log = "0.4.22"
num-traits = { version = "0.2.19", default-features = false }
prove_block = { git = "https://github.com/keep-starknet-strange/snos", rev = "e4599fe" }
prove_block = { git = "https://github.com/cartridge-gg/snos", rev = "7183af4" }
reqwest = { version = "0.12.12", default-features = false, features = ["json", "multipart", "rustls-tls"] }
serde = { version = "1.0.217", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.134", default-features = false }
Expand Down
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,33 @@

Saya is a settlement service for Katana.

## Katana provable mode

Katana must be running in provable mode to be proven by Saya.

Use this [PR](https://github.com/dojoengine/dojo/pull/2980) for the latest Katana changes related to provable mode.

1. Use `katana init` CLI interface to setup the chain spec, the questions will be:
```
# A chain ID (short string).
> Id <CHAIN_ID>

# Currently only Sepolia supported.
> Settlement chain Sepolia

# Account to deploy appchain core contract and associated private key.
> Account
> Private key

# Answer `Yes` to automatically deploy the settlement contract and setup it's configuration:
✓ Deployment successful (0x391401b25a12e821e12b3e0992c5e98822b07dc11e17ba2e8dfff27ba180564)
```
2. `katana init` generates a directory with configuration file and genesis block. Use `katana init --show-config <CHAIN_ID>` to display the configuration file path if you want to inspect it.
3. Start Katana with `katana --chain <CHAIN_ID>` to load the generated parameters at start.

## Requirements

- Katana up and running in provable mode (run `katana init` to generate the chain spec, and then start katana with `katana --chain <CHAIN_ID>` to load the generated parameters).
- Katana up and running in provable mode.
- Herodotus Dev account with API key, which can be obtained from https://staging.dashboard.herodotus.dev.

### Sovereign mode
Expand Down
2 changes: 1 addition & 1 deletion bin/saya/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async fn main() -> Result<()> {
let cli = Cli::parse();

if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "info,saya=debug,saya_core=debug");
std::env::set_var("RUST_LOG", "info,saya=debug,saya_core=debug,rpc_client=off");
}
env_logger::init();

Expand Down
9 changes: 9 additions & 0 deletions saya/core/src/orchestrator/persistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,17 @@ where
.build()
.await
.unwrap();

// Since the `Felt` type is wrapping (`Felt::MAX + 1 = 0`), there is not
// need for a special case for the genesis block, and `+1` works as expected.
//
// TODO: should we change to `settlement.next_block_number()` instead to always return `u64`?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xJonathanLEI I would tend to add the new method, or always manipulating the block number as a Felt, wdyt?

let start_block = settlement.get_block_number().await? + 1;

// Now that the special value of `Felt::MAX` is handled, we can use the block number as `u64`.
let start_block: u64 = start_block.try_into()?;
dbg!(start_block);

let ingestor = self
.ingestor_builder
.start_block(start_block)
Expand Down
5 changes: 4 additions & 1 deletion saya/core/src/settlement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ pub trait SettlementBackendBuilder {
}

pub trait SettlementBackend: Daemon {
fn get_block_number(&self) -> impl Future<Output = Result<u64>> + Send;
/// Gets the block number of the last block verified by the settlement layer.
///
/// It returns a `Felt` since the previous block value for genesis block is `Felt::MAX`.
fn get_block_number(&self) -> impl Future<Output = Result<Felt>> + Send;
}

// TODO: abstract over this to allow other settlement backends.
Expand Down
4 changes: 2 additions & 2 deletions saya/core/src/settlement/piltover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct PiltoverSettlementBackendBuilder {
struct AppchainState {
#[allow(unused)]
state_root: Felt,
block_number: u64,
block_number: Felt,
#[allow(unused)]
block_hash: Felt,
}
Expand Down Expand Up @@ -342,7 +342,7 @@ impl SettlementBackendBuilder for PiltoverSettlementBackendBuilder {
}

impl SettlementBackend for PiltoverSettlementBackend {
async fn get_block_number(&self) -> Result<u64> {
async fn get_block_number(&self) -> Result<Felt> {
let appchain_state = self.get_state().await?;
Ok(appchain_state.block_number)
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate_layout_bridge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
REPO_ROOT=$( dirname -- $SCRIPT_DIR )

CAIRO_VERSION="0.13.3"
COMPILER_VERSION="0.13.2"
COMPILER_VERSION="0.13.3"

mkdir -p $REPO_ROOT/programs

Expand Down