Skip to main content

Crate truent_solana_macro

Crate truent_solana_macro 

Source
Expand description

Solana invariant enforcement procedural macro.

§#invariant_enforced Attribute Macro

Current status: scaffolding only, not yet enforcing. This macro parses its check-expression arguments and computes a deterministic hash of them (see parse_invariant_checks/compute_check_hash), but generate_check_statements currently emits only comments (// Invariant: <check>) followed by let _ = (); - no assertion, no require, no compile-time validation, no runtime enforcement. Applying this attribute to a function does not change that function’s behavior.

Do not rely on this macro for any security property until real enforcement is implemented; the properties below describe the intended design, not current behavior.

§Intended Security Properties (not yet implemented)

  • Deterministic injection order (alphabetical by state variable)
  • No silent failures (compile error if invariant can’t be resolved)
  • Tamper detection: Hash embedded in generated code comments
  • Type-safe: All injected code type-checked by Rust compiler

§Example

ⓘ
#[invariant_enforced("balance >= 0", "supply == sum_of_balances")]
pub fn transfer(
    from: &mut Account,
    to: &mut Account,
    amount: u64,
) -> ProgramResult {
    from.balance = from.balance.checked_sub(amount)?;
    to.balance = to.balance.checked_add(amount)?;
    // No invariant check is actually injected here yet.
    Ok(())
}

Attribute Macros§

invariant_enforced
Procedural attribute macro, currently scaffolding only - see the module doc comment above. It parses the check expressions given as its arguments but does not currently validate, type-check, or enforce them; applying it to a function is a no-op.