The present invention relates to macrocyclic compounds of formula (I): wherein W, n, R1, Ra, Rb, R3, R4, M, Z, ring A and ring B are defined herein, and pharmaceutically acceptable salts thereof, pharmaceutical compositions comprising them, and their use for the treatment or prevention of infection by hepatitis C virus.