Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract ed25519-instructions crate #3330

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ members = [
"sdk/cpi",
"sdk/decode-error",
"sdk/derivation-path",
"sdk/ed25519-instructions",
"sdk/epoch-rewards",
"sdk/epoch-schedule",
"sdk/feature-set",
Expand Down Expand Up @@ -432,6 +433,7 @@ solana-decode-error = { path = "sdk/decode-error", version = "=2.2.0" }
solana-define-syscall = { path = "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" }
Expand Down
14 changes: 14 additions & 0 deletions programs/sbf/Cargo.lock

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

2 changes: 2 additions & 0 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ full = [
"solana-commitment-config",
"digest",
"solana-pubkey/rand",
"dep:solana-ed25519-instructions",
"dep:solana-keypair",
"dep:solana-precompile-error",
"dep:solana-presigner",
Expand Down Expand Up @@ -98,6 +99,7 @@ solana-bn254 = { workspace = true }
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 = [
Expand Down
32 changes: 32 additions & 0 deletions sdk/ed25519-instructions/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "solana-ed25519-instructions"
description = "Instructions for the Solana ed25519 native program"
documentation = "https://docs.rs/solana-ed25519-instructions"
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, 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"]

[lints]
workspace = true
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
//!
//! [np]: https://docs.solanalabs.com/runtime/programs#ed25519-program

#![cfg(feature = "full")]

use {
bytemuck::bytes_of,
bytemuck_derive::{Pod, Zeroable},
ed25519_dalek::{ed25519::signature::Signature, Signer, Verifier},
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;
Expand All @@ -19,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)]
Expand Down Expand Up @@ -79,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,
}
Expand Down Expand Up @@ -190,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(
Expand Down Expand Up @@ -249,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,
}
Expand Down Expand Up @@ -489,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())
}
}
7 changes: 6 additions & 1 deletion sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -122,6 +121,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")]
Expand Down
Loading