Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
chudkowsky committed Oct 9, 2024
1 parent f2136f9 commit f5a9e80
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 58 deletions.
2 changes: 1 addition & 1 deletion bin/saya/src/args/settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::str::FromStr;

use clap::builder::PossibleValue;
use clap::{Args, ValueEnum};
use starknet::core::types::Felt;
use saya_core::SayaMode;
use starknet::core::types::Felt;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SayaModeArg(pub SayaMode);
Expand Down
2 changes: 1 addition & 1 deletion bin/scheduler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use std::fs;
use std::sync::Arc;

use clap::Parser;
use starknet::core::types::Felt;
use saya_core::prover::{HttpProverParams, ProgramInput};
use saya_core::ProverAccessKey;
use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use starknet::core::types::Felt;
use tokio::fs::File;
use tokio::io::AsyncWriteExt;

Expand Down
27 changes: 14 additions & 13 deletions crates/saya/core/src/dojo_os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ use std::time::Duration;

use dojo_utils::{TransactionExt, TxnConfig};
use itertools::chain;
use starknet::accounts::{Account,ConnectedAccount};
use starknet::core::types::Call;
use starknet::core::types::{Felt, TransactionExecutionStatus, TransactionStatus};
use starknet::accounts::{Account, ConnectedAccount};
use starknet::core::types::{Call, Felt, TransactionExecutionStatus, TransactionStatus};
use starknet::core::utils::get_selector_from_name;
use starknet::providers::Provider;
use tokio::time::sleep;
use tracing::trace;

use crate::{error::Error, SayaStarknetAccount};
use crate::{retry, LOG_TARGET};
use crate::error::Error;
use crate::{retry, SayaStarknetAccount, LOG_TARGET};

pub async fn starknet_apply_diffs(
world: Felt,
Expand All @@ -41,14 +40,16 @@ pub async fn starknet_apply_diffs(
.collect();

let txn_config = TxnConfig { wait: true, receipt: true, ..Default::default() };
let tx = retry!(account
.execute_v1(vec![Call {
to: world,
selector: get_selector_from_name("upgrade_state").expect("invalid selector"),
calldata: calldata.clone(),
}])
.nonce(nonce)
.send_with_cfg(&txn_config))
let tx = retry!(
account
.execute_v1(vec![Call {
to: world,
selector: get_selector_from_name("upgrade_state").expect("invalid selector"),
calldata: calldata.clone(),
}])
.nonce(nonce)
.send_with_cfg(&txn_config)
)
.map_err(|e| Error::TransactionFailed(e.to_string()))?;

let start_fetching = std::time::Instant::now();
Expand Down
18 changes: 10 additions & 8 deletions crates/saya/core/src/dojo_os/piltover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ pub async fn starknet_apply_piltover(
let txn_config = TxnConfig { wait: true, receipt: true, ..Default::default() };
let calldata = to_felts(&calldata)?;
trace!(target: LOG_TARGET, "Sending `update_state` piltover transaction to contract {:#x}", contract);
let tx = retry!(account
.execute_v1(vec![Call {
to: contract,
selector: get_selector_from_name("update_state").expect("invalid selector"),
calldata: calldata.clone()
}])
.nonce(nonce)
.send_with_cfg(&txn_config))
let tx = retry!(
account
.execute_v1(vec![Call {
to: contract,
selector: get_selector_from_name("update_state").expect("invalid selector"),
calldata: calldata.clone()
}])
.nonce(nonce)
.send_with_cfg(&txn_config)
)
.map_err(|e| ProverError::SendTransactionError(e.to_string()))?;
trace!(target: LOG_TARGET, "Sent `update_state` piltover transaction {:#x}", tx.transaction_hash);
wait_for_sent_transaction(tx, account).await?;
Expand Down
9 changes: 5 additions & 4 deletions crates/saya/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ use saya_provider::rpc::JsonRpcProvider;
use saya_provider::Provider as SayaProvider;
use serde::{Deserialize, Serialize};
use starknet::accounts::{ExecutionEncoding, SingleOwnerAccount};
use starknet::core::types::Call;
use starknet::core::types::{BlockId, BlockTag};
use starknet::core::types::{BlockId, BlockTag, Call};
use starknet::core::utils::cairo_short_string_to_felt;
use starknet::providers::jsonrpc::HttpTransport;
use starknet::providers::JsonRpcClient;
Expand Down Expand Up @@ -469,7 +468,8 @@ impl Saya {
proof: serde_json::to_value(&proof.proof).unwrap(),
};
// let ns = Namespace::new_v0(b"saya-dev").unwrap();
// let commitment = Commitment::from_blob(ns, 0, &serialized_proof.iter().map(|felt| felt.to_bytes()).collect::<Vec<_>>());
// let commitment = Commitment::from_blob(ns, 0, &serialized_proof.iter().map(|felt|
// felt.to_bytes()).collect::<Vec<_>>());
let (commitment, height) = if self.config.mode != SayaMode::Ephemeral {
da.publish_checkpoint(checkpoint).await?
} else if self.config.skip_publishing_proof {
Expand Down Expand Up @@ -518,7 +518,8 @@ impl Saya {
let serialized_output = program_output.iter().copied().collect_vec();
println!("serialized_output: {:?}", serialized_output);

// todo!("Persistent mode does not support publishing updated state with SNOS yet.");
// todo!("Persistent mode does not support publishing updated state with SNOS
// yet.");

let deduplicated_output =
serialized_output[1..serialized_output.len() / 2].to_vec();
Expand Down
3 changes: 2 additions & 1 deletion crates/saya/core/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ macro_rules! retry {

loop {
match $func.await {
Ok(result) => break Ok(result), // If the function succeeds, break the loop and return the result
Ok(result) => break Ok(result), /* If the function succeeds, break the loop and
* return the result */
Err(err) => {
tracing::warn!("Error: {}", err);

Expand Down
6 changes: 3 additions & 3 deletions crates/saya/core/src/prover/client.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::sync::Arc;

use cairo1_playground::get_cairo_pie;
use herodotus_sharp_playground::SharpSdk;
use prover_sdk::access_key::ProverAccessKey;
use prover_sdk::errors::SdkErrors;
use prover_sdk::sdk::ProverSDK;
use prover_sdk::{JobResponse, ProverResult};
use starknet::core::types::Felt;
use std::sync::Arc;
use tracing::trace;
use url::Url;

use crate::error::ProverError;

use super::loader::{load_program, prepare_input_cairo};
use super::ProveProgram;
use crate::error::ProverError;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HttpProverParams {
Expand Down
5 changes: 2 additions & 3 deletions crates/saya/core/src/prover/loader.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use prover_sdk::CairoProverInput;
use std::env;
use std::path::PathBuf;

use prover_sdk::CairoProverInput;
use serde_json::Value;
use starknet_crypto::Felt;
use tokio::fs::File;
use tokio::io::AsyncReadExt;

use crate::error::ProverError;

use super::ProveProgram;
use crate::error::ProverError;

pub async fn load_program(prove_program: ProveProgram) -> Result<Value, ProverError> {
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?);
Expand Down
5 changes: 2 additions & 3 deletions crates/saya/core/src/prover/program_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use katana_primitives::transaction::{L1HandlerTx, TxHash};
use katana_rpc_types::trace::TxExecutionInfo;
use serde::ser::{SerializeSeq, Serializer};
use serde::{Deserialize, Deserializer, Serialize};
use starknet::core::types::Call;
use starknet::core::types::Felt;
use starknet::core::types::{Call, Felt};

/// Based on https://github.com/cartridge-gg/piltover/blob/2be9d46f00c9c71e2217ab74341f77b09f034c81/src/snos_output.cairo#L19-L20
/// With the new state root computed by the prover.
Expand Down Expand Up @@ -208,7 +207,7 @@ impl ProgramInput {

updates
}
//TODO: change to use cainome/serde_felt
// TODO: change to use cainome/serde_felt
fn serialize_to_prover_args(&self) -> Vec<Felt> {
let mut out = vec![
self.prev_state_root,
Expand Down
3 changes: 2 additions & 1 deletion crates/saya/core/src/verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
use ::starknet::core::types::Felt;
use serde::{Deserialize, Serialize};

use crate::{error::Error, SayaStarknetAccount};
use crate::error::Error;
use crate::SayaStarknetAccount;

mod starknet;
pub mod utils;
Expand Down
41 changes: 22 additions & 19 deletions crates/saya/core/src/verifier/starknet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use std::vec;
use dojo_utils::{TransactionExt, TxnConfig};
use itertools::Itertools;
use starknet::accounts::{Account, ConnectedAccount};
use starknet::core::types::Call;
use starknet::core::types::Felt;
use starknet::core::types::{Call, Felt};
use starknet::core::utils::get_selector_from_name;
use starknet_crypto::poseidon_hash_many;
use tokio::time::sleep;
Expand Down Expand Up @@ -40,14 +39,16 @@ pub async fn starknet_verify(
let hash = poseidon_hash_many(&fragment);
hashes.push(hash);
fragment.insert(0, fragment.len().into());
let tx = retry!(account
.execute_v1(vec![Call {
to: fact_registry_address,
selector: get_selector_from_name("publish_fragment").expect("invalid selector"),
calldata: fragment.clone(),
}])
.nonce(nonce)
.send_with_cfg(&txn_config))
let tx = retry!(
account
.execute_v1(vec![Call {
to: fact_registry_address,
selector: get_selector_from_name("publish_fragment").expect("invalid selector"),
calldata: fragment.clone(),
}])
.nonce(nonce)
.send_with_cfg(&txn_config)
)
.map_err(|e| ProverError::SendTransactionError(e.to_string()))?;

wait_for_sent_transaction(tx.clone(), account).await?;
Expand All @@ -66,15 +67,17 @@ pub async fn starknet_verify(
sleep(Duration::from_secs(2)).await;
let nonce = account.get_nonce().await?;

let tx = retry!(account
.execute_v1(vec![Call {
to: fact_registry_address,
selector: get_selector_from_name("verify_and_register_fact_from_fragments")
.expect("invalid selector"),
calldata: calldata.clone(),
}])
.nonce(nonce)
.send_with_cfg(&txn_config))
let tx = retry!(
account
.execute_v1(vec![Call {
to: fact_registry_address,
selector: get_selector_from_name("verify_and_register_fact_from_fragments")
.expect("invalid selector"),
calldata: calldata.clone(),
}])
.nonce(nonce)
.send_with_cfg(&txn_config)
)
.map_err(|e| ProverError::SendTransactionError(e.to_string()))?;

let transaction_hash = format!("{:#x}", tx.transaction_hash);
Expand Down
3 changes: 2 additions & 1 deletion crates/saya/core/src/verifier/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::time::Duration;

use starknet::accounts::ConnectedAccount;
use starknet::core::types::{
InvokeTransactionResult, TransactionExecutionStatus, TransactionStatus,
};
use starknet::providers::Provider;
use std::time::Duration;
use tokio::time::sleep;
use tracing::trace;

Expand Down

0 comments on commit f5a9e80

Please sign in to comment.