RAPO-Sol: Retrieval-Augmented Preference Optimization for Repository-Level Solidity Code Generation
Rongcun Wang, Shi Chen
Key points
From the paper's conclusion- We present RAPO-Sol, a two-stage training framework for repository-level Solidity code generation.
Abstract
Smart contracts written in Solidity manage assets, permissions, and irreversible state changes, making code generation both useful and security-critical. Repository-level Solidity generation is challenging because models must synthesize complete contracts or libraries while preserving consistency across state variables, modifiers, events, inheritance, external calls, and access-control logic. We present RAPO-Sol, a two-stage training framework for repository-level Solidity code generation. First, Retrieval-Augmented Fine-Tuning (RAFT) augments each training input with similar Solidity examples, helping the model learn recurring contract-level patterns while remaining retrieval-free at inference time. Second, Direct Preference Optimization (DPO) trains the model to prefer reference contracts over close but semantically flawed alternatives. We construct rejected samples using Solidity Semantic-Anchor Perturbation (SAP), which perturbs validation statements, visibility modifiers, data-location keywords, context variables, payment operations, and low-level calls. Experiments on SolidityBench with CodeLlama-7B-Instruct, DeepSeek-Coder-6.7B-Instruct, and Qwen2.5-Coder-7B-Instruct show that RAFT consistently improves over supervised fine-tuning, while SAP-based DPO provides further gains in BLEU and SolidityScore. The full RAFT+DPO pipeline achieves the best performance across all three models, demonstrating complementary benefits from retrieval during training and Solidity-aware preference optimization without adding retrieval cost at inference.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- SmartCoder-R1: Towards Secure and Explainable Smart Contract Generation with Security-Aware Group Relative Policy OptimizationProceedings of the ACM on software engineering. · 2026
- SecureFlow: An LLM-Based Multi-Agent System for Automated Smart Contract Vulnerability Detection and PatchingJournal of Cybersecurity and Privacy · 2026
- Augmenting Smart Contract Decompiler Output Through Fine-Grained Dependency Analysis and LLM-Facilitated Semantic RecoveryIEEE Transactions on Software Engineering · 2025
- Augmenting Multi-technique Static Analysis with Large Language Models: A Neuro-symbolic Approach to Smart Contract Vulnerability DetectionProceedings of the ACM on Software Engineering · 2026
- LLM See, LLM Do: Enhancing Repository-Aware Code Generation in LLMs Through Logical Context and Usage KnowledgeACM Transactions on Software Engineering and Methodology · 2026
- Large-scale Repository Engineering via Agent-Native Reusable Code PrimitivesarXiv · 2026