fix: stackoverflow during proof construction in `grind`

This PR fixes a stack overflow that occurs when constructing a proof
term in `grind`.

Closes 11081
3 files changed