setCollectionCosts
lacks input validation, risking incorrect price calculation and exploitation.
#327
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
unsatisfactory
does not satisfy C4 submission criteria; not eligible for awards
Lines of code
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/MinterContract.sol#L157
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/MinterContract.sol#L44-L53
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/MinterContract.sol#L161
https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/MinterContract.sol#L157
Vulnerability details
Impact
Incorrect rate parameters in
setCollectionCosts
could lead to unexpected prices. Therate
parameter insetCollectionCosts
is used to calculate minting price but lacks input validation.This could allow setting unexpected rate values that break the price calculation. This allows setting any
_rate
value:Breaking the price calculation and charging incorrect prices.
Bug Description
My observation about the lack of input validation on the
_rate
parameter in thesetCollectionCosts
function. This could lead to unexpected behavior when calculating minting prices.Here is my assessment:
The
_rate
value passed tosetCollectionCosts
is stored in thecollectionPhases
struct and later used to calculate prices.However, there is no validation on
_rate
before storing it.This allows setting any arbitrary
_rate
value, which could break the price calculation when used.For example, an extremely large
_rate
could cause prices to decrease too rapidly or even go negative.By setting an unreasonable
_rate
then profiting from the resulting incorrect prices.In summary, the unrestricted
_rate
input allows manipulating the price calculation and could lead to unexpected user charges or other economic impacts.I would recommend adding input validation on
_rate
insetCollectionCosts
, such as:This would prevent storing invalid
_rate
values that could be exploited.Proof of Concept
The
setCollectionCosts
function sets therate
parameter used for minting price calculation but does not validate the input value.MinterContract.sol#setCollectionCosts
The
rate
is stored incollectionPhases
struct: MinterContract.sol#collectionPhasesDataStructuresetCollectionCosts
sets the rate value: MinterContract.sol#Line 161collectionPhases[_collectionID].rate = _rate;
And later used to calculate price.
However,
setCollectionCosts
does no validation on_rate
: MinterContract.sol#Line 157It's because of lack of input validation on
_rate
insetCollectionCosts
:Potential Implications
Allowing extremely high or low
rate
values would cause the price calculation to behave incorrectly.Users would pay unexpected prices.
Could disrupt revenue model.
Attacker could profit by manipulating rates.
Steps to Reproduce
setCollectionCosts
with a very high rate value:Call the minting function.
Price paid will be incorrect based on invalid rate.
Attacker profits from price discrepancy.
Tools Used
Manual
Mitigation
Should validate rate range. Add rate range check:
This prevents unexpected values being used.
Assessed type
Invalid Validation
The text was updated successfully, but these errors were encountered: