Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Cli: the authority passed to solana program write-buffer must be a proper signer #29476

Merged
merged 2 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2565,7 +2542,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 @@ -2589,7 +2566,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 @@ -2616,7 +2593,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 @@ -2646,7 +2623,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 @@ -2681,7 +2658,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