Skip to content

Commit a3ef4b6

Browse files
committed
drop executable code
1 parent ae604b4 commit a3ef4b6

File tree

3 files changed

+15
-49
lines changed

3 files changed

+15
-49
lines changed

program/src/error.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ use {
1313
/// Errors that can be returned by the Config program.
1414
#[derive(Error, Clone, Debug, Eq, PartialEq, FromPrimitive)]
1515
pub enum ConfigError {
16-
/// Instruction changed executable account's data.
17-
#[error("Instruction changed executable account's data")]
18-
ExecutableDataModified,
1916
/// Instruction modified data of a read-only account.
2017
#[error("Instruction modified data of a read-only account")]
2118
ReadonlyDataModified,

program/src/processor.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,12 @@ pub fn process(program_id: &Pubkey, accounts: &[AccountInfo], input: &[u8]) -> P
173173
// rendering the serialized account state unchanged, the program succeeds.
174174
//
175175
// In order to maximize backwards compatibility between the BPF version and
176-
// its original builtin, we add these checks from `TransactionContext` to
177-
// the program directly, to throw even when the data being written is the
176+
// its original builtin, we add this check from `TransactionContext` to the
177+
// program directly, to throw even when the data being written is the same
178178
// same as what's currently in the account.
179179
//
180-
// Unfortunately, the two `InstructionError` variants thrown do not have
181-
// `ProgramError` counterparts, so we mock them out with custom error
182-
// codes.
183-
if config_account.executable {
184-
return Err(ConfigError::ExecutableDataModified.into());
185-
}
180+
// Since the account can never be executable and also owned by the config
181+
// program, we'll just focus on readonly.
186182
if !config_account.is_writable {
187183
return Err(ConfigError::ReadonlyDataModified.into());
188184
}

program/tests/functional.rs

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use {
1010
state::{ConfigKeys, ConfigState},
1111
},
1212
solana_sdk::{
13-
account::{AccountSharedData, WritableAccount},
13+
account::AccountSharedData,
1414
instruction::{AccountMeta, Instruction},
1515
program_error::ProgramError,
1616
pubkey::Pubkey,
@@ -84,7 +84,7 @@ fn test_process_create_ok() {
8484
&[(config, config_account)],
8585
&[
8686
Check::success(),
87-
Check::compute_units(619),
87+
Check::compute_units(616),
8888
Check::account(&config)
8989
.data(
9090
&bincode::serialize(&(ConfigKeys { keys: vec![] }, MyConfig::default()))
@@ -112,7 +112,7 @@ fn test_process_store_ok() {
112112
&[(config, config_account)],
113113
&[
114114
Check::success(),
115-
Check::compute_units(619),
115+
Check::compute_units(616),
116116
Check::account(&config)
117117
.data(&bincode::serialize(&(ConfigKeys { keys }, my_config)).unwrap())
118118
.build(),
@@ -187,7 +187,7 @@ fn test_process_store_with_additional_signers() {
187187
],
188188
&[
189189
Check::success(),
190-
Check::compute_units(3_274),
190+
Check::compute_units(3_271),
191191
Check::account(&config)
192192
.data(&bincode::serialize(&(ConfigKeys { keys }, my_config)).unwrap())
193193
.build(),
@@ -335,7 +335,7 @@ fn test_config_updates() {
335335
(signer0, AccountSharedData::default()),
336336
(signer1, AccountSharedData::default()),
337337
],
338-
&[Check::success(), Check::compute_units(3_274)],
338+
&[Check::success(), Check::compute_units(3_271)],
339339
);
340340

341341
// Use this for next invoke.
@@ -353,7 +353,7 @@ fn test_config_updates() {
353353
],
354354
&[
355355
Check::success(),
356-
Check::compute_units(3_275),
356+
Check::compute_units(3_272),
357357
Check::account(&config)
358358
.data(&bincode::serialize(&(ConfigKeys { keys }, new_config)).unwrap())
359359
.build(),
@@ -466,7 +466,7 @@ fn test_config_update_contains_duplicates_fails() {
466466
(signer0, AccountSharedData::default()),
467467
(signer1, AccountSharedData::default()),
468468
],
469-
&[Check::success(), Check::compute_units(3_274)],
469+
&[Check::success(), Check::compute_units(3_271)],
470470
);
471471

472472
// Attempt update with duplicate signer inputs.
@@ -510,7 +510,7 @@ fn test_config_updates_requiring_config() {
510510
],
511511
&[
512512
Check::success(),
513-
Check::compute_units(3_370),
513+
Check::compute_units(3_367),
514514
Check::account(&config)
515515
.data(&bincode::serialize(&(ConfigKeys { keys: keys.clone() }, my_config)).unwrap())
516516
.build(),
@@ -531,7 +531,7 @@ fn test_config_updates_requiring_config() {
531531
],
532532
&[
533533
Check::success(),
534-
Check::compute_units(3_370),
534+
Check::compute_units(3_367),
535535
Check::account(&config)
536536
.data(&bincode::serialize(&(ConfigKeys { keys }, new_config)).unwrap())
537537
.build(),
@@ -625,7 +625,7 @@ fn test_maximum_keys_input() {
625625
let result = mollusk.process_and_validate_instruction(
626626
&instruction,
627627
&[(config, config_account)],
628-
&[Check::success(), Check::compute_units(25_282)],
628+
&[Check::success(), Check::compute_units(25_279)],
629629
);
630630

631631
// Use this for next invoke.
@@ -638,7 +638,7 @@ fn test_maximum_keys_input() {
638638
let result = mollusk.process_and_validate_instruction(
639639
&instruction,
640640
&[(config, updated_config_account)],
641-
&[Check::success(), Check::compute_units(25_282)],
641+
&[Check::success(), Check::compute_units(25_279)],
642642
);
643643

644644
// Use this for next invoke.
@@ -750,33 +750,6 @@ fn test_safe_deserialize_from_state() {
750750
);
751751
}
752752

753-
// Backwards compatibility test case.
754-
#[test]
755-
fn test_write_same_data_to_executable() {
756-
let mollusk = setup();
757-
758-
let config = Pubkey::new_unique();
759-
let keys = vec![];
760-
761-
// Creates a config account with `MyConfig::default()`.
762-
let mut config_account = create_config_account(&mollusk, keys.clone());
763-
764-
// Make the config account executable.
765-
config_account.set_executable(true);
766-
767-
// Pass the exact same data (`MyConfig::default()`) to the instruction,
768-
// which we'll attempt to write into the account.
769-
let instruction = config_instruction::store(&config, true, keys.clone(), &MyConfig::default());
770-
771-
mollusk.process_and_validate_instruction(
772-
&instruction,
773-
&[(config, config_account)],
774-
&[Check::err(ProgramError::Custom(
775-
ConfigError::ExecutableDataModified as u32,
776-
))],
777-
);
778-
}
779-
780753
// Backwards compatibility test case.
781754
#[test]
782755
fn test_write_same_data_to_readonly() {

0 commit comments

Comments
 (0)