Ain't It Funny is written in the key of G Locrian.
According to the Theorytab database, it is the 7th most popular key among Locrian keys and the 79th most popular among all keys. The G Locrian scale is similar to the G Minor scale except that both the 2nd and the 5th notes (A♭ and D♭) are a half step lower. This means that the characteristic "home base" chord of G Locrian has a dissonant diminished quality (g˚), which makes it a very uncommon choice for songs.
See the G Locrian Cheat Sheet for popular chords, chord progressions, downloadable midi files and more!