Multiplier is incorrectly calculated in Controller
The Controller contract multiplies the entire integral term by i_gain, including the previously accumulated old_i_term, instead of only the new contribution. This makes the multiplier differ from the documented formula and could affect the yin borrowing rate.
In Controller smart contract, due to mistake in multiplication of i_gain, it’s miscalculated and the error occurs. This can lead to a multiplier reflecting an incorrect value and therefore affect yin borrowing rate.
Proof of Concept
According to the multiplier formula, first we calculate p_term. The formula for p_term is following:
p_term = p_gain * error
And that’s done right using the get_p_term_internal() function:
The warden has demonstrated how the formula that is in use by the Controller contradicts the documentation of the project, and namely the specification of the aforementioned formula.
In detail, the specification states:
Note: Please see provided formula in the judge’s original comment.
We are interested in the latter part of the formula, specifically:
Note: Please see provided formula in the judge’s original comment.
The documentation states that k_i stands for the:
gain that is applied to the integral term
The problem highlighted by the warden is that the implementation will calculate the following:
Note: Please see provided formula in the judge’s original comment.
The above corresponds to:
let new_i_term: SignedRay = self.get_i_term_internal();
multiplier += i_gain * new_i_term;
Whereby the get_i_term_internal function will ultimately yield:
Note: please review provided terms in the judge’s original comment.
Based on the above analysis, the documentation indeed contradicts what the code calculates. The Opus team is invited to evaluate this exhibit; however, regardless of the correct behaviour of the system, this submission will be accepted as valid due to the documentation being the “source of truth” during the audit’s duration.
The original report as published on Code4rena, by ABAIKUNANBAEV. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the gain factor i_gain is applied to the whole integral term (including the stored old_i_term) rather than only to the newly computed contribution.
Impact
The multiplier could reflect an incorrect value and therefore affect the yin borrowing rate.
What the attacker needed
None
The fix
The code should be changed so that i_gain multiplies only the new nonlinear-transform contribution inside get_i_term_internal, and the multiplier should add new_i_term without an extra i_gain multiplication.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
A smart contract calculates an interest-like multiplier using a formula with several parts. One part, the integral term, is supposed to have a gain factor applied only to the newly added piece, but the code applies it to the whole running total. This means the number used for borrowing rates can drift from what the designers intended.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.