Just done this on my iphone & now running 4.01 - was running 3.1.3 that was JB with Spirit - Oh & I has the new bootrom that has been making JB difficult
Be quick, as apple still sign 4.01, once they stop signing the firmware, you cant do it...
Download firmware 4.01 from
http://www.felixbruns.de/iPod/firmware/Then connect your phone to your puter, launch itunes.
Switch your phone off.
Hold down power button & home button for 10seconds & release only the power button.. your phone will start to boot & go into recovery mode.
Itunes will tell you your in recovery mode.
Click Ok to that message, next hold down shift key on your keyboard & click restore button in itunes.. browse to 4.01 firmware & let it update.
Once all done & updated log onto the website
http://www.jailbreakme.com on your iphone & let it do its stuff...
not my fault if you make your iphone an ibrick