Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit b020dd2

Browse files
authored
Add Ristretto version of THEMIS (#566)
* 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
1 parent 66f334b commit b020dd2

32 files changed

+1750
-20
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ members = [
33
"utils/cgen",
44
"utils/test-client",
55
"memo/program",
6-
"themis/program",
6+
"themis/program_bn",
7+
"themis/program_ristretto",
78
"token-swap/program",
89
"token/cli",
910
"token/program",
1011
"token/program-v3",
1112
]
1213
exclude = [
13-
"themis/client",
14+
"themis/client_bn",
15+
"themis/client_ristretto",
1416
"token/perf-monitor",
1517
]
1618

ci/script.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ done
6767

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

7273

7374
# Test token js bindings

themis/client/Cargo.lock renamed to themis/client_bn/Cargo.lock

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

themis/client/Cargo.toml renamed to themis/client_bn/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
[package]
3-
name = "spl-themis-client"
3+
name = "spl-themis-bn-client"
44
version = "0.1.0"
55
description = "SPL THEMIS client"
66
authors = ["Solana Maintainers <[email protected]>"]
@@ -24,7 +24,7 @@ futures = "0.3"
2424
solana-banks-client = "1.3.14"
2525
solana-cli-config = "1.3.14"
2626
solana-sdk = "1.3.14"
27-
spl-themis = { version = "0.1.0", path = "../program" }
27+
spl-themis-bn = { version = "0.1.0", path = "../program_bn" }
2828
tarpc = { version = "0.21.1", features = ["full"] }
2929
tokio = "0.2"
3030
url = "2.1"

themis/client/build.rs renamed to themis/client_bn/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn main() {
55
Command::new(canonicalize("../../do.sh").unwrap())
66
.current_dir("../..")
77
.arg("build")
8-
.arg("themis/program")
8+
.arg("themis/program_bn")
99
.status()
1010
.expect("Failed to build themis program")
1111
.success();

themis/client/examples/tps.rs renamed to themis/client_bn/examples/tps.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bn::Fr;
44
use solana_banks_client::start_tcp_client;
55
use solana_cli_config::{Config, CONFIG_FILE};
66
use solana_sdk::signature::read_keypair_file;
7-
use spl_themis_client::test_e2e;
7+
use spl_themis_bn_client::test_e2e;
88
use std::path::Path;
99
use tokio::runtime::Runtime;
1010
use url::Url;

themis/client/src/lib.rs renamed to themis/client_bn/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use solana_sdk::{
1212
system_instruction,
1313
transaction::Transaction,
1414
};
15-
use spl_themis::{
15+
use spl_themis_bn::{
1616
instruction,
1717
state::generate_keys, // recover_scalar, User},
1818
};
@@ -245,7 +245,7 @@ mod tests {
245245
instruction::InstructionError,
246246
program_error::ProgramError,
247247
};
248-
use spl_themis::processor::process_instruction;
248+
use spl_themis_bn::processor::process_instruction;
249249
use std::{
250250
collections::HashMap,
251251
sync::{Arc, RwLock},
@@ -337,7 +337,7 @@ mod tests {
337337
fn test_local_e2e_2ads() {
338338
let (genesis_config, sender_keypair) = create_genesis_config(sol_to_lamports(9_000_000.0));
339339
let mut bank = Bank::new(&genesis_config);
340-
bank.add_builtin_program("Themis", spl_themis::id(), process_instruction_native);
340+
bank.add_builtin_program("Themis", spl_themis_bn::id(), process_instruction_native);
341341
let bank_forks = Arc::new(RwLock::new(BankForks::new(bank)));
342342
Runtime::new().unwrap().block_on(async {
343343
let transport = start_local_server(&bank_forks).await;

themis/client/tests/assert_instruction_count.rs renamed to themis/client_bn/tests/assert_instruction_count.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use solana_sdk::{
1818
message::Message,
1919
pubkey::Pubkey,
2020
};
21-
use spl_themis::{
21+
use spl_themis_bn::{
2222
instruction::ThemisInstruction,
2323
state::{generate_keys, /*recover_scalar,*/ Policies, User},
2424
};
@@ -42,7 +42,7 @@ fn run_program(
4242
instruction_data: &[u8],
4343
) -> Result<u64, InstructionError> {
4444
let mut program_account = SolanaAccount::default();
45-
program_account.data = load_program("spl_themis");
45+
program_account.data = load_program("spl_themis_bn");
4646
let loader_id = bpf_loader::id();
4747
let mut invoke_context = MockInvokeContext::default();
4848
let executable = EbpfVm::<solana_bpf_loader_program::BPFError>::create_executable_from_elf(

themis/client_ristretto/Cargo.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
[package]
3+
name = "spl-themis-ristretto-client"
4+
version = "0.1.0"
5+
description = "SPL THEMIS client"
6+
authors = ["Solana Maintainers <[email protected]>"]
7+
repository = "https://github.com/solana-labs/solana-program-library"
8+
license = "Apache-2.0"
9+
edition = "2018"
10+
exclude = ["js/**"]
11+
12+
[features]
13+
no-entrypoint = []
14+
skip-no-mangle = ["solana-sdk/skip-no-mangle"]
15+
program = ["solana-sdk/program"]
16+
default = ["solana-sdk/default"]
17+
18+
[dependencies]
19+
bincode = "1.3"
20+
borsh = "0.7.1"
21+
curve25519-dalek = {git = "https://github.com/garious/curve25519-dalek", rev = "60efef3553d6bf3d7f3b09b5f97acd54d72529ff", default-features = false, features = ["borsh"]}
22+
elgamal_ristretto = { git = "https://github.com/garious/elgamal", rev = "260763fb67c34debe3915b39d95b6e7b3e1461d0" }
23+
futures = "0.3"
24+
solana-banks-client = "1.3.14"
25+
solana-cli-config = "1.3.14"
26+
solana-sdk = "1.3.14"
27+
spl-themis-ristretto = { version = "0.1.0", path = "../program_ristretto" }
28+
tarpc = { version = "0.21.1", features = ["full"] }
29+
tokio = "0.2"
30+
url = "2.1"
31+
32+
[dev-dependencies]
33+
separator = "0.4.1"
34+
solana-banks-server = "1.3.14"
35+
solana-bpf-loader-program = "1.3.14"
36+
solana_rbpf = "=0.1.31"
37+
solana-runtime = "1.3.14"
38+
39+
[lib]
40+
crate-type = ["cdylib", "lib"]

themis/client_ristretto/build.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use std::{fs::canonicalize, process::Command};
2+
3+
fn main() {
4+
println!("cargo:warning=(not a warning) Building SPL Themis shared object");
5+
Command::new(canonicalize("../../do.sh").unwrap())
6+
.current_dir("../..")
7+
.arg("build")
8+
.arg("themis/program_ristretto")
9+
.status()
10+
.expect("Failed to build themis program")
11+
.success();
12+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//! Themis client
2+
3+
use solana_banks_client::start_tcp_client;
4+
use solana_cli_config::{Config, CONFIG_FILE};
5+
use solana_sdk::signature::read_keypair_file;
6+
use spl_themis_ristretto_client::test_e2e;
7+
use std::path::Path;
8+
use tokio::runtime::Runtime;
9+
use url::Url;
10+
11+
fn main() {
12+
let config_file = CONFIG_FILE.as_ref().unwrap();
13+
let config = if Path::new(&config_file).exists() {
14+
Config::load(&config_file).unwrap()
15+
} else {
16+
Config::default()
17+
};
18+
let rpc_banks_url = Config::compute_rpc_banks_url(&config.json_rpc_url);
19+
let url = Url::parse(&rpc_banks_url).unwrap();
20+
let host_port = (url.host_str().unwrap(), url.port().unwrap());
21+
22+
Runtime::new().unwrap().block_on(async {
23+
let mut banks_client = start_tcp_client(host_port).await.unwrap();
24+
let policies = vec![1u64.into(), 2u64.into()];
25+
let sender_keypair = read_keypair_file(&config.keypair_path).unwrap();
26+
test_e2e(
27+
&mut banks_client,
28+
sender_keypair,
29+
policies,
30+
1_000,
31+
3u64.into(),
32+
)
33+
.await
34+
.unwrap();
35+
});
36+
}

0 commit comments

Comments
 (0)