veNFT withdraw and merge fail for approved callers
The veNFT contract's merge and withdraw functions allow approved spenders to call them, but the internal _burn function incorrectly passes msg.sender instead of the token owner to _removeTokenFrom, causing a revert. As a result, approved callers cannot merge or withdraw veNFTs, limiting functionality to the token owner only.
Originally disclosed on Code4rena
Submitted by horsefacts, also found by berndartmueller, csanuragjain, GalloDaSballo, hansfriese, IllIllI, kenzo, minhquanym, and rotcivegaf
Golom is impacted by a known issue with the veNFT contract that causes the merge and withdraw functions to revert when called by an approved spender rather than the token owner.
merge and withdraw may both be called by either the token owner or an approved spender. Note that both of these functions check _isApprovedOrOwner:
function merge(uint256 _from, uint256 _to) external {
require(attachments[_from] == 0 && !voted[_from], 'attached');
require(_from != _to);
require(_isApprovedOrOwner(msg.sender, _from));
require(_isApprovedOrOwner(msg.sender, _to));
LockedBalance memory _locked0 = locked[_from];
LockedBalance memory _locked1 = locked[_to];
uint256 value0 = uint256(int256(_locked0.amount));
uint256 end = _locked0.end >= _locked1.end ? _locked0.end : _locked1.end;
locked[_from] = LockedBalance(0, 0);
_checkpoint(_from, _locked0, LockedBalance(0, 0));
_burn(_from);
_deposit_for(_to, value0, end, _locked1, DepositType.MERGE_TYPE);
}
/// @notice Withdraw all tokens for `_tokenId`
/// @dev Only possible if the lock has expired
function withdraw(uint256 _tokenId) external nonreentrant {
assert(_isApprovedOrOwner(msg.sender, _tokenId));
require(attachments[_tokenId] == 0 && !voted[_tokenId], 'attached');
LockedBalance memory _locked = locked[_tokenId];
require(block.timestamp >= _locked.end, "The lock didn't expire");
uint256 value = uint256(int256(_locked.amount));
locked[_tokenId] = LockedBalance(0, 0);
uint256 supply_before = supply;
supply = supply_before - value;
// old_locked can have either expired <= timestamp or zero end
// _locked has only 0 end
// Both can have >= 0 amount
_checkpoint(_tokenId, _locked, LockedBalance(0, 0));
assert(IERC20(token).transfer(msg.sender, value));
// Burn the NFT
_burn(_tokenId);
emit Withdraw(msg.sender, _tokenId, value, block.timestamp);
emit Supply(supply_before, supply_before - value);
}
However, both functions make internal calls to _burn, which does not handle the case of an approved caller correctly. The call to _removeTokenFrom on L1234 passes msg.sender rather than the token owner, which will revert:
function _burn(uint256 _tokenId) internal {
require(_isApprovedOrOwner(msg.sender, _tokenId), 'caller is not owner nor approved');
address owner = ownerOf(_tokenId);
// Clear approval
approve(address(0), _tokenId);
// Remove token
_removeTokenFrom(msg.sender, _tokenId);
emit Transfer(owner, address(0), _tokenId);
}
Impact
Approved callers cannot merge or withdraw veNFTs. merge and withdraw may only be called by the token owner.
Recommended Mitigation Steps
Update _burn to pass token owner address rather than msg.sender:
function _burn(uint256 _tokenId) internal {
require(_isApprovedOrOwner(msg.sender, _tokenId), 'caller is not owner nor approved');
address owner = ownerOf(_tokenId);
// Clear approval
approve(address(0), _tokenId);
// Remove token
_removeTokenFrom(owner, _tokenId);
emit Transfer(owner, address(0), _tokenId);
}
Removed
mergeand fixed withdraw here: https://github.com/golom-protocol/contracts/commit/c79913ec08ba2dca87a22f1bc6fe47f65f7b4202
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
Approved callers cannot merge or withdraw veNFTs; these functions may only be called by the token owner.
What the attacker needed
Caller is approved spender; veNFT lock expired for withdraw
The fix
The fix was to update _burn to pass the token owner address instead of msg.sender to _removeTokenFrom; the project removed merge and fixed withdraw.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In this smart contract, a token owner can approve someone else to manage their token. The merge and withdraw functions are supposed to let that approved person act on the owner's behalf. However, a mistake in an internal function called _burn uses the caller's address instead of the owner's address when removing the token, which causes the transaction to fail. So approved users cannot perform these actions, even though they should be allowed.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.