-
Notifications
You must be signed in to change notification settings - Fork 113
Multi-chain reputation rebooted #1216
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
Closed
Closed
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
334b257
Make upgrade tests work with next version
area c8137a7
Make upgrade tests work with next version
area 6720816
First commit, to be squashed
area abeda29
Bridge skills on creation to home chain
area 753a47e
Add functionality to bridge reputation state
area 480be93
Add some more bridging tests
area c14543a
Low hanging fruit from first (p)review
area ab443ab
Test reputation decay on troubled bridging
area 2119eb2
Additional multichain tests
area d7828a4
Straighten out bridged skill trees so they match
area 23de753
First changes following second review
area 647e29a
First changes following second review
area 37a301b
Update relevant Network struct definitions
kronosapiens d6067e9
Add helper functions, misc refactoring
kronosapiens eac2c8e
Introduce ColonyNetworkSkills
kronosapiens 651fbac
Make bridging function names consistent
kronosapiens fb38608
Minor test edits
kronosapiens 199a7ee
Fix chainIds, revert cross-chain setup
area 9414d60
Some tweaks from review, add events
area e29cc30
Resurrect skipped tests as appropriate
area 74a585b
Minor close to final tweaks
area 6566443
Non-functional tweaks
area d7da304
Some contract tidying, extra tests for coverage
area f1e4f9c
Slither updates
area 4b5bea3
Change how bridged transactions are tracked in tests
area 0507a59
Add guards for unsupported large chainIds
area f755d5d
Add missing awaits to tests
area c86989d
Meaningless tweaks and correctly error-out in tests
area 2092d7b
Continue making cross-chain tests more robust
area 426f446
Fix flubbed rebase
area e9968a4
Add example tests that need to pass
area 3a29e18
Add and get all bridging permission tests passing
area 4748003
Pickup post-rebase
area c6864c4
WIP: Wormhole restructuring
area e73009f
Make chainIds configurable
area 120ba2f
Low hanging fruit from review
area a59624a
More updates post-review
area 4b28154
Remove mintTokensForColonyNetwork
area b92595f
Update version-specific extension tests
area 512165c
Adjust multi-chain logic around mining skill id
area 5e11e58
Add extra output to upgrade scripts
area 90a4739
First pass after new review
area 64e34fa
Finish easy bits from first review plus rebase
area c25658e
Try to factorise calls to bridge
area 7f794ea
Further pickups from review
area a90c748
First attempt to add tests with mining on a non-xdai chain
area 9c6f0f1
Move skillId to a string in miner db
area f528684
More fixes for mining on non-gnosis chain
area 66f3558
MINING_CHAIN_ID needs to be set for cross-chaintests
area bcc4f78
Fix setup for test:reputation:2:anotherChain
area 8caed67
Temporary workaround for upgrade tests
area fb0f170
New contracts need new solidity version
area 1790a8e
Slither wants to use hardhat, so update imports
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
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 { | ||
kronosapiens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // 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
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.