Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use proxies from OpenZeppelin Contracts 4.8.3 #795

Merged
merged 8 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Use proxies from OpenZeppelin Contracts 4.8.3. ([#795](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/795))

## 1.26.0 (2023-05-08)

- Enable using OpenZeppelin Platform for deployments. ([#763](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/763))
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openzeppelin/upgrades-core",
"version": "1.26.0",
"version": "1.26.1",
"description": "",
"repository": "https://github.com/OpenZeppelin/openzeppelin-upgrades/tree/master/packages/core",
"license": "MIT",
Expand Down Expand Up @@ -34,8 +34,8 @@
"@ava/typescript": "^2.0.0",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-etherscan": "^3.0.0",
"@openzeppelin/contracts": "4.1.0",
"@openzeppelin/contracts-upgradeable": "4.1.0",
"@openzeppelin/contracts": "4.8.3",
"@openzeppelin/contracts-upgradeable": "4.8.3",
"@types/cbor": "^5.0.0",
"@types/debug": "^4.1.5",
"@types/mocha": "^7.0.2",
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-hardhat/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Use proxies from OpenZeppelin Contracts 4.8.3. ([#795](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/795))

## 1.25.1 (2023-05-10)

- Fix type error with `platform.deployContract`. ([#793](https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/793))
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-hardhat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-etherscan": "^3.1.0",
"@openzeppelin/contracts": "4.1.0",
"@openzeppelin/contracts-upgradeable": "4.1.0",
"@openzeppelin/contracts": "4.8.3",
"@openzeppelin/contracts-upgradeable": "4.8.3",
"@types/mocha": "^7.0.2",
"ava": "^5.0.0",
"fgbg": "^0.1.4",
Expand All @@ -33,7 +33,7 @@
"rimraf": "^3.0.2"
},
"dependencies": {
"@openzeppelin/upgrades-core": "^1.26.0",
"@openzeppelin/upgrades-core": "^1.26.1",
"chalk": "^4.1.0",
"debug": "^4.1.1",
"defender-admin-client": "^1.39.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin-hardhat/src/upgrade-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Manifest, getAdminAddress, getCode, isEmptySlot } from '@openzeppelin/u
import {
UpgradeProxyOptions,
deployProxyImpl,
getTransparentUpgradeableProxyFactory,
getITransparentUpgradeableProxyFactory,
getProxyAdminFactory,
getContractAddress,
ContractAddressOrInstance,
Expand Down Expand Up @@ -46,9 +46,9 @@ export function makeUpgradeProxy(hre: HardhatRuntimeEnvironment, platformModule:
const adminBytecode = await getCode(provider, adminAddress);

if (isEmptySlot(adminAddress) || adminBytecode === '0x') {
// No admin contract: use TransparentUpgradeableProxyFactory to get proxiable interface
const TransparentUpgradeableProxyFactory = await getTransparentUpgradeableProxyFactory(hre, signer);
const proxy = TransparentUpgradeableProxyFactory.attach(proxyAddress);
// No admin contract: use ITransparentUpgradeableProxyFactory to get proxiable interface
const ITransparentUpgradeableProxyFactory = await getITransparentUpgradeableProxyFactory(hre, signer);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for this change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I remember now, and I understand why this was done.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting for completeness:

The upgradeProxy function in the plugins invokes the upgradeToAndCall or upgradeTo function on the proxy, regardless of whether it is a UUPS or Transparent proxy. It did this by using TransparentUpgradeableProxy's contract factory to encode those functions, which depends on the ABI. (Note this also works for UUPS proxies because those function signatures are the same between UUPS and Transparent).

In OpenZeppelin Contracts 4.8.3, the upgradeToAndCall and upgradeTo functions are not part of TransparentUpgradeableProxy's ABI, but are in the interface ITransparentUpgradeableProxy's ABI. Therefore, we use ITransparentUpgradeableProxy's contract factory to encode those functions instead.

const proxy = ITransparentUpgradeableProxyFactory.attach(proxyAddress);

return (nextImpl, call) => (call ? proxy.upgradeToAndCall(nextImpl, call) : proxy.upgradeTo(nextImpl));
} else {
Expand Down
8 changes: 8 additions & 0 deletions packages/plugin-hardhat/src/utils/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ERC1967Proxy from '@openzeppelin/upgrades-core/artifacts/@openzeppelin/co
import BeaconProxy from '@openzeppelin/upgrades-core/artifacts/@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol/BeaconProxy.json';
import UpgradeableBeacon from '@openzeppelin/upgrades-core/artifacts/@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol/UpgradeableBeacon.json';
import TransparentUpgradeableProxy from '@openzeppelin/upgrades-core/artifacts/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json';
import ITransparentUpgradeableProxy from '@openzeppelin/upgrades-core/artifacts/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/ITransparentUpgradeableProxy.json';
import ProxyAdmin from '@openzeppelin/upgrades-core/artifacts/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol/ProxyAdmin.json';

export async function getProxyFactory(hre: HardhatRuntimeEnvironment, signer?: Signer): Promise<ContractFactory> {
Expand All @@ -17,6 +18,13 @@ export async function getTransparentUpgradeableProxyFactory(
return hre.ethers.getContractFactory(TransparentUpgradeableProxy.abi, TransparentUpgradeableProxy.bytecode, signer);
}

export async function getITransparentUpgradeableProxyFactory(
hre: HardhatRuntimeEnvironment,
signer?: Signer,
): Promise<ContractFactory> {
return hre.ethers.getContractFactory(ITransparentUpgradeableProxy.abi, ITransparentUpgradeableProxy.bytecode, signer);
}

export async function getProxyAdminFactory(hre: HardhatRuntimeEnvironment, signer?: Signer): Promise<ContractFactory> {
return hre.ethers.getContractFactory(ProxyAdmin.abi, ProxyAdmin.bytecode, signer);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-truffle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Use proxies from OpenZeppelin Contracts 4.8.3. ([#795](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/795))

## 1.18.0 (2023-04-26)

- Support `prepareUpgrade` from an implementation address. ([#777](https://github.com/OpenZeppelin/openzeppelin-upgrades/issues/777))
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-truffle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"rimraf": "^3.0.2"
},
"dependencies": {
"@openzeppelin/upgrades-core": "^1.25.0",
"@openzeppelin/upgrades-core": "^1.26.1",
"@truffle/contract": "^4.3.26",
"chalk": "^4.1.0",
"debug": "^4.1.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin-truffle/src/upgrade-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ContractInstance,
wrapProvider,
deployProxyImpl,
getTransparentUpgradeableProxyFactory,
getITransparentUpgradeableProxyFactory,
getProxyAdminFactory,
UpgradeProxyOptions,
withDefaults,
Expand Down Expand Up @@ -46,9 +46,9 @@ async function getUpgrader(
const adminBytecode = await getCode(provider, adminAddress);

if (isEmptySlot(adminAddress) || adminBytecode === '0x') {
// No admin contract: use TransparentUpgradeableProxyFactory to get proxiable interface
const TransparentUpgradeableProxyFactory = getTransparentUpgradeableProxyFactory(contractTemplate);
const proxy = new TransparentUpgradeableProxyFactory(proxyAddress);
// No admin contract: use ITransparentUpgradeableProxyFactory to get proxiable interface
const ITransparentUpgradeableProxyFactory = getITransparentUpgradeableProxyFactory(contractTemplate);
const proxy = new ITransparentUpgradeableProxyFactory(proxyAddress);

return (nextImpl, call) => {
return call ? proxy.upgradeToAndCall(nextImpl, call) : proxy.upgradeTo(nextImpl);
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-truffle/src/utils/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { TruffleContract, ContractClass, getTruffleDefaults, getTruffleProvider

import ERC1967ProxyArtifact from '@openzeppelin/upgrades-core/artifacts/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol/ERC1967Proxy.json';
import TransparentUpgradeableProxyArtifact from '@openzeppelin/upgrades-core/artifacts/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json';
import ITransparentUpgradeableProxyArtifact from '@openzeppelin/upgrades-core/artifacts/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/ITransparentUpgradeableProxy.json';
import ProxyAdminArtifact from '@openzeppelin/upgrades-core/artifacts//@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol/ProxyAdmin.json';
import BeaconProxyArtifact from '@openzeppelin/upgrades-core/artifacts//@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol/BeaconProxy.json';
import UpgradeableBeaconArtifact from '@openzeppelin/upgrades-core/artifacts//@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol/UpgradeableBeacon.json';
Expand All @@ -17,6 +18,7 @@ function makeFactoryGetter(artifacts: unknown): (template?: ContractClass) => Co

export const getProxyFactory = makeFactoryGetter(ERC1967ProxyArtifact);
export const getTransparentUpgradeableProxyFactory = makeFactoryGetter(TransparentUpgradeableProxyArtifact);
export const getITransparentUpgradeableProxyFactory = makeFactoryGetter(ITransparentUpgradeableProxyArtifact);
export const getProxyAdminFactory = makeFactoryGetter(ProxyAdminArtifact);
export const getBeaconProxyFactory = makeFactoryGetter(BeaconProxyArtifact);
export const getUpgradeableBeaconFactory = makeFactoryGetter(UpgradeableBeaconArtifact);
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2182,15 +2182,15 @@
dependencies:
"@octokit/openapi-types" "^14.0.0"

"@openzeppelin/contracts-upgradeable@4.1.0":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.1.0.tgz#36a6113ceeda278ae14f740280e5388161dfd383"
integrity sha512-QZSvbYqNpU/x60vARhq/jghh97VWjml3NAlKfu4u1XehvpEBbHVXJyKTBSZtZY7jviG305jOczEisnN8VeOMcw==

"@openzeppelin/contracts@4.1.0":
version "4.1.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.1.0.tgz#baec89a7f5f73e3d8ea582a78f1980134b605375"
integrity sha512-TihZitscnaHNcZgXGj9zDLDyCqjziytB4tMCwXq0XimfWkAjBYyk5/pOsDbbwcavhlc79HhpTEpQcrMnPVa1mw==
"@openzeppelin/contracts-upgradeable@4.8.3":
version "4.8.3"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts-upgradeable/-/contracts-upgradeable-4.8.3.tgz#6b076a7b751811b90fe3a172a7faeaa603e13a3f"
integrity sha512-SXDRl7HKpl2WDoJpn7CK/M9U4Z8gNXDHHChAKh0Iz+Wew3wu6CmFYBeie3je8V0GSXZAIYYwUktSrnW/kwVPtg==

"@openzeppelin/contracts@4.8.3":
version "4.8.3"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-4.8.3.tgz#cbef3146bfc570849405f59cba18235da95a252a"
integrity sha512-bQHV8R9Me8IaJoJ2vPG4rXcL7seB7YVuskr4f+f5RyOStSZetwzkWtoqDMl5erkBJy0lDRUnIR2WIkPiC0GJlg==

"@openzeppelin/docs-utils@^0.1.0":
version "0.1.3"
Expand Down