Bug Bounty Report: natspec documents wrong onERC721Received magic value (0xf0b9e5ba vs implemented 0x150b7a02)

未关闭 适合新手
#299 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
82/100
Issue 类型
文档
描述清晰度
描述清楚
活跃度
活跃
技术栈
python

调研方向

错误的签名位于 src/contracts/tokens/erc721.sol(约第 49-50 行)和 src/contracts/tokens/nf-token.sol(约第 116-117 行)的 natspec 注释中。请将它们与 nf-token.sol 第 32-35 行的常量 MAGIC_ON_ERC721_RECEIVED 以及 src/contracts/token/erc721-token-receiver.sol 中的接收者接口进行比较。当两处注释都写明 onERC721Received(address,address,uint256,bytes),并与选择器 0x150b7a02 一致时即完成;你可以用 issue 中的 Python 代码片段确认该哈希。

由索引模型根据 Issue 内容生成。

描述

Found while reviewing src/contracts under the bug bounty program (latest release, @nibbstack/erc721 2.6.1).

What

The natspec on safeTransfer / safeTransferFrom documents the required receiver magic value with the wrong function signature:

src/contracts/tokens/erc721.sol:49-50 and src/contracts/tokens/nf-token.sol:116-117:

* function checks if `_to` is a smart contract (code size > 0). If so, it calls
* `onERC721Received` on `_to` and throws if the return value is not
* `bytes4(keccak256("onERC721Received(address,uint256,bytes)"))`.

The implementation does not check that value. src/contracts/tokens/nf-token.sol:32-35:

* Equal to: bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")).
bytes4 internal constant MAGIC_ON_ERC721_RECEIVED = 0x150b7a02;

The two selectors differ:

$ python3 -c "from Crypto.Hash import keccak
for s in ['onERC721Received(address,uint256,bytes)','onERC721Received(address,address,uint256,bytes)']:
    k=keccak.new(digest_bits=256); k.update(s.encode()); print(s, '0x'+k.hexdigest()[:8])"
onERC721Received(address,uint256,bytes) 0xf0b9e5ba
onERC721Received(address,address,uint256,bytes) 0x150b7a02

So the documented value is 0xf0b9e5ba while the code requires 0x150b7a02. The interface natspec at src/contracts/token/erc721-token-receiver.sol states the correct four-argument signature, which makes the two in-repo documents contradict each other.

Impact

A developer implementing a receiver from the main safeTransferFrom natspec returns 0xf0b9e5ba; every safeTransferFrom to that contract then reverts with "unsafe recipient". The failure looks like a contract bug rather than a documentation mismatch, and counterparties reading the same natspec draw the wrong conclusion about what an implementation requires. This falls under "any undocumented and unintuitive behavior" in the program scope.

Suggested fix

Update the natspec string in erc721.sol and nf-token.sol to onERC721Received(address,address,uint256,bytes) so it matches MAGIC_ON_ERC721_RECEIVED and the receiver interface.

Tested against tag 2.6.1 (commit 198dec9, npm tarball byte-identical with the repo).

主要语言
Solidity
星标
1k
派生
391
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

fulldecent/erc721 的其他 Issue

查看 fulldecent/erc721 的全部 Issue

相似的 Issue

更多 Blockchain Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。