Assuming your devices bootloader is locked and the key hash matches what is shown on the GrapheneOS website then yes, most likely, your operating system is fine and a factory reset will remove any software, including malware, that's not apart of the signed GrapheneOS image. All user data is destroyed during a factory reset as soon as the security chip drops the encryption keys.
Most likely its not an attack, your phones behavior is most likely a software issue related to processing touch or a hardware issue
Factory reset it, install another operating system like the official google OS and try typing, if its still behaving problematically then contact Google for a repair because 99% chance at that point its a hardware issue you should fix.
If it works fine on other operating systems but not on GrapheneOS, write it here so the devs can assist you in a bug report.