Algebraic prolongation and rigidity of Carnot groups