The program demonstrates Inconsistent Error Handling in its arithmetic operations. Specifically, when performing checked_sub or checked_add, the code sometimes maps None (overflow) to ProgramError::InsufficientFunds and other times to a generic panic or ErrorCode::CalculationOverflow.
While checked_ math prevents the catastrophic "Solana Panic" that halts the program without a message, using the wrong error type (InsufficientFunds vs Overflow) creates significant risks:
Misleading Debugging: Developers or UIs viewing the error will assume the user lacks balance, leading to wasted support time or incorrect user assumptions.
Safety Masking: If an overflow represents a logic bug (e.g., trying to refund more than raised), masking it as "Insufficient Funds" hides the root cause (the math is wrong, not the balance).
Frontend Instability: dApps expecting specific error codes for flow control will break.
Severity: Low
Likelihood: Low
Impact: Low
Impact Details:
Developer Experience: High friction in maintenance.
Client Confusion: Incorrect error messaging to end-users.
A solana-program-test demonstrating the incorrect error return.
Standardize all arithmetic error mapping. Use a dedicated CalculationOverflow (or similar) error for true math errors, and InsufficientFunds only for balance checks.
Code Diff:
The contest is live. Earn rewards by submitting a finding.
Submissions are being reviewed by our AI judge. Results will be available in a few minutes.
View all submissionsThe contest is complete and the rewards are being distributed.