Why does the upgradeable contracts have functions that may never be used? Wouldn't this be more expensive when deploying it?

I have noticed that the UUPSUpgradeable.sol contract which every UUPS implementation contract is supposed to inherit from may have a number of functions that may not be used at all. Not only that, it seems like all proxy contracts inherit from ERC1967Proxy and they may all inherit the same set of functions. Would this end up bloating the gas costs needed to deploy the proxy and implementation contracts?

For example, there are a bunch of functions meant for updating of beacon and setting admin. Most of them are internal functions. I will still have to create functions to wrap them to use them. Would this further bloat the size of the contracts? If I were only using UUPS, I don't think I will ever be touching the beacon functions even though the functions are included and will be deployed, would I?

And for the setting admin related functions, should I be using the ones that come included or using onlyOwner from OwnableUpgradeable?

Also, the ERC1967Proxy which will be used to point to the UUPS implementation seems to have similar functions in both the proxy and implementation contract in it. For eg, ERC1967Upgrade.sol at here and ERC1967UpgradeUpgradeable.sol at here.

Why doesn't the proxy contract only do a delegatecall (may even cost less to deploy?) but included very similar looking set of upgrade/admin functions as the implementation contract in it? Which one should be used then?

The optimizer removes unused internal functions from the bytecode, so those do not affect deployment cost - see Does importing interfaces increase contract size? - #2 by cameel

And for the setting admin related functions, should I be using the ones that come included or using onlyOwner from OwnableUpgradeable ?

This depends on your proxy pattern.

Also, the ERC1967Proxy which will be used to point to the UUPS implementation seems to have similar functions in both the proxy and implementation contract in it. For eg, ERC1967Upgrade.sol at here and ERC1967UpgradeUpgradeable.sol at here .

ERC1967Upgrade is an abstract contract for interacting with ERC1967 storage slots, so it is used by both proxy and UUPS implementation contracts. Normally you would not need to interact with its functions directly, but just use the ones exposed in the proxy or UUPS implementation. And as mentioned above, unused functions are removed from bytecode by the optimizer.

1 Like