From 16e7e988aa5d1c8e8d45ef8ac22fc1c544abe150 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Tue, 8 Oct 2024 16:59:32 +0400 Subject: [PATCH 1/7] strat extracting ed25519-instructions crate --- Cargo.lock | 12 ++++++++++ Cargo.toml | 2 ++ sdk/ed25519-instructions/Cargo.toml | 24 +++++++++++++++++++ .../src/lib.rs} | 2 -- sdk/src/lib.rs | 7 +++++- 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 sdk/ed25519-instructions/Cargo.toml rename sdk/{src/ed25519_instruction.rs => ed25519-instructions/src/lib.rs} (99%) diff --git a/Cargo.lock b/Cargo.lock index be294c5cb7f1f2..05e54ea9cbd79d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6810,6 +6810,18 @@ dependencies = [ "solana-sdk", ] +[[package]] +name = "solana-ed25519-instruction" +version = "2.2.0" +dependencies = [ + "bytemuck", + "bytemuck_derive", + "ed25519-dalek", + "solana-feature-set", + "solana-instruction", + "solana-precompile-error", +] + [[package]] name = "solana-ed25519-program-tests" version = "2.2.0" diff --git a/Cargo.toml b/Cargo.toml index 383d9e65316625..b8776cd00733b5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -111,6 +111,7 @@ members = [ "sdk/decode-error", "sdk/define-syscall", "sdk/derivation-path", + "sdk/ed25519-instructions", "sdk/epoch-rewards", "sdk/epoch-schedule", "sdk/feature-set", @@ -438,6 +439,7 @@ solana-decode-error = { path = "sdk/decode-error", version = "=2.2.0" } solana-define-syscall = { path = "sdk/define-syscall", version = "=2.2.0" } solana-derivation-path = { path = "sdk/derivation-path", version = "=2.2.0" } solana-download-utils = { path = "download-utils", version = "=2.2.0" } +solana-ed25519-instructions = { path = "sdk/ed25519-instructions", version = "=2.2.0" } solana-entry = { path = "entry", version = "=2.2.0" } solana-program-entrypoint = { path = "sdk/program-entrypoint", version = "=2.2.0" } solana-epoch-rewards = { path = "sdk/epoch-rewards", version = "=2.2.0" } diff --git a/sdk/ed25519-instructions/Cargo.toml b/sdk/ed25519-instructions/Cargo.toml new file mode 100644 index 00000000000000..79f41efc8c7528 --- /dev/null +++ b/sdk/ed25519-instructions/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "solana-ed25519-instruction" +description = "Instructions for the Solana ed25519 native program" +documentation = "https://docs.rs/solana-ed25519-instruction" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[dependencies] +bytemuck = { workspace = true } +bytemuck_derive = { workspace = true } +ed25519-dalek = { workspace = true } +solana-feature-set = { workspace = true } +solana-instruction = { workspace = true } +solana-precompile-error = { workspace = true } + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[lints] +workspace = true diff --git a/sdk/src/ed25519_instruction.rs b/sdk/ed25519-instructions/src/lib.rs similarity index 99% rename from sdk/src/ed25519_instruction.rs rename to sdk/ed25519-instructions/src/lib.rs index 688ef0dade9d39..85a691a7755e4f 100644 --- a/sdk/src/ed25519_instruction.rs +++ b/sdk/ed25519-instructions/src/lib.rs @@ -2,8 +2,6 @@ //! //! [np]: https://docs.solanalabs.com/runtime/programs#ed25519-program -#![cfg(feature = "full")] - use { bytemuck::bytes_of, bytemuck_derive::{Pod, Zeroable}, diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 10721132595c5d..befe275a0ee223 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -64,7 +64,6 @@ pub use solana_signer::signers; pub mod client; pub mod compute_budget; pub mod deserialize_utils; -pub mod ed25519_instruction; pub mod entrypoint; pub mod entrypoint_deprecated; pub mod epoch_info; @@ -120,6 +119,12 @@ pub use solana_bn254 as alt_bn128; pub use solana_decode_error as decode_error; #[deprecated(since = "2.1.0", note = "Use `solana-derivation-path` crate instead")] pub use solana_derivation_path as derivation_path; +#[cfg(feature = "full")] +#[deprecated( + since = "2.2.0", + note = "Use `solana-ed25519-instructions` crate instead" +)] +pub use solana_ed25519_instructions as ed25519_instruction; #[deprecated(since = "2.1.0", note = "Use `solana-feature-set` crate instead")] pub use solana_feature_set as feature_set; #[deprecated(since = "2.2.0", note = "Use `solana-fee-structure` crate instead")] From 3f17f9c19cfa09645046e79909910645e30a39df Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Wed, 16 Oct 2024 13:09:50 +0400 Subject: [PATCH 2/7] missing feature activation --- sdk/ed25519-instructions/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/ed25519-instructions/Cargo.toml b/sdk/ed25519-instructions/Cargo.toml index 79f41efc8c7528..312b197d270ea0 100644 --- a/sdk/ed25519-instructions/Cargo.toml +++ b/sdk/ed25519-instructions/Cargo.toml @@ -14,7 +14,7 @@ bytemuck = { workspace = true } bytemuck_derive = { workspace = true } ed25519-dalek = { workspace = true } solana-feature-set = { workspace = true } -solana-instruction = { workspace = true } +solana-instruction = { workspace = true, features = ["std"] } solana-precompile-error = { workspace = true } [package.metadata.docs.rs] From 5a18faf3b958d6713c2e41a240f26828b6915266 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Mon, 28 Oct 2024 14:42:22 +0400 Subject: [PATCH 3/7] fix imports and deps --- Cargo.lock | 7 +++++++ programs/sbf/Cargo.lock | 14 ++++++++++++++ sdk/Cargo.toml | 2 ++ sdk/ed25519-instructions/Cargo.toml | 12 ++++++++++-- sdk/ed25519-instructions/src/lib.rs | 23 +++++++++++++++-------- 5 files changed, 48 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 05e54ea9cbd79d..02472798cfe7ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6817,9 +6817,15 @@ dependencies = [ "bytemuck", "bytemuck_derive", "ed25519-dalek", + "hex", + "rand 0.7.3", "solana-feature-set", + "solana-hash", "solana-instruction", + "solana-logger", "solana-precompile-error", + "solana-pubkey", + "solana-sdk", ] [[package]] @@ -8340,6 +8346,7 @@ dependencies = [ "solana-commitment-config", "solana-decode-error", "solana-derivation-path", + "solana-ed25519-instructions", "solana-feature-set", "solana-fee-structure", "solana-frozen-abi", diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index d705475746e296..d3ee5fb21becd0 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5459,6 +5459,19 @@ dependencies = [ "solana-sdk", ] +[[package]] +name = "solana-ed25519-instructions" +version = "2.1.0" +dependencies = [ + "bytemuck", + "bytemuck_derive", + "ed25519-dalek", + "solana-feature-set", + "solana-instruction", + "solana-precompile-error", + "solana-pubkey", +] + [[package]] name = "solana-entry" version = "2.2.0" @@ -7062,6 +7075,7 @@ dependencies = [ "solana-commitment-config", "solana-decode-error", "solana-derivation-path", + "solana-ed25519-instructions", "solana-feature-set", "solana-fee-structure", "solana-inflation", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 8d9f1225701eba..2475950c971c9d 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -35,6 +35,7 @@ full = [ "digest", "solana-pubkey/rand", "dep:solana-cluster-type", + "dep:solana-ed25519-instructions", "dep:solana-keypair", "dep:solana-precompile-error", "dep:solana-presigner", @@ -104,6 +105,7 @@ solana-cluster-type = { workspace = true, features = [ solana-commitment-config = { workspace = true, optional = true, features = ["serde"] } solana-decode-error = { workspace = true } solana-derivation-path = { workspace = true } +solana-ed25519-instructions = { workspace = true, optional = true } solana-feature-set = { workspace = true } solana-fee-structure = { workspace = true, features = ["serde"] } solana-frozen-abi = { workspace = true, optional = true, features = [ diff --git a/sdk/ed25519-instructions/Cargo.toml b/sdk/ed25519-instructions/Cargo.toml index 312b197d270ea0..d628183664e9fe 100644 --- a/sdk/ed25519-instructions/Cargo.toml +++ b/sdk/ed25519-instructions/Cargo.toml @@ -1,7 +1,7 @@ [package] -name = "solana-ed25519-instruction" +name = "solana-ed25519-instructions" description = "Instructions for the Solana ed25519 native program" -documentation = "https://docs.rs/solana-ed25519-instruction" +documentation = "https://docs.rs/solana-ed25519-instructions" version = { workspace = true } authors = { workspace = true } repository = { workspace = true } @@ -16,6 +16,14 @@ ed25519-dalek = { workspace = true } solana-feature-set = { workspace = true } solana-instruction = { workspace = true, features = ["std"] } solana-precompile-error = { workspace = true } +solana-pubkey = { workspace = true } + +[dev-dependencies] +hex = { workspace = true } +rand0-7 = { workspace = true } +solana-hash = { workspace = true } +solana-logger = { workspace = true } +solana-sdk = { path = ".." } [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/sdk/ed25519-instructions/src/lib.rs b/sdk/ed25519-instructions/src/lib.rs index 85a691a7755e4f..0c8bedb071cfd6 100644 --- a/sdk/ed25519-instructions/src/lib.rs +++ b/sdk/ed25519-instructions/src/lib.rs @@ -9,6 +9,7 @@ use { solana_feature_set::{ed25519_precompile_verify_strict, FeatureSet}, solana_instruction::Instruction, solana_precompile_error::PrecompileError, + solana_pubkey::{pubkey, Pubkey}, }; pub const PUBKEY_SERIALIZED_SIZE: usize = 32; @@ -17,6 +18,8 @@ pub const SIGNATURE_OFFSETS_SERIALIZED_SIZE: usize = 14; // bytemuck requires structures to be aligned pub const SIGNATURE_OFFSETS_START: usize = 2; pub const DATA_START: usize = SIGNATURE_OFFSETS_SERIALIZED_SIZE + SIGNATURE_OFFSETS_START; +// copied from solana_sdk::ed25519_program to avoid solana_sdk dependency +const ED25519_PROGRAM_ID: Pubkey = pubkey!("Ed25519SigVerify111111111111111111111111111"); #[derive(Default, Debug, Copy, Clone, Zeroable, Pod, Eq, PartialEq)] #[repr(C)] @@ -77,7 +80,7 @@ pub fn new_ed25519_instruction(keypair: &ed25519_dalek::Keypair, message: &[u8]) instruction_data.extend_from_slice(message); Instruction { - program_id: solana_sdk::ed25519_program::id(), + program_id: ED25519_PROGRAM_ID, accounts: vec![], data: instruction_data, } @@ -188,15 +191,14 @@ fn get_data_slice<'a>( pub mod test { use { super::*, - crate::{ - ed25519_instruction::new_ed25519_instruction, - hash::Hash, - signature::{Keypair, Signer}, - transaction::Transaction, - }, hex, rand0_7::{thread_rng, Rng}, solana_feature_set::FeatureSet, + solana_hash::Hash, + solana_sdk::{ + signer::{keypair::Keypair, Signer}, + transaction::Transaction, + }, }; pub fn new_ed25519_instruction_raw( @@ -247,7 +249,7 @@ pub mod test { instruction_data.extend_from_slice(message); Instruction { - program_id: solana_sdk::ed25519_program::id(), + program_id: ED25519_PROGRAM_ID, accounts: vec![], data: instruction_data, } @@ -487,4 +489,9 @@ pub mod test { let feature_set = FeatureSet::all_enabled(); assert!(tx.verify_precompiles(&feature_set).is_err()); // verify_strict does NOT pass } + + #[test] + fn test_inlined_program_id() { + assert_eq!(ED25519_PROGRAM_ID, solana_sdk::ed25519_program::id()) + } } From 2dde6035bc45520506d93491fb003309475af18f Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Tue, 29 Oct 2024 23:06:30 +0400 Subject: [PATCH 4/7] update lock file --- Cargo.lock | 2 +- programs/sbf/Cargo.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 02472798cfe7ee..76e29446f23b9a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6811,7 +6811,7 @@ dependencies = [ ] [[package]] -name = "solana-ed25519-instruction" +name = "solana-ed25519-instructions" version = "2.2.0" dependencies = [ "bytemuck", diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index d3ee5fb21becd0..99b3b4bd68f79f 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5461,7 +5461,7 @@ dependencies = [ [[package]] name = "solana-ed25519-instructions" -version = "2.1.0" +version = "2.2.0" dependencies = [ "bytemuck", "bytemuck_derive", From 78ee470147d4ea5309d349830d51e83e91a7bdbc Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Thu, 7 Nov 2024 16:09:37 +0400 Subject: [PATCH 5/7] import program id from solana_sdk_ids --- Cargo.lock | 2 +- programs/sbf/Cargo.lock | 2 +- sdk/ed25519-instructions/Cargo.toml | 2 +- sdk/ed25519-instructions/src/lib.rs | 10 +--------- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 76e29446f23b9a..ee59f1bbdacd0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6824,8 +6824,8 @@ dependencies = [ "solana-instruction", "solana-logger", "solana-precompile-error", - "solana-pubkey", "solana-sdk", + "solana-sdk-ids", ] [[package]] diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 99b3b4bd68f79f..fcf5836ef124f4 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5469,7 +5469,7 @@ dependencies = [ "solana-feature-set", "solana-instruction", "solana-precompile-error", - "solana-pubkey", + "solana-sdk-ids", ] [[package]] diff --git a/sdk/ed25519-instructions/Cargo.toml b/sdk/ed25519-instructions/Cargo.toml index d628183664e9fe..e64032577e39f1 100644 --- a/sdk/ed25519-instructions/Cargo.toml +++ b/sdk/ed25519-instructions/Cargo.toml @@ -16,7 +16,7 @@ ed25519-dalek = { workspace = true } solana-feature-set = { workspace = true } solana-instruction = { workspace = true, features = ["std"] } solana-precompile-error = { workspace = true } -solana-pubkey = { workspace = true } +solana-sdk-ids = { workspace = true } [dev-dependencies] hex = { workspace = true } diff --git a/sdk/ed25519-instructions/src/lib.rs b/sdk/ed25519-instructions/src/lib.rs index 0c8bedb071cfd6..81e7c386ead027 100644 --- a/sdk/ed25519-instructions/src/lib.rs +++ b/sdk/ed25519-instructions/src/lib.rs @@ -9,7 +9,6 @@ use { solana_feature_set::{ed25519_precompile_verify_strict, FeatureSet}, solana_instruction::Instruction, solana_precompile_error::PrecompileError, - solana_pubkey::{pubkey, Pubkey}, }; pub const PUBKEY_SERIALIZED_SIZE: usize = 32; @@ -18,8 +17,6 @@ pub const SIGNATURE_OFFSETS_SERIALIZED_SIZE: usize = 14; // bytemuck requires structures to be aligned pub const SIGNATURE_OFFSETS_START: usize = 2; pub const DATA_START: usize = SIGNATURE_OFFSETS_SERIALIZED_SIZE + SIGNATURE_OFFSETS_START; -// copied from solana_sdk::ed25519_program to avoid solana_sdk dependency -const ED25519_PROGRAM_ID: Pubkey = pubkey!("Ed25519SigVerify111111111111111111111111111"); #[derive(Default, Debug, Copy, Clone, Zeroable, Pod, Eq, PartialEq)] #[repr(C)] @@ -80,7 +77,7 @@ pub fn new_ed25519_instruction(keypair: &ed25519_dalek::Keypair, message: &[u8]) instruction_data.extend_from_slice(message); Instruction { - program_id: ED25519_PROGRAM_ID, + program_id: solana_sdk_ids::ed25519_program::id(), accounts: vec![], data: instruction_data, } @@ -489,9 +486,4 @@ pub mod test { let feature_set = FeatureSet::all_enabled(); assert!(tx.verify_precompiles(&feature_set).is_err()); // verify_strict does NOT pass } - - #[test] - fn test_inlined_program_id() { - assert_eq!(ED25519_PROGRAM_ID, solana_sdk::ed25519_program::id()) - } } From 98983e187c12d06c444b9ad42f9a2cb510b91d2b Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Mon, 11 Nov 2024 17:06:08 +0400 Subject: [PATCH 6/7] use more granular dev deps --- Cargo.lock | 2 ++ sdk/ed25519-instructions/Cargo.toml | 2 ++ sdk/ed25519-instructions/src/lib.rs | 7 +++---- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ee59f1bbdacd0e..7dc59eefb29437 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6822,10 +6822,12 @@ dependencies = [ "solana-feature-set", "solana-hash", "solana-instruction", + "solana-keypair", "solana-logger", "solana-precompile-error", "solana-sdk", "solana-sdk-ids", + "solana-signer", ] [[package]] diff --git a/sdk/ed25519-instructions/Cargo.toml b/sdk/ed25519-instructions/Cargo.toml index e64032577e39f1..27014a646374b7 100644 --- a/sdk/ed25519-instructions/Cargo.toml +++ b/sdk/ed25519-instructions/Cargo.toml @@ -22,8 +22,10 @@ solana-sdk-ids = { workspace = true } hex = { workspace = true } rand0-7 = { workspace = true } solana-hash = { workspace = true } +solana-keypair = { workspace = true } solana-logger = { workspace = true } solana-sdk = { path = ".." } +solana-signer = { workspace = true } [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/sdk/ed25519-instructions/src/lib.rs b/sdk/ed25519-instructions/src/lib.rs index 81e7c386ead027..142d51021aa95a 100644 --- a/sdk/ed25519-instructions/src/lib.rs +++ b/sdk/ed25519-instructions/src/lib.rs @@ -192,10 +192,9 @@ pub mod test { rand0_7::{thread_rng, Rng}, solana_feature_set::FeatureSet, solana_hash::Hash, - solana_sdk::{ - signer::{keypair::Keypair, Signer}, - transaction::Transaction, - }, + solana_keypair::Keypair, + solana_sdk::transaction::Transaction, + solana_signer::Signer, }; pub fn new_ed25519_instruction_raw( From e279e8e7ac51e743fc7da4167745b40731e49291 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Mon, 11 Nov 2024 17:07:36 +0400 Subject: [PATCH 7/7] fix program id in tests --- sdk/ed25519-instructions/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/ed25519-instructions/src/lib.rs b/sdk/ed25519-instructions/src/lib.rs index 142d51021aa95a..8e81aeac903d2d 100644 --- a/sdk/ed25519-instructions/src/lib.rs +++ b/sdk/ed25519-instructions/src/lib.rs @@ -245,7 +245,7 @@ pub mod test { instruction_data.extend_from_slice(message); Instruction { - program_id: ED25519_PROGRAM_ID, + program_id: solana_sdk_ids::ed25519_program::id(), accounts: vec![], data: instruction_data, }