"I screwed up. What should I do?"
NO. You have not screwed up in any way.
Before I dwell deeper into addressing your specific concerns, I am compelled to throw some light on what a PhD entails, IMHO.
I recently graduated, a bad time to do so when the world is locked down ina pandemic. PhD is a project which teaches a number of skills. A significant skill is, of course, becoming an expert in the very specific and narrow area of your research. But that is NOT the only important skill. In the long run, that is not even most significant.
During your PhD, you do a number of things, like learning to write a research proposal, doing the legwork, managing resources efficiently. Learning to write effectively for conferences, journals etc. If I may take the liberty, you also understand the politics in scientific and technological community. You learn the ethics behind collaborating effectively and sharing credit. You learn the art of conversation and arguing effectively, something you will need during your defence of the thesis. Itis the combination of all these activities (and more) and your skill in doing these which will help you in your career.
Now, since you are so worried about using code from another source ( assuming it was open source), it means that some of the aforementioned skills are still lacking. You need to understand that no PhD work or for that matter any body of work is done from scratch. In fact, in this world, it is foolhardy to do so.
At a stage when you are defending your thesis, why do you put yourself down by worrying about your ability to achieve a successful and rewarding career in the said field of your choice? If you have honestly worked hard and your 20% contribution ( as you pointed out) is good enough for you to successfully defend your PhD, you can also have a career in the same field. More importantly, you have also learnt a number of other significant skills which are crucial for success in any career.
When you are defending your thesis, it is not just the work you have done, but also your ability as a researcher to convincingly present your arguments and address the questions raised by the examiner. That is a skill. You have a written a paper, and got it accepted for publication. That is a skill. So focus on improving each of those skills because all of these collectively make you a good researcher.
So be confident, you have done nothing wrong. Apparently, you are on the right track. Best of luck with your defence.