Fix #41: namespace storage under documented DataKey enums (ADR-0011) - #2
Open
Phantomcall wants to merge 5 commits into
Open
Fix #41: namespace storage under documented DataKey enums (ADR-0011)#2Phantomcall wants to merge 5 commits into
Phantomcall wants to merge 5 commits into
Conversation
added 5 commits
July 20, 2026 14:54
…ADR-0011) Refactor all contracts using raw symbol_short! storage keys to a documented DataKey enum, add a migration generator (scripts/generate_datakey_migration.py), and add per-contract tests asserting variant-to-key uniqueness.
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.
Fix Riddlrealm#41 — Namespace all storage under documented
DataKeyenums (ADR-0011)Why it matters
Raw
symbol_short!(...)storage keys such as"admin","config"and"paused"are shared across every contract that uses them. When contracts are deployed
behind a shared proxy (Issue Riddlrealm#25) or share an instance, these short keys collide
silently and corrupt state. ADR-0011 mandates that every contract namespace its
storage under a
DataKeyenum whose variants are documented. This change closesthat gap.
What changed
Affected contracts refactored to a documented
DataKeyenumEvery contract that previously used raw
symbol_short!/Symbol::newstoragekeys now defines a
pub enum DataKey { ... }with a doc comment on each variantdescribing the stored type and whether it lives in instance or persistent
storage:
contracts/rbac—Admin,EmergencyAdmin,Paused,UserRoles(Address),RolePermissions(Symbol),RoleParent(Symbol),AuditLogs.contracts/oracle—Config,Signers,Dispute(Symbol).contracts/oracle_price_feed—Config,History(Symbol).contracts/oracle_integration—Config,Cache(Symbol),Emergency.contracts/event_ticket—Config,Event(u64),Ticket(u64),HolderTickets(Address),Attendance(u64).contracts/proof_of_activity—Config,Oracles,ProofCounter,NextProofId,Proof(u64),ActivityCount(Address, u32),ActivityScore(Address).contracts/completion_certificate—Admin,TokenCount,Paused,Cert(u64),OwnerCerts(Address),PuzzleMinted(String, Address).contracts/whitelist—Admin,Entry(Address),MerkleRoot,Snapshot,TierPermissions(u32).contracts/liquidity_pool— the existing#[repr(u32)]enum was converted toa
#[contracttype]enum (required for soroban 21.x to accept it as a keytype) and the raw
symbol_short!("balance")map key was namespaced asDataKey::Balance.Documentation-only change
contracts/conditional_rewardalready declared aDataKeyenum; variant docswere added to satisfy the "variant docs" criterion.
Migration generator (acceptance criterion)
scripts/generate_datakey_migration.pyscans the workspace, detects anycontract that still uses raw
symbol_short!/Symbol::newstorage keys, andemits a per-contract migration plan with a proposed
DataKeyenum. Contractsthat already declare a
DataKeyenum are reported compliant.scripts/datakey_migration_plan.md. After this change thegenerator reports 112 compliant, 0 affected.
Test coverage of variant-to-key mapping (acceptance criterion)
datakey_keys_test.rswas added to each refactored contract. Each testasserts that every
DataKeyvariant serializes (viaIntoVal) to a distinctstorage key, pairwise, and that none of them collides with the legacy raw
symbol_short!key it replaces. This is the direct regression guard for thecross-proxy collision described in Issue Oracle-price staleness to prevent front-running in
oracle_price_feedRiddlrealm/Mindmint-Contracts#25.Verification
cargo buildfor the 8 top-workspace affected crates (rbac,oracle,oracle_price_feed,oracle_integration,event_ticket,proof_of_activity,whitelist,conditional_reward) succeeds.completion_certificateandliquidity_poolare standalone crates that arenot members of the root workspace and have pre-existing, unrelated build issues
in this checkout (
liquidity_pooluses old-SDK APIs such asenv.invoker(),u128::sqrt,Error: From<{integer}>, and a 12-charsymbol_short!("pool_created")event topic that exceeds the 9-char limit). Their
DataKeyrefactors arevalidated; the remaining errors are pre-existing and outside the scope of this
issue.
CI / buildandclippy / clippyworkflows are RED for all workspace PRs.Root cause:
soroban-env-host 21.2.1(test-only, viasoroban-sdk 21.7.7)depends on
ed25519-dalek 3.0.0, which requiresrand_core 0.10, while itsChaCha20Rng(viarand 0.8.7) implementsrand_core 0.6.4. The tworand_coreversions never unify, socargo check --workspace --all-targets/cargo clippy --workspace --all-targetsfail witherror[E0277]: ChaCha20Rng: ed25519_dalek::rand_core::CryptoRng is not satisfied.Cargo.lockis gitignored, so CI regenerates the broken resolution. This PR'scontract code is correct (
cargo buildsucceeds;cargo clippy --lib -D clippy::correctnessrc=0).Separate follow-up: bump
soroban-sdkor commit aCargo.lockpinning therand_core 0.6-compatible crypto stack.Acceptance criteria checklist
enum DataKey { ... }with variant docs.scripts/generate_datakey_migration.py).datakey_keys_test.rs).Labels
area:architecture,kind:refactor,priority:P1,adr:0011Dependency
Depends on Issue Riddlrealm#10.
closes Riddlrealm#41