Skip to content

fix(storage): hash the map key in storage get --key - #180

Merged
illuzen merged 2 commits into
Quantus-Network:mainfrom
ara-stock:fix/storage-get-map-key-hasher
Oct 19, 2026
Merged

illuzen merged 2 commits into
Quantus-Network:mainfrom
ara-stock:fix/storage-get-map-key-hasher

Conversation

@ara-stock

Copy link
Copy Markdown
Contributor

Summary

quantus storage get --pallet <P> --name <N> --key <K> --key-type <T> builds the storage key as twox128(P) ++ twox128(N) ++ encode(K). It never applies the map's hasher. For System::Account (Blake2_128Concat), the example in the --key help text, the resulting key does not exist, so the command always prints "No value found". (#27 worked around this by passing a hand-built --storage-key.)

This PR looks up the entry's hasher in the live metadata and applies it to the encoded key (all seven StorageHasher variants). Using --key on a plain value, or on a map with more than one key, now returns a clear error instead of silently querying a key that does not exist.

Before (key built by the CLI) vs. what subxt's codegen produces for System::Account([7; 32]):

cli:     26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9 0707…07
codegen: 26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9 ddd6249d8a7334cf5ea37d21811e6671 0707…07

Testing

  • Added storage_map_key_matches_codegen_for_system_account, which compares against get_address_bytes for the generated System::Account address using the checked-in metadata, and storage_map_key_rejects_plain_storage_value. Both fail on main and pass with this change.
  • cargo test --lib, cargo clippy --all-targets -- -D warnings, cargo +nightly-2026-08-31 fmt --check. The only test failure is batch_verifier::loads_private_and_public_batch_verifiers, which needs generated circuit bins that I skipped with SKIP_CIRCUIT_BUILD=1.

I used an AI assistant (Claude) while preparing this. I reproduced the issue and checked the fix and tests myself.

🤖 Generated with Claude Code

ara-stock and others added 2 commits October 8, 2026 19:24
@illuzen
illuzen requested a review from n13 October 19, 2026 10:16
@illuzen illuzen added the bot-review Request automated review from review-bot label Oct 19, 2026

@n13 n13 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer model: GPT-6.1 Sol

APPROVE — no blocking findings in the diff from a74fd735fdb7cae2381b66dbaaa513630c0d58d9 to f3b638795462d5a0c6f8c02ee2ac2dd148a0c83e.

The seven hasher implementations match Subxt's storage-key construction. The caller selects metadata for the requested block before looking up the hasher; plain values and maps requiring multiple hashers return errors. The complete --storage-key path remains valid, and other keyed storage reads already use Subxt.

Validation:

  • SKIP_CIRCUIT_BUILD=1 cargo test --locked --lib cli::storage::tests: 8 passed, including both new regression tests.
  • cargo +nightly-2026-08-31 fmt --all -- --check: passed.
  • git diff --check a74fd735fdb7cae2381b66dbaaa513630c0d58d9...f3b638795462d5a0c6f8c02ee2ac2dd148a0c83e: passed.
  • GitHub format, dependency cooldown, Clippy/documentation, and security-audit checks passed. The Linux/macOS build-and-test and example jobs are still running.

Local validation was limited to the storage tests; circuit generation was skipped.

@n13 n13 removed the bot-review Request automated review from review-bot label Oct 19, 2026
@illuzen
illuzen merged commit 365ef8c into Quantus-Network:main Oct 19, 2026
9 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.

3 participants