EchoPrime: Deterministic safe prime oracle and cryptographic primitive
Project description
EchoPrime ๐
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 constanta โ 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 demonstrationbatch_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
PrimeVerifiedevent 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
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Run the tests (
python -m pytest tests/ -v) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a5f3fdc99f07fb6fd02a79ec6551b18f7ec98f081122f1223be879040f3f6c0
|
|
| MD5 |
442c83acded0ba16e9df454ee0021897
|
|
| BLAKE2b-256 |
5f18bfdcb2cf16150be306a9ee4205a49bba9e69ba8d8e8c6c39ae5cd4cccdb1
|