feat(token): implement two-step ownership transfer pattern#38
Merged
p3ris0n merged 3 commits intoMay 8, 2026
Merged
Conversation
- Add DataKey::PendingAdmin for storing pending admin address - Add propose_owner() for admin to propose new admin - Add accept_ownership() for pending admin to accept transfer - Add cancel_transfer() for admin to cancel pending transfer - Add pending_owner() read-only function to check pending transfers - Mark old transfer_ownership() as deprecated in docs - Add events: emit_ownership_proposed, emit_ownership_accepted, emit_ownership_cancelled - Add 5 comprehensive tests: * Happy path: propose -> accept -> new admin can mint * Accept without proposal fails * Cancel transfer clears pending admin * Cancel without proposal fails * Double propose updates pending admin - Improves security: prevents permanent loss of admin access due to typos Closes BCPathway#14
|
@ACodehunter 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! 🚀 |
Contributor
|
@ACodehunter please fix issues |
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
Implements a secure two-step ownership transfer pattern for the token contract as specified in Issue #14. This prevents permanent loss of admin access due to typos or incorrect addresses.
Problem
The current
transfer_ownership()function immediately transfers admin rights in a single step. If the new address is incorrect (typo, wrong key), the admin role is irrecoverably lost.Solution
Implemented a two-step ownership transfer pattern:
propose_owner(new_admin)- Current admin proposes a new adminaccept_ownership()- Pending admin accepts the transfercancel_transfer()- Current admin can cancel a pending transferpending_owner()- Read-only function to check pending transfersChanges
Contract Updates (lib.rs)
DataKey::PendingAdminpropose_owner(): Propose new admin (admin-only)accept_ownership(): Accept pending transfer (pending admin only)cancel_transfer(): Cancel pending transfer (admin-only)pending_owner(): Query pending admin addresstransfer_ownership()marked with deprecation notice in docsEvents (events.rs)
emit_ownership_proposed(): Emitted when admin is proposedemit_ownership_accepted(): Emitted when transfer is acceptedemit_ownership_cancelled(): Emitted when transfer is cancelledTests (test.rs)
Added 5 comprehensive tests:
Acceptance Criteria
DataKey::PendingAdminstorage keypropose_owner,accept_ownership,cancel_transfer,pending_ownerfunctionstransfer_ownership()still works (deprecated)Security Benefits
Migration Path
Existing code using
transfer_ownership()will continue to work. New code should use:Closes #14