Skip to content

Commit

Permalink
Avoid entropy sources when constructing a solana_program::message::Me…
Browse files Browse the repository at this point in the history
…ssage.

The solana-program crate can be used in certain embedded environments (HSMs) where
the source of entropy, whether used for cryptographic purposes or not, is tightly
controlled. In these cases, using the default OS source of entrophy is not always
acceptable. Thus, using the default Rust stdlib entropy source for seeding its
default hasher, is prohibited. This means any use of HashMap/HashSet must be able
to be constructed and used with a custom hasher implementation.

This commit removes the use of Itertools::unique() to dedupe Instructions that are
being compiled into a new Message, which uses a default-configured HashMap
under-the-hood. Instead, we use a BTreeSet which does not invoke any entropy
source in order to seed a hash implementation.
  • Loading branch information
Jarred Nicholls authored and mvines committed Dec 8, 2021
1 parent f0acf76 commit 4da435f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sdk/program/src/message/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ use {
},
short_vec, system_instruction, system_program, sysvar,
},
itertools::Itertools,
lazy_static::lazy_static,
std::{convert::TryFrom, str::FromStr},
std::{collections::BTreeSet, convert::TryFrom, str::FromStr},
};

lazy_static! {
Expand Down Expand Up @@ -159,10 +158,11 @@ fn get_keys(instructions: &[Instruction], payer: Option<&Pubkey>) -> Instruction

/// Return program ids referenced by all instructions. No duplicates and order is preserved.
fn get_program_ids(instructions: &[Instruction]) -> Vec<Pubkey> {
let mut set = BTreeSet::new();
instructions
.iter()
.map(|ix| ix.program_id)
.unique()
.filter(|&program_id| set.insert(program_id))
.collect()
}

Expand Down

0 comments on commit 4da435f

Please sign in to comment.