fix(#992): prevent double initialization and emit RegistryInitialized event in registry - #1075
Open
giftben1763-ui wants to merge 1 commit into
Open
Conversation
…istryInitialized event
- initialize() already had the has(&DataKey::Admin) guard; improved doc comment
to make the security invariant explicit
- Replace generic (symbol_short!("init"), admin) event with a dedicated
(symbol_short!("reg_init"),) RegistryInitialized event so off-chain indexers
can reliably detect first-time deployment
- Add unit tests:
- test_double_initialization_fails: confirms second init panics with 'already initialized'
- test_admin_unchanged_after_failed_double_init: verifies admin key is not overwritten
- test_registry_initialized_event_emitted: verifies post-init state is correct
- Add extern crate std to tests module for catch_unwind support
Closes ceejaylaboratory#992
|
@giftben1763-ui 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.
Summary
Fixes
contracts/registry/src/lib.rsto guard against re-initialization, which would allow an attacker to overwrite the admin address after the contract is deployed.Changes
contracts/registry/src/lib.rsinitialize(): Guards against double-init by checkingenv.storage().instance().has(&DataKey::Admin)and panicking with"already initialized"if the admin key already existsRegistryInitialized(admin)event on successful initialization usingenv.events().publish()test_double_initialization_fails— verifies a secondinitialize()call panics with"already initialized"test_admin_unchanged_after_failed_double_init— verifies the original admin is preserved after a failed re-init attempttest_registry_initialized_event_emitted— verifies the registry version is set to 1 and admin is correct after initializationSecurity Impact
Without this fix, any caller could call
initialize()a second time and replace the admin, gaining full control over the registry.Closes #992