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

Multisig support on invoke helpers #233

Merged
merged 6 commits into from
Feb 28, 2025
Merged

Multisig support on invoke helpers #233

merged 6 commits into from
Feb 28, 2025

Conversation

grod220
Copy link
Contributor

@grod220 grod220 commented Feb 26, 2025

== Bug fix ==

At the moment, these helpers are passing in an empty signers slice to transfer_checked() and transfer_checked_with_fee() to avoid clones. Unfortunately, for multisigs, this improperly adds signer status to the authority_info which causes an permissions escalation error for consumers.

This PR does:

  • Fixes bug where it passes signers to helpers
  • Creates a single internal _invoke_transfer_internal() to reduce redundancy between functions & allow dependency injection
  • Adds unit tests

mint_info.key,
destination_info.key,
authority_info.key,
&[], // add them later, to avoid unnecessary clones
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source of the bug. Signer status is added depending if the accounts are added here. See:

accounts.push(AccountMeta::new_readonly(
*authority_pubkey,
signer_pubkeys.is_empty(),
));

@grod220 grod220 force-pushed the invoke-transfer-bug-fix branch from 1e0c162 to 5f0af83 Compare February 26, 2025 14:24
@grod220 grod220 requested review from joncinque and buffalojoec and removed request for joncinque and buffalojoec February 26, 2025 14:48
@grod220
Copy link
Contributor Author

grod220 commented Feb 27, 2025

Talked to @buffalojoec offline about stubbing the sys calls versus the manual dependency injection pattern. Will re-request when ready 👍

@grod220 grod220 force-pushed the invoke-transfer-bug-fix branch from 5f0af83 to 4b8d38b Compare February 27, 2025 19:18
@grod220 grod220 force-pushed the invoke-transfer-bug-fix branch from 1fedcbb to 44d9478 Compare February 27, 2025 19:28
@grod220 grod220 requested a review from buffalojoec February 28, 2025 14:56
Comment on lines 630 to 647
#[test]
fn test_single_signer() {
test_parameterized_invoke_fns(false, false, false);
}

#[test]
fn test_single_signer_with_fee() {
test_parameterized_invoke_fns(false, true, false);
}

#[test]
fn test_single_signer_with_transfer_hook() {
test_parameterized_invoke_fns(false, false, true);
}

#[test]
fn test_single_signer_with_fee_and_transfer_hook() {
test_parameterized_invoke_fns(false, true, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should consider test_case!

@grod220 grod220 merged commit 14e0a45 into main Feb 28, 2025
19 of 20 checks passed
@grod220 grod220 deleted the invoke-transfer-bug-fix branch February 28, 2025 22:52
@joncinque
Copy link
Contributor

Sorry for the late review, but this looks good! I've been working on using the split-up crates in token-2022, which unfortunately means that we can't use the program stubs, so I refactored the code a little bit to make it testable without the program stubs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants