-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #1727: Improve revert reason when assuming interface compliance contracts. #1943
Changes from all commits
3e2ad2d
3f38430
1ca3742
3d96ecf
d210bae
486f8db
a625b8d
a58cd80
4109cd6
af1372d
06b34a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
|
||
contract ERC721ReceiverNotImplementedMock{ | ||
bytes4 private _retval; | ||
bool private _reverts; | ||
|
||
event Received(address operator, address from, uint256 tokenId, bytes data, uint256 gas); | ||
|
||
constructor (bytes4 retval, bool reverts) public { | ||
_retval = retval; | ||
_reverts = reverts; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,23 @@ | ||||||
pragma solidity ^0.5.0; | ||||||
|
||||||
import "../token/ERC721/IERC721Receiver.sol"; | ||||||
|
||||||
contract ERC721ReceiverRevertsMock is IERC721Receiver { | ||||||
bytes4 private _retval; | ||||||
bool private _reverts; | ||||||
|
||||||
event Received(address operator, address from, uint256 tokenId, bytes data, uint256 gas); | ||||||
|
||||||
constructor (bytes4 retval, bool reverts) public { | ||||||
_retval = retval; | ||||||
_reverts = reverts; | ||||||
} | ||||||
|
||||||
function onERC721Received(address operator, address from, uint256 tokenId, bytes memory data) | ||||||
public returns (bytes4) | ||||||
{ | ||||||
require(!_reverts, "ERC721ReceiverMock: Transaction rejected by receiver"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
emit Received(operator, from, tokenId, data, gasleft()); | ||||||
return _retval; | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -331,8 +331,24 @@ contract ERC721 is Context, ERC165, IERC721 { | |||||
return true; | ||||||
} | ||||||
|
||||||
bytes4 retval = IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data); | ||||||
return (retval == _ERC721_RECEIVED); | ||||||
bytes memory payload = abi.encodeWithSignature( | ||||||
"onERC721Received(address,address,uint256,bytes)", | ||||||
Comment on lines
+334
to
+335
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||||||
msg.sender, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use
Suggested change
|
||||||
from, | ||||||
tokenId, | ||||||
_data | ||||||
); | ||||||
|
||||||
//solhint-disable-next-line avoid-low-level-calls | ||||||
(bool success, bytes memory returndata) = to.call(payload); | ||||||
if (!success) { | ||||||
if (returndata.length > 0){ | ||||||
revert(string(returndata)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From reading the Solidity documentation, it seems that both If I understand correctly, this means that we're "wrapping" the revert reason twice, since Let me know if this was clear @NoopurShinde. |
||||||
}else | ||||||
revert("ERC721: to address does not implement ERC721Received interface"); | ||||||
} else {return true;} | ||||||
// bytes4 retval = IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data); | ||||||
// return (retval == _ERC721_RECEIVED); | ||||||
Comment on lines
+344
to
+351
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please tidy up the whitespace here to conform to our usual style and remove the commented out lines. 🙂 |
||||||
} | ||||||
|
||||||
/** | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove these two variables since they're not used.