There’s no way for us to know how dogs experience the smell of cake, but a properly trained dog can alert to half a teaspoon of sugar diluted in an Olympic-sized swimming pool. So I’m certain that a dog could tell you whether there are, for example, eggs in a cake. While they probably have a good idea of what a complete cake smells like, they might also be able to discern the list of ingredients.
I had assumed that once a cake had been made, the individual smells of those ingredients went away because now it is all combined and baked. I had assumed drugs or bomb sniffing was different.
I think you’re generally right about that. Certainly, the baked mixture smells very different than the raw one. However, even humans can smell more detail in a baked cake than just, “Oh, a cake.” I’d trust myself to pick out a cake with ground nuts rather than flour, possibly even one with whole-wheat flour vs. regular. I could identify the one vegan cake in a row of cakes with eggs (I think). I have in the past made a cake with butter, and then the same recipe with shortening, and those were quite different as well.
This theory of distinct scents, by the way, is often used to explain why dogs react differently to smells we consider gross. It’s possible that regurgitated or pre-digested meals, for example, simply smell like the different foods consumed. Whereas we, with our much blunter sense of smell, have retained only the ability to detect a warning smell of bacteria which might make us sick. (Of course, part of this is cultural).
If you’d like to read more, I like “What the Dog Knows” by Cat Warren. I also enjoyed “Inside of a Dog”, by Alexandra Horowitz, though that one is a bit more dry. Also, these videos about allergen detection dogs might be interesting to you.
PS: For some fun training with your own dogs, amateur scent detection is pretty exciting.