Skip to content

Commit aec3204

Browse files
authored
feat(sozo): add support for blake2s casm class hashing (#3377)
* wip: may not need to bump starknet-rs at all... * fix: use latest block for most operations since block time is now very small * fix migration on pre confirmed and update dependencies * fix: add a flag to override blake2s usage * docs: update comment regarding the block tag chosen
1 parent 3a1970e commit aec3204

File tree

33 files changed

+1782
-467
lines changed

33 files changed

+1782
-467
lines changed

Cargo.lock

Lines changed: 1559 additions & 311 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ debug = true
5353
inherits = "release"
5454

5555
[workspace.dependencies]
56-
cainome = { version = "0.10.1", features = [ "abigen-rs" ] }
57-
cainome-cairo-serde = { version = "0.4.1" }
56+
cainome = { git = "https://github.com/cartridge-gg/cainome", branch = "types-rs-100-blake2s", features = [ "abigen-rs" ] }
57+
cainome-cairo-serde = { git = "https://github.com/cartridge-gg/cainome", branch = "types-rs-100-blake2s" }
5858

5959
dojo-utils = { path = "crates/dojo/utils" }
6060

@@ -80,9 +80,9 @@ sozo-walnut = { path = "crates/sozo/walnut" }
8080
merge-options = { path = "crates/macros/merge-options" }
8181

8282
# On the branch to support rpc 0.9 (incl starknet bump)
83-
katana-runner = { git = "https://github.com/dojoengine/katana", rev = "eba352a" }
83+
katana-runner = { git = "https://github.com/dojoengine/katana", branch = "types-rs-100-blake2s" }
8484

85-
anyhow = "1.0.89"
85+
anyhow = "1"
8686
arbitrary = { version = "1.3.2", features = [ "derive" ] }
8787
assert_fs = "1.1"
8888
assert_matches = "1.5.0"
@@ -91,7 +91,7 @@ auto_impl = "1.2.0"
9191
base64 = "0.21.2"
9292
bigdecimal = "0.4.1"
9393
bytes = "1.6"
94-
cairo-lang-starknet-classes = "2.13.1"
94+
cairo-lang-starknet-classes = "=2.13.1"
9595
camino = { version = "1.1.2", features = [ "serde1" ] }
9696
chrono = { version = "0.4.24", features = [ "serde" ] }
9797
clap = { version = "4.5.16", features = [ "derive", "env", "string" ] }
@@ -138,14 +138,13 @@ salsa = "0.16.1"
138138
scarb-metadata = "1.15.1"
139139
semver = "1.0.5"
140140
serde = { version = "1.0", features = [ "derive" ] }
141-
serde_json = { version = "1.0.142", features = [ "arbitrary_precision" ] }
141+
serde_json = { version = "1", features = [ "arbitrary_precision" ] }
142142
serde_with = "3.11.0"
143143
similar-asserts = "1.5.0"
144144
smol_str = { version = "0.3", features = [ "serde" ] }
145145
spinoff = "0.8.0"
146146
sqlx = { version = "0.8.2", features = [ "chrono", "macros", "regexp", "runtime-async-std", "runtime-tokio", "sqlite", "uuid" ] }
147-
#starknet_api = "0.11.0"
148-
starknet_api = { git = "https://github.com/dojoengine/sequencer", rev = "802c5dc" }
147+
starknet_api = "0.16.0-rc.1"
149148
strum = "0.25"
150149
strum_macros = "0.25"
151150
tempfile = "3.9.0"
@@ -169,12 +168,10 @@ mime_guess = "2.0"
169168
hyper = "1.5"
170169
warp = "0.3"
171170

172-
# Slot integration. Dojo don't need to manually include `account_sdk` as dependency as `slot` already re-exports it.
173-
slot-core = { git = "https://github.com/cartridge-gg/slot", branch = "compartmentalization" }
174-
slot-session = { git = "https://github.com/cartridge-gg/slot", branch = "compartmentalization" }
171+
slot = { git = "https://github.com/cartridge-gg/slot", branch = "types-rs-100-blake2s" }
175172

176-
starknet = "0.17"
177-
starknet-crypto = "0.8"
178-
starknet-types-core = { version = "0.2", features = [ "arbitrary", "hash" ] }
173+
starknet = { git = "https://github.com/dojoengine/starknet-rs", branch = "feat/types-rs-100-blake2s" }
174+
starknet-crypto = { git = "https://github.com/dojoengine/starknet-rs", branch = "feat/types-rs-100-blake2s" }
175+
starknet-types-core = { version = "1.0.0", features = [ "arbitrary", "hash" ] }
179176

180177
bitvec = "1.0.1"

bin/sozo/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ version.workspace = true
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
slot-core = { workspace = true, optional = true }
10-
slot-session = { workspace = true, optional = true }
9+
slot = { workspace = true, optional = true }
1110

1211
anyhow.workspace = true
1312
async-trait.workspace = true
@@ -54,7 +53,7 @@ serde_json.workspace = true
5453
[features]
5554
default = [ "controller", "walnut" ]
5655

57-
controller = [ "dep:slot-core", "dep:slot-session" ]
56+
controller = [ "dep:slot" ]
5857
walnut = [ "dep:sozo-walnut", "sozo-ops/walnut" ]
5958

6059
[[bench]]

bin/sozo/src/commands/build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,16 @@ impl BuildArgs {
129129
// directly during the compilation to get the data we need from it.
130130
bindgen.generate(None).await?;
131131

132+
// During the build, the class hashes are not used. Set to true as default since it
133+
// will be the standard once 0.14.1 hits mainnet.
134+
let use_blake2s_casm_class_hash = true;
135+
132136
if self.stats != StatOptions::default() {
133137
let world = WorldLocal::from_directory(
134138
scarb_metadata.target_dir_profile(),
135139
&scarb_metadata.current_profile,
136140
scarb_metadata.load_dojo_profile_config().unwrap(),
141+
use_blake2s_casm_class_hash,
137142
)?;
138143

139144
let world_stat = world.to_stat_item();

bin/sozo/src/commands/events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ async fn match_event<P: Provider + Send + Sync>(
178178
let block_id = if let Some(block_number) = block_number {
179179
BlockId::Number(block_number)
180180
} else {
181-
BlockId::Tag(BlockTag::PreConfirmed)
181+
BlockId::Tag(BlockTag::Latest)
182182
};
183183

184184
let (name, content) = match event {

bin/sozo/src/commands/options/account/controller.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ use std::collections::HashMap;
22

33
use anyhow::{bail, Result};
44
use dojo_world::contracts::contract_info::ContractInfo;
5-
use slot_session::account_sdk::account::session::account::SessionAccount;
6-
use slot_session::account_sdk::account::session::merkle::MerkleTree;
7-
use slot_session::account_sdk::account::session::policy::{
8-
CallPolicy, MerkleLeaf, Policy, ProvedPolicy,
9-
};
10-
use slot_session::account_sdk::provider::CartridgeJsonRpcProvider;
11-
use slot_session::{FullSessionInfo, PolicyMethod};
5+
use slot::account_sdk::account::session::account::SessionAccount;
6+
use slot::account_sdk::account::session::merkle::MerkleTree;
7+
use slot::account_sdk::account::session::policy::{CallPolicy, MerkleLeaf, Policy, ProvedPolicy};
8+
use slot::account_sdk::provider::CartridgeJsonRpcProvider;
9+
use slot::session::{FullSessionInfo, PolicyMethod};
1210
use starknet::core::types::Felt;
1311
use starknet::core::utils::get_selector_from_name;
1412
use starknet::macros::felt;
@@ -40,7 +38,7 @@ pub async fn create_controller(
4038
let chain_id = rpc_provider.chain_id().await?;
4139

4240
trace!(target: "account::controller", "Loading Slot credentials.");
43-
let credentials = slot_core::credentials::Credentials::load()?;
41+
let credentials = slot::credential::Credentials::load()?;
4442
let username = credentials.account.id;
4543

4644
// Right now, the Cartridge Controller API ensures that there's always a Controller associated
@@ -52,7 +50,7 @@ pub async fn create_controller(
5250
let policies = collect_policies(contract_address, contracts)?;
5351

5452
// Check if the session exists, if not create a new one
55-
let session_details = match slot_session::get(chain_id)? {
53+
let session_details = match slot::session::get(chain_id)? {
5654
Some(session) => {
5755
trace!(target: "account::controller", expires_at = %session.session.inner.expires_at, policies = session.session.proved_policies.len(), "Found existing session.");
5856

@@ -69,17 +67,17 @@ pub async fn create_controller(
6967
"Policies have changed. Creating new session."
7068
);
7169

72-
let session = slot_session::create(rpc_url.clone(), &policies).await?;
73-
slot_session::store(chain_id, &session)?;
70+
let session = slot::session::create(rpc_url.clone(), &policies).await?;
71+
slot::session::store(chain_id, &session)?;
7472
session
7573
}
7674
}
7775

7876
// Create a new session if not found
7977
None => {
8078
trace!(target: "account::controller", %username, chain = format!("{chain_id:#}"), "Creating new session.");
81-
let session = slot_session::create(rpc_url.clone(), &policies).await?;
82-
slot_session::store(chain_id, &session)?;
79+
let session = slot::session::create(rpc_url.clone(), &policies).await?;
80+
slot::session::store(chain_id, &session)?;
8381
session
8482
}
8583
};

bin/sozo/src/commands/options/account/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use dojo_utils::env::DOJO_ACCOUNT_ADDRESS_ENV_VAR;
88
use dojo_world::config::Environment;
99
use dojo_world::contracts::ContractInfo;
1010
#[cfg(feature = "controller")]
11-
use slot_session::account_sdk::provider::CartridgeJsonRpcProvider;
11+
use slot::account_sdk::provider::CartridgeJsonRpcProvider;
1212
use starknet::accounts::{ExecutionEncoding, SingleOwnerAccount};
1313
use starknet::core::types::{BlockId, BlockTag, Felt};
1414
use starknet::providers::Provider;
@@ -130,9 +130,9 @@ impl AccountOptions {
130130
let mut account =
131131
SingleOwnerAccount::new(provider, signer, account_address, chain_id, encoding);
132132

133-
// The default is `Latest` in starknet-rs, which does not reflect
134-
// the nonce changes in the pending block.
135-
account.set_block_id(BlockId::Tag(BlockTag::PreConfirmed));
133+
// Since now the block frequency is higher than before, using latest is
134+
// totally fine. We keep it explicitely set here to easy toggle if necessary.
135+
account.set_block_id(BlockId::Tag(BlockTag::Latest));
136136
Ok(account)
137137
}
138138

bin/sozo/src/commands/options/account/type.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::Arc;
22

33
use async_trait::async_trait;
44
#[cfg(feature = "controller")]
5-
use slot_session::account_sdk::provider::CartridgeJsonRpcProvider;
5+
use slot::account_sdk::provider::CartridgeJsonRpcProvider;
66
use starknet::accounts::{
77
single_owner, Account, ConnectedAccount, ExecutionEncoder, RawDeclarationV3, RawExecutionV3,
88
SingleOwnerAccount,
@@ -28,7 +28,7 @@ pub enum SozoAccountSignError {
2828

2929
#[cfg(feature = "controller")]
3030
#[error(transparent)]
31-
Controller(#[from] slot_session::account_sdk::signers::SignError),
31+
Controller(#[from] slot::account_sdk::signers::SignError),
3232
}
3333

3434
/// To unify the account types, we define a wrapper type that implements the

bin/sozo/src/commands/options/starknet.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ pub struct StarknetOptions {
1818
#[arg(help = "The Starknet RPC endpoint.")]
1919
#[arg(global = true)]
2020
pub rpc_url: Option<Url>,
21+
22+
#[arg(long, default_value = "false")]
23+
#[arg(help = "Whether to use the blake2s class hash, which is currently required for \
24+
Sepolia. Sozo will attempt to detect the chain id from the rpc url and set \
25+
this flag automatically if the RPC URL contains `sepolia` or `testnet`. \
26+
Otherwise, use this flag to manually set it.")]
27+
#[arg(global = true)]
28+
pub use_blake2s_casm_class_hash: bool,
2129
}
2230

2331
impl StarknetOptions {

bin/sozo/src/commands/options/transaction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ pub struct TransactionOptions {
6767
#[arg(long)]
6868
#[arg(help = "The finality status to wait for. Since 0.14, the nodes syncing is sometime \
6969
not fast enough to propagate the transaction to the nodes in the \
70-
PRE-CONFIRMED state. The default is ACCEPTED_ON_L2. Available options are: \
71-
PRE-CONFIRMED, ACCEPTED_ON_L2, ACCEPTED_ON_L1.")]
70+
PRE_CONFIRMED state. The default is ACCEPTED_ON_L2. Available options are: \
71+
PRE_CONFIRMED, ACCEPTED_ON_L2, ACCEPTED_ON_L1.")]
7272
#[arg(global = true)]
7373
#[arg(default_value = "ACCEPTED_ON_L2")]
7474
pub finality_status: Option<String>,

0 commit comments

Comments
 (0)