Skip to content

bitwyre/gpucoin

Repository files navigation

GPUCoin

A blockchain where smart contracts are CUDA kernels. Deploy .cu files, execute them on real GPUs, and verify results deterministically.

GPUCoin uses the BarraCUDA compiler to compile CUDA source into BIR (BarraCUDA Intermediate Representation), which serves as the on-chain bytecode. Miners execute kernels on AMD GPUs via compiled .hsaco binaries, while validators verify execution deterministically through a BIR software interpreter.

Architecture

                    CLI / Wallet
                        |
                   JSON-RPC API (port 8545)
                        |
    +-------------------+-------------------+
    |                   |                   |
 Mempool          World State          Blockchain
    |              (RocksDB)           (headers + bodies)
    |                   |                   |
    +--------+----------+----------+--------+
             |                     |
      Transaction Executor    Block Validator
             |                     |
    +--------+--------+    +-------+-------+
    |                 |    |               |
 BarraCUDA       GPU Runtime    BIR Interpreter
 (compile .cu)   (run .hsaco)   (deterministic verify)
    |                 |
    +--------+--------+
             |
        P2P Network (Boost.Asio)

Key Design

  • BIR as bytecode: BarraCUDA's SSA-form intermediate representation is the canonical smart contract format. Target-independent and deterministically serializable.
  • Compute metering: Gas is computed at the BIR opcode level (144 opcodes with assigned costs). Cost = sum(opcode_costs) * grid_dim * block_dim.
  • Proof of Computation: Miners execute on real GPUs (fast path). Validators optimistically trust results. Any node can challenge via deterministic BIR replay within a 100-block window.
  • Fork choice: Heaviest-compute chain wins (not longest).
  • Transaction types: Transfer (type 0), DeployKernel (type 1), ExecuteKernel (type 2).

Prerequisites

  • C++23 compiler (GCC 13+, Clang 17+, or AppleClang 15+)
  • CMake 3.24+
  • OpenSSL 3.x
  • RocksDB
  • Boost 1.80+ (header-only: Asio, Beast)
  • BarraCUDA cloned at ../BarraCUDA (relative to this repo)

macOS (Homebrew)

brew install cmake openssl rocksdb boost
git clone https://github.com/nicholascw/BarraCUDA.git ../BarraCUDA

Ubuntu

sudo apt-get install cmake ninja-build g++-13 libssl-dev librocksdb-dev libboost-all-dev
git clone https://github.com/nicholascw/BarraCUDA.git ../BarraCUDA

Build

# Debug build (ASan + UBSan enabled by default)
cmake --preset debug
cmake --build build/debug

# Release build
cmake --preset release
cmake --build build/release

Sanitizer Builds

# Address Sanitizer (memory errors, leaks)
cmake --preset asan
cmake --build build/asan

# Thread Sanitizer (data races, deadlocks)
cmake --preset tsan
cmake --build build/tsan

# Build for Valgrind (no compiler sanitizers)
cmake --preset valgrind
cmake --build build/valgrind

Test

# Run all tests
ctest --test-dir build/debug --output-on-failure

# Run with ASan leak detection
ASAN_OPTIONS=detect_leaks=1 ctest --test-dir build/asan --output-on-failure

# Run with Thread Sanitizer
ctest --test-dir build/tsan --output-on-failure

# Run with Valgrind
valgrind --leak-check=full --error-exitcode=1 \
  --suppressions=valgrind.supp \
  build/valgrind/tests/test_crypto

Run

# Start a full node
./build/debug/src/gpucoin node start

# Start with mining
./build/debug/src/gpucoin node start --mine --miner <address>

# Create an account
./build/debug/src/gpucoin account create --password mypassword

# List accounts
./build/debug/src/gpucoin account list

# Compile a CUDA kernel
./build/debug/src/gpucoin kernel compile path/to/kernel.cu

# Show chain info
./build/debug/src/gpucoin chain info

JSON-RPC API

The node exposes an Ethereum-compatible JSON-RPC API on port 8545:

# Get block number
curl -X POST http://localhost:8545 \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

# Get balance
curl -X POST http://localhost:8545 \
  -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0x...address..."],"id":1}'

Custom GPU methods: gpu_compileKernel, gpu_deployKernel, gpu_executeKernel, gpu_getKernelInfo.

Project Structure

gpucoin/
  CMakeLists.txt              # Root build config
  CMakePresets.json           # Build presets (debug, asan, tsan, valgrind, release)
  cmake/                      # CMake modules
  third_party/barracuda/      # BarraCUDA compiler as static library
  include/gpucoin/            # Public headers
  src/
    core/                     # Types, transactions, blocks
    crypto/                   # SHA-256, secp256k1, Keccak-256
    state/                    # RocksDB wrapper, world state, Merkle tree
    compiler/                 # BarraCUDA C++ wrapper, kernel cache
    execution/                # Compute meter, transaction executor, GPU runtime
    consensus/                # BIR interpreter, Proof of Computation, fraud proofs
    net/                      # P2P protocol, sessions, gossip, block sync
    rpc/                      # JSON-RPC server, Ethereum + GPU methods
    mempool/                  # Fee-ordered transaction pool
    node/                     # Chain management, full node assembly
    cli/                      # Wallet, CLI commands
    main.cpp                  # Entry point
  tests/                      # Unit tests (GoogleTest)
  proto/                      # Protobuf/gRPC definitions
  docs/                       # Documentation
  .github/workflows/ci.yml   # CI pipeline

Documentation

See the docs/ directory for detailed documentation:

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors