The work done by friction is often calculated just as we would with any force. If we give a block of mass $m$ a velocity $v$ on a rough surface and it comes to rest after traversing a distance $x$, the work done by friction is $-\mu mg$ where $\mu$ is the coefficient of friction between the block and the surface.
Doing so seems reasonable at first sight because it agrees with the expected result we get from applying only Newton's laws.
However, looking at the mechanism of friction on the microscopic level, friction arises from cold welding between the block and the surface particles, which slows down the block. But the work done by the forces that arise due these cold welds cannot be equal to $-\mu m g$, since the point of application of the force isn't shifting at all. In fact, they should do no work (there is probably a flaw in this argument since they apparently do some work because the block slows down).
Looking again at the situation I mentioned above, the ground applies a force $\mu m g$ on the block, and the block applies and equal and opposite force on the ground. If we go by the same reasoning we used to write the work done by friction in the beginning, since the point of application of the force of friction shifts by a distance $x$ on the ground, the block does work $+\mu m g x$ on the ground, which is completely nonsensical.
Where am I going wrong?