Add zk_token_sdk_enabled feature to gate Zk Token proof program and `sol_zk_token_elgamal_op` syscalls
This commit is contained in:
parent
98e7fada15
commit
bb3a1b6b31
|
@ -4555,6 +4555,7 @@ dependencies = [
|
|||
"solana-program-runtime",
|
||||
"solana-runtime",
|
||||
"solana-sdk",
|
||||
"solana-zk-token-sdk",
|
||||
"solana_rbpf",
|
||||
"thiserror",
|
||||
]
|
||||
|
@ -5706,6 +5707,8 @@ dependencies = [
|
|||
"solana-sdk",
|
||||
"solana-stake-program",
|
||||
"solana-vote-program",
|
||||
"solana-zk-token-proof-program",
|
||||
"solana-zk-token-sdk",
|
||||
"symlink",
|
||||
"tar",
|
||||
"tempfile",
|
||||
|
|
|
@ -27,6 +27,42 @@ version = "1.0.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "aead"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877"
|
||||
dependencies = [
|
||||
"generic-array 0.14.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aes"
|
||||
version = "0.7.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"cipher",
|
||||
"cpufeatures 0.2.1",
|
||||
"opaque-debug",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aes-gcm-siv"
|
||||
version = "0.10.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589c637f0e68c877bbd59a4599bbe849cac8e5f3e4b5a3ebae8f528cd218dcdc"
|
||||
dependencies = [
|
||||
"aead",
|
||||
"aes",
|
||||
"cipher",
|
||||
"ctr",
|
||||
"polyval",
|
||||
"subtle",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.4.7"
|
||||
|
@ -409,6 +445,15 @@ dependencies = [
|
|||
"chrono",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cipher"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7"
|
||||
dependencies = [
|
||||
"generic-array 0.14.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "2.33.3"
|
||||
|
@ -594,6 +639,15 @@ dependencies = [
|
|||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ctr"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "049bb91fb4aaf0e3c7efa6cd5ef877dbbbd15b39dad06d9948de4ec8a75761ea"
|
||||
dependencies = [
|
||||
"cipher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "curve25519-dalek"
|
||||
version = "2.1.0"
|
||||
|
@ -616,6 +670,7 @@ dependencies = [
|
|||
"byteorder 1.4.3",
|
||||
"digest 0.9.0",
|
||||
"rand_core 0.5.1",
|
||||
"serde",
|
||||
"subtle",
|
||||
"zeroize",
|
||||
]
|
||||
|
@ -1568,6 +1623,18 @@ dependencies = [
|
|||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "merlin"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e261cf0f8b3c42ded9f7d2bb59dea03aa52bc8a1cbc7482f9fc3fd1229d3b42"
|
||||
dependencies = [
|
||||
"byteorder 1.4.3",
|
||||
"keccak",
|
||||
"rand_core 0.5.1",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mime"
|
||||
version = "0.3.16"
|
||||
|
@ -1870,6 +1937,18 @@ version = "0.2.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
|
||||
|
||||
[[package]]
|
||||
name = "polyval"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"cpufeatures 0.2.1",
|
||||
"opaque-debug",
|
||||
"universal-hash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.8"
|
||||
|
@ -2584,6 +2663,7 @@ dependencies = [
|
|||
"solana-measure",
|
||||
"solana-program-runtime",
|
||||
"solana-sdk",
|
||||
"solana-zk-token-sdk",
|
||||
"solana_rbpf",
|
||||
"thiserror",
|
||||
]
|
||||
|
@ -2924,6 +3004,14 @@ dependencies = [
|
|||
"solana-program 1.10.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bpf-rust-zk_token_elgamal"
|
||||
version = "1.10.0"
|
||||
dependencies = [
|
||||
"solana-program 1.10.0",
|
||||
"solana-zk-token-sdk",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-bucket-map"
|
||||
version = "1.10.0"
|
||||
|
@ -3381,6 +3469,8 @@ dependencies = [
|
|||
"solana-sdk",
|
||||
"solana-stake-program",
|
||||
"solana-vote-program",
|
||||
"solana-zk-token-proof-program",
|
||||
"solana-zk-token-sdk",
|
||||
"symlink",
|
||||
"tar",
|
||||
"tempfile",
|
||||
|
@ -3549,6 +3639,47 @@ dependencies = [
|
|||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-zk-token-proof-program"
|
||||
version = "1.10.0"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"getrandom 0.1.14",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"solana-program-runtime",
|
||||
"solana-sdk",
|
||||
"solana-zk-token-sdk",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana-zk-token-sdk"
|
||||
version = "1.10.0"
|
||||
dependencies = [
|
||||
"aes-gcm-siv",
|
||||
"arrayref",
|
||||
"base64 0.13.0",
|
||||
"bincode",
|
||||
"bytemuck",
|
||||
"byteorder 1.4.3",
|
||||
"cipher",
|
||||
"curve25519-dalek 3.2.0",
|
||||
"getrandom 0.1.14",
|
||||
"lazy_static",
|
||||
"merlin",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"rand 0.7.3",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha3 0.9.1",
|
||||
"solana-program 1.10.0",
|
||||
"solana-sdk",
|
||||
"subtle",
|
||||
"thiserror",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "solana_rbpf"
|
||||
version = "0.2.21"
|
||||
|
@ -4056,6 +4187,16 @@ version = "0.2.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
||||
|
||||
[[package]]
|
||||
name = "universal-hash"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05"
|
||||
dependencies = [
|
||||
"generic-array 0.14.4",
|
||||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unreachable"
|
||||
version = "1.0.0"
|
||||
|
|
|
@ -86,6 +86,7 @@ members = [
|
|||
"rust/sysvar",
|
||||
"rust/upgradeable",
|
||||
"rust/upgraded",
|
||||
"rust/zk_token_elgamal",
|
||||
]
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
|
|
|
@ -95,6 +95,7 @@ fn main() {
|
|||
"spoof1_system",
|
||||
"upgradeable",
|
||||
"upgraded",
|
||||
"zk_token_elgamal",
|
||||
];
|
||||
for program in rust_programs.iter() {
|
||||
println!(
|
||||
|
|
|
@ -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 <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 = "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"]
|
|
@ -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!();
|
|
@ -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),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#[allow(deprecated)]
|
||||
use solana_sdk::sysvar::fees::Fees;
|
||||
use {
|
||||
crate::{alloc, BpfError},
|
||||
alloc::Alloc,
|
||||
|
@ -24,7 +23,7 @@ use {
|
|||
entrypoint::{BPF_ALIGN_OF_U128, MAX_PERMITTED_DATA_INCREASE, SUCCESS},
|
||||
epoch_schedule::EpochSchedule,
|
||||
feature_set::{
|
||||
blake3_syscall_enabled, disable_fees_sysvar, do_support_realloc,
|
||||
self, blake3_syscall_enabled, disable_fees_sysvar, do_support_realloc,
|
||||
fixed_memcpy_nonoverlapping_check, libsecp256k1_0_5_upgrade_enabled,
|
||||
prevent_calling_precompiles_as_programs, return_data_syscall_enabled,
|
||||
secp256k1_recover_syscall_enabled, sol_log_data_syscall_enabled,
|
||||
|
@ -40,7 +39,7 @@ use {
|
|||
secp256k1_recover::{
|
||||
Secp256k1RecoverError, SECP256K1_PUBLIC_KEY_LENGTH, SECP256K1_SIGNATURE_LENGTH,
|
||||
},
|
||||
sysvar::{self, Sysvar, SysvarId},
|
||||
sysvar::{self, fees::Fees, Sysvar, SysvarId},
|
||||
transaction_context::InstructionAccount,
|
||||
},
|
||||
std::{
|
||||
|
@ -158,6 +157,22 @@ pub fn register_syscalls(
|
|||
syscall_registry.register_syscall_by_name(b"sol_blake3", SyscallBlake3::call)?;
|
||||
}
|
||||
|
||||
if invoke_context
|
||||
.feature_set
|
||||
.is_active(&feature_set::zk_token_sdk_enabled::id())
|
||||
{
|
||||
syscall_registry
|
||||
.register_syscall_by_name(b"sol_zk_token_elgamal_op", SyscallZkTokenElgamalOp::call)?;
|
||||
syscall_registry.register_syscall_by_name(
|
||||
b"sol_zk_token_elgamal_op_with_lo_hi",
|
||||
SyscallZkTokenElgamalOpWithLoHi::call,
|
||||
)?;
|
||||
syscall_registry.register_syscall_by_name(
|
||||
b"sol_zk_token_elgamal_op_with_scalar",
|
||||
SyscallZkTokenElgamalOpWithScalar::call,
|
||||
)?;
|
||||
}
|
||||
|
||||
syscall_registry
|
||||
.register_syscall_by_name(b"sol_get_clock_sysvar", SyscallGetClockSysvar::call)?;
|
||||
syscall_registry.register_syscall_by_name(
|
||||
|
@ -244,6 +259,9 @@ pub fn bind_syscall_context_objects<'a, 'b>(
|
|||
let is_sol_log_data_syscall_active = invoke_context
|
||||
.feature_set
|
||||
.is_active(&sol_log_data_syscall_enabled::id());
|
||||
let is_zk_token_sdk_enabled = invoke_context
|
||||
.feature_set
|
||||
.is_active(&feature_set::zk_token_sdk_enabled::id());
|
||||
|
||||
let loader_id = invoke_context
|
||||
.transaction_context
|
||||
|
@ -352,6 +370,28 @@ pub fn bind_syscall_context_objects<'a, 'b>(
|
|||
}),
|
||||
);
|
||||
|
||||
bind_feature_gated_syscall_context_object!(
|
||||
vm,
|
||||
is_zk_token_sdk_enabled,
|
||||
Box::new(SyscallZkTokenElgamalOp {
|
||||
invoke_context: invoke_context.clone(),
|
||||
}),
|
||||
);
|
||||
bind_feature_gated_syscall_context_object!(
|
||||
vm,
|
||||
is_zk_token_sdk_enabled,
|
||||
Box::new(SyscallZkTokenElgamalOpWithLoHi {
|
||||
invoke_context: invoke_context.clone(),
|
||||
}),
|
||||
);
|
||||
bind_feature_gated_syscall_context_object!(
|
||||
vm,
|
||||
is_zk_token_sdk_enabled,
|
||||
Box::new(SyscallZkTokenElgamalOpWithScalar {
|
||||
invoke_context: invoke_context.clone(),
|
||||
}),
|
||||
);
|
||||
|
||||
vm.bind_syscall_context_object(
|
||||
Box::new(SyscallGetClockSysvar {
|
||||
invoke_context: invoke_context.clone(),
|
||||
|
@ -1596,6 +1636,195 @@ impl<'a, 'b> SyscallObject<BpfError> for SyscallSecp256k1Recover<'a, 'b> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct SyscallZkTokenElgamalOp<'a, 'b> {
|
||||
invoke_context: Rc<RefCell<&'a mut InvokeContext<'b>>>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> SyscallObject<BpfError> for SyscallZkTokenElgamalOp<'a, 'b> {
|
||||
fn call(
|
||||
&mut self,
|
||||
op: u64,
|
||||
ct_0_addr: u64,
|
||||
ct_1_addr: u64,
|
||||
ct_result_addr: u64,
|
||||
_arg5: u64,
|
||||
memory_mapping: &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 loader_id = question_mark!(
|
||||
invoke_context
|
||||
.transaction_context
|
||||
.get_loader_key()
|
||||
.map_err(SyscallError::InstructionError),
|
||||
result
|
||||
);
|
||||
|
||||
let ct_0 = question_mark!(
|
||||
translate_type::<pod::ElGamalCiphertext>(memory_mapping, ct_0_addr, &loader_id),
|
||||
result
|
||||
);
|
||||
let ct_1 = question_mark!(
|
||||
translate_type::<pod::ElGamalCiphertext>(memory_mapping, ct_1_addr, &loader_id),
|
||||
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,
|
||||
&loader_id,
|
||||
),
|
||||
result
|
||||
) = ct_result;
|
||||
*result = Ok(0);
|
||||
} else {
|
||||
*result = Ok(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SyscallZkTokenElgamalOpWithLoHi<'a, 'b> {
|
||||
invoke_context: Rc<RefCell<&'a mut InvokeContext<'b>>>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> SyscallObject<BpfError> for SyscallZkTokenElgamalOpWithLoHi<'a, 'b> {
|
||||
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: &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 loader_id = question_mark!(
|
||||
invoke_context
|
||||
.transaction_context
|
||||
.get_loader_key()
|
||||
.map_err(SyscallError::InstructionError),
|
||||
result
|
||||
);
|
||||
|
||||
let ct_0 = question_mark!(
|
||||
translate_type::<pod::ElGamalCiphertext>(memory_mapping, ct_0_addr, &loader_id),
|
||||
result
|
||||
);
|
||||
let ct_1_lo = question_mark!(
|
||||
translate_type::<pod::ElGamalCiphertext>(memory_mapping, ct_1_lo_addr, &loader_id),
|
||||
result
|
||||
);
|
||||
let ct_1_hi = question_mark!(
|
||||
translate_type::<pod::ElGamalCiphertext>(memory_mapping, ct_1_hi_addr, &loader_id),
|
||||
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,
|
||||
&loader_id,
|
||||
),
|
||||
result
|
||||
) = ct_result;
|
||||
*result = Ok(0);
|
||||
} else {
|
||||
*result = Ok(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SyscallZkTokenElgamalOpWithScalar<'a, 'b> {
|
||||
invoke_context: Rc<RefCell<&'a mut InvokeContext<'b>>>,
|
||||
}
|
||||
|
||||
impl<'a, 'b> SyscallObject<BpfError> for SyscallZkTokenElgamalOpWithScalar<'a, 'b> {
|
||||
fn call(
|
||||
&mut self,
|
||||
op: u64,
|
||||
ct_addr: u64,
|
||||
scalar: u64,
|
||||
ct_result_addr: u64,
|
||||
_arg5: u64,
|
||||
memory_mapping: &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 loader_id = question_mark!(
|
||||
invoke_context
|
||||
.transaction_context
|
||||
.get_loader_key()
|
||||
.map_err(SyscallError::InstructionError),
|
||||
result
|
||||
);
|
||||
|
||||
let ct = question_mark!(
|
||||
translate_type::<pod::ElGamalCiphertext>(memory_mapping, ct_addr, &loader_id),
|
||||
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,
|
||||
&loader_id,
|
||||
),
|
||||
result
|
||||
) = ct_result;
|
||||
*result = Ok(0);
|
||||
} else {
|
||||
*result = Ok(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Blake3
|
||||
pub struct SyscallBlake3<'a, 'b> {
|
||||
invoke_context: Rc<RefCell<&'a mut InvokeContext<'b>>>,
|
||||
|
|
|
@ -35,18 +35,20 @@ regex = "1.5.4"
|
|||
serde = { version = "1.0.133", features = ["rc"] }
|
||||
serde_derive = "1.0.103"
|
||||
solana-address-lookup-table-program = { path = "../programs/address-lookup-table", version = "=1.10.0" }
|
||||
solana-config-program = { path = "../programs/config", version = "=1.10.0" }
|
||||
solana-bucket-map = { path = "../bucket_map", version = "=1.10.0" }
|
||||
solana-compute-budget-program = { path = "../programs/compute-budget", version = "=1.10.0" }
|
||||
solana-config-program = { path = "../programs/config", version = "=1.10.0" }
|
||||
solana-frozen-abi = { path = "../frozen-abi", version = "=1.10.0" }
|
||||
solana-frozen-abi-macro = { path = "../frozen-abi/macro", version = "=1.10.0" }
|
||||
solana-measure = { path = "../measure", version = "=1.10.0" }
|
||||
solana-metrics = { path = "../metrics", version = "=1.10.0" }
|
||||
solana-bucket-map = { path = "../bucket_map", version = "=1.10.0" }
|
||||
solana-program-runtime = { path = "../program-runtime", version = "=1.10.0" }
|
||||
solana-rayon-threadlimit = { path = "../rayon-threadlimit", version = "=1.10.0" }
|
||||
solana-sdk = { path = "../sdk", version = "=1.10.0" }
|
||||
solana-stake-program = { path = "../programs/stake", version = "=1.10.0" }
|
||||
solana-vote-program = { path = "../programs/vote", version = "=1.10.0" }
|
||||
solana-zk-token-proof-program = { path = "../programs/zk-token-proof", version = "=1.10.0" }
|
||||
solana-zk-token-sdk = { path = "../zk-token-sdk", version = "=1.10.0" }
|
||||
symlink = "0.1.0"
|
||||
tar = "0.4.38"
|
||||
tempfile = "3.2.0"
|
||||
|
|
|
@ -181,6 +181,15 @@ fn feature_builtins() -> Vec<(Builtin, Pubkey, ActivationType)> {
|
|||
feature_set::versioned_tx_message_enabled::id(),
|
||||
ActivationType::NewProgram,
|
||||
),
|
||||
(
|
||||
Builtin::new(
|
||||
"zk_token_proof_program",
|
||||
solana_zk_token_sdk::zk_token_proof_program::id(),
|
||||
with_program_logging!(solana_zk_token_proof_program::process_instruction),
|
||||
),
|
||||
feature_set::zk_token_sdk_enabled::id(),
|
||||
ActivationType::NewProgram,
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,11 @@ use {
|
|||
crate::{
|
||||
hash::Hash,
|
||||
instruction::{CompiledInstruction, Instruction},
|
||||
message::{v0::{self, LoadedAddresses}, legacy::Message as LegacyMessage, MessageHeader},
|
||||
message::{
|
||||
legacy::Message as LegacyMessage,
|
||||
v0::{self, LoadedAddresses},
|
||||
MessageHeader,
|
||||
},
|
||||
pubkey::Pubkey,
|
||||
sanitize::{Sanitize, SanitizeError},
|
||||
serialize_utils::{append_slice, append_u16, append_u8},
|
||||
|
|
|
@ -304,9 +304,7 @@ mod tests {
|
|||
num_readonly_unsigned_accounts: 0,
|
||||
},
|
||||
recent_blockhash: Hash::new_unique(),
|
||||
account_keys: vec![
|
||||
Pubkey::new_unique(),
|
||||
],
|
||||
account_keys: vec![Pubkey::new_unique()],
|
||||
address_table_lookups: vec![
|
||||
MessageAddressTableLookup {
|
||||
account_key: Pubkey::new_unique(),
|
||||
|
|
|
@ -5,7 +5,7 @@ use {
|
|||
pubkey::Pubkey,
|
||||
sysvar,
|
||||
},
|
||||
std::{collections::HashSet, ops::Deref, convert::TryFrom},
|
||||
std::{collections::HashSet, convert::TryFrom, ops::Deref},
|
||||
};
|
||||
|
||||
/// Combination of a version #0 message and its loaded addresses
|
||||
|
|
|
@ -125,10 +125,7 @@ impl Message {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use {
|
||||
super::*,
|
||||
crate::message::VersionedMessage,
|
||||
};
|
||||
use {super::*, crate::message::VersionedMessage};
|
||||
|
||||
#[test]
|
||||
fn test_sanitize() {
|
||||
|
@ -251,7 +248,6 @@ mod tests {
|
|||
.is_err());
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_sanitize_with_max_account_keys() {
|
||||
assert!(Message {
|
||||
|
|
|
@ -88,6 +88,8 @@ 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,
|
||||
/// Optional program heap region size, if `None` then loader default
|
||||
pub heap_size: Option<usize>,
|
||||
/// Number of compute units per additional 32k heap above the default (~.5
|
||||
|
@ -117,6 +119,7 @@ impl ComputeBudget {
|
|||
sysvar_base_cost: 100,
|
||||
secp256k1_recover_cost: 25_000,
|
||||
syscall_base_cost: 100,
|
||||
zk_token_elgamal_op_cost: 25_000,
|
||||
heap_size: None,
|
||||
heap_cost: 8,
|
||||
}
|
||||
|
|
|
@ -161,6 +161,10 @@ pub mod gate_large_block {
|
|||
solana_sdk::declare_id!("2ry7ygxiYURULZCrypHhveanvP5tzZ4toRwVp89oCNSj");
|
||||
}
|
||||
|
||||
pub mod zk_token_sdk_enabled {
|
||||
solana_sdk::declare_id!("zk1snxsc6Fh3wsGNbbHAJNHiJoYgF29mMnTSusGx5EJ");
|
||||
}
|
||||
|
||||
pub mod versioned_tx_message_enabled {
|
||||
solana_sdk::declare_id!("3KZZ6Ks1885aGBQ45fwRcPXVBCtzUvxhUTkwKMR41Tca");
|
||||
}
|
||||
|
@ -326,6 +330,7 @@ lazy_static! {
|
|||
(disable_fees_sysvar::id(), "disable fees sysvar"),
|
||||
(stake_merge_with_unmatched_credits_observed::id(), "allow merging active stakes with unmatched credits_observed #18985"),
|
||||
(gate_large_block::id(), "validator checks block cost against max limit in realtime, reject if exceeds."),
|
||||
(zk_token_sdk_enabled::id(), "enable Zk Token proof program and syscalls"),
|
||||
(versioned_tx_message_enabled::id(), "enable versioned transaction message processing"),
|
||||
(libsecp256k1_fail_on_bad_count::id(), "fail libsec256k1_verify if count appears wrong"),
|
||||
(instructions_sysvar_owned_by_sysvar::id(), "fix owner for instructions sysvar"),
|
||||
|
|
Loading…
Reference in New Issue