-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathstep6.sol
48 lines (40 loc) · 1.16 KB
/
step6.sol
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
pragma solidity ^0.5.1;
contract StorageContract {
uint counter;
}
contract ProxyContract is StorageContract {
address internal proxied;
function setLogicContractAddress (address newAddress) public
{
proxied = newAddress;
}
constructor(address _proxied) public {
proxied = _proxied;
}
/**
* Fallback function allowing to perform a delegatecall
* to the given implementation. This function will return
* whatever the implementation call returns
*/
function () external payable {
address addr = proxied;
assembly {
let freememstart := mload(0x40)
calldatacopy(freememstart, 0, calldatasize())
let success := delegatecall(not(0), addr, freememstart, calldatasize(), freememstart, 32)
switch success
case 0 { revert(freememstart, 32) }
default { return(freememstart, 32) }
}
}
}
contract LogicContract is StorageContract {
function getcounter () public view returns (uint)
{
return counter;
}
function incrementcounter () public
{
counter++;
}
}