@filip I see that the upgrade function is callable by anybody. Why not make this function onlyOwner? because this could be potentially very dangerous. I would make the proxy.sol look like this:
pragma solidity 0.5.12;
import "./Storage.sol";
contract Proxy is Storage {
address currentAddress;
constructor(address _currentAddress) public {
currentAddress = _currentAddress;
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender == owner);
_;
}
// upgrade address of the functionality contract
function upgrade(address _newAddress) public onlyOwner {
currentAddress = _newAddress;
}
// Fallback function that is used to proxy to our functionality contract
function () payable external {
//REDIRECT to currentAddress
address implementation = currentAddress;
require(currentAddress != address(0));
bytes memory data = msg.data;
// Delegatecall every function call to the underlying functional contract
// making this contract a proxy contract
assembly {
let result := delegatecall(gas, implementation, add(data, 0x20), mload(data), 0, 0)
let size := returndatasize
let ptr := mload(0x40)
returndatacopy(ptr, 0, size)
switch result
case 0 {revert(ptr, size)}
default {return(ptr, size)}
}
}
}