-
Notifications
You must be signed in to change notification settings - Fork 16
Reimplementation of the world program with Pinocchio #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
34 files reviewed, 20 comments
pub const ADD_AUTHORIITY_DISCRIMINATOR: u64 = 13217455069452700133; | ||
pub const REMOVE_AUTHORIITY_DISCRIMINATOR: u64 = 15585545156648003826; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax: Typo in constant names: 'AUTHORIITY' should be 'AUTHORITY'
pub const ADD_AUTHORIITY_DISCRIMINATOR: u64 = 13217455069452700133; | |
pub const REMOVE_AUTHORIITY_DISCRIMINATOR: u64 = 15585545156648003826; | |
pub const ADD_AUTHORITY_DISCRIMINATOR: u64 = 13217455069452700133; | |
pub const REMOVE_AUTHORITY_DISCRIMINATOR: u64 = 15585545156648003826; |
ApproveSystem = APPROVE_SYSTEM_DISCRIMINATOR, | ||
RemoveSystem = REMOVE_SYSTEM_DISCRIMINATOR, | ||
AddEntity = ADD_ENTITY_DISCRIMINATOR, | ||
InitilizeComponent = INITIALIZE_COMPONENT_DISCRIMINATOR, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax: Typo in enum variant: 'InitilizeComponent' should be 'InitializeComponent'
InitilizeComponent = INITIALIZE_COMPONENT_DISCRIMINATOR, | |
InitializeComponent = INITIALIZE_COMPONENT_DISCRIMINATOR, |
@@ -0,0 +1 @@ | |||
pub const DISCRIMATOR_LENGTH: usize = 8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax: Typo in constant name: 'DISCRIMATOR_LENGTH' should be 'DISCRIMINATOR_LENGTH' (missing 'IN'). This matches the naming convention used elsewhere and fixes the spelling error.
pub const DISCRIMATOR_LENGTH: usize = 8; | |
pub const DISCRIMINATOR_LENGTH: usize = 8; |
if *is_permissionless { | ||
*is_permissionless = false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax: Missing semicolon after assignment
if *is_permissionless { | |
*is_permissionless = false | |
} | |
if *is_permissionless { | |
*is_permissionless = false; | |
} |
if !authorities.contains(authority_to_delete.key()) { | ||
return Err(WorldError::InvalidAuthority.into()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Missing authority validation - should verify that the calling authority
has permission to remove other authorities from the world
AccountMeta::readonly(self.instruction_sysvar_account.key()), | ||
]; | ||
|
||
const DISCRIMATOR_LENGTH: usize = 8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax: Typo: 'DISCRIMATOR_LENGTH' should be 'DISCRIMINATOR_LENGTH'
const DISCRIMATOR_LENGTH: usize = 8; | |
const DISCRIMINATOR_LENGTH: usize = 8; |
@@ -0,0 +1,70 @@ | |||
use crate::consts::DISCRIMATOR_LENGTH; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax: Typo in constant name: 'DISCRIMATOR_LENGTH' should be 'DISCRIMINATOR_LENGTH'
use crate::consts::DISCRIMATOR_LENGTH; | |
use crate::consts::DISCRIMINATOR_LENGTH; |
} | ||
.invoke()?; | ||
|
||
let return_data = get_return_data().ok_or(ProgramError::InvalidAccountData)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Return data validation only checks for existence, not minimum size. If system returns malformed data with less than 4 bytes, the subsequent parsing will fail.
return Err(ProgramError::MissingRequiredSignature); | ||
} | ||
|
||
let world_id = u64::from_le_bytes(unsafe { (data.as_ptr() as *const [u8; 8]).read() }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Unsafe pointer casting without length validation could cause memory safety issues if data is shorter than 8 bytes
let world_id = u64::from_le_bytes(unsafe { (data.as_ptr() as *const [u8; 8]).read() }); | |
let world_id = u64::from_le_bytes( | |
data.get(..8) | |
.ok_or(ProgramError::InvalidInstructionData)? | |
.try_into() | |
.map_err(|_| ProgramError::InvalidInstructionData)? | |
); |
|
||
let mut instruction_data = [0u8; 1024]; | ||
|
||
const DISCRIMATOR_LENGTH: usize = 8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax: Typo in constant name: 'DISCRIMATOR_LENGTH' should be 'DISCRIMINATOR_LENGTH' to match standard spelling
const DISCRIMATOR_LENGTH: usize = 8; | |
const DISCRIMINATOR_LENGTH: usize = 8; |
How are you testing it? |
Problem
What problem are you trying to solve?
Anchor is not the most adequate for real-time systems on solana. Bloated, slow, expensive
Solution
How did you solve the problem?
Rewrite pieces of bolt with zero-copy pinocchio with full backwards compatiblity
Before & After Screenshots
Deploy Notes
cargo build-sbf
overanchor build
.anchor build
for generating idlsNew dependencies:
pinocchio
: PinocchioGreptile Summary
This PR introduces a significant architectural change by implementing a Pinocchio-based alternative to the existing Anchor-based world program in the Bolt framework. The core motivation is performance optimization - addressing Anchor's limitations for real-time systems on Solana by replacing it with zero-copy operations.
Key Changes:
New Pinocchio World Program: A complete rewrite of the world program using the
pinocchio
framework, located incrates/pinocchio/world/
. This includes all instruction handlers (add_entity
,apply_system
,initialize_component
, etc.) rewritten with manual memory management and unsafe operations for performance.CPI Interface Layer: A new
bolt-cpi-interface
crate that provides cross-program invocation interfaces for component operations (initialize, update, destroy) and system execution using Pinocchio's primitives instead of Anchor's CPI abstractions.State Management Rewrite: Complete reimplementation of state structures (
World
,Entity
,Registry
,SystemWhitelist
) using zero-copyTransmutable
traits and manual discriminator handling.Instruction Dispatching: Custom instruction dispatch system using u64 discriminators instead of Anchor's automatic deserialization, with manual byte parsing and unsafe pointer operations.
Architecture Integration:
The implementation maintains full backwards compatibility by preserving the same program ID, instruction discriminators, and account structures. This allows existing clients to work unchanged while benefiting from reduced compute unit costs. The new implementation coexists with the existing Anchor version, suggesting a gradual migration strategy where both can operate during the transition period.
The change affects the core ECS (Entity Component System) functionality of Bolt, including world management, entity creation, component lifecycle, and system execution - all critical paths for real-time blockchain gaming applications.
Confidence score: 1/5
crates/pinocchio/world/src/instructions/mod.rs
,crates/pinocchio/world/src/state/world.rs
,crates/pinocchio/world/src/consts.rs