Add Ownable2Step base for safe two-step ownership transfer#1770
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master-n3 #1770 +/- ##
=============================================
+ Coverage 82.95% 82.96% +0.01%
=============================================
Files 306 307 +1
Lines 27372 27434 +62
Branches 3826 3848 +22
=============================================
+ Hits 22706 22761 +55
- Misses 3497 3501 +4
- Partials 1169 1172 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
shargon
reviewed
Jun 24, 2026
ajara87
previously approved these changes
Jun 24, 2026
shargon
reviewed
Jun 24, 2026
shargon
previously approved these changes
Jun 25, 2026
Wi1l-B0t
previously approved these changes
Jun 26, 2026
ajara87
previously approved these changes
Jun 26, 2026
892243a
shargon
reviewed
Jun 26, 2026
892243a to
cdd7270
Compare
ajara87
previously approved these changes
Jun 28, 2026
Contributor
Author
|
Updated with latest master. Could you please take another look? |
Wi1l-B0t
previously approved these changes
Jun 29, 2026
shargon
reviewed
Jun 30, 2026
shargon
reviewed
Jul 1, 2026
The framework only shipped single-step Ownable: SetOwner assigns the new owner immediately, with no witness check on the incoming account. Passing a mistyped or otherwise unusable address loses contract control irrecoverably — the classic single-step ownership-transfer footgun. Add a standalone Ownable2Step base (the OpenZeppelin Ownable2Step analog, adapted to Neo's static-method model). Ownership changes hands only in two steps: the owner proposes a pending owner via TransferOwnership, and the transfer completes only when that account itself calls AcceptOwnership and proves control with Runtime.CheckWitness. A mistyped address can never take ownership because it can never sign the acceptance. The class is standalone rather than extending Ownable so it does not re-expose the unsafe single-step SetOwner (Neo has no static-method override). It adds: - TransferOwnership / AcceptOwnership: the two-step flow; re-proposing supersedes any in-flight pending and emits a cancellation event for it. - CancelOwnershipTransfer: owner clears an in-flight pending. - RenounceOwnership: the one deliberate irreversible action; removes the owner and clears any pending so a previously-proposed account cannot seize an abandoned contract. - GetOwner / GetPendingOwner: [Safe] read-only accessors. Storage uses reserved prefixes 0xFD (owner) and 0xFC (pending), distinct from Ownable (0xFF) and Pausable (0xFE). Pending is the single source of truth for an in-flight transfer (absent = none), which collapses double-accept, accept-with-no-pending, and stale-accept-after-renounce to one null check. Storage is written before events on every transition. Adds Ownable2StepTest covering the happy path plus every adversarial edge: transfer to self/zero/by non-owner, accept with no pending / by the wrong account / twice, renounce-then-stale-accept, cancel with nothing pending / by non-owner, post-renounce lockout, re-propose supersession, event emission, and the manifest safe-flag attribution.
1bf6c2f to
d38e873
Compare
shargon
approved these changes
Jul 3, 2026
ajara87
approved these changes
Jul 4, 2026
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
The framework only shipped single-step
Ownable:SetOwnerassigns the new owner immediately, with no witness check on the incoming account. Passing a mistyped or otherwise unusable address loses contract control irrecoverably — the classic single-step ownership-transfer footgun that OpenZeppelin introducedOwnable2Stepto fix.This adds a standalone
Ownable2Stepbase (the OpenZeppelinOwnable2Stepanalog, adapted to Neo's static-method model). Ownership changes hands only in two steps:TransferOwnership, andAcceptOwnershipand proves control withRuntime.CheckWitness.A mistyped address can never take ownership because it can never sign the acceptance.
API
TransferOwnership(newOwner)/AcceptOwnership()— the two-step flow. Re-proposing supersedes any in-flight pending and emits a cancellation event for the dropped candidate.CancelOwnershipTransfer()— owner clears an in-flight pending.RenounceOwnership()— the one deliberate, irreversible action; removes the owner and clears any pending so a previously-proposed account cannot seize an abandoned contract.GetOwner()/GetPendingOwner()—[Safe]read-only accessors.InitializeOwner(data, update)— call from_deploy; defaults to the tx sender, no-op on update.Design notes
Ownable— so it does not re-expose the unsafe single-stepSetOwner(Neo has no static-method override to hide it).0xFD(owner) /0xFC(pending), distinct fromOwnable(0xFF) andPausable(0xFE).[Safe]is only on the two pure-read accessors; every state-mutating method is non-[Safe]and reachesCheckWitness.Testing
Ownable2StepTest(17 cases) covers the happy path plus every adversarial edge: transfer to self / to zero / by non-owner; accept with no pending / by the wrong account (incl. the current owner) / twice; renounce-then-stale-accept; cancel with nothing pending / by non-owner; post-renounce lockout; re-propose supersession; full event emission; and the manifest safe-flag attribution. Full framework suite green (270).The design and this implementation were each put through an independent adversarial security review (ownership-theft, bricking, witness-bypass, storage/event ordering, stale-pending seizure) before submission.