In the end, well, the beginning of the end starts with Martin Sheen's character risking his life to save Costigan. In return, Sheen's character is thrown off of the roof only to land right in front of a stunned, fearful, and disheveled Costigan. Costigan looks at the body, freaks, and regroups with the people (Costello's other henchmen) who did it.
While in the Bar with the man who was shot, Costigan learns that the terminal man knows that he's the rat. The man dies, so Costigan is saved. Long story short, Sullivan learns that Costello is an FBI informant (can't remember exactly when), but it compels him to allow Frank to embark on a very 'hot' or incriminating situation. (his vehicles were loaded w/ coke I think. . .can't remember)
Costello and his men are confronted by Sullivan/a State trooper task force; Costigan felt suspicious about the meeting, so he fled immediately prior to the invasive raid that happens. It's a classic Scorcese blood-bath, and every bad guy tastes some steel vengeance. There's a scene where Sullivan[Damon's character] confronts Costello[Nicholson], and is infuriated at the old man for not divulging that he is a rat.
[Apparently, Costello had been an FBI informant for years, and it was the major reason why he never saw any jail time. The respective law-enforcement agencies do not communicate thoroughly, so no person in the Boston SIU knew about this. It also keyed the viewer in to the reason why Costello - not only Costigan - was afraid{although Costello showed his fear through irrational violence}, and starting to unravel. He knew that he was also a 'rat'.]
Sullivan shoots Costello, and the officers assume that it was in self-defense. The spotless kid, who's been groomed to be a mole, is promoted.
Now, Costigan knows that 1 of the 2 men, who were aware of his circumstances, is dead, so he's in a bad state of mind. I can't remember exactly how Costigan gets in contact with Sullivan, other than the cell face-off, and going to the Police station to get his story straight. In there, he actually is speaking to Sullivan, who's been appointed as an incumbent replacement for the late character of Sheen. Remember the envelope with the census of Costello's men, that everyone including Costigan filled out? Costigan sees that exact envelope on the table of Sullivan's desk. He flees the police station yet again, as Sullivan (knows of Costigan at this point) is erasing Costigan's police records.
Costigan goes to Sullivan's gf and entrusts her with the official documents that prove who he is. Then, Costigan calls Sullivan and arranges a meeting. When Sullivan shows up(same place where Sheen was killed), Costigan draws his weapon, and attempts to arrest Sullivan. Another officer arrives and there is a face-off - a 2nd arrives - all in all, Costigan is shot, the 1st officer who arrived is shot, and we discover that the 2nd officer was another mole of Frank Costellos.{This man had more workers then a sweat shop} The 2nd officer who arrived, beseeches Sullivan, and tells him that they have to stick together. Sullivan shoots him on sight, and uses him as a scapegoat.
Sullivan ostensibly has remorse for the way Costigan dies, so he goes ahead with his initial plan of recommending the late insurgent for a prestigious honor. At Costigan's funeral, it is mentioned, and Sullivan is sitting across from a painfully, tearful girlfriend who knows everything. (remember the papers that Costigan gave her to open, should anything happen to him?) What would happen next was clearly indicated by her brushing off her boyfriend (potentially the father of her kid/although, it was never specified as to whether it was Costigan's or not). A remorseful/instrospective Costigan returns to his apartment with groceries.
Wahlberg's character received the papers from Sullivan's girlfriend, although, that wasn't shown. He probably gained easy access to the apartment by even taking her key. . .though that was never explained. Sullivan comes home to a bullet in the head. That's the ending. It's not as complete as Infernal Affairs, but it's the most faithful remake that I've ever seen, and had it's own creatively efficient prescence. It's a solid film. I hope that I explained what you were missing. If not, what do you want from me? [Costigan]DO YOU WANT TO CHOP ME UP AND FEED ME TO THE POOR?!?!?![/Costigan]