Bug Bounty Report: natspec documents wrong onERC721Received magic value (0xf0b9e5ba vs implemented 0x150b7a02)
还没有人认领这个 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 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
fulldecent/erc721 的其他 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 70/100
fulldecent/erc721#293 · 1 个 reaction ·
-
Bug Bounty Report: Security Issue in ERC-721 Reference Implementation可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 4/5 3-5 天 新手友好度 8/100
fulldecent/erc721#306 ·
-
难度 3/5 1-2 天 新手友好度 45/100
fulldecent/erc721#304 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 45/100
fulldecent/erc721#303 · 1 条评论 ·
-
Bug Bounty Report: remaining typos in natspec at 2.6.1 (wich/whitch/intefraces/suported/overriden)可能已有人在做 @Jah-yee 于 27 天前认领。 未关闭
难度 1/5 1-3 小时 新手友好度 25/100
fulldecent/erc721#301 · 1 条评论 ·
查看 fulldecent/erc721 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
blinklabs-io/dingo#6074 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
btclib-org/btclib-node#2242 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
blinklabs-io/gouroboros#2958 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
-
难度 2/5 1-3 小时 新手友好度 70/100
foundry-rs/starknet-foundry#4689 ·
维护者通常 7 天内回复