From 6228437cd8f659509cf3452805c2314a9ef508df Mon Sep 17 00:00:00 2001 From: samkim-crypto Date: Tue, 18 Jun 2024 11:34:34 +0900 Subject: [PATCH] [sdk] Add ZK Elgamal Proof program feature gate (#1679) * add `zk-elgamal-proof-program-enabled` feature gate * reserve account for zk elgamal proof program * add zk elgamal proof as builtin program * cargo lock * cargo sort * replace feature gate key to start with `zk..` * add simd number * update `elgamal_program` to `zk_elgamal_proof_program` --- Cargo.lock | 2 + programs/sbf/Cargo.lock | 40 +++++++++++++++++++ runtime/Cargo.toml | 2 + .../core_bpf_migration/target_builtin.rs | 4 ++ runtime/src/bank/builtins/mod.rs | 30 ++++++++++++++ runtime/src/bank/tests.rs | 2 +- sdk/src/feature_set.rs | 5 +++ sdk/src/reserved_account_keys.rs | 6 +++ 8 files changed, 90 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index e83d21f5500698..a1460e2cd4ea22 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7341,6 +7341,8 @@ dependencies = [ "solana-version", "solana-vote", "solana-vote-program", + "solana-zk-elgamal-proof-program", + "solana-zk-sdk", "solana-zk-token-proof-program", "solana-zk-token-sdk", "static_assertions", diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 3f9194988b04a5..4b5c46f55cfd80 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5760,6 +5760,8 @@ dependencies = [ "solana-version", "solana-vote", "solana-vote-program", + "solana-zk-elgamal-proof-program", + "solana-zk-sdk", "solana-zk-token-proof-program", "solana-zk-token-sdk", "static_assertions", @@ -6697,6 +6699,44 @@ dependencies = [ "solana-vote-program", ] +[[package]] +name = "solana-zk-elgamal-proof-program" +version = "2.0.0" +dependencies = [ + "bytemuck", + "num-derive", + "num-traits", + "solana-program-runtime", + "solana-sdk", + "solana-zk-sdk", +] + +[[package]] +name = "solana-zk-sdk" +version = "2.0.0" +dependencies = [ + "aes-gcm-siv", + "base64 0.22.1", + "bincode", + "bytemuck", + "curve25519-dalek", + "itertools 0.12.1", + "lazy_static", + "merlin", + "num-derive", + "num-traits", + "rand 0.7.3", + "serde", + "serde_derive", + "serde_json", + "sha3 0.9.1", + "solana-program", + "solana-sdk", + "subtle", + "thiserror", + "zeroize", +] + [[package]] name = "solana-zk-token-proof-program" version = "2.0.0" diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index e9650cdaa0f29e..da551f4ac4686d 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -71,6 +71,8 @@ solana-transaction-status = { workspace = true } solana-version = { workspace = true } solana-vote = { workspace = true } solana-vote-program = { workspace = true } +solana-zk-elgamal-proof-program = { workspace = true } +solana-zk-sdk = { workspace = true } solana-zk-token-proof-program = { workspace = true } solana-zk-token-sdk = { workspace = true } static_assertions = { workspace = true } diff --git a/runtime/src/bank/builtins/core_bpf_migration/target_builtin.rs b/runtime/src/bank/builtins/core_bpf_migration/target_builtin.rs index fdd8c3279fd54f..b89a951ffd2cdf 100644 --- a/runtime/src/bank/builtins/core_bpf_migration/target_builtin.rs +++ b/runtime/src/bank/builtins/core_bpf_migration/target_builtin.rs @@ -120,6 +120,10 @@ mod tests { solana_zk_token_sdk::zk_token_proof_program::id(), Some(feature_set::zk_token_sdk_enabled::id()) )] + #[test_case( + solana_zk_sdk::zk_elgamal_proof_program::id(), + Some(feature_set::zk_elgamal_proof_program_enabled::id()) + )] fn test_target_program_builtin(program_address: Pubkey, activation_feature: Option) { let migration_target = CoreBpfMigrationTargetType::Builtin; let mut bank = create_simple_test_bank(0); diff --git a/runtime/src/bank/builtins/mod.rs b/runtime/src/bank/builtins/mod.rs index 8a7760850dc64c..6e1797be11a8cb 100644 --- a/runtime/src/bank/builtins/mod.rs +++ b/runtime/src/bank/builtins/mod.rs @@ -121,6 +121,13 @@ pub static BUILTINS: &[BuiltinPrototype] = &[ program_id: solana_sdk::loader_v4::id(), entrypoint: solana_loader_v4_program::Entrypoint::vm, }), + testable_prototype!(BuiltinPrototype { + core_bpf_migration_config: None, + name: zk_elgamal_proof_program, + enable_feature_id: Some(feature_set::zk_elgamal_proof_program_enabled::id()), + program_id: solana_zk_sdk::zk_elgamal_proof_program::id(), + entrypoint: solana_zk_elgamal_proof_program::Entrypoint::vm, + }), ]; pub static STATELESS_BUILTINS: &[StatelessBuiltinPrototype] = &[StatelessBuiltinPrototype { @@ -328,6 +335,25 @@ mod test_only { datapoint_name: "migrate_builtin_to_core_bpf_loader_v4_program", }; } + + pub mod zk_elgamal_proof_program { + pub mod feature { + solana_sdk::declare_id!("EYtuxScWqGWmcPEDmeUsEt3iPkvWE26EWLfSxUvWP2WN"); + } + pub mod source_buffer { + solana_sdk::declare_id!("AaVrLPurAUmjw6XRNGr6ezQfHaJWpBGHhcRSJmNjoVpQ"); + } + pub mod upgrade_authority { + solana_sdk::declare_id!("EyGkQYHgynUdvdNPNiWbJQk9roFCexgdJQMNcWbuvp78"); + } + pub const CONFIG: super::CoreBpfMigrationConfig = super::CoreBpfMigrationConfig { + source_buffer_address: source_buffer::id(), + upgrade_authority_address: Some(upgrade_authority::id()), + feature_id: feature::id(), + migration_target: super::CoreBpfMigrationTargetType::Builtin, + datapoint_name: "migrate_builtin_to_core_bpf_zk_elgamal_proof_program", + }; + } } #[cfg(test)] @@ -377,6 +403,10 @@ mod tests { &super::BUILTINS[10].core_bpf_migration_config, &Some(super::test_only::loader_v4::CONFIG) ); + assert_eq!( + &super::BUILTINS[11].core_bpf_migration_config, + &Some(super::test_only::zk_elgamal_proof_program::CONFIG) + ); // Feature Gate has a live migration config, so it has no test-only // configs to test here. } diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index 836705e37b1bb2..87aa5a84617b7b 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -7985,7 +7985,7 @@ fn test_reserved_account_keys() { assert_eq!( bank.get_reserved_account_keys().len(), - 29, + 30, "after activating the new feature, bank should have new active reserved keys" ); } diff --git a/sdk/src/feature_set.rs b/sdk/src/feature_set.rs index e44f83d0db7a4a..e4970cf8cda0a3 100644 --- a/sdk/src/feature_set.rs +++ b/sdk/src/feature_set.rs @@ -824,6 +824,10 @@ pub mod migrate_address_lookup_table_program_to_core_bpf { solana_sdk::declare_id!("C97eKZygrkU4JxJsZdjgbUY7iQR7rKTr4NyDWo2E5pRm"); } +pub mod zk_elgamal_proof_program_enabled { + solana_sdk::declare_id!("zkhiy5oLowR7HY4zogXjCjeMXyruLqBwSWH21qcFtnv"); +} + lazy_static! { /// Map of feature identifiers to user-visible description pub static ref FEATURE_NAMES: HashMap = [ @@ -1025,6 +1029,7 @@ lazy_static! { (migrate_config_program_to_core_bpf::id(), "Migrate Config program to Core BPF #1378"), (enable_get_epoch_stake_syscall::id(), "Enable syscall: sol_get_epoch_stake #884"), (migrate_address_lookup_table_program_to_core_bpf::id(), "Migrate Address Lookup Table program to Core BPF #1651"), + (zk_elgamal_proof_program_enabled::id(), "Enable ZkElGamalProof program SIMD-0153"), /*************** ADD NEW FEATURES HERE ***************/ ] .iter() diff --git a/sdk/src/reserved_account_keys.rs b/sdk/src/reserved_account_keys.rs index a1a1d367d18ffd..e3c6bed5c973be 100644 --- a/sdk/src/reserved_account_keys.rs +++ b/sdk/src/reserved_account_keys.rs @@ -22,6 +22,11 @@ mod zk_token_proof_program { solana_sdk::declare_id!("ZkTokenProof1111111111111111111111111111111"); } +// Inline zk-elgamal-proof program id since it isn't available in the sdk +mod zk_elgamal_proof_program { + solana_sdk::declare_id!("ZkE1Gama1Proof11111111111111111111111111111"); +} + // ReservedAccountKeys is not serialized into or deserialized from bank // snapshots but the bank requires this trait to be implemented anyways. #[cfg(all(RUSTC_WITH_SPECIALIZATION, feature = "frozen-abi"))] @@ -162,6 +167,7 @@ lazy_static! { ReservedAccount::new_active(stake::program::id()), ReservedAccount::new_active(system_program::id()), ReservedAccount::new_active(vote::program::id()), + ReservedAccount::new_pending(zk_elgamal_proof_program::id(), feature_set::add_new_reserved_account_keys::id()), ReservedAccount::new_pending(zk_token_proof_program::id(), feature_set::add_new_reserved_account_keys::id()), // sysvars