This guide provides instruction on how to jailbreak and unlock the iPhone 3GS (old bootrom) firmware 4.0 using Pwnagetool4.01 for OS X by the iphone dev team.
If you are on firmware 3.1.3 and jailbroken with Spirit you can not go directly to jailbroken 4.0.
If your iPhone 3GS has the new bootrom you can not currently jailbreak 4.0.
You can figure out what bootrom you have by running f0recast, if it says Tethered Yes then you can not currently jailbreak 4.0.
You need to be on 3.1.2 firmware and jailbroken. If you need to downgrade back down to 3.1.2 make sure you have you SHSHs on file in Cydia for 3.1.2.
Afterwords simply run blackra1n, edit your hosts file back to normal, and you'll be ready to follow this guide.
If you are on 3.1.3 or 4.0 and can't downgrade to 3.1.2 because you don't have your SHSHs on file you currently can't jailbreak your iPhone 3GS to 4.0.
Now that you're on 3.1.2 jailbroken we're ready to start jailbreaking to 4.0!
Lets first download everything needed.
iPhone 3GS 4.0 firmware
Run PwnageTool 4.01. Click OK.
Select iPhone 3GS, Click the Arrow.
PwnageTool will automatically search your computer for the correct IPSW, if it doesn't find it browse to the one you downloaded earlier, click the arrow.
Click yes to save the custom IPSW on your desktop.
If you are using an iPhone carrier and use iTunes to activate click yes, otherwise if you are unlocking or don't activate with iTunes click no.
PwnageTool does its thing.
PawnageTool will ask you to authenticate, enter in your password and click OK.
Click Ok, then close out of PwnageTool.
Open iTunes. Make sure your phone is off. Plug in your phone while holding the home button. Keep holding the home button until you see the recovery screen on your iPhone 3GS. Option + click Restore.
Browse to and select your custom 4.0 IPSW (on the desktop unless you chose to save it elsewhere). Click OK.
Itunes restores your iPhone.
Set up your phone and you're done!