Skip to content

fix(soroban): fix off-by-one key extraction in listStorageKeys - #276

Merged
akargi merged 1 commit into
Chulilee:mainfrom
shobhamerabacha-star:fix/list-storage-keys-off-by-one-87
Oct 2, 2026
Merged

akargi merged 1 commit into
Chulilee:mainfrom
shobhamerabacha-star:fix/list-storage-keys-off-by-one-87

Conversation

@shobhamerabacha-star

Copy link
Copy Markdown
Contributor

Summary

This PR resolves an off-by-one error in ContractStateService.listStorageKeys() where parts[3] was returning the cache entry's durability instead of the actual storage key. It also adds warning logging when individual key reads fail during exportContractState() and provides full unit test coverage.

Changes Made

  1. Storage Key Indexing & Structure (src/modules/stellar/soroban/contract-state.service.ts):

    • Cache key format: soroban:state:{contractId}:{durability}:{keyPart}.
    • Updated listStorageKeys() to check parts.length >= 5 and extract parts.slice(4).join(':'), ensuring storage keys with colons are fully preserved.
    • Retained raw key as fallback when the key does not match standard segment counts.
  2. Failure Logging (exportContractState):

    • Added this.logger.warn() in exportContractState when individual key fetches fail, replacing silent error swallowing while allowing the rest of the export to proceed.
  3. Unit Test Coverage (src/modules/stellar/soroban/contract-state.service.spec.ts):

    • Verified that listStorageKeys() returns actual storage keys (admin_address, fee_rate) and never durability strings (persistent, temporary).
    • Verified that complex storage keys with embedded colons (user:account:12345) are preserved.
    • Verified fallback behavior for non-conforming cache keys.
    • Verified exportContractState() exports all cached state and logs a warning on key read failure.

Closes #87

- Fix listStorageKeys returning durability instead of the storage key by indexing parts.slice(4).join(':')
- Guard against unexpected key shapes with parts.length >= 5
- Add warning logging in exportContractState when individual key reads fail
- Add unit tests for listStorageKeys (durability vs key, colon handling, fallback) and exportContractState
@vercel

vercel Bot commented Oct 1, 2026

Copy link
Copy Markdown

@shobhamerabacha-star is attempting to deploy a commit to the Akargi Team on Vercel.

A member of the Team first needs to authorize it.

@ykargeee-bit

Copy link
Copy Markdown
Contributor

✅ Ready to merge — all CI checks pass (Build and TypeScript Check ✅). The Vercel deployment failures are authorization issues unrelated to the code changes. This PR fixes an off-by-one bug in Soroban contract state key extraction and includes comprehensive tests. Safe to merge when a maintainer with write access reviews.

@akargi
akargi merged commit d4a8f3f into Chulilee:main Oct 2, 2026
1 of 3 checks passed
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.

[Bug]: listStorageKeys() returns the durability instead of the storage key (off-by-one)

3 participants