Skip to content

fix(evm): reject repeated byte-string keys in Solidity metadata - #4024

Merged
morluto merged 1 commit into
morluto:mainfrom
Sriram-PR:fix/evm-metadata-repeated-byte-keys
Oct 21, 2026
Merged

morluto merged 1 commit into
morluto:mainfrom
Sriram-PR:fix/evm-metadata-repeated-byte-keys

Conversation

@Sriram-PR

Copy link
Copy Markdown
Contributor

Summary

bytecode.metadata reported a terminal CBOR root map with the same byte-string key twice as decoded, with both entries and no diagnostic, while the same map with a repeated text key is not-decoded. SolidityMetadata.ts relies on cborg's rejectDuplicateMapKeys, but with useMaps that check compares Map keys by identity, and each byte-string key decodes to its own Uint8Array, so two equal byte keys never match.

Fixes #3991

Problem and expected behavior

Smallest trigger: the bytecode 00a24101014101020007 (STOP, the 7-byte map {h'01': 1, h'01': 2}, length 0007). inspect-evm-interface <file> hex returned metadata status: "decoded", two entries with key bytes 01, diagnostic: null. Expected (docs/evm-bytecode.md: malformed candidates report not-decoded with a diagnostic): not-decoded, offset 1 and length 7 kept, no entries, no compiler version, as for repeated text keys.

Change and scope

  • src/evm/SolidityMetadata.ts: while collecting root map entries, compare each scalar key by kind and value and throw on a repeat. The existing catch turns that into not-decoded with the message as the diagnostic (CBOR decode error: found repeat map key {"kind":"bytes","value":"01"}), keeping the offset and length.
  • Keys that are nested containers (uninterpreted) are left out of the comparison: two different nested maps both project to { kind: "uninterpreted", container: "map" }, so they are not comparable from the projection. Their exact bytes stay addressable as before.
  • Text, integer, boolean and null repeats were already rejected by cborg and still are, with the same message.
  • Not included: duplicate keys inside nested containers, which this profile leaves uninterpreted.

Contribution scope: ordinary fix within existing boundaries; no scope decision needed.

Contract and boundary impact

  • Semantic owner and earliest changed stage: inspectSolidityMetadata in src/evm/SolidityMetadata.ts, when the root map's entries are projected.
  • Contribution scope fit and linked maintainer decision: not applicable (bug fix, [Bug] Duplicate byte-string CBOR metadata keys receive decoded status #3991).
  • CLI and MCP/tool-catalog contract: no schema change. inspect-evm-interface / inspect_evm_interface report not-decoded with a diagnostic for a root map with repeated byte-string keys.
  • Provider, bridge, target-format, or platform compatibility: none; the EVMole engine and its raw_result are untouched.
  • Evidence, artifact, provenance, or reconstruction contract: bytecode.metadata only; the original bytecode and recorded range are unchanged.
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata, package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: src/evm/SolidityMetadata.test.ts adds duplicate byte key (a2410101410102) to the existing malformed-candidate table, and a control test that distinct byte keys still decode and that two distinct nested-container keys still give partial.
  • Base reproduction: on the base revision the duplicate byte key case fails (expected { ... } to match object { status: 'not-decoded', ... }); the control test passes on both.
  • User-visible CLI output (inspect-evm-interface <file> hex --format json, bytecode.metadata status / entry count / diagnostic, Linux x64):
    bytecode               base                          PR
    00a24101014102020007   decoded, 2, null              decoded, 2, null
    00a26178016178020007   not-decoded, 0, repeat "x"    not-decoded, 0, repeat "x"
    00a24101014101020007   decoded, 2, null              not-decoded, 0, CBOR decode error: found repeat map key {"kind":"bytes","value":"01"}
    
    The compiled worker (dist/evm/EvmoleInterfaceWorker.js) run from the issue gives the same statuses, with offset 1 and length 7 kept for all three.
  • Remaining proof gaps: synthetic fixtures only; no real contract artifact with repeated byte keys was tried.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:local -- src/evm/*.test.ts src/domain/evm/*.test.ts (5 files): 53 passed (the duplicate byte key case fails on the base revision)
  • npm run test:focused -- tests/boundary/mcp/evmInterfaceMcp.test.ts tests/boundary/evm/solidityMetadataWorker.test.ts: 19 passed
  • npm run check:fast: typecheck and lint passed
  • CLI and worker comparison above, built with npm run build:cached on base and on this branch

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: Linux x64, Node 24.18.0; no provider involved.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: none.

Author readiness

Human owner: @Sriram-PR

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

cborg's rejectDuplicateMapKeys compares Map keys by identity, and each byte-string key decodes to its own Uint8Array, so a terminal metadata map with the same byte key twice was reported as decoded. Compare the root map's scalar keys by kind and value and report a repeat as not-decoded, like repeated text keys.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T07:43:47.723522Z 8787a02 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Rejects repeated byte-string keys in terminal Solidity metadata while preserving the original byte range.

  • Repeated byte keys in metadata are now rejected.

Reviews (1) · Last reviewed commit: "fix(evm): reject repeated byte-string ke..." · Reviewed by Greptile

@baron baron left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 8787a0251fc398e829ba3cbb61cb2b63ad3125fa; no blocking source finding.

The duplicate comparison belongs at the Solidity metadata parser boundary: scalar kind/value identity distinguishes byte strings from text/integers and avoids collapsing distinct uninterpreted containers. Existing failure handling clears interpreted entries/compiler version while retaining the candidate range; raw bytecode and worker/application consumers remain unchanged. Nested-container key equality is explicitly outside this scalar profile rather than falsely claimed as verified.

Independent isolated validation with Node 24.18.0/npm 11.16.0 and cloned dependencies whose installed lock entries match this PR's lock: exact SolidityMetadata.test.ts, 21 passed. Replacing only the producer with its base version gives 1 expected failure / 20 passes, reproducing the repeated-byte-key decoded/not-decoded error. This exercises actual cborg/parser behavior on synthetic trailer bytes, not a real-world contract artifact. No build/full checks/CLI/MCP rerun here; current CI includes a successful real-EVM lane.

All published check runs currently pass or are unrelated skips, and named-human declarations are filled. The disabled formal PR readiness status is an infrastructure limitation, not missing human ownership or an additional approval gate. The complete existing human declaration and current green repository CI support source-clear approval.

@baron baron left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving 8787a0251fc398e829ba3cbb61cb2b63ad3125fa. Parser-owned scalar kind/value duplicate detection preserves candidate provenance and existing partial/unknown semantics without reparsing in consumers. Independent exact suite: 21 passed; base producer substitution reproduces the one duplicate-byte-key failure. Pinned Node/npm and lock-matching dependencies; synthetic trailer bytes, no independent real-contract or CLI/MCP rerun. Current head is mergeable, repository CI/title checks are green, and the existing named-human declaration is complete. Disabled formal readiness automation is reported, not treated as missing human ownership. No merge authorization is implied.

@x1mm4nu3l

Copy link
Copy Markdown

Reproduced through the real EVM CLI on Linux/Node 24.18.0: inspect-evm-interface FILE hex --json with 00a24101014101020007 reports duplicate byte keys as decoded on main 4eaf3a1. On 8787a02 it reports not-decoded while keeping offset 1 and length 7; distinct byte keys still decode. All 21 metadata tests pass. These are offline carrier fixtures, with no chain access.

@morluto
morluto merged commit 8fe8622 into morluto:main Oct 21, 2026
63 checks passed
@Sriram-PR
Sriram-PR deleted the fix/evm-metadata-repeated-byte-keys branch October 22, 2026 01:15
@morluto morluto added bug Something isn't working provider: evm Analysis provider / engine: evm labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working provider: evm Analysis provider / engine: evm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Duplicate byte-string CBOR metadata keys receive decoded status

4 participants