Repository navigation
Conversation
…licy Define accepted CID versions/codecs/hashes (CIDv0 Qm, CIDv1 multibase b/z/f/k/u/m/t), normalize CIDv1 multibase prefixes to lowercase canonical form, bind each CID to a caller-supplied content digest with bidirectional consistency enforcement, enforce MIN/MAX CID length bounds, and detect duplicates on the canonical CID hash per claim. Events expose canonical cidHash and contentDigest. Adds comprehensive tests for valid/invalid CID, alternate encoding, Unicode, duplicate content, digest mismatch, zero/oversized metadata, and fuzz scenarios. Closes DigiNodes#724
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the post-Wave-9 source and hosted-gate audit's focused contract readiness boundary for Content Identifier (CID) handling in
EvidenceManager.sol. Defines accepted CID versions/codecs/hashes, byte/string normalization, digest binding, size policy, and duplicate behavior. Adds comprehensive test coverage for valid/invalid CID, alternate encoding, Unicode, duplicate content, digest mismatch, zero/oversized metadata, and fuzz scenarios.Problem Context
The post-Wave-9 audit identified a contract readiness boundary around CID handling in the legacy
EvidenceManagermodule. The previous implementation:"Z…"vs"z…") to hash to different identifiers and bypass duplicate detectionTechnical Scope
1. Accepted CID Versions / Codecs / Hashes
Qmb/Bz/Zf/Fk/Ku/Um/Mt/TUnsupportedCIDVersion()Exposed as public constants:
CID_PREFIX_V0 = "Qm"CID_PREFIX_V1_LOWERCASE = "bzfkumt"2. Byte/String Normalization
New
_normalizeCID()internal pure function:"Qm…"): returned unchanged (already canonical)B→b,Z→z,F→f,K→k,U→u,M→m,T→t); rest of string unchangedEquivalent CIDs (e.g.
"ZDJ7…"vs"zdj7…") resolve to the same canonical string before hashing or storage, ensuring deterministic duplicate detection.3. Digest Binding
addEvidencenow accepts abytes32 contentDigestparameter:ZeroDigest()_cidToDigest)_digestToCid)ContentDigestMismatch()4. Size Policy
MIN_CID_LENGTH)InvalidCID()MAX_CID_LENGTH)CIDTooLarge()MAX_EVIDENCE_PER_CLAIM)EvidenceCapacityExceeded()5. Duplicate Behavior
DuplicateEvidence()Events
EvidenceAddednow exposes canonical identifiers:cidHashis indexed for efficient log filtering by consumers (Indexer, Frontend, Verification Engine, Dispute Resolution, Settlement Engine, Reputation System).Files Changed
contracts/EvidenceManager.soltest/EvidenceManager.test.tsconfig/networks.tshardhat.config.tsTest Coverage
Valid / Invalid CID
x,1,http://, etc.) rejected withUnsupportedCIDVersion()Qwithoutmsecond char rejectedAlternate Encoding (Normalization)
Z,B,F) accepted and normalized to lowercaseisCIDRegisteredandgetContentDigestnormalize input before lookupUnicode Validation
é, emoji) rejected withInvalidCID()Duplicate Content
DuplicateEvidence()Mismatched Digest
ContentDigestMismatch()ContentDigestMismatch()getContentDigestreturns bound digest; zero for unregisteredZero / Oversized Metadata
ZeroDigest()MIN_CID_LENGTH→InvalidCID()MAX_CID_LENGTH→CIDTooLarge()MAX_CID_LENGTH(512 bytes) → acceptedFuzz Tests
UnsupportedCIDVersion()ContentDigestMismatch()Acceptance Criteria Mapping
_normalizeCIDlowercases CIDv1 multibase prefix_validateCIDPrefixrejects unknown prefixes_cidToDigest/_digestToCidenforcementEvidenceAddedemitscidHash(indexed) andcontentDigestConstraints Preserved
uncheckedblocks preserved, no arithmetic changesAccessControlroles unchanged (PAUSER_ROLE,CLAIM_REGISTRY_ROLE)whenNotPausedmodifier preservedkeccak256of canonical CID string is deterministicgetEvidence,getEvidenceByClaim,isCIDRegisteredsignatures preserved; newgetContentDigestadditive onlyDependencies
Non-Goals
Verification
EvidenceManager.test.tstests updated for newcontentDigestparameter and expandedEvidenceAddedeventaddEvidencedirectly (verified via grep)addEvidencedirectly (only UI label string inmessages/en.json)Closes #724