parent
4563bf40f6
commit
24c6f820ce
|
@ -59,8 +59,6 @@ pub struct ComputeBudget {
|
|||
pub secp256k1_recover_cost: u64,
|
||||
/// Number of compute units consumed to do a syscall without any work
|
||||
pub syscall_base_cost: u64,
|
||||
/// Number of compute units consumed to call zktoken_crypto_op
|
||||
pub zk_token_elgamal_op_cost: u64, // to be replaced by curve25519 operations
|
||||
/// Number of compute units consumed to validate a curve25519 edwards point
|
||||
pub curve25519_edwards_validate_point_cost: u64,
|
||||
/// Number of compute units consumed to add two curve25519 edwards points
|
||||
|
@ -111,7 +109,6 @@ impl ComputeBudget {
|
|||
sysvar_base_cost: 100,
|
||||
secp256k1_recover_cost: 25_000,
|
||||
syscall_base_cost: 100,
|
||||
zk_token_elgamal_op_cost: 25_000,
|
||||
curve25519_edwards_validate_point_cost: 5_000, // TODO: precisely determine curve25519 costs
|
||||
curve25519_edwards_add_cost: 5_000,
|
||||
curve25519_edwards_subtract_cost: 5_000,
|
||||
|
|
|
@ -4410,14 +4410,6 @@ dependencies = [
|
|||
"solana-program 1.11.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-zk_token_elgamal"
|
||||
version = "1.11.2"
|
||||
dependencies = [
|
||||
"solana-program 1.11.2",
|
||||
"solana-zk-token-sdk 1.11.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bucket-map"
|
||||
version = "1.11.2"
|
||||
|
|
|
@ -92,7 +92,6 @@ members = [
|
|||
"rust/sysvar",
|
||||
"rust/upgradeable",
|
||||
"rust/upgraded",
|
||||
"rust/zk_token_elgamal",
|
||||
]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
|
|
|
@ -101,7 +101,6 @@ fn main() {
|
|||
"spoof1_system",
|
||||
"upgradeable",
|
||||
"upgraded",
|
||||
"zk_token_elgamal",
|
||||
];
|
||||
for program in rust_programs.iter() {
|
||||
println!(
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
[package]
|
||||
name = "solana-bpf-rust-zk_token_elgamal"
|
||||
version = "1.11.2"
|
||||
description = "Solana BPF test program written in Rust"
|
||||
authors = ["Solana Maintainers <maintainers@solana.foundation>"]
|
||||
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 = "2021"
|
||||
|
||||
[dependencies]
|
||||
solana-program = { path = "../../../../sdk/program", version = "=1.11.2" }
|
||||
solana-zk-token-sdk = { path = "../../../../zk-token-sdk", version = "=1.11.2" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
|
@ -1,54 +0,0 @@
|
|||
//! @brief zk_token_elgamal syscall tests
|
||||
|
||||
extern crate solana_program;
|
||||
use {
|
||||
solana_program::{custom_heap_default, 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_heap_default!();
|
||||
custom_panic_default!();
|
|
@ -514,7 +514,6 @@ 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),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,6 @@ use {
|
|||
curve25519_syscall_enabled, disable_fees_sysvar, executables_incur_cpi_data_cost,
|
||||
libsecp256k1_0_5_upgrade_enabled, limit_secp256k1_recovery_id,
|
||||
prevent_calling_precompiles_as_programs, quick_bail_on_panic, syscall_saturated_math,
|
||||
zk_token_sdk_enabled,
|
||||
},
|
||||
hash::{Hasher, HASH_BYTES},
|
||||
instruction::{
|
||||
|
@ -131,9 +130,6 @@ pub fn register_syscalls(
|
|||
let blake3_syscall_enabled = invoke_context
|
||||
.feature_set
|
||||
.is_active(&blake3_syscall_enabled::id());
|
||||
let zk_token_sdk_enabled = invoke_context
|
||||
.feature_set
|
||||
.is_active(&zk_token_sdk_enabled::id());
|
||||
let curve25519_syscall_enabled = invoke_context
|
||||
.feature_set
|
||||
.is_active(&curve25519_syscall_enabled::id());
|
||||
|
@ -213,29 +209,6 @@ pub fn register_syscalls(
|
|||
SyscallBlake3::call,
|
||||
)?;
|
||||
|
||||
// ZK Token
|
||||
register_feature_gated_syscall!(
|
||||
syscall_registry,
|
||||
zk_token_sdk_enabled,
|
||||
b"sol_zk_token_elgamal_op",
|
||||
SyscallZkTokenElgamalOp::init,
|
||||
SyscallZkTokenElgamalOp::call,
|
||||
)?;
|
||||
register_feature_gated_syscall!(
|
||||
syscall_registry,
|
||||
zk_token_sdk_enabled,
|
||||
b"sol_zk_token_elgamal_op_with_lo_hi",
|
||||
SyscallZkTokenElgamalOpWithLoHi::init,
|
||||
SyscallZkTokenElgamalOpWithLoHi::call,
|
||||
)?;
|
||||
register_feature_gated_syscall!(
|
||||
syscall_registry,
|
||||
zk_token_sdk_enabled,
|
||||
b"sol_zk_token_elgamal_op_with_scalar",
|
||||
SyscallZkTokenElgamalOpWithScalar::init,
|
||||
SyscallZkTokenElgamalOpWithScalar::call,
|
||||
)?;
|
||||
|
||||
// Elliptic Curve Point Validation
|
||||
//
|
||||
// TODO: add group operations and multiscalar multiplications
|
||||
|
@ -1594,6 +1567,7 @@ declare_syscall!(
|
|||
Ok(id) => id,
|
||||
Err(_) => {
|
||||
*result = Ok(Secp256k1RecoverError::InvalidRecoveryId.into());
|
||||
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
@ -1627,186 +1601,6 @@ declare_syscall!(
|
|||
}
|
||||
);
|
||||
|
||||
declare_syscall!(
|
||||
SyscallZkTokenElgamalOp,
|
||||
fn call(
|
||||
&mut self,
|
||||
op: u64,
|
||||
ct_0_addr: u64,
|
||||
ct_1_addr: u64,
|
||||
ct_result_addr: u64,
|
||||
_arg5: u64,
|
||||
memory_mapping: &mut MemoryMapping,
|
||||
result: &mut Result<u64, EbpfError<BpfError>>,
|
||||
) {
|
||||
use solana_zk_token_sdk::zk_token_elgamal::{ops, pod};
|
||||
|
||||
let invoke_context = question_mark!(
|
||||
self.invoke_context
|
||||
.try_borrow()
|
||||
.map_err(|_| SyscallError::InvokeContextBorrowFailed),
|
||||
result
|
||||
);
|
||||
let cost = invoke_context.get_compute_budget().zk_token_elgamal_op_cost;
|
||||
question_mark!(invoke_context.get_compute_meter().consume(cost), result);
|
||||
|
||||
let ct_0 = question_mark!(
|
||||
translate_type::<pod::ElGamalCiphertext>(
|
||||
memory_mapping,
|
||||
ct_0_addr,
|
||||
invoke_context.get_check_aligned()
|
||||
),
|
||||
result
|
||||
);
|
||||
let ct_1 = question_mark!(
|
||||
translate_type::<pod::ElGamalCiphertext>(
|
||||
memory_mapping,
|
||||
ct_1_addr,
|
||||
invoke_context.get_check_aligned()
|
||||
),
|
||||
result
|
||||
);
|
||||
|
||||
if let Some(ct_result) = match op {
|
||||
ops::OP_ADD => ops::add(ct_0, ct_1),
|
||||
ops::OP_SUB => ops::subtract(ct_0, ct_1),
|
||||
_ => None,
|
||||
} {
|
||||
*question_mark!(
|
||||
translate_type_mut::<pod::ElGamalCiphertext>(
|
||||
memory_mapping,
|
||||
ct_result_addr,
|
||||
invoke_context.get_check_aligned(),
|
||||
),
|
||||
result
|
||||
) = ct_result;
|
||||
*result = Ok(0);
|
||||
} else {
|
||||
*result = Ok(1);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
declare_syscall!(
|
||||
SyscallZkTokenElgamalOpWithLoHi,
|
||||
fn call(
|
||||
&mut self,
|
||||
op: u64,
|
||||
ct_0_addr: u64,
|
||||
ct_1_lo_addr: u64,
|
||||
ct_1_hi_addr: u64,
|
||||
ct_result_addr: u64,
|
||||
memory_mapping: &mut MemoryMapping,
|
||||
result: &mut Result<u64, EbpfError<BpfError>>,
|
||||
) {
|
||||
use solana_zk_token_sdk::zk_token_elgamal::{ops, pod};
|
||||
|
||||
let invoke_context = question_mark!(
|
||||
self.invoke_context
|
||||
.try_borrow()
|
||||
.map_err(|_| SyscallError::InvokeContextBorrowFailed),
|
||||
result
|
||||
);
|
||||
let cost = invoke_context.get_compute_budget().zk_token_elgamal_op_cost;
|
||||
question_mark!(invoke_context.get_compute_meter().consume(cost), result);
|
||||
|
||||
let ct_0 = question_mark!(
|
||||
translate_type::<pod::ElGamalCiphertext>(
|
||||
memory_mapping,
|
||||
ct_0_addr,
|
||||
invoke_context.get_check_aligned()
|
||||
),
|
||||
result
|
||||
);
|
||||
let ct_1_lo = question_mark!(
|
||||
translate_type::<pod::ElGamalCiphertext>(
|
||||
memory_mapping,
|
||||
ct_1_lo_addr,
|
||||
invoke_context.get_check_aligned()
|
||||
),
|
||||
result
|
||||
);
|
||||
let ct_1_hi = question_mark!(
|
||||
translate_type::<pod::ElGamalCiphertext>(
|
||||
memory_mapping,
|
||||
ct_1_hi_addr,
|
||||
invoke_context.get_check_aligned()
|
||||
),
|
||||
result
|
||||
);
|
||||
|
||||
if let Some(ct_result) = match op {
|
||||
ops::OP_ADD => ops::add_with_lo_hi(ct_0, ct_1_lo, ct_1_hi),
|
||||
ops::OP_SUB => ops::subtract_with_lo_hi(ct_0, ct_1_lo, ct_1_hi),
|
||||
_ => None,
|
||||
} {
|
||||
*question_mark!(
|
||||
translate_type_mut::<pod::ElGamalCiphertext>(
|
||||
memory_mapping,
|
||||
ct_result_addr,
|
||||
invoke_context.get_check_aligned(),
|
||||
),
|
||||
result
|
||||
) = ct_result;
|
||||
*result = Ok(0);
|
||||
} else {
|
||||
*result = Ok(1);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
declare_syscall!(
|
||||
SyscallZkTokenElgamalOpWithScalar,
|
||||
fn call(
|
||||
&mut self,
|
||||
op: u64,
|
||||
ct_addr: u64,
|
||||
scalar: u64,
|
||||
ct_result_addr: u64,
|
||||
_arg5: u64,
|
||||
memory_mapping: &mut MemoryMapping,
|
||||
result: &mut Result<u64, EbpfError<BpfError>>,
|
||||
) {
|
||||
use solana_zk_token_sdk::zk_token_elgamal::{ops, pod};
|
||||
|
||||
let invoke_context = question_mark!(
|
||||
self.invoke_context
|
||||
.try_borrow()
|
||||
.map_err(|_| SyscallError::InvokeContextBorrowFailed),
|
||||
result
|
||||
);
|
||||
let cost = invoke_context.get_compute_budget().zk_token_elgamal_op_cost;
|
||||
question_mark!(invoke_context.get_compute_meter().consume(cost), result);
|
||||
|
||||
let ct = question_mark!(
|
||||
translate_type::<pod::ElGamalCiphertext>(
|
||||
memory_mapping,
|
||||
ct_addr,
|
||||
invoke_context.get_check_aligned()
|
||||
),
|
||||
result
|
||||
);
|
||||
|
||||
if let Some(ct_result) = match op {
|
||||
ops::OP_ADD => ops::add_to(ct, scalar),
|
||||
ops::OP_SUB => ops::subtract_from(ct, scalar),
|
||||
_ => None,
|
||||
} {
|
||||
*question_mark!(
|
||||
translate_type_mut::<pod::ElGamalCiphertext>(
|
||||
memory_mapping,
|
||||
ct_result_addr,
|
||||
invoke_context.get_check_aligned(),
|
||||
),
|
||||
result
|
||||
) = ct_result;
|
||||
*result = Ok(0);
|
||||
} else {
|
||||
*result = Ok(1);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
declare_syscall!(
|
||||
// Elliptic Curve Point Validation
|
||||
//
|
||||
|
|
|
@ -46,9 +46,6 @@ define_syscall!(fn sol_sha256(vals: *const u8, val_len: u64, hash_result: *mut u
|
|||
define_syscall!(fn sol_keccak256(vals: *const u8, val_len: u64, hash_result: *mut u8) -> u64);
|
||||
define_syscall!(fn sol_secp256k1_recover(hash: *const u8, recovery_id: u64, signature: *const u8, result: *mut u8) -> u64);
|
||||
define_syscall!(fn sol_blake3(vals: *const u8, val_len: u64, hash_result: *mut u8) -> u64);
|
||||
define_syscall!(fn sol_zk_token_elgamal_op(op: u64, ct_0: *const u8, ct_1: *const u8, ct_result: *mut u8) -> u64);
|
||||
define_syscall!(fn sol_zk_token_elgamal_op_with_lo_hi(op: u64, ct_0: *const u8, ct_1_lo: *const u8, ct_1_hi: *const u8, ct_result: *mut u8) -> u64);
|
||||
define_syscall!(fn sol_zk_token_elgamal_op_with_scalar(op: u64, ct: *const u8, scalar: u64, ct_result: *mut u8) -> u64);
|
||||
define_syscall!(fn sol_get_clock_sysvar(addr: *mut u8) -> u64);
|
||||
define_syscall!(fn sol_get_epoch_schedule_sysvar(addr: *mut u8) -> u64);
|
||||
define_syscall!(fn sol_get_fees_sysvar(addr: *mut u8) -> u64);
|
||||
|
|
Loading…
Reference in New Issue