forked from minaminao/ctf-blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlienCodexFactory.sol
29 lines (24 loc) · 1008 Bytes
/
AlienCodexFactory.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "../Ethernaut/Level.sol";
import "forge-std/Script.sol";
import "forge-std/Vm.sol";
import "./AlienCodex-08.sol";
contract AlienCodexFactory is Level {
function createInstance(address _player) public payable override returns (address) {
_player;
address VM_ADDRESS = address(bytes20(uint160(uint256(keccak256("hevm cheat code")))));
Vm vm = Vm(VM_ADDRESS);
// https://book.getfoundry.sh/cheatcodes/get-code#examples
bytes memory bytecode = abi.encodePacked(vm.getCode("AlienCodex.sol:AlienCodex"));
address instanceAddress;
assembly {
instanceAddress := create(0, add(bytecode, 0x20), mload(bytecode))
}
return instanceAddress;
}
function validateInstance(address payable _instance, address _player) public view override returns (bool) {
AlienCodex instance = AlienCodex(_instance);
return instance.owner() == _player;
}
}