From 4903bec361a225f3fdbdb287f962a37ee72ae517 Mon Sep 17 00:00:00 2001 From: Daniel Wang <99078276+dantaik@users.noreply.github.com> Date: Fri, 10 May 2024 14:52:46 +0800 Subject: [PATCH] fix(protocol): revert adding batchBurn to IBridgedERC1155 (#17077) Co-authored-by: dantaik --- packages/protocol/contracts/tokenvault/BridgedERC1155.sol | 8 ++++---- packages/protocol/contracts/tokenvault/ERC1155Vault.sol | 4 +++- .../protocol/contracts/tokenvault/IBridgedERC1155.sol | 8 ++++---- packages/protocol/test/tokenvault/ERC1155Vault.t.sol | 4 +--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/protocol/contracts/tokenvault/BridgedERC1155.sol b/packages/protocol/contracts/tokenvault/BridgedERC1155.sol index 7e25b4ccb76..3084b37b423 100644 --- a/packages/protocol/contracts/tokenvault/BridgedERC1155.sol +++ b/packages/protocol/contracts/tokenvault/BridgedERC1155.sol @@ -76,16 +76,16 @@ contract BridgedERC1155 is } /// @inheritdoc IBridgedERC1155 - function burnBatch( - uint256[] calldata _ids, - uint256[] calldata _amounts + function burn( + uint256 _id, + uint256 _amount ) external whenNotPaused onlyFromNamed(LibStrings.B_ERC1155_VAULT) nonReentrant { - _burnBatch(msg.sender, _ids, _amounts); + _burn(msg.sender, _id, _amount); } /// @inheritdoc IBridgedERC1155 diff --git a/packages/protocol/contracts/tokenvault/ERC1155Vault.sol b/packages/protocol/contracts/tokenvault/ERC1155Vault.sol index a560cd70267..0b36cd750f9 100644 --- a/packages/protocol/contracts/tokenvault/ERC1155Vault.sol +++ b/packages/protocol/contracts/tokenvault/ERC1155Vault.sol @@ -241,7 +241,9 @@ contract ERC1155Vault is BaseNFTVault, ERC1155ReceiverUpgradeable { IERC1155(_op.token).safeBatchTransferFrom( msg.sender, address(this), _op.tokenIds, _op.amounts, "" ); - IBridgedERC1155(_op.token).burnBatch(_op.tokenIds, _op.amounts); + for (uint256 i; i < _op.tokenIds.length; ++i) { + IBridgedERC1155(_op.token).burn(_op.tokenIds[i], _op.amounts[i]); + } } else { // is a ctoken token, meaning, it lives on this chain ctoken_ = CanonicalNFT({ diff --git a/packages/protocol/contracts/tokenvault/IBridgedERC1155.sol b/packages/protocol/contracts/tokenvault/IBridgedERC1155.sol index c479b285349..3d0ac0a93de 100644 --- a/packages/protocol/contracts/tokenvault/IBridgedERC1155.sol +++ b/packages/protocol/contracts/tokenvault/IBridgedERC1155.sol @@ -16,10 +16,10 @@ interface IBridgedERC1155 { ) external; - /// @dev Batch burns tokens. - /// @param _ids Array of IDs of the tokens to burn. - /// @param _amounts Amount of tokens to burn respectively. - function burnBatch(uint256[] calldata _ids, uint256[] calldata _amounts) external; + /// @dev Burns tokens. + /// @param _id ID of the token to burn. + /// @param _amount Amount of token to burn respectively. + function burn(uint256 _id, uint256 _amount) external; /// @notice Gets the canonical token's address and chain ID. /// @return The canonical token's address. diff --git a/packages/protocol/test/tokenvault/ERC1155Vault.t.sol b/packages/protocol/test/tokenvault/ERC1155Vault.t.sol index d61e35380a8..c7a4853e664 100644 --- a/packages/protocol/test/tokenvault/ERC1155Vault.t.sol +++ b/packages/protocol/test/tokenvault/ERC1155Vault.t.sol @@ -975,11 +975,9 @@ contract ERC1155VaultTest is TaikoTest { destChainErc1155Vault.sendToken{ value: GAS_LIMIT }(sendOpts); // Also Vault cannot burn tokens it does not own (even if the priv key compromised) - uint256[] memory randomIdAndLength = new uint256[](1); - randomIdAndLength[0] = 20; vm.prank(address(destChainErc1155Vault), address(destChainErc1155Vault)); vm.expectRevert("ERC1155: burn amount exceeds balance"); - BridgedERC1155(deployedContract).burnBatch(randomIdAndLength, randomIdAndLength); + BridgedERC1155(deployedContract).burn(1, 20); // After setApprovalForAll() ERC1155Vault can transfer and burn vm.prank(Alice, Alice);