Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Reduce asm in Proxy.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
k06a committed Feb 29, 2020
1 parent abe30da commit 2a9a5b1
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions packages/lib/contracts/upgradeability/Proxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,10 @@ contract Proxy {
* @param implementation Address to delegate.
*/
function _delegate(address implementation) internal {
(bool success, bytes memory data) = implementation.delegatecall(msg.data);
require(success, string(data));
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize)

// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas, implementation, 0, calldatasize, 0, 0)

// Copy the returned data.
returndatacopy(0, 0, returndatasize)

switch result
// delegatecall returns 0 on error.
case 0 { revert(0, returndatasize) }
default { return(0, returndatasize) }
return(add(data, 32), returndatasize)
}
}

Expand Down

0 comments on commit 2a9a5b1

Please sign in to comment.