0Pricing
Blockchain Smart Contracts with Solidity · 강의

다이아몬드 표준(다중 패싯 프록시)

여러 패싯을 갖춘 고도로 모듈화되고 확장 가능한 업그레이드 가능 계약을 구축하기 위한 다이아몬드 표준(EIP-2535)을 살펴봅니다.

다이아몬드 표준(다중 패싯 프록시)은(는) CoddyKit의 무료 Blockchain Smart Contracts with Solidity 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Blockchain Smart Contracts with Solidity 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Blockchain Smart Contracts with Solidity 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Intro to Diamond Standard

Welcome to the final lesson on upgradeable contracts! We've explored UUPS, but what if your contract grows too big or needs extreme modularity?

The Diamond Standard (EIP-2535) is a powerful pattern that allows a single proxy contract to delegate calls to multiple implementation contracts, called facets.

Single Proxy Limitations

Traditional proxy patterns, like UUPS or Transparent proxies, typically delegate all calls to a single implementation contract.

While effective, this can lead to:

  • Contract Size Limit: Ethereum contracts have a 24KB limit. A single, monolithic implementation can hit this quickly.
  • Complexity: A single contract managing many features becomes hard to maintain and audit.
  • Upgrade Costs: Upgrading means redeploying the entire large implementation contract, even if only a small part changed.

Facets: Modular Contracts

The Diamond Standard solves this by breaking down your contract's logic into smaller, independent pieces called facets.

Think of facets as:

  • Individual smart contracts, each handling specific functionalities.
  • Like 'plugins' or 'modules' for your main proxy.
  • Each facet has its own set of functions.

The Diamond proxy then decides which facet to forward a call to.

How Diamond Proxies Work

At its core, a Diamond proxy works similarly to other proxies:

  1. A user calls a function on the Diamond proxy.
  2. The proxy looks at the function selector (the first 4 bytes of the call data).
  3. It then determines which facet contains that function.
  4. Finally, it delegates the call (using delegatecall) to the correct facet.

The magic is that the proxy maintains a mapping of function selectors to facet addresses.

Diamond Storage: Shared State

A crucial aspect of the Diamond Standard is how state is managed. Even though logic is split across facets, they all operate on the same storage within the Diamond proxy contract.

This is achieved by:

  • Defining a shared storage struct (e.g., AppStorage).
  • Each facet accesses this shared storage using a specific Solidity pattern (often via a library).
  • This ensures consistency and allows facets to interact with the same data.

Managing Facets with `diamondCut`

The central function for managing your Diamond is diamondCut. This function allows you to:

  • Add new facets (new functionality).
  • Replace existing facets (upgrade or fix bugs).
  • Remove facets (deprecate functionality).

diamondCut is typically only callable by the contract's owner, making it the secure upgrade mechanism for your multi-faceted contract.

A Simple Facet Example

Here's what a very basic Solidity facet might look like. Remember, facets are just regular contracts that implement specific logic.

Try compiling this simple example:

pragma solidity ^0.8.0;

contract MySimpleFacet {
    // Facets interact with shared storage
    // located in the Diamond proxy contract.
    // They don't declare state variables directly
    // in the way a standalone contract would.

    function getFacetVersion() external pure returns (string memory) {
        return "MySimpleFacet v1.0";
    }

    function greetUser(string memory _name) external pure returns (string memory) {
        return string(abi.encodePacked("Hello, ", _name, " from MySimpleFacet!"));
    }
}

The Diamond Proxy Itself

The Diamond proxy contract itself is remarkably lean. Its primary responsibilities are:

  • Storing the mapping of function selectors to facet addresses.
  • Implementing the diamondCut function for upgrades.
  • The fallback function, which handles delegating calls to the correct facet.

It acts as the central router for all incoming calls, directing them to the appropriate piece of logic.

Why Choose Diamond Standard?

The Diamond Standard offers significant advantages for complex DApps:

  • Unlimited Contract Size: Easily bypass the 24KB limit by splitting logic into many small facets.
  • Extreme Modularity: Develop and deploy features independently.
  • Gas Efficiency: Only upgrade (deploy) the specific facets that change, not the entire contract.
  • Clear Separation of Concerns: Improves code readability, testing, and security auditing.
  • Incremental Development: Add new features over time without affecting existing ones.

Diamond Standard Check

The Diamond Standard (EIP-2535) provides a robust framework for building highly modular and upgradeable smart contracts. Which of the following statements accurately describe its key benefits or characteristics?

Recap: Multi-facet Proxies

In this lesson, we explored the Diamond Standard (EIP-2535), a powerful pattern for building highly modular and upgradeable smart contracts.

  • We learned about facets, which are individual contracts containing specific logic.
  • The Diamond proxy delegates calls to these multiple facets based on function selectors.
  • All facets share the Diamond proxy's storage.
  • The diamondCut function is used to add, replace, or remove facets.
  • Key benefits include overcoming the 24KB contract size limit, extreme modularity, and efficient upgrades.

You're now equipped with knowledge of advanced upgradeability patterns!

자주 묻는 질문

“다이아몬드 표준(다중 패싯 프록시)” 강의는 무료인가요?

네 — “다이아몬드 표준(다중 패싯 프록시)” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Blockchain Smart Contracts with Solidity 강의 전체를 잠금 해제할 수 있습니다. Blockchain Smart Contracts with Solidity 강의에는 총 4개의 강의가 포함되어 있습니다.

“다이아몬드 표준(다중 패싯 프록시)”에서 뭘 배우나요?

여러 패싯을 갖춘 고도로 모듈화되고 확장 가능한 업그레이드 가능 계약을 구축하기 위한 다이아몬드 표준(EIP-2535)을 살펴봅니다. 브라우저에서 직접 실행하는 실습 코드로 Blockchain Smart Contracts with Solidity을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Blockchain Smart Contracts with Solidity을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Blockchain Smart Contracts with Solidity은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.

“다이아몬드 표준(다중 패싯 프록시)” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Blockchain Smart Contracts with Solidity 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Blockchain Smart Contracts with Solidity 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 업그레이드 가능한 계약이 필요한 이유
  2. UUPS 프록시 패턴 구현
  3. 다이아몬드 표준(다중 패싯 프록시)
  4. 투명 프록시 패턴과 스토리지 레이아웃
← Blockchain Smart Contracts with Solidity(으)로 돌아가기