Skip to content

Adding onlyOwner to it

Currently, anyone can update the implementation of the contract. Lets change that so only owners can change the implementation

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "@openzeppelin/contracts/access/Ownable.sol";
contract StorageProxy is Ownable {
uint public num;
address implementation;
constructor(address _implementation) Ownable(msg.sender) {
num = 0;
implementation = _implementation;
}
function setNum(uint _num) public {
(bool success, ) = implementation.delegatecall(
abi.encodeWithSignature("setNum(uint256)", _num)
);
require(success, "Error while delegating call");
}
function setImplementation(address _implementation) public onlyOwner {
implementation = _implementation;
}
}

Try to test this, and you will notice that the variables dont update as expected.