Skip to content

Commit

Permalink
Cli: the authority passed to solana program write-buffer must be a …
Browse files Browse the repository at this point in the history
…proper signer (#29476)

* Fix upgrade signer parsing in program deploy (noop)

* Fix buffer-authority signer parsing in program write-buffer (error on Pubkey input)
  • Loading branch information
CriesofCarrots committed Jan 3, 2023
1 parent 660596f commit 71ba409
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 49 deletions.
55 changes: 16 additions & 39 deletions cli/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub enum ProgramCliCommand {
program_location: String,
buffer_signer_index: Option<SignerIndex>,
buffer_pubkey: Option<Pubkey>,
buffer_authority_signer_index: Option<SignerIndex>,
buffer_authority_signer_index: SignerIndex,
max_len: Option<usize>,
skip_fee_check: bool,
},
Expand Down Expand Up @@ -461,19 +461,9 @@ pub fn parse_program_subcommand(
pubkey_of_signer(matches, "program_id", wallet_manager)?
};

let upgrade_authority_pubkey =
if let Ok((upgrade_authority_signer, Some(upgrade_authority_pubkey))) =
signer_of(matches, "upgrade_authority", wallet_manager)
{
bulk_signers.push(upgrade_authority_signer);
Some(upgrade_authority_pubkey)
} else {
Some(
default_signer
.signer_from_path(matches, wallet_manager)?
.pubkey(),
)
};
let (upgrade_authority, upgrade_authority_pubkey) =
signer_of(matches, "upgrade_authority", wallet_manager)?;
bulk_signers.push(upgrade_authority);

let max_len = value_of(matches, "max_len");

Expand Down Expand Up @@ -512,19 +502,9 @@ pub fn parse_program_subcommand(
pubkey_of_signer(matches, "buffer", wallet_manager)?
};

let buffer_authority_pubkey =
if let Ok((buffer_authority_signer, Some(buffer_authority_pubkey))) =
signer_of(matches, "buffer_authority", wallet_manager)
{
bulk_signers.push(buffer_authority_signer);
Some(buffer_authority_pubkey)
} else {
Some(
default_signer
.signer_from_path(matches, wallet_manager)?
.pubkey(),
)
};
let (buffer_authority, buffer_authority_pubkey) =
signer_of(matches, "buffer_authority", wallet_manager)?;
bulk_signers.push(buffer_authority);

let max_len = value_of(matches, "max_len");

Expand All @@ -537,7 +517,8 @@ pub fn parse_program_subcommand(
buffer_signer_index: signer_info.index_of_or_none(buffer_pubkey),
buffer_pubkey,
buffer_authority_signer_index: signer_info
.index_of_or_none(buffer_authority_pubkey),
.index_of(buffer_authority_pubkey)
.unwrap(),
max_len,
skip_fee_check,
}),
Expand Down Expand Up @@ -1067,7 +1048,7 @@ fn process_write_buffer(
program_location: &str,
buffer_signer_index: Option<SignerIndex>,
buffer_pubkey: Option<Pubkey>,
buffer_authority_signer_index: Option<SignerIndex>,
buffer_authority_signer_index: SignerIndex,
max_len: Option<usize>,
skip_fee_check: bool,
) -> ProcessResult {
Expand All @@ -1083,11 +1064,7 @@ fn process_write_buffer(
buffer_keypair.pubkey(),
)
};
let buffer_authority = if let Some(i) = buffer_authority_signer_index {
config.signers[i]
} else {
config.signers[0]
};
let buffer_authority = config.signers[buffer_authority_signer_index];

if let Some(account) = rpc_client
.get_account_with_commitment(&buffer_pubkey, config.commitment)?
Expand Down Expand Up @@ -2527,7 +2504,7 @@ mod tests {
program_location: "/Users/test/program.so".to_string(),
buffer_signer_index: None,
buffer_pubkey: None,
buffer_authority_signer_index: Some(0),
buffer_authority_signer_index: 0,
max_len: None,
skip_fee_check: false,
}),
Expand All @@ -2551,7 +2528,7 @@ mod tests {
program_location: "/Users/test/program.so".to_string(),
buffer_signer_index: None,
buffer_pubkey: None,
buffer_authority_signer_index: Some(0),
buffer_authority_signer_index: 0,
max_len: Some(42),
skip_fee_check: false,
}),
Expand All @@ -2578,7 +2555,7 @@ mod tests {
program_location: "/Users/test/program.so".to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: Some(0),
buffer_authority_signer_index: 0,
max_len: None,
skip_fee_check: false,
}),
Expand Down Expand Up @@ -2608,7 +2585,7 @@ mod tests {
program_location: "/Users/test/program.so".to_string(),
buffer_signer_index: None,
buffer_pubkey: None,
buffer_authority_signer_index: Some(1),
buffer_authority_signer_index: 1,
max_len: None,
skip_fee_check: false,
}),
Expand Down Expand Up @@ -2643,7 +2620,7 @@ mod tests {
program_location: "/Users/test/program.so".to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: Some(2),
buffer_authority_signer_index: 2,
max_len: None,
skip_fee_check: false,
}),
Expand Down
20 changes: 10 additions & 10 deletions cli/tests/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ fn test_cli_program_write_buffer() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: None,
buffer_pubkey: None,
buffer_authority_signer_index: None,
buffer_authority_signer_index: 0,
max_len: None,
skip_fee_check: false,
});
Expand Down Expand Up @@ -813,7 +813,7 @@ fn test_cli_program_write_buffer() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: None,
buffer_authority_signer_index: 0,
max_len: Some(max_len),
skip_fee_check: false,
});
Expand Down Expand Up @@ -875,7 +875,7 @@ fn test_cli_program_write_buffer() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: Some(2),
buffer_authority_signer_index: 2,
max_len: None,
skip_fee_check: false,
});
Expand Down Expand Up @@ -913,7 +913,7 @@ fn test_cli_program_write_buffer() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: None,
buffer_pubkey: None,
buffer_authority_signer_index: Some(2),
buffer_authority_signer_index: 2,
max_len: None,
skip_fee_check: false,
});
Expand Down Expand Up @@ -987,7 +987,7 @@ fn test_cli_program_write_buffer() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: None,
buffer_pubkey: None,
buffer_authority_signer_index: None,
buffer_authority_signer_index: 0,
max_len: None,
skip_fee_check: false,
});
Expand Down Expand Up @@ -1028,7 +1028,7 @@ fn test_cli_program_write_buffer() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: None,
buffer_authority_signer_index: 0,
max_len: None, //Some(max_len),
skip_fee_check: false,
});
Expand Down Expand Up @@ -1100,7 +1100,7 @@ fn test_cli_program_set_buffer_authority() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: None,
buffer_authority_signer_index: 0,
max_len: None,
skip_fee_check: false,
});
Expand Down Expand Up @@ -1216,7 +1216,7 @@ fn test_cli_program_mismatch_buffer_authority() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: Some(2),
buffer_authority_signer_index: 2,
max_len: None,
skip_fee_check: false,
});
Expand Down Expand Up @@ -1312,7 +1312,7 @@ fn test_cli_program_show() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: Some(2),
buffer_authority_signer_index: 2,
max_len: None,
skip_fee_check: false,
});
Expand Down Expand Up @@ -1499,7 +1499,7 @@ fn test_cli_program_dump() {
program_location: noop_path.to_str().unwrap().to_string(),
buffer_signer_index: Some(1),
buffer_pubkey: Some(buffer_keypair.pubkey()),
buffer_authority_signer_index: Some(2),
buffer_authority_signer_index: 2,
max_len: None,
skip_fee_check: false,
});
Expand Down

0 comments on commit 71ba409

Please sign in to comment.