Bug Bounty Report: natspec documents wrong onERC721Received magic value (0xf0b9e5ba vs implemented 0x150b7a02)
まだ誰も着手していません。
評価
- 難易度
- 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 ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
fulldecent/erc721 のほかの issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
fulldecent/erc721#293 · リアクション 1 件 ·
-
Bug Bounty Report: Security Issue in ERC-721 Reference Implementation再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 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 が 26 日前に担当しました。 オープン
難易度 1/5 1〜3時間 初心者へのやさしさ 25/100
fulldecent/erc721#301 · コメント 1 件 ·
fulldecent/erc721 の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
NethermindEth/nethermind#15683 ·
メンテナーはふだん 1 日以内に返信
-
integration revocation-registry test
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
cybermax4200/stellar-did-credit#1254 ·
メンテナーはふだん 1 日以内に返信
-
area:contract complexity:low good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
-
Epoch change aborts when a departing validator's pool grows past the rest of the committee's stakeオープンC-bug core-protocol
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
iotaledger/iota#13480 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
near/near-sdk-rs#1676 ·
メンテナーはふだん 2 日以内に返信