Hadith 8:3152
Abu Bakr narrated to us, he said: Ibn ‘Ulayyah narrated to us, from Layth, from ‘Ata’ and Tawus, they both said regarding a man who performed eight circuits (of Tawaf): If he remembers before he prays two rak'ahs, he should perform six circuits and pray four rak'ahs. And if he remembers after he has prayed two rak'ahs, he should perform six circuits, then pray two rak'ahs. And if he wishes, he may not count that (Tawaf).
حدثنا أبو بكر قال نا بن علية عن ليث عن عطاء وطاوس قالا في الرجل طاف ثمانية أشواط قال إن ذكرها قبل أن يصلي ركعتين طاف ستة أطواف وصلى أربع ركعات وإذا ذكر بعد ما يصلي ركعتين طاف ستة أطواف ثم صلى ركعتين وإن شاء لم يعتد ذلك