by Yu Feng
int sum_n(int n){
int s=0,i=0;
while(i<n){ /* ? */
i++; s+=i;
}
return s;
}
// want s == n*(n+1)/2
contract TokenVault {
mapping(address => uint) balances;
uint totalSupply;
// Invariant: sum(balances) == totalSupply
function transfer(address to, uint amount) public {
require(balances[msg.sender] >= amount);
balances[msg.sender] -= amount;
balances[to] += amount;
}
}
sess->user
object is freed under one thread and later accessed by another, yielding a remote use-after-free (UAF) in the logoff code path.// Initial sketch with missing implementation
int max(int x,int y){
??
}
// LLM-generated sketch with holes
int max(int x,int y){
if (x ??cmp?? y) return ??sel1??;
else return ??sel2??;
}
// Completed implementation after solving
int max(int x,int y){
if (x > y) return x;
else return y;
}
"[email protected]" → "Alice Smith"
"[email protected]" → "Bob Jones"
⋯ 100k similar rows
Capitalize(Replace(Split(email,"@")[0], "_", " "))
Preserve: (1) binary-search order (2) red-black invariants
- int len = strlen(s); // crashes when s == NULL
+ if (!s) return -1;
+ int len = strlen(s);
sess->user
and another thread dereferences it under rare timing conditions.Take-away: Let LLMs auto-patch common "cookie-cutter" defects, but keep formal tools in the loop for concurrency, logic, and other data-sparse bugs.