Invariants
Each invariant has kit tests for the success path and every revert path; they ship in the program repository under tests/invariants.
| ID | Invariant |
|---|---|
I-1 | A transaction containing a borrow and no matching repay cannot succeed. |
I-2 | Repay amount ≥ borrowed principal + fee, measured as tokens received by the vault. |
I-3 | Borrow invoked from another program always fails. |
I-4 | At most one borrow per transaction, regardless of reserve. |
I-5 | Reserve share price is non-decreasing across any successful transaction. |
I-6 | A frozen reserve rejects borrow but always accepts repay. |
Repay-path review
Scope: wedesak::borrow, wedesak::repay, reserve accounting and the freeze switch. Findings and their status:
| ID | Severity | Finding | Status |
|---|---|---|---|
R-01 | Medium | Repay matched by absolute instruction index could be satisfied by a repay for a different reserve when two loans shared a transaction. | Fixed — one loan per transaction; repay matched by reserve, mint and borrower. |
R-02 | Medium | Token-2022 mints with transfer fees under-credited the vault on repay. | Fixed — vault balance delta is measured, not the instruction amount. |
R-03 | Low | Borrow did not reject a repay placed before it in the transaction. | Fixed — the sysvar walk starts at the borrow's own index. |
R-04 | Informational | Compute units of the sysvar walk grow with transaction length. | Accepted — bounded by the 1,400,000 compute units transaction cap; documented. |
Why these checks
Flash-loan attacks fell from 54% of DeFi losses in 2020 to under 1% in 2025 as protocols hardened against borrowed capital. The remaining risk sits on the lender: in September 2025 a disclosed bug in another lender’s flash-loan flow left more than $160M in deposits exposed until it was patched, with no funds lost. R-01 above is the same class of bug.
Bug bounty
Critical findings that would let a loan leave without repayment are paid from the treasury. Report privately through the security contact listed in the repository’s SECURITY.md; please include a kit test that reproduces the issue. See the error codes for expected reverts.