hifi-finance / hifi

Monorepo implementing the Hifi fixed-rate, fixed-term lending protocol
https://app.hifi.finance
Other
105 stars 15 forks source link

Implement a "pow" function with a normalization factor to stave off overflow when time to maturity is large #73

Open PaulRBerg opened 2 years ago

PaulRBerg commented 2 years ago

A "pow" function with a normalization factor would joggle with the numbers in such a way that it staves off overflows when the time to maturity is large.

See Yield's pow function, this PDF document:

And this algorithm explanation:

pow-function-with-normalization-factor
PaulRBerg commented 2 years ago

The catch is that PRBMath, unlike YieldMath, used 256 bits to represent the operands. I'm not sure if this is a show-stopper, in the sense that we can't implement a normalization factor like Yield does for 128 bits numbers.

I guess that in our case we should set f to 2^256-1 but I'm not sure yet.