🤖 AI Summary
Existing LLMs generate functionally correct Solidity smart contracts but struggle to simultaneously optimize gas efficiency and security, hindering practical deployment. This paper proposes PrefGen, the first multi-objective joint optimization framework that explicitly incorporates blockchain-specific quantitative metrics—Gas@k and Secure@k—into the Direct Preference Optimization (DPO) paradigm. PrefGen integrates supervised fine-tuning, on-chain metric modeling, and a four-dimensional automated evaluation suite (Pass@k, Compile@k, Gas@k, Secure@k). Compared to single-objective optimization baselines, PrefGen achieves substantial improvements: Pass@5 = 66.7%, Gas@5 = 58.9%, and Secure@5 = 62.5%, enabling direct deployment of efficient and secure contracts. Its core innovation lies in formalizing critical on-chain constraints—functional correctness, gas cost, and security—as explicit preference learning objectives, thereby enabling synergistic optimization across functionality, cost-efficiency, and security.
📝 Abstract
While Large Language Models (LLMs) have demonstrated remarkable progress in generating functionally correct Solidity code, they continue to face critical challenges in producing gas-efficient and secure code, which are critical requirements for real-world smart contract deployment. Although recent advances leverage Supervised Fine-Tuning (SFT) and Direct Preference Optimization (DPO) for code preference alignment, existing approaches treat functional correctness, gas optimization, and security as independent objectives, resulting in contracts that may achieve operational soundness but suffer from prohibitive execution costs or dangerous vulnerabilities. To address these limitations, we propose PrefGen, a novel framework that extends standard DPO beyond human preferences to incorporate quantifiable blockchain-specific metrics, enabling holistic multi-objective optimization specifically tailored for smart contract generation. Our framework introduces a comprehensive evaluation methodology with four complementary metrics: Pass@k (functional correctness), Compile@k (syntactic correctness), Gas@k (gas efficiency), and Secure@k (security assessment), providing rigorous multi-dimensional contract evaluation. Through extensive experimentation, we demonstrate that PrefGen significantly outperforms existing approaches across all critical dimensions, achieving 66.7% Pass@5, 58.9% Gas@5, and 62.5% Secure@5, while generating production-ready smart contracts that are functionally correct, cost-efficient, and secure.