Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #315 from maticnetwork/mat-1927
Browse files Browse the repository at this point in the history
overriden owner in upgradable proxy (mat-1980)
  • Loading branch information
jdkanani authored Nov 23, 2020
2 parents beba192 + 8e1096c commit 45aa3a6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions contracts/common/misc/UpgradableProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {DelegateProxy} from "./DelegateProxy.sol";

contract UpgradableProxy is DelegateProxy {
event ProxyUpdated(address indexed _new, address indexed _old);
event OwnerUpdate(address _new, address _old);
event ProxyOwnerUpdate(address _new, address _old);

bytes32 constant IMPLEMENTATION_SLOT = keccak256("matic.network.proxy.implementation");
bytes32 constant OWNER_SLOT = keccak256("matic.network.proxy.owner");

constructor(address _proxyTo) public {
setOwner(msg.sender);
setProxyOwner(msg.sender);
setImplementation(_proxyTo);
}

Expand All @@ -21,15 +21,15 @@ contract UpgradableProxy is DelegateProxy {
}

modifier onlyProxyOwner() {
require(loadOwner() == msg.sender, "NOT_OWNER");
require(loadProxyOwner() == msg.sender, "NOT_OWNER");
_;
}

function owner() external view returns(address) {
return loadOwner();
function proxyOwner() external view returns(address) {
return loadProxyOwner();
}

function loadOwner() internal view returns(address) {
function loadProxyOwner() internal view returns(address) {
address _owner;
bytes32 position = OWNER_SLOT;
assembly {
Expand All @@ -51,13 +51,13 @@ contract UpgradableProxy is DelegateProxy {
return _impl;
}

function transferOwnership(address newOwner) public onlyProxyOwner {
function transferProxyOwnership(address newOwner) public onlyProxyOwner {
require(newOwner != address(0), "ZERO_ADDRESS");
emit OwnerUpdate(newOwner, loadOwner());
setOwner(newOwner);
emit ProxyOwnerUpdate(newOwner, loadProxyOwner());
setProxyOwner(newOwner);
}

function setOwner(address newOwner) private {
function setProxyOwner(address newOwner) private {
bytes32 position = OWNER_SLOT;
assembly {
sstore(position, newOwner)
Expand Down
2 changes: 1 addition & 1 deletion contracts/staking/validatorShare/ValidatorShareFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract ValidatorShareFactory {
function create(uint256 validatorId, address loggerAddress, address registry) public returns (address) {
ValidatorShareProxy proxy = new ValidatorShareProxy(registry);

proxy.transferOwnership(msg.sender);
proxy.transferProxyOwnership(msg.sender);

address proxyAddr = address(proxy);
(bool success, bytes memory data) = proxyAddr.call.gas(gasleft())(
Expand Down
8 changes: 4 additions & 4 deletions test/units/UpgradableProxy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,25 @@ contract('UpgradableProxy', function() {
})
})

describe('transferOwnership', function() {
describe('transferProxyOwnership', function() {
before(doDeploy)
before(async function() {
this.newOwner = wallets[1].getChecksumAddressString()
})

describe('when from is not owner', function() {
it('reverts', async function() {
await expectRevert(this.proxy.transferOwnership(this.newOwner, { from: this.newOwner }), 'NOT_OWNER')
await expectRevert(this.proxy.transferProxyOwnership(this.newOwner, { from: this.newOwner }), 'NOT_OWNER')
})
})

describe('when from is owner', function() {
it('must update owner', async function() {
await this.proxy.transferOwnership(this.newOwner)
await this.proxy.transferProxyOwnership(this.newOwner)
})

it('must have correct owner', async function() {
const owner = await this.proxy.owner()
const owner = await this.proxy.proxyOwner()
owner.should.be.equal(this.newOwner)
})
})
Expand Down

0 comments on commit 45aa3a6

Please sign in to comment.