diff --git a/library-solidity/config/ZamaConfig.sol b/library-solidity/config/ZamaConfig.sol index 96052c050..9aa483d52 100644 --- a/library-solidity/config/ZamaConfig.sol +++ b/library-solidity/config/ZamaConfig.sol @@ -98,3 +98,66 @@ abstract contract ZamaEthereumConfig { return ZamaConfig.getConfidentialProtocolId(); } } + +/** + * @title ZamaEthereumConfigInitializable + * @dev A clone-compatible version of ZamaEthereumConfig. + * Includes a custom initializer modifier to avoid OpenZeppelin dependencies. + */ +abstract contract ZamaEthereumConfigInitializable { + /** + * @dev Indicates that the contract has been initialized. + */ + bool private _initialized; + + /** + * @dev Indicates that the contract is in the process of being initialized. + */ + bool private _initializing; + + /** + * @dev Modifier to protect an initializer function from being invoked twice. + */ + modifier initializer() { + // If the contract is already initialized, we revert. + // We allow re-entrancy into the modifier if we are currently initializing + // (useful for inheritance chains), but simplest case is just check _initialized. + require(!_initialized && !_initializing, "ZamaConfig: already initialized"); + + _initializing = true; + _initialized = true; + _; + _initializing = false; + } + + /** + * @dev ToDo: Constructor to prevent initialization of implementation contracts. + * This is a security best practice for proxies. + */ + constructor() { + FHE.setCoprocessor(ZamaConfig.getEthereumCoprocessorConfig()); + } + + /** + * @dev Should be called inside your proxy's initialize function. + * This sets up the FHE coprocessor configuration for the specific network. + */ + function __ZamaEthereumConfig_init() internal onlyInitializing { + FHE.setCoprocessor(ZamaConfig.getEthereumCoprocessorConfig()); + } + + /** + * @dev Helper to ensure internal init is only called from within an initializer. + */ + modifier onlyInitializing() { + require(_initializing, "ZamaConfig: function can only be called during initialization"); + _; + } + + /** + * @dev Exposes the protocol ID, matching the original ZamaEthereumConfig interface. + */ + function confidentialProtocolId() public view virtual returns (uint256) { + return ZamaConfig.getConfidentialProtocolId(); + } +}