Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions contracts/token/ERC1155/ERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,16 @@ abstract contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IER
return _operatorApprovals[account][operator];
}

/// @inheritdoc IERC1155
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) public virtual {
function _checkAuthorized(address from) internal view {
address sender = _msgSender();
if (from != sender && !isApprovedForAll(from, sender)) {
revert ERC1155MissingApprovalForAll(sender, from);
}
}
Comment on lines +98 to +103
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Consider making the function virtual and add NatSpec documentation.

The refactoring successfully consolidates the authorization logic. However, consider two improvements:

  1. Add the virtual modifier: OpenZeppelin contracts are designed for inheritance, and marking internal helper functions as virtual allows derived contracts to customize authorization behavior if needed.

  2. Add NatSpec documentation: OpenZeppelin maintains comprehensive documentation standards. Consider adding a docstring like:

/**
 * @dev Checks whether `_msgSender()` is authorized to transfer tokens from `from`.
 * 
 * Requirements:
 * 
 * - `_msgSender()` must be either `from` or approved for all transfers from `from`.
 */

Apply this diff to add the virtual modifier:

-    function _checkAuthorized(address from) internal view {
+    function _checkAuthorized(address from) internal view virtual {
         address sender = _msgSender();
         if (from != sender && !isApprovedForAll(from, sender)) {
             revert ERC1155MissingApprovalForAll(sender, from);
         }
     }
🤖 Prompt for AI Agents
In contracts/token/ERC1155/ERC1155.sol around lines 98 to 103, the internal
helper _checkAuthorized lacks NatSpec and is not overridable; add a NatSpec
docblock describing that it checks whether _msgSender() is authorized to
transfer tokens from `from` and the requirement that sender must be `from` or
approved for all, then add the `virtual` modifier to the function signature so
derived contracts can override the authorization behavior.


/// @inheritdoc IERC1155
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) public virtual {
_checkAuthorized(from);
_safeTransferFrom(from, to, id, value, data);
}

Expand All @@ -112,13 +116,9 @@ abstract contract ERC1155 is Context, ERC165, IERC1155, IERC1155MetadataURI, IER
uint256[] memory values,
bytes memory data
) public virtual {
address sender = _msgSender();
if (from != sender && !isApprovedForAll(from, sender)) {
revert ERC1155MissingApprovalForAll(sender, from);
}
_checkAuthorized(from);
_safeBatchTransferFrom(from, to, ids, values, data);
}

/**
* @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`. Will mint (or burn) if `from`
* (or `to`) is the zero address.
Expand Down
Loading