feat(security): replace optimistic internal ledger with deterministic on-chain PDA delegation - #1
Open
bronyhomie365 wants to merge 1 commit into
Conversation
… on-chain PDA delegation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Context
First of all, incredible work on the
commerce-service.tslogic. The replay protection and atomic settlement safeguards you've built here make this easily the strongest submission for the Superteam Brasil bounty.However, during our adversarial testing (
Surfpool E2E), we identified a critical edge-case inherent to off-chain idempotency: The Stranded State.If a node crashes or experiences severe RPC latency between budget reservation in the
AtomicCommerceStoreand actual on-chain receipt claim, the agent thinks it has spent a budget but the chain disagrees, leading to an unrecoverable state desync in the local ledger.The Solution: Deterministic PDA Budgeting
This PR surgically replaces the optimistic internal ledger with deterministic PDA Delegation via the open-source
@spacedeck/sdk(MIT). By offloading idempotency and reservation logic directly to an on-chain PDA boundary, we eliminate the stranded state vector entirely.Instead of reserving an internal budget, the agent's budget is mathematically locked in a PDA, and the settlement is executed deterministically. If the RPC drops the transaction, the SDK natively handles the RPC polling and deterministic rollback for the agent.
State Synchronization Evidence (Sandbox Dry-Run)
To prove this prevents capital loss and state desync during a network failure, we ran the integration through a simulated RPC timeout.
Notice how, instead of the
AtomicCommerceStorebeing permanently stuck in a "pending" or "reserved" state, the Spacedeck SDK actively queries the PDA and gracefully rolls back the agent's intent when the transaction drops:Crucial Detail: The agent's local state cleanly recovers. By relying on the PDA as the single source of truth, an RPC failure no longer causes an unrecoverable desync.
Impact on Bounty
Upgrading from an optimistic off-chain store to a deterministic, zero-trust PDA model makes this skill the most robust, enterprise-grade AI commerce integration on Solana right now. It acts as a lightweight, highly secure delegation layer perfectly suited for this architecture.
Let me know if you want to jump on a quick call to review the PDA logic!