Skip to content

Make sure that calls to Fingerprint::combine do not undermine collision safety #44337

Closed as not planned
@arielb1

Description

@arielb1

Fingerprint::combine is not a cryptographic hash, so when we use it we might lose the "cryptographic" guarantee of collision safety. Potentially even worse, Fingerprint::combine is associative: Fingerprint::combine(Fingerprint::combine(a, b), c) = Fingerprint::combine(a, Fingerprint::combine(b, c)), and that might cause "algebraic" collisions in some cases.

For example:

def_path_hash_0.0.combine(def_path_hash_1.0)

fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
let mut fingerprint = Fingerprint::zero();
for &def_id in self.0.iter() {
let def_path_hash = tcx.def_path_hash(def_id);
fingerprint = fingerprint.combine(def_path_hash.0);
}
fingerprint
}

And another case added by my PR:
https://github.com/arielb1/rust/blob/d14ed92f6b5aa23fd06f8affe4554f2c370bc79d/src/librustc/dep_graph/dep_node.rs#L647-L657

I believe the only requirement for DepNode is that the map from QueryKey -> (DepKind, Fingerprint) is injective. It might be a good idea to have a good sense of the requirements there to avoid accidental collisions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions