Skip to content

A simplified implementation of a smart contract proxy pattern in Solidity, based on EIP-1967. This project explores the concept of upgradable smart contracts using proxies, and includes a clear explanation, example code, and key considerations for implementing upgradeable logic safely.

License

Notifications You must be signed in to change notification settings

xElKaNoNx/ProxyContractImplementation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Proxy Contract Implementation 🚀

License Solidity EIP-1967

Welcome to the Proxy Contract Implementation repository! This project offers a simplified implementation of a smart contract proxy pattern in Solidity, following EIP-1967 standards.

Table of Contents

Introduction

In the world of blockchain, upgradable smart contracts are crucial for maintaining and enhancing decentralized applications. The proxy pattern allows developers to upgrade smart contracts without losing state or requiring users to interact with a new contract address. This repository explores the proxy pattern in detail, providing a clear explanation and practical examples.

Features

  • Simplified implementation of the proxy pattern.
  • Adheres to EIP-1967 standards.
  • Comprehensive examples to guide implementation.
  • Clear explanations of key concepts and considerations.
  • Testing framework included for verification.

Getting Started

To get started with this project, clone the repository to your local machine:

git clone https://github.com/xElKaNoNx/ProxyContractImplementation.git
cd ProxyContractImplementation

Prerequisites

Ensure you have the following installed:

  • Node.js
  • npm
  • Truffle or Hardhat
  • Ganache (for local testing)

Installation

Install the required dependencies:

npm install

Example Code

This section provides an overview of the main components of the proxy implementation. Below is a basic example of how to set up a proxy contract.

Proxy Contract

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Proxy {
    address public implementation;

    constructor(address _implementation) {
        implementation = _implementation;
    }

    fallback() external payable {
        address _impl = implementation;
        require(_impl != address(0), "Implementation not set");
        
        assembly {
            calldatacopy(0, 0, calldatasize())
            let result := delegatecall(gas(), _impl, 0, calldatasize(), 0, 0)
            returndatacopy(0, 0, returndatasize())
            switch result
            case 0 { revert(0, returndatasize()) }
            default { return(0, returndatasize()) }
        }
    }
}

Implementation Contract

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Implementation {
    uint public value;

    function setValue(uint _value) public {
        value = _value;
    }
}

Key Considerations

When implementing upgradeable contracts using the proxy pattern, keep the following in mind:

  1. Storage Layout: Ensure that the storage layout remains consistent across upgrades. Changing variable types or order can lead to data corruption.

  2. Access Control: Implement proper access control mechanisms to prevent unauthorized upgrades.

  3. Testing: Thoroughly test the proxy and implementation contracts. Use automated tests to verify functionality and edge cases.

  4. Gas Costs: Be aware of gas costs associated with delegate calls. Optimize code to minimize expenses.

  5. Security Audits: Conduct security audits before deploying to production. Engage third-party auditors if possible.

Testing

To run the tests, ensure that Ganache is running and execute the following command:

npm test

This will run all the tests defined in the test directory. Make sure to check the output for any errors or failures.

Contributing

We welcome contributions! If you would like to contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and commit them.
  4. Push your branch to your forked repository.
  5. Create a pull request with a clear description of your changes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Releases

For the latest releases, visit our Releases page. Download the necessary files and execute them as needed.


Thank you for checking out the Proxy Contract Implementation repository! We hope this project helps you understand and implement the proxy pattern in your own smart contracts. If you have any questions or feedback, feel free to reach out.

For more details on releases, visit Releases.

About

A simplified implementation of a smart contract proxy pattern in Solidity, based on EIP-1967. This project explores the concept of upgradable smart contracts using proxies, and includes a clear explanation, example code, and key considerations for implementing upgradeable logic safely.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •