Skip to content

Commit e5d1b69

Browse files
authored
Merge pull request #23 from Steake/rc1
Rc1
2 parents 30ca7e6 + 37a1080 commit e5d1b69

77 files changed

Lines changed: 12127 additions & 1663 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/benchmarks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
benchmark:
1111
name: Run Benchmarks
12-
runs-on: ubuntu-latest
12+
runs-on: ubuntu-latest-xl
1313
steps:
1414
- uses: actions/checkout@v4
1515

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
runs-on: ${{ matrix.os }}
1717
strategy:
1818
matrix:
19-
os: [ubuntu-latest, macos-latest, windows-latest]
19+
os: [ubuntu-latest-xl, macos-latest, windows-latest]
2020
rust: [stable]
2121
steps:
2222
- uses: actions/checkout@v4
@@ -53,7 +53,7 @@ jobs:
5353

5454
fmt:
5555
name: Rustfmt
56-
runs-on: ubuntu-latest
56+
runs-on: ubuntu-latest-xl
5757
steps:
5858
- uses: actions/checkout@v4
5959
- uses: dtolnay/rust-toolchain@stable
@@ -63,7 +63,7 @@ jobs:
6363

6464
clippy:
6565
name: Clippy
66-
runs-on: ubuntu-latest
66+
runs-on: ubuntu-latest-xl
6767
steps:
6868
- uses: actions/checkout@v4
6969
- uses: dtolnay/rust-toolchain@stable
@@ -73,7 +73,7 @@ jobs:
7373

7474
build:
7575
name: Build
76-
runs-on: ubuntu-latest
76+
runs-on: ubuntu-latest-xl
7777
steps:
7878
- uses: actions/checkout@v4
7979
- uses: dtolnay/rust-toolchain@stable
@@ -86,7 +86,7 @@ jobs:
8686

8787
security:
8888
name: Security Audit
89-
runs-on: ubuntu-latest
89+
runs-on: ubuntu-latest-xl
9090
steps:
9191
- uses: actions/checkout@v4
9292
- uses: dtolnay/rust-toolchain@stable
@@ -99,7 +99,7 @@ jobs:
9999

100100
coverage:
101101
name: Code Coverage
102-
runs-on: ubuntu-latest
102+
runs-on: ubuntu-latest-xl
103103
steps:
104104
- uses: actions/checkout@v4
105105
- uses: dtolnay/rust-toolchain@stable

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
fail-fast: false
2020
matrix:
2121
include:
22-
- os: ubuntu-latest
22+
- os: ubuntu-latest-xl
2323
target: x86_64-unknown-linux-gnu
2424
artifact_name: bitcell-linux-x86_64
2525
- os: macos-latest
@@ -115,7 +115,7 @@ jobs:
115115
release:
116116
name: Upload Release Assets
117117
needs: build
118-
runs-on: ubuntu-latest
118+
runs-on: ubuntu-latest-xl
119119
if: github.event_name == 'release'
120120
permissions:
121121
contents: write

AGENT_PLAN.md

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# AI Agent Implementation Plan: BitCell RC1 Readiness
2+
3+
This plan outlines a linear, dependency-aware workflow for an AI agent to bring the BitCell codebase to RC1 readiness. Execute these steps in order.
4+
5+
---
6+
7+
## Phase 1: Core Functionality (Transactions & State)
8+
9+
### 1.1. Implement Transaction Building in Wallet GUI
10+
**Goal**: Enable users to create real transactions.
11+
**Files**: `crates/bitcell-wallet-gui/src/main.rs`
12+
**Action**:
13+
1. Locate `on_send_transaction` callback.
14+
2. Replace the `mock_tx` string formatting with actual `Transaction` struct construction.
15+
3. Use `rpc_client.get_nonce(from_address)` to get the correct nonce.
16+
4. Sign the transaction using the wallet's private key.
17+
5. Serialize the transaction (bincode/hex).
18+
6. Call `rpc_client.send_raw_transaction(hex_tx)`.
19+
20+
### 1.2. Implement Raw Transaction Decoding in RPC
21+
**Goal**: Process incoming raw transactions.
22+
**Files**: `crates/bitcell-node/src/rpc.rs`
23+
**Action**:
24+
1. In `bitcell_sendRawTransaction`:
25+
2. Decode the hex string into bytes.
26+
3. Deserialize bytes into `Transaction` struct.
27+
4. Validate signature and nonce.
28+
5. Add to `TxPool` (via `node.tx_pool`).
29+
6. Return the transaction hash.
30+
31+
### 1.3. Implement Balance Fetching in RPC
32+
**Goal**: Return real account balances.
33+
**Files**: `crates/bitcell-node/src/rpc.rs`
34+
**Action**:
35+
1. In `eth_getBalance`:
36+
2. Parse the address (PublicKey).
37+
3. Access `node.blockchain.state`.
38+
4. Call `state.get_account(address)`.
39+
5. Return `account.balance` (or 0 if not found).
40+
41+
### 1.4. Implement State Persistence (RocksDB)
42+
**Goal**: Persist state across restarts.
43+
**Files**: `crates/bitcell-state/src/storage.rs`, `crates/bitcell-state/Cargo.toml`
44+
**Action**:
45+
1. Add `rocksdb` dependency to `bitcell-state`.
46+
2. Implement `Storage` trait using RocksDB.
47+
3. Store `Account` and `BondState` data serialized.
48+
4. Update `StateManager` to use this persistent storage instead of `HashMap`.
49+
50+
---
51+
52+
## Phase 2: Security & Verification
53+
54+
### 2.1. Implement VRF for Block Proposers
55+
**Goal**: Randomize block proposer selection.
56+
**Files**: `crates/bitcell-node/src/blockchain.rs`, `crates/bitcell-crypto/src/vrf.rs` (create if needed)
57+
**Action**:
58+
1. Implement ECVRF (Elliptic Curve Verifiable Random Function) using `schnorrkel` or similar.
59+
2. In `produce_block`:
60+
- Generate VRF output using previous block's VRF output as input.
61+
- Store `vrf_output` and `vrf_proof` in `BlockHeader`.
62+
3. In `validate_block`:
63+
- Verify the `vrf_proof` against the proposer's public key.
64+
65+
### 2.2. Implement ZKP Circuits (Basic Verification)
66+
**Goal**: Verify battle outcomes cryptographically.
67+
**Files**: `crates/bitcell-zkp/src/battle_circuit.rs`, `crates/bitcell-zkp/src/lib.rs`
68+
**Action**:
69+
1. Update `Groth16Proof` struct to hold real proof data (Bellman/Arkworks).
70+
2. In `BattleCircuit`:
71+
- Define constraints for CA evolution (start state -> end state).
72+
- Even a simplified version checking hash consistency is better than mock.
73+
3. Update `generate_proof` to actually run the setup and prove.
74+
4. Update `verify` to run the verifier.
75+
76+
---
77+
78+
## Phase 3: Networking
79+
80+
### 3.1. Integrate libp2p Gossipsub
81+
**Goal**: Efficient block/tx propagation.
82+
**Files**: `crates/bitcell-network/src/transport.rs`, `crates/bitcell-network/Cargo.toml`
83+
**Action**:
84+
1. Ensure `libp2p` features `gossipsub` are enabled.
85+
2. Initialize `Gossipsub` behaviour in the swarm.
86+
3. Subscribe to topics: `blocks`, `transactions`, `consensus`.
87+
4. Implement `broadcast_block` and `broadcast_transaction` to publish to these topics.
88+
5. Handle incoming gossip messages in the event loop.
89+
90+
---
91+
92+
## Phase 4: Observability
93+
94+
### 4.1. Real-Time Metrics Collection
95+
**Goal**: Populate admin dashboard with real data.
96+
**Files**: `crates/bitcell-admin/src/api/metrics.rs`
97+
**Action**:
98+
1. Inject `Arc<Node>` or `Arc<MetricsRegistry>` into the admin API state.
99+
2. In `get_metrics`:
100+
- Read `uptime` from node start time.
101+
- Read `block_height` from blockchain.
102+
- Read `peer_count` from network manager.
103+
- Calculate `average_block_time` from recent blocks.
104+
105+
### 4.2. Connect Block Explorer
106+
**Goal**: Show real chain data.
107+
**Files**: `crates/bitcell-admin/src/api/blocks.rs`
108+
**Action**:
109+
1. In `get_blocks`:
110+
- Iterate backwards from current height.
111+
- Fetch blocks from `blockchain`.
112+
- Map to API response format.
113+
2. In `get_block_by_hash`:
114+
- Lookup block in `blockchain`.
115+
116+
---
117+
118+
## Phase 5: Polish & Cleanup
119+
120+
### 5.1. Replace Panic with Result
121+
**Goal**: Robust error handling.
122+
**Files**: `crates/bitcell-ca/src/grid.rs`, `crates/bitcell-state/src/bonds.rs`
123+
**Action**:
124+
1. Search for `panic!`.
125+
2. Change function signature to return `Result<T, Error>`.
126+
3. Propagate errors up the stack.
127+
128+
### 5.2. Expose Node Identity & Reputation
129+
**Goal**: Complete RPC API.
130+
**Files**: `crates/bitcell-node/src/rpc.rs`
131+
**Action**:
132+
1. In `getNodeInfo`, return actual `local_peer_id`.
133+
2. Implement `bitcell_getReputation` by querying `TournamentManager`.
134+
135+
### 5.3. Hex Parsing Utils
136+
**Goal**: Clean code.
137+
**Files**: `crates/bitcell-node/src/rpc.rs`
138+
**Action**:
139+
1. Use `hex::decode` consistently instead of manual string slicing.
140+
2. Add proper error handling for invalid hex strings.
141+
142+
---
143+
144+
## Execution Strategy
145+
146+
1. **Sequential Execution**: Follow the phases in order (1 -> 5).
147+
2. **Verification**: Run `cargo test` after each major component implementation.
148+
3. **Integration**: Run the full node and wallet to verify end-to-end functionality (e.g., send a tx and see it in the explorer).

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ark-groth16 = "0.4"
3737
ark-bn254 = "0.4"
3838
ark-bls12-381 = "0.4"
3939
ark-crypto-primitives = "0.4"
40+
ark-snark = "0.4"
4041

4142
# Cryptography
4243
sha2 = "0.10"

README.md

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[![Rust](https://img.shields.io/badge/rust-1.82%2B-orange.svg)](https://www.rust-lang.org/)
66
[![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](LICENSE)
7-
[![Status](https://img.shields.io/badge/status-alpha-yellow.svg)](https://github.com/Steake/BitCell)
7+
[![Status](https://img.shields.io/badge/status-RC1-green.svg)](https://github.com/Steake/BitCell)
88

99
> _"We don't mine blocks. We cultivate them in a Conway garden where only the fittest gliders survive."_
1010
@@ -174,9 +174,14 @@ Three independent circuits:
174174
**v0.1**: Individual Groth16 proofs
175175
**Future**: Recursive aggregation via Plonk/STARK
176176

177-
## Economics (Deterministic Payouts)
177+
## Economics (Bitcoin-Style Halving)
178178

179179
```
180+
Initial block reward: 50 CELL
181+
Halving interval: 210,000 blocks (~4 years)
182+
Maximum halvings: 64 (subsidy reaches 0)
183+
Total supply: ~21 million CELL
184+
180185
block_reward = base_subsidy(h) + tx_fees + contract_fees
181186
182187
Distribution:
@@ -252,13 +257,17 @@ BitCell/
252257
│ ├── bitcell-ebsl/ # Evidence tracking, trust scores, slashing
253258
│ ├── bitcell-zkp/ # Groth16 circuits (battle, exec, state)
254259
│ ├── bitcell-consensus/ # Blocks, tournament protocol, fork choice
255-
│ ├── bitcell-state/ # State management, bonds, accounts
260+
│ ├── bitcell-state/ # State management, bonds, accounts (RocksDB)
256261
│ ├── bitcell-zkvm/ # Private smart contract execution
257-
│ ├── bitcell-economics/ # Rewards, fees, treasury
258-
│ ├── bitcell-network/ # P2P, gossip, compact blocks
259-
│ └── bitcell-node/ # Miner/validator/light client nodes
260-
├── docs/ # Architecture, specs, tutorials
261-
├── benches/ # Performance benchmarks
262+
│ ├── bitcell-economics/ # Rewards, fees, treasury, halving
263+
│ ├── bitcell-network/ # libp2p, gossip, DHT, compact blocks
264+
│ ├── bitcell-node/ # Miner/validator nodes, JSON-RPC, WebSocket
265+
│ ├── bitcell-wallet/ # CLI wallet
266+
│ ├── bitcell-wallet-gui/ # GUI wallet with tournament visualization
267+
│ ├── bitcell-admin/ # Admin console with metrics
268+
│ └── bitcell-simulation/ # Network simulation and testing
269+
├── docs/ # Architecture, specs, release notes
270+
├── scripts/ # Development and testing scripts
262271
└── tests/ # Integration tests
263272
```
264273

@@ -302,33 +311,38 @@ We're in alpha. Things break. PRs welcome.
302311

303312
## Roadmap
304313

305-
### v0.1 (Current: Alpha)
314+
### v0.1 ✅ (Alpha)
306315
- [x] Core crypto primitives (ECDSA, VRF, ring sigs, commitments)
307316
- [x] CA engine with battles (1024×1024 grid, Conway rules, energy)
308317
- [x] EBSL trust scores (evidence tracking, decay, slashing)
309-
- [ ] ZK circuits (battle verification, execution, state)
310-
- [ ] Consensus structures (blocks, tournament, fork choice)
311-
- [ ] P2P networking (gossip, compact blocks)
312-
- [ ] Local testnet
313-
314-
### v0.2 (Beta)
315-
- [ ] ZKVM execution
316-
- [ ] Smart contract deployment
317-
- [ ] State management
318-
- [ ] Full validator implementation
319-
- [ ] Public testnet
320-
- [ ] Explorer
321-
322-
### v0.3 (Candidate)
318+
- [x] ZK circuits (battle verification, execution, state constraints)
319+
- [x] Consensus structures (blocks, tournament, fork choice)
320+
- [x] P2P networking (libp2p-based gossip, DHT)
321+
- [x] Local testnet
322+
323+
### v0.2 ✅ (Beta)
324+
- [x] ZKVM execution framework
325+
- [x] Smart contract deployment (basic)
326+
- [x] State management with RocksDB persistence
327+
- [x] Full validator implementation
328+
- [x] GUI Wallet with tournament visualization
329+
- [x] Admin console with metrics
330+
331+
### v0.3 (Current: Release Candidate 1)
332+
- [x] JSON-RPC and WebSocket APIs
333+
- [x] Block reward halving mechanism (Bitcoin-style economics)
334+
- [x] Transaction processing and mempool
335+
- [x] Comprehensive economic parameters
336+
- [x] Security improvements (DoS protection, gas limits)
323337
- [ ] Light clients
324338
- [ ] Bridge to Ethereum
325339
- [ ] DeFi primitives
326-
- [ ] Governance system
327-
- [ ] Security audit
328340

329341
### v1.0 (Mainnet)
330-
- [ ] Production-ready zkSNARKs
331-
- [ ] Optimized CA performance
342+
- [ ] Production-ready zkSNARKs (recursive aggregation)
343+
- [ ] Governance system
344+
- [ ] Security audit
345+
- [ ] Optimized CA performance (SIMD/GPU)
332346
- [ ] Mobile wallets
333347
- [ ] Full documentation
334348
- [ ] 🚀 Launch

README.old.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)