A trust-minimized backend service that generates, stores and serves STARK proofs, block headers and transaction-inclusion metadata for Bitcoin.
- Rust 1.70+
- Cargo
# Clone the repository
git clone https://github.com/keep-starknet-strange/raito-proving-service
cd raito-proving-service
# Build the project
cargo build --release
# Run the service (will automatically create and seed SQLite database)
cargo run --release
The service will start on http://localhost:8080
by default.
The service uses SQLite by default with automatic migrations and seeding:
- Database file:
data/raito.db
(auto-created) - Migrations: Run automatically on startup
- Mock data: Auto-seeded on first run
Variable | Description | Default | Example |
---|---|---|---|
DATABASE_URL |
Database connection string | sqlite:data/raito.db |
sqlite:data/raito.db |
DATABASE_SEED |
Seed database with mock data | true |
false |
DATABASE_RUN_MIGRATIONS |
Run migrations on startup | true |
false |
PORT |
Server port | 8080 |
3000 |
RUST_LOG |
Log level | info |
debug |
# PostgreSQL (for production)
export DATABASE_URL="postgresql://user:password@localhost:5432/raito"
# In-memory SQLite (for testing)
export DATABASE_URL="sqlite::memory:"
# Custom SQLite location
export DATABASE_URL="sqlite:/path/to/custom.db"
GET /v1/blocks
- List recent blocks with paginationGET /v1/blocks/{height|hash}
- Get block details by height or hashGET /v1/blocks/{height}/proof
- Download STARK proof for a block
GET /v1/tx/{txid}
- Check transaction inclusion statusGET /v1/header/{hash}
- Check block header existence
GET /healthz
- Service health check (includes database connectivity)GET /metrics
- Prometheus metricsGET /docs
- Interactive API documentation (Swagger UI)
The service automatically generates OpenAPI 3.0 documentation available at:
- Interactive docs:
http://localhost:8080/docs
- OpenAPI JSON:
http://localhost:8080/api-docs/openapi.json
# Run with fresh database
rm -f data/raito.db && cargo run
# Run without seeding mock data
DATABASE_SEED=false cargo run
# Run with debug logging including SQL queries
RUST_LOG=debug,sqlx=debug cargo run
# Run all tests (uses in-memory database)
cargo test
# Run with coverage
cargo test --coverage
# Run specific test
cargo test test_health_check
# Format code
cargo fmt
# Lint code
cargo clippy
# Security audit
cargo audit
The service uses a normalized SQLite schema:
- blocks - Bitcoin block information
- transactions - Transaction IDs with block associations
- proof_files - STARK proof file metadata
- block_headers - Optimized header hash lookups
See migrations/001_initial.sql
for the complete schema.
βββ src/
β βββ main.rs # Application entry point
β βββ lib.rs # Library root
β βββ handlers.rs # HTTP request handlers
β βββ middleware.rs # Custom middleware
β βββ model.rs # Data models and schemas
β βββ database.rs # Database operations and connection management
β βββ store.rs # Legacy mock store (for reference)
β βββ error.rs # Error handling
βββ migrations/ # Database migration files
β βββ 001_initial.sql # Initial schema
βββ data/
β βββ mock_blocks.json # Mock block data
β βββ proofs/ # Mock STARK proof files
βββ config/ # Configuration documentation
βββ scripts/ # Demo and test scripts
βββ .sqlx/ # SQLx query metadata (committed to git)
The service is designed to handle:
- 100+ requests/second on a single vCPU
- Sub-300ms P95 latency for block operations
- Concurrent proof downloads
- SQLite supports millions of reads with WAL mode
- CORS protection
- Security headers (CSP, HSTS, etc.)
- Input validation with database constraints
- SQL injection protection (compile-time checked queries)
- Rate limiting ready
- Structured JSON logging
# Build image
docker build -t raito-proving-service .
# Run container with persistent database
docker run -p 8080:8080 -v $(pwd)/data:/app/data raito-proving-service
# Run with custom database URL
docker run -p 8080:8080 -e DATABASE_URL="sqlite:custom.db" raito-proving-service
version: '3.8'
services:
raito-proving-service:
image: ghcr.io/raito/proving-service:latest
ports:
- "8080:8080"
environment:
- RUST_LOG=info
- PORT=8080
- DATABASE_URL=sqlite:data/raito.db
- DATABASE_SEED=false # Disable seeding in production
volumes:
- ./data:/app/data # Persist database
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/healthz"]
interval: 30s
timeout: 10s
retries: 3
version: '3.8'
services:
postgres:
image: postgres:15
environment:
POSTGRES_DB: raito
POSTGRES_USER: raito
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
raito-proving-service:
image: ghcr.io/raito/proving-service:latest
depends_on:
- postgres
environment:
- DATABASE_URL=postgresql://raito:${DB_PASSWORD}@postgres:5432/raito
- DATABASE_SEED=false
ports:
- "8080:8080"
volumes:
postgres_data:
The service includes realistic mock data for development and testing:
- 5 sample blocks (heights 869119-869123)
- STARK proof files for each block
- Transaction mappings for inclusion checks
- Header hash mappings for verification
Mock data is automatically loaded from data/mock_blocks.json
and data/proofs/
on first startup.
- β REST API with SQLite database
- β OpenAPI documentation
- β Health checks and metrics
- β Comprehensive testing
- β Docker containerization
- β Database migrations and seeding
- Real STARK proof generation (Cairo + STWO integration)
- PostgreSQL support for production scaling
- Job queue for async proof generation
- WebSocket/SSE for progress updates
- Authentication and API keys
- Caching layer (Redis) for performance
- gRPC API for high-performance use cases
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Make your changes
- Add tests for new functionality
- Ensure all tests pass (
cargo test
) - Format code (
cargo fmt
) - Submit a pull request
When modifying the database schema:
- Create a new migration file in
migrations/
- Test the migration:
rm -f data/raito.db && cargo run
- Prepare SQLx queries:
cargo sqlx prepare
- Commit the
.sqlx/
directory changes
- Follow Rust best practices and idioms
- Maintain test coverage above 90%
- Use structured logging with appropriate levels
- Document public APIs with examples
- Keep functions small and focused
This project is licensed under the MIT License - see the LICENSE file for details.
- Raito - Bitcoin consensus client in Cairo
- Shinigami - Bitcoin Script verification
- ZeroSync - Inspiration for the project
Built with β€οΈ by the Raito team