Skip to content

fix(#992): prevent double initialization and emit RegistryInitialized event in registry - #1075

Open
giftben1763-ui wants to merge 1 commit into
ceejaylaboratory:mainfrom
giftben1763-ui:fix/992-registry-double-init
Open

fix(#992): prevent double initialization and emit RegistryInitialized event in registry#1075
giftben1763-ui wants to merge 1 commit into
ceejaylaboratory:mainfrom
giftben1763-ui:fix/992-registry-double-init

Conversation

@giftben1763-ui

Copy link
Copy Markdown

Summary

Fixes contracts/registry/src/lib.rs to guard against re-initialization, which would allow an attacker to overwrite the admin address after the contract is deployed.

Changes

contracts/registry/src/lib.rs

  • initialize(): Guards against double-init by checking env.storage().instance().has(&DataKey::Admin) and panicking with "already initialized" if the admin key already exists
  • Event: Emits a RegistryInitialized(admin) event on successful initialization using env.events().publish()
  • Added unit tests:
    • test_double_initialization_fails — verifies a second initialize() call panics with "already initialized"
    • test_admin_unchanged_after_failed_double_init — verifies the original admin is preserved after a failed re-init attempt
    • test_registry_initialized_event_emitted — verifies the registry version is set to 1 and admin is correct after initialization

Security Impact

Without this fix, any caller could call initialize() a second time and replace the admin, gaining full control over the registry.

Closes #992

…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
@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

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.

[Soroban] Implement contract instance metadata initialization check in Registry contract

1 participant