Will flatten contracts save more gas?

Just wan to know will flatten contracts save more gas?
hardhat-etherscan plugin seems to verfiy contract as "multi-file", any option can i choose verify as single-file?

do solidity compile the same bytecode with "single-file" and "multi-file" ?

I don't think it makes sense to speak about gas savings in regard to source code verification. The source you verify is supposed to be the exact same thing you deployed so it should use the same amount of gas.

Flattening itself is not supposed to affect gas usage. In theory it should give you the same exact bytecode as non-flattened contract (the only difference being the metadata hash embedded at the end). In practice it's a modification of the original source so it has some potential to result in a slightly different bytecode if you hit some obscure corner case or even a bug in the compiler. I'd say it's always safer to verify the same exact thing you actually compiled and deployed and that would be the "multi-file" version. Actually, even better if your framework can give you the Standard JSON input because that's the "multi-file" version but packaged into a single JSON file together with all the compiler settings used for compilation (and those can affect bytecode too).

2 Likes