If you are from one of those who updated their device from the 3.1.2 or 3.1.3 OS to the latest iOS4, and then finally found that the device is bricked this article is for you. There are pretty good number of ways to Jailbreak & unlock your device using Ultrasn0w, Redsn0w, Pwnagetool etc, but if none of these Jailbreaking Applications help you out because of incompatible device or baseband issues, then its better to revert back to the original OS 3.1.3 or 3.1.2 which can be unlocked easily with Spirit, QuickPwn, PwnageTool 3.0 etc
To get started you need to first download the latest iTunes application and then the backup restore files which you had used to backup the device before upgrade. You can also download a copy of iPhone OS 3.1.3 in case you dont have a backup copy. In case you want to find out the available backups on your computer you need to search in the following directory.
Windows > C:\Documents and Settings\[username]\Application Data\Apple Computer\iTunes\iPhone Software Updates
Mac OS X > ~/Library/iTunes/iPhone Software Updates
Once you find a file which is something like iPhone1,1_3.1.3_7E18_Restore.ipsw or iPhone1,2_3.1.3_7E18_Restore.ipsw you are confirmed that these are the restore files which you would need for downgrading back and these files have all the data you need to get the phone back in the position it was earlier in. These .ipsw files work like backup Images with complete restore to the previous setup along with the data settings stored in it. When the files location is found you need to proceed towards the downgrading process. In case you still cannot locate this, find out the corresponding file and then save it on your desktop to continue.
Next you will have to Put the Apple iPhone into DFU Mode which can be implemented by performing a series of 5 steps and following which when the iPhone is connected to your Computer, iTunes will display a message saying ‘iTunes has detected an iPhone in recovery mode. You must restore this iPhone before it can be used with iTunes.’
You need to press on ok to dismiss this message and continue towards the restore process once the device is in Recovery Mode. Under the iTunes you will find a ‘Restore’ button which should not be directly clicked because this will make iTunes to restore this to a official 3.1.3 OS. Press Shift + Restore button in Windows or Alt / Option + Restore button click to make iTunes display a popup with a window to choose a custom restore file. You need to now navigate the 3.1.3 OS file you have earlier downloaded and then select it to make the iTunes restore the device to the normal state. This process would include extraction of packages, installation, temporary files removal and then finally the device will be restored after being downgraded from the iOS 4 and would most probably make the device locked displaying a Invalid SIM Message for International users.
Next perform a Jailbreak 3.1.3 procedure to make the device available for any Mobile Carrier and then finally you will have to Restore your Backup, which was earlier generated. Once you connect your Apple iPhone with the iTunes after a final reboot, you will get a message to Restore from the Backup of Amit Bhawani’s iPhone, Phone Number : xxxxxxxx, Last Synced : details. This means that after another few minutes of wait all the data like Music, Photos, Data, Messages, Contacts, Apps etc are completely restored on the downgraded device and there is no loss in the overall process. Enjoy the iPhone Now!

This will not work unless you have saved your SHSH blobs from your earlier setup. Simply trying to replace the current os4 software with the downloaded 313 WILL NOT WORK . You must have saved the SHSH blobs from your earlier installation.