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.
- Edge
CovGuard - Executes the instrumentation opcodes on this thread while alive, recording edge hits when
edgesis set and comparison operands whencmp_logis set. - Instrumented
Edge Hit - 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.