Web3 Lab / Trigonometry Master

Solidity trigonometry, measured against real EVM constraints.

An experimental trigonometry library and benchmark framework for Ethereum-style execution environments—evaluated across gas, precision, bytecode, and Diamond deployment paths.

TRIGπ/4

sin(π/4)
Diamond path

Framework

What Trigonometry Master is

Trigonometry Master is an experimental Solidity trigonometry library, feasibility framework, and Diamond-compatible production-path demonstrator. It studies how binary128-style arithmetic, special-value handling, deployment structure, and gas behavior interact on the EVM without overstating production readiness.

Scope

What it supports

The project combines trigonometric operations with deliberately explicit execution and characterization paths.

01

sin, cos, tan, cot

02

asin, acos, atan

03

ABDK binary128-backed TrigMath facade

04

Diamond-compatible deployment path

05

Direct harness, facet, and production-path benchmarks

06

Raw binary128 edge-case characterization

07

ULP reporting and bytecode-size guardrails

Measured results

Benchmark highlights

Recorded local Hardhat receipt measurements and size figures. They describe this project configuration, not universal mainnet guarantees.

BenchmarkResultConfiguration
sin at π/443,473 gasDiamond-routed local Hardhat receipt
cos at π/442,504 gasDiamond-routed local Hardhat receipt
tan at π/454,827 gasDiamond-routed local Hardhat receipt
cot at π/454,831 gasDiamond-routed local Hardhat receipt
TrigonometryFacet runtime size18,333 bytes6,243 bytes of EIP-170 headroom
TrigonometryFacet deployment4,013,373 gasLocal deployment receipt
Default test suite40 passingCurrent project suite
EIP-170 headroom6,243 bytes

Runtime size is kept below the contract-size limit.

Project budget headroom4,667 bytes

Bytecode budget guardrails are part of the suite.

DiamondCut installation647,863 gas

Recorded local installation receipt.

Evidence

Engineering quality and reproducibility

  • Explicit policy for NaN, infinity, domain boundaries, and poles
  • Signed-zero, subnormal, large finite-value, and raw binary128 edge-case coverage
  • Diamond selector, loupe, access-control, and integration tests
  • High-resolution sin/cos characterization with ULP reporting
  • Bytecode budget tests and production Diamond gas benchmarks
  • Deployment script and direct-vs-Diamond trade-off documentation

What this is / what this is not

What this is

  • Solidity trigonometry and benchmarking framework
  • Web3 numerical-engineering case study
  • EVM gas and bytecode feasibility exploration
  • Diamond deployment-path demonstrator

What this is not

  • An audited production financial-math library
  • Proof that all trigonometric workloads are economical on mainnet
  • A fully binary128 correctly-rounded trigonometric implementation
  • An arbitrary-large-angle Payne–Hanek reducer

Applications

Where it is useful

01

Feasibility decisions

Web3 teams evaluating whether math-heavy smart-contract work is practical within bounded execution paths.

02

Deployment trade-offs

Solidity teams comparing direct execution with Diamond routing and deployment overhead.

03

Numerical research

Research prototypes for EVM numerical computation and bounded on-chain trigonometric utility experiments.

04

Optimization studies

Gas and bytecode investigations for contracts with specialized mathematical behavior.

Constraints

Feasibility and limitations

  • Finite direct-angle inputs are supported for |x| ≤ 2^32.
  • sin and cos use finite Taylor polynomials; they are not binary128-accurate across the full binary128 domain.
  • Current high-resolution characterization records maximum absolute error of approximately 2.0364e-14 for sine and 3.8881e-13 for cosine.
  • The published gas figures are local Hardhat results, not universal mainnet guarantees.
  • Arbitrary binary128 angle reduction is intentionally out of scope; it would need multiprecision Payne–Hanek-style reduction.
  • Diamond routing adds selector, delegatecall, deployment, and operational complexity.

Trigonometry Master

Explore the implementation, benchmark methodology, deployment path, and documented limits in the public repository.

View on GitHub