A novel plasma-wall instability and the distribution of halo currents in tokamaks