To downgrade from 4.0 to 3.1.3 this is all you have to do.
1. Download this program:
http://blackra1n.com/ ( there is a windows and mac version)
2. After it is installed, push the button that says make in rain.
3. it will then say "searching for device", put the iphone in DFU mode and the program should then recognize the phone
4. The screen will turn black but not go off, wait about a minute then hold down the home button and the power button until the apple logo shows up.
5. It should take less than a minute to restore and you will then be asked to re-sync.
I went through this last night around 1 in the morning and it worked thank god.