OpenZeppelin / OpenZeppelin/openzeppelin-contracts

Should bytes calldata be replaced with bytes memory in IERC721 to prevent compilation errors?

Open
#5,201 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Solidity
Stars
27.2k
Forks
12.4k
Avg merge
2d 19h
Merged PRs (30d)
33

Description

Summary

When working with the safeTransferFrom function in the IERC721 interface, there are instances where the use of bytes calldata leads to compilation errors, especially when trying to pass empty values (e.g., safeTransferFrom(from, to, tokenId, "")). In contrast, using bytes memory resolves the issue and prevents such errors from occurring.

Detailed Description

Currently, the safeTransferFrom function in IERC721 defines the data parameter as bytes calldata, which causes issues when trying to pass empty byte arrays or when making certain calls within the implementation. In practice, this often leads to Solidity compilation errors when empty values are used, such as "", since it can't implicitly convert between string literals and bytes calldata.

Switching the argument type from calldata to memory in the IERC721 interface and its associated functions resolves the issue without causing any functional or performance drawbacks. Additionally, it aligns with the practical usage patterns seen in many ERC-721 implementations, where memory is already frequently used.

Question

Is it possible or appropriate to update the IERC721 interface to use bytes memory instead of bytes calldata for the data parameter in safeTransferFrom?

Expected Behavior
  • The IERC721 interface would be updated to use bytes memory in the safeTransferFrom function to prevent compilation errors when passing empty values or making internal calls.
Context

This issue primarily affects developers who encounter errors when trying to pass empty byte arrays in contracts implementing the ERC-721 standard. Changing to bytes memory resolves these errors and allows for smoother development, especially in cases where safeTransferFrom is called without data.

Before and After Example

Before:

function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;

After:

function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) external;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the IERC721 safeTransferFrom declarations and the associated implementations that use the data parameter. Reproduce the reported compilation error with an empty value such as "", then compare compilation and relevant interface compatibility after changing the data location. Done means the empty-value call compiles without breaking ERC-721 implementations or interface behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
solidity
Domain
blockchain
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.