Repository navigation
fix(evm): reject repeated byte-string keys in Solidity metadata - #4024
Conversation
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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] The PR appears safe to merge. SummaryRejects repeated byte-string keys in terminal Solidity metadata while preserving the original byte range.
Reviews (1) · Last reviewed commit: "fix(evm): reject repeated byte-string ke..." · Reviewed by Greptile |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
Reproduced through the real EVM CLI on Linux/Node 24.18.0: |
Summary
bytecode.metadatareported a terminal CBOR root map with the same byte-string key twice asdecoded, with both entries and no diagnostic, while the same map with a repeated text key isnot-decoded.SolidityMetadata.tsrelies on cborg'srejectDuplicateMapKeys, but withuseMapsthat check compares Map keys by identity, and each byte-string key decodes to its ownUint8Array, 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}, length0007).inspect-evm-interface <file> hexreturned metadatastatus: "decoded", two entries with keybytes 01,diagnostic: null. Expected (docs/evm-bytecode.md: malformed candidates reportnot-decodedwith 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 intonot-decodedwith the message as the diagnostic (CBOR decode error: found repeat map key {"kind":"bytes","value":"01"}), keeping the offset and length.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.Contribution scope: ordinary fix within existing boundaries; no scope decision needed.
Contract and boundary impact
inspectSolidityMetadatainsrc/evm/SolidityMetadata.ts, when the root map's entries are projected.inspect-evm-interface/inspect_evm_interfacereportnot-decodedwith a diagnostic for a root map with repeated byte-string keys.raw_resultare untouched.bytecode.metadataonly; the original bytecode and recorded range are unchanged.Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.
Evidence and regression coverage
src/evm/SolidityMetadata.test.tsaddsduplicate 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 givepartial.duplicate byte keycase fails (expected { ... } to match object { status: 'not-decoded', ... }); the control test passes on both.inspect-evm-interface <file> hex --format json,bytecode.metadatastatus / entry count / diagnostic, Linux x64):dist/evm/EvmoleInterfaceWorker.js) run from the issue gives the same statuses, with offset 1 and length 7 kept for all three.For evidence-bearing changes:
Validation performed
npm run test:local -- src/evm/*.test.ts src/domain/evm/*.test.ts(5 files): 53 passed (theduplicate byte keycase fails on the base revision)npm run test:focused -- tests/boundary/mcp/evmInterfaceMcp.test.ts tests/boundary/evm/solidityMetadataWorker.test.ts: 19 passednpm run check:fast: typecheck and lint passednpm run build:cachedon base and on this branchCompatibility, safety, and release
Author readiness
Human owner: @Sriram-PR
Before merge
type(scope): outcome.