Skip to content

Commit fde4131

Browse files
committed
Fix operator contract upgrader logic
Make sure each service contract has its own operator contract upgrader.
1 parent 74fd0ea commit fde4131

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

contracts/solidity/contracts/KeepRandomBeaconServiceImplV1.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ contract KeepRandomBeaconServiceImplV1 is DelayedWithdrawal, ReentrancyGuard {
9595
hex"15c30f4b6cf6dbbcbdcc10fe22f54c8170aea44e198139b776d512d8f027319a1b9e8bfaf1383978231ce98e42bafc8129f473fc993cf60ce327f7d223460663";
9696

9797
/**
98-
* @dev Throws if called by any account other than the operator contract upgrader.
98+
* @dev Throws if called by any account other than the operator contract upgrader authorized for this service contract.
9999
*/
100100
modifier onlyOperatorContractUpgrader() {
101-
address operatorContractUpgrader = Registry(_registry).operatorContractUpgrader();
101+
address operatorContractUpgrader = Registry(_registry).operatorContractUpgraderFor(address(this));
102102
require(operatorContractUpgrader == msg.sender, "Caller is not operator contract upgrader");
103103
_;
104104
}

contracts/solidity/contracts/Registry.sol

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ contract Registry {
1818
// that have been previously approved by the Registry Keeper.
1919
address internal panicButton;
2020

21-
// Operator Contract Upgrader can add approved operator contracts to
22-
// the service contract and deprecate old ones.
23-
address public operatorContractUpgrader;
21+
// Each service contract has a Operator Contract Upgrader whose purpose
22+
// is to manage operator contracts for that specific service contract.
23+
// The Operator Contract Upgrader can add new operator contracts to the
24+
// service contract’s operator contract list, and deprecate old ones.
25+
mapping(address => address) public operatorContractUpgraders;
2426

2527
// The registry of operator contracts
2628
// 0 - NULL (default), 1 - APPROVED, 2 - DISABLED
@@ -45,7 +47,6 @@ contract Registry {
4547
governance = msg.sender;
4648
registryKeeper = msg.sender;
4749
panicButton = msg.sender;
48-
operatorContractUpgrader = msg.sender;
4950
}
5051

5152
function setGovernance(address _governance) public onlyGovernance {
@@ -60,8 +61,8 @@ contract Registry {
6061
panicButton = _panicButton;
6162
}
6263

63-
function setOperatorContractUpgrader(address _operatorContractUpgrader) public onlyGovernance {
64-
operatorContractUpgrader = _operatorContractUpgrader;
64+
function setOperatorContractUpgrader(address _serviceContract, address _operatorContractUpgrader) public onlyGovernance {
65+
operatorContractUpgraders[_serviceContract] = _operatorContractUpgrader;
6566
}
6667

6768
function approveOperatorContract(address operatorContract) public onlyRegistryKeeper {
@@ -75,4 +76,8 @@ contract Registry {
7576
function isApprovedOperatorContract(address operatorContract) public view returns (bool) {
7677
return operatorContracts[operatorContract] == 1;
7778
}
79+
80+
function operatorContractUpgraderFor(address _serviceContract) public view returns (address) {
81+
return operatorContractUpgraders[_serviceContract];
82+
}
7883
}

contracts/solidity/migrations/3_initialize.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ module.exports = async function(deployer, network) {
2828

2929
await keepRandomBeaconOperator.setPriceFeedEstimate(priceFeedEstimate);
3030
await registry.approveOperatorContract(keepRandomBeaconOperator.address);
31+
32+
// Set service contract owner as operator contract upgrader by default
33+
const operatorContractUpgrader = await keepRandomBeaconService.owner();
34+
await registry.setOperatorContractUpgrader(keepRandomBeaconService.address, operatorContractUpgrader);
3135
keepRandomBeaconService.addOperatorContract(
32-
keepRandomBeaconOperator.address
36+
keepRandomBeaconOperator.address,
37+
{from: operatorContractUpgrader}
3338
);
3439
};

contracts/solidity/test/TestKeepContractsAuthorization.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ contract('Registry', function(accounts) {
3131

3232
await registry.setRegistryKeeper(registryKeeper)
3333
await registry.setPanicButton(panicButton)
34-
await registry.setOperatorContractUpgrader(operatorContractUpgrader)
34+
await registry.setOperatorContractUpgrader(serviceContract.address, operatorContractUpgrader)
3535
})
3636

3737
beforeEach(async () => {

contracts/solidity/test/helpers/initContracts.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ async function initContracts(KeepToken, TokenStaking, KeepRandomBeaconService,
4848

4949
await registry.approveOperatorContract(operatorContract.address);
5050
await serviceContract.initialize(priceFeedEstimate, fluctuationMargin, dkgContributionMargin, withdrawalDelay, registry.address);
51+
52+
// Set service contract owner as operator contract upgrader by default
53+
const operatorContractUpgrader = await serviceContract.owner()
54+
await registry.setOperatorContractUpgrader(serviceContract.address, operatorContractUpgrader);
55+
5156
await serviceContract.addOperatorContract(operatorContract.address);
5257

5358
let dkgGasEstimate = await operatorContract.dkgGasEstimate();

0 commit comments

Comments
 (0)