CodeEraser: Tools for Secure Code Erasure
- CodeEraser is a suite of tools and methodologies enabling controlled code and data erasure via segment-level unlearning, multi-scale refactoring, and cryptographic deletion.
- It employs advanced techniques—such as gradient ascent with KL-divergence constraints and AST-based refactoring—to remove sensitive information while preserving core functionalities.
- The framework demonstrates robust empirical results, reducing memorization and contamination risks, and offers IND-Erase secure file erasure confirmed by cryptographic proofs.
CodeEraser refers to a suite of technical tools and methodologies—distinct yet sharing a focus on controlled erasure, refactoring, or removal within code-oriented contexts—introduced across several recent works. The term encompasses advanced toolkits for (1) privacy-preserving segment-level unlearning in code LLMs (CLMs), (2) data contamination mitigation via language- and scale-general code refactoring, and (3) cryptographically provable file erasure based on ransomware-derived primitives. Each solution operates at a different abstraction layer but targets robust, verifiable data or artifact "erasure" within modern computational systems.
1. CodeEraser for Machine Unlearning in CLMs
"CodeEraser" designates a selective segment-level machine unlearning procedure aimed at removing sensitive memorized information from CLMs, such as API keys, credentials, or proprietary sequences. Developed as an enhancement of prior sample-level gradient ascent (GA) and constraint-based unlearning (CU), CodeEraser partitions each targeted example into sensitive segments (to forget) and context (to preserve). The optimization simultaneously maximizes the log-likelihood of (thereby erasing them), minimizes loss on , and constrains model drift via targeted KL-divergence penalties: where control the balance, and is a retained, non-sensitive corpus. Practical implementation restricts token length (512 for forgotten, 128 for context), omits regularization, and achieves batchwise unlearning at ∼47 s per sample on a 7B parameter CLM (Qwen2.5-Coder) (Chu et al., 17 Sep 2025).
Quantitative evaluation demonstrates CodeEraser reduces memorization accuracy (MA) and extraction likelihoods (EL) on high-risk samples by ~94%, while preserving >99% of code-generation utility (as measured by Pass@1, Pass@5, Pass@10 on HumanEval). In contrast, GA and CU baseline methods degrade utility by 10–30%. The segment-level targeting, as opposed to whole-sample erasure, is responsible for the empirical precision and minimal collateral degradation.
2. CodeEraser for Data Contamination Mitigation
Within the context of CLM evaluation, "CodeEraser" also refers to a toolkit that implements a suite of 11 semantics-preserving code refactoring operators, directly derived from the CODECLEANER framework (Cao et al., 2024). These operators operate at method, class, and cross-class level, and include:
| Category | Operator (Example) | Logic Sketch |
|---|---|---|
| Syntactic | If-condition flipping (IFF), Loop transformation, Iter | Invert conditionals, morph loop types, etc. |
| Semantic | Special parameter appending, Identifier renaming (Renm) | Add args/*kwargs, synonym-based renaming |
| Code Style | Normalization (Norm), Naming style switch (Styl) | Unify formatting, switch naming convention |
| Structural | Method shuffling (Shuf), Inherited method appending | Shuffle method order, copy superclass methods |
Effectiveness is measured via raw n-gram overlap (R) with pretraining corpora ("The Stack"), model-wise familiarity (perplexity, Min-20% Prob), and empirically on open CLMs (StarCoder-Instruct, CodeLlama-7B-Instruct, etc.). Application of all 11 Python operators reduces median overlap from 87% to 22% across 384 methods—a 65 percentage-point drop. For Java, a port of four operators gives a 17-point drop (98% to 81%) on class-level code. Model-wise, Min-20% Prob increases by 0.26–0.50, signifying less CLM "memorization" after refactoring.
The toolkit exposes a Python API, command-line interface, and metrics adapter. Industrially, CodeEraser is intended for integration into CI pipelines, CLM benchmarking, and continuous monitoring to mitigate data leakage and contamination risks.
3. CodeEraser for Provably Secure File Erasure
Leveraging principles from ransomware cryptography, the CodeEraser erasure tool is derived from the SEER framework (Shang et al., 16 Apr 2025). The architecture employs a triple-layer scheme for each file:
- Ephemeral Key Exchange: Dual-party Curve25519 ECDH with two CSPRNG-generated ephemeral keys per session.
- Key Derivation: SHA-256 over concatenated pubkeys and shared secret, forming SM_key.
- Stream Cipher Encryption: Sosemanuk stream cipher generates per-block keystream; plaintext is XOR-encrypted in-place.
- Immediate Key Destruction: Ephemeral secrets are securely zeroed in volatile memory post-operation (via
memset), eliminating recovery avenues.
The security guarantee follows the “indistinguishability after key erasure” (IND-Erase) model: provided Curve25519 (IND-CPA), SHA-256 (collision resistance), and Sosemanuk (pseudorandomness) assumptions hold.
Performance benchmarks against DoD 5220.22 overwrite show SEER/CodeEraser is approximately 648× faster on small-file workloads (10,000 × 1 KB: 20 s vs. 12,960 s) and defeats forensic recovery tools. Practical considerations include SSD FTL behavior, hypervisor integration for VM memory, and side-channel/fault-injection threats. Recommendations include syscall-level modularity, audit hooks, and post-erase verification.
4. Comparative Features Across CodeEraser Variants
| Application Layer | Main Mechanism | Performance/Guarantee | Evaluation Highlights |
|---|---|---|---|
| CLM Unlearning | Segment-level GA+KL | 94% sensitive erasure | Utility >99% retained; scalable, precise |
| Data Contamination | Multi-scale AST refactoring | 65% overlap reduction | Model less confident; works for Python/Java |
| Cryptographic Erasure | Triple encryption, key zero | IND-Erase security | 648× faster than DoD, defeats forensics |
Each variant is grounded in rigorous formalism (mathematical losses or cryptographic proofs), prioritizes practical engineering (modular APIs, zeroization, efficient routines), and demonstrates empirically validated guarantees.
5. Limitations, Extensions, and Advisory
Current CodeEraser methodologies show limitations: CLM unlearning relies on regex-based segment identification, so exotic secrets risk escaping erasure; contamination refactors may, in rare cases (e.g., Iter, Comm), increase model familiarity; inherited-method appending in CODECLEANER can raise overlap if superclass code is highly duplicated. For file erasure, cold-boot and side-channel attacks are residual challenges.
Suggested extensions include advanced secret detection (AST, type inference), expansion of refactoring operators to more languages, adaptive operator selection based on initial scans, and theoretical certification of segmentwise unlearning.
Industrially, CodeEraser is recommended for integration into ML Ops and QA workflows to ensure meaningful CLM evaluation, privacy compliance (e.g., GDPR “right to be forgotten”), and resilient data destruction standards. Its technical robustness and multi-layer applicability position it as a critical component for secure, trustworthy software engineering pipelines.