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

1 stars 0 forks source link

Use free functions to replace external calls can save gas #130

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

WatchPug

Vulnerability details

Functions can be defined outside of a contract, also called “free functions”, always have implicit internal visibility.

Every call to an external contract costs a decent amount of gas. For optimization of gas usage, use free functions to replace external calls can save gas.

For example:

Basket.sol#validateWeights() can be defined as a free function, so that Factory.sol#proposeBasketLicense() can save an external call.

https://github.com/code-423n4/2021-09-defiProtocol/blob/main/contracts/contracts/Factory.sol#L72

GalloDaSballo commented 2 years ago

I don't understand how the internal function would save gas here

You'd be calling an internal function, which then performs an external call, you're still paying for the external calls gas, it's no like the free function would make those costs free

In lack of evidence I'm setting this as invalid, would love to see a POC and am happy to change my mind

loudoguno commented 2 years ago

marking invalid as per findings sheet