Skip to content

btc-vision/mini-bob

Repository files navigation

World's First On-Chain AI

Bitcoin L1 OPNet WebAssembly 1M Params Vibes

MiniBob

The world's first AI brain that lives directly on Bitcoin.

Not an API. Not an oracle. Not a wrapper. A real neural network, running on-chain, verified by every node.

This has never been done before. Not on Bitcoin. Not on Ethereum. Not on Solana. Not anywhere.


Who is Bob?

Bob is a degen. Bob lives on Bitcoin. Bob doesn't call ChatGPT. Bob is the AI.

He's a 1-million parameter transformer language model compiled into a single smart contract on OPNet, Bitcoin's Layer 1 smart contract platform. When you talk to Bob, your message goes into a Bitcoin transaction, the neural network runs inside the virtual machine on every node, and Bob's response comes back. Deterministic, verifiable, unstoppable.

Bob was trained on crypto conversations, degen slang, math, and OPNet lore. He's not GPT-4. He's not trying to be. He's a small, fast, opinionated AI that exists entirely on the most secure blockchain in the world. He's the proof that real on-chain AI is possible. Not tomorrow, not with some future L2, but right now, on Bitcoin L1.


Why Should You Care?

Every "AI crypto" project is lying to you.

Let's be honest. Here's what "AI + crypto" has looked like until now:

  • A token with a chatbot on a website
  • An oracle posting GPT answers on-chain
  • A "decentralized inference network" that's just servers with extra steps
  • A governance token for someone else's API

None of that is on-chain AI. That's off-chain AI with a token attached.

MiniBob is different.

The weights are in the bytecode. The matrix multiplications happen in the VM. The tokenizer, the attention mechanism, the sampling, all of it executes on-chain. Every node runs the same forward pass and gets the same answer. You don't trust a server. You verify.

This is the first real case study of decentralized AI.

Not decentralized hosting. Not decentralized fine-tuning. Decentralized intelligence, a neural network whose entire inference is verified by Bitcoin consensus.


The Fake vs The Real

The Fake vs The Real


How It Works (The Simple Version)

How It Works

That's it. No servers. No APIs. No middlemen. Just math on Bitcoin.


How It Works (The Technical Version)

For the builders, researchers, and anyone who wants to understand how you actually fit a transformer into a smart contract.

The Architecture

Architecture

Inside each transformer layer: RMSNorm → i8 QKV projection (4x unrolled, raw WASM memory loads) → RoPE (precomputed sin/cos) → KV-Cache (right-sized) → multi-head attention → softmax (exp LUT) → output projection + residual → RMSNorm → FFN (128 → 256 → 128, ReLU) + residual.

The Challenge: No Floats Allowed

Smart contracts don't have floating point. MiniBob does everything in integer arithmetic:

What Format How
Weights Int8 (8-bit) Per-matrix abs_max quantization
Activations Q16.16 (32-bit) 16 integer bits + 16 fractional bits
Logits i32 Direct matmul output, no i64 intermediary
RMSNorm scales Q8.8 (i16) Raw load<i16> instead of 2x byte + shift
RoPE tables Q1.15 (i16) Raw load<i16> precomputed sin/cos
Exp / InvSqrt StaticArray<i32> (256 entries) Native i32 LUTs, zero runtime parsing

The int8 quantized model produces identical top-5 predictions to the float32 original.

KV-Cache: Don't Repeat Yourself

KV-Cache

Without KV-Cache, generating 10 tokens means running the full attention over all previous tokens 10 times. With it, each new token only processes itself against the cache. The cache is right-sized to min(inputLen + maxNewTokens, 512), no wasted memory. Massive gas savings.


From Training to Bitcoin

The full journey of how Bob's brain gets built and deployed:

From Training to Bitcoin


What Makes This Hard

Running AI on-chain isn't just "deploy a model." Here's what makes it borderline insane:

What Makes This Hard

MiniBob solves all of them. That's why it took this long. That's why nobody else has done it.


Bob's Specs

Parameters 1,049,728 (~1M)
Vocabulary 4,096 tokens (BPE)
Embedding Dim 128
Layers 4 transformer blocks
Attention Heads 4 (32-dim each)
FFN Hidden Dim 256
Max Context 512 tokens
Quantization Int8 weights, Q16.16 fixed-point
Output Vocab 2,048 tokens (dedicated output embedding)
WASM Size ~1.4 MB
Personality Full degen crypto bro
Blockchain Bitcoin L1 via OPNet
Trust Assumptions Zero. Verified by consensus.

Gas Optimization

Every gas unit matters when you're running a transformer on-chain. Here's how Bob stays efficient:

Gas Optimization


Contract API

Three methods. That's all you need.

generate(prompt, maxTokens, contextSize)

Talk to Bob. Send UTF-8 text, get a response.

Input:  prompt (bytes)      - Your message as UTF-8
        maxTokens (u16)     - How many tokens Bob should generate (1-512)
        contextSize (u16)   - Context window (128-512)

Output: response (bytes)    - Bob's UTF-8 response

tokenizeText(input) (view)

See how Bob breaks text into tokens.

Input:  text (bytes)        - UTF-8 text
Output: tokenIds (bytes)    - Token IDs (u16, big-endian)

getModelInfo() (view)

Get Bob's brain specs.

Output: vocabSize, embedDim, numLayers, maxSeqLen, paramCount

Build It Yourself

Prerequisites

  • Node.js & npm
  • Python 3.10+ with PyTorch & CUDA (for training only)

Quick Start

npm install                     # Install dependencies
npm run build:minibob           # Compile the contract to WASM (~1.4 MB)
npm run test                    # Run all tests

Full Pipeline

# Train from scratch
npm run train:tokenizer         # Train the BPE tokenizer
npm run train:model             # Train the transformer (GPU required)

# Export & verify
npm run export:weights          # Quantize to int8 & generate weight files
npm run verify                  # Verify int8 matches float inference

# Build & test
npm run build:minibob           # Compile to WASM (~1.4 MB)
npm run test                    # Run all unit tests

# Preview locally
cd training && python3 preview.py

On-Chain Constraints

The box Bob has to fit in:

Resource Limit
WASM binary (compressed) 512 KB
WASM binary (decompressed) 1.5 MB
Runtime memory 32 MB
Gas per transaction 150 billion
Max context window 512 tokens

The Stack

Layer Tech
Blockchain Bitcoin L1
Smart Contracts OPNet
Contract Language AssemblyScript
Compilation WebAssembly
Training PyTorch (CUDA)
Quantization Custom int8 + Q16.16
Tokenizer BPE (GPT-2 byte encoding)

The Bottom Line

This isn't a whitepaper. This isn't a roadmap. This isn't a promise.

This is a working neural network on Bitcoin. The code is here. The weights are here. The contract compiles, deploys, and generates text, verified by every node in the network.

1 million parameters. 4 transformer layers. Integer-only arithmetic. Zero trust assumptions.

The first real on-chain AI. Built on Bitcoin. His name is Bob.


Feed Bob's Brain

Bob lives on-chain, but his creators run on caffeine and ramen.
If MiniBob made your jaw drop, consider dropping some sats.

BTC

bc1p9q5jk57r2lg2cjnlzcf79te4qtunx4nqn7t69rhrwfhh06hsecfqw55ua4

ETH

0xd29ccBFA1E0CB0B3190724100eEcdA5aaC0A4AAA

SOL

GEd5iMHy6h8o49KKo3sS6TSdFMiJZuern9E2wWhYudpD

Bob was born on Bitcoin, but he won't judge your chain of choice.


License

Apache2.0

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors