It is within the bounds of the constitution to collect forensic data of every gun sold and connect that data to an ID number printed on the gun (and by extension, make unlawful the removal of those numbers). It would also be constitutional to register those guns to their owners in a national database (and guess who has such a database? Our "friends" the NRA!).
Which part of the constitution provides the federal government with this ability?
It is not prohibited, and state governments can do whatever the hell they want as long as it isn't explicitly prohibited. The federal government can probably get away with it as well because of interstate commerce.
If we were to take it even farther, it would still be constitutional to restrict the sale of all firearms to registered state militia only, placing safety and security restrictions on those militia.
And by denying membership to the state militia to only people you want to have guns, you basically remove any affect the 2nd amendment might have had in restricting what the government could do.
...
There would be mass looting. Do you really want guns in the hands of non-militia members when the time comes to bear our arms?
Yes, because I am not in the national guard, and for all I know, it may be the national guard that we are fighting if that time actually comes.
Registered state militia does not have to mean government. A militia is by definition a very local group, and I would expect to see them form at the town level, or in large cities at the district level. Militias, then, could have anybody they want based solely on the desires of the local people in charge (and who that is would ideally depend on local democracy). With possible exceptions for violent felons and the mentally unstable, which would go along with reasonable safety and security regulations to make sure, among other things, that the militia armory is appropriately secured from theft.
I would like to see super deadly weapons restricted as well. Which is why I would like to see the 2nd amendment changed. But what I think is pretty obvious is that the founding fathers did not want the 2nd amendment to be interpreted in such a way that it places no meaningful restrictions on what the government can do in terms of prohibiting weapons.
In the same way that the 1st amendment was probably not meant to be interpreted as allowing the government to decide when speech could be criminalized, and as long as some speech is allowed (e.g. speech that praises the president), then it is not a violation of the 1st amendment, because you are still free to say whatever you want except the things that are illegal.
I think that everything I have said is consistent with the United States government having meaningful restrictions on how it can infringe upon the right to bear arms and the right to free expression. But "meaningful restriction" does not mean "total restriction". The 2nd amendment was written with an explicit purpose, it is my belief that any restriction on gun ownership and use may be constitutional as long as it is still possible to form a well-regulated militia with meaningful self-defensive force.