Current code generation benchmarks measure functional correctness on well-formed inputs, as test cases are curated to satisfy input preconditions. This leaves a gap: generated programs may appear correct but fail to satisfy contracts -- assertion-level validity constraints for rejecting ill-formed inputs. We introduce ContractEval, a benchmark for evaluating contract-satisfying assertions in code generation, i.e., whether code rejects contract-violating inputs by triggering intended assertions. Built on HumanEval+ and MBPP+, ContractEval augments each task with contract-violation tests derived from reference assertions. We synthesize these via a neuro-symbolic pipeline: an LLM converts assertion clauses into constraints, and an SMT solver enumerates satisfiable violation combinations to generate inputs that violate selected clauses while satisfying the rest. Across five code LLMs, standard prompting yields 0% contract satisfaction, while adding a few contract-violation examples boosts contract satisfaction to 49--53% while maintaining pass@1 by 92% of the original. Our code is available at https://github.com/suhanmen/ContractEval.


翻译:当前代码生成基准主要衡量程序在格式良好输入下的功能正确性,因为测试用例通常被设计为满足输入前提条件。这导致了一个空白:生成的程序可能看似正确,却未能满足契约——即用于拒绝格式不良输入的断言级有效性约束。我们提出了ContractEval,一个用于评估代码生成中契约满足性断言的基准,即检验代码是否通过触发预期断言来拒绝违反契约的输入。该基准基于HumanEval+和MBPP+构建,通过从参考断言派生的契约违反测试对每个任务进行增强。我们采用神经符号化流程合成这些测试:首先使用大语言模型将断言子句转换为约束条件,随后通过可满足性模理论求解器枚举可满足的违反组合,从而生成违反选定子句同时满足其余子句的输入。在五个代码大语言模型的测试中,标准提示方法产生的契约满足率为0%,而添加少量契约违反示例可将契约满足率提升至49–53%,同时保持原始任务通过率(pass@1)的92%。我们的代码发布于https://github.com/suhanmen/ContractEval。

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
专知会员服务
34+阅读 · 2021年5月8日
专知会员服务
16+阅读 · 2021年1月23日
智能合约的形式化验证方法研究综述
专知
16+阅读 · 2021年5月8日
最新论文解读 | 基于预训练自然语言生成的文本摘要方法
微软研究院AI头条
57+阅读 · 2019年3月19日
论文浅尝 | Global Relation Embedding for Relation Extraction
开放知识图谱
12+阅读 · 2019年3月3日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
相关VIP内容
专知会员服务
34+阅读 · 2021年5月8日
专知会员服务
16+阅读 · 2021年1月23日
相关基金
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员