Will there be an OpenZeppelin Contracts implementation of exponentiation by squaring algorithm?

@MicahZoltu was asking in a Discord (CryptoDevs) about when there might be an implementation of exponentiation by squaring algorithm in OpenZeppelin Contracts.

In Computing and Accumulating Interest On-Chain (common patterns and their properties) @Austin-Williams talks about the possible opportunity of adding a fixed-precision library to OpenZeppelin Contracts, including an implementation of the exponentiation by squaring algorithm.

1 Like

I believe the plan is to look at adding a fixed point library with basic operations. Once that is done, then consider adding an implementation of exponentiation by squaring. Need to define the semantics of overflow.

@MicahZoltu would be good to have your input on this.

What I want is basically exactly what was described in @Austin-Williams’s presentation. A library that lets me plug in a principal and a time and return a value that is interest accrued since compounded daily. This requires exponentiation by squaring, and that is the hardest part to get right so providing just exponentiation by squaring would be a big help.


@MicahZoltu I created a new post on Designing Fixed Point Math in OpenZeppelin Contracts. While I do intend to have an exponentiation-by-squaring pow function be included, it’ll likely not be part of the initial release, until we settle on the low-level details behind representation.

I’d love to hear your thoughts on it!

1 Like