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

オープン 初心者向け
#299 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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 はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

fulldecent/erc721 のほかの issue

fulldecent/erc721 の issue をすべて見る

似ている issue

Blockchain の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。