If one performs a commandment through a sin, it is as if he hs not performed that commandment.
A typical case is when a person steals a Lulab on Sukkoth and uses it for the Na'anu'im, it is considered that he has not fulfilled his obligation. The Shulhan 'Arukh also says that if someone eats stolen Massa (matzah) on Pesah, he has not fulfilled his obligation.
A question is asked in Torah Lishmah about a guest at a Seder who was given Massa which was stolen. The guest had no reason to suspect this and ate it. Has he fulfilled his obligation?
The answer is based on the laws of reading Shema' Yisrael. One may not read the Shema' in an unclean place. If one reads the Shema' in a place which one can reasonably expect to be unclean and later on finds that it was, indeed, unclean, he has to repeat the Shema' because he did not fulfill his obligation. However, if the person had no reason to suspect that the place was unclean and later on found that it was, in fact, an inappropriate place in which to read the Shema', he does not have to repeat it since he had no reason to suspect that it was unclean.
So, therefore, in our case, since the guest had no reason to suspect that the host had stolen the Massa, he has fulfilled his obligation and does not have to eat more again.
(See Torah Lishmah, Orah Haiim, Oth Qof Kaf Waw)