This repository was archived by the owner on Apr 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Upgradable Authenticator #351
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4fe914f
making Authenticator upgradable
bh2smith 8d96c84
remove customInitiallyOwnable
bh2smith 6a0ba03
remove unnecessary deployment options
bh2smith 137f6a1
remove commented import
bh2smith dd520d2
Update src/ts/proxy.ts
bh2smith ee3cd11
remove dependency on oz/contracts-upgradable, implement own idempoten…
bh2smith 3920986
Update test/e2e/upgradeAuthenticator.test.ts
bh2smith 7f3e8c0
include note about how from address is owner/manager on upgrade
bh2smith 39e5c51
fetch solver from wallets:
bh2smith cee5b69
Update src/ts/proxy.ts
bh2smith 9526057
Merge branch 'main' into 167/upgradable_authenticator
bh2smith ecd7315
yarn lock
bh2smith 26e8335
copy paste lock file from main
bh2smith 106c2c0
check idempotency with from owner
bh2smith 1a1f5ad
add additionaly idempotency check
bh2smith b4e7d5c
Merge branch 'main' into 167/upgradable_authenticator
bh2smith 6c5ad0f
Merge branch 'main' into 167/upgradable_authenticator
bh2smith 504228d
include onlyProxyAdmin modifier for updateManager
bh2smith 888c203
Merge branch '167/upgradable_authenticator' of github.com:gnosis/gp-v…
bh2smith 9414ed8
revert onlyProxyAdmin for another PR
bh2smith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
pragma solidity ^0.7.6; | ||
|
||
import "../GPv2AllowListAuthentication.sol"; | ||
|
||
contract GPv2AllowListAuthenticationV2 is GPv2AllowListAuthentication { | ||
function newMethod() external pure returns (uint256) { | ||
return 1337; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// defined in https://eips.ethereum.org/EIPS/eip-1967 | ||
|
||
import { BigNumber } from "ethers"; | ||
import { ethers } from "hardhat"; | ||
|
||
// The proxy contract used by hardhat-deploy implements EIP-1967 (Standard Proxy | ||
// Storage Slot). See <https://eips.ethereum.org/EIPS/eip-1967>. | ||
function slot(string: string) { | ||
return ethers.utils.defaultAbiCoder.encode( | ||
["bytes32"], | ||
[BigNumber.from(ethers.utils.id(string)).sub(1)], | ||
); | ||
} | ||
const IMPLEMENTATION_STORAGE_SLOT = slot("eip1967.proxy.implementation"); | ||
const OWNER_STORAGE_SLOT = slot("eip1967.proxy.admin"); | ||
|
||
/** | ||
* Returns the address of the implementation of an EIP-1967-compatible proxy | ||
* from its address. | ||
* | ||
* @param proxy Address of the proxy contract. | ||
* @returns The address of the contract storing the proxy implementation. | ||
*/ | ||
export async function implementationAddress(proxy: string): Promise<string> { | ||
const [implementation] = await ethers.utils.defaultAbiCoder.decode( | ||
["address"], | ||
await ethers.provider.getStorageAt(proxy, IMPLEMENTATION_STORAGE_SLOT), | ||
); | ||
return implementation; | ||
} | ||
|
||
/** | ||
* Returns the address of the implementation of an EIP-1967-compatible proxy | ||
* from its address. | ||
* | ||
* @param proxy Address of the proxy contract. | ||
* @returns The address of the administrator of the proxy. | ||
*/ | ||
export async function ownerAddress(proxy: string): Promise<string> { | ||
bh2smith marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const [owner] = await ethers.utils.defaultAbiCoder.decode( | ||
["address"], | ||
await ethers.provider.getStorageAt(proxy, OWNER_STORAGE_SLOT), | ||
); | ||
return owner; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { expect } from "chai"; | ||
import { Contract, Wallet } from "ethers"; | ||
import { deployments, ethers } from "hardhat"; | ||
|
||
import { deployTestContracts } from "./fixture"; | ||
|
||
describe("Upgrade Authenticator", () => { | ||
let authenticator: Contract; | ||
let deployer: Wallet; | ||
let owner: Wallet; | ||
let solver: Wallet; | ||
|
||
beforeEach(async () => { | ||
({ | ||
authenticator, | ||
deployer, | ||
owner, | ||
wallets: [solver], | ||
} = await deployTestContracts()); | ||
}); | ||
|
||
it("should upgrade authenticator", async () => { | ||
const GPv2AllowListAuthenticationV2 = await ethers.getContractFactory( | ||
"GPv2AllowListAuthenticationV2", | ||
deployer, | ||
); | ||
// Note that, before the upgrade this is actually the old instance | ||
const authenticatorV2 = GPv2AllowListAuthenticationV2.attach( | ||
authenticator.address, | ||
); | ||
// This method doesn't exist before upgrade | ||
await expect(authenticatorV2.newMethod()).to.be.reverted; | ||
|
||
await upgrade( | ||
"GPv2AllowListAuthentication", | ||
"GPv2AllowListAuthenticationV2", | ||
); | ||
// This method should exist on after upgrade | ||
expect(await authenticatorV2.newMethod()).to.equal(1337); | ||
}); | ||
|
||
it("should preserve storage", async () => { | ||
await authenticator.connect(owner).addSolver(solver.address); | ||
|
||
// Upgrade after storage is set. | ||
await upgrade( | ||
"GPv2AllowListAuthentication", | ||
"GPv2AllowListAuthenticationV2", | ||
); | ||
|
||
const GPv2AllowListAuthenticationV2 = await ethers.getContractFactory( | ||
"GPv2AllowListAuthenticationV2", | ||
deployer, | ||
); | ||
const authenticatorV2 = GPv2AllowListAuthenticationV2.attach( | ||
authenticator.address, | ||
); | ||
// Both, the listed solvers and original manager are still set | ||
expect(await authenticatorV2.isSolver(solver.address)).to.equal(true); | ||
expect(await authenticatorV2.manager()).to.equal(owner.address); | ||
}); | ||
|
||
fedgiac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
async function upgrade(contractName: string, newContractName: string) { | ||
// Note that deterministic deployment and gasLimit are not needed/used here as deployment args. | ||
await deployments.deploy(contractName, { | ||
contract: newContractName, | ||
// From differs from initial deployment here since the proxy owner is the Authenticator manager. | ||
from: owner.address, | ||
bh2smith marked this conversation as resolved.
Show resolved
Hide resolved
|
||
proxy: true, | ||
}); | ||
} | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.