|
| 1 | +// Jest Snapshot v1, https://goo.gl/fbAQLP |
| 2 | + |
| 3 | +exports[`Proxy.sol 1`] = ` |
| 4 | +pragma solidity ^0.4.24; |
| 5 | +
|
| 6 | +/** |
| 7 | + * @title Proxy |
| 8 | + * @dev Gives the possibility to delegate any call to a foreign implementation. |
| 9 | + */ |
| 10 | +contract Proxy { |
| 11 | +
|
| 12 | + /** |
| 13 | + * @dev Tells the address of the implementation where every call will be delegated. |
| 14 | + * @return address of the implementation to which it will be delegated |
| 15 | + */ |
| 16 | + function _implementation() internal view returns (address); |
| 17 | +
|
| 18 | + /** |
| 19 | + * @dev Fallback function. |
| 20 | + * Implemented entirely in \`_fallback\`. |
| 21 | + */ |
| 22 | + function _fallback() internal { |
| 23 | + _delegate(_implementation()); |
| 24 | + } |
| 25 | +
|
| 26 | + /** |
| 27 | + * @dev Fallback function allowing to perform a delegatecall to the given implementation. |
| 28 | + * This function will return whatever the implementation call returns |
| 29 | + */ |
| 30 | + function _delegate(address implementation) internal { |
| 31 | + /*solium-disable-next-line security/no-inline-assembly*/ |
| 32 | + assembly { |
| 33 | + // Copy msg.data. We take full control of memory in this inline assembly |
| 34 | + // block because it will not return to Solidity code. We overwrite the |
| 35 | + // Solidity scratch pad at memory position 0. |
| 36 | + calldatacopy(0, 0, calldatasize) |
| 37 | +
|
| 38 | + // Call the implementation. |
| 39 | + // out and outsize are 0 because we don't know the size yet. |
| 40 | + let result := delegatecall(gas, implementation, 0, calldatasize, 0, 0) |
| 41 | +
|
| 42 | + // Copy the returned data. |
| 43 | + returndatacopy(0, 0, returndatasize) |
| 44 | +
|
| 45 | + switch result |
| 46 | + // delegatecall returns 0 on error. |
| 47 | + case 0 { revert(0, returndatasize) } |
| 48 | + default { return(0, returndatasize) } |
| 49 | + } |
| 50 | + } |
| 51 | +
|
| 52 | + function () public payable { |
| 53 | + _fallback(); |
| 54 | + } |
| 55 | +} |
| 56 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 57 | +pragma solidity ^0.4.24; |
| 58 | +
|
| 59 | +/** |
| 60 | + * @title Proxy |
| 61 | + * @dev Gives the possibility to delegate any call to a foreign implementation. |
| 62 | + */ |
| 63 | +contract Proxy { |
| 64 | + /** |
| 65 | + * @dev Tells the address of the implementation where every call will be delegated. |
| 66 | + * @return address of the implementation to which it will be delegated |
| 67 | + */ |
| 68 | + function _implementation() internal view returns (address); |
| 69 | +
|
| 70 | + /** |
| 71 | + * @dev Fallback function. |
| 72 | + * Implemented entirely in \`_fallback\`. |
| 73 | + */ |
| 74 | + function _fallback() internal { |
| 75 | + _delegate(_implementation()); |
| 76 | + } |
| 77 | +
|
| 78 | + /** |
| 79 | + * @dev Fallback function allowing to perform a delegatecall to the given implementation. |
| 80 | + * This function will return whatever the implementation call returns |
| 81 | + */ |
| 82 | + function _delegate(address implementation) internal { |
| 83 | + /*solium-disable-next-line security/no-inline-assembly*/ |
| 84 | + assembly { |
| 85 | + // Copy msg.data. We take full control of memory in this inline assembly |
| 86 | + // block because it will not return to Solidity code. We overwrite the |
| 87 | + // Solidity scratch pad at memory position 0. |
| 88 | + calldatacopy(0, 0, calldatasize) |
| 89 | + // Call the implementation. |
| 90 | + // out and outsize are 0 because we don't know the size yet. |
| 91 | + let result := delegatecall(gas, implementation, 0, calldatasize, 0, 0) |
| 92 | + // Copy the returned data. |
| 93 | + returndatacopy(0, 0, returndatasize) |
| 94 | + switch result |
| 95 | + // delegatecall returns 0 on error. |
| 96 | + case 0 { |
| 97 | + revert(0, returndatasize) |
| 98 | + } |
| 99 | + default { |
| 100 | + return(0, returndatasize) |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | +
|
| 105 | + function() public payable { |
| 106 | + _fallback(); |
| 107 | + } |
| 108 | +} |
| 109 | +
|
| 110 | +`; |
0 commit comments