fix: stackoverflow during proof construction in `grind` (#11084)

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

Closes #11081
3 files changed