Expand description
Composable Validation Pipeline.
Three layers of validation composition:
-
Atomic rules –
fnpointers and closures (combinators).ValidationGraphstoresfnpointers for static rule sets.require_signer_at()and friends return closures for inline use. -
Named groups and bundles –
ValidationGroupbundles related rules under a label for reuse.ValidationBundlecomposes groups into a single check.TransitionRulePackdispatches rules by instruction tag. -
Post-mutation checks –
PostMutationValidatorholds checks that run after account writes. Balance conservation, solvency invariants, authority immutability – anything that needs the final state to verify.
AccountConstraint and TransactionConstraint provide builder-pattern
validation for single accounts and global instruction-level checks.
// Named group for reuse across instructions:
let mut signer_checks = ValidationGroup::<2>::new("signer_checks");
signer_checks.add(validate_authority)?;
signer_checks.add(validate_fee_payer)?;
// Bundle groups together:
let mut bundle = ValidationBundle::<2>::new();
bundle.add(&signer_checks)?;
bundle.add(&tx_constraint)?;
bundle.run(&ctx)?;
// Instruction-specific rules:
let mut rules = TransitionRulePack::<8>::new();
rules.add(0, validate_init)?;
rules.add(1, validate_deposit)?;
rules.run_for(instruction_tag, &ctx)?;
// Post-mutation invariants:
let mut post = PostMutationValidator::<2>::new();
post.add(check_vault_solvent)?;
post.run(accounts, program_id)?;Structs§
- Account
Constraint - A builder for constructing validation constraints on a single account.
- Post
Mutation Validator - Collects post-mutation checks that run after instruction execution.
- Transaction
Constraint - Transaction-level constraint that validates global properties.
- Transition
Rule Pack - Associates validation rules with specific instruction tags.
- Validation
Bundle - A bundle that composes multiple
ValidationGroups into a single check. - Validation
Context - Context passed to each validation node.
- Validation
Graph - A stack-allocated validation graph with up to
Nnodes. - Validation
Group - A named group of validation rules.
Traits§
- Validatable
- Trait for validation runnables (groups and graphs).
Functions§
- require_
all_ unique_ accounts - Validate that all account addresses are unique.
- require_
data_ min - Validate minimum instruction data length.
- require_
keys_ equal - Validate two accounts have the same key (e.g., stored address == provided account).
- require_
lamports_ gte - Validate that an account has at least
minlamports. - require_
owned_ at - Validate that a specific account is owned by the program.
- require_
signer_ at - Validate that a specific account is a signer.
- require_
unique - Validate two accounts are different (no duplicates).
- require_
unique_ signer_ accounts - Validate that no duplicated account is used as a signer.
- require_
unique_ writable_ accounts - Validate that no duplicated account is writable.
- require_
writable_ at - Validate that a specific account is writable.
Type Aliases§
- Instruction
Tag - Instruction dispatch tag for associating validation rules with specific instructions.
- Post
Mutation Fn - Signature for a post-mutation check function.
- Validate
Fn - A validation function signature.