From 3e5ba8dcaa123e86f5cc3c8ea55beb3dcd9777b3 Mon Sep 17 00:00:00 2001 From: jon-chuang <9093549+jon-chuang@users.noreply.github.com> Date: Fri, 20 Aug 2021 23:32:28 +0800 Subject: [PATCH] bug: `sysvar::Instructions` is not owned by `Sysvar1111111111111111111111111111111111111` (#19242) * Fix instructions sysvar owner * Update feature switch address Co-authored-by: Justin Starry --- programs/bpf/rust/sysvar/src/lib.rs | 2 ++ runtime/src/accounts.rs | 18 ++++++++++++++++-- sdk/src/feature_set.rs | 4 ++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/programs/bpf/rust/sysvar/src/lib.rs b/programs/bpf/rust/sysvar/src/lib.rs index 67a9c19ebe..f5994d09a6 100644 --- a/programs/bpf/rust/sysvar/src/lib.rs +++ b/programs/bpf/rust/sysvar/src/lib.rs @@ -10,6 +10,7 @@ use solana_program::{ msg, program_error::ProgramError, pubkey::Pubkey, + system_program, sysvar::{ self, clock::Clock, epoch_schedule::EpochSchedule, instructions, rent::Rent, slot_hashes::SlotHashes, slot_history::SlotHistory, stake_history::StakeHistory, Sysvar, @@ -46,6 +47,7 @@ pub fn process_instruction( // Instructions msg!("Instructions identifier:"); sysvar::instructions::id().log(); + assert_eq!(*accounts[4].owner, system_program::id()); let index = instructions::load_current_index(&accounts[4].try_borrow_data()?); assert_eq!(0, index); diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index b7fa3ee12e..9d608d7953 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -35,6 +35,7 @@ use solana_sdk::{ native_loader, nonce, nonce::NONCED_TX_MARKER_IX_INDEX, pubkey::Pubkey, + system_program, sysvar, transaction::{Result, SanitizedTransaction, TransactionError}, }; use std::{ @@ -197,12 +198,21 @@ impl Accounts { } } - fn construct_instructions_account(message: &SanitizedMessage) -> AccountSharedData { + fn construct_instructions_account( + message: &SanitizedMessage, + is_owned_by_sysvar: bool, + ) -> AccountSharedData { let mut data = message.serialize_instructions(); // add room for current instruction index. data.resize(data.len() + 2, 0); + let owner = if is_owned_by_sysvar { + sysvar::id() + } else { + system_program::id() + }; AccountSharedData::from(Account { data, + owner, ..Account::default() }) } @@ -243,7 +253,11 @@ impl Accounts { if message.is_writable(i) { return Err(TransactionError::InvalidAccountIndex); } - Self::construct_instructions_account(message) + Self::construct_instructions_account( + message, + feature_set + .is_active(&feature_set::instructions_sysvar_owned_by_sysvar::id()), + ) } else { let (account, rent) = self .accounts_db diff --git a/sdk/src/feature_set.rs b/sdk/src/feature_set.rs index 8641670d1c..0d0cf203a9 100644 --- a/sdk/src/feature_set.rs +++ b/sdk/src/feature_set.rs @@ -30,6 +30,10 @@ pub mod instructions_sysvar_enabled { solana_sdk::declare_id!("EnvhHCLvg55P7PDtbvR1NwuTuAeodqpusV3MR5QEK8gs"); } +pub mod instructions_sysvar_owned_by_sysvar { + solana_sdk::declare_id!("H3kBSaKdeiUsyHmeHqjJYNc27jesXZ6zWj3zWkowQbkV"); +} + pub mod deprecate_rewards_sysvar { solana_sdk::declare_id!("GaBtBJvmS4Arjj5W1NmFcyvPjsHN38UGYDq2MDwbs9Qu"); }