Skip to main content
Sigvex

Program Interface Compliance Remediation

How to fix program interface compliance issues.

Program Interface Compliance Remediation

Overview

Related Detector: Program Interface Compliance

Non-standard interfaces reduce composability. The fix is to follow standard return patterns, use consistent error types, and adopt naming conventions that enable client library generation.

// Consistent interface pattern
pub fn process_instruction(
    program_id: &Pubkey,
    accounts: &[AccountInfo],
    instruction_data: &[u8],
) -> ProgramResult {
    match instruction_data[0] {
        0 => initialize(program_id, accounts, &instruction_data[1..]),
        1 => deposit(program_id, accounts, &instruction_data[1..]),
        _ => Err(ProgramError::InvalidInstructionData),
    }
}

Alternative Mitigations

Use Anchor for Automatic IDL Generation

an account-validation framework programs automatically generate compliant interfaces and IDL files:

#[program]
pub mod my_program {
    pub fn initialize(ctx: Context<Initialize>) -> Result<()> { ... }
    pub fn deposit(ctx: Context<Deposit>, amount: u64) -> Result<()> { ... }
}

Common Mistakes

Mistake: Mixing Error Types

// WRONG: inconsistent error types across instructions
pub fn deposit(...) -> ProgramResult { Err(ProgramError::Custom(1)) }
pub fn withdraw(...) -> Result<()> { Err(error!(MyError::Custom)) }

Use a single error type consistently across all instructions.

References