20,000 USDC
View results
Submission Details
Severity: gas
Valid

`PoolBalanceUpdated` event is emitted even when pool balance is not changed.

Vulnerability Details

function setPool(Pool calldata p) public returns (bytes32 poolId) {
...
uint256 currentBalance = pools[poolId].poolBalance;
if (p.poolBalance > currentBalance) {
// if new balance > current balance then transfer the difference from the lender
IERC20(p.loanToken).transferFrom(
p.lender,
address(this),
p.poolBalance - currentBalance
);
} else if (p.poolBalance < currentBalance) {
// if new balance < current balance then transfer the difference back to the lender
IERC20(p.loanToken).transfer(
p.lender,
currentBalance - p.poolBalance
);
}
emit PoolBalanceUpdated(poolId, p.poolBalance);
...
}

Tools Used

Manual Review

Recommendations

It should only emit when balance is changed.

function setPool(Pool calldata p) public returns (bytes32 poolId) {
...
uint256 currentBalance = pools[poolId].poolBalance;
if (p.poolBalance > currentBalance) {
// if new balance > current balance then transfer the difference from the lender
IERC20(p.loanToken).transferFrom(
p.lender,
address(this),
p.poolBalance - currentBalance
);
+ emit PoolBalanceUpdated(poolId, p.poolBalance);
} else if (p.poolBalance < currentBalance) {
// if new balance < current balance then transfer the difference back to the lender
IERC20(p.loanToken).transfer(
p.lender,
currentBalance - p.poolBalance
);
+ emit PoolBalanceUpdated(poolId, p.poolBalance);
}
- emit PoolBalanceUpdated(poolId, p.poolBalance);
...
}

Support

FAQs

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

Give us feedback!