The blocks lose traveled distance when they enter the wall based on how far they entered the wall, because you reset the position to the bounds of the rectangle. Think about the problem in 1D. If you have a line from 0 to 100 and 2 points:

P1 = 90

P2 = 95

If you take movespeed = 7 and apply one frame of your algorithm, then

P1 = 90+1*7 = 97

P2 = 100+1*7 = 107

Then apply 1 more frame for the direction switch

P1 = 97+1*7 = 104

P2 = min(100, 107)-1*7 = 93

Now you can see the points have a separation of 11 instead of 10

Next frame

P1 = min(100, 104) - 1*7 = 97

P2 = 93-1*7 = 86

... So the problem is that the distance traveled in reduced when a cube leaves and enters the bounding rectangle. Remove the lines that clip the position.

    block->sprite->position.x = viewportWidth - block->sprite->width;

and

    block->sprite->position.x = 0;