Skip to content

fix(realloc): handle already funded accounts - #795

Closed
pol-cova wants to merge 1 commit into
solana-foundation:mainfrom
pol-cova:fix/realloc-rent-shortfall
Closed

pol-cova wants to merge 1 commit into
solana-foundation:mainfrom
pol-cova:fix/realloc-rent-shortfall

Conversation

@pol-cova

Copy link
Copy Markdown

Linked issue

What and why

The native and Pinocchio realloc examples panic when an account holds more lamports than its new rent minimum.

Calculate the rent shortfall safely and transfer only when more lamports are needed. Preserve the payer signature check when skipping the transfer.

Add regression tests for exact funding, excess funding, and unsigned-payer rejection. Check account data, balances, and CPI behavior.

No dependency or account-layout changes.

Testing

  • Built both SBF programs with platform-tools v1.58.
  • pnpm test in both affected examples: 6 passing each.
  • TypeScript checks and Prettier passed.
  • Existing Rust tests, rustfmt, and Clippy passed.
  • Confirmed regression tests fail before the fix.

AI disclosure

  • No AI tooling was used beyond editor autocomplete.
  • AI tooling was used. Tool and extent: OpenAI Codex helped
    investigate the bug, and some implementations of the fix.

Transfer rent only when the account needs more lamports.
Keep the payer signature check when skipping transfers.

This prevents subtraction overflow on overfunded accounts
and avoids unnecessary transfers.
@pol-cova
pol-cova requested a review from dev-jodee as a code owner November 11, 2026 16:13

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Every commit in a Solana Foundation repository needs signature verification, and these are unverified:

  • fda8cde fix(realloc): handle already funded accounts

Set up signing, then sign the existing commits (git rebase --exec 'git commit --amend --no-edit -S' main) and force-push. This review is dismissed automatically once every commit verifies.

@github-actions github-actions Bot added the needs-issue PR does not reference an issue a maintainer has accepted label Nov 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hi @pol-cova,

Thanks for the pull request. We ask that every change references an issue a maintainer has accepted, and there isn't one linked here.

These examples are a teaching resource and each one has to stay small enough to read in one sitting, so whether a new example or framework flavor belongs here is worth settling before anyone writes it. Agreeing on the approach in an issue first means nobody writes code that can't be merged. See CONTRIBUTING.md for the full workflow.

Please open an issue describing the change, or comment on the existing one. Once a maintainer has labelled it accepted, put Fixes #<issue> in this description and reopen this pull request; the check runs again and clears itself. Typos, broken links and comment-only fixes are exempt: write Linked issue: trivial instead.

@github-actions github-actions Bot closed this Nov 11, 2026
@greptile-apps

greptile-apps Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Both realloc examples now handle accounts that already hold enough lamports.

  • Realloc keeps funded accounts intact while adding address fields.

Reviews (1) · Last reviewed commit: "fix(realloc): handle already funded acco..." · Reviewed by Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-issue PR does not reference an issue a maintainer has accepted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant