Proxy
The Proxy Contract is a fundamental component of the UCS (ERC-7546) architecture. It serves as the stable, unchanging address that users and other contracts interact with, while delegating calls to the appropriate Function Contracts.
Overview
The Proxy Contract in UCS maintains the state of the contract account (nonce, balance, and storage) and delegates all calls to the appropriate Function Contracts as registered in the Dictionary Contract.
Key Features
- State Management: Maintains the contract's state.
- Delegation: Delegates all calls to the appropriate Function Contracts.
- Upgradability: Allows for upgrading the contract's functionality without changing its address.
Storage
The Proxy Contract stores the Dictionary Contract address in a specific storage slot:
bytes32 constant DICTIONARY_SLOT = 0x267691be3525af8a813d30db0c9e2bad08f63baecf6dceb85e2cf3676cff56f4;
This slot is calculated as bytes32(uint256(keccak256('erc7546.proxy.dictionary')) - 1), following the method defined in ERC-1967.
Events
The Proxy Contract emits an event when the Dictionary address is changed:
event DictionaryUpgraded(address dictionary);
Usage
To interact with a UCS contract, always use the Proxy Contract's address. The Proxy will handle delegating the call to the appropriate Function Contract.
// Example usage
FunctionA(proxyAddress).functionA(arg1);
FunctionB(proxyAddress).functionB(arg1, arg2);
Security Considerations
- The Proxy Contract should not define any external functions to avoid potential collisions with function selectors registered in the Dictionary Contract.
- Care should be taken when updating the Dictionary address, as it could potentially give control of the contract to an untrusted party.
- The Proxy Contract is not designed to handle
DELEGATECALLs and may behave unexpectedly if called this way.
For more detailed information on security considerations, please refer to the Security Considerations document.