Primrose Docs
  • Home
    • ⛓️Blockchain
      • Avalanche
        • What is AVAX?
      • Ethereum
        • Ethereum Cancun Upgrade Explained(draft)
        • go-ethereum: gas estimate
        • Blockchain Transaction Lifecycle
        • Mempool
        • Gas optimization in Solidity, Ethereum
      • Solidity DeepDive
        • Meta transaction
        • solidity: patterns
        • UUPS vs Transparent
        • Solidity Interface
        • Smart contract storage
        • ERC-2981 Contract
        • Solidity modifier
        • Solidity delete keyword
        • How To Make NFTs with On-Chain Metadata - Hardhat and JavaScript
        • How to Build "Buy Me a Coffee" DeFi dapp
        • How to Develop an NFT Smart Contract (ERC 721) with Alchemy
        • Upgradeable Contract
        • Smart Contract Verification
      • Common
        • Eigenlayer
        • MultiSig(draft)
        • Chain-Based Proof-of- Stake, BFT-Style Proof-of-Stake
        • Byzantine Fault Tolerance
        • Zero-knowledge
        • Hierarchical Deterministic Wallet
        • Maker DAO
        • Defi
        • Uniswap
        • IBC
        • Cosmos
        • Gossip Protocol
        • Tendermint
        • UTXO vs Account
        • Blockchain Layer
        • Consensus Algorithm
        • How does mining work?
        • Immutable Ledger
        • SHA256 Hash
        • Filecoin
        • IPFS - InterPlanetary File System
        • IPFS와 파일코인
        • Livepeer
        • Layer 0
      • Bitcoin
        • BIP for HD Wallet
        • P2WPKH
        • Segwit vs Native Segwit
    • 📖Languages
      • Javascript/Typescript
        • Hoisting
        • This value in Javascript
        • Execution Context
        • About Javscript
        • tsconfig.json
        • Nest js Provider
        • 'return await promise' vs 'return promise'
      • Python
        • Pythonic
        • Python: Iterable, Iterator
        • Uvicorn & Gunicorn
        • WSGI, ASGI
        • Python docstring
        • Decorator in Python
        • Namespace in Python
        • Python Method
      • Go
        • GORM+MySQL Connection Pool
        • Context in golang
        • How to sign Ethereum EIP-1559 transactions using AWS KMS
        • Mongo DB in golang(draft)
        • Golang HTTP Package
        • Panic
        • Golang new/make
        • golang container package
        • errgroup in golang
        • Generic Programming in Golang
        • Goroutine(draft)
    • 📝Database
      • MongoDB in golang
      • Nested loop join, Hash join
      • DB Query plan
      • Index
      • Optimistic Lock Pessimistic Lock
    • 💻Computer Science
      • N+1 query in go
      • Web server 를 구성할 때 Thread, Process 개수를 어떻게 정할 것인가?
      • CAP
      • Socket programming
      • DNS, IP
      • URL, URI
      • TLS과 SSL
      • Caching(draft)
      • Building Microservices: Micro Service 5 Deploy Principle
      • Red Black Tree
      • AOP
      • Distributed Lock
      • VPC
      • Docker
      • All about Session and JWT
      • Closure
      • Singleton Pattern
      • TCP 3 way handshake & 4 way handshake
      • Race Condition
      • Process Address Space 
      • Call by value, Call by reference, Call by assignment
      • Zookeeper, ETCD
      • URL Shortening
      • Raft consensus
      • Sharding, Partitioning
    • 📒ETC
      • K8S SIGTERM
      • SQS
      • Git Branch Strategy: Ship / Show / Ask
      • Kafka
      • Redis Data Types
      • CI/CD
      • How does Google design APIs?
      • Minishell (42 cursus)
      • Coroutine & Subroutine
      • Redis
Powered by GitBook
On this page
  • Why Upgradeable Contract ?
  • What is Upgradeable Contract ?
  • But How?
  • Sources…
  1. Home
  2. Blockchain
  3. Solidity DeepDive

Upgradeable Contract

PreviousHow to Develop an NFT Smart Contract (ERC 721) with AlchemyNextSmart Contract Verification

Last updated 1 year ago

Why Upgradeable Contract ?

Upgradeable is literally upgradeable.

The smart contract on the blockchain cannot be changed. That is the core and advantage of the contract implemented in code.

However, it is not just good that the code cannot be changed. (especially to developers)

Any program can have a bug. Either it's trivial, or it's fatal.

The point is code is written by a developer. It can eventually cause errors because it is written by a human.

If a bug is found while the service is already being deployed and in progress, it will be very difficult problem.

In particular, in decentralized Web3 Dapp, it is the same level as forced termination of the servi

To solve these problems, an Upgradeable Contract appears.

What is Upgradeable Contract ?

To upgrade an unchangeable smart contract, use the Proxy pattern.

A schematic diagram of the Proxy pattern is as follows.

  1. The user (client) sends a request to the Proxy contract.

  2. Proxy Contract delivers the request to a contract containing the actual implementation and logic.

The important concept is, after all, the two sentences right above.

If a function needs to be added to the contract, or if issues and bugs are found in the function, we don't have to fix the Proxy contract.

In other words, the client only needs to call as usual, and only changes the implementation contract address and sets it to the Proxy contract.

It's like using an interface, the calling partial code doesn't change, but only the internal implementation.

But How?

We know the concept, but what is the implementation? First of all, there's a proposition here.

Even if a function of another contract is called, it affects the storage of the contract which is called, but does not affect the storage of the contract which called another.

In other words, even if you call a contract containing logic through Proxy contract, only the data of the contract containing logic changes

The data in the Proxy contract does not change.

For this magic, Solidity uses a friend named delegatecall and call.

Call and degatecall correspond to opcode (machine language), not functions.

Internally, Solidity uses call and degatecall when calling other contracts.

Call is the opcode we usually use to call a contract.

Delegatecall uses code from other contracts, but the execution environment allows it to be performed on existing contracts.

When Contract A calls Contract B, when using Contract B, if it uses Contract B's code, it changes Contract A's Storage.

Sources…

⛓️
Proxy pattern