Skip to content

smartcontract: derive multicast group PDA from code to prevent duplicates#3155

Open
martinsander00 wants to merge 3 commits intomainfrom
ms/3115
Open

smartcontract: derive multicast group PDA from code to prevent duplicates#3155
martinsander00 wants to merge 3 commits intomainfrom
ms/3115

Conversation

@martinsander00
Copy link
Contributor

Resolves: #3115

Summary

  • Multicast group PDAs were derived from a monotonic account_index, allowing two groups with the same code to be created at different addresses. Changed PDA derivation to use code as the seed (matching the Tenant pattern), so duplicate codes are structurally impossible — a second create with the same code derives the same PDA, which already exists, triggering AccountAlreadyInitialized.
  • Code-based lookups (get <code>) now derive the PDA directly for O(1) lookup instead of scanning all accounts. A fallback to getProgramAccounts scan ensures backward compatibility with legacy index-based accounts.
  • Removed globalstate mutation from the create processor (no longer increments account_index for multicast groups).

Lines of Code

Section Added Removed
serviceability (pda, create processor) +10 -17
sdk/rs (create, get, allowlist commands) +130 -120
cli +6 -6
activator +3 -3
integration tests +101 -89

Testing Verification

  • Added integration test test_multicastgroup_create_duplicate_code_fails that creates a multicast group, then attempts to create another with the same code and asserts failure
  • Added unit test test_commands_multicastgroup_get_legacy_index_pda_fallback that verifies code-based lookup falls back to getProgramAccounts scan when the code-derived PDA doesn't exist (legacy account scenario)
  • All existing multicast group tests updated and passing (create, get, list, activate, delete, subscribe, allowlist add/remove for both publishers and subscribers)

…0.9.0

testnet v0.9.0 was released before the code-based PDA change,
so it computes the wrong PDA against the current program.
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.

Address possibility of duplicate mg at PDA creation level

1 participant