To make one thing clear: It doesn't matter what firmware was installed when you made the shsh backup. The version you backup just depends on the date you made it. When iOS4 came out (June?) you have 4.0 shsh backup. After Feb. 2010 and before June 2010 = 3.1.3 shsh backup, before Feb. 2010 = 3.1.2 shsh backup. etc.
If you really have shsh backup for 3.1.2 then you can restore firmware 3.1.2. Search for TinyTSS / Saurik in these forums.
Please note that baseband (modem) won't be downgraded for some reason and remains on 05.13.x. And after downgrade from 4.0 you will get an error message because of that and iPhone is blocked in a boot loop. There are articles to fix this here also.