From d10c09fc3d2e977d38d8c9ef3c72821a19f72933 Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Tue, 28 Mar 2023 11:56:25 -0700 Subject: [PATCH 1/2] Return error early if program is a tombstone --- runtime/src/accounts.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index 8c9ebf90f40bda..f2405558d31f1e 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -300,9 +300,7 @@ impl Accounts { program_accounts: &HashMap, ) -> Result { // Check for tombstone - // Ignoring the tombstone here for now. The loader will catch this condition and return - // error. - let _ignore = match &program.program { + match &program.program { LoadedProgramType::FailedVerification | LoadedProgramType::Closed => { Err(TransactionError::InvalidProgramForExecution) } @@ -311,7 +309,7 @@ impl Accounts { Err(TransactionError::InvalidProgramForExecution) } _ => Ok(()), - }; + }?; // It's an executable program account. The program is already loaded in the cache. // So the account data is not needed. Return a dummy AccountSharedData with meta // information. From 8e195edd3995504b7feaa4e4075a9abeaded6412 Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Wed, 29 Mar 2023 05:20:09 -0700 Subject: [PATCH 2/2] feature gate --- runtime/src/accounts.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index f2405558d31f1e..d58fc338703c89 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -300,7 +300,7 @@ impl Accounts { program_accounts: &HashMap, ) -> Result { // Check for tombstone - match &program.program { + let result = match &program.program { LoadedProgramType::FailedVerification | LoadedProgramType::Closed => { Err(TransactionError::InvalidProgramForExecution) } @@ -309,7 +309,13 @@ impl Accounts { Err(TransactionError::InvalidProgramForExecution) } _ => Ok(()), - }?; + }; + if feature_set.is_active(&simplify_writable_program_account_check::id()) { + // Currently CPI only fails if an execution is actually attempted. With this check it + // would also fail if a transaction just references an invalid program. So the checking + // of the result is being feature gated. + result?; + } // It's an executable program account. The program is already loaded in the cache. // So the account data is not needed. Return a dummy AccountSharedData with meta // information.