Overview
The CTF Exchange implements a dual-role access control system with Admin and Operator roles. This separation of concerns ensures that critical configuration changes require admin privileges while routine operations can be delegated to operators.Role System
The exchange uses a mapping-based role system defined inAuth.sol:8-83:
Roles are stored as
uint256 values where 1 indicates the role is active and 0 indicates it’s inactive.Admin Role
Admins have full control over the protocol and can:- Pause and unpause trading
- Add and remove other admins and operators
- Configure proxy and safe factories
- Register new tokens for trading
- Renounce their own admin role
Operator Role
Operators can:- Execute trades via
fillOrder(),fillOrders(), andmatchOrders() - Renounce their own operator role
Admin Functions
Pausability Controls
Admins can halt and resume trading in emergency situations.pauseTrading
CTFExchange.sol:45
Description: Pauses all trading on the exchange. When paused, all trading functions will revert with a Paused() error.
Effects:
- Sets
pausedstate totrue - Emits
TradingPaused(msg.sender)event - All functions with
notPausedmodifier will revert
unpauseTrading
CTFExchange.sol:50
Description: Resumes trading on the exchange after it has been paused.
Effects:
- Sets
pausedstate tofalse - Emits
TradingUnpaused(msg.sender)event - Trading functions become callable again
Factory Configuration
Admins can update the factory contracts used for signature verification.setProxyFactory
CTFExchange.sol:97
Description: Updates the Polymarket Proxy Wallet factory address used for verifying proxy wallet signatures.
Parameters:
_newProxyFactory: Address of the new proxy factory contract
- Updates
proxyFactorystate variable - Emits
ProxyFactoryUpdated(oldProxyFactory, newProxyFactory)event
Changing the proxy factory affects how proxy wallet signatures are verified. Ensure the new factory is compatible before making this change.
setSafeFactory
CTFExchange.sol:103
Description: Updates the Gnosis Safe factory address used for verifying Safe wallet signatures.
Parameters:
_newSafeFactory: Address of the new Safe factory contract
- Updates
safeFactorystate variable - Emits
SafeFactoryUpdated(oldSafeFactory, newSafeFactory)event
Token Registration
registerToken
CTFExchange.sol:111
Description: Registers a token pair (outcome tokens) and their associated condition ID for trading on the exchange.
Parameters:
token: The token ID to registercomplement: The complement token ID (the opposite outcome)conditionId: The CTF condition ID from the Conditional Tokens Framework
Registry.sol:41-43):
tokenandcomplementmust be different- Neither
tokennorcomplementcan be zero - Neither token can already be registered
- Registers both tokens in the registry mapping
- Associates both tokens with the condition ID
- Emits
TokenRegistered(token, complement, conditionId)event for both tokens
Role Management Functions
Adding Roles
addAdmin
Auth.sol:41
Description: Grants admin privileges to a new address.
Effects:
- Sets
admins[admin_] = 1 - Emits
NewAdmin(admin_, msg.sender)event
addOperator
Auth.sol:49
Description: Grants operator privileges to a new address.
Effects:
- Sets
operators[operator_] = 1 - Emits
NewOperator(operator_, msg.sender)event
Removing Roles
removeAdmin
Auth.sol:57
Description: Revokes admin privileges from an address.
Effects:
- Sets
admins[admin] = 0 - Emits
RemovedAdmin(admin, msg.sender)event
removeOperator
Auth.sol:65
Description: Revokes operator privileges from an address.
Effects:
- Sets
operators[operator] = 0 - Emits
RemovedOperator(operator, msg.sender)event
Renouncing Roles
renounceAdminRole
Auth.sol:72
Description: Allows an admin to voluntarily give up their admin privileges.
Effects:
- Sets
admins[msg.sender] = 0 - Emits
RemovedAdmin(msg.sender, msg.sender)event
renounceOperatorRole
Auth.sol:79
Description: Allows an operator to voluntarily give up their operator privileges.
Effects:
- Sets
operators[msg.sender] = 0 - Emits
RemovedOperator(msg.sender, msg.sender)event
View Functions
Role Checking
Auth.sol:30-36
Description: Check if an address has admin or operator privileges.
Example:
Factory Information
PolyFactoryHelper.sol:31-48
Description: Retrieve the current factory addresses and their implementations.
Pause State
Pausable.sol:7
Description: Returns true if trading is currently paused, false otherwise.
Events
Access Control Events
Pausability Events
Configuration Events
Errors
Security Considerations
Admin Key Management
Admin Key Management
Admin keys have powerful privileges. Follow these best practices:
- Use hardware wallets or multi-signature wallets for admin accounts
- Maintain multiple admin addresses for redundancy
- Regularly rotate admin keys
- Monitor admin transactions on-chain
Operator Security
Operator Security
Operators can execute trades but cannot modify protocol state:
- Operators should use secure key management
- Monitor operator activity for unauthorized trades
- Implement rate limiting at the application layer
- Remove compromised operators immediately
Emergency Procedures
Emergency Procedures
In case of a security incident:
- Call
pauseTrading()immediately - Investigate the issue
- Remove compromised operators/admins if necessary
- Deploy fixes or mitigation measures
- Call
unpauseTrading()once resolved
Factory Updates
Factory Updates
When updating factories:
- Verify the new factory contract thoroughly
- Test signature verification with the new factory
- Coordinate with users who may be affected
- Monitor for any signature verification failures
Related Documentation
Security Audit
View the ChainSecurity audit report
Best Practices
Security guidelines for integrators