Used by humans as a stimulant and anesthetic for thousands of years, the drug commonly known as cocaine has been carefully shaped by species of the coca plant (Erythroxylum) over tens of millions of years in an arms race against hungry insects.

Knowing just how the plants pull off this feat of chemical engineering would be a big win for the pharmaceutical industry while helping biologists better understand the evolution of similar pesticides across the plant kingdom.

Yet the sheer complexity of the chemical's production has been one of nature's best-kept secrets, one that scientists have spent the better part of a century untangling.

Now, researchers from China's Kunming Institute of Botany have finally uncovered the last major steps of the biosynthetic process.

Not only did they more or less map the biochemical pathway of cocaine's production, but the researchers also reconstructed the entire chain inside a humble tobacco plant for good measure.

The process of forcing tobacco to churn out cocaine is unlikely to ever improve on current methods of production, nor provide any serious advances on new ways to spin out stimulants.

But a similar method involving bacteria or yeast could one day revolutionize the way we design and industrialize pharmaceuticals.

Cocaine is a member of a class of organic molecules known as tropane alkaloids. A whole family of plants evolved ways of making these chemicals to thwart herbivores, and in turn, we humans have taken advantage of the incidental effects they have on our own biology.

Hyoscyamine, for instance, is a tropane alkaloid. Made by deadly nightshade (Atropa belladonna), we've used hyoscyamine medicinally to dilate our pupils, paralyze our spit glands during surgery, and treat our fluttering hearts for more than a century.

The history of cocaine use could be a longer one, from chewing coca leaves for an energy boost since ancient times to using it as a topical anesthetic in modern surgery to its psychoactive effects in the form of an illicit recreational drug.

Chemically speaking, cocaine has a lot in common with hyoscyamine, with a recent discovery that both emerge from the same precursor – a molecule called 4-(1-methyl-2-pyrrolidinyl)-3-oxobutanoic acid (or MPOA for short).

The structural difference between the two molecules is subtle but critical, though just how Erythroxylum mitigates the crucial transformation from MPOA to cocaine has until now remained a mystery.

Fortunately, the small contrast in molecular structures was enough for researchers to confine their search to a particular group of proteins, leading to the discovery of a pair of enzymes dubbed EnCYP81AN15 and EnMT4.

The molecular origami each is responsible for not only fills in crucial steps on how cocaine arises out of a convoluted chemical production line but reinforces the relationship between two pharmacologically significant plant compounds.

There remain a few small holes in the map, though researchers are confident enzymes well known to biochemistry could easily do the job.

To demonstrate this, they plugged six cocaine-production genes into the tobacco plant, Nicotiana benthamiana, leaving the genetic hybrid to fill in the gaps using its own versions of the suspected enzymes.

Sure enough, the engineered tobacco plants generated cocaine, providing rough proof that the team had a working knowledge of how cocaine is made.

Putting aside questions of how it might impact its illicit manufacture – if at all – the knowledge could have profound implications for the pharmaceutical industry, allowing researchers to tweak the formula and potentially uncover new bioactive compounds with far more efficiency.

Derivatives of cocaine, such as cocaine hydrochloride, have been approved for use by the FDA as local anesthetics as recently as 2020, demonstrating this age-old stimulant is far from a relic of history.

This research was published in Journal of the American Chemical Society.