Skip to content

jeevan4476/Ore-Forge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ore Forge

Ore Mining

A high-performance proof-of-work mining simulator and pool coordinator built in Rust

Ore Forge is a production-ready mining pool implementation featuring multi-threaded local mining, TCP-based distributed mining, and efficient zero-copy serialization. Built with Tokio for async networking and designed for extensibility to integrate with Solana's ORE token mining.


Features

1: Local Multi-Threaded Mining

  • Keccak-256 Proof-of-Work: Bitcoin-style hashing with configurable difficulty
  • Multi-threaded Mining: Parallel mining workers with work distribution
  • Dynamic Difficulty Adjustment: Bitcoin-inspired retargeting algorithm
  • Token Economics: Reward calculation based on difficulty and time
  • CLI Interface: Easy-to-use command-line tool with clap

2: TCP Mining Pool

  • Coordinator Server: Async TCP server managing multiple remote miners
  • Miner Client: Connect to pool, receive challenges, submit proofs
  • Zero-Copy Serialization: Wincode protocol for minimal overhead
  • Length-Prefixed Framing: Reliable message boundary detection
  • Concurrent State Management: Thread-safe coordinator state with Arc<RwLock>
  • Real-time Leaderboard: Live updates of miner performance
  • Graceful Shutdown: Ctrl-C handling with cleanup

3: Solana Integration

  • Drillx Hash Algorithm: Replace Keccak-256 with Solana ORE's hash function
  • Solana RPC Integration: Submit proofs on-chain to claim ORE tokens
  • Devnet Mining: Mine real ORE tokens on Solana devnet
  • Challenge Source Abstraction: Pluggable challenge providers (local/Solana)
  • Wallet Management: File-based keypair support (Solana CLI format)

Performance Benchmarks

Hash Rate Performance

Keccak-256 Hash Rate:       ~1,700,000 hashes/sec (single-threaded)

Message Serialization (Wincode)

Challenge (serialize):      ~600 ns
Challenge (deserialize):    ~400 ns
Proof (serialize):          ~800 ns
Proof (deserialize):        ~500 ns
Leaderboard (serialize):    ~2.5 μs (10 miners)
Leaderboard (deserialize):  ~2.0 μs (10 miners)

Server State Operations

Register Miner:             ~5-10 μs (100 concurrent miners)
Update Balance:             ~5-10 μs (100 concurrent miners)
Generate Leaderboard:       ~20-30 μs (100 miners)

Connection Throughput

Message Send/Receive:       50+ messages/sec per connection

Mining Scalability

1 Thread:   ~1.7M H/s
2 Threads:  ~3.4M H/s (2.0x scaling)
4 Threads:  ~6.8M H/s (4.0x scaling)
8 Threads:  ~13.6M H/s (8.0x scaling)

Run benchmarks yourself:

cargo bench --bench hash_benchmark
cargo bench --bench mining_benchmark
cargo bench --bench framing_benchmark
cargo bench --bench state_benchmark

Quick Start

Prerequisites

  • Rust 1.92.0 (with cargo)
  • Linux/macOS/Windows (cross-platform)

Installation

git clone https://github.com/yourusername/ore-forge.git
cd ore-forge
cargo build --release

Usage

Local Multi-Threaded Mining

# Start mining locally with 4 threads
cargo run --release -- local --threads 4 --rounds 10

Sample Output:

[INFO  ore_sim::coordinator] Round 1 | challenge: 0f6a46...9e0831
[INFO  ore_sim::coordinator] Round 1 | nonce=46245 attempts=4625 time=107ms earned=3.062430 total=3.062430 difficulty: 16->20
[INFO  ore_sim::coordinator] Round 2 | challenge: 616d9c...8f5857
[INFO  ore_sim::coordinator] Round 2 | nonce=71495 attempts=7150 time=163ms earned=32.164908 total=35.227338 difficulty: 20->24

TCP Mining Pool

Start Coordinator:

# Terminal 1: Start pool coordinator
cargo run --release -- coord --bind 127.0.0.1:9000

Connect Miners:

# Terminal 2: Connect first miner
cargo run --release -- mine --server 127.0.0.1:9000 --name P1 --threads 4

# Terminal 3: Connect second miner
cargo run --release -- mine --server 127.0.0.1:9000 --name P2 --threads 2

# Terminal 4: Connect third miner
cargo run --release -- mine --server 127.0.0.1:9000 --name P3 --threads 8

Coordinator Output:

[INFO  ore_sim::server] Coordinator listening on 127.0.0.1:9000
[INFO  ore_sim::server::connection] Miner P1 connected
[INFO  ore_sim::server::connection] Miner P2 connected
[INFO  ore_sim::server::connection] Miner P3 connected
[INFO  ore_sim::server] Round 1 complete | Winner: P3 | Reward: 10.50 ORE
[INFO  ore_sim::server] Leaderboard: 1. P3 (10.50) 2. P1 (0.00) 3. P2 (0.00)

Miner Output:

[INFO  ore_sim::client] Connected to pool at 127.0.0.1:9000
[INFO  ore_sim::client] Mining with 4 threads as 'P1'
[INFO  ore_sim::client] Challenge received: a3f2c8...9de102
[INFO  ore_sim::client::worker] Thread 0: Mining started
[INFO  ore_sim::client::worker] Thread 1: Mining started
[INFO  ore_sim::client::worker] Thread 2: Mining started
[INFO  ore_sim::client::worker] Thread 3: Mining started
[INFO  ore_sim::client] Proof found! nonce=152894 attempts=612456 time=359ms
[INFO  ore_sim::client] Proof submitted successfully
[INFO  ore_sim::client] Current balance: 0.00 ORE

Architecture

Phase 1: Local Mining

+--------------------------------------------------------------+
│                        Coordinator                           │
│  ┌────────────┐  ┌────────────┐  ┌────────────┐              │
│  │  Miner 1   │  │  Miner 2   │  │  Miner 3   │  (threads)   │
│  │ KeccakHash │  │ KeccakHash │  │ KeccakHash │              │
│  └────────────┘  └────────────┘  └────────────┘              │
│         │                │                │                  │
│         +----------------+----------------+                  │
│                          │                                   │
│                    DifficultyAdjust                          │
│                    AccountBalances                           │
+--------------------------------------------------------------+

Phase 2: TCP Mining Pool

+-------------------------------------------------------------+
│                    Coordinator Server (Tokio)               │
│  +------------------------------------------------------+   │
│  │               ServerState (Arc<RwLock>)              │   │
│  │  • Miners: HashMap<String, MinerInfo>                │   │
│  │  • Balances: HashMap<String, u64>                    │   │
│  │  • Current Challenge: [u8; 32]                       │   │
│  │  • Difficulty: u32                                   │   │
│  +------------------------------------------------------+   │
│           │                    │                    │       │
│  +----------------+  +----------------+  +----------------+ │
│  │ Connection 1   │  │ Connection 2   │  │ Connection 3   │ │
│  │ (P1)           │  |(P2)            │  │ (P3)           │ │
│  │ Tokio Task     │  │ Tokio Task     │  │ Tokio Task     | │
│  +----------------+  +----------------+  +----------------+ │
+-------------------------------------------------------------+
           │                    │                    │
         (TCP)                (TCP)                (TCP)
           │                    │                    │
  +----------------+  +----------------+  +----------------+  
  │ MinerClient 1  │  │ MinerClient 2  │  │ MinerClient 3  │  
  │   (P1)         │  │    (P2)        │  │  (P3)          │  
  │  ┌──────────┐  │  │  ┌──────────┐  │  │  ┌──────────┐  │  
  │  │ Worker 1 │  │  │  │ Worker 1 │  │  │  │ Worker 1 │  │  
  │  │ Worker 2 │  │  │  │ Worker 2 │  │  │  │ Worker 2 │  │  
  │  │ Worker 3 │  │  │  └──────────┘  │  │  │ Worker 3 │  │
  │  │ Worker 4 │  │  │                │  │  │ Worker 4 │  │
  │  └──────────┘  │  │                │  │  │ Worker 5 │  │
  │  (4 threads)   │  │  (2 threads)   │  │  │ Worker 6 │  │
  │                │  │                │  │  │ Worker 7 │  │
  │                │  │                │  │  │ Worker 8 │  │
  │                │  │                │  │  └──────────┘  │
  │                │  │                │  │  (8 threads)   │
  +----------------+  +----------------+  +----------------+

Message Protocol (Wincode)

+---------------------------------------------------------+
│              Length-Prefixed Framing (4 bytes)          │
+---------------------------------------------------------+
│  Message Type     │  Wire Format                        │
+-------------------+-------------------------------------+
│  Challenge        │ [32 bytes hash] [4 bytes difficulty]│
│  Proof            │  [32 bytes nonce] [8 bytes hash]    │
│  ProofResult      │  [1 byte accepted] [8 bytes balance]│
│  Leaderboard      │  [4 bytes count] [entries...]       │
+---------------------------------------------------------+

For Mainnet Mining:

  • Requires competitive hardware (high hash rates)
  • Real SOL needed for transaction fees
  • Competes with other miners globally
  • Potential for actual token rewards with market value

Project Structure

ore-forge/
|-- src/
│   |-- lib.rs                    # Module exports
│   |-- main.rs                   # CLI entry point
│   |-- hash.rs                   # HashBackend trait + KeccakBackend
│   |-- protocol.rs               # Wincode message types
│   |-- wire.rs                   # TCP length-prefixed framing
│   |-- difficulty.rs             # Bitcoin-style difficulty adjustment
│   |-- account.rs                # Token reward calculation
│   |-- cli.rs                    # Clap CLI definitions
│   |-- shutdown.rs               # Ctrl-C handler
│   |-- coordinator.rs            # Phase 1 local coordinator
│   |-- miner.rs                  # Phase 1 local miners
│   |-- client/
│   |   |-- mod.rs               # MinerClient (TCP client)
│   |   |-- worker.rs            # MiningWorker (blocking threads)
│   |-- server/
│   |   |-- mod.rs               # CoordinatorServer (Tokio)
│   |   |-- state.rs             # ServerState (concurrent state)
│   |   |-- connection.rs        # Per-connection handler
|-- tests/
│   |-- common/
│   |   |-- fixtures.rs          # Sample data generators
│   |   |-- helpers.rs           # Test utilities
│   |   |-- mock.rs              # Mock hash backends
│   |-- protocol_tests.rs        # 16 tests - Serialization
│   |-- wire_tests.rs            # 12 tests - TCP framing
│   |-- server_state_tests.rs    # 19 tests - Concurrent state
│   |-- connection_tests.rs      # 8 tests - Connection lifecycle
│   |-- worker_tests.rs          # 6 tests - Mining worker
│   |-- client_server_tests.rs   # 10 tests - Full integration
│   |-- e2e_tests.rs             # 5 tests - CLI binary tests
|-- benches/
│   |-- hash_benchmark.rs        # Hash rate benchmarks
│   |-- mining_benchmark.rs      # Thread scaling benchmarks
│   |-- framing_benchmark.rs     # Serialization benchmarks
│   |-- state_benchmark.rs       # State operation benchmarks
|-- public/
│   |-- oremining.jpg            # Cover image
|-- Cargo.toml                   # Dependencies + benchmark configs
|-- README.md                    

Technology Stack

  • Language: Rust 2021 Edition
  • Async Runtime: Tokio (multi-threaded scheduler)
  • Serialization: Wincode (zero-copy, Solana-compatible)
  • Hashing: Keccak-256 via tiny-keccak-> Drillx
  • CLI: Clap with derive macros
  • Testing: tokio-test, serial_test for E2E
  • Benchmarking: Criterion.rs with statistical analysis
  • Coverage: cargo-tarpaulin
  • Networking: Tokio TCP streams with length-prefixed framing

Development

Run Tests

# All tests (76 total)
cargo test --workspace

# Specific test suites
cargo test --test protocol_tests
cargo test --test e2e_tests -- --test-threads=1

# With logs
RUST_LOG=debug cargo test --test client_server_tests -- --nocapture

Run Benchmarks

# All benchmarks
cargo bench

# Specific benchmarks
cargo bench --bench hash_benchmark
cargo bench --bench mining_benchmark -- --quick

Coverage Report

# Install tarpaulin
cargo install cargo-tarpaulin

# Generate coverage
cargo tarpaulin --timeout 300 --out Html

Linting & Formatting

cargo fmt --check        # Check formatting
cargo clippy -- -D warnings  # Lint with warnings as errors

Learning Resources

This project is designed as a learning platform for:

  • Async Rust: Tokio runtime, futures, async/await
  • Zero-Copy Optimization: Wincode serialization, memory efficiency
  • Distributed Systems: TCP networking, state synchronization
  • Proof-of-Work Algorithms: Hashing, difficulty adjustment
  • Blockchain Concepts: Mining, consensus, tokenomics
  • Solana Development: RPC integration, on-chain transactions

Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Write tests for new functionality
  4. Run tests and linting (cargo test && cargo clippy)
  5. Commit changes (git commit -m 'feats')
  6. Push to branch (git push origin feature/123)
  7. Open a Pull Request

License

MIT License - See LICENSE file for details


Acknowledgments

  • Solana ORE Protocol: Inspiration for proof-of-work on Solana
  • Tokio Project: Excellent async runtime and ecosystem
  • Rust Community: Best-in-class tooling and documentation

Contact


About

high-performance proof-of-work mining simulator and pool coordinator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages