Did the company B mention it is specifically a sign on bonus ? If yes, its a sign on bonus. Not a payout amount. What you use the sign on bonus for is upto you. However if you had wrongful intent during this process, due to which you got the said amount as bonus, it is best to come clean.
Nevertheless, if I were you, I would drop in a mail thanking company B for the offer and the signing bonus. The mail would also reinstate that 40k was a sign on bonus and that there were no strings attached to it (of course, other than having to pay back a part if you quit within some period of time). I would also put in a point saying it was my mistake to not confirm the exact amount that I would have had to pay to company A. The exact amount is X and I was under the impression it is Y.
For all you know company B gives a sign on bonus to everybody.
EDIT : Just read your edit. I see no need of any clarification. As Chad says "beyond what is already there" and let things be the way they are and let this be a learning lesson for the future.