Debugging Cryptographic Programs
Debugging cryptographic programs can be a challenging task, and many of the bugs you will run into are different than those you may have encountered in previous classes. In this guide, we will outline strategies that can help you identify what might be going wrong. This is not an exhaustive summary, but is rather intended to give a high-level set of approaches that you can apply to all of your projects in this course.
Environment Issues
Environment issues can be extremely annoying to deal with. If you are having trouble with your container, vscode, or anything else related to your coding environment, we suggest you check out the devenv guide. If that does not help, please post on Edstem or come into TA hours!
Autograder Issues
Autograder issues typically come in 2 major forms:
- Failed Tests
- Autograder Timeouts
There are a number of things that can cause these to occur; we highlight some of the most commonly used strategies in the following subsections.
Failed Tests
When a test on Gradescope fails, it will typically include some simple message regarding the problem. For example, the output might say:
Your implementation failed our test: Original: student_cipher.rsa_verify(n, e, m, ta_sig) Evaluated: false
If you see a function being called and it is evaluating incorrectly, then it is recommended you double-check the function listed, as well as any corresponding ones (for example, rsa_verify(...) corresponds with rsa_sign(...)).
Even if the test does not have any specific output that you find useful, the name of the test can provide valuable insights. We have tried to ensure autograder test names provide a high-level overview of what they evaluate, so you can narrow down which section of your code the bug may occur in. If you are ever unsure what part of your program is being tested, feel free to reach out.
Autograder Timeouts
Autograder Timeouts can be particularly challenging to deal with, since you no longer can see what test might be failing, or why it might be failing. To deal with this, there are 3 major things you should look at:
- Ensure that all of your functions
returnsomething. Some of the autograder tests may expect you to return something, and if you don't, then the test suite will not automatically progress. - Watch out for infinite loops. When looping over various values, ensure that your exit condition will actually be met. If you ever get into an infinite loop, the autograder will time out.
- Check to ensure you send and receive all messages exactly in the order described in the stencil code. If you don't properly do this, the autograder may be waiting to send or receive a message, and will never progress and thus timeout.
General Debugging Tips
As with many classes, use of debuggers such as the built-in vscode debugger or gdb in your terminal can be very useful. Stepping through code and making sure things are run exactly in the order you hope is always useful.
Unlike other classes, we also actually encourage you to try debugging via printlines as well. When autograder tests fail, you can see what the most recent printline was and use that to help narrow down the possible location of your bug. Additionally, if running the binaries locally, you can follow the same process to identify the location of potential bugs.
If you are stuck on a specific test, rereading that section of the project handout and ensuring you follow the exact approach described there and in the stencil code comments can often help you identify what is going wrong.