Closed code423n4 closed 2 years ago
https://github.com/code-423n4/2022-03-joyn/blob/c9297ccd925ebb2c44dbc6eaa3effd8db5d2368a/core-contracts/contracts/CoreCollection.sol#L173-L177
function withdraw() external onlyOwner { uint256 amount = payableToken.balanceOf(address(this)); payableToken.transferFrom(address(this), msg.sender, amount); emit NewWithdrawal(msg.sender, amount); }
Unlike ERC721, most ERC20 tokens require an allowance when calling transferFrom(), even when the from == msg.sedner.
transferFrom()
from == msg.sedner
Therefore, in the withdraw() function, it should be using payableToken.trasnfer(msg.sender, amount); instead of payableToken.transferFrom().
withdraw()
payableToken.trasnfer(msg.sender, amount);
payableToken.transferFrom()
The current implementation will most certainly revert with the error: "ERC20: insufficient allowance" for almost all ERC20 tokens.
See: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol#L164
Change to: payableToken.trasnfer(msg.sender, amount);
duplicate of #52
Actually a duplicate of #80
Lines of code
https://github.com/code-423n4/2022-03-joyn/blob/c9297ccd925ebb2c44dbc6eaa3effd8db5d2368a/core-contracts/contracts/CoreCollection.sol#L173-L177
Vulnerability details
https://github.com/code-423n4/2022-03-joyn/blob/c9297ccd925ebb2c44dbc6eaa3effd8db5d2368a/core-contracts/contracts/CoreCollection.sol#L173-L177
Unlike ERC721, most ERC20 tokens require an allowance when calling
transferFrom()
, even when thefrom == msg.sedner
.Therefore, in the
withdraw()
function, it should be usingpayableToken.trasnfer(msg.sender, amount);
instead ofpayableToken.transferFrom()
.The current implementation will most certainly revert with the error: "ERC20: insufficient allowance" for almost all ERC20 tokens.
See: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol#L164
Recommendation
Change to:
payableToken.trasnfer(msg.sender, amount);