:sparkles: System directly updates components
| Status | Type | ⚠️ Core Change | Issue |
|---|---|---|---|
| Ready | Feature | Yes | #194 |
Problem
Systems serializes and returns the components data with a limit of 1024kb so the component program can take the data and write it back.
Solution
Change the whole execution logic.
- Component program gives ownership of the component to the system program.
- System program executes and changes it.
- System program gives ownership back to the component program.
- World program checks if the system program gave the ownership back.
Breaking changes:
- This requires an intermediate Buffer account to hold the data while we change ownership and the clients needs to be updated to add the Buffer account to the transaction. The API is the same, but everyone has to update the client code.
- The execute function signature changed. We no longer return the serialized data.
- BoltMetadata was moved to the top of the component structure
CU report:
Small bar is CPI cost Big bar is total cost
Previous
%%{init: {"xyChart": {"width": 1200, "height": 400, "xAxis": {}}}}%%
xychart
title "Bolt Apply System Cost"
x-axis ["1C-CPIs:2","2C-CPIs:3","3C-CPIs:4","4C-CPIs:5","5C-CPIs:6","6C-CPIs:7","7C-CPIs:8","8C-CPIs:9","9C-CPIs:10","10C-CPIs:11"]
y-axis "CU" 5000 --> 200000
bar [15254,24352,33653,43017,52358,61568,71006,80482,89958,99299]
bar [6162,11236,16305,21374,26443,31516,36608,41892,46984,52077]
Using Anchor CPI code
%%{init: {"xyChart": {"width": 1200, "height": 400, "xAxis": {}}}}%%
xychart
title "Bolt Apply System Cost"
x-axis ["1C-CPIs:5","2C-CPIs:9","3C-CPIs:13","4C-CPIs:17","5C-CPIs:21","6C-CPIs:25","7C-CPIs:29","8C-CPIs:33","9C-CPIs:0","10C-CPIs:0"]
y-axis "CU" 5000 --> 200000
bar [24092,41860,59800,77799,95615,113456,131593,149581,0,0]
bar [6920,12931,18925,24915,30909,36900,42977,49059,0,0]
Using Solana CPI code
%%{init: {"xyChart": {"width": 1200, "height": 400, "xAxis": {}}}}%%
xychart
title "Bolt Apply System Cost"
x-axis ["1C-CPIs:5","2C-CPIs:9","3C-CPIs:13","4C-CPIs:17","5C-CPIs:21","6C-CPIs:25","7C-CPIs:29","8C-CPIs:33","9C-CPIs:37","10C-CPIs:40"]
y-axis "CU" 5000 --> 200000
bar [20119,34196,48290,62402,76546,90715,104998,119314,133655,0]
bar [6919,12930,18924,24914,30908,36899,42976,49058,55137,59718]
Greptile Summary
This PR implements a fundamental architectural redesign of the Bolt ECS framework to eliminate a critical 1024-byte limitation in component data serialization. Previously, systems would serialize component data and return it to component programs for storage, creating both size constraints and performance bottlenecks. The new execution model implements an ownership transfer pattern that allows systems to directly modify components of any size.
The core workflow changes from data serialization to ownership transfer: (1) Component programs transfer ownership of component accounts to system programs via a Buffer account, (2) System programs execute and directly modify component data in-place, (3) System programs return ownership back to component programs, and (4) World programs validate that ownership was properly restored. This eliminates the serialization step entirely while maintaining the ECS paradigm.
Key architectural changes include:
- Function signatures: System
executefunctions now returnResult<()>instead ofResult<Components>, removing the serialization requirement - New instructions: Added
set_ownerandset_datainstructions for ownership manipulation and data copying from buffer accounts - BoltMetadata positioning: Moved to the top of component structures to support the ownership transfer protocol
- Buffer accounts: Introduction of intermediate Buffer PDAs derived from authority keys to hold data during ownership transitions
- CPI authentication: Enhanced cross-program invocation security through
FindCpiAuthPda()for ownership transfer authorization - Client API changes: All apply operations now require buffer accounts, breaking existing client implementations
The implementation spans multiple language clients (TypeScript, C#) and removes multi-component apply instructions (apply2-apply5) in favor of the new unified ownership-based approach. The BoltAccount wrapper enables dynamic ownership validation during deserialization using const generics. While this change addresses the size limitation and improves performance, it requires comprehensive client code updates to include Buffer accounts in transactions.
Confidence score: 2/5
- This PR has significant implementation gaps and critical bugs that make it unsafe to merge in its current state
- Score reflects incomplete implementations in core system programs, infinite recursion bugs in C# client code, and placeholder functions that don't perform required operations
- Pay close attention to
crates/programs/bolt-system/src/lib.rs,crates/programs/bolt-component/src/lib.rs, andclients/csharp/Solana.Unity.Bolt/WorldProgram/World.cswhich contain empty implementations and serious bugs