Hey there, I just read a Certik auditing report for Lydia Finance and noticed they had a section on PG 12 highlighting using external instead of public visibility for gas optimization, but I did some simple tests given below and found no difference between public
and external
visibility in gas consumption. Wondering if I am missing anything. Thanks.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.4;
contract Test {
uint256 private val;
function setVal(uint256 val_) external {
val = val_;
}
function getVal() external view returns (uint256) {
return val;
}
}
I don’t think changing public to external will lead to any difference in gas. I think public
v/s external
is only used for analysis, and doesn’t affect the generated code. However, changing to internal
will lead to some gas savings. This is because there is one less function during the function dispatch.
Glad to get confirmed. It looks like Certik auditing is picking stones out of eggs.
@maxareo Could you please ask them why they think the gas would change?
1 Like
Have not heard back from them yet.
Was doing some digging and I concur that it’s not applicable in today’s context, nor in the context of the commit being audited.
@maxareo , Have a look at this SO answer solidity - does using external over public in a library reduce any gas costs? - Ethereum Stack Exchange and probably run your test for the Solidity version being audited (0.6.12) and something older (0.6.1)?