Skip to content

Commit

Permalink
[H-3] BatchMetadata modules may apply baseURI to incorrect token ids
Browse files Browse the repository at this point in the history
  • Loading branch information
GWSzeto committed Sep 28, 2024
1 parent a58c573 commit 6edc471
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/module/token/metadata/BatchMetadataERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ contract BatchMetadataERC1155 is BatchMetadataERC721, UpdateMetadataCallbackERC1
if (_startTokenId < _batchMetadataStorage().nextTokenIdRangeStart) {
revert BatchMetadataMetadataAlreadySet();
}
_setMetadata(_quantity, _baseURI);
_setMetadata(_startTokenId, _quantity, _baseURI);
}

}
11 changes: 5 additions & 6 deletions src/module/token/metadata/BatchMetadataERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ contract BatchMetadataERC721 is Module, UpdateMetadataCallbackERC721 {
if (_startTokenId < _batchMetadataStorage().nextTokenIdRangeStart) {
revert BatchMetadataMetadataAlreadySet();
}
_setMetadata(_quantity, _baseURI);
_setMetadata(_startTokenId, _quantity, _baseURI);
}

/*//////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -150,7 +150,7 @@ contract BatchMetadataERC721 is Module, UpdateMetadataCallbackERC721 {

/// @notice Uploads metadata for a range of tokenIds.
function uploadMetadata(uint256 _amount, string calldata _baseURI) external virtual {
_setMetadata(_amount, _baseURI);
_setMetadata(_batchMetadataStorage().nextTokenIdRangeStart, _amount, _baseURI);
}

function nextTokenIdToMint() external view returns (uint256) {
Expand Down Expand Up @@ -219,19 +219,18 @@ contract BatchMetadataERC721 is Module, UpdateMetadataCallbackERC721 {
}

/// @notice sets the metadata for a range of tokenIds.
function _setMetadata(uint256 _amount, string calldata _baseURI) internal virtual {
function _setMetadata(uint256 _rangeStart, uint256 _amount, string calldata _baseURI) internal virtual {
if (_amount == 0) {
revert BatchMetadataZeroAmount();
}

uint256 rangeStart = _batchMetadataStorage().nextTokenIdRangeStart;
uint256 rangeEndNonInclusive = rangeStart + _amount;
uint256 rangeEndNonInclusive = _rangeStart + _amount;

_batchMetadataStorage().nextTokenIdRangeStart = rangeEndNonInclusive;
_batchMetadataStorage().tokenIdRangeEnd.push(rangeEndNonInclusive);
_batchMetadataStorage().baseURIOfTokenIdRange[rangeEndNonInclusive] = _baseURI;

emit BatchMetadataUpdate(rangeStart, rangeEndNonInclusive - 1);
emit BatchMetadataUpdate(_rangeStart, rangeEndNonInclusive - 1);
}

function _batchMetadataStorage() internal pure returns (BatchMetadataStorage.Data storage) {
Expand Down

0 comments on commit 6edc471

Please sign in to comment.