Skip to content
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

Add strict rules about upgrading to next versions of colony/OneTxPayment #1181

Merged
merged 6 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions contracts/colony/Colony.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { IColonyNetwork } from "./../colonyNetwork/IColonyNetwork.sol";
import { PatriciaTreeProofs } from "./../patriciaTree/PatriciaTreeProofs.sol";
import { ColonyStorage } from "./ColonyStorage.sol";
import { ColonyAuthority } from "./ColonyAuthority.sol";
import { ColonyExtension } from "./../extensions/ColonyExtension.sol";

contract Colony is BasicMetaTransaction, Multicall, ColonyStorage, PatriciaTreeProofs {
// This function, exactly as defined, is used in build scripts. Take care when updating.
Expand Down Expand Up @@ -337,6 +338,24 @@ contract Colony is BasicMetaTransaction, Multicall, ColonyStorage, PatriciaTreeP
sig = bytes4(keccak256("setPaymentPayout(uint256,uint256,uint256,address,uint256)"));
colonyAuthority.setRoleCapability(uint8(ColonyRole.Administration), address(this), sig, false);
sig = bytes4(keccak256("finalizePayment(uint256,uint256,uint256)"));

// If OneTxPayment extension is installed, add the new role and upgrade it
bytes32 ONE_TX_PAYMENT = keccak256("OneTxPayment");
IColonyNetwork network = IColonyNetwork(colonyNetworkAddress);
address oneTxPaymentAddress = network.getExtensionInstallation(ONE_TX_PAYMENT, address(this));

if (oneTxPaymentAddress != address(0x0)) {
uint256 installedVersion = ColonyExtension(oneTxPaymentAddress).version();
require(installedVersion >= 5, "colony-upgrade-one-tx-payment-to-6");
if (installedVersion == 5) {
// If installed in root, add arbitration permission
if (colonyAuthority.hasUserRole(oneTxPaymentAddress, 1, uint8(ColonyRole.Administration))) {
colonyAuthority.setUserRole(oneTxPaymentAddress, 1, uint8(ColonyRole.Arbitration), true);
}
// Upgrade extension
network.upgradeExtension(ONE_TX_PAYMENT, 6);
}
}
}

function getMetatransactionNonce(address _user) public view override returns (uint256 nonce) {
Expand Down
9 changes: 7 additions & 2 deletions contracts/colony/ColonyAuthority.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ contract ColonyAuthority is CommonAuthority {
colony = _colony;

// Add permissions for the Administration role
// Task and Payments have been deprecated (see #1150)

addRoleCapability(ADMINISTRATION_ROLE, "makeTask(uint256,uint256,bytes32,uint256,uint256,uint256)"); // Only for versions < 14
addRoleCapability(ADMINISTRATION_ROLE, "addPayment(uint256,uint256,address,address,uint256,uint256,uint256)"); // Only for versions < 14
addRoleCapability(ADMINISTRATION_ROLE, "setPaymentRecipient(uint256,uint256,uint256,address)"); // Only for versions < 14
addRoleCapability(ADMINISTRATION_ROLE, "setPaymentSkill(uint256,uint256,uint256,uint256)"); // Only for versions < 14
addRoleCapability(ADMINISTRATION_ROLE, "setPaymentPayout(uint256,uint256,uint256,address,uint256)"); // Only for versions < 14
addRoleCapability(ADMINISTRATION_ROLE, "finalizePayment(uint256,uint256,uint256)"); // Only for versions < 14

// Add permissions for the Funding role
addRoleCapability(FUNDING_ROLE, "moveFundsBetweenPots(uint256,uint256,uint256,uint256,uint256,uint256,address)");

Expand Down
7 changes: 5 additions & 2 deletions contracts/extensions/OneTxPayment.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ contract OneTxPayment is ColonyExtension, BasicMetaTransaction {
/// @notice Returns the version of the extension
/// @return _version The extension's version number
function version() public pure override returns (uint256 _version) {
return 7;
return 6;
}

/// @notice Configures the extension
Expand All @@ -68,7 +68,10 @@ contract OneTxPayment is ColonyExtension, BasicMetaTransaction {
}

/// @notice Called when upgrading the extension
function finishUpgrade() public override auth {} // solhint-disable-line no-empty-blocks
function finishUpgrade() public override auth {
// Check colony has been upgraded first
require(colony.version() >= 14, "voting-rep-upgrade-colony-first");
} // solhint-disable-line no-empty-blocks

/// @notice Called when deprecating (or undeprecating) the extension
/// @param _deprecated Indicates whether the extension should be deprecated or undeprecated
Expand Down
90 changes: 0 additions & 90 deletions contracts/testHelpers/TasksPayments.sol

This file was deleted.

11 changes: 9 additions & 2 deletions helpers/test-data-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const {
SLOT0,
SLOT1,
SLOT2,
ADDRESS_ZERO,
} = require("./constants");
const { getTokenArgs, web3GetAccounts, getChildSkillIndex, web3SignTypedData } = require("./test-helper");

Expand Down Expand Up @@ -289,8 +290,14 @@ exports.setupRandomColony = async function setupRandomColony(colonyNetwork, lock
return { colony, token };
};

exports.setupColony = async function setupColony(colonyNetwork, tokenAddress) {
const { logs } = await colonyNetwork.createColony(tokenAddress, 0, "", "");
exports.setupColony = async function setupColony(colonyNetwork, tokenAddress, version = 0) {
if (version > 0) {
const resolverAddress = await colonyNetwork.getColonyVersionResolver(version);
if (resolverAddress === ADDRESS_ZERO) {
throw new Error(`No resolver found for version ${version}. Do you need to use deployOldColonyVersion in your test?`);
}
}
const { logs } = await colonyNetwork.createColony(tokenAddress, version, "", "");
kronosapiens marked this conversation as resolved.
Show resolved Hide resolved
const { colonyAddress } = logs.filter((x) => x.event === "ColonyAdded")[0].args;
const colony = await IColony.at(colonyAddress);
return colony;
Expand Down
Loading