solmath 0.2.0 · deployed SBF medians

ln at 739 CU. Black‑Scholes and all five Greeks at 25,021 CU.

Both figures are medians over 2,000 inputs, measured withsol_log_compute_units immediately around the call. The logarithm has a source-bound all-input error certificate of at most 3 ULP. SolMath uses integer arithmetic at 12 decimal places and has no runtime dependencies.

cargo add solmathcrates.io
≤ 3 ULP all-input ln certificate≤ 2 ULP all-i128 normal CDF certificate545 / 545 bit-precise Kani checks0 runtime dependencies

Fixed-point representation

SolMath fixes the scale at 1,000,000,000,000. In other words, it reads the integer 1,250,000,000,000 as 1.25. Multiplication and division use wider intermediate integers before restoring that scale.

Every public operation returns an error on overflow. Settlement code can choose a floor function for a payout or a ceiling function for a collection, so the rounding rule is clear at the call site.

Decimal value1.250000000000
Stored integer1,250,000,000,000
Runtime arithmeticChecked integers

Compute-unit measurements

Solana measures program work in compute units (CU). A costly logarithm is not a small inconvenience: weighted-pool arithmetic may call it several times before the program has checked an account or moved a token.

The competitor figures below are the retained medians from the last shared localnet harness. SolMath's row uses the final 0.2.0 median. Both measurements put the CU markers immediately around the function call, but they are separate campaigns, so I do not manufacture a fresh speed-up ratio from them.

Natural logarithm — published on-chain median CU
LibraryMedian CU
SolMath 0.2.0739
brine-fp 0.341,815
rust_decimal 1.40.097,188

The shared comparison pins rust_decimal 1.40.0 with its mathsfeature and brine-fp 0.3. Its SolMath build predates 0.2.0, so the SolMath row above comes from the later release sweep. Read the retained comparison

SolMath 0.2.0 — median CU over 2,000 SBF calls
OperationMedian CUMeasurement
ln_fixed_i739standard-precision call
exp_fixed_i962standard-precision call
norm_cdf_poly983standard-precision call
Black–Scholes + all Greeks25,021standard-precision call
Black–Scholes HP + all Greeks112,816high-precision call
Arithmetic-Asian / TWAP161,471practical-domain call
Exponential NIG28,261mixed execution tiers
American KBI call / put382,636 / 382,652math call

These figures bracket the SolMath call; they are not complete transaction costs. Medians describe typical work, not a safe budget. The linked record also gives P95, P99 and maximum values. Read the complete release measurements

Accuracy and proof work

Low CU is of little use if the answer is loose. For 0.2.0, the logarithm has a source-bound all-input certificate of at most 3 ULP, and the normal CDF has an all-i128 certificate of at most 2 ULP. Kani checks the core integer operations over their machine domains. The pricing functions are compared with high-precision and QuantLib references. This is my release work, not an independent audit.

01

Machine arithmetic

545 / 545 bit-precise Kani checks across 13 harnesses, including widened multiplication and division, rounding and square-root transitions.

02

Function bounds

The release certificates bind the active source constants and kernel: at most 3 ULP for ln_fixed_i and 2 ULP for norm_cdf_poly across their stated full domains.

03

Lean boundary

The current Lean work proves the underlying wide-integer multiplication and division mathematics. Its Aeneas correspondence to the production Rust is still unfinished, so I do not describe the crate as formally verified end to end.

Functions and models

See every public function
01

Core arithmetic

Multiplication, division, square roots and rounding at 12 decimal places, with wider integers for intermediate results.

  • fp_mul
  • fp_div
  • fp_sqrt
  • DoubleWord
02

Probability and functions

Logarithms, exponentials, powers, trigonometric functions and one- and two-variable normal probabilities.

  • ln_fixed_i
  • exp_fixed_i
  • norm_cdf
  • bivariate_normal_cdf
03

Pricing models

European, barrier, Asian/TWAP, American, rainbow and NIG options, with price sensitivities (Greeks) and implied volatility.

  • bs_full
  • implied_vol
  • american_kbi_price
  • nig_price_certified
04

DeFi calculations

Weighted-pool swaps, token conversions, and separate round-down and round-up functions for settlement.

  • weighted_out_given_in
  • token conversion
  • floor payout
  • ceil collection

Feature flags

Core arithmetic does not compile any pricing model. Turn off the default features, enable the module you need, then measure the resulting Solana program.

Read the feature documentation
Cargo.tomlBlack–Scholes only
[dependencies]
solmath = { version = "0.2", default-features = false, features = ["bs"] }
arithmetic.rsSCALE = 1e12
use solmath::{fp, fp_mul};

let amount = fp("1250.50")?;
let rate = fp("0.035")?;
let interest = fp_mul(amount, rate)?;

FAQ

What is fixed-point maths?

Fixed-point arithmetic agrees in advance how many digits sit after the decimal point. SolMath uses 12. The integer 1,250,000,000,000 therefore represents 1.25, and the runtime needs no floating-point instructions.

Why use fixed point in a Solana program?

Every validator must obtain the same answer. Integer arithmetic provides that consistency, while the chosen rounding function decides deliberately what happens to a remainder. The published SBF measurements show what these operations cost in the reference programs.

Is SolMath only for financial models?

No. Arithmetic, logarithms, exponentials and probability functions can be used without compiling any pricing model. Cargo feature flags select the extra modules.

Is the crate audited?

No independent auditor has reviewed SolMath. The repository does contain the checks used for the release: bit-precise Kani runs, reference comparisons, certificate summaries, SBF measurements and the security assumptions.

Does SolMath work with no_std?

Yes. The runtime crate is no_std, takes no dependencies, contains no unsafe Rust, and neither allocates on the heap nor calls the network.