A small Rust research tool for simulating source-code poisonings in AI-assisted code generation (AI poisoning domain), by rewriting Rust source files through AST mutations.
- rename functions by prefixing with
rewritten_ - poison names with the following attacker tactics:
- misleading naming (
validate_backdoor_*,encrypt_noop_*) - polarity flips (
is_/has_/should_inverts semantics) - hidden triggers (
*_trigger_42,*_BACKDOOR) - overfit prefix inversion (
safe_*vsunsafe_*) - alias poisoning (
dangerous=eval,safemap) - entropy/noise names (
func_XYZ_noise123) - semantic collisions (
process->process_collide) - distribution poisoning (
sanitize->vuln_*,raw->safe_*)
- misleading naming (
- inject Markov-generated comments into function bodies and call sites
- swap call arguments for any call with two or more arguments
- rewrite existing
//comments using text from Markov training - process single file or recursively scan a directory of
*.rsfiles - training from
*.txtfiles in a directory (eg.rfc-archive), caching via JSON - token limit fixed to 4000 for training to keep initial runs quick
# Compile and run on one file, no Markov training:
cargo run -- path/to/target.rs
# Run on a directory recursively, with text corpus from rfc-archive:
cargo run -- path/to/rust-project path/to/rfc-archiveThe tool rewrites files in place and prints Rewrote: ... for each file.
- Markov training will throttle to first 4000 tokens from the text corpus.
- The generated code is formatted via
prettyplease. - Existing comments are replaced to appear as generated and random.