Skip to content

Commit

Permalink
remove chainId checks
Browse files Browse the repository at this point in the history
we have no cross-chain capabilities anyways. it would lead to bricked mechs in case of network forks
  • Loading branch information
jfschwarz committed Dec 13, 2023
1 parent f9f0f68 commit cf79eea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
21 changes: 5 additions & 16 deletions contracts/ERC1155TokenboundMech.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import "./base/TokenboundMech.sol";
*/
contract ERC1155TokenboundMech is TokenboundMech {
function isOperator(address signer) public view override returns (bool) {
(uint256 chainId, address tokenContract, uint256 tokenId) = token();
if (chainId != block.chainid) return false;
(, address tokenContract, uint256 tokenId) = token();
return IERC1155(tokenContract).balanceOf(signer, tokenId) > 0;
}

Expand All @@ -21,16 +20,10 @@ contract ERC1155TokenboundMech is TokenboundMech {
uint256,
bytes calldata
) external view override returns (bytes4) {
(
uint256 chainId,
address boundTokenContract,
uint256 boundTokenId
) = token();
(, address boundTokenContract, uint256 boundTokenId) = token();

if (
chainId == block.chainid &&
msg.sender == boundTokenContract &&
receivedTokenId == boundTokenId
msg.sender == boundTokenContract && receivedTokenId == boundTokenId
) {
// We block the transfer only if the sender has no balance left after the transfer.
// Note: ERC-1155 prescribes that balances are updated BEFORE the call to onERC1155Received.
Expand All @@ -51,13 +44,9 @@ contract ERC1155TokenboundMech is TokenboundMech {
uint256[] calldata,
bytes calldata
) external view override returns (bytes4) {
(
uint256 chainId,
address boundTokenContract,
uint256 boundTokenId
) = token();
(, address boundTokenContract, uint256 boundTokenId) = token();

if (chainId == block.chainid && msg.sender == boundTokenContract) {
if (msg.sender == boundTokenContract) {
// We block the transfer only if the sender has no balance left after the transfer.
// Note: ERC-1155 prescribes that balances are updated BEFORE the call to onERC1155BatchReceived.
for (uint256 i = 0; i < ids.length; i++) {
Expand Down
13 changes: 3 additions & 10 deletions contracts/ERC721TokenboundMech.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import "./base/TokenboundMech.sol";
*/
contract ERC721TokenboundMech is TokenboundMech {
function isOperator(address signer) public view override returns (bool) {
(uint256 chainId, address tokenContract, uint256 tokenId) = token();
if (chainId != block.chainid) return false;
(, address tokenContract, uint256 tokenId) = token();
return
IERC721(tokenContract).ownerOf(tokenId) == signer &&
signer != address(0);
Expand All @@ -23,16 +22,10 @@ contract ERC721TokenboundMech is TokenboundMech {
uint256 receivedTokenId,
bytes calldata
) external view override returns (bytes4) {
(
uint256 chainId,
address boundTokenContract,
uint256 boundTokenId
) = token();
(, address boundTokenContract, uint256 boundTokenId) = token();

if (
chainId == block.chainid &&
msg.sender == boundTokenContract &&
receivedTokenId == boundTokenId
msg.sender == boundTokenContract && receivedTokenId == boundTokenId
) {
revert OwnershipCycle();
}
Expand Down

0 comments on commit cf79eea

Please sign in to comment.