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

0 stars 0 forks source link

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

Open code423n4 opened 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-12-defiprotocol/blob/205d3766044171e325df6a8bf2e79b37856eece1/contracts/contracts/Factory.sol#L75-L75

basketImpl.validateWeights(tokens, weights);