✨ CPI Authentication using a World PDA #196
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
We needed to improve the CPI authentication mechanism to guarantee that the instruction is being called from the World program. We couldn't rely on getting the relative instructions from sysvar because we could only test against the topmost instruction, making it impossible to CPI the World program.
Solution
Use a PDA from the World program as an authentication mechanism.
Greptile Summary
This PR implements a significant security enhancement to the CPI (Cross-Program Invocation) authentication mechanism in the Bolt ECS framework. The change replaces the previous instruction sysvar-based authentication with a World PDA (Program Derived Address) based system.
What Changed:
The PR removes the vulnerable
solana_program::sysvar::instructions::get_instruction_relative
approach that could only verify the topmost instruction in a transaction. Instead, it introduces a hardcoded World PDA address (B2f2y3QTBv346wE6nWKor72AUhUvFF6mPk7TWCF2QVhi
) that serves as a cryptographic proof for legitimate CPI calls.Key Implementation Details:
CPI_AUTH_ADDRESS
constant across TypeScript and C# clientsinstruction_sysvar_account
fields withcpi_auth
fields in all instruction account structuresWorld::cpi_auth_seeds()
for signing CPI callscpi_auth
as aSigner
accountHow It Fits in the Codebase:
This change touches the core authentication layer of the Bolt ECS framework, affecting how the World program communicates with component programs. The World program now acts as the sole authority for component operations by providing its PDA signature, ensuring that only legitimate World program instructions can modify components. This maintains the architectural integrity of the ECS system while strengthening security guarantees.
Confidence score: 3/5