code-423n4 / 2021-10-pooltogether-findings

0 stars 0 forks source link

Gas improvement _transferTwab #16

Open code423n4 opened 3 years ago

code423n4 commented 3 years ago

Handle

gpersoon

Vulnerability details

Impact

I've found some gas improvements for _transferTwab, see below.

Proof of Concept

https://github.com/pooltogether/v4-core/blob/master/contracts/Ticket.sol#L296-L313

Tools Used

Recommended Mitigation Steps

function _transferTwab(address _from, address _to, uint256 _amount) internal { if (_from==_to) return; // no need to transfer if both are the same if (_from != address(0)) { _decreaseUserTwab(_from, _amount); if (_to == address(0)) _decreaseTotalSupplyTwab(_amount); }
if (_to != address(0)) {
_increaseUserTwab(_to, _amount); if (_from == address(0)) _increaseTotalSupplyTwab(_amount); } }

PierrickGT commented 3 years ago

Valid improvement except for the first condition.

if (_from==_to) return; // no need to transfer if both are the same

This condition is actually handled by the functions calling _transferTwab:

PierrickGT commented 3 years ago

PR: https://github.com/pooltogether/v4-core/pull/229

GalloDaSballo commented 3 years ago

Sponsor has applied the improvement