-
Notifications
You must be signed in to change notification settings - Fork 112
Feat/multichain reputation rebased hardhat 2 #1238
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 60 commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
5f99255
Make upgrade tests work with next version
area 581e5fa
Make upgrade tests work with next version
area 7280bb6
First commit, to be squashed
area eec4ec4
Bridge skills on creation to home chain
area e04c364
Add functionality to bridge reputation state
area b3369d4
Add some more bridging tests
area 164b5d2
Low hanging fruit from first (p)review
area fc2b943
Test reputation decay on troubled bridging
area 69804b0
Additional multichain tests
area b90ef5c
Straighten out bridged skill trees so they match
area 64fb07c
First changes following second review
area aa89f46
First changes following second review
area 070ef94
Update relevant Network struct definitions
kronosapiens 98eafd4
Add helper functions, misc refactoring
kronosapiens 9ae3382
Introduce ColonyNetworkSkills
kronosapiens b9402e3
Make bridging function names consistent
kronosapiens 6623c79
Minor test edits
kronosapiens eff163c
Fix chainIds, revert cross-chain setup
area 2099acb
Some tweaks from review, add events
area 669c3a1
Resurrect skipped tests as appropriate
area 6801949
Minor close to final tweaks
area 4ed1684
Non-functional tweaks
area 7c8c897
Some contract tidying, extra tests for coverage
area fddc5aa
Slither updates
area 98f687c
Change how bridged transactions are tracked in tests
area 5399f02
Add guards for unsupported large chainIds
area 82bff34
Add missing awaits to tests
area 0a1fa3d
Meaningless tweaks and correctly error-out in tests
area 07da17f
Continue making cross-chain tests more robust
area dee1ae0
Fix flubbed rebase
area b31fd3c
Add example tests that need to pass
area 25b0886
Add and get all bridging permission tests passing
area a0dc262
Pickup post-rebase
area 59bfcfc
WIP: Wormhole restructuring
area b83167b
Make chainIds configurable
area a6b0b6c
Low hanging fruit from review
area 2c0909c
More updates post-review
area 41f2e19
Remove mintTokensForColonyNetwork
area ed472cb
Update version-specific extension tests
area 465b55a
Adjust multi-chain logic around mining skill id
area ad9bc22
Add extra output to upgrade scripts
area 52466e5
First pass after new review
area 12ee067
Finish easy bits from first review plus rebase
area 6639068
Try to factorise calls to bridge
area afb4b6c
Merge branch 'maint/hardhat-2' into feat/multichain-reputation-rebase…
area ce8a459
Merge branch 'maint/hardhat-2' into feat/multichain-reputation-rebase…
area 8f31c4f
Further pickups from review
area f574f27
First attempt to add tests with mining on a non-xdai chain
area 1de0919
Move skillId to a string in miner db
area 15e2f63
More fixes for mining on non-gnosis chain
area d94674f
MINING_CHAIN_ID needs to be set for cross-chaintests
area 4db80e1
Fix setup for test:reputation:2:anotherChain
area 6839f17
Temporary workaround for upgrade tests
area 48edf00
Merge branch 'feat/multichain-reputation-rebased' into feat/multichai…
area 0fc2bea
Temporary workaround for upgrade tests
area d79fe09
Coerce tests after merge
area 3015493
Fix spotty client-core-functionality tests
area 97428fc
Log error in setupEtherRouter to help in future
area 1caf6e5
Can't run smoke tests with hardhat yet
area 4036572
Merge branch 'maint/hardhat-2' into feat/multichain-reputation-rebase…
area 15c78f3
Changes post review
area d81142a
Changes post review II
area 92f496c
Try to pin down spotty miner test
area 1969840
Changes post review III
area 0d9436c
Disable incorrect-equality on slither
area 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
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 |
|---|---|---|
| @@ -1,5 +1,24 @@ | ||
| const config = require("./.solcover.js") | ||
| const ethers = require("ethers"); | ||
|
|
||
| config.istanbulFolder = `./coverage-cross-chain-${process.env.HARDHAT_FOREIGN ? "foreign" : "home"}` | ||
| const { FORKED_XDAI_CHAINID } = require("./helpers/constants"); | ||
|
|
||
| config.istanbulFolder = `./coverage-cross-chain-${process.env.HARDHAT_FOREIGN === "true" ? "foreign" : "home"}` | ||
| console.log(`Coverage folder: ${config.istanbulFolder}`) | ||
|
|
||
| let chainId; | ||
| // We configure the truffle coverage chain to have the same chainid as one of the | ||
| // nodes we've started up, but on a different port | ||
| // TODO: Actually query nodes, don't hard-code here, or work out how to get environment | ||
| // variables in package.json to work here as I want. | ||
| if (JSON.parse(process.env.HARDHAT_FOREIGN)){ | ||
| chainId = FORKED_XDAI_CHAINID + 1; | ||
| } else { | ||
| chainId = FORKED_XDAI_CHAINID; | ||
| } | ||
|
|
||
| config.providerOptions.network_id = chainId; | ||
| config.providerOptions._chainId = chainId; | ||
| config.providerOptions._chainIdRpc = chainId; | ||
|
|
||
| module.exports = config |
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,52 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| /* | ||
| This file is part of The Colony Network. | ||
|
|
||
| The Colony Network is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation, either version 3 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| The Colony Network is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with The Colony Network. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| pragma solidity 0.8.25; | ||
| pragma experimental "ABIEncoderV2"; | ||
|
|
||
| interface IColonyBridge { | ||
| /// @notice Function that checks whether a chain with the supplied evmChainId is supported | ||
| /// @param _evmChainId The chain id to check | ||
| /// @return bool Whether the chain is supported | ||
| function supportedEvmChainId(uint256 _evmChainId) external view returns (bool); | ||
|
|
||
| /// @notice Function to set the colony network address that the bridge will interact with | ||
| /// @param _colonyNetwork The address of the colony network | ||
| function setColonyNetworkAddress(address _colonyNetwork) external; | ||
|
|
||
| /// @notice Function to get the colony network address that the bridge is interacting with | ||
| /// @return address The address of the colony network | ||
| function getColonyNetworkAddress() external view returns (address); | ||
|
|
||
| /// @notice Function to set the address of the instance of this contract on other chains, that | ||
| /// this contract will expect to receive messages from | ||
| /// @param _evmChainId The chain id to set the address for | ||
| /// @param _colonyBridge The address of the colony bridge contract on the other chain | ||
| function setColonyBridgeAddress(uint256 _evmChainId, address _colonyBridge) external; | ||
|
|
||
| /// @notice Function to get the address of the instance of this contract on other chains | ||
| /// @param evmChainId The chain id to get the address for | ||
| function getColonyBridgeAddress(uint256 evmChainId) external view returns (address); | ||
|
|
||
| /// @notice Function to send a message to the colony bridge on another chain | ||
| /// @param evmChainId The chain id to send the message to | ||
| /// @param payload The message payload | ||
| /// @return bool Whether the message was sent successfully (to the best of the contract's knowledge, | ||
| /// in terms of the underlying bridge implementation) | ||
| function sendMessage(uint256 evmChainId, bytes memory payload) external returns (bool); | ||
| } |
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,135 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| /* | ||
| This file is part of The Colony Network. | ||
|
|
||
| The Colony Network is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation, either version 3 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| The Colony Network is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with The Colony Network. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| pragma solidity 0.8.25; | ||
|
|
||
| import { IWormhole } from "../../lib/wormhole/ethereum/contracts/interfaces/IWormhole.sol"; | ||
| import { IColonyNetwork } from "../colonyNetwork/IColonyNetwork.sol"; | ||
| import { IColonyBridge } from "./IColonyBridge.sol"; | ||
| import { CallWithGuards } from "../common/CallWithGuards.sol"; | ||
| import { DSAuth } from "../../lib/dappsys/auth.sol"; | ||
|
|
||
| contract WormholeBridgeForColony is DSAuth, IColonyBridge, CallWithGuards { | ||
| address colonyNetwork; | ||
| IWormhole public wormhole; | ||
|
|
||
| // ChainId => colonyBridge | ||
| mapping(uint256 => address) colonyBridges; | ||
|
|
||
| // Maps evm chain id to wormhole chain id | ||
| mapping(uint256 => uint16) public evmChainIdToWormholeChainId; | ||
|
|
||
| modifier onlyColonyNetwork() { | ||
| require(msg.sender == colonyNetwork, "wormhole-bridge-only-colony-network"); | ||
| _; | ||
| } | ||
|
|
||
| function setChainIdMapping( | ||
| uint256[] calldata evmChainIds, | ||
| uint16[] calldata wormholeChainIds | ||
| ) public auth { | ||
| require( | ||
| evmChainIds.length == wormholeChainIds.length, | ||
| "colony-bridge-chainid-mapping-length-mismatch" | ||
| ); | ||
| for (uint256 i = 0; i < evmChainIds.length; i++) { | ||
| evmChainIdToWormholeChainId[evmChainIds[i]] = wormholeChainIds[i]; | ||
| } | ||
| } | ||
|
|
||
| function supportedEvmChainId(uint256 _evmChainId) public view returns (bool) { | ||
| return evmChainIdToWormholeChainId[_evmChainId] != 0; | ||
| } | ||
|
|
||
| function setWormholeAddress(address _wormhole) public auth { | ||
| wormhole = IWormhole(_wormhole); | ||
| } | ||
|
|
||
| function setColonyNetworkAddress(address _colonyNetwork) public auth { | ||
| colonyNetwork = _colonyNetwork; | ||
| } | ||
|
|
||
| function getColonyNetworkAddress() public view returns (address) { | ||
| return colonyNetwork; | ||
| } | ||
|
|
||
| function setColonyBridgeAddress(uint256 _evmChainId, address _bridgeAddress) public auth { | ||
| require(_evmChainId <= type(uint128).max, "colony-bridge-chainid-too-large"); | ||
| uint16 requestedWormholeChainId = evmChainIdToWormholeChainId[_evmChainId]; | ||
| colonyBridges[requestedWormholeChainId] = _bridgeAddress; | ||
| } | ||
|
|
||
| function getColonyBridgeAddress(uint256 evmChainId) public view returns (address) { | ||
| uint16 requestedWormholeChainId = evmChainIdToWormholeChainId[evmChainId]; | ||
| return colonyBridges[requestedWormholeChainId]; | ||
| } | ||
|
|
||
| function wormholeAddressToEVMAddress( | ||
| bytes32 _wormholeFormatAddress | ||
| ) public pure returns (address) { | ||
| return address(uint160(uint256(_wormholeFormatAddress))); | ||
| } | ||
|
|
||
| function receiveMessage(bytes memory _vaa) public { | ||
| // VAAs are the primitives used on wormhole (Verified Action Approvals) | ||
| // See https://docs.wormhole.com/wormhole/explore-wormhole/vaa for more details | ||
| // Note that the documentation sometimes also calls them VMs (as does IWormhole) | ||
| // I believe VM stands for 'Verified Message' | ||
| (IWormhole.VM memory wormholeMessage, bool valid, string memory reason) = wormhole | ||
| .parseAndVerifyVM(_vaa); | ||
|
|
||
| // Check the vaa was valid | ||
| require(valid, reason); | ||
|
|
||
| // Check came from a known colony bridge | ||
| require( | ||
| wormholeAddressToEVMAddress(wormholeMessage.emitterAddress) == | ||
| colonyBridges[wormholeMessage.emitterChainId], | ||
| "colony-bridge-bridged-tx-only-from-colony-bridge" | ||
| ); | ||
|
|
||
| // We ignore sequence numbers - bridging out of order is okay, because we have our own way of handling that | ||
|
|
||
| // Make the call requested to the colony network | ||
| (bool success, bytes memory returndata) = callWithGuards( | ||
| colonyNetwork, | ||
| wormholeMessage.payload | ||
| ); | ||
|
|
||
| // Note that this is not a require because returndata might not be a string, and if we try | ||
| // to decode it we'll get a revert. | ||
| if (!success) { | ||
| revert(abi.decode(returndata, (string))); | ||
| } | ||
| } | ||
|
|
||
| function sendMessage( | ||
| uint256 _evmChainId, | ||
| bytes memory _payload | ||
| ) public onlyColonyNetwork returns (bool) { | ||
| require(supportedEvmChainId(_evmChainId), "colony-bridge-not-known-chain"); | ||
| // This returns a sequence, but we don't care about it | ||
| // The first sequence ID is, I believe 0, so all return values are potentially valid | ||
| // slither-disable-next-line unused-return | ||
| try wormhole.publishMessage(0, _payload, 0) { | ||
| return true; | ||
| } catch { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
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
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.