Skip to content

feat(v2): Compile-time required constraints for AnchorAccount#4503

Open
chop0 wants to merge 1 commit into
otter-sec:anchor-nextfrom
chop0:custom-account-constraints
Open

feat(v2): Compile-time required constraints for AnchorAccount#4503
chop0 wants to merge 1 commit into
otter-sec:anchor-nextfrom
chop0:custom-account-constraints

Conversation

@chop0
Copy link
Copy Markdown

@chop0 chop0 commented May 2, 2026

Custom AnchorAccount types can now declare a type-level list of AccountConstraint markers that every #[account(...)] usage must apply. The derive macro emits a const-block superset assertion per field; missing required constraints fail to compile.

  • traits.rs: ConstraintList, Find<C, Idx> (frunk Here/There index trick), IsSuperset<R, I>, plus required_constraints![] helper macro.
  • AnchorAccount gains type RequiredConstraints: ConstraintList. Built-in wrappers default to (); Box forwards from inner T.
  • derive: per-field assertion built from attrs.namespaced and spliced beside the impl TryAccounts block.
  • tests-v2/programs/custom-constraints: TestAccount (1 required) and TestMultiAccount (2 required) wrappers + handlers covering single, multi (reverse-order), Box forwarding, update(...) satisfaction.
  • tests-v2/tests/ui_required_constraints: trybuild compile-fail snapshots for missing and partial requirements.

Custom AnchorAccount types can now declare a type-level list of
AccountConstraint markers that every #[account(...)] usage must apply.
The derive macro emits a const-block superset assertion per field;
missing required constraints fail to compile.

- traits.rs: ConstraintList, Find<C, Idx> (frunk Here/There index trick),
  IsSuperset<R, I>, plus required_constraints![] helper macro.
- AnchorAccount gains `type RequiredConstraints: ConstraintList`.
  Built-in wrappers default to (); Box<T> forwards from inner T.
- derive: per-field assertion built from attrs.namespaced and spliced
  beside the impl TryAccounts block.
- tests-v2/programs/custom-constraints: TestAccount<T> (1 required) and
  TestMultiAccount<T> (2 required) wrappers + handlers covering single,
  multi (reverse-order), Box<TestAccount> forwarding, update(...)
  satisfaction.
- tests-v2/tests/ui_required_constraints: trybuild compile-fail snapshots
  for missing and partial requirements.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 2, 2026

@chop0 is attempting to deploy a commit to the Solana Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@jamie-osec
Copy link
Copy Markdown
Collaborator

Can you fix the compile-fail test issues?

@eteen12
Copy link
Copy Markdown
Contributor

eteen12 commented May 14, 2026

@chop0 id be happy to help with the compile tests if you want, i saw in the discord u were gonna take a look this morning, but if you want me to help out let me know

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