diff --git a/Cargo.lock b/Cargo.lock index 0dd1d77c8189c4..dcb0d8590572c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2571,7 +2571,6 @@ version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ - "serde", "typenum", "version_check", ] @@ -5446,6 +5445,15 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-big-array" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11fc7cc2c76d73e0f27ee52abbd64eec84d46f370c88371120433196934e4b7f" +dependencies = [ + "serde", +] + [[package]] name = "serde_bytes" version = "0.11.15" @@ -6986,7 +6994,6 @@ dependencies = [ "bitflags 2.6.0", "bs58", "bv", - "generic-array 0.14.7", "im", "log", "memmap2", @@ -8330,7 +8337,6 @@ dependencies = [ "curve25519-dalek 4.1.3", "digest 0.10.7", "ed25519-dalek", - "generic-array 0.14.7", "getrandom 0.1.16", "hex", "itertools 0.12.1", @@ -8526,17 +8532,21 @@ dependencies = [ name = "solana-signature" version = "2.2.0" dependencies = [ + "bincode", "bs58", "curve25519-dalek 4.1.3", "ed25519-dalek", - "generic-array 0.14.7", "rand 0.8.5", "serde", + "serde-big-array", "serde_derive", + "serde_json", "solana-frozen-abi", "solana-frozen-abi-macro", "solana-program", "solana-sanitize", + "solana-short-vec", + "solana-signature", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 0a69c87500c164..ca41e8d147d636 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -297,7 +297,6 @@ fs_extra = "1.3.0" futures = "0.3.31" futures-util = "0.3.29" gag = "1.0.0" -generic-array = { version = "0.14.7", default-features = false } gethostname = "0.2.3" getrandom = "0.2.10" goauth = "0.13.1" @@ -385,6 +384,7 @@ scopeguard = "1.2.0" semver = "1.0.23" seqlock = "0.2.0" serde = "1.0.215" # must match the serde_derive version, see https://github.com/serde-rs/serde/issues/2584#issuecomment-1685252251 +serde-big-array = "0.5.1" serde_bytes = "0.11.15" serde_derive = "1.0.215" # must match the serde version, see https://github.com/serde-rs/serde/issues/2584#issuecomment-1685252251 serde_json = "1.0.132" diff --git a/core/src/consensus/tower1_7_14.rs b/core/src/consensus/tower1_7_14.rs index fb87a475c520b0..e792d510587abe 100644 --- a/core/src/consensus/tower1_7_14.rs +++ b/core/src/consensus/tower1_7_14.rs @@ -42,7 +42,7 @@ pub struct Tower1_7_14 { #[cfg_attr( feature = "frozen-abi", derive(AbiExample), - frozen_abi(digest = "2ngfAgnN19JwF6FnFYPYp2aHQiZnnjzaYP1vSRMRiSaq") + frozen_abi(digest = "2bgXEjDjQqkHrXtffNA6jusFLNt4rJBMVEsRctYABnn1") )] #[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct SavedTower1_7_14 { diff --git a/core/src/consensus/tower_storage.rs b/core/src/consensus/tower_storage.rs index 6b25ab44292ed2..a84931d9692236 100644 --- a/core/src/consensus/tower_storage.rs +++ b/core/src/consensus/tower_storage.rs @@ -79,7 +79,7 @@ impl From for SavedTowerVersions { #[cfg_attr( feature = "frozen-abi", derive(AbiExample), - frozen_abi(digest = "JBXfVQ6BXHBGSNY919yEkXN4H7XxmAMA7QcGrf7DiWHP") + frozen_abi(digest = "2XiuhmDfRzWGdwZdMbpH5NcjGnTRi9zY1XTNHSknddA7") )] #[derive(Default, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct SavedTower { diff --git a/core/src/repair/serve_repair.rs b/core/src/repair/serve_repair.rs index 426eb00155e03b..1e6b7635a0f5a6 100644 --- a/core/src/repair/serve_repair.rs +++ b/core/src/repair/serve_repair.rs @@ -144,7 +144,7 @@ impl AncestorHashesRepairType { #[cfg_attr( feature = "frozen-abi", derive(AbiEnumVisitor, AbiExample), - frozen_abi(digest = "9SdneX58ekpqLJBzUwfwJsK2fZc9mN4vTcaS4temEjkP") + frozen_abi(digest = "GPS6e6pgUdbXLwXN6XHTqrUVMwAL2YKLPDawgMi5hHzi") )] #[derive(Debug, Deserialize, Serialize)] pub enum AncestorHashesResponse { @@ -225,7 +225,7 @@ pub(crate) type Ping = ping_pong::Ping<[u8; REPAIR_PING_TOKEN_SIZE]>; #[cfg_attr( feature = "frozen-abi", derive(AbiEnumVisitor, AbiExample), - frozen_abi(digest = "3E2R8jiSt9QfVHdX3MgW3UdeNWfor7zNjJcLJLz2K1JY") + frozen_abi(digest = "9KN64WUT7XDYj9zZopS1hztGyAP9y4N4QznsyC4mqsGs") )] #[derive(Debug, Deserialize, Serialize)] pub enum RepairProtocol { @@ -273,7 +273,7 @@ fn discard_malformed_repair_requests( #[cfg_attr( feature = "frozen-abi", derive(AbiEnumVisitor, AbiExample), - frozen_abi(digest = "CpKVYghdpMDRMiGjZpa71dcnB7rCVHLVogZbB3AGDKAK") + frozen_abi(digest = "9A6ae44qpdT7PaxiDZbybMM2mewnSnPs3C4CxhpbbYuV") )] #[derive(Debug, Deserialize, Serialize)] pub(crate) enum RepairResponse { diff --git a/gossip/src/protocol.rs b/gossip/src/protocol.rs index 053a199c053d12..fd874a4401a9ae 100644 --- a/gossip/src/protocol.rs +++ b/gossip/src/protocol.rs @@ -46,7 +46,7 @@ pub(crate) const PULL_RESPONSE_MIN_SERIALIZED_SIZE: usize = 161; #[cfg_attr( feature = "frozen-abi", derive(AbiExample, AbiEnumVisitor), - frozen_abi(digest = "DBz7mUjknfMiea98WMx9b5jYyT9X9bmQV2JxmMN1VggR") + frozen_abi(digest = "D8HvpYCkdo6JweUW61WQ9ZQH2AFvzh3G1qthicnvz4E8") )] #[derive(Serialize, Deserialize, Debug)] #[allow(clippy::large_enum_variant)] diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index af34c3be761c26..7d7742e93108d4 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -1930,7 +1930,6 @@ version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ - "serde", "typenum", "version_check", ] @@ -4596,6 +4595,15 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-big-array" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11fc7cc2c76d73e0f27ee52abbd64eec84d46f370c88371120433196934e4b7f" +dependencies = [ + "serde", +] + [[package]] name = "serde_bytes" version = "0.11.15" @@ -7228,9 +7236,9 @@ version = "2.2.0" dependencies = [ "bs58", "ed25519-dalek", - "generic-array", "rand 0.8.5", "serde", + "serde-big-array", "serde_derive", "solana-sanitize", ] diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index fb69474c16a700..25dd65176aa21d 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -74,10 +74,6 @@ chrono = { workspace = true, features = ["alloc"], optional = true } curve25519-dalek = { workspace = true, optional = true } digest = { workspace = true, optional = true } ed25519-dalek = { workspace = true, optional = true } -generic-array = { workspace = true, features = [ - "serde", - "more_lengths", -], optional = true } itertools = { workspace = true } lazy_static = { workspace = true } libsecp256k1 = { workspace = true, optional = true, features = ["hmac"] } diff --git a/sdk/frozen-abi/Cargo.toml b/sdk/frozen-abi/Cargo.toml index b85de97dee3b0f..8ac0d0282b3b02 100644 --- a/sdk/frozen-abi/Cargo.toml +++ b/sdk/frozen-abi/Cargo.toml @@ -21,7 +21,6 @@ solana-frozen-abi-macro = { workspace = true } thiserror = { workspace = true } [target.'cfg(not(target_os = "solana"))'.dependencies] -generic-array = { workspace = true, features = ["serde", "more_lengths"] } im = { workspace = true, features = ["rayon", "serde"] } memmap2 = { workspace = true } diff --git a/sdk/frozen-abi/src/abi_example.rs b/sdk/frozen-abi/src/abi_example.rs index b20a38e0eeb68c..63b3c1d68c28d6 100644 --- a/sdk/frozen-abi/src/abi_example.rs +++ b/sdk/frozen-abi/src/abi_example.rs @@ -219,15 +219,6 @@ atomic_example_impls! { AtomicI64 } atomic_example_impls! { AtomicIsize } atomic_example_impls! { AtomicBool } -#[cfg(not(target_os = "solana"))] -use generic_array::{ArrayLength, GenericArray}; -#[cfg(not(target_os = "solana"))] -impl> AbiExample for GenericArray { - fn example() -> Self { - Self::default() - } -} - use bv::{BitVec, BlockType}; impl AbiExample for BitVec { fn example() -> Self { diff --git a/sdk/signature/Cargo.toml b/sdk/signature/Cargo.toml index b01518d9692d8e..bf312618a450da 100644 --- a/sdk/signature/Cargo.toml +++ b/sdk/signature/Cargo.toml @@ -12,9 +12,9 @@ edition = { workspace = true } [dependencies] bs58 = { workspace = true } ed25519-dalek = { workspace = true, optional = true } -generic-array = { workspace = true, features = ["more_lengths"] } rand = { workspace = true, optional = true } serde = { workspace = true, optional = true } +serde-big-array = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } solana-frozen-abi = { workspace = true, optional = true, features = [ "frozen-abi", @@ -25,9 +25,14 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = [ solana-sanitize = { workspace = true } [dev-dependencies] +bincode = { workspace = true } curve25519-dalek = { workspace = true } ed25519-dalek = { workspace = true } +serde_derive = { workspace = true } +serde_json = { workspace = true } solana-program = { workspace = true } +solana-short-vec = { workspace = true } +solana-signature = { path = ".", features = ["serde"] } [features] default = ["std"] @@ -37,7 +42,7 @@ frozen-abi = [ "std" ] rand = ["dep:rand"] -serde = ["dep:serde", "dep:serde_derive", "generic-array/serde"] +serde = ["dep:serde", "dep:serde_derive", "dep:serde-big-array"] std = [] verify = ["dep:ed25519-dalek"] diff --git a/sdk/signature/src/lib.rs b/sdk/signature/src/lib.rs index 7e793d75603cf1..30548a665859f8 100644 --- a/sdk/signature/src/lib.rs +++ b/sdk/signature/src/lib.rs @@ -4,19 +4,19 @@ #![cfg_attr(feature = "frozen-abi", feature(min_specialization))] #[cfg(any(test, feature = "verify"))] use core::convert::TryInto; -#[cfg(feature = "serde")] -use serde_derive::{Deserialize, Serialize}; -use { - core::{ - fmt, - str::{from_utf8, FromStr}, - }, - generic_array::{typenum::U64, GenericArray}, +use core::{ + fmt, + str::{from_utf8, FromStr}, }; #[cfg(feature = "std")] extern crate std; #[cfg(feature = "std")] use std::{error::Error, vec::Vec}; +#[cfg(feature = "serde")] +use { + serde_big_array::BigArray, + serde_derive::{Deserialize, Serialize}, +}; /// Number of bytes in a signature pub const SIGNATURE_BYTES: usize = 64; @@ -25,9 +25,17 @@ const MAX_BASE58_SIGNATURE_LEN: usize = 88; #[repr(transparent)] #[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))] +#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] -#[derive(Clone, Copy, Default, Eq, PartialEq, Ord, PartialOrd, Hash)] -pub struct Signature(GenericArray); +pub struct Signature( + #[cfg_attr(feature = "serde", serde(with = "BigArray"))] [u8; SIGNATURE_BYTES], +); + +impl Default for Signature { + fn default() -> Self { + Self([0u8; 64]) + } +} impl solana_sanitize::Sanitize for Signature {} @@ -85,14 +93,14 @@ impl fmt::Display for Signature { impl From for [u8; 64] { fn from(signature: Signature) -> Self { - signature.0.into() + signature.0 } } impl From<[u8; SIGNATURE_BYTES]> for Signature { #[inline] fn from(signature: [u8; SIGNATURE_BYTES]) -> Self { - Self(GenericArray::from(signature)) + Self(signature) } } @@ -156,7 +164,11 @@ impl FromStr for Signature { #[cfg(test)] mod tests { - use {super::*, solana_program::pubkey::Pubkey}; + use { + super::*, + serde_derive::{Deserialize, Serialize}, + solana_program::pubkey::Pubkey, + }; #[test] fn test_off_curve_pubkey_verify_fails() { @@ -178,4 +190,38 @@ mod tests { // can do is `is_err()` here. assert!(signature.verify_verbose(pubkey.as_ref(), &[0u8]).is_err()); } + + #[test] + fn test_short_vec() { + #[derive(Debug, Deserialize, Serialize, PartialEq)] + struct SigShortVec { + #[serde(with = "solana_short_vec")] + pub signatures: Vec, + } + let sig = Signature::from([ + 120, 138, 162, 185, 59, 209, 241, 157, 71, 157, 74, 131, 4, 87, 54, 28, 38, 180, 222, + 82, 64, 62, 61, 62, 22, 46, 17, 203, 187, 136, 62, 43, 11, 38, 235, 17, 239, 82, 240, + 139, 130, 217, 227, 214, 9, 242, 141, 223, 94, 29, 184, 110, 62, 32, 87, 137, 63, 139, + 100, 221, 20, 137, 4, 5, + ]); + let to_serialize = SigShortVec { + signatures: std::vec![sig], + }; + let json_serialized = serde_json::to_string(&to_serialize).unwrap(); + assert_eq!(json_serialized, "{\"signatures\":[[1],[120,138,162,185,59,209,241,157,71,157,74,131,4,87,54,28,38,180,222,82,64,62,61,62,22,46,17,203,187,136,62,43,11,38,235,17,239,82,240,139,130,217,227,214,9,242,141,223,94,29,184,110,62,32,87,137,63,139,100,221,20,137,4,5]]}"); + let json_deserialized: SigShortVec = serde_json::from_str(&json_serialized).unwrap(); + assert_eq!(json_deserialized, to_serialize); + let bincode_serialized = bincode::serialize(&to_serialize).unwrap(); + assert_eq!( + bincode_serialized, + [ + 1, 120, 138, 162, 185, 59, 209, 241, 157, 71, 157, 74, 131, 4, 87, 54, 28, 38, 180, + 222, 82, 64, 62, 61, 62, 22, 46, 17, 203, 187, 136, 62, 43, 11, 38, 235, 17, 239, + 82, 240, 139, 130, 217, 227, 214, 9, 242, 141, 223, 94, 29, 184, 110, 62, 32, 87, + 137, 63, 139, 100, 221, 20, 137, 4, 5 + ] + ); + let bincode_deserialized: SigShortVec = bincode::deserialize(&bincode_serialized).unwrap(); + assert_eq!(bincode_deserialized, to_serialize); + } } diff --git a/sdk/src/transaction/mod.rs b/sdk/src/transaction/mod.rs index f0fdfce2346d45..4d2d0356235aa8 100644 --- a/sdk/src/transaction/mod.rs +++ b/sdk/src/transaction/mod.rs @@ -173,7 +173,7 @@ pub type Result = result::Result; #[cfg_attr( feature = "frozen-abi", derive(AbiExample), - frozen_abi(digest = "686AAhRhjXpqKidmJEdHHcJCL9XxCxebu8Xmku9shp83") + frozen_abi(digest = "GESn6AYYNhpNfzJXdQ6kGjqz4VjpMw3ye9rghqaEqks7") )] #[derive(Debug, PartialEq, Default, Eq, Clone, Serialize, Deserialize)] pub struct Transaction {