From 2a9a5b11b3684718657b7ab31bdb6808a495918a Mon Sep 17 00:00:00 2001 From: Anton Bukov Date: Sat, 29 Feb 2020 23:08:51 +0300 Subject: [PATCH] Reduce asm in Proxy.sol --- .../lib/contracts/upgradeability/Proxy.sol | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/packages/lib/contracts/upgradeability/Proxy.sol b/packages/lib/contracts/upgradeability/Proxy.sol index 350de19e6..53c6b5813 100644 --- a/packages/lib/contracts/upgradeability/Proxy.sol +++ b/packages/lib/contracts/upgradeability/Proxy.sol @@ -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) } }