I created an onion v3 service and the Tor created three files for it: private and public keys and hostname. The private key is actually contains the public key internally. So why do we need the public key file? Usually the splitting makes sense to share the public key. But for the Tor it looks like doesn't make sense. The actual pubkey sharing is the onion domain itself.
I checked sources and found a big function ed_key_init_from_file() Internally it will load the pubkey and compare with a pubkey from secret key. If the pubkey is not exists then if will "repair" it from a secret file.
https://gitlab.torproject.org/tpo/core/tor/-/blob/main/src/feature/keymgt/loadkey.c#L512
This looks for me as an overcomplication. Basically if the pubkey is not needed then we can skip it's loading, repairing, comparison. I'm using the Tor for access to an old router behind CGNAT. And if we can make the binary smaller, don't waste time and space for the pubkey and keep the NAND flash that would be great.
On the line 511 we are loading the pubkey even if a secret doesn't exists with a comment "We only have the public key; better use that". I can't understand why to do that because without a secret key nothing should work anyway.
And I have and additional questions: Does the Tor recreates the hostname file if only a secret key exists?