diff --git a/packages/protocol/contracts/tokenvault/BridgedERC721.sol b/packages/protocol/contracts/tokenvault/BridgedERC721.sol index e7ee02356c..960ed9a180 100644 --- a/packages/protocol/contracts/tokenvault/BridgedERC721.sol +++ b/packages/protocol/contracts/tokenvault/BridgedERC721.sol @@ -51,41 +51,33 @@ contract BridgedERC721 is EssentialContract, ERC721Upgradeable { /// @dev Mints tokens. /// @param _account Address to receive the minted token. - /// @param _tokenIds IDs of the tokens to mint. - function batchMint( + /// @param _tokenId ID of the token to mint. + function mint( address _account, - uint256[] memory _tokenIds + uint256 _tokenId ) external whenNotPaused onlyFromNamed(LibStrings.B_ERC721_VAULT) nonReentrant { - for (uint256 i; i < _tokenIds.length; ++i) { - _safeMint(_account, _tokenIds[i]); - } + _safeMint(_account, _tokenId); } /// @dev Burns tokens. - /// @param _tokenIds IDs of the tokens to burn. - function batchBurn(uint256[] memory _tokenIds) + /// @param _tokenId ID of the token to burn. + function burn(uint256 _tokenId) external whenNotPaused onlyFromNamed(LibStrings.B_ERC721_VAULT) nonReentrant { - for (uint256 i; i < _tokenIds.length; ++i) { - // Check if the caller is the owner of the token. Somehow this is not done inside the - // _burn() function below. - if (ownerOf(_tokenIds[i]) != msg.sender) revert BTOKEN_INVALID_BURN(); - _burn(_tokenIds[i]); - } - } - - function safeBatchTransferFrom(address _from, address _to, uint256[] memory _tokenIds) public { - for (uint256 i; i < _tokenIds.length; ++i) { - safeTransferFrom(_from, _to, _tokenIds[i], ""); + // Check if the caller is the owner of the token. Somehow this is not done inside the + // _burn() function below. + if (ownerOf(_tokenId) != msg.sender) { + revert BTOKEN_INVALID_BURN(); } + _burn(_tokenId); } /// @notice Gets the source token and source chain ID being bridged. diff --git a/packages/protocol/contracts/tokenvault/ERC721Vault.sol b/packages/protocol/contracts/tokenvault/ERC721Vault.sol index e4eb99b901..4fa1800b93 100644 --- a/packages/protocol/contracts/tokenvault/ERC721Vault.sol +++ b/packages/protocol/contracts/tokenvault/ERC721Vault.sol @@ -177,7 +177,9 @@ contract ERC721Vault is BaseNFTVault, IERC721Receiver { } } else { token_ = _getOrDeployBridgedToken(_ctoken); - BridgedERC721(token_).batchMint(_to, _tokenIds); + for (uint256 i; i < _tokenIds.length; ++i) { + BridgedERC721(token_).mint(_to, _tokenIds[i]); + } } } @@ -194,10 +196,12 @@ contract ERC721Vault is BaseNFTVault, IERC721Receiver { CanonicalNFT storage _ctoken = bridgedToCanonical[_op.token]; if (_ctoken.addr != address(0)) { ctoken_ = _ctoken; - BridgedERC721(_op.token).safeBatchTransferFrom( - msg.sender, address(this), _op.tokenIds - ); - BridgedERC721(_op.token).batchBurn(_op.tokenIds); + for (uint256 i; i < _op.tokenIds.length; ++i) { + BridgedERC721(_op.token).safeTransferFrom( + msg.sender, address(this), _op.tokenIds[i] + ); + BridgedERC721(_op.token).burn(_op.tokenIds[i]); + } } else { ctoken_ = CanonicalNFT({ chainId: uint64(block.chainid), @@ -207,7 +211,9 @@ contract ERC721Vault is BaseNFTVault, IERC721Receiver { }); for (uint256 i; i < _op.tokenIds.length; ++i) { - IERC721(_op.token).safeTransferFrom(msg.sender, address(this), _op.tokenIds[i]); + ERC721Upgradeable(_op.token).safeTransferFrom( + msg.sender, address(this), _op.tokenIds[i] + ); } } } diff --git a/packages/protocol/test/tokenvault/ERC721Vault.t.sol b/packages/protocol/test/tokenvault/ERC721Vault.t.sol index 638806bdf3..c43ed5fde0 100644 --- a/packages/protocol/test/tokenvault/ERC721Vault.t.sol +++ b/packages/protocol/test/tokenvault/ERC721Vault.t.sol @@ -907,10 +907,7 @@ contract ERC721VaultTest is TaikoTest { // Also Vault cannot burn tokens it does not own (even if the priv key compromised) vm.prank(address(destChainErc721Vault), address(destChainErc721Vault)); vm.expectRevert(BridgedERC721.BTOKEN_INVALID_BURN.selector); - - tokenIds = new uint256[](1); - tokenIds[0] = 1; - BridgedERC721(deployedContract).batchBurn(tokenIds); + BridgedERC721(deployedContract).burn(1); // After approve() ERC721Vault can transfer and burn vm.prank(Alice, Alice);