diffMaxMinRuntime gets default value of 0
A state variable in a smart contract is declared but never initialised or updated, so it keeps its default value of zero. Calculations that use it for bucket indexes or sizes therefore either always return zero when multiplying or fail when dividing.
Marginswap
Originally disclosed on Code4rena
uint256 public diffMaxMinRuntime; This variable is never set nor updated so it gets a default value of 0.``diffMaxMinRuntime` with 0 value is making the calculations that use it either always return 0 (when multiplying) or fail (when dividing) when calculating bucket indexes or sizes.
Recommend setting the appropriate value for diffMaxMinRuntime and update it whenever min or max runtime variables change.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
Calculations for bucket indexes or sizes could always return zero or fail, which may break the contract logic that depends on them.
What the attacker needed
None
The fix
It should be fixed by setting an appropriate value for the variable and updating it whenever the min or max runtime variables change.
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.
In many programming languages, a number that is declared but never given a value starts at zero. Here a contract variable meant to hold a runtime difference is left at that default, so any maths that relies on it produces zero or breaks. The author recommends assigning a real value and keeping it in sync.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.