DeFiHardhat
12,000 USDC
View results
Submission Details
Severity: low
Invalid

QA: `ConstantProduct2::calcRate()` - it's not obvious to all users/callers that `i` & `j` represent a specific sequence.

  1. QA: ConstantProduct2::calcRate() - it's not obvious to all users/callers that i & j represent a specific sequence.

It's important to make it clear that they represent not only a specific sequence, but represent two tokens to be swapped. Reserve token i being swapped for reserve token j, i.e. to calc their exchange rate before a swap.

Risk: It's easy enough to make the mistake to calculate exchage rate for a swap from i to j, but then swap from j to i, or vice versa.

function calcRate(
uint256[] calldata reserves,
uint256 i,
uint256 j,
bytes calldata
) external pure returns (uint256 rate) {
return reserves[i] * CALC_RATE_PRECISION / reserves[j];
}

Recommendation:

+ /// With a recommended natspec comment here to explain i & j clearly
function calcRate(
uint256[] calldata reserves,
- uint256 i,
+ uint256 i_Sell,
- uint256 j,
+ uint256 j_Buy,
bytes calldata
) external pure returns (uint256 rate) {
- return reserves[i] * CALC_RATE_PRECISION / reserves[j];
+ return reserves[i_Sell] * CALC_RATE_PRECISION / reserves[j_Buy];
}
Updates

Lead Judging Commences

giovannidisiena Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Informational/Invalid

Support

FAQs

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