-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDelegate.sol
35 lines (26 loc) · 858 Bytes
/
Delegate.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
pragma solidity ^0.6.0;
contract Delegate {
address public owner;
constructor(address _owner) public {
owner = _owner;
}
function pwn() public {
owner = msg.sender;
}
}
contract Delegation {
address public owner;
Delegate delegate;
constructor(address _delegateAddress) public {
delegate = Delegate(_delegateAddress);
owner = msg.sender;
}
fallback() external { //oops, it has fallback function AND the delegatecall is inside the fallback :D
(bool result, bytes memory data) = address(delegate).delegatecall(msg.data); // what we need to do is just trigger this fallback and send the "pwn()" function to it.
if (result) {
this;
}
}
}
// we can use metamask to trigger the fallback function and send the data.
// if you don't see the data feature, you need to go to the setting and enable it