Skip to content

Adds unchecked calls to system program #130

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

redmannequin
Copy link

@redmannequin redmannequin commented Apr 11, 2025

Problem

The predefined solana programs(system, token, etc.) only expose invoke and invoke_signed calls. It would be nice to have unsafe calls as well.

Solution

  • Adds Invoke trait that contains default implementations for 'invoke' and 'invoke_signed' as well as for the unsafe counter parts.
  • Invoke is auto implemented for any type that can convert into InvokeParts which contains all the necessary information to run an invoke call.
  • Implements From<T> for InvokeParts for all instructions

NOTES

@redmannequin redmannequin force-pushed the add-unchecked-calls-to-system-program branch from 96fb12e to 60d4104 Compare April 11, 2025 23:54
@redmannequin redmannequin force-pushed the add-unchecked-calls-to-system-program branch from 60d4104 to 755df53 Compare April 11, 2025 23:56
/// callee, then Rust's aliasing rules will be violated and cause undefined
/// behavior.
pub unsafe fn invoke_signed_access_unchecked<const ACCOUNTS: usize>(
instruction: &Instruction,
Copy link
Author

@redmannequin redmannequin Apr 14, 2025

Choose a reason for hiding this comment

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

It could be worth creating a FixedInstruction variant that takes in const generic for the account metas length. constraining the number of accounts to account metas at type level/compile time.

@redmannequin redmannequin marked this pull request as ready for review April 15, 2025 08:24
@redmannequin redmannequin changed the title WIP: add unchecked calls to system program Adds unchecked calls to system program Apr 15, 2025
///
/// `InvokeParts` is a helper structure that encapsulates all parts of a Solana instruction call,
/// including the program ID, account references, account metadata, and the instruction data payload.
pub struct InvokeParts<'a, const ACCOUNTS: usize, Data> {
Copy link
Author

Choose a reason for hiding this comment

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

I don't think this should live in the SDK -- perhaps a pinocchio-client-helpers crate?

But for now let's just copy the trait + types into the other clients and see if it generalizes well?

Copy link
Author

Choose a reason for hiding this comment

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

we'll need at least one more InstructionData for slices

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.

1 participant