bug: `sysvar::Instructions` is not owned by `Sysvar1111111111111111111111111111111111111` (#19242)

* Fix instructions sysvar owner

* Update feature switch address

Co-authored-by: Justin Starry <justin@solana.com>
This commit is contained in:
jon-chuang 2021-08-20 23:32:28 +08:00 committed by GitHub
parent 3be5715f45
commit 3e5ba8dcaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View File

@ -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);

View File

@ -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

View File

@ -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");
}