Performs abstract interpretation over source code to infer possible program states, variable ranges, and data properties without executing the program. Reports potential runtime errors including out-of-bounds accesses, null dereferences, type inconsistencies, division by zero, and integer overflows. Use when analyzing code for potential runtime errors, performing static analysis, checking safety properties, or verifying program behavior without execution.
Install with Tessl CLI
npx tessl i github:ArabelaTso/Skills-4-SE --skill abstract-state-analyzer94
Does it follow best practices?
Validation for skill structure
This skill performs abstract interpretation to statically analyze source code and infer possible program states, variable ranges, and data properties. It identifies potential runtime errors without executing the program.
Analyze the code to identify:
Choose appropriate abstract domains based on the analysis goals:
Interval Domain: Track numeric variable ranges
x ∈ [0, 100] means x is between 0 and 100Sign Domain: Track whether values are positive, negative, or zero
Null Domain: Track whether pointers/references can be null
Type Domain: Track possible types of variables
Combination: Use multiple domains together for more precise analysis
Set initial abstract values for:
Example:
def process(arr, index):
# Initial state:
# arr: not-null (assumed)
# index: ⊤ (unknown integer)Propagate abstract states through the program:
Assignment: Update abstract value
x = 5
# x: [5, 5]
y = x + 3
# y: [8, 8]Conditionals: Split into branches
if x > 10:
# Branch 1: x ∈ [11, ∞]
else:
# Branch 2: x ∈ [-∞, 10]Loops: Iterate until fixpoint
i = 0
while i < n:
# Iteration 1: i ∈ [0, 0]
# Iteration 2: i ∈ [0, 1]
# ...
# Fixpoint: i ∈ [0, n-1]
i += 1Join Points: Merge states from multiple paths
if condition:
x = 5 # x: [5, 5]
else:
x = 10 # x: [10, 10]
# After join: x ∈ [5, 10]Check for violations at each operation:
Array Bounds:
arr[index]
# Check: index ∈ [0, len(arr)-1]?
# If index: ⊤ → Potential out-of-bounds
# If index: [0, 5] and len(arr) = 10 → SafeNull Dereference:
ptr.field
# Check: ptr is not-null?
# If ptr: maybe-null → Potential null dereferenceDivision by Zero:
x / y
# Check: 0 ∉ y?
# If y: [1, 10] → Safe
# If y: [-5, 5] → Potential division by zeroInteger Overflow:
x = a * b
# Check: a * b within type bounds?
# If a: [1000, 2000], b: [1000, 2000] → Potential overflow for int32Type Inconsistency:
result = func(arg)
# Check: arg type matches parameter type?For each potential error, report:
def find_max(arr, n):
if n <= 0:
return None
max_val = arr[0]
i = 1
while i < n:
if arr[i] > max_val:
max_val = arr[i]
i += 1
return max_valAnalysis:
Initial State:
Line 2: if n <= 0
Line 3: return None (Branch 1)
Line 5: max_val = arr[0] (Branch 2)
Line 6: i = 1
Line 7: while i < n
Line 8: if arr[i] > max_val
Line 10: i += 1
Report:
POTENTIAL ERRORS FOUND:
1. Out-of-Bounds Access
Location: line 5, arr[0]
State: n ∈ [1, ∞], arr length unknown
Severity: Potential
Explanation: Array 'arr' might be empty when n > 0
Suggestion: Add check: if len(arr) == 0 or add precondition
2. Out-of-Bounds Access
Location: line 8, arr[i]
State: i ∈ [1, n-1], arr length unknown
Severity: Potential
Explanation: If n > len(arr), accessing beyond array bounds
Suggestion: Add precondition: n <= len(arr) or check i < len(arr)When loops don't converge quickly, apply widening:
# Instead of: [0, 0] → [0, 1] → [0, 2] → ...
# Widen to: [0, ∞]For called functions, use summaries instead of full analysis:
def helper(x):
# Summary: returns x + 1, no errors
return x + 1
# Use summary instead of analyzing helper bodyFor complex conditionals, track path conditions:
if x > 0 and x < 10:
# x ∈ [1, 9] (path-sensitive)
# vs x ∈ [-∞, ∞] (path-insensitive)For detailed information on abstract interpretation techniques and domains:
0f00a4f
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.