Skip to main content

Module edgecov

Module edgecov 

Source
Expand description

Compiler-instrumented edge coverage and comparison logging through the EDGECOV and CMPLOG opcodes.

Coverage builds of a compiler emit PUSHn <id>; EDGECOV on every control-flow edge and PUSHn <site << 8 | cmp opcode>; CMPLOG right before every EQ, LT, GT, SLT and SGT. Both opcodes are otherwise undefined. Foundry’s EVMs carry them in their opcode tables, but they fail as undefined opcodes unless an EdgeCovGuard is alive on the thread.

While it is, EDGECOV pops the edge ID and bumps its AFL NeverZero hit counter, and CMPLOG pops its tag and records the two words below it, the operands of the comparison that follows. Both refund the 3 gas of the PUSH the compiler emits before them, so a probe costs no gas once it ran. Hits and operands are kept per thread in dense tables indexed by ID, and taken once the call ends.

Structs§

CmpOperands
A comparison operand pair captured during execution.
EdgeCovGuard
Executes the instrumentation opcodes on this thread while alive, recording edge hits when edges is set and comparison operands when cmp_log is set.
InstrumentedEdgeHit
One instrumented edge hit during a call: its ID and AFL-style hit counter.

Constants§

MAX_CMP_LOG_SITES
Maximum number of unique comparison sites tracked per call for CmpLog-style feedback.
MAX_CMP_OBSERVATIONS_PER_SITE
Maximum number of comparison operand pairs tracked per site. This matches the downstream loop detection threshold so a hot loop can be classified without filling the whole log.

Functions§

take_cmp_log
Takes this thread’s comparison operands.
take_edges
Takes this thread’s edge hits in first-hit order.