code-423n4 / 2024-07-traitforge-findings

0 stars 0 forks source link

`msg.value` is can become stuck inside EntityForging #929

Closed howlbot-integration[bot] closed 1 month ago

howlbot-integration[bot] commented 2 months ago

Lines of code

https://github.com/code-423n4/2024-07-traitforge/blob/main/contracts/EntityForging/EntityForging.sol#L126

Vulnerability details

Impact

forgeWithListed accepts arbitrary msg.value and if forgingFee is less than that it will just hold stuck it inside the contract with no way of withdrawing it.

Proof of Concept

forgeWithListed can be called with an arbitrary value, where only forgingFee is taken from it and the rest is left stuck inside the contract.

    require(msg.value >= forgingFee, "Insufficient fee for forging");

    ...
    uint256 devFee = forgingFee / taxCut;
    uint256 forgerShare = forgingFee - devFee;
    address payable forgerOwner = payable(nftContract.ownerOf(forgerTokenId));

Here is an example where due to the a network congestion the merger losses some of his ETH:

  1. NFT is listed for 1 ETH
  2. Merger sends a TX, but due to network congestion (aka. expensive gas fees) the TX takes a few hours to execute
  3. Forger's NFT is not merged, so he lists it again for a lower price of 0.9 ETH
  4. Our merger TX finally gets executed and he buys the NFT for 1 ETH.

In the example above due to bad luck our merger lost 0.1 ETH. This should never be the case and the function should either return the extra or revert if the msg.value doesn't match the asked price.

Tools Used

Manual review

Recommended Mitigation Steps

Revert if msg.value doesn't match price.

-   require(msg.value >= forgingFee, "Insufficient fee for forging");
+   require(msg.value == forgingFee, "Incorrect amount sent");

Assessed type

Error

c4-judge commented 2 months ago

koolexcrypto changed the severity to QA (Quality Assurance)

c4-judge commented 1 month ago

koolexcrypto marked the issue as grade-c

c4-judge commented 1 month ago

This previously downgraded issue has been upgraded by koolexcrypto

c4-judge commented 1 month ago

koolexcrypto marked the issue as duplicate of #687

c4-judge commented 1 month ago

koolexcrypto marked the issue as duplicate of #687

c4-judge commented 1 month ago

koolexcrypto marked the issue as duplicate of #218

c4-judge commented 1 month ago

koolexcrypto marked the issue as duplicate of #218

c4-judge commented 1 month ago

koolexcrypto removed the grade

c4-judge commented 1 month ago

koolexcrypto marked the issue as not a duplicate

c4-judge commented 1 month ago

koolexcrypto marked the issue as duplicate of #41

c4-judge commented 1 month ago

koolexcrypto marked the issue as satisfactory