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

1 stars 0 forks source link

`Basket.sol#handleFees()` Cache external call results can save gas #133

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

WatchPug

Vulnerability details

https://github.com/code-423n4/2021-09-defiProtocol/blob/main/contracts/contracts/Basket.sol#L120-L121

Every call to an external contract costs a decent amount of gas. For optimization of gas usage, external call results should be cached if they are being used for more than one time.

For example:

_mint(publisher, fee * (BASE - factory.ownerSplit()) / BASE);
_mint(Ownable(address(factory)).owner(), fee * factory.ownerSplit() / BASE);

Can be changed to:

uint256 ownerSplit = factory.ownerSplit();
_mint(publisher, fee * (BASE - ownerSplit) / BASE);
_mint(Ownable(address(factory)).owner(), fee * ownerSplit / BASE);
GalloDaSballo commented 2 years ago

Duplicate of #43