Gold should be uniformly scattered throughout the Earth's crust, not in giant deposits, because it is unreactive. It is one of the most inert metals in the whole Periodic Table, it doesn't easily react with other substances, so it should not have come together in sufficient quantity to mine.

Yet it did, and became prized for its purity and stability and later for its rarity. It's still rare. The World Gold Council estimates that all the gold ever mined in the world would fit into a 20x20x20-meter cube. 

Chemists may have found an answer as to why it should not form into deposits yet did, and it may also explain why many gold miners were at risk from arsenic poisoning.

Scanning electron microscopy photomicrograph showing gold microparticles (bright color) deposited with pyrite crystals from a hydrothermal solution in a laboratory experiment. Image: 
Maria Kokh and Gleb Pokrovski

Gold has been found for centuries near arsenic. The Salsigne mine near Carcassonne was one of Western Europe's largest gold mines, and the world's largest arsenic producer. Gold nuggets are rare but an appreciable amount is bound up with minerals, such as iron- and arsenic-containing minerals like pyrite and arsenopyrite. These minerals act sort of like a sponge, and are capable of concentrating gold up to a million times more than is found elsewhere in nature, such as in the hot spring waters that transport the gold. This gold becomes chemically bound in these minerals, so it is invisible to the naked eye. 

A team studied the action of the gold-concentrating minerals using X-rays at the European Synchrotron (ESRF) at Grenoble in France, which can probe the chemical bonds between the mineral and gold and found that when the mineral is enriched with arsenic, gold can enter the mineral structural sites by directly binding to arsenic (forming, chemically speaking, Au(2+) and As(1-) bonds), which allows gold to be stabilized in the mineral. However, when the arsenic concentration is low, gold doesn't enter the mineral structure but only forms weak gold-sulfur bonds with the mineral surface.

They found that arsenic drives the concentration of gold. This arsenic-driven gold pump explains how these iron sulfides can massively capture and then release gold, so controlling ore deposit formation and distribution. In practical terms, it means that it will make it easier to find new sources of gold and other precious metals, which bind to arsenic-containing iron sulfides.