Edward J. Schwartz commited on
Commit
d60d50d
·
1 Parent(s): 0684174

Describe and color example accordions by expected result

Browse files
README.md CHANGED
@@ -14,8 +14,12 @@ Public Gradio frontend for comparing a binary function with candidate C. Select
14
  an example or upload an ELF x86-64 binary, supply its function address and candidate
15
  source, and stream verification results with assembly previews and a JSON download.
16
  The application includes 60 examples in expandable sections: Basics, Calls and
17
- memory, Types and ABI, Real binaries, Faultless paper, Related work, and Ghidra
18
- exports. Basics starts open; expand any other section to browse its examples.
 
 
 
 
19
 
20
  The verification library is a private GitHub repository referenced by the `core/`
21
  Git submodule. This repository publishes the UI and demo assets. Running verification
@@ -93,11 +97,15 @@ to clone private code before the Docker build. Local developers use the explicit
93
  Startup retains the pinned private core checkout in `core/` after removing its Git
94
  metadata. The UI reads example sources from that checkout and compiles originals
95
  when preparing examples. Local development uses the same loader and submodule.
96
- The Related work section adds nine cases from D-Helix, DiscScope, and Decompile-Diverge,
97
- including a deliberately uncompilable export. See `core/docs/related-work-examples.md`
98
  for provenance, interface adaptations, and published counterexamples.
99
- Reference C is a display aid; uploaded binaries have none. The bundled `factor`
100
- executable and redistribution notices are read from `core/examples/binaries/` and
 
 
 
 
101
  copied together into the prepared example directory.
102
 
103
  ## Publish under the existing Space name
 
14
  an example or upload an ELF x86-64 binary, supply its function address and candidate
15
  source, and stream verification results with assembly previews and a JSON download.
16
  The application includes 60 examples in expandable sections: Basics, Calls and
17
+ memory, Types and ABI, Real binaries, Related work, and Ghidra exports. Each section
18
+ has a short description with relevant paper or tool links. Basics starts open;
19
+ expand any other section to browse its examples.
20
+ Example labels show the expected result with the bundled settings: green for
21
+ agreement, yellow for inconclusive results or compilation/type errors, and red
22
+ for mismatches.
23
 
24
  The verification library is a private GitHub repository referenced by the `core/`
25
  Git submodule. This repository publishes the UI and demo assets. Running verification
 
97
  Startup retains the pinned private core checkout in `core/` after removing its Git
98
  metadata. The UI reads example sources from that checkout and compiles originals
99
  when preparing examples. Local development uses the same loader and submodule.
100
+ The Related work section combines six Faultless cases with nine cases from D-Helix,
101
+ DiscScope, and Decompile-Diverge, including a deliberately uncompilable export. See `core/docs/related-work-examples.md`
102
  for provenance, interface adaptations, and published counterexamples.
103
+ Reference C is a display aid; uploaded binaries have none. DiscScope `orig.c`
104
+ excerpts are stored alongside their `raw.c` and `cand.c` in the shared core cases.
105
+ They come from binutils 2.29, libsmi 0.4.8, and JasPer 1.900.16, with source
106
+ locations, checksums, and license notices. Verification uses the published
107
+ DiscScope binaries. The bundled `factor` executable and redistribution notices
108
+ are read from `core/examples/binaries/` and
109
  copied together into the prepared example directory.
110
 
111
  ## Publish under the existing Space name
core CHANGED
@@ -1 +1 @@
1
- Subproject commit b86a6824f1feaefa49af7256b8829de59dca43d2
 
1
+ Subproject commit 79008f675f1576409387b903a034b3ba250ccb0f
core-revision.json CHANGED
@@ -1,5 +1,5 @@
1
  {
2
  "repository": "https://github.com/edmcman/decompile-verify.git",
3
- "commit": "b86a6824f1feaefa49af7256b8829de59dca43d2",
4
  "version": "0.0.0"
5
  }
 
1
  {
2
  "repository": "https://github.com/edmcman/decompile-verify.git",
3
+ "commit": "79008f675f1576409387b903a034b3ba250ccb0f",
4
  "version": "0.0.0"
5
  }
demo/app.py CHANGED
@@ -218,7 +218,7 @@ same seeds to see how the assembly and results change.
218
  For your own input, upload an **x86-64 ELF binary**, enter the **function start address**,
219
  and paste complete **Candidate C**. Set **Candidate function name** to the C function to test.
220
  The examples include matching implementations, deliberate bugs, real `factor` binary
221
- functions, Faultless paper cases, **Related work** examples, and saved **Ghidra exports** in expandable sections.
222
  Some Ghidra exports agree; others reveal mismatches or compile/type errors. **Reference C**, when shown, is a reading
223
  aid; verification runs the binary.
224
  """)
@@ -272,11 +272,23 @@ aid; verification runs the binary.
272
  max_new_testcases_per_run, solver_timeout_ms, random_input_probability]
273
  inputs = [*example_inputs, *mode_inputs]
274
  gr.Markdown("### Examples\nOpen a section and select an example.", elem_id="examples")
 
 
 
 
 
 
275
  example_pickers = []
276
  for group_number, (label, indices) in enumerate(example_groups(example_catalog.EXAMPLE_NAMES)):
277
  with gr.Accordion(f"{label} ({len(indices)})", open=label == "Basics"):
 
 
 
 
278
  picker = gr.Examples(examples=[examples[index] for index in indices], inputs=example_inputs,
279
- label=label, example_labels=[EXAMPLE_LABELS[index] for index in indices],
 
 
280
  examples_per_page=len(indices), cache_examples=False,
281
  elem_id=f"examples-group-{group_number}")
282
  example_pickers.append((picker, indices))
 
218
  For your own input, upload an **x86-64 ELF binary**, enter the **function start address**,
219
  and paste complete **Candidate C**. Set **Candidate function name** to the C function to test.
220
  The examples include matching implementations, deliberate bugs, real `factor` binary
221
+ functions, paper and artifact cases under **Related work**, and saved **Ghidra exports** in expandable sections.
222
  Some Ghidra exports agree; others reveal mismatches or compile/type errors. **Reference C**, when shown, is a reading
223
  aid; verification runs the binary.
224
  """)
 
272
  max_new_testcases_per_run, solver_timeout_ms, random_input_probability]
273
  inputs = [*example_inputs, *mode_inputs]
274
  gr.Markdown("### Examples\nOpen a section and select an example.", elem_id="examples")
275
+ gr.HTML('<div class="example-legend" aria-label="Expected example results">'
276
+ '<span>Expected with bundled settings:</span>'
277
+ '<span class="indicator green">Agree</span>'
278
+ '<span class="indicator amber">Inconclusive / error</span>'
279
+ '<span class="indicator red">Mismatch</span></div>',
280
+ apply_default_css=False)
281
  example_pickers = []
282
  for group_number, (label, indices) in enumerate(example_groups(example_catalog.EXAMPLE_NAMES)):
283
  with gr.Accordion(f"{label} ({len(indices)})", open=label == "Basics"):
284
+ gr.Markdown(example_catalog.EXAMPLE_GROUP_DESCRIPTIONS[label],
285
+ elem_classes=["example-description"])
286
+ expected = [example_catalog.expected_result(example_catalog.EXAMPLE_NAMES[index],
287
+ examples[index][8]) for index in indices]
288
  picker = gr.Examples(examples=[examples[index] for index in indices], inputs=example_inputs,
289
+ label=label, example_labels=[
290
+ f"{result.capitalize()} · {EXAMPLE_LABELS[index]}"
291
+ for index, result in zip(indices, expected)],
292
  examples_per_page=len(indices), cache_examples=False,
293
  elem_id=f"examples-group-{group_number}")
294
  example_pickers.append((picker, indices))
demo/examples.py CHANGED
@@ -23,6 +23,15 @@ def reference_sources():
23
  return tuple(example_metadata(name)["reference"] for name in EXAMPLE_NAMES)
24
 
25
 
 
 
 
 
 
 
 
 
 
26
  def prepare_examples(directory, *, include_ghidra=True):
27
  rows = dict(zip(core_examples.EXAMPLE_NAMES, core_examples.prepare_examples(directory)))
28
  names = EXAMPLE_NAMES if include_ghidra else tuple(
@@ -41,12 +50,35 @@ EXAMPLE_GROUPS = (
41
  ("Types and ABI", ("wide-integer", "float-identity", "signed-zero", "nan-payload",
42
  "struct-fields", "struct-indirect", "struct-padding", "pointer-identity")),
43
  ("Real binaries", ("factor-gcd", "factor-gcd-euclidean", "factor-gcd-even")),
44
- ("Faultless paper", core_examples.FAULTLESS_NAMES),
45
- ("Related work", core_examples.RESEARCH_NAMES),
46
  ("Ghidra exports", GHIDRA_EXAMPLE_NAMES),
47
  )
48
 
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  def example_groups(names):
51
  """Return nonempty categories with indices into the selected catalog."""
52
  return tuple((label, tuple(index for index, name in enumerate(names) if name in members))
 
23
  return tuple(example_metadata(name)["reference"] for name in EXAMPLE_NAMES)
24
 
25
 
26
+ def expected_result(name, compiler="gcc"):
27
+ """Recorded result for the bundled candidate and compiler, before user edits."""
28
+ metadata = example_metadata(name)
29
+ if metadata.get("expected_error"):
30
+ return "error"
31
+ return metadata.get("compiler_verdicts", {}).get(compiler,
32
+ metadata.get("expected_verdict")) or "inconclusive"
33
+
34
+
35
  def prepare_examples(directory, *, include_ghidra=True):
36
  rows = dict(zip(core_examples.EXAMPLE_NAMES, core_examples.prepare_examples(directory)))
37
  names = EXAMPLE_NAMES if include_ghidra else tuple(
 
50
  ("Types and ABI", ("wide-integer", "float-identity", "signed-zero", "nan-payload",
51
  "struct-fields", "struct-indirect", "struct-padding", "pointer-identity")),
52
  ("Real binaries", ("factor-gcd", "factor-gcd-euclidean", "factor-gcd-even")),
53
+ ("Related work", core_examples.FAULTLESS_NAMES + core_examples.RESEARCH_NAMES),
 
54
  ("Ghidra exports", GHIDRA_EXAMPLE_NAMES),
55
  )
56
 
57
 
58
+ EXAMPLE_GROUP_DESCRIPTIONS = {
59
+ "Basics": "Small arithmetic and bitwise examples, including matching implementations and deliberate bugs.",
60
+ "Calls and memory": "Examples involving function calls, allocation, strings, globals, and memory writes.",
61
+ "Types and ABI": "Examples exploring integer widths, floating-point values, structs, and pointer types.",
62
+ "Real binaries": (
63
+ "Compare the GCD function in the bundled [GNU coreutils `factor` binary]"
64
+ "(https://www.gnu.org/software/coreutils/manual/html_node/factor-invocation.html) "
65
+ "with matching and deliberately incorrect C implementations."
66
+ ),
67
+ "Related work": (
68
+ "Paper examples and artifact cases from [Faultless](https://arxiv.org/abs/2609.34089), "
69
+ "[D-Helix](https://www.usenix.org/system/files/usenixsecurity24-zou.pdf), "
70
+ "[DiscScope](https://doi.org/10.1145/3708821.3733877), and "
71
+ "[Decompile-Diverge](https://arxiv.org/abs/2609.05370), "
72
+ "covering pointer and memory behavior, decompilation errors, and compilation failures."
73
+ ),
74
+ "Ghidra exports": (
75
+ "Saved C exports from Ghidra 12.1.3 using "
76
+ "[GhidraFunctionCPPExporter](https://github.com/edmcman/GhidraFunctionCPPExporter). "
77
+ "Examples include agreement, mismatches, and compilation or type errors."
78
+ ),
79
+ }
80
+
81
+
82
  def example_groups(names):
83
  """Return nonempty categories with indices into the selected catalog."""
84
  return tuple((label, tuple(index for index, name in enumerate(names) if name in members))
demo/workbench.css CHANGED
@@ -2,6 +2,24 @@
2
  #intro { margin-bottom: 0; }
3
  #intro h1 { font-size: 1.65rem; letter-spacing: -.025em; }
4
  #scope { font-size: .85rem; color: var(--body-text-color-subdued); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  #setup { align-items: stretch; }
6
  #binary { min-height: 110px; }
7
  #binary .wrap { min-height: 72px; }
 
2
  #intro { margin-bottom: 0; }
3
  #intro h1 { font-size: 1.65rem; letter-spacing: -.025em; }
4
  #scope { font-size: .85rem; color: var(--body-text-color-subdued); }
5
+ .example-description p { font-size: .85rem; color: var(--body-text-color-subdued); }
6
+ .example-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
7
+ font-size: .85rem; color: var(--body-text-color-subdued); }
8
+ [id^="examples-group-"] .gallery-item[data-expected-result] {
9
+ color: var(--example-color); background: var(--example-background);
10
+ border: 1px solid var(--example-color); }
11
+ [id^="examples-group-"] .gallery-item[data-expected-result] * { color: inherit; }
12
+ .gallery-item[data-expected-result="agree"] { --example-color: #166534; --example-background: #dcfce7; }
13
+ .gallery-item[data-expected-result="mismatch"] { --example-color: #991b1b; --example-background: #fee2e2; }
14
+ .gallery-item[data-expected-result="inconclusive"], .gallery-item[data-expected-result="error"] {
15
+ --example-color: #854d0e; --example-background: #fef3c7; }
16
+ .dark .gallery-item[data-expected-result="agree"] { --example-color: #86efac; --example-background: #143b2b; }
17
+ .dark .gallery-item[data-expected-result="mismatch"] { --example-color: #fca5a5; --example-background: #451d26; }
18
+ .dark .gallery-item[data-expected-result="inconclusive"], .dark .gallery-item[data-expected-result="error"] {
19
+ --example-color: #fde68a; --example-background: #423519; }
20
+ [id^="examples-group-"] .gallery-item[data-expected-result]:hover { filter: brightness(.95); }
21
+ [id^="examples-group-"] .gallery-item[data-expected-result]:focus-visible {
22
+ outline: 2px solid var(--color-accent); outline-offset: 2px; }
23
  #setup { align-items: stretch; }
24
  #binary { min-height: 110px; }
25
  #binary .wrap { min-height: 72px; }
demo/workbench.js CHANGED
@@ -25,8 +25,18 @@
25
  }
26
  }
27
  };
28
- labelPanes();
29
- new MutationObserver(labelPanes).observe(document.body, {
 
 
 
 
 
 
 
 
 
 
30
  childList: true, subtree: true,
31
  });
32
  })();
 
25
  }
26
  }
27
  };
28
+ const colorExamples = () => {
29
+ for (const button of document.querySelectorAll('[id^="examples-group-"] button.gallery-item')) {
30
+ const result = button.textContent.trim().match(/^(Agree|Inconclusive|Mismatch|Error) · /);
31
+ if (result) button.dataset.expectedResult = result[1].toLowerCase();
32
+ }
33
+ };
34
+ const updateWorkbench = () => {
35
+ labelPanes();
36
+ colorExamples();
37
+ };
38
+ updateWorkbench();
39
+ new MutationObserver(updateWorkbench).observe(document.body, {
40
  childList: true, subtree: true,
41
  });
42
  })();
tests/test_examples.py CHANGED
@@ -18,7 +18,7 @@ def test_example_groups_cover_catalog_once():
18
  assert len(members) == len(set(members)) == len(examples.EXAMPLE_NAMES)
19
  assert set(members) == set(examples.EXAMPLE_NAMES)
20
  groups = examples.example_groups(examples.EXAMPLE_NAMES)
21
- assert [len(indices) for _, indices in groups] == [6, 7, 8, 3, 6, 9, 21]
22
  for _, indices in groups:
23
  assert list(indices) == sorted(indices)
24
 
 
18
  assert len(members) == len(set(members)) == len(examples.EXAMPLE_NAMES)
19
  assert set(members) == set(examples.EXAMPLE_NAMES)
20
  groups = examples.example_groups(examples.EXAMPLE_NAMES)
21
+ assert [len(indices) for _, indices in groups] == [6, 7, 8, 3, 15, 21]
22
  for _, indices in groups:
23
  assert list(indices) == sorted(indices)
24
 
tests/test_ui.py CHANGED
@@ -35,7 +35,7 @@ def test_example_reference_pane_events(tmp_path):
35
  load = loads[0]
36
  from demo.examples import example_groups
37
  groups = example_groups(EXAMPLE_NAMES)
38
- assert len(loads) == len(groups) == 7
39
  datasets = [fn.inputs[0] for fn in loads]
40
  reset = next(fn for fn in app.fns.values() if fn.api_name == "reset_outputs")
41
  assert set(reset.targets) == {(dataset._id, "click") for dataset in datasets}
 
35
  load = loads[0]
36
  from demo.examples import example_groups
37
  groups = example_groups(EXAMPLE_NAMES)
38
+ assert len(loads) == len(groups) == 6
39
  datasets = [fn.inputs[0] for fn in loads]
40
  reset = next(fn for fn in app.fns.values() if fn.api_name == "reset_outputs")
41
  assert set(reset.targets) == {(dataset._id, "click") for dataset in datasets}