Al pi [1], according to the testimony of two or three shall something be established.” (Devarim 19:15) With so much power given to the word of witnesses Jewish law does not take kindly to those whose word cannot be trusted. This includes not only known liars, cheats and thieves but even those who we fear may not, to use modern parlance, “tell the whole truth and nothing but the truth.” Thus a gambler is invalidated, not so much because he will purposely not be truthful[2] but rather because “he is not involved in the settlement of the world” and his perspective of what he sees is somewhat skewed (Sanhedrin 24b). To be a credible witness one must be cognizant of the world around him.  While the aforementioned may not testify in a court of law the Torah reserves its greatest punishment for edim zomemim, plotting witness, who are to be given the punishment they had wanted to inflict on the victim. This would include the death penalty for falsely testifying that they were witness to Reuven killing Shimon.  
This is all the more revealing when we realize that in a case of edim zomemim Reuven may have actually killed Shimon, and Reuven may even have confided such to them, but if it is discovered that these "witnesses" were elsewhere at the time of the murder they are declared to be edim zomemim.
 
It is the claim that they actually witnessed an event when they did not that turns them into edim zomemim. Had they made up the entire story and a second pair of witnesses testified that Reuven could not have killed Shimon because Reuven was somewhere else they would be declared “contradicted witnesses” but not edim zomemim. While their testimony would be thrown out there would be no further punishment given to the witness. While inventing a story would seem to be worse the “chidush”, novelty, of the Torah is that such is not so. 
 
While all agree that edim zomemim are untrustworthy and their testimony invalid Abaye and Rava debate (Bava Kamma 72b) exactly at what point they become untrustworthy. 
 
Abaye argues lemafrea hu nifsal, that the witnesses are declared invalid retroactively i.e. from the time of the testimony of the witnesses, not from the time they are declared edim zomemim. If witnesses testify on January 1 that Reuven stole Shimon’s ox and they are discovered to be edim zomemim on March 1 we would declare that all of their testimony beginning from January 1 is invalidated. The Torah tells us that we should not join with the wicked and it is at the moment of their testimony that they have become “wicked”. Getting caught or not has little bearing on the one’s status. 
 
Rava on the other hand argues that the witnesses are only invalidated from the time they are declared zomemim i.e. on March 1. The Gemara explains that the law of edim zomemim is a chidush, a novel law that we would not have known if not for the Torah telling us so. In order to be declared edim zomemim a second set of witnesses must testify that the first set were not where they said they were. But prima facie there is no reason to believe the second set and not the first[3]. As this is the chidush of the Torah we only invalidate from that point on.  
 
However the Gemara gives a second explanation for Rava in which he fundamentally agrees with Abaye that the witnesses should be invalided from the time of their initial testimony. However to do so would create havoc as it would mean all testimony given between the time of the testifying and being caught would be retroactively invalidated. As the Gemara explains there could be a loss to an innocent third party who used these witnesses to sign on some real estate deal which could then be set aside if challenged. To prevent uncertainty in the marketplace the Rabbis declared that witnesses would be declared invalid only from the time their perjury is discovered, grandfathering in testimony given up until that point.   
 
Most interestingly the Gemara does not present a case of even greater havoc, namely that of marriage or divorce. Here retroactively invalidating the witnesses has the potential to create mamzerim. Presumably this is because while the rabbis have almost unlimited power in regards to monetary transactions[4] they generally do not have the power to change Biblical law in the realm of “ritual”. Thus according to this second understanding of Rava a get signed by these witnesses on February 1 would be invalid even according to Rava. 
 
Yet perhaps one could argue that the rabbis were using the more common example of commerce but such “grandfathering” would also apply to marriage and divorce. As the Gemara notes in Gittin (33a) “whoever marries, marries according to the rules of the rabbis” and hence the rabbis have the right to declare when couples are or are not married even when such may not conform to Biblical law. By invoking their power on the laws of marriage and divorce they would prevent a potential nightmare scenario of adultery, mamzerim and the impact on so many.  
  
Yet such discussion as the Rava’s reasoning has little practical application as the Gemara notes that this is one of only six cases where the law follows Abaye and not Rava.

[1] It based on this phrase “al pi, on the mouth of” that our rabbis derive that testimony must be given orally. It is harder to lie when forced to look someone in the eye. 

[2] The Gemara (Sanhedrin 24b) does quote a view that monies taken from another via gambling is a form of theft. This view is ultimately rejected with gambling seen more as a moral failure than a legal wrong. 

[3] As to why then we do believe the second set of witnesses see one explanation here.
 
 [4] This is based on the principle of hefker beit din hefker, that a court can declare money ownerless and bestow it upon others. This fits very well with the modern State’s power of eminent domain which allows governments to expropriate property if they deem such to be in the public interest.