|
20 | 20 | num_traits::FromPrimitive,
|
21 | 21 | solana_program::{
|
22 | 22 | account_info::AccountInfo,
|
23 |
| - bpf_loader_upgradeable::UpgradeableLoaderState, |
| 23 | + bpf_loader_upgradeable::{ |
| 24 | + self, |
| 25 | + UpgradeableLoaderState, |
| 26 | + }, |
24 | 27 | program::invoke,
|
25 | 28 | program_error::ProgramError,
|
26 | 29 | pubkey::Pubkey,
|
@@ -208,45 +211,28 @@ pub fn is_component_update(cmd_args: &UpdPriceArgs) -> Result<bool, OracleError>
|
208 | 211 | }
|
209 | 212 |
|
210 | 213 |
|
211 |
| -/// These 3 accounts need to get passed to make sure that the upgrade authority is signing the |
212 |
| -/// transaction |
213 |
| -/// - `program_account` is the program at address `program_id`. It just contains a pointer to the |
214 |
| -/// `programdata_account` |
215 |
| -/// - `programdata_account` has an `upgrade_authority_address` field that needs to match |
216 |
| -/// `upgrade_authority.key` |
| 214 | +/// Check that `programdata_account` is actually the buffer for `program_id`. |
| 215 | +/// Check that the authority in `programdata_account` matches `upgrade_authority_account`. |
217 | 216 | pub fn check_is_upgrade_authority_for_program(
|
218 | 217 | upgrade_authority_account: &AccountInfo,
|
219 |
| - program_account: &AccountInfo, |
220 | 218 | programdata_account: &AccountInfo,
|
221 | 219 | program_id: &Pubkey,
|
222 | 220 | ) -> Result<(), ProgramError> {
|
223 |
| - let program_deserialized: UpgradeableLoaderState = |
224 |
| - bincode::deserialize(&program_account.try_borrow_data()?) |
225 |
| - .map_err(|_| OracleError::DeserializationError)?; |
226 | 221 | let programdata_deserialized: UpgradeableLoaderState =
|
227 | 222 | bincode::deserialize(&programdata_account.try_borrow_data()?)
|
228 | 223 | .map_err(|_| OracleError::DeserializationError)?;
|
229 | 224 |
|
230 |
| - // 1. program_account is actually this program's account |
| 225 | + // 1. programdata_account is actually this program's buffer |
| 226 | + let (programdata_address, _) = |
| 227 | + Pubkey::find_program_address(&[&program_id.to_bytes()], &bpf_loader_upgradeable::id()); |
| 228 | + |
231 | 229 | pyth_assert(
|
232 |
| - program_account.key.eq(program_id) && program_account.executable, |
| 230 | + programdata_address.eq(programdata_account.key), |
233 | 231 | OracleError::InvalidUpgradeAuthority.into(),
|
234 | 232 | )?;
|
235 | 233 |
|
236 |
| - // 2. programdata_account is actually this program's buffer |
237 |
| - if let UpgradeableLoaderState::Program { |
238 |
| - programdata_address, |
239 |
| - } = program_deserialized |
240 |
| - { |
241 |
| - pyth_assert( |
242 |
| - programdata_address.eq(programdata_account.key), |
243 |
| - OracleError::InvalidUpgradeAuthority.into(), |
244 |
| - )?; |
245 |
| - } else { |
246 |
| - return Err(OracleError::InvalidUpgradeAuthority.into()); |
247 |
| - } |
248 | 234 |
|
249 |
| - // 3. upgrade_authority_account is actually the authority inside programdata_account |
| 235 | + // 2. upgrade_authority_account is actually the authority inside programdata_account |
250 | 236 | if let UpgradeableLoaderState::ProgramData {
|
251 | 237 | slot: _,
|
252 | 238 | upgrade_authority_address: Some(upgrade_authority_key),
|
|
0 commit comments