Skip to content
This repository has been archived by the owner on May 18, 2023. It is now read-only.

Latest commit

 

History

History
18 lines (13 loc) · 1.04 KB

README.md

File metadata and controls

18 lines (13 loc) · 1.04 KB

better-secret-math

This package works with ethnum and prb-math to implement efficient fixed-point math that works with numbers which are considered to have 18 trailing decimals. The criterion crate is used for benchmarking, and it has shown a performance boost of 2x to 3x in most cases (though this has yet to be tested to see if it translates into lower gas costs).

This crate was made to only work with Secret Cosmwasm v1.

Usage

better-secret-math = { git = "https://github.com/securesecrets/better-secret-math" }

Sample Performance Differences

muldiv vs multiply_ratio

mul

In the one above, we perform 4 multiplication operations using:

  • unchecked U256
  • converting from Uint256 -> doing checked U256 -> converting back to Uint256
  • converting from Uint256 -> unchecked U256 -> converting back to Uint256
  • checked Uint256 (this is the same as unchecked Uint256 since the Mul impl for this type uses checked_mul in it)