Skip to content

Commit 720ed7d

Browse files
authored
[fix] reentrancy attack on 721 (#146)
1 parent 9844c47 commit 720ed7d

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

contracts/token/erc721/abstract/ERC721Hybrid.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,9 @@ abstract contract ERC721Hybrid is ERC721PsiBurnable, ERC721, IImmutableERC721Err
262262
if (_burnedTokens.get(tokenId)) {
263263
revert IImmutableERC721TokenAlreadyBurned(tokenId);
264264
}
265-
ERC721._mint(to, tokenId);
265+
266266
_idMintTotalSupply++;
267+
ERC721._mint(to, tokenId);
267268
}
268269

269270
/** @notice safe mints number of tokens specified to a multiple specified addresses via erc721
@@ -278,8 +279,9 @@ abstract contract ERC721Hybrid is ERC721PsiBurnable, ERC721, IImmutableERC721Err
278279
if (_burnedTokens.get(tokenId)) {
279280
revert IImmutableERC721TokenAlreadyBurned(tokenId);
280281
}
281-
ERC721._safeMint(to, tokenId);
282+
282283
_idMintTotalSupply++;
284+
ERC721._safeMint(to, tokenId);
283285
}
284286

285287
/** @notice mints multiple tokens by id to a specified address via erc721

contracts/token/erc721/abstract/ImmutableERC721Base.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,12 @@ abstract contract ImmutableERC721Base is
240240
if (mintRequest.to == address(0)) {
241241
revert IImmutableERC721SendingToZerothAddress();
242242
}
243+
244+
_totalSupply = _totalSupply + mintRequest.tokenIds.length;
243245
for (uint256 j = 0; j < mintRequest.tokenIds.length; j++) {
244246
_mint(mintRequest.to, mintRequest.tokenIds[j]);
245247
}
246-
_totalSupply = _totalSupply + mintRequest.tokenIds.length;
248+
247249
}
248250

249251
/** @notice safe mints a batch of tokens with specified ids to a specified address

contracts/token/erc721/preset/ImmutableERC721MintByID.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ contract ImmutableERC721MintByID is ImmutableERC721Base {
3838
* @param tokenID the ID of the token to mint
3939
*/
4040
function safeMint(address to, uint256 tokenID) external onlyRole(MINTER_ROLE) {
41-
_safeMint(to, tokenID, "");
4241
_totalSupply++;
42+
_safeMint(to, tokenID, "");
4343
}
4444

4545
/** @notice Allows minter to safe mint `tokenID` to `to`
4646
* @param to the address to mint the token to
4747
* @param tokenID the ID of the token to mint
4848
*/
4949
function mint(address to, uint256 tokenID) external onlyRole(MINTER_ROLE) {
50-
_mint(to, tokenID);
5150
_totalSupply++;
51+
_mint(to, tokenID);
5252
}
5353

5454
/**

0 commit comments

Comments
 (0)