-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathYulProxy.sol
More file actions
53 lines (50 loc) · 1.66 KB
/
YulProxy.sol
File metadata and controls
53 lines (50 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @notice A proxy contract that forwards calls to an implementation contract
* @dev This proxy uses the EIP-1967 standard for storage slots
*/
contract YulProxy {
/**
* @notice Storage slot with the address of the current implementation
* @dev This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1
*/
bytes32 private constant _IMPLEMENTATION_SLOT =
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @notice Initializes the proxy with the address of the initial implementation contract
* @param logic Address of the initial implementation
*/
constructor(address logic) {
assembly ("memory-safe") {
sstore(_IMPLEMENTATION_SLOT, logic)
}
}
/**
* @notice Fallback function which forwards all calls to the implementation contract
* @dev Uses delegatecall to ensure the context remains within the proxy
*/
fallback() external payable {
assembly {
/* not memory-safe */
calldatacopy(0, 0, calldatasize())
let _singleton := and(
sload(_IMPLEMENTATION_SLOT),
0xffffffffffffffffffffffffffffffffffffffff
)
let success := delegatecall(
gas(),
_singleton,
0,
calldatasize(),
0,
0
)
returndatacopy(0, 0, returndatasize())
if iszero(success) {
revert(0, returndatasize())
}
return(0, returndatasize())
}
}
}