Grubs gnaw roots, maggots munch fruits and caterpillars chew leaves. In textbook food chains, animals eat plants, not the other way round.

But there are plant species that break this rule – at least 600 species of them on the last count. These are the carnivorous plants, and they routinely feast on insects, spiders, worms – even potentially small mammals.

Life for a carnivorous plant is challenging. They cannot very well march across the landscape in search of a meal. Dinner has to come to them. The plants have evolved sticky leaves, water pots and the like to catch animals, but how – if at all – do they lure their prey into these traps?

A study published in February 2016 shows for the first time that some carnivorous plants use smells to secure meals – validating an idea that Charles Darwin suggested 140 years ago.

Darwin worked on the sundews, a type of predatory plant with leaves covered in tentacles, each tentacle having a drop of sticky fluid at its tip. Darwin described the sticky leaves as "temporary stomachs" with which the plants catch live prey, break it down with acids, and "feed like animals".

Surprised by the large numbers of insects caught in sundew traps, Darwin suspected that the plants release odours that attract insect prey to their sticky leaves – although he did not test the idea.

In fact, nobody thought to explore Darwin's hypothesis for over a century.

"It's common to analyse plant volatiles, so it's quite amazing that nobody has tested Darwin's hypothesis," says chemical ecologist Ashraf El-Sayed at the New Zealand Institute for Plant & Food Research Limited.

Studying sundews in New Zealand, El-Sayed's team found that one species, Drosera auriculata, uses smells to lure prey. Their leaves emit volatiles that beckon gnats, midges and mosquitoes.

Carnivorous plants face a more profound problem: sex

"I was working on lure-and-kill tactics in pest management when I realised that wow, carnivorous plants have been at it for a very long time," says El-Sayed.

Carnivory evolved independently at least six times across the plant kingdom. Carnivorous plants live in places like bogs and rocky slopes where the soil – if there is any – is so nutrient-poor that few plants can survive. Carnivorous plants eke out a living here because they converged on the same solution to the nutrient problem: animals are nutritious, so eat them.

But the path to meat-eating is costly. As plants transform their leaves into traps that can trick, bind, drown, and digest prey, they gradually become less effective for harnessing sunlight to produce energy. Therefore, most carnivorous plants grow slowly and stay small.

Beyond that carnivorous plants face a more profound problem: sex.

Like many plants, carnivorous plants produce flowers when they are ready to reproduce. Most of these flowers appear suitable for insect-pollination – again, in keeping with many plants.

The trouble is that many carnivorous plants trap and kill insects. They are faced with a unique dilemma called "pollinator-prey conflict": they need to eat insects without jeopardising their chances of being pollinated by insects.

The most obvious way to protect pollinators is to keep flowers away from traps

For example, a carnivorous plant from Spain called Pinguicula vallisneriifolia could produce more seeds if its flowers receive more pollinators. But sticky leaves mere inches away from the flowers kill a good number of those pollinators.

The carnivorous plant's challenge is to avoid confusing the insects it needs to eat with the insects it relies on for pollination. Studies suggest that most carnivorous plants handle this challenge very well. There is often very little overlap between the insects visiting flowers and those dying in traps.

Somehow, carnivorous plants can separate pollinators from prey.

The most obvious way to protect pollinators is to keep flowers away from traps. Some carnivorous plants do this by making sure their flowers bloom and die before the traps open. A field survey of 560 Sarracenia alata pitcher plants found only five with flowers and pitchers active at the same time.

Many carnivorous plants seem to spare their pollinators

There is another option. One-third of carnivorous plants have removed all risks of pollinator-prey conflict by growing their traps underwater and keeping their flowers above ground. Many carnivorous plants also raise their flowers on long stalks. Some researchers speculate that long stalks serve to distance pollinators from traps.

But the role of long stalks in protecting pollinators remains debated. Some plants extend their flowers on stalks even though pollinators cannot reach their traps: bladderworts (Utricularia), for instance, have stalked flowers despite the fact that their traps lie underground.

Furthermore, a survey of more than 50 sundew species found that plants closer to ground grow longer stalks than those higher up. Some scientists argue that carnivorous plants evolve long stalks to better attract flying pollinators rather than to better protect them.

Whether or not their flowers are far from traps, many carnivorous plants seem to spare their pollinators. This suggests that the plants have another way to mitigate pollinator-prey conflict.

We suspected that the plants might be using other cues to guide the insects

"We studied three sundew species with different distances between flowers and sticky leaves," says El-Sayed.

The sundews were lethal – less than 20% of insects caught on leaves escaped. But in all three species, less than 5% of insects caught on leaves were also found in flowers.

"We suspected that the plants might be using other cues to guide the insects," says El-Sayed.

El-Sayed found that Drosera auriculata – the species whose flowers grow closest to its leaves – has flowers that smell distinct from its leaves.

El-Sayed then exposed insects to synthetic blends of these odours. He found that flower odours attract floral visitors – insect pollinators – while leaf odours deter them. Only insects that the sundews usually eat are attracted by the leaf odours.

Some of these chemicals might help us manage pests

This means D. auriculata is the first carnivorous plant known to use odours both to lure prey and protect pollinators.

However, the other two sundews in El-Sayed's study, D. spatulata and D. arcturi, have scentless sticky leaves and flowers that grow further apart. Floral visitors prefer the white colour of flowers, while prey do not discriminate between flower and trap colours.

So instead of smells, D. spatulata and D. arcturi use visual signals and separation to protect pollinators.

"D. spatulata and D. arcturi grow in open sites. Their flowers are often the highest points around," says El-Sayed. Potential pollinators flying by would likely find the flowers easily even without odours. "Investing in odours to guide pollinators would not be cost-effective in these sundews."

D. auriculata is the first carnivorous plant known to use odours both to lure prey and protect pollinators

El-Sayed hopes that the discovery of carnivorous plant odours will stimulate new research and applications for the chemicals.

His team has now begun studying a pitcher plant that emits even more complex and distinct smells than those he found studying sundews. "Who knows? Some of these chemicals might help us manage pests," he says.

Carnivorous plants so captivated Darwin that he called them "the most wonderful plants in the world". After tens of millions of years of juggling hunger and sex, these wonderful plants have evolved into effective and selective killers. Their adaptations could well be a treasure vault that we have just begun to unlock.

Join over five million BBC Earth fans by liking us on Facebook, or follow us on Twitter and Instagram.

If you liked this story, sign up for the weekly features newsletter called "If You Only Read 6 Things This Week". A handpicked selection of stories from BBC Future, Earth, Culture, Capital, Travel and Autos, delivered to your inbox every Friday.