Skip to content

fix(v2): support explicit bumps with init_if_needed#4582

Merged
jamie-osec merged 1 commit into
otter-sec:anchor-nextfrom
abhinavgautam01:fix/2996-init-if-needed-bump
May 26, 2026
Merged

fix(v2): support explicit bumps with init_if_needed#4582
jamie-osec merged 1 commit into
otter-sec:anchor-nextfrom
abhinavgautam01:fix/2996-init-if-needed-bump

Conversation

@abhinavgautam01
Copy link
Copy Markdown
Contributor

Fixes #2996

Summary

  • Allows #[account(init_if_needed, ..., bump = <expr>)] in the v2 derive.
  • Keeps #[account(init, ..., bump = <expr>)] rejected so plain init still uses the canonical bump.
  • Runs explicit-bump PDA verification only on the existing-account branch of init_if_needed.
  • Preserves canonical bump behavior on the create branch, so handlers can store ctx.bumps.<account> for later reuse.

Testing

  • rustfmt --check lang-v2/derive/src/parse.rs tests-v2/programs/constraints/src/lib.rs tests-v2/tests/constraints.rs
  • cargo test -p anchor-derive-accounts-v2 explicit_bump
  • cargo test -p tests-v2 init_if_needed
  • git diff --check

@0x4ka5h 0x4ka5h requested a review from jamie-osec May 25, 2026 14:04
@abhinavgautam01 abhinavgautam01 force-pushed the fix/2996-init-if-needed-bump branch from c988762 to d8487cc Compare May 25, 2026 14:47
Copy link
Copy Markdown
Collaborator

@swaroop-osec swaroop-osec left a comment

Choose a reason for hiding this comment

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

lgtm

@jamie-osec jamie-osec merged commit 55f284d into otter-sec:anchor-next May 26, 2026
41 checks passed
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