Remove native id check in pda creation (#19595)

This commit is contained in:
Jack May
2021-09-07 14:44:52 -07:00
committed by GitHub
parent a0552e5b46
commit 529fefc7cc
4 changed files with 84 additions and 89 deletions

View File

@ -1,8 +1,5 @@
#![allow(clippy::integer_arithmetic)]
use crate::{
bpf_loader, bpf_loader_deprecated, config, decode_error::DecodeError, feature, hash::hashv,
secp256k1_program, stake, system_program, sysvar, vote,
};
use crate::{decode_error::DecodeError, hash::hashv};
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use num_derive::{FromPrimitive, ToPrimitive};
@ -214,10 +211,6 @@ impl Pubkey {
}
}
if program_id.is_native_program_id() {
return Err(PubkeyError::IllegalOwner);
}
// Perform the calculation inline, calling this from within a program is
// not supported
#[cfg(not(target_arch = "bpf"))]
@ -368,22 +361,6 @@ impl Pubkey {
#[cfg(not(target_arch = "bpf"))]
crate::program_stubs::sol_log(&self.to_string());
}
pub fn is_native_program_id(&self) -> bool {
let all_program_ids = [
bpf_loader::id(),
bpf_loader_deprecated::id(),
feature::id(),
config::program::id(),
stake::program::id(),
stake::config::id(),
vote::program::id(),
secp256k1_program::id(),
system_program::id(),
sysvar::id(),
];
all_program_ids.contains(self)
}
}
impl AsRef<[u8]> for Pubkey {
@ -600,20 +577,6 @@ mod tests {
}
}
#[test]
fn test_is_native_program_id() {
assert!(bpf_loader::id().is_native_program_id());
assert!(bpf_loader_deprecated::id().is_native_program_id());
assert!(config::program::id().is_native_program_id());
assert!(feature::id().is_native_program_id());
assert!(secp256k1_program::id().is_native_program_id());
assert!(stake::program::id().is_native_program_id());
assert!(stake::config::id().is_native_program_id());
assert!(system_program::id().is_native_program_id());
assert!(sysvar::id().is_native_program_id());
assert!(vote::program::id().is_native_program_id());
}
fn pubkey_from_seed_by_marker(marker: &[u8]) -> Result<Pubkey, PubkeyError> {
let key = Pubkey::new_unique();
let owner = Pubkey::default();

View File

@ -199,10 +199,14 @@ pub mod ed25519_program_enabled {
solana_sdk::declare_id!("E1TvTNipX8TKNHrhRC8SMuAwQmGY58TZ4drdztP3Gxwc");
}
pub mod allow_native_ids {
solana_sdk::declare_id!("GVnDbNkECwrzLM7aVBGWpBYo3yH1ACaXB4ottNX8pedZ");
}
lazy_static! {
/// Map of feature identifiers to user-visible description
pub static ref FEATURE_NAMES: HashMap<Pubkey, &'static str> = [
(deprecate_rewards_sysvar::id(), "deprecate unused rewards sysvar"),
(deprecate_rewards_sysvar::id(), "deprecate unused rewards sysvar"),
(pico_inflation::id(), "pico inflation"),
(full_inflation::devnet_and_testnet::id(), "full inflation on devnet and testnet"),
(spl_token_v2_multisig_fix::id(), "spl-token multisig fix"),
@ -244,6 +248,7 @@ lazy_static! {
(stake_program_advance_activating_credits_observed::id(), "Enable advancing credits observed for activation epoch #19309"),
(demote_program_write_locks::id(), "demote program write locks to readonly #19593"),
(ed25519_program_enabled::id(), "enable builtin ed25519 signature verify program"),
(allow_native_ids::id(), "allow native program ids in program derived addresses"),
/*************** ADD NEW FEATURES HERE ***************/
]
.iter()