Machine arithmetic
545 / 545 bit-precise Kani checks across 13 harnesses, including widened multiplication and division, rounding and square-root transitions.
solmath 0.2.0 · deployed SBF medians
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 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.
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.
| Library | Median CU |
|---|---|
SolMath 0.2.0 | 739 |
brine-fp 0.3 | 41,815 |
rust_decimal 1.40.0 | 97,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
| Operation | Median CU | Measurement |
|---|---|---|
ln_fixed_i | 739 | standard-precision call |
exp_fixed_i | 962 | standard-precision call |
norm_cdf_poly | 983 | standard-precision call |
Black–Scholes + all Greeks | 25,021 | standard-precision call |
Black–Scholes HP + all Greeks | 112,816 | high-precision call |
Arithmetic-Asian / TWAP | 161,471 | practical-domain call |
Exponential NIG | 28,261 | mixed execution tiers |
American KBI call / put | 382,636 / 382,652 | math 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
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.
545 / 545 bit-precise Kani checks across 13 harnesses, including widened multiplication and division, rounding and square-root transitions.
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.
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.
Multiplication, division, square roots and rounding at 12 decimal places, with wider integers for intermediate results.
fp_mulfp_divfp_sqrtDoubleWordLogarithms, exponentials, powers, trigonometric functions and one- and two-variable normal probabilities.
ln_fixed_iexp_fixed_inorm_cdfbivariate_normal_cdfEuropean, barrier, Asian/TWAP, American, rainbow and NIG options, with price sensitivities (Greeks) and implied volatility.
bs_fullimplied_volamerican_kbi_pricenig_price_certifiedWeighted-pool swaps, token conversions, and separate round-down and round-up functions for settlement.
weighted_out_given_intoken conversionfloor payoutceil collectionCore 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[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 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.
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.
No. Arithmetic, logarithms, exponentials and probability functions can be used without compiling any pricing model. Cargo feature flags select the extra modules.
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.
Yes. The runtime crate is no_std, takes no dependencies, contains no unsafe Rust, and neither allocates on the heap nor calls the network.