Skip to content

Commit

Permalink
Merge branch 'main' into feature/allow-unaccelerated-proving
Browse files Browse the repository at this point in the history
  • Loading branch information
koxu1996 authored Jul 26, 2024
2 parents fc35d21 + d53e3a4 commit 8079b75
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 61 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions kairos-cli/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::env;
use std::fs;
use std::path::Path;

fn main() {
// Path
let session_binaries_dir = env::var("PATH_TO_SESSION_BINARIES")
.expect("PATH_TO_SESSION_BINARIES environment variable is not set");

// Get the output directory set by Cargo.
let out_dir = env::var("OUT_DIR").expect("OUT_DIR not set");
let source_path = Path::new(&session_binaries_dir).join("deposit-session-optimized.wasm");
let dest_path = Path::new(&out_dir).join("deposit-session-optimized.wasm");

// Copy the file from the source to the destination
fs::copy(&source_path, dest_path).expect("Failed to copy WASM file");

// Print out a message to re-run this script if the source file changes.
println!("cargo:rerun-if-changed={}", source_path.display());
}
11 changes: 1 addition & 10 deletions kairos-cli/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use kairos_server::PublicKey;
use reqwest::Url;
use serde::{Deserialize, Serialize};
use std::fmt;
use std::fs;
use std::path::Path;

#[cfg(feature = "database")]
use kairos_data::transaction::{TransactionFilter, Transactions};
Expand Down Expand Up @@ -55,20 +53,13 @@ impl From<reqwest::Error> for KairosClientError {

pub fn deposit(
base_url: &Url,
deposit_session_wasm_bytes: &[u8],
depositor_secret_key: &SecretKey,
chain_name: &str,
contract_hash: &ContractHash,
amount: impl Into<U512>,
recipient: casper_client_types::PublicKey,
) -> Result<DeployHash, KairosClientError> {
let deposit_session_wasm_path =
Path::new(env!("PATH_TO_SESSION_BINARIES")).join("deposit-session-optimized.wasm");
let deposit_session_wasm_bytes = fs::read(&deposit_session_wasm_path).unwrap_or_else(|err| {
panic!(
"Failed to read the deposit session wasm as bytes from file: {:?}.\n{}",
deposit_session_wasm_path, err
)
});
let deposit_session = ExecutableDeployItem::new_module_bytes(
deposit_session_wasm_bytes.into(),
runtime_args! {
Expand Down
35 changes: 34 additions & 1 deletion kairos-cli/src/commands/deposit.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
use std::fs;
use std::path::PathBuf;

use crate::client;
use crate::common::args::{
AmountArg, ChainNameArg, ContractHashArg, PrivateKeyPathArg, RecipientArg,
};
use crate::error::CliError;

use casper_client_types::{crypto::SecretKey, ContractHash};
use clap::Parser;
use clap::{Args as ClapArgs, Parser};
use hex::FromHex;
use reqwest::Url;

use kairos_crypto::error::CryptoError;

const DEFAULT_DEPOSIT_SESSION_WASM: &[u8] =
include_bytes!(concat!(env!("OUT_DIR"), "/deposit-session-optimized.wasm"));

#[derive(Parser, Debug)]
pub struct Args {
#[clap(flatten)]
Expand All @@ -22,6 +28,8 @@ pub struct Args {
#[clap(flatten)]
recipient: RecipientArg,
#[clap(flatten)]
session_path: SessionPathArg,
#[clap(flatten)]
chain_name: ChainNameArg,
}

Expand All @@ -46,8 +54,21 @@ pub fn run(args: Args, kairos_server_address: Url) -> Result<String, CliError> {
Some(name) => name,
};

let deposit_session_wasm: Vec<u8> = match args.session_path.field {
Some(deposit_session_wasm_path) => {
fs::read(&deposit_session_wasm_path).unwrap_or_else(|err| {
panic!(
"Failed to read the deposit session wasm as bytes from file: {:?}.\n{}",
deposit_session_wasm_path, err
)
})
}
None => DEFAULT_DEPOSIT_SESSION_WASM.to_vec(),
};

client::deposit(
&kairos_server_address,
&deposit_session_wasm,
&depositor_secret_key,
&chain_name,
&contract_hash,
Expand All @@ -68,3 +89,15 @@ pub fn run(args: Args, kairos_server_address: Url) -> Result<String, CliError> {
output
})
}

#[derive(ClapArgs, Debug)]
pub struct SessionPathArg {
#[arg(
id = "session-path",
long,
short = 's',
value_name = "PATH",
help = "Path to the custom WASM session code for deposit"
)]
pub field: Option<PathBuf>,
}
10 changes: 5 additions & 5 deletions kairos-cli/src/commands/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ use chrono::NaiveDateTime;
pub struct Args {
#[arg(long, short, value_name = "PUBLIC_KEY_HEX")]
sender: Option<String>,
#[arg(long, short, value_name = "ISO8601_TIMESTAMP")]
#[arg(long, short = 't', value_name = "ISO8601_TIMESTAMP")]
min_timestamp: Option<NaiveDateTime>,
#[arg(long, short, value_name = "ISO8601_TIMESTAMP")]
#[arg(long, short = 'T', value_name = "ISO8601_TIMESTAMP")]
max_timestamp: Option<NaiveDateTime>,
#[arg(long, short, value_name = "NUM_MOTES")]
#[arg(long, short = 'm', value_name = "NUM_MOTES")]
min_amount: Option<u64>,
#[arg(long, short, value_name = "NUM_MOTES")]
#[arg(long, short = 'M', value_name = "NUM_MOTES")]
max_amount: Option<u64>,
#[arg(long, short, value_name = "PUBLIC_KEY_HEX")]
recipient: Option<String>,
#[arg(long, short, value_name = "TRANSACTION_TYPE", value_enum)]
#[arg(long, short = 'x', value_name = "TRANSACTION_TYPE", value_enum)]
transaction_type: Option<TransactionType>,
}

Expand Down
8 changes: 4 additions & 4 deletions kairos-cli/src/commands/run_cctl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::{Path, PathBuf};
use std::path::PathBuf;

use casper_client_types::{runtime_args, RuntimeArgs};
use kairos_test_utils::cctl::{CCTLNetwork, DeployableContract};
Expand All @@ -16,10 +16,10 @@ pub fn run() -> Result<String, CliError> {
path: contract_wasm_path,
};
println!("Deploying contract...");
let chainspec_path = Path::new(env!("CCTL_CHAINSPEC"));
let config_path = Path::new(env!("CCTL_CONFIG"));
let chainspec_path = PathBuf::from(std::env::var("CCTL_CHAINSPEC").unwrap());
let config_path = PathBuf::from(std::env::var("CCTL_CONFIG").unwrap());

let network = CCTLNetwork::run(None, Some(contract_to_deploy), Some(chainspec_path), Some(config_path))
let network = CCTLNetwork::run(None, Some(contract_to_deploy), Some(chainspec_path.as_path()), Some(config_path.as_path()))
.await
.unwrap();

Expand Down
4 changes: 2 additions & 2 deletions kairos-contracts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions kairos-data/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub async fn get(
let mut query = transactions::table.into_boxed::<diesel::pg::Pg>();

if let Some(sender) = filter.sender {
query = query.filter(transactions::public_key.eq(sender));
query = query.filter(transactions::public_key.eq(sender.to_lowercase()));
}
if let Some(min_timestamp) = filter.min_timestamp {
query = query.filter(transactions::timestamp.ge(min_timestamp));
Expand All @@ -66,7 +66,7 @@ pub async fn get(
query = query.filter(transactions::amount.le(BigDecimal::from(max_amount)));
}
if let Some(recipient) = filter.recipient {
query = query.filter(transactions::recipient.eq(recipient));
query = query.filter(transactions::recipient.eq(recipient.to_lowercase()));
}
if let Some(transaction_type) = filter.transaction_type {
query = query.filter(transactions::trx.eq(transaction_type));
Expand Down
16 changes: 8 additions & 8 deletions kairos-prover/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion kairos-prover/kairos-prover-risc0-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ prove = [ "risc0-zkvm/prove" ]

[dependencies]
methods = { path = "../methods" }
risc0-zkvm = { version="=1.0.2", default-features=false }
risc0-zkvm = { version="=1.0.3", default-features=false }

tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
Expand Down
2 changes: 1 addition & 1 deletion kairos-prover/kairos-verifier-risc0-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ disable-dev-mode = [ "risc0-zkvm/disable-dev-mode" ]


[dependencies]
risc0-zkvm = { version = "=1.0.2", default-features = false, optional = true }
risc0-zkvm = { version = "=1.0.3", default-features = false, optional = true }
kairos-circuit-logic = { path = "../kairos-circuit-logic", features = ["serde", "borsh"], default-features = false, optional = true }
borsh = { version = "1", default-features = false, optional = true }
2 changes: 1 addition & 1 deletion kairos-prover/methods/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ edition.workspace = true
license.workspace = true

[build-dependencies]
risc0-binfmt = "=1.0.2"
risc0-binfmt = "=1.0.3"
kairos-verifier-risc0-lib = { path = "../kairos-verifier-risc0-lib", default-features = false }
2 changes: 1 addition & 1 deletion kairos-prover/profiling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license.workspace = true

[dependencies]
methods = { path = "../methods" }
risc0-zkvm = "=1.0.2"
risc0-zkvm = "=1.0.3"

tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
Expand Down
12 changes: 8 additions & 4 deletions kairos-test-utils/src/cctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ impl CCTLNetwork {
chainspec_path: Option<&Path>,
config_path: Option<&Path>,
) -> anyhow::Result<CCTLNetwork> {
let chainspec_path = chainspec_path.unwrap_or_else(|| Path::new(env!("CCTL_CHAINSPEC")));
let config_path = config_path.unwrap_or_else(|| Path::new(env!("CCTL_CONFIG")));
let chainspec_path: String = chainspec_path
.map(|p| p.to_str().unwrap().to_owned())
.unwrap_or_else(|| std::env::var("CCTL_CHAINSPEC").unwrap());
let config_path: String = config_path
.map(|p| p.to_str().unwrap().to_owned())
.unwrap_or_else(|| std::env::var("CCTL_CONFIG").unwrap());

let working_dir = working_dir
.map(|dir| {
Expand All @@ -92,9 +96,9 @@ impl CCTLNetwork {
let mut setup_command = Command::new("cctl-infra-net-setup");
setup_command.env("CCTL_ASSETS", &assets_dir);

setup_command.arg(format!("chainspec={}", chainspec_path.to_str().unwrap()));
setup_command.arg(format!("chainspec={}", chainspec_path));

setup_command.arg(format!("config={}", config_path.to_str().unwrap()));
setup_command.arg(format!("config={}", config_path));

tracing::info!("Setting up network configuration");
let output = setup_command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use casper_types::ContractHash;
use hex::FromHex;
use kairos_test_utils::cctl::CCTLNetwork;
use std::fs;
use std::path::Path;
use std::path::PathBuf;

use casper_client_types::{runtime_args, RuntimeArgs};
Expand Down Expand Up @@ -30,14 +29,14 @@ async fn test_cctl_deploys_a_contract_successfully() {
path: contract_wasm_path,
};

let chainspec = Path::new(env!("CCTL_CHAINSPEC"));
let config = Path::new(env!("CCTL_CONFIG"));
let chainspec = PathBuf::from(std::env::var("CCTL_CHAINSPEC").unwrap());
let config = PathBuf::from(std::env::var("CCTL_CONFIG").unwrap());

let network = CCTLNetwork::run(
None,
Some(contract_to_deploy),
Some(chainspec),
Some(config),
Some(chainspec.as_path()),
Some(config.as_path()),
)
.await
.unwrap();
Expand Down
Loading

0 comments on commit 8079b75

Please sign in to comment.