Skip to content

Commit

Permalink
Moved Upgradeable.sol into Proxy.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
Ihor Barenblat committed Mar 22, 2020
1 parent c865649 commit 0d00799
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 65 deletions.
53 changes: 49 additions & 4 deletions contracts/contracts/Proxy.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,62 @@
pragma solidity 0.5.16;

import "./Upgradeable.sol";
import "./Ownable.sol";


/// @title Proxy Contract
/// @author Matter Labs
contract Proxy is Upgradeable {
contract Proxy is Ownable {

/// @notice Storage position of "target" (actual implementation address)
bytes32 private constant targetPosition = keccak256("target");

/// @notice Contract constructor
/// @dev Calls Upgradeable contract constructor
/// @dev Calls Ownable contract constructor and initialize target
/// @param target Initial implementation address
/// @param targetInitializationParameters Target initialization parameters
constructor(address target, bytes memory targetInitializationParameters) Upgradeable(target, targetInitializationParameters) public {}
constructor(address target, bytes memory targetInitializationParameters) Ownable(msg.sender) public {
setTarget(target);
(bool initializationSuccess, ) = getTarget().delegatecall(
abi.encodeWithSignature("initialize(bytes)", targetInitializationParameters)
);
require(initializationSuccess, "uin11"); // uin11 - target initialization failed
}

/// @notice Intercepts initialization calls
function initialize(bytes calldata) external pure {
revert("ini11"); // ini11 - interception of initialization call
}

/// @notice Returns target of contract
/// @return Actual implementation address
function getTarget() public view returns (address target) {
bytes32 position = targetPosition;
assembly {
target := sload(position)
}
}

/// @notice Sets new target of contract
/// @param _newTarget New actual implementation address
function setTarget(address _newTarget) internal {
bytes32 position = targetPosition;
assembly {
sstore(position, _newTarget)
}
}

/// @notice Upgrades target
/// @param newTarget New target
/// @param newTargetInitializationParameters New target initialization parameters
function upgradeTarget(address newTarget, bytes calldata newTargetInitializationParameters) external {
requireMaster(msg.sender);

setTarget(newTarget);
(bool initializationSuccess, ) = getTarget().delegatecall(
abi.encodeWithSignature("initialize(bytes)", newTargetInitializationParameters)
);
require(initializationSuccess, "ufu11"); // ufu11 - target initialization failed
}

/// @notice Performs a delegatecall to the contract implementation
/// @dev Fallback function allowing to perform a delegatecall to the given implementation
Expand Down
61 changes: 0 additions & 61 deletions contracts/contracts/Upgradeable.sol

This file was deleted.

0 comments on commit 0d00799

Please sign in to comment.