iPhone 2G/3G/3GS 3.1.3 - Sn0wbreeze
To start if you havn't already, don't upgrade to 3.1.3 yet! It's a lot more trouble than 3.1.2 and you might lose your unlock. Just to keep it simple don't upgrade until a better unlock and jailbreak becomes available. If you already upgraded use this guide below....Sn0wbreeze 3.1.3 can jailbreak iPhone 2G, 3G and iPhone 3GS on 3.1.3 firmware. It will work with iPhone 3GS only if it has the older bootrom, non-MC model.
How do I know what bootrom I have?
Check your model number, if it begins with "MC" then you have the new bootrom if it is not "MC" then you have an older bootrom also check the 4th and 5th number in you serial number if it is lower then 40 then you have an old bootrom.Settings->general->about, scroll down to model number and check. The first two numbers in the serial are the factory numbers, the third number is the year it was made and the two numbers following those numbers are the week of that year it was made.
Follow this step by step guide to jailbreak your iPhone 2G, 3G and iPhone 3GS