I assume you are jailbroken at 3.0 to proceed to jailbroken 4.0
Since apple is not signing 4.0 anymore, restore to a custom firmware 4.0.
Things to download :
3G 4.0 ipsw from here : iClarified - iPhone - Where To Download iPhone Firmware Files From
SnowBreeze 1.6.2 or 1.7 OR Pwnage tools 4.0.1
Build your custom firmware and it will be placed on the desktop.
Put your Iphone into Recovery mode. ( Turn off iphone, while holding the Home button, plug your iphone into the pc until you see the itunes cable logo)
Shift + Restore to the custom firmware of iOS 4.0
Let it restore, when done you are jailbroken at 4.0
Install Ultrasn0w from Cydia.
You are all set