code-423n4 / 2021-09-defiprotocol-findings

1 stars 0 forks source link

Hardcoding numbers is error-prone #203

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

pauliax

Vulnerability details

Impact

Hardcoding numbers that depend on other variables is error-prone, e.g. require(newOwnerSplit <= 2e17); // 20% You must not forget to update this if you decide to change the BASE value.

Recommended Mitigation Steps

Better define a separate constant that directly depends on the BASE, e.g.: uint256 private constant MAX_OWNER_SPLIT = BASE / 5; // 20% require(newOwnerSplit <= MAX_OWNER_SPLIT);

GalloDaSballo commented 3 years ago

100% agree with the warden, Magic Values can cause big issues, recently I've seen a UniV2 fork forget a 0 in 10_000 (because they weren't using CONSTANTS) and get completely rekt