hashgraph / hashgraph/hedera-forking

[Bug] mintToken incorrectly rejects NFT minting when amount=0

Open
#308 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Solidity
Stars
3
Forks
4
PR merge metrics
No merged PRs in 30d

Description

## Description

The `mintToken` function in `HtsSystemContract.sol` incorrectly rejects NFT minting because it requires `amount > 0`. However, per HTS specification, NFT minting should use `amount = 0` with the `metadata` array determining how many NFTs to mint.

## Current Behavior

In [`contracts/HtsSystemContract.sol` line 105](https://github.com/hashgraph/hedera-forking/blob/main/contracts/HtsSystemContract.sol#L105):

```solidity
function _mintToken(address token, int64 amount, bool checkSupplyKey) private returns (
int64 responseCode,
int64 newTotalSupply,
int64[] memory serialNumbers
) {
require(token != address(0), "mintToken: invalid token");
require(amount > 0, "mintToken: invalid amount"); // <-- Bug: rejects NFT minting
// ...
}
```

When calling mintToken for an NFT with amount = 0 and a non-empty metadata array, the transaction reverts with:
```Error: VM Exception while processing transaction: reverted with reason string 'mintToken: invalid amount```

## Suggested Fix

```
function _mintToken(address token, int64 amount, bytes[] memory metadata, bool checkSupplyKey) private returns (
int64 responseCode,
int64 newTotalSupply,
int64[] memory serialNumbers
) {
require(token != address(0), "mintToken: invalid token");

(int64 tokenInfoResponseCode, TokenInfo memory tokenInfo) = IHederaTokenService(token).getTokenInfo(token);
require(tokenInfoResponseCode == HederaResponseCodes.SUCCESS, "mintToken: failed to get token info");

// Check if NFT (tokenType == 1) or Fungible (tokenType == 0)
bool isNFT = tokenInfo.token.tokenType == 1;

if (isNFT) {
require(amount == 0, "mintToken: amount must be 0 for NFT");
require(metadata.length > 0, "mintToken: metadata required for NFT minting");

// Mint NFTs based on metadata array
serialNumbers = new int64[](metadata.length);
for (uint256 i = 0; i < metadata.length; i++) {
// Assign serial numbers and update ownership
serialNumbers[i] = _nextSerial++;
}
newTotalSupply = int64(uint64(IERC721(token).totalSupply()));
} else {
require(amount > 0, "mintToken: invalid amount for fungible token");
// Existing fungible minting logic...
serialNumbers = new int64[](0);
}

responseCode = HederaResponseCodes.SUCCESS;
}
```

Environment
@hashgraph/system-contracts-forking: v0.1.2
Hardhat: 2.22.19
Solidity: 0.8.28

### Steps to reproduce

```
// Create NFT collection
(int64 code, address nftToken) = IHederaTokenService(0x167).createNonFungibleToken(token);

// Try to mint - FAILS with "invalid amount"
bytes[] memory metadata = new bytes[](1);
metadata[0] = bytes("NFT metadata");
IHederaTokenService(0x167).mintToken(nftToken, 0, metadata);
```

### Additional context

The metadata parameter is already accepted by the function but completely ignored:

```
function mintToken(address token, int64 amount, bytes[] memory) htsCall external override returns (...)
```

Note the unnamed bytes[] memory parameter - it's never used in the implementation.

### Hedera network

other

### Version

v0.1.2

### Operating system

None

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.