Casting flux is used to:
It is desirable to use a flux for gold crown and bridge alloys to aid in minimizing porosity. When properly used, the flux increases the fluidity of the alloy and the film of flux formed on the surface of the molten alloy helps prevent oxidation. 
Reducing fluxes containing powdered charcoal are often used, but small bits of carbon may be carried into the mold and cause a deficiency at a critical margin. Although such reducing fluxes are excellent for cleaning old alloy, a better flux for the casting procedure may be made from equal parts of fused borax powder ground with boric acid powder. The boric acid aids in retaining the borax on the surface of the alloy. The flux is added when the alloy is completely melted and should be used with both old and new alloy. Old sprues and buttons from the same alloy may be recast if they are not contaminated.
Reference: PHILLIPS’ SCIENCE OF DENTAL MATERIALS, 12th ed page no 222
Prevent the oxidation of the metal during melting
Increase the melting point of the flux
Prevent the contamination of the metal and the liner
All of the above