Core Contracts

Regnum Aurum Acquisition Corp
HardhatReal World AssetsNFT
77,280 USDC
View results
Submission Details
Severity: low
Invalid

`mint` function in RAACNFT contract can avoid refund by transferring `price` directly.

Summary

mintfunction in the RAACNFT contract is defined as follows:

function mint(uint256 _tokenId, uint256 _amount) public override {
uint256 price = raac_hp.tokenToHousePrice(_tokenId);
if (price == 0) revert RAACNFT__HousePrice();
if (price > _amount) revert RAACNFT__InsufficientFundsMint();
token.safeTransferFrom(msg.sender, address(this), _amount);
_safeMint(msg.sender, _tokenId);
if (_amount > price) {
uint256 refundAmount = _amount - price;
token.safeTransfer(msg.sender, refundAmount);
}
emit NFTMinted(msg.sender, _tokenId, price);
}

We can see that this function takes an _amount as argument, and checks that this amount is greater than or equal to the price of the house.

Then, the whole _amount is transferred to the RAACNFT contract and if this _amount is greater than price, a refund is executed.

The refunding pattern can be avoided by directly transferring price to the contract, thus saving gas and avoiding a useless token transfer.

Impact

The impact of this issue is low as it consists of useless function calls (safeTransfer) that costs gas and should be avoided.

Tools Used

Manual review

Recommendations

mint function implementation could be modified for:

function mint(uint256 _tokenId) public override {
uint256 price = raac_hp.tokenToHousePrice(_tokenId);
if (price == 0) revert RAACNFT__HousePrice();
token.safeTransferFrom(msg.sender, address(this), price);
_safeMint(msg.sender, _tokenId);
emit NFTMinted(msg.sender, _tokenId, price);
}

Indeed, any user can get the price of the house with the getHousePrice function and approve the required amount, allowing to get rid of the _amount parameter while consuming entirely the approval amount:

function getHousePrice(uint256 _tokenId) public view override returns (uint256) {
return raac_hp.tokenToHousePrice(_tokenId);
}
Updates

Lead Judging Commences

inallhonesty Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!