Skip to main content

EchoPrime: Deterministic safe prime oracle and cryptographic primitive

Project description

EchoPrime ๐Ÿ”

License: Apache 2.0 Python 3.8+ Version DOI

Deterministic safe prime oracle and cryptographic primitive.

EchoPrime provides a deterministic method for estimating, locating, and verifying safe primes using an analytic projection based on the Bateman-Horn heuristic. It includes a symbolic collapse score verifier and an oracle trace format for on-chain publication.

Key Features

  • Analytic Estimator โ€” Projects the n-th safe prime location using p_n โ‰ˆ a ยท n ยท (log n)ยฒ with empirically fitted constant a โ‰ˆ 2.8913
  • Symbolic Collapse Verifier โ€” Verifies primes using binomial coefficient divisibility (Lucas' theorem)
  • Safe Prime Finder โ€” Deterministic search from estimated regions
  • Oracle Traces โ€” SHA-256 hashed records for on-chain publication
  • Ethereum Contract Format โ€” Ready-to-submit tuple format for smart contracts

Installation

pip install echoprime

Or from source:

git clone https://github.com/DarrenEdwards111/echoprime.git
cd echoprime
pip install -e .

Quick Start

from echoprime import (
    estimate_nth_safe_prime,
    find_safe_prime_near,
    verify_safe_prime,
    create_trace,
)

# Estimate where the 100th safe prime lives
estimate = estimate_nth_safe_prime(100)
print(f"Estimate for index 100: {estimate}")

# Find the actual safe prime near that estimate
p, q = find_safe_prime_near(100)
print(f"Found safe prime p={p}, Sophie Germain q={q}")

# Verify with symbolic collapse scoring
result = verify_safe_prime(p)
print(f"Verified: {result['verified']}")
print(f"Collapse score (p): {result['score_p']}")
print(f"Collapse score (q): {result['score_q']}")

# Create oracle trace for on-chain publication
trace = create_trace(
    index=100, p=p, q=q,
    score_p=result['score_p'],
    score_q=result['score_q'],
    verified=result['verified'],
)
print(f"Trace hash: {trace['hash']}")

API Reference

Estimator (echoprime.estimator)

Function Description
estimate_nth_safe_prime(n) Estimate the n-th safe prime: p_n โ‰ˆ a ยท n ยท (log n)ยฒ
find_safe_prime_near(n) Find actual safe prime at/above the estimate for index n
get_candidate_from_index(k) Get a candidate p = 2ยทnextprime(raw)+1 from index k
projector_index(epoch_n, offset=0) Map epoch number to starting lattice index
A_CONSTANT Bateman-Horn fitted constant โ‰ˆ 2.8913

Verifier (echoprime.verifier)

Function Description
collapse_score(p, window=128) Symbolic collapse score: fraction of C(p,k) โ‰ก 0 mod p
verify_safe_prime(p, window=128, threshold=0.95) Full verification with primality + collapse scoring
batch_verify(candidates, window=128, threshold=0.95) Verify multiple candidates

Oracle (echoprime.oracle)

Function Description
create_trace(index, p, q, score_p, score_q, verified) Create SHA-256 hashed oracle trace record
format_for_contract(trace) Format for Ethereum smart contract submission
export_traces(traces, filepath) Export traces to JSON file

Utilities (echoprime.utils)

Symbol Description
KNOWN_SAFE_PRIMES First 100 known safe primes for validation
is_safe_prime(p) Quick safe prime check
timer(func) Decorator that returns (result, elapsed_seconds)

The Math

Safe Primes

A safe prime is a prime p such that q = (p-1)/2 is also prime. The prime q is called a Sophie Germain prime.

Analytic Projection

The n-th safe prime is estimated using:

p_n โ‰ˆ a ยท n ยท (ln n)ยฒ

where a โ‰ˆ 2.8913 is an empirically fitted constant derived from the Bateman-Horn conjecture applied to the polynomial pair (x, 2x+1).

Symbolic Collapse Score

For a candidate prime p, the collapse score measures:

S(p) = |{k โˆˆ [1,T] : C(p,k) โ‰ก 0 (mod p)}| / T

By Lucas' theorem, for any prime p > T, all binomial coefficients C(p,k) for 1 โ‰ค k โ‰ค T are divisible by p. Therefore S(p) = 1.0 for all primes above the window size (default T=128).

Examples

See the examples/ directory:

  • basic_usage.py โ€” Core workflow demonstration
  • batch_verify.py โ€” Batch verification with JSON export

Benchmarks

# Quick test (1000 candidates, 10% sampled)
python benchmarks/million_run.py --count 1000 --sample-rate 0.1

# Full million-candidate benchmark
python benchmarks/million_run.py

Running Tests

pip install pytest
python -m pytest tests/ -v

Project Structure

echoprime/
โ”œโ”€โ”€ pyproject.toml          # Package configuration
โ”œโ”€โ”€ README.md               # This file
โ”œโ”€โ”€ LICENSE                  # Apache 2.0 License
โ”œโ”€โ”€ setup.py                # Backwards compatibility
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ echoprime/
โ”‚       โ”œโ”€โ”€ __init__.py     # Public API
โ”‚       โ”œโ”€โ”€ estimator.py    # Analytic safe prime estimator
โ”‚       โ”œโ”€โ”€ verifier.py     # Symbolic collapse score verifier
โ”‚       โ”œโ”€โ”€ oracle.py       # On-chain oracle trace format
โ”‚       โ””โ”€โ”€ utils.py        # Utilities and known primes
โ”œโ”€โ”€ contracts/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ EchoPrimeOracle.sol   # Solidity oracle contract
โ”‚   โ”‚   โ””โ”€โ”€ IEchoPrimeOracle.sol  # Contract interface
โ”‚   โ”œโ”€โ”€ test/                     # 20 Hardhat tests
โ”‚   โ”œโ”€โ”€ scripts/                  # Deploy + submit scripts
โ”‚   โ”œโ”€โ”€ hardhat.config.js
โ”‚   โ””โ”€โ”€ README.md                 # Contract docs
โ”œโ”€โ”€ whitepaper/
โ”‚   โ”œโ”€โ”€ echoprime-whitepaper.tex  # LaTeX source
โ”‚   โ””โ”€โ”€ echoprime-whitepaper.pdf  # Compiled PDF
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_estimator.py   # Estimator tests
โ”‚   โ”œโ”€โ”€ test_verifier.py    # Verifier tests
โ”‚   โ””โ”€โ”€ test_integration.py # Full pipeline tests
โ”œโ”€โ”€ examples/
โ”‚   โ”œโ”€โ”€ basic_usage.py      # Basic workflow
โ”‚   โ””โ”€โ”€ batch_verify.py     # Batch verification
โ””โ”€โ”€ benchmarks/
    โ””โ”€โ”€ million_run.py      # 1M candidate benchmark

Smart Contracts

EchoPrime includes an Ethereum-compatible smart contract (EchoPrimeOracle.sol) that serves as a public, on-chain registry for verified safe primes.

Features

  • Submit โ€” Publish a verified safe prime with its index, collapse scores, and primality verdict
  • Batch submit โ€” Submit up to 100 primes in a single transaction
  • Query โ€” Retrieve any published prime by its deterministic index
  • Access control โ€” Owner can authorize oracle bots as submitters
  • Events โ€” Every submission emits a PrimeVerified event for off-chain indexing

Quick Start

cd contracts
npm install
npx hardhat compile
npx hardhat test          # 20 tests
npx hardhat run scripts/deploy.js --network sepolia

Contract API

Function Description
submitVerification(index, p, scoreP, scoreQ, verified) Submit a verified safe prime
batchSubmit(indices[], primes[], scoresP[], scoresQ[], verifieds[]) Batch submit (max 100)
getPrime(index) Query a prime record by index
isPrimeSubmitted(index) Check if an index has been submitted
totalSubmissions Total number of published primes
addSubmitter(address) Authorize an oracle bot (owner only)
removeSubmitter(address) Revoke authorization (owner only)

See contracts/README.md for full deployment guide and environment setup.

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Run the tests (python -m pytest tests/ -v)
  4. Commit your changes (git commit -m 'Add amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

About Mikoshi Ltd

EchoPrime is built by Mikoshi Ltd โ€” a UK fintech and cryptographic infrastructure company based in Swansea, Wales.

Mikoshi builds tools at the intersection of finance, AI, and cryptography:

  • Mikoshi Invest โ€” Investment intelligence platform with AI analysis, ML forecasting, and real-time market signals
  • EchoPrime โ€” Deterministic safe prime oracle for Web3 and cryptographic infrastructure
  • Mikoshi AI โ€” AI companion and intelligence products

Mikoshi's mission is to make sophisticated financial and cryptographic tools accessible to everyone โ€” not just Wall Street.

๐Ÿ“ง Contact: mikoshiuk@gmail.com ๐ŸŒ Website: mikoshi.co.uk ๐Ÿ”ฌ EchoPrime: echoprime.xyz ๐Ÿ“„ Paper: Edwards, D. (2026). Zenodo. DOI: 10.5281/zenodo.18529723

Citation

@article{edwards2026echoprime,
  title   = {EchoPrime: A Verifiable Oracle for Deterministic Safe Prime Generation with On-Chain Audit Trails},
  author  = {Edwards, Darren J.},
  year    = {2026},
  doi     = {10.5281/zenodo.18529723},
  url     = {https://doi.org/10.5281/zenodo.18529723},
  publisher = {Zenodo}
}

License

Licensed under the Apache License, Version 2.0 โ€” see the LICENSE file for details.

Author

Darren J. Edwards, Ph.D. Founder & CEO, Mikoshi Ltd GitHub ยท mikoshi.co.uk


EchoPrime: Deterministic cryptographic infrastructure for the future of Web3. ยฉ 2025 Mikoshi Ltd. All rights reserved.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

echoprime-1.0.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file echoprime-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: echoprime-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for echoprime-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a5f3fdc99f07fb6fd02a79ec6551b18f7ec98f081122f1223be879040f3f6c0
MD5 442c83acded0ba16e9df454ee0021897
BLAKE2b-256 5f18bfdcb2cf16150be306a9ee4205a49bba9e69ba8d8e8c6c39ae5cd4cccdb1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page