-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathW10day4.sol
More file actions
63 lines (48 loc) · 1.49 KB
/
W10day4.sol
File metadata and controls
63 lines (48 loc) · 1.49 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
54
55
56
57
58
59
60
61
62
63
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
// ================= IMPLEMENTATION =================
contract LogicV1 {
uint public value;
address public owner;
function initialize(uint _value) public {
require(owner == address(0), "Already initialized");
value = _value;
owner = msg.sender;
}
function setValue(uint _value) public {
require(msg.sender == owner, "Not owner");
value = _value;
}
}
// ================= PROXY =================
contract SimpleProxy {
uint public value;
address public owner;
address public implementation;
constructor(address _implementation, bytes memory data) {
implementation = _implementation;
if(data.length > 0){
(bool success,) = _implementation.delegatecall(data);
require(success, "Init failed");
}
}
receive() external payable { }
fallback() external payable {
address impl = implementation;
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(
gas(),
impl,
0,
calldatasize(),
0,
0
)
returndatacopy(0, 0, returndatasize())
switch result
case 0 { revert(0, returndatasize()) }
default { return(0, returndatasize()) }
}
}
}