feat(stellar): pin and verify escrow contract metadata#311
Merged
mikewheeleer merged 1 commit intoJun 2, 2026
Merged
Conversation
|
@Muyideen-js Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Closes #271
Description:
Adds contract metadata pinning and verification to prevent operating on swapped/unexpected escrow contracts.
Loads an optional pinned metadata hash from SOROBAN_ESCROW_CONTRACT_METADATA_HASH and verifies fetched on-chain metadata against it before use.
On mismatch: refuses to operate, throws a safe ContractMetadataMismatchError, and increments Prometheus metric contract_metadata_mismatch_total{contract}.
Includes deterministic canonicalization and SHA-256 hashing for stable verification.
Adds unit tests for match and mismatch behavior.
Files changed:
Added: contractMetadata.ts, contractMetadata.unit.test.ts
Modified: sorobanEnv.ts, safeErrors.ts, appError.ts
Testing:
Unit tests added cover canonicalization, successful verification, and mismatch + metric.
Please run:
Acceptance criteria:
Integration tests should cover both matching metadata (allowed) and mismatched metadata (rejected). The new unit tests demonstrate the core behavior. I recommend adding an integration test that wires the module into the Soroban RPC integration path (e.g., via an injected fetcher or a mock RPC server) to exercise end-to-end behavior.
Security notes & assumptions
The pinned hash is a SHA-256 hex digest of a canonicalized JSON representation of contract metadata. Rotation procedure: update SOROBAN_ESCROW_CONTRACT_METADATA_HASH in your environment/secrets, deploy with a canary, and verify metric / health checks before promoting.
No secrets are stored in code. Use environment secrets in deployment.
The verification function accepts an injectable fetcher (for safe unit/integration testing). In production, wire it to your Soroban RPC client with appropriate retry/backoff and auth if required.
On mismatch, the module throws a safe error code contract_metadata_mismatch. The safe message is mapped in safeErrors.ts.
Added Prometheus counter metric contract_metadata_mismatch_total to alert on unexpected contract metadata changes.