This project demonstrates the implementation of an upgradeable smart contract using the EIP-1967 proxy standard. The EIP-1967 standardizes the storage slots for proxy contracts, facilitating seamless upgrades while maintaining consistent storage layouts.
To deepen understanding of smart contract proxy patterns and their significance in enabling contract upgradability. This includes:
- Researching the EIP-1967 proxy standard.
- Documenting findings comprehensively.
- Implementing a simplified version in Solidity.
- Deploying and interacting with the contracts using Hardhat.
EIP-1967 is an Ethereum Improvement Proposal that specifies standard storage slots for proxy contracts. This standardization ensures that the storage layout of proxy contracts does not conflict with that of the implementation contracts, thereby facilitating safe and predictable upgrades.
- Standardized Storage Slots: Defines specific storage slots for critical proxy data, such as the implementation address.
- Upgradeability:: Allows the logic of a contract to be upgraded without altering its address or disrupting its state.
- Compatibility: Enhances compatibility with tools and services that interact with smart contracts by providing predictable storage layouts.
In the EIP-1967 pattern:
-
Proxy Contract: Delegates calls to an implementation contract using delegatecall. It holds the state and the address of the implementation contract.
-
Implementation Contract: Contains the logic to be executed. It does not hold any state.
-
Storage Slot: The implementation address is stored in a specific storage slot defined by EIP-1967 to prevent storage collisions.
Upgradeability Modular and reusable code Compatible with tools like OpenZeppelin
A simple contract that allows setting and retrieving a uint256 value.
A simple proxy contract that holds a delegatecall
Node.js and npm installed. Hardhat installed globally or as a dev dependency.
-
Clone the repository to your local machine:
git clone https://github.com/James-wasonga/UpgradeableSmartContract.git
-
Navigate to the project directory:
cd UpgradeableSmartContract -
Install the necessary dependencies:
npm install
-
Compile contracts:
npx hardhat compile
-
Deploy Contracts:
npx hardhat run scripts/deploy.js
-
Testing:
npx hardhat test