Skip to content
Request an audit

‹ All findings

If statements can be inverted to increase readability

Low/InfoGlacier·Three Sigma · Liquid staking · 12th July, 20233S-GLACIER-N06

Description

Inverting if statements can help increase readability and decrease overall code complexity.

Recommendation

Take a look at the following example.

solidity
function withdraw(uint256 amount) external nonReentrant {
    ... if (toWithdraw > 0) {

<code when toWithdraw > 0>

solidity
}
emit Withdraw(user, totalWithdrawAvaxAmount);
}

It can be replaced by

solidity
function withdraw(uint256 amount) external nonReentrant {
    ... emit Withdraw(user, totalWithdrawAvaxAmount);
    if (toWithdraw <= 0) return;

<code when toWithdraw > 0> }

Status

Currently being reviewed by the team.