Core arithmetic
545 / 545 bit-precise Kani checks across 13 harnesses, including widened arithmetic, division and square-root transitions.
solmath 0.2.0 · Rust 1.79+
SolMath is a zero-dependency Rust crate for decimal arithmetic, probability, option pricing and DeFi calculations. It uses integer operations at runtime and publishes compute-unit measurements from deployed SBF programs.
cargo add solmathcrates.io SolMath stores each number as an integer scaled by 1,000,000,000,000. The value 1.25 is stored as 1,250,000,000,000. Calculations therefore use integers rather than floating point.
Every public operation checks for overflow. Settlement helpers provide separate floor and ceiling variants, so the caller chooses how a result is rounded.
In the published SBF runs, the log, exponential and normal-CDF functions each had an observed maximum below 1,000 CU. The table also shows averages and maxima for the larger pricing functions.
A figure may cover a single function or a complete benchmark instruction. The last column states which. Your program will have additional transaction costs.
| Operation | Average CU | Observed maximum | Measurement |
|---|---|---|---|
ln_fixed_i | 705 | 808 | math call |
exp_fixed_i | 961 | 992 | math call |
norm_cdf_poly | 960 | 993 | math call |
Black–Scholes + Greeks | 24,717 | 25,650 | standard precision |
Black–Scholes HP + Greeks | 113,177 | 149,925 | high precision |
Arithmetic-Asian / TWAP | 137,997 | 182,458 | math call |
Exponential NIG | 129,872 | 382,441 | full instruction |
American KBI call / put | 381,096 / 371,876 | 390,628 / 390,786 | full instruction |
CU figures come from the published v0.2.0 SBF campaigns. They are not guarantees for an application's complete transaction.
The release repository includes bit-precise arithmetic checks, certificates for selected functions, comparison corpora and SBF measurements. This is internal validation. SolMath has not had an independent third-party audit.
545 / 545 bit-precise Kani checks across 13 harnesses, including widened arithmetic, division and square-root transitions.
The Asian/TWAP, American KBI and NIG tests each include 100,000 production cases and 10,000 adversarial cases.
No independent audit is claimed. The validation and security files state the tested input ranges and the caller's responsibilities.
Checked multiply, divide, square root, rounding and widened intermediate arithmetic at 12 decimal places.
fp_mulfp_divfp_sqrtDoubleWordLogs, exponentials, powers, trigonometry, normal distributions and bivariate probabilities.
ln_fixed_iexp_fixed_inorm_cdfbivariate_normal_cdfEuropean, barrier, Asian/TWAP, American, rainbow and NIG options with Greeks and implied volatility.
bs_fullimplied_volamerican_kbi_pricenig_price_certifiedWeighted-pool swaps, token conversion and explicit payout or collection rounding for settlement code.
weighted_out_given_intoken conversionfloor payoutceil collectionCore arithmetic does not require any pricing model. Disable default features, add the required module, then measure the resulting SBF program.
Open the API reference[dependencies]
solmath = { version = "0.2", default-features = false, features = ["bs"] }use solmath::{fp, fp_mul};
let amount = fp("1250.50")?;
let rate = fp("0.035")?;
let interest = fp_mul(amount, rate)?;Fixed-point arithmetic stores a decimal as an integer plus an agreed scale. SolMath uses 12 decimal places, so 1.25 is represented as 1,250,000,000,000. The decimal point is a convention; runtime operations remain integer operations.
On-chain code needs deterministic results and an explicit rounding policy. Fixed point makes both visible. SolMath also publishes SBF compute-unit measurements so teams can choose a precision tier against a real transaction budget.
No. Core arithmetic and transcendental functions can be used without linking any pricing model. Feature flags let a program include only the capabilities it calls.
SolMath does not claim an independent third-party audit. Its internal release evidence is public: bit-precise Kani checks, reference corpora, certificate summaries, SBF measurements and a documented security contract.
Yes. The runtime crate is no_std, has no dependencies, forbids unsafe Rust and performs no heap allocation, network access or off-chain pricing.