Skip to content

Commit

Permalink
Add zk_token_sdk_enabled feature to gate Zk Token proof program and `…
Browse files Browse the repository at this point in the history
…sol_zk_token_elgamal_op` syscalls
  • Loading branch information
mvines committed Jan 5, 2022
1 parent 98e7fad commit bb3a1b6
Show file tree
Hide file tree
Showing 17 changed files with 482 additions and 15 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

141 changes: 141 additions & 0 deletions programs/bpf/Cargo.lock

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

1 change: 1 addition & 0 deletions programs/bpf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ members = [
"rust/sysvar",
"rust/upgradeable",
"rust/upgraded",
"rust/zk_token_elgamal",
]

[package.metadata.docs.rs]
Expand Down
1 change: 1 addition & 0 deletions programs/bpf/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fn main() {
"spoof1_system",
"upgradeable",
"upgraded",
"zk_token_elgamal",
];
for program in rust_programs.iter() {
println!(
Expand Down
20 changes: 20 additions & 0 deletions programs/bpf/rust/zk_token_elgamal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "solana-bpf-rust-zk_token_elgamal"
version = "1.10.0"
description = "Solana BPF test program written in Rust"
authors = ["Solana Maintainers <[email protected]>"]
repository = "https://github.com/solana-labs/solana"
license = "Apache-2.0"
homepage = "https://solana.com/"
documentation = "https://docs.rs/solana-bpf-rust-zktoken_crypto"
edition = "2018"

[dependencies]
solana-program = { path = "../../../../sdk/program", version = "=1.10.0" }
solana-zk-token-sdk = { path = "../../../../zk-token-sdk", version = "=1.10.0" }

[lib]
crate-type = ["cdylib"]

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
53 changes: 53 additions & 0 deletions programs/bpf/rust/zk_token_elgamal/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//! @brief zk_token_elgamal syscall tests
extern crate solana_program;
use {
solana_program::{custom_panic_default, msg},
solana_zk_token_sdk::zk_token_elgamal::{
ops,
pod::{ElGamalCiphertext, Zeroable},
},
};

#[no_mangle]
pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
let zero = ElGamalCiphertext::zeroed();

msg!("add_to");
let one = ops::add_to(&zero, 1).expect("add_to");

msg!("subtract_from");
assert_eq!(zero, ops::subtract_from(&one, 1).expect("subtract_from"));

msg!("add");
assert_eq!(one, ops::add(&zero, &one).expect("add"));

msg!("subtract");
assert_eq!(zero, ops::subtract(&one, &one).expect("subtract"));

msg!("add_with_lo_hi");
assert_eq!(
one,
ops::add_with_lo_hi(
&one,
&ElGamalCiphertext::zeroed(),
&ElGamalCiphertext::zeroed()
)
.expect("add_with_lo_hi")
);

msg!("subtract_with_lo_hi");
assert_eq!(
one,
ops::subtract_with_lo_hi(
&one,
&ElGamalCiphertext::zeroed(),
&ElGamalCiphertext::zeroed()
)
.expect("subtract_with_lo_hi")
);

0
}

custom_panic_default!();
1 change: 1 addition & 0 deletions programs/bpf/tests/programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ fn test_program_bpf_sanity() {
("solana_bpf_rust_sanity", true),
("solana_bpf_rust_secp256k1_recover", true),
("solana_bpf_rust_sha", true),
("solana_bpf_rust_zk_token_elgamal", true),
]);
}

Expand Down
1 change: 1 addition & 0 deletions programs/bpf_loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ libsecp256k1 = "0.6.0"
solana-measure = { path = "../../measure", version = "=1.10.0" }
solana-program-runtime = { path = "../../program-runtime", version = "=1.10.0" }
solana-sdk = { path = "../../sdk", version = "=1.10.0" }
solana-zk-token-sdk = { path = "../../zk-token-sdk", version = "=1.10.0" }
solana_rbpf = "=0.2.21"
thiserror = "1.0"

Expand Down
Loading

0 comments on commit bb3a1b6

Please sign in to comment.