Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing check_number_of_instruction_accounts() in StakeInstruction::Authorize #23672

Merged
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
39 changes: 26 additions & 13 deletions programs/stake/src/stake_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ pub fn process_instruction(
me.initialize(&authorized, &lockup, &rent)
}
StakeInstruction::Authorize(authorized_pubkey, stake_authorize) => {
instruction_context.check_number_of_instruction_accounts(3)?;
let require_custodian_for_locked_stake_authorize = invoke_context
.feature_set
.is_active(&feature_set::require_custodian_for_locked_stake_authorize::id());
Expand Down Expand Up @@ -1501,6 +1502,11 @@ mod tests {
is_signer: false,
is_writable: false,
},
AccountMeta {
pubkey: authority_address,
is_signer: false,
is_writable: false,
},
];

// should fail, uninit
Expand Down Expand Up @@ -1567,11 +1573,7 @@ mod tests {

// Test a second authorization by the new authority_address
instruction_accounts[0].is_signer = false;
instruction_accounts.push(AccountMeta {
pubkey: authority_address,
is_signer: true,
is_writable: false,
});
instruction_accounts[2].is_signer = true;
let accounts = process_instruction(
&serialize(&StakeInstruction::Authorize(
authority_address_2,
Expand Down Expand Up @@ -1666,6 +1668,11 @@ mod tests {
is_signer: false,
is_writable: false,
},
AccountMeta {
pubkey: authority_address,
is_signer: false,
is_writable: false,
},
];

// Authorize a staker pubkey and move the withdrawer key into cold storage.
Expand All @@ -1683,11 +1690,7 @@ mod tests {

// Attack! The stake key (a hot key) is stolen and used to authorize a new staker.
instruction_accounts[0].is_signer = false;
instruction_accounts.push(AccountMeta {
pubkey: authority_address,
is_signer: true,
is_writable: false,
});
instruction_accounts[2].is_signer = true;
let accounts = process_instruction(
&serialize(&StakeInstruction::Authorize(
mallory_address,
Expand All @@ -1714,7 +1717,7 @@ mod tests {

// Verify the withdrawer (pulled from cold storage) can save the day.
instruction_accounts[0].is_signer = true;
instruction_accounts.pop();
instruction_accounts[2].is_signer = false;
let accounts = process_instruction(
&serialize(&StakeInstruction::Authorize(
authority_address,
Expand All @@ -1729,11 +1732,11 @@ mod tests {

// Attack! Verify the staker cannot be used to authorize a withdraw.
instruction_accounts[0].is_signer = false;
instruction_accounts.push(AccountMeta {
instruction_accounts[2] = AccountMeta {
pubkey: mallory_address,
is_signer: true,
is_writable: false,
});
};
process_instruction(
&serialize(&StakeInstruction::Authorize(
authority_address,
Expand Down Expand Up @@ -1973,6 +1976,11 @@ mod tests {
is_signer: false,
is_writable: false,
},
AccountMeta {
pubkey: authority_address,
is_signer: false,
is_writable: false,
},
],
Ok(()),
);
Expand Down Expand Up @@ -3571,6 +3579,11 @@ mod tests {
is_signer: false,
is_writable: false,
},
AccountMeta {
pubkey: authorized_address,
is_signer: false,
is_writable: false,
},
],
Ok(()),
);
Expand Down