Submitted by rvierdiiev, also found by bin2chen, evan, and ladboy233
LienToken._payment function increases users debt. Every time when user pays not whole lien amount then interests are added to the loan amount, so next time user pays interests based on interests.
LienToken._payment is used by LienToken.makePayment function that allows borrower to repay part or all his debt.
https://github.com/code-423n4/2023-01-astaria/blob/main/src/LienToken.sol#L790-L853
The main problem is in line 826. stack.point.amount = owed.safeCastTo88();
https://github.com/code-423n4/2023-01-astaria/blob/main/src/LienToken.sol#L826
Here stack.point.amount becomes stack.point.amount + accrued interests, because owed is loan amount + accrued interests by this time.
stack.point.amount is the amount that user borrowed. So actually that line has just increased users debt. And in case if he didnt pay all amount of lien, then next time he will pay more interests, because interests depend on loan amount.
In the docs Astaria protocol claims that:
https://docs.astaria.xyz/docs/protocol-mechanics/loanterms
You can check that inside Interest rate section.
However _payment function is compounding interests.
To avoid this, another field interestsAccrued should be introduced which will track already accrued interests.
VsCode
You need to store accrued interests by the moment of repayment to another variable interestsAccrued.
And calculate _getInterest functon like this.
SantiagoGregory (Astaria) acknowledged and commented via duplicate issue #574:
Picodes (judge) commented via duplicate issue #574
