Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
Check depositor when burning ERC721 tokens (#687)
Browse files Browse the repository at this point in the history
* burn fix

* Release v2.1.4

* Fix tests

---------

Co-authored-by: Kirill Pisarev <[email protected]>
  • Loading branch information
mpetrun5 and P1sar authored Feb 3, 2023
1 parent 2f29dd7 commit b929c98
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion contracts/ERC721Safe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ contract ERC721Safe {
@param tokenAddress Address of ERC721 to burn.
@param tokenID ID of token to burn.
*/
function burnERC721(address tokenAddress, uint256 tokenID) internal {
function burnERC721(address tokenAddress, address owner, uint256 tokenID) internal {
ERC721MinterBurnerPauser erc721 = ERC721MinterBurnerPauser(tokenAddress);
require(erc721.ownerOf(tokenID) == owner, 'Burn not from owner');
erc721.burn(tokenID);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/handlers/ERC721Handler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ contract ERC721Handler is IDepositExecute, HandlerHelpers, ERC721Safe {
}

if (_burnList[tokenAddress]) {
burnERC721(tokenAddress, tokenID);
burnERC721(tokenAddress, depositer, tokenID);
} else {
lockERC721(tokenAddress, depositer, address(this), tokenID);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@chainsafe/chainbridge-contracts",
"version": "2.1.3",
"version": "2.1.4",
"description": "",
"main": "dist/index.js",
"repository": "https://github.com/ChainSafe/chainbridge-solidity.git",
Expand Down
13 changes: 11 additions & 2 deletions test/handlers/erc721/depositBurn.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright 2020 ChainSafe Systems
* SPDX-License-Identifier: LGPL-3.0-only
*/

const TruffleAssert = require('truffle-assertions');

const Helpers = require('../../helpers');
Expand Down Expand Up @@ -48,7 +48,7 @@ contract('ERC721Handler - [Deposit Burn ERC721]', async (accounts) => {
ERC721HandlerContract.new(BridgeInstance.address).then(instance => ERC721HandlerInstance = instance),
ERC721MintableInstance1.mint(depositerAddress, tokenID, "")
]);

await Promise.all([
ERC721MintableInstance1.approve(ERC721HandlerInstance.address, tokenID, { from: depositerAddress }),
BridgeInstance.adminSetResource(ERC721HandlerInstance.address, resourceID1, ERC721MintableInstance1.address),
Expand Down Expand Up @@ -89,4 +89,13 @@ contract('ERC721Handler - [Deposit Burn ERC721]', async (accounts) => {
ERC721MintableInstance1.ownerOf(tokenID),
'ERC721: owner query for nonexistent token');
});
it('depositAmount of ERC721MintableInstance1 tokens should NOT burn from NOT token owner', async () => {
await TruffleAssert.reverts(BridgeInstance.deposit(
domainID,
resourceID1,
depositData,
{ from: accounts[3] }
),
'Burn not from owner');
});
});

0 comments on commit b929c98

Please sign in to comment.