Ownable and Ownable2Step contracts provide ownership and access control mechanisms for CCTP contracts. Ownable2Step extends Ownable with a two-step ownership transfer pattern for additional security.
Contracts:
src/roles/Ownable.solsrc/roles/Ownable2Step.sol
Ownable
Base contract providing single-owner access control mechanism.State Variables
_owner
Functions
owner
transferOwnership
Ownable contract, this is a single-step process.
Parameters:
newOwner: Address of the new owner
- Caller must be the current owner
- New owner must be non-zero address
OwnershipTransferred(address indexed previousOwner, address indexed newOwner)
Source: Ownable.sol:80
Internal Functions
_checkOwner
_transferOwnership
newOwner: Address of the new owner
OwnershipTransferred(address indexed previousOwner, address indexed newOwner)
Source: Ownable.sol:92
Modifiers
onlyOwner
Events
OwnershipTransferred
previousOwner: Address of the previous ownernewOwner: Address of the new owner
Ownable2Step
ExtendsOwnable with a two-step ownership transfer pattern for enhanced security.
Key Concepts
Two-Step Transfer Pattern:- Current owner calls
transferOwnership()to propose a new owner - New owner must call
acceptOwnership()to complete the transfer
State Variables
_pendingOwner
Functions
pendingOwner
transferOwnership
Ownable function.
Parameters:
newOwner: Address of the proposed new owner
- Caller must be the current owner
- Sets
_pendingOwnertonewOwner - Does NOT immediately transfer ownership
OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner)
Source: Ownable2Step.sol:55
acceptOwnership
- Caller must be the pending owner
- Transfers ownership to the caller
- Clears the pending owner
OwnershipTransferred(address indexed previousOwner, address indexed newOwner)
Source: Ownable2Step.sol:77
Internal Functions
_transferOwnership
newOwner: Address of the new owner
Events
OwnershipTransferStarted
previousOwner: Address of the current ownernewOwner: Address of the proposed new owner
Usage Examples
Ownable2Step (Recommended)
Replacing a Pending Transfer
Owner Privileges
In CCTP contracts, the owner role typically has the following privileges:- Update the attester manager (
Attestable) - Update the pauser (
Pausable) - Update the rescuer (
Rescuable) - Update the token controller (
TokenController) - Other administrative functions
Security Considerations
Why Use Ownable2Step?
- Prevents Typos: Cannot accidentally transfer to wrong address
- Verifies Access: Ensures new owner can sign transactions from that address
- Allows Cancellation: Can initiate new transfer to different address before acceptance
- No Renounce: Neither contract includes
renounceOwnership()to prevent accidental loss of control
Best Practices
- Use
Ownable2Stepfor all production contracts (as CCTP does) - Owner should be a multisig or DAO governance contract
- Never transfer ownership to an unverified address
- Ensure the new owner address is controlled and accessible
- Monitor for
OwnershipTransferStartedevents - Complete pending transfers promptly or replace them
Inheritance Hierarchy
Ownable2Step for maximum security.
Origin
Forked from OpenZeppelin Contracts with modifications:- Updated Solidity version from 0.8.0 to 0.7.6
- Removed
renounceOwnership()function for safety - Based on v8 contracts which include internal
_transferOwnershipmethod