Skip to content

Commit

Permalink
Add Ristretto version of THEMIS (solana-labs#566)
Browse files Browse the repository at this point in the history
* Add Ristretto version of THEMIS

BN BPF instruction counts:
  CalculateAggregate:    83,511
  SubmitProofDecryption: 33,755,027

Ristretto BPF instruction counts:
  CalculateAggregate:    13,049,558
  SubmitProofDecryption: 13,149,232

* Fix CI script
  • Loading branch information
garious authored Oct 6, 2020
1 parent 66f334b commit b020dd2
Show file tree
Hide file tree
Showing 32 changed files with 1,750 additions and 20 deletions.
78 changes: 74 additions & 4 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ members = [
"utils/cgen",
"utils/test-client",
"memo/program",
"themis/program",
"themis/program_bn",
"themis/program_ristretto",
"token-swap/program",
"token/cli",
"token/program",
"token/program-v3",
]
exclude = [
"themis/client",
"themis/client_bn",
"themis/client_ristretto",
"token/perf-monitor",
]

Expand Down
3 changes: 2 additions & 1 deletion ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ done

# Run SPL Token's performance monitor
_ cargo test --manifest-path=token/perf-monitor/Cargo.toml -- --nocapture
_ cargo test --manifest-path=themis/client/Cargo.toml -- --nocapture
_ cargo test --manifest-path=themis/client_bn/Cargo.toml -- --nocapture
_ cargo test --manifest-path=themis/client_ristretto/Cargo.toml -- --nocapture


# Test token js bindings
Expand Down
6 changes: 3 additions & 3 deletions themis/client/Cargo.lock → themis/client_bn/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 themis/client/Cargo.toml → themis/client_bn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

[package]
name = "spl-themis-client"
name = "spl-themis-bn-client"
version = "0.1.0"
description = "SPL THEMIS client"
authors = ["Solana Maintainers <[email protected]>"]
Expand All @@ -24,7 +24,7 @@ futures = "0.3"
solana-banks-client = "1.3.14"
solana-cli-config = "1.3.14"
solana-sdk = "1.3.14"
spl-themis = { version = "0.1.0", path = "../program" }
spl-themis-bn = { version = "0.1.0", path = "../program_bn" }
tarpc = { version = "0.21.1", features = ["full"] }
tokio = "0.2"
url = "2.1"
Expand Down
2 changes: 1 addition & 1 deletion themis/client/build.rs → themis/client_bn/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn main() {
Command::new(canonicalize("../../do.sh").unwrap())
.current_dir("../..")
.arg("build")
.arg("themis/program")
.arg("themis/program_bn")
.status()
.expect("Failed to build themis program")
.success();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bn::Fr;
use solana_banks_client::start_tcp_client;
use solana_cli_config::{Config, CONFIG_FILE};
use solana_sdk::signature::read_keypair_file;
use spl_themis_client::test_e2e;
use spl_themis_bn_client::test_e2e;
use std::path::Path;
use tokio::runtime::Runtime;
use url::Url;
Expand Down
6 changes: 3 additions & 3 deletions themis/client/src/lib.rs → themis/client_bn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use solana_sdk::{
system_instruction,
transaction::Transaction,
};
use spl_themis::{
use spl_themis_bn::{
instruction,
state::generate_keys, // recover_scalar, User},
};
Expand Down Expand Up @@ -245,7 +245,7 @@ mod tests {
instruction::InstructionError,
program_error::ProgramError,
};
use spl_themis::processor::process_instruction;
use spl_themis_bn::processor::process_instruction;
use std::{
collections::HashMap,
sync::{Arc, RwLock},
Expand Down Expand Up @@ -337,7 +337,7 @@ mod tests {
fn test_local_e2e_2ads() {
let (genesis_config, sender_keypair) = create_genesis_config(sol_to_lamports(9_000_000.0));
let mut bank = Bank::new(&genesis_config);
bank.add_builtin_program("Themis", spl_themis::id(), process_instruction_native);
bank.add_builtin_program("Themis", spl_themis_bn::id(), process_instruction_native);
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
Runtime::new().unwrap().block_on(async {
let transport = start_local_server(&bank_forks).await;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use solana_sdk::{
message::Message,
pubkey::Pubkey,
};
use spl_themis::{
use spl_themis_bn::{
instruction::ThemisInstruction,
state::{generate_keys, /*recover_scalar,*/ Policies, User},
};
Expand All @@ -42,7 +42,7 @@ fn run_program(
instruction_data: &[u8],
) -> Result<u64, InstructionError> {
let mut program_account = SolanaAccount::default();
program_account.data = load_program("spl_themis");
program_account.data = load_program("spl_themis_bn");
let loader_id = bpf_loader::id();
let mut invoke_context = MockInvokeContext::default();
let executable = EbpfVm::<solana_bpf_loader_program::BPFError>::create_executable_from_elf(
Expand Down
40 changes: 40 additions & 0 deletions themis/client_ristretto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

[package]
name = "spl-themis-ristretto-client"
version = "0.1.0"
description = "SPL THEMIS client"
authors = ["Solana Maintainers <[email protected]>"]
repository = "https://github.com/solana-labs/solana-program-library"
license = "Apache-2.0"
edition = "2018"
exclude = ["js/**"]

[features]
no-entrypoint = []
skip-no-mangle = ["solana-sdk/skip-no-mangle"]
program = ["solana-sdk/program"]
default = ["solana-sdk/default"]

[dependencies]
bincode = "1.3"
borsh = "0.7.1"
curve25519-dalek = {git = "https://github.com/garious/curve25519-dalek", rev = "60efef3553d6bf3d7f3b09b5f97acd54d72529ff", default-features = false, features = ["borsh"]}
elgamal_ristretto = { git = "https://github.com/garious/elgamal", rev = "260763fb67c34debe3915b39d95b6e7b3e1461d0" }
futures = "0.3"
solana-banks-client = "1.3.14"
solana-cli-config = "1.3.14"
solana-sdk = "1.3.14"
spl-themis-ristretto = { version = "0.1.0", path = "../program_ristretto" }
tarpc = { version = "0.21.1", features = ["full"] }
tokio = "0.2"
url = "2.1"

[dev-dependencies]
separator = "0.4.1"
solana-banks-server = "1.3.14"
solana-bpf-loader-program = "1.3.14"
solana_rbpf = "=0.1.31"
solana-runtime = "1.3.14"

[lib]
crate-type = ["cdylib", "lib"]
12 changes: 12 additions & 0 deletions themis/client_ristretto/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::{fs::canonicalize, process::Command};

fn main() {
println!("cargo:warning=(not a warning) Building SPL Themis shared object");
Command::new(canonicalize("../../do.sh").unwrap())
.current_dir("../..")
.arg("build")
.arg("themis/program_ristretto")
.status()
.expect("Failed to build themis program")
.success();
}
36 changes: 36 additions & 0 deletions themis/client_ristretto/examples/tps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//! Themis client
use solana_banks_client::start_tcp_client;
use solana_cli_config::{Config, CONFIG_FILE};
use solana_sdk::signature::read_keypair_file;
use spl_themis_ristretto_client::test_e2e;
use std::path::Path;
use tokio::runtime::Runtime;
use url::Url;

fn main() {
let config_file = CONFIG_FILE.as_ref().unwrap();
let config = if Path::new(&config_file).exists() {
Config::load(&config_file).unwrap()
} else {
Config::default()
};
let rpc_banks_url = Config::compute_rpc_banks_url(&config.json_rpc_url);
let url = Url::parse(&rpc_banks_url).unwrap();
let host_port = (url.host_str().unwrap(), url.port().unwrap());

Runtime::new().unwrap().block_on(async {
let mut banks_client = start_tcp_client(host_port).await.unwrap();
let policies = vec![1u64.into(), 2u64.into()];
let sender_keypair = read_keypair_file(&config.keypair_path).unwrap();
test_e2e(
&mut banks_client,
sender_keypair,
policies,
1_000,
3u64.into(),
)
.await
.unwrap();
});
}
Loading

0 comments on commit b020dd2

Please sign in to comment.