@@ -18,68 +18,71 @@ pragma solidity ^0.8.0;
1818 * returned by the abstract _implementation() internal function.
1919 */
2020abstract contract Proxy {
21- /**
22- * @dev Receive function.
23- * Implemented entirely in `_fallback`.
24- */
25- receive () external payable virtual {
26- _fallback ();
27- }
21+ /**
22+ * @dev Receive function.
23+ * Implemented entirely in `_fallback`.
24+ */
25+ receive () external payable virtual {
26+ _fallback ();
27+ }
2828
29- /**
30- * @dev Fallback function.
31- * Implemented entirely in `_fallback`.
32- */
33- fallback () external payable {
34- _fallback ();
35- }
29+ /**
30+ * @dev Fallback function.
31+ * Implemented entirely in `_fallback`.
32+ */
33+ fallback () external payable {
34+ _fallback ();
35+ }
3636
37- /**
38- * @return impl The Address of the implementation.
39- */
40- function _implementation () internal virtual view returns (address impl );
37+ /**
38+ * @return impl The Address of the implementation.
39+ */
40+ function _implementation () internal view virtual returns (address impl );
4141
42- /**
43- * @dev Delegates execution to an implementation contract.
44- * This is a low level function that doesn't return to its internal call site.
45- * It will return to the external caller whatever the implementation returns.
46- * @param implementation Address to delegate.
47- */
48- function _delegate (address implementation ) internal {
49- assembly {
50- // Copy msg.data. We take full control of memory in this inline assembly
51- // block because it will not return to Solidity code. We overwrite the
52- // Solidity scratch pad at memory position 0.
53- calldatacopy (0 , 0 , calldatasize ())
42+ /**
43+ * @dev Delegates execution to an implementation contract.
44+ * This is a low level function that doesn't return to its internal call site.
45+ * It will return to the external caller whatever the implementation returns.
46+ * @param implementation Address to delegate.
47+ */
48+ function _delegate (address implementation ) internal {
49+ assembly {
50+ // Copy msg.data. We take full control of memory in this inline assembly
51+ // block because it will not return to Solidity code. We overwrite the
52+ // Solidity scratch pad at memory position 0.
53+ calldatacopy (0 , 0 , calldatasize ())
5454
55- // Call the implementation.
56- // out and outsize are 0 because we don't know the size yet.
57- let result := delegatecall (gas (), implementation, 0 , calldatasize (), 0 , 0 )
55+ // Call the implementation.
56+ // out and outsize are 0 because we don't know the size yet.
57+ let result := delegatecall (gas (), implementation, 0 , calldatasize (), 0 , 0 )
5858
59- // Copy the returned data.
60- returndatacopy (0 , 0 , returndatasize ())
59+ // Copy the returned data.
60+ returndatacopy (0 , 0 , returndatasize ())
6161
62- switch result
63- // delegatecall returns 0 on error.
64- case 0 { revert (0 , returndatasize ()) }
65- default { return (0 , returndatasize ()) }
62+ switch result
63+ // delegatecall returns 0 on error.
64+ case 0 {
65+ revert (0 , returndatasize ())
66+ }
67+ default {
68+ return (0 , returndatasize ())
69+ }
70+ }
6671 }
67- }
6872
69- /**
70- * @dev Function that is run as the first thing in the fallback function.
71- * Can be redefined in derived contracts to add functionality.
72- * Redefinitions must call super._willFallback().
73- */
74- function _willFallback () internal virtual {
75- }
73+ /**
74+ * @dev Function that is run as the first thing in the fallback function.
75+ * Can be redefined in derived contracts to add functionality.
76+ * Redefinitions must call super._willFallback().
77+ */
78+ function _willFallback () internal virtual {}
7679
77- /**
78- * @dev fallback implementation.
79- * Extracted to enable manual triggering.
80- */
81- function _fallback () internal {
82- _willFallback ();
83- _delegate (_implementation ());
84- }
80+ /**
81+ * @dev fallback implementation.
82+ * Extracted to enable manual triggering.
83+ */
84+ function _fallback () internal {
85+ _willFallback ();
86+ _delegate (_implementation ());
87+ }
8588}
0 commit comments