---
eip: 7546
label: ERC-7546
title: Upgradeable Clone for Scalable Contracts
status: Draft
type: Standards Track
category: ERC
created: 2023-10-25
requires: 165, 1967, 7201
official: https://eips.ethereum.org/EIPS/eip-7546
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7546.md
canonical: https://eips.huatuo.xyz/ko/eip-7546/
lang: ko
tldr: 함수 단위 업그레이드(Diamond 방식)와 비콘식 공유 업그레이드를 결합한 초안 프록시 패턴. 복제된 많은 프록시를 한 번의 트랜잭션으로 함수별로 업그레이드할 수 있다.
tags: [proxy, upgradeability, clone, factory, solidity]
---

# ERC-7546: Upgradeable Clone for Scalable Contracts

> An upgradeable, cloneable, horizontally extensible proxy pattern.

**TL;DR:** 함수 단위 업그레이드(Diamond 방식)와 비콘식 공유 업그레이드를 결합한 초안 프록시 패턴. 복제된 많은 프록시를 한 번의 트랜잭션으로 함수별로 업그레이드할 수 있다.

## 어떤 문제를 해결하나요?

기존 프록시 표준은 각각 영역의 일부만 다룹니다.

| 필요 | 기존 해법 |
| --- | --- |
| 저렴한 클론, 업그레이드 없음 | [ERC-1167](/eip-1167/) 미니멀 프록시 |
| 컨트랙트 전체 업그레이드 | UUPS / 투명 프록시 |
| 많은 클론을 한꺼번에 업그레이드 | [ERC-1967](/eip-1967/)의 비콘 프록시 |
| 개별 함수 업그레이드 | [ERC-2535](/eip-2535/) Diamond |

빠져 있는 것은 **클론 팩토리를 위한 함수 단위 업그레이드**입니다. Diamond는 셀렉터와 facet의 매핑 표를 각 프록시 안에 저장하므로, 복제된 Diamond 1,000개를 업그레이드하려면 1,000번의 업데이트가 필요합니다. ERC-7546, *Upgradeable Clone Standard*(UCS)가 이 틈을 메웁니다. 로직을 함수별로 나누면 24,576바이트 컨트랙트 크기 제한에도 도움이 됩니다.

## 어떻게 동작하나요?

하나의 논리적 컨트랙트를 세 부분으로 나눕니다.

1. **Proxy**: 상태(잔액, 스토리지)를 보관합니다. ERC-1967 방식의 슬롯 `bytes32(uint256(keccak256('erc7546.proxy.dictionary')) - 1)`에 Dictionary의 주소를 저장합니다. 호출할 때마다 Dictionary에 `getImplementation(msg.sig)`를 물어보고 그 결과로 delegatecall합니다. 셀렉터 충돌을 피하려면 자체 external 함수를 정의하지 않아야 하며, Dictionary가 바뀌면 `DictionaryUpgraded`를 emit합니다.
2. **Dictionary**: 함수 셀렉터를 구현 주소에 매핑하는 공유 레지스트리입니다. `getImplementation`과 보통 `setImplementation`을 제공하고 `ImplementationUpgraded`를 emit합니다. 집합 전체에 대해 ERC-165 `supportsInterface`에 응답할 수도 있습니다.
3. **Function contracts**: 로직 본체이며 각각 하나 이상의 함수를 가집니다. delegatecall을 통해 프록시의 스토리지에서 실행됩니다.

많은 프록시가 같은 Dictionary를 가리킬 수 있으므로, `setImplementation`을 한 번 호출하면 **모든** 프록시의 함수가 한꺼번에 업그레이드됩니다. 비콘과 비슷하지만 함수 단위입니다.

## 샘플 코드

최소한의 UCS 프록시(명세의 설계를 단순화한 것):

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

interface IDictionary {
    function getImplementation(bytes4 selector) external view returns (address);
}

contract UCSProxy {
    // bytes32(uint256(keccak256("erc7546.proxy.dictionary")) - 1)
    bytes32 internal constant DICTIONARY_SLOT =
        0x267691be3525af8a813d30db0c9e2bad08f63baecf6dceb85e2cf3676cff56f4;

    event DictionaryUpgraded(address dictionary);

    constructor(address dictionary, bytes memory initData) {
        assembly { sstore(DICTIONARY_SLOT, dictionary) }
        emit DictionaryUpgraded(dictionary);
        if (initData.length > 0) {
            (bool ok, ) = address(this).call(initData);
            require(ok, "init failed");
        }
    }

    fallback() external payable {
        address dict;
        assembly { dict := sload(DICTIONARY_SLOT) }
        address impl = IDictionary(dict).getImplementation(msg.sig);
        require(impl != address(0), "no impl");
        assembly {
            calldatacopy(0, 0, calldatasize())
            let ok := delegatecall(gas(), impl, 0, calldatasize(), 0, 0)
            returndatacopy(0, 0, returndatasize())
            switch ok case 0 { revert(0, returndatasize()) } default { return(0, returndatasize()) }
        }
    }
}
```

## 알아둘 점

- 상태는 **Draft**입니다.
- 모든 function contract가 프록시의 스토리지를 공유하므로 레이아웃 충돌은 현실적인 위험입니다. 명세는 방법을 정하지 않지만 [ERC-7201](/eip-7201/) 같은 네임스페이스 스토리지를 제안합니다.
- Dictionary를 통제하는 사람이 연결된 모든 프록시의 코드를 통제합니다. 신뢰할 수 없는 관리자가 운영하는 Dictionary에 프록시를 연결하지 말고, 다른 Dictionary로 전환할 수 있게 하는 것도 고려하세요.
- Dictionary 주소를 하드코딩(immutable)하면 Dictionary 관리자가 내가 아닐 경우 변경이 영구히 막힐 수 있습니다.
- 셀렉터는 실제로 그것을 구현한 function contract에만 등록하세요. 불일치하면 호출이 실패합니다. 프록시는 `DELEGATECALL`로 호출되도록 설계되지 않았습니다.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-7546
