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

Commit acc0c62

Browse files
authored
Add Themis using the BN curve (#549)
* Add THEMIS Policy Contract * Add test with 128 ads * Add instructions * Allow clients to work concurrently * pub(crate) utils to find unused code * Remove serde_json dep * Drop dependency on primitive_types * Add a simpler inner_product * Use elgamal for proof verification * Migrate to Ristretto Also, use Serde for instruction serialization * Add remaining instructions to processor * Remove rand 0.6 dependency * Add instruction constructors * Add e2e test * Move client test out of BPF build * Add BPF instruction count test Shows us that serde makes too many recursive calls and causes a very high instruction count (Vec<U256> becomes impractical). * Use Borsh serialization and test calculate_aggregate() Bump BPF instruction count limits after upgrading compiler * Test SubmitProofDecryption BPF instruction count * Remove CompressedRistretto This drops SubmitProofDecryption instructions by ~2.5M. Also, box up more RistrettoPoints, because they're huge (120 bytes) and blow up the BPF stack. * Add transaction size metrics and update BPF counts * Switch back to BN * Add benchmarking * Use configured keypair path * Make num_users configurable * Make testnet benchmark an example, not a test * Exclude themis client from CI build Because of Travis failure on itertools dependency
1 parent 748ff6c commit acc0c62

File tree

17 files changed

+1953
-569
lines changed

17 files changed

+1953
-569
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ members = [
33
"utils/cgen",
44
"utils/test-client",
55
"memo/program",
6+
"themis/program",
67
"token-swap/program",
7-
"token/cli",
8+
#"token/cli",
89
"token/program",
910
"token/program-v3",
1011
]
1112
exclude = [
13+
"themis/client",
1214
"token/perf-monitor",
1315
]
1416

themis/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Brave THEMIS
2+
3+
An implementation of Brave's THEMIS research project. This project contains
4+
two privacy-oriented smart contracts, the Policy Smart Contract (PSC) and
5+
the Fund Smart Contract (FSC). Together, the two contracts allow users to
6+
be compensated for engaging with ad publishers. The users do not expose
7+
their identities or preferences.

themis/client/Cargo.toml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
[package]
3+
name = "spl-themis-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+
bn = {git = "https://github.com/garious/bn", rev = "5c35c737ffabac9921310f53f48725216d59cbf1", default-features = false, features = ["borsh"]}
22+
elgamal_bn = { git = "https://github.com/garious/elgamal_bn", rev = "ba9bdcdb6cdd6fb8e74d0b8bc1b918bcd1b543a9" }
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 = { version = "0.1.0", path = "../program" }
28+
tarpc = { version = "0.21.1", features = ["full"] }
29+
tokio = "0.2"
30+
url = "2.1"
31+
32+
[dev-dependencies]
33+
solana-banks-server = "1.3.14"
34+
solana-bpf-loader-program = "1.3.14"
35+
solana_rbpf = "=0.1.31"
36+
solana-runtime = "1.3.14"
37+
38+
[lib]
39+
crate-type = ["cdylib", "lib"]

themis/client/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")
9+
.status()
10+
.expect("Failed to build themis program")
11+
.success();
12+
}

themis/client/examples/tps.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//! Themis client
2+
3+
use bn::Fr;
4+
use solana_banks_client::start_tcp_client;
5+
use solana_cli_config::{Config, CONFIG_FILE};
6+
use solana_sdk::signature::read_keypair_file;
7+
use spl_themis_client::test_e2e;
8+
use std::path::Path;
9+
use tokio::runtime::Runtime;
10+
use url::Url;
11+
12+
fn main() {
13+
let config_file = CONFIG_FILE.as_ref().unwrap();
14+
let config = if Path::new(&config_file).exists() {
15+
Config::load(&config_file).unwrap()
16+
} else {
17+
Config::default()
18+
};
19+
let rpc_banks_url = Config::compute_rpc_banks_url(&config.json_rpc_url);
20+
let url = Url::parse(&rpc_banks_url).unwrap();
21+
let host_port = (url.host_str().unwrap(), url.port().unwrap());
22+
23+
Runtime::new().unwrap().block_on(async {
24+
let mut banks_client = start_tcp_client(host_port).await.unwrap();
25+
let policies = vec![Fr::new(1u64.into()).unwrap(), Fr::new(2u64.into()).unwrap()];
26+
let sender_keypair = read_keypair_file(&config.keypair_path).unwrap();
27+
test_e2e(
28+
&mut banks_client,
29+
sender_keypair,
30+
policies,
31+
1_000,
32+
Fr::new(3u64.into()).unwrap(),
33+
)
34+
.await
35+
.unwrap();
36+
});
37+
}

0 commit comments

Comments
 (0)