一句话:把直接偏好优化扩展到可量化的区块链专用度量,实现智能合约功能、Gas 与安全的多目标联合优化。
大语言模型虽能生成功能正确的 Solidity 代码,但在真实部署同样关键的 Gas 效率与安全性上仍明显不足;现有基于监督微调与直接偏好优化(DPO)的方法把功能正确性、Gas 优化与安全视为彼此独立的目标,生成的合约要么执行成本过高,要么存在危险漏洞。本文提出 PrefGen,将标准 DPO 从人类偏好扩展到可量化的区块链专用度量,实现面向智能合约生成的整体多目标优化,并设计了 Pass@k(功能正确性)、Compile@k(语法正确性)、Gas@k(Gas 效率)、Secure@k(安全评估)四个互补指标的评估方法。实验表明 PrefGen 在所有关键维度上显著优于现有方法,达到 66.7% Pass@5、58.9% Gas@5 与 62.5% Secure@5,可生成功能正确、成本低且安全的可部署合约。
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.
DOI 原文 ·
@inproceedings{paperbot9203,
title = {PrefGen: A Preference-Driven Methodology for Secure Yet Gas-Efficient Smart Contract Generation},
author = {Zhiyuan Peng and Xin Yin and Zijie Zhou and Chenhao Ying and Chao Ni and Yuan Luo},
booktitle = {ASE},
year = {2025},
doi = {10.1109/ase63991.2025.00034}
}