The Design of a Self-Compiling C Transpiler Targeting POSIX Shell
dl.acm.org
dl.acm.org
Full steps on https://github.com/fosslinux/live-bootstrap/blob/master/part...
There is a problem if you want to verify using the C source though (assuming the resulting shell script is as inscrutably as binary executable). Even if you use pnut.sh to compile pnut.c and see that you get the correct output, or even include GCC in the chain, you're still (afaict) susceptible to a "trusting trust" attack on the original pnut.sh .
> assuming the resulting shell script is as inscrutably as binary executable
It's quite the opposite, pnut generates shell code that's close to the original C code to make it easy to audit the code. A useful way to see pnut is as a tool that rewrites C code to POSIX shell, without significantly changing the structure.
This means that even if GCC is required for the initial compilation of pnut (GCC compiles pnut, then pnut compiles itself and we get the pnut-sh.sh script), the script can be "sanitized" from trusting trust attacks by simply comparing the script to the C code and making sure GCC hasn't introduced any malicious code.
Page 10 of the SLE24 presentation has a tombstone diagram showing the compilation steps to go from pnut's C code to a GCC binary: https://github.com/udem-dlteam/pnut/blob/main/doc/presentati...