Repository navigation
fix(oft): audit medium/low remediations (M-01..M-05, L-01..L-09) #15
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
167 changes: 116 additions & 51 deletions
167
packages/bridge-contracts/contracts/oft/GoodDollarOFTAdapter.sol
Large diffs are not rendered by default.
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
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
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
111 changes: 111 additions & 0 deletions
111
packages/bridge-contracts/scripts/oft/verify-invariants.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,111 @@ | ||
| import { task } from "hardhat/config"; | ||
| import type { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
| import { EndpointId } from "@layerzerolabs/lz-definitions"; | ||
| import Contracts from "@gooddollar/goodprotocol/releases/deployment.json"; | ||
| import config from "./oft.config.json"; | ||
| import { getOftDeploymentAddresses } from "../../deploy/utils/getOftDeploymentAddresses"; | ||
|
|
||
| const REMOTE_NETWORK: Record<string, string> = { | ||
| "production-xdc": "production-celo", | ||
| "production-celo": "production-xdc", | ||
| "development-xdc": "development-celo", | ||
| "development-celo": "development-xdc", | ||
| }; | ||
|
|
||
| const MIN_REQUIRED_DVNS = 2; | ||
| const ULN_CONFIG_TYPE = 2; | ||
| const ULN_CONFIG_ABI = [ | ||
| "tuple(uint64 confirmations, uint8 requiredDVNCount, uint8 optionalDVNCount, uint8 optionalDVNThreshold, address[] requiredDVNs, address[] optionalDVNs)", | ||
| ]; | ||
| const ENDPOINT_ABI = [ | ||
| "function delegates(address) view returns (address)", | ||
| "function getSendLibrary(address _sender, uint32 _dstEid) view returns (address)", | ||
| "function getReceiveLibrary(address _receiver, uint32 _srcEid) view returns (address lib, bool isDefault)", | ||
| "function getConfig(address _oapp, address _lib, uint32 _eid, uint32 _configType) view returns (bytes)", | ||
| ]; | ||
|
|
||
| const eidOf = (networkName: string) => | ||
| networkName.includes("xdc") ? EndpointId.XDC_V2_MAINNET : EndpointId.CELO_V2_MAINNET; | ||
|
|
||
| /** | ||
| * Post-deploy invariants: Avatar owns/delegates the adapter, peers, limits, DVNs and minting rights are as expected. | ||
| * Collects every failure and throws once at the end. | ||
| */ | ||
| export async function verifyOftInvariants(hre: HardhatRuntimeEnvironment) { | ||
| const { ethers, network } = hre; | ||
| const { verifyOftDeployment } = await import("../../deploy/utils/verifyOftDeployment"); | ||
| const { parseLimit } = await import("./steps/set-bridge-limits"); | ||
|
|
||
| const networkName = network.name; | ||
| const remoteNetwork = REMOTE_NETWORK[networkName]; | ||
| if (!remoteNetwork) throw new Error(`Unknown network pairing for "${networkName}"`); | ||
| const gp = (Contracts as any)[networkName]; | ||
| const avatar: string = gp?.Avatar; | ||
| if (!avatar) throw new Error(`Avatar not found for ${networkName}`); | ||
|
|
||
| // implementation slots, token/minterBurner/feeRecipient wiring, operators(adapter); owner must be the Avatar | ||
| await verifyOftDeployment(networkName, [avatar]); | ||
|
|
||
| const failures: string[] = []; | ||
| const check = (ok: boolean, label: string) => { | ||
| console.log(`${ok ? "ok " : "FAIL"} ${label}`); | ||
| if (!ok) failures.push(label); | ||
| }; | ||
| const same = (a: string, b: string) => a.toLowerCase() === b.toLowerCase(); | ||
|
|
||
| const { GoodDollarOFTAdapter: adapterAddress, GoodDollarOFTMinterBurner: minterBurnerAddress } = | ||
| getOftDeploymentAddresses(networkName); | ||
| const { GoodDollarOFTAdapter: remoteAdapter } = getOftDeploymentAddresses(remoteNetwork); | ||
| const adapter = await ethers.getContractAt("GoodDollarOFTAdapter", adapterAddress); | ||
| const endpoint = await ethers.getContractAt(ENDPOINT_ABI, await adapter.endpoint()); | ||
| const remoteEid = eidOf(remoteNetwork); | ||
|
|
||
| check(same(await adapter.owner(), avatar), `adapter.owner() == Avatar ${avatar}`); | ||
| check(same(await endpoint.delegates(adapterAddress), avatar), "endpoint.delegates(adapter) == Avatar"); | ||
| check( | ||
| same(await adapter.peers(remoteEid), ethers.utils.hexZeroPad(remoteAdapter, 32)), | ||
| `adapter.peers(${remoteEid}) == ${remoteNetwork} adapter ${remoteAdapter}` | ||
| ); | ||
|
|
||
| const token = await ethers.getContractAt( | ||
| "contracts/oft/interfaces/ISuperGoodDollar.sol:ISuperGoodDollar", | ||
| gp.GoodDollar | ||
| ); | ||
| check(await token.isMinter(minterBurnerAddress), "G$.isMinter(minterBurner)"); | ||
|
|
||
| const expected = (config as any)[networkName]?.limits; | ||
| if (!expected) { | ||
| check(false, `limits for ${networkName} in oft.config.json`); | ||
| } else { | ||
| const actual = await adapter.bridgeLimits(); | ||
| for (const key of ["dailyLimit", "txLimit", "accountDailyLimit", "minAmount"]) { | ||
| check(parseLimit(expected[key])!.eq(actual[key]), `bridgeLimits.${key} == ${expected[key]}`); | ||
| } | ||
| check(actual.onlyWhitelisted === expected.onlyWhitelisted, `bridgeLimits.onlyWhitelisted == ${expected.onlyWhitelisted}`); | ||
| } | ||
|
|
||
| const sendLib: string = await endpoint.getSendLibrary(adapterAddress, remoteEid); | ||
| const [receiveLib] = await endpoint.getReceiveLibrary(adapterAddress, remoteEid); | ||
| for (const [side, lib] of [ | ||
| ["send", sendLib], | ||
| ["receive", receiveLib], | ||
| ]) { | ||
| const raw = await endpoint.getConfig(adapterAddress, lib, remoteEid, ULN_CONFIG_TYPE); | ||
| const [uln] = ethers.utils.defaultAbiCoder.decode(ULN_CONFIG_ABI, raw); | ||
| check( | ||
| uln.requiredDVNCount >= MIN_REQUIRED_DVNS && uln.requiredDVNCount !== 255, | ||
| `${side} ULN requiredDVNCount ${uln.requiredDVNCount} >= ${MIN_REQUIRED_DVNS} (${uln.requiredDVNs.join(", ")})` | ||
| ); | ||
|
blueogin marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| if (failures.length > 0) { | ||
| throw new Error(`OFT invariants failed on ${networkName}:\n- ${failures.join("\n- ")}`); | ||
| } | ||
| console.log(`OFT invariants hold on ${networkName}`); | ||
| } | ||
|
|
||
| task("oft:verify", "Check post-deploy OFT invariants (ownership, delegate, peers, limits, DVNs, minter)").setAction( | ||
| async (_, hre) => { | ||
| await verifyOftInvariants(hre); | ||
| } | ||
| ); | ||
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.