codemap icon indicating copy to clipboard operation
codemap copied to clipboard

accuracy(Solidity): measure import graph accuracy and close gaps below 90%

Open JordanCoin opened this issue 1 month ago • 1 comments

Part of #237.

Starting estimate: 75-90% recall. This is an unmeasured guess.

Measure

Run codemap on real Solidity repositories at pinned commits and compare it to ground truth.

  • Suggested ground truth: solc or forge AST output.
  • Report: recall, precision, and whether the coverage status was honest for each file.

Likely gaps to check

remappings, node_modules and lib imports.

Done when

  • Repositories, commits, method and numbers are recorded here.
  • Each miss has a root cause.
  • Recall is at or above 90%, or the remaining gap is one codemap cannot close and its coverage status says so.

JordanCoin avatar Nov 01 '26 11:11 JordanCoin

Solidity import graph accuracy (#249)

Repos: Uniswap/v4-core @ bea7f6d1c11cd5dc4f0d5151ffa37a1c239feee6 (132 .sol, remappings.txt to lib/ submodules, which are not cloned so those are external), OpenZeppelin/openzeppelin-contracts @ b7f748eae2341b9e8e8f85cf966e94476813d168 (430 .sol; remappings.txt maps @openzeppelin/contracts/=contracts/, an intra-project remap) Method: git clone --depth 1, static reading only (no scripts, builds or tests executed). Sample: 30 files per repo via shuf -n 30 with a fixed seed (a sample, not the whole repo). For each sampled file F, codemap --json --importers F (codemap 4.6.3) was compared to a ground-truth importer set. Because 9 s per call ruled out querying every file, the unit is incoming edges to the sampled file. Truth was built by a regex resolver I wrote (tools/truth.py in the local scratch dir) and the disagreements were reviewed by hand. Intra-project edges only. Recall = TP/(TP+FN), precision = TP/(TP+FP) over edges. Honesty = whether coverage_status for a sampled file with a miss was something other than complete. Auto-written .codemap/config.json only lists were checked and include the target language. Truth = relative imports plus remappings.txt prefix rewriting, resolved to in-repo files.

repo sampled TP FP FN recall precision files with a miss miss under complete
v4-core 30 166 0 0 1.00 1.00 0 0
openzeppelin-contracts 30 63 0 3 0.95 1.00 3 3

Honesty: v4-core fine. In openzeppelin-contracts all 3 misses were reported under complete (worst case).

Root cause (only one found): remappings are not read. grep for "remapping" in scanner/*.go (non-test) returns nothing. Example: test/utils/Blockhash.t.sol:5 import {Blockhash} from "@openzeppelin/contracts/utils/Blockhash.sol" should resolve to contracts/utils/Blockhash.sol; codemap has no edge. Whole-repo count from my resolver: 71 of 899 truth edges (8 percent) originate in the 32 .t.sol files and all are remap-dependent; the sample hit 3 of them (3 of 66 sampled-target edges). Expect worse in repos that remap src aliases to in-repo dirs. Fix size: medium (parse remappings.txt and foundry.toml remappings, rewrite prefix before resolution; also hardhat/node_modules cases not tested). Interim: coverage should say partial when a remappings file exists.


Measured with codemap 4.6.3. Sampled numbers are samples, not a census.

JordanCoin avatar Nov 01 '26 11:11 JordanCoin