Public visibility or external visibility from an auditing perspective

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.