Skip to content

add CreateAccountAllowPrefund builder#307

Open
rustopian wants to merge 13 commits intoanza-xyz:mainfrom
rustopian:create-account-allow-prefund
Open

add CreateAccountAllowPrefund builder#307
rustopian wants to merge 13 commits intoanza-xyz:mainfrom
rustopian:create-account-allow-prefund

Conversation

@rustopian
Copy link
Contributor

CreateAccountAllowPrefund is now available in solana-system-interface and agave. This adds a builder in pinocchio analogous to the existing system instruction builders.

) -> Result<Self, ProgramError> {
let rent = Rent::from_account_view(rent_sysvar)?;
let required_lamports = rent.try_minimum_balance(space as usize)?;
let lamports = required_lamports.saturating_sub(to.lamports());
Copy link
Contributor Author

@rustopian rustopian Jan 5, 2026

Choose a reason for hiding this comment

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

This does allow a wallet to be bricked with a large lamport balance, which is explicitly the risk developers must avoid when using CreateAccountAllowPrefund.

But measures such as checked_sub here seem inappropriate, since the lamports pre-funded may be a little bit more than required rent, and any defensive check for an arbitrary amount of overage in lamports adds compute.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we document this "risk"?

@rustopian rustopian force-pushed the create-account-allow-prefund branch 2 times, most recently from 6eba538 to a8fc962 Compare January 5, 2026 12:36
@rustopian rustopian force-pushed the create-account-allow-prefund branch from a8fc962 to 9db0e2d Compare January 5, 2026 12:38
@rustopian rustopian requested a review from febo January 5, 2026 13:15
@rustopian rustopian marked this pull request as ready for review January 5, 2026 13:16
@rustopian rustopian changed the title add create_account_allow_prefund add CreateAccountAllowPrefund builder Jan 5, 2026
Comment on lines +24 to +25
/// Funding account and lamports to transfer to the new account.
pub payer_and_lamports: Option<(&'a AccountView, u64)>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wondering whether would be better to keep the same "interface" as CreateAccount or not – i.e., from and lamports as separate fields.

Copy link
Contributor Author

@rustopian rustopian Jan 5, 2026

Choose a reason for hiding this comment

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

I thought about this, but it mirrors the same change elsewhere, and semantically keeps the two together

Up to you tho; will change if you prefer

Copy link
Collaborator

Choose a reason for hiding this comment

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

Make sense. What do you think if we are more explicit about the role of these values?

/// Funding lamports to transfer into a newly created account.
pub struct Funding<'a> {
    /// Funding account.
    pub from: &'a AccountView,

    /// Number of lamports to transfer to the new account.
    pub lamports: u64,
}

Then the field would be:

pub funding: Option<Funding<'a>>,

And you would use as:

CreateAccountPrefund {
    funding: Funding {
        from,
        lamports: 1_000_000_000,
    },
    ...
}

AccountView, Address, ProgramResult,
};

/// Create a new account without the `lamports==0` assertion.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Can we expand a little bit the description?

Suggested change
/// Create a new account without the `lamports==0` assertion.
/// Create a new account, which can be prefunded.
///
/// While [`super::CreateAccount`] can only be used when the account being created has
/// no lamports, `CreatePrefund` relaxes this requirement.

Comment on lines +34 to +35
/// This instruction does not warn if the account has more than enough lamports; large
/// lamport balances can be frozen by `CreateAccountAllowPrefund` if used incorrectly.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Maybe we should put this under a "# Important" section and expand a bit on the risk of "bricking" a wallet account if it is mistakenly passed as the account to create.

Copy link
Collaborator

@febo febo left a comment

Choose a reason for hiding this comment

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

Looks good, left a couple of suggestions to discuss.

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.

2 participants