Skip to content

feat(security): replace optimistic internal ledger with deterministic on-chain PDA delegation - #1

Open
bronyhomie365 wants to merge 1 commit into
devvvenus:mainfrom
bronyhomie365:feat/spacedeck-pda-delegation
Open

feat(security): replace optimistic internal ledger with deterministic on-chain PDA delegation#1
bronyhomie365 wants to merge 1 commit into
devvvenus:mainfrom
bronyhomie365:feat/spacedeck-pda-delegation

Conversation

@bronyhomie365

Copy link
Copy Markdown

Context

First of all, incredible work on the commerce-service.ts logic. 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 AtomicCommerceStore and 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 AtomicCommerceStore being 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:

[Spacedeck SDK] Initiating Intent: 7da9100f-3f98-4690-9b90-fc36a4b542a2
[Spacedeck SDK] Target: PDA Delegation Authorized
[RPC] Timeout detected. Transaction confirmation failed.
[Spacedeck SDK] Verifying on-chain state... PDA unchanged.
[Spacedeck SDK] Resolving intent state: ROLLBACK_SUCCESSFUL
[Agent] State synced. Capital safely preserved. Intent cancelled.

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant