Skip to content
Merged
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
137 changes: 72 additions & 65 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ openssl = "0.10.72"
pairing = "0.23.0"
parking_lot = "0.12"
pbkdf2 = { version = "0.11.0", default-features = false }
proc-macro2 = "1.0.101"
proc-macro2 = "1.0.106"
proptest = "1.9"
qstring = "0.7.2"
qualifier_attr = { version = "0.2.2", default-features = false }
quote = "1.0.41"
quote = "1.0.44"
rand = "0.9.2"
rand_chacha = "0.9.0"
rayon = "1.10.0"
Expand Down Expand Up @@ -327,15 +327,15 @@ static_assertions = "1.1.0"
strum = "0.24"
strum_macros = "0.24"
subtle = "2.6.1"
syn = "2.0.106"
syn = "2.0.114"
tempfile = "3.20.0"
test-case = "3.3.1"
thiserror = { version = "2.0.16", default-features = false }
thiserror = { version = "2.0.18", default-features = false }
tiny-bip39 = "2.0.0"
toml = "0.8.23"
uriparse = "0.6.4"
wasm-bindgen = "0.2.100"
wincode = { version = "0.2.5", features = ["derive"], default-features = false }
wincode = { version = "0.4.1", features = ["derive"], default-features = false }

[profile.release]
split-debuginfo = "unpacked"
Expand Down
8 changes: 4 additions & 4 deletions message/src/compiled_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde_derive::{Deserialize, Serialize};
#[cfg(feature = "frozen-abi")]
use solana_frozen_abi_macro::AbiExample;
#[cfg(feature = "wincode")]
use wincode::{containers, len::ShortU16Len, SchemaRead, SchemaWrite};
use wincode::{containers, len::ShortU16, SchemaRead, SchemaWrite};
use {solana_address::Address, solana_sanitize::Sanitize};

/// A compact encoding of an instruction.
Expand All @@ -26,19 +26,19 @@ pub struct CompiledInstruction {
pub program_id_index: u8,
/// Ordered indices into the transaction keys array indicating which accounts to pass to the program.
#[cfg_attr(feature = "serde", serde(with = "solana_short_vec"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16Len>"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16>"))]
pub accounts: Vec<u8>,
/// The program input data.
#[cfg_attr(feature = "serde", serde(with = "solana_short_vec"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16Len>"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16>"))]
pub data: Vec<u8>,
}

impl Sanitize for CompiledInstruction {}

impl CompiledInstruction {
#[cfg(feature = "wincode")]
pub fn new<T: wincode::SchemaWrite<Src = T>>(
pub fn new<T: wincode::Serialize<Src = T>>(
program_ids_index: u8,
data: &T,
accounts: Vec<u8>,
Expand Down
6 changes: 3 additions & 3 deletions message/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use serde_derive::{Deserialize, Serialize};
#[cfg(feature = "frozen-abi")]
use solana_frozen_abi_macro::{frozen_abi, AbiExample};
#[cfg(feature = "wincode")]
use wincode::{containers, len::ShortU16Len, SchemaRead, SchemaWrite};
use wincode::{containers, len::ShortU16, SchemaRead, SchemaWrite};
use {
crate::{
compiled_instruction::CompiledInstruction, compiled_keys::CompiledKeys,
Expand Down Expand Up @@ -88,7 +88,7 @@ pub struct Message {

/// All the account keys used by this transaction.
#[cfg_attr(feature = "serde", serde(with = "solana_short_vec"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16Len>"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16>"))]
pub account_keys: Vec<Address>,

/// The id of a recent ledger entry.
Expand All @@ -97,7 +97,7 @@ pub struct Message {
/// Programs that will be executed in sequence and committed in one atomic transaction if all
/// succeed.
#[cfg_attr(feature = "serde", serde(with = "solana_short_vec"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16Len>"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16>"))]
pub instructions: Vec<CompiledInstruction>,
}

Expand Down
41 changes: 24 additions & 17 deletions message/src/versions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use {
},
core::mem::MaybeUninit,
wincode::{
config::Config,
io::{Reader, Writer},
ReadResult, SchemaRead, SchemaWrite, WriteResult,
},
Expand Down Expand Up @@ -368,29 +369,35 @@ impl<'de> serde::Deserialize<'de> for VersionedMessage {
}

#[cfg(feature = "wincode")]
impl SchemaWrite for VersionedMessage {
unsafe impl<C: Config> SchemaWrite<C> for VersionedMessage {
type Src = Self;

// V0 and V1 add +1 for message version prefix
#[allow(clippy::arithmetic_side_effects)]
#[inline(always)]
fn size_of(src: &Self::Src) -> WriteResult<usize> {
match src {
VersionedMessage::Legacy(message) => LegacyMessage::size_of(message),
VersionedMessage::V0(message) => Ok(1 + v0::Message::size_of(message)?),
VersionedMessage::Legacy(message) => {
<LegacyMessage as SchemaWrite<C>>::size_of(message)
}
VersionedMessage::V0(message) => {
Ok(1 + <v0::Message as SchemaWrite<C>>::size_of(message)?)
}
VersionedMessage::V1(message) => Ok(1 + message.size()),
}
}

// V0 and V1 add +1 for message version prefix
#[allow(clippy::arithmetic_side_effects)]
#[inline(always)]
fn write(writer: &mut impl Writer, src: &Self::Src) -> WriteResult<()> {
fn write(mut writer: impl Writer, src: &Self::Src) -> WriteResult<()> {
match src {
VersionedMessage::Legacy(message) => LegacyMessage::write(writer, message),
VersionedMessage::Legacy(message) => {
<LegacyMessage as SchemaWrite<C>>::write(writer, message)
}
VersionedMessage::V0(message) => {
u8::write(writer, &MESSAGE_VERSION_PREFIX)?;
v0::Message::write(writer, message)
<u8 as SchemaWrite<C>>::write(&mut writer, &MESSAGE_VERSION_PREFIX)?;
<v0::Message as SchemaWrite<C>>::write(writer, message)
}
VersionedMessage::V1(message) => {
let total = message.size();
Expand All @@ -412,23 +419,23 @@ impl SchemaWrite for VersionedMessage {
}

#[cfg(feature = "wincode")]
impl<'de> SchemaRead<'de> for VersionedMessage {
unsafe impl<'de, C: Config> SchemaRead<'de, C> for VersionedMessage {
type Dst = Self;

fn read(reader: &mut impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>) -> ReadResult<()> {
fn read(mut reader: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>) -> ReadResult<()> {
// If the first bit is set, the remaining 7 bits will be used to determine
// which message version is serialized starting from version `0`. If the first
// is bit is not set, all bytes are used to encode the legacy `Message`
// format.
let variant = u8::get(reader)?;
let variant = <u8 as SchemaRead<C>>::get(&mut reader)?;

if variant & MESSAGE_VERSION_PREFIX != 0 {
use wincode::error::invalid_tag_encoding;

let version = variant & !MESSAGE_VERSION_PREFIX;
return match version {
0 => {
let msg = v0::Message::get(reader)?;
let msg = <v0::Message as SchemaRead<C>>::get(reader)?;
dst.write(VersionedMessage::V0(msg));
Ok(())
}
Expand All @@ -450,21 +457,21 @@ impl<'de> SchemaRead<'de> for VersionedMessage {
}

let mut msg = MaybeUninit::<LegacyMessage>::uninit();
let mut msg_builder = LegacyMessageUninitBuilder::from_maybe_uninit_mut(&mut msg);
let mut msg_builder = LegacyMessageUninitBuilder::<C>::from_maybe_uninit_mut(&mut msg);
// We've already read the variant byte which, in the legacy case, represents
// the `num_required_signatures` field.
// As such, we need to write the remaining fields into the message manually,
// as calling `LegacyMessage::read` will miss the first field.
let mut header_builder =
MessageHeaderUninitBuilder::from_maybe_uninit_mut(msg_builder.uninit_header_mut());
MessageHeaderUninitBuilder::<C>::from_maybe_uninit_mut(msg_builder.uninit_header_mut());
header_builder.write_num_required_signatures(variant);
header_builder.read_num_readonly_signed_accounts(reader)?;
header_builder.read_num_readonly_unsigned_accounts(reader)?;
header_builder.read_num_readonly_signed_accounts(&mut reader)?;
header_builder.read_num_readonly_unsigned_accounts(&mut reader)?;
header_builder.finish();
unsafe { msg_builder.assume_init_header() };

msg_builder.read_account_keys(reader)?;
msg_builder.read_recent_blockhash(reader)?;
msg_builder.read_account_keys(&mut reader)?;
msg_builder.read_recent_blockhash(&mut reader)?;
msg_builder.read_instructions(reader)?;
msg_builder.finish();

Expand Down
12 changes: 6 additions & 6 deletions message/src/versions/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use serde_derive::{Deserialize, Serialize};
#[cfg(feature = "frozen-abi")]
use solana_frozen_abi_macro::AbiExample;
#[cfg(feature = "wincode")]
use wincode::{containers, len::ShortU16Len, SchemaRead, SchemaWrite};
use wincode::{containers, len::ShortU16, SchemaRead, SchemaWrite};
use {
crate::{
compiled_instruction::CompiledInstruction,
Expand Down Expand Up @@ -47,11 +47,11 @@ pub struct MessageAddressTableLookup {
pub account_key: Address,
/// List of indexes used to load writable account addresses
#[cfg_attr(feature = "serde", serde(with = "solana_short_vec"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16Len>"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16>"))]
pub writable_indexes: Vec<u8>,
/// List of indexes used to load readonly account addresses
#[cfg_attr(feature = "serde", serde(with = "solana_short_vec"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16Len>"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16>"))]
pub readonly_indexes: Vec<u8>,
}

Expand All @@ -78,7 +78,7 @@ pub struct Message {

/// List of accounts loaded by this transaction.
#[cfg_attr(feature = "serde", serde(with = "solana_short_vec"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16Len>"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16>"))]
pub account_keys: Vec<Address>,

/// The blockhash of a recent block.
Expand All @@ -98,13 +98,13 @@ pub struct Message {
/// 2) ordered list of keys loaded from `writable` lookup table indexes
/// 3) ordered list of keys loaded from `readable` lookup table indexes
#[cfg_attr(feature = "serde", serde(with = "solana_short_vec"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16Len>"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16>"))]
pub instructions: Vec<CompiledInstruction>,

/// List of address table lookups used to load additional accounts
/// for this transaction.
#[cfg_attr(feature = "serde", serde(with = "solana_short_vec"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16Len>"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16>"))]
pub address_table_lookups: Vec<MessageAddressTableLookup>,
}

Expand Down
9 changes: 5 additions & 4 deletions message/src/versions/v1/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use solana_frozen_abi_macro::AbiExample;
use {
crate::v1::MAX_TRANSACTION_SIZE,
wincode::{
config::ConfigCore,
error::invalid_tag_encoding,
io::{Reader, Writer},
ReadResult, SchemaRead, SchemaWrite, WriteResult,
Expand Down Expand Up @@ -511,7 +512,7 @@ impl Sanitize for Message {
}

#[cfg(feature = "wincode")]
impl SchemaWrite for Message {
unsafe impl<C: ConfigCore> SchemaWrite<C> for Message {
type Src = Self;

#[allow(clippy::arithmetic_side_effects)]
Expand All @@ -522,7 +523,7 @@ impl SchemaWrite for Message {

// V0 and V1 add +1 for message version prefix
#[inline(always)]
fn write(writer: &mut impl Writer, src: &Self::Src) -> WriteResult<()> {
fn write(mut writer: impl Writer, src: &Self::Src) -> WriteResult<()> {
// SAFETY: Serializing a slice of `[u8]`.
unsafe {
writer
Expand All @@ -533,10 +534,10 @@ impl SchemaWrite for Message {
}

#[cfg(feature = "wincode")]
impl<'de> SchemaRead<'de> for Message {
unsafe impl<'de, C: ConfigCore> SchemaRead<'de, C> for Message {
type Dst = Self;

fn read(reader: &mut impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>) -> ReadResult<()> {
fn read(mut reader: impl Reader<'de>, dst: &mut MaybeUninit<Self::Dst>) -> ReadResult<()> {
let bytes = reader.fill_buf(MAX_TRANSACTION_SIZE)?;
let (message, consumed) = deserialize(bytes).map_err(|_| invalid_tag_encoding(1))?;

Expand Down
6 changes: 2 additions & 4 deletions nonce/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,10 @@ mod test {
#[test]
#[cfg(feature = "wincode")]
fn test_nonce_state_size_wincode() {
use wincode::SchemaWrite;

let data = Versions::new(State::Initialized(Data::default()));
assert_eq!(
<Versions as SchemaWrite>::size_of(&data).unwrap(),
State::size()
State::size() as u64,
wincode::serialized_size(&data).unwrap(),
);
}
}
4 changes: 2 additions & 2 deletions transaction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub use {
pub use {
solana_hash::Hash,
solana_signer::{signers::Signers, SignerError},
wincode::{containers, len::ShortU16Len, SchemaRead, SchemaWrite},
wincode::{containers, len::ShortU16, SchemaRead, SchemaWrite},
};
use {
solana_message::inline_nonce::is_advance_nonce_instruction_data,
Expand Down Expand Up @@ -194,7 +194,7 @@ pub struct Transaction {
/// [`num_required_signatures`]: https://docs.rs/solana-message/latest/solana_message/struct.MessageHeader.html#structfield.num_required_signatures
// NOTE: Serialization-related changes must be paired with the direct read at sigverify.
#[cfg_attr(feature = "serde", serde(with = "short_vec"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16Len>"))]
#[cfg_attr(feature = "wincode", wincode(with = "containers::Vec<_, ShortU16>"))]
pub signatures: Vec<Signature>,

/// The message to sign.
Expand Down
Loading