Skip to main content

Module graph

Module graph 

Source
Expand description

Composable Validation Pipeline.

Three layers of validation composition:

  1. Atomic rulesfn pointers and closures (combinators). ValidationGraph stores fn pointers for static rule sets. require_signer_at() and friends return closures for inline use.

  2. Named groups and bundlesValidationGroup bundles related rules under a label for reuse. ValidationBundle composes groups into a single check. TransitionRulePack dispatches rules by instruction tag.

  3. Post-mutation checksPostMutationValidator holds 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§

AccountConstraint
A builder for constructing validation constraints on a single account.
PostMutationValidator
Collects post-mutation checks that run after instruction execution.
TransactionConstraint
Transaction-level constraint that validates global properties.
TransitionRulePack
Associates validation rules with specific instruction tags.
ValidationBundle
A bundle that composes multiple ValidationGroups into a single check.
ValidationContext
Context passed to each validation node.
ValidationGraph
A stack-allocated validation graph with up to N nodes.
ValidationGroup
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 min lamports.
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§

InstructionTag
Instruction dispatch tag for associating validation rules with specific instructions.
PostMutationFn
Signature for a post-mutation check function.
ValidateFn
A validation function signature.