Repository navigation
fix(oft): audit fixes C-01, H-01, H-02, H-03, M-01a, L-05 #14
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
Merged
Merged
Changes from all commits
Commits
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 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
56 changes: 56 additions & 0 deletions
56
packages/bridge-contracts/deploy/utils/verifyOftDeployment.ts
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,56 @@ | ||
| import { deployments, ethers } from 'hardhat'; | ||
| import Contracts from '@gooddollar/goodprotocol/releases/deployment.json'; | ||
|
|
||
| const EIP1967_IMPLEMENTATION_SLOT = '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'; | ||
|
|
||
| async function readProxyImplementation(proxy: string): Promise<string> { | ||
| const raw = await ethers.provider.getStorageAt(proxy, EIP1967_IMPLEMENTATION_SLOT); | ||
| return ethers.utils.getAddress(ethers.utils.hexDataSlice(raw, 12)); | ||
| } | ||
|
|
||
| function expectEqual(label: string, actual: string, expected: string) { | ||
| if (actual.toLowerCase() !== expected.toLowerCase()) { | ||
| throw new Error(`OFT deployment check failed: ${label} is ${actual}, expected ${expected}`); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Verifies the OFT proxies point at our implementations and were initialized with the expected wiring. | ||
| * Must pass before granting MINTER_ROLE or setting LZ peers. | ||
| * @param allowedOwners adapter owners accepted at this stage (deployer before handover, Avatar after) | ||
| */ | ||
| export async function verifyOftDeployment(networkName: string, allowedOwners: string[]) { | ||
| const gp = Contracts[networkName as keyof typeof Contracts] as any; | ||
| if (!gp?.GoodDollar || !gp?.Avatar) throw new Error(`Missing GoodDollar/Avatar for ${networkName}`); | ||
|
|
||
| const minterBurnerAddress = (await deployments.get('GoodDollarOFTMinterBurner')).address; | ||
| const adapterAddress = (await deployments.get('GoodDollarOFTAdapter')).address; | ||
|
|
||
| expectEqual( | ||
| 'GoodDollarOFTAdapter implementation', | ||
| await readProxyImplementation(adapterAddress), | ||
| (await deployments.get('GoodDollarOFTAdapter_Implementation')).address, | ||
| ); | ||
| expectEqual( | ||
| 'GoodDollarOFTMinterBurner implementation', | ||
| await readProxyImplementation(minterBurnerAddress), | ||
| (await deployments.get('GoodDollarOFTMinterBurner_Implementation')).address, | ||
| ); | ||
|
|
||
| const adapter = await ethers.getContractAt('GoodDollarOFTAdapter', adapterAddress); | ||
| const owner: string = await adapter.owner(); | ||
| if (!allowedOwners.some((o) => o.toLowerCase() === owner.toLowerCase())) { | ||
| throw new Error(`OFT deployment check failed: adapter owner ${owner} not in [${allowedOwners.join(', ')}]`); | ||
| } | ||
| expectEqual('adapter.token()', await adapter.token(), gp.GoodDollar); | ||
| expectEqual('adapter.minterBurner()', await adapter.minterBurner(), minterBurnerAddress); | ||
| expectEqual('adapter.feeRecipient()', await adapter.feeRecipient(), gp.Avatar); | ||
|
|
||
| const minterBurner = await ethers.getContractAt('GoodDollarOFTMinterBurner', minterBurnerAddress); | ||
| expectEqual('minterBurner.token()', await minterBurner.token(), gp.GoodDollar); | ||
| if (!(await minterBurner.operators(adapterAddress))) { | ||
| throw new Error('OFT deployment check failed: adapter is not a MinterBurner operator'); | ||
| } | ||
|
|
||
| console.log(`OFT deployment verified on ${networkName} (adapter owner ${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
Oops, something went wrong.
Oops, something went wrong.
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.