ALPHAVM_SIMPLIFICATION_PLAN.md
1 # AlphaVM Simplification Plan 2 3 ## Overview 4 5 Simplify AlphaVM for single-token private economy (AX credits) by removing/disabling unused functionality. ALPHA chain only needs to run `credits.alpha` - no third-party smart contracts. 6 7 **Key Discovery**: Credits.alpha circuits are ALREADY pre-compiled and embedded in `alphavm/parameters/`. The lazy-loading pattern in `Stack::get_proving_key()` handles this automatically. 8 9 --- 10 11 ## Phase 1: Disable Program Deployment (HIGH IMPACT) 12 13 **Goal**: Prevent any new program deployments; only `credits.alpha` is allowed. 14 15 ### 1.1 Disable Feature Flags 16 17 **File**: `/mnt/c/Users/MarcoAniballi/Claude-Code/BlockBlox-MD/alphavm/Cargo.toml` 18 19 Remove from default features: 20 ```toml 21 default = [ 22 "algorithms", 23 "circuit", 24 "console", 25 "ledger", 26 "parameters", 27 "synthesizer", 28 "utilities", 29 # REMOVE: "package", 30 # REMOVE: "file", 31 ] 32 ``` 33 34 This disables: 35 - `vm/package/` module (deployment handling) 36 - `vm/file/` module (program file handling) 37 38 ### 1.2 Reject Deploy Transactions at VM Level 39 40 **File**: `/mnt/c/Users/MarcoAniballi/Claude-Code/BlockBlox-MD/alphavm/synthesizer/src/vm/verify.rs` 41 42 Add early rejection in `check_transaction()` (around line 183): 43 ```rust 44 Transaction::Deploy(..) => { 45 bail!("Program deployment is disabled. Only credits.alpha is supported."); 46 } 47 ``` 48 49 ### 1.3 Remove Deployment from Finalization 50 51 **File**: `/mnt/c/Users/MarcoAniballi/Claude-Code/BlockBlox-MD/alphavm/synthesizer/src/vm/finalize.rs` 52 53 In `atomic_speculate()` (lines 386-443), replace deploy handling with error: 54 ```rust 55 ConfirmedTransaction::AcceptedDeploy(..) | ConfirmedTransaction::RejectedDeploy(..) => { 56 bail!("Program deployment is disabled"); 57 } 58 ``` 59 60 ### 1.4 Skip Deployment Loading on Startup 61 62 **File**: `/mnt/c/Users/MarcoAniballi/Claude-Code/BlockBlox-MD/alphavm/synthesizer/src/vm/mod.rs` 63 64 In `load_existing_deployments()` (lines 190-220): 65 - Keep loading `credits.alpha` (required) 66 - Skip all other programs or log warning 67 68 **Estimated Impact**: ~500 lines disabled, eliminates entire deployment code path 69 70 --- 71 72 ## Phase 2: Restrict Instruction Set (MEDIUM IMPACT) 73 74 **Goal**: Only allow instructions used by `credits.alpha`. 75 76 ### 2.1 Credits.alpha Uses Only 13 Instructions 77 78 **Keep**: 79 - Arithmetic: `add`, `sub` 80 - Comparison: `gte`, `gt`, `lte`, `lt`, `is.eq`, `is.neq` 81 - Bitwise: `and`, `or`, `nor` 82 - Control: `ternary`, `async` 83 - Type: `cast` 84 - Finalize: `contains`, `get`, `get.or_use`, `set`, `remove`, `position`, `branch.eq` 85 86 **Remove** (85+ instructions): 87 - All hash operations (35+): `hash.bhp*`, `hash.keccak*`, `hash.ped*`, `hash.psd*`, `hash.sha3*` 88 - All commit operations (6): `commit.bhp*`, `commit.ped*` 89 - All ECDSA operations 90 - Serialization operations 91 - Unused math: `pow`, `sqrt`, `inv`, `abs`, `double`, `neg`, `square` 92 - Unused bitwise: `xor`, `nand`, `not`, `shl`, `shr` 93 94 ### 2.2 Add Instruction Whitelist 95 96 **File**: `/mnt/c/Users/MarcoAniballi/Claude-Code/BlockBlox-MD/alphavm/synthesizer/process/src/stack/register_types/initialize.rs` 97 98 Add validation at instruction check (around line 347): 99 ```rust 100 fn is_allowed_instruction(opcode: &Opcode) -> bool { 101 matches!(opcode, 102 Opcode::Add | Opcode::Sub | 103 Opcode::Gte | Opcode::Gt | Opcode::Lte | Opcode::Lt | 104 Opcode::IsEq | Opcode::IsNeq | 105 Opcode::And | Opcode::Or | Opcode::Nor | 106 Opcode::Ternary | Opcode::Async | Opcode::Cast 107 ) 108 } 109 ``` 110 111 **Estimated Impact**: Prevents execution of 85+ unused instruction types 112 113 --- 114 115 ## Phase 3: Simplify Type Validation (MEDIUM IMPACT) 116 117 **Goal**: Reduce type system to credits.alpha requirements. 118 119 ### 3.1 Credits.alpha Uses Only 5 Literal Types 120 121 **Keep**: `address`, `u64`, `u32`, `u8`, `boolean` 122 123 **Can Disable** (12 types): 124 - Signed integers: `i8`, `i16`, `i32`, `i64`, `i128` 125 - Large unsigned: `u16`, `u128` 126 - Cryptographic: `field`, `group`, `scalar` 127 - Other: `signature`, `string` 128 129 ### 3.2 Add Type Whitelist (Optional - Lower Priority) 130 131 **File**: `/mnt/c/Users/MarcoAniballi/Claude-Code/BlockBlox-MD/alphavm/console/program/src/data_types/literal_type/mod.rs` 132 133 Add validation helper: 134 ```rust 135 impl LiteralType { 136 pub fn is_credits_compatible(&self) -> bool { 137 matches!(self, 138 LiteralType::Address | 139 LiteralType::Boolean | 140 LiteralType::U8 | 141 LiteralType::U32 | 142 LiteralType::U64 143 ) 144 } 145 } 146 ``` 147 148 **Note**: This is lower priority since credits.alpha is the only program and already validated. 149 150 --- 151 152 ## Phase 4: Code Cleanup (LOW IMPACT - Optional) 153 154 **Goal**: Remove dead code paths for cleaner codebase. 155 156 ### 4.1 Files That Can Be Removed/Gated 157 158 Under `#[cfg(feature = "deployment")]` or removed entirely: 159 160 | File | Lines | Purpose | 161 |------|-------|---------| 162 | `synthesizer/process/src/deploy.rs` | 69 | Process::deploy() | 163 | `synthesizer/process/src/verify_deployment.rs` | 85 | Process::verify_deployment() | 164 | `synthesizer/process/src/stack/deploy.rs` | 223 | Stack::deploy/verify | 165 | `synthesizer/src/vm/deploy.rs` | 105 | VM::deploy() | 166 | `vm/package/` directory | ~400 | Package handling | 167 | `vm/file/` directory | ~300 | File handling | 168 169 **Total**: ~1,200 lines can be removed or feature-gated 170 171 ### 4.2 Cost Calculation Simplification 172 173 **File**: `/mnt/c/Users/MarcoAniballi/Claude-Code/BlockBlox-MD/alphavm/synthesizer/process/src/cost.rs` 174 175 - Remove `deployment_cost_v1()`, `deployment_cost_v2()` (not needed) 176 - Keep only `execution_cost()` for credits.alpha functions 177 - Can be simplified to static lookup table for 15 known functions 178 179 --- 180 181 ## Implementation Order 182 183 | Phase | Effort | Impact | Priority | 184 |-------|--------|--------|----------| 185 | 1.1 Feature flags | Low | High | **P0** | 186 | 1.2 Reject deploy TX | Low | High | **P0** | 187 | 1.3 Remove finalization | Low | High | **P0** | 188 | 1.4 Skip loading | Low | Medium | P1 | 189 | 2.1-2.2 Instruction whitelist | Medium | Medium | P1 | 190 | 3.1-3.2 Type whitelist | Medium | Low | P2 | 191 | 4.1-4.2 Code cleanup | Medium | Low | P3 | 192 193 --- 194 195 ## Testing Strategy 196 197 1. **Unit Tests**: Verify deployment rejection returns proper error 198 2. **Integration Tests**: Ensure credits.alpha still executes correctly 199 3. **Regression Tests**: Run full test suite after each phase 200 4. **Devnet Test**: Start devnet and verify transfers/staking work 201 202 --- 203 204 ## Rollback Plan 205 206 All changes are additive guards. To rollback: 207 1. Re-enable `package` and `file` features 208 2. Remove transaction rejection checks 209 3. No data migration needed 210 211 --- 212 213 ## Files to Modify (Phase 1 - Immediate) 214 215 1. `/mnt/c/Users/MarcoAniballi/Claude-Code/BlockBlox-MD/alphavm/Cargo.toml` - Remove features 216 2. `/mnt/c/Users/MarcoAniballi/Claude-Code/BlockBlox-MD/alphavm/synthesizer/src/vm/verify.rs` - Reject deploy TX 217 3. `/mnt/c/Users/MarcoAniballi/Claude-Code/BlockBlox-MD/alphavm/synthesizer/src/vm/finalize.rs` - Remove deploy finalization 218 4. `/mnt/c/Users/MarcoAniballi/Claude-Code/BlockBlox-MD/alphavm/synthesizer/src/vm/mod.rs` - Skip non-credits loading 219 220 ## Success Criteria 221 222 - [x] `cargo check -p alphavm --no-default-features` compiles 223 - [x] Deploy transactions are rejected with clear error 224 - [ ] credits.alpha transfers work correctly (pending devnet test) 225 - [ ] credits.alpha staking/bonding works correctly (pending devnet test) 226 - [ ] Devnet starts and produces blocks (pending devnet test) 227 228 --- 229 230 ## Implementation Progress 231 232 ### Phase 1: COMPLETED (2025-12-27) 233 234 **Commits:** 235 - `alphavm` @ e772e90: "feat(vm): Disable program deployment - credits.alpha only" 236 - `adnet` @ 3d57b2a: "feat(delta): Alpha-triggered startup and graceful degradation" 237 238 **Changes Made:** 239 1. ✅ Disabled `package` and `file` features in alphavm/Cargo.toml 240 2. ✅ Added deployment rejection in verify.rs (check_transaction + check_fee) 241 3. ✅ Added deployment rejection in finalize.rs (AcceptedDeploy + RejectedDeploy) 242 4. ✅ Added warning log for non-credits deployments in mod.rs 243 5. ✅ All 21 adnet tests pass 244 6. ✅ ~270 lines of deployment verification code removed 245 246 **Additional Work (adnet):** 247 - Added Alpha-triggered DELTA startup (waits for first attestation) 248 - Added graceful degradation (503 when Alpha unavailable) 249 - Deposit/withdraw endpoints check alpha_available flag 250 251 ### Phases 2-4: PENDING 252 253 These phases are lower priority and can be implemented later: 254 - Phase 2: Instruction set restriction (medium impact) 255 - Phase 3: Type system simplification (low impact) 256 - Phase 4: Dead code cleanup (optional)