Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make scp::Msg derive(Digestible) #127

Merged
merged 8 commits into from
May 1, 2020

Conversation

eranrund
Copy link
Contributor

@eranrund eranrund commented May 1, 2020

This PR makes scp::Msg (and everything else that is needed in order to support that) derive Digestible. This would allow us to get rid of some hackish uses of mcserial, such as this one.

This required making the derive macro support generics and enums, so there are a bunch of changes around that.

proc-macro2 = "0.4.4"
quote = "0.6.3"
syn = { version = "0.15", features = [ "extra-traits" ] }
proc-macro2 = "1.0.8"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are actually newer versions, but courtesy of mbedtls and its dependency on an old bindgen, we need to pin to these exact versions :(

Copy link
Contributor

Choose a reason for hiding this comment

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

one thing is, there was a new version of cargo feature that can allow separating dependencies for build-time tools -- I don't know that we ever enabled it but it might help here? i'm not sure

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

it sounds like it might not actually help yet anyways

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this is caused because we can only have one version of clang-sys at a time. Right now grpc and mbedtls both need version 6, so that's the one we're stuck on.

@eranrund eranrund requested review from cbeck88 and jcape May 1, 2020 01:15
.iter()
.map(|variant| {
let variant_ident = &variant.ident;

Copy link
Contributor

@cbeck88 cbeck88 May 1, 2020

Choose a reason for hiding this comment

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

I think I would want to add something like, variants.enumerate() so that we know if this is the i'th possibility, and then encode that number as a fixed width integer, e.g. a u32, and stick that in the hash before the other stuff. Something that is ensuring that there is a prefix-free representation of which variant it is before we start hitting the data associated to that value. Because the enum variant names are user generated and may not be fixed width or prefix free -- we'd like to ensure that there's no way that a hash from Option1 and Option2 can collide. that was the mechanism that I imagined would completely prevent that

@cbeck88
Copy link
Contributor

cbeck88 commented May 1, 2020

This looks really good, thank you for doing this!

let expanded = quote! {
impl mc_crypto_digestible::Digestible for #ident {
impl #impl_generics mc_crypto_digestible::Digestible for #ident #ty_generics #where_clause {
fn digest<D: mc_crypto_digestible::Digest>(&self, hasher: &mut D) {
hasher.input(stringify!(#ident).as_bytes());
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure you want to also inject the full path to each generic here as well, otherwise you can get hash collisions between, e.g. FlyingKite<Thing1> and FlyingKite<Thing2>.

Copy link
Contributor

@cbeck88 cbeck88 left a comment

Choose a reason for hiding this comment

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

LGTM thank you

@eranrund eranrund requested a review from jcape May 1, 2020 18:58
Copy link
Contributor

@jcape jcape left a comment

Choose a reason for hiding this comment

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

The expected value in the unit tests (L147) needs to include some indication of what the resolution of the generic is. i.e. Digestible derived for TestEnum<V> needs to have some indication that V is a u64 go into the hash.

@eranrund
Copy link
Contributor Author

eranrund commented May 1, 2020

The expected value in the unit tests (L147) needs to include some indication of what the resolution of the generic is. i.e. Digestible derived for TestEnum<V> needs to have some indication that V is a u64 go into the hash.

I see, yeah, good point.

@eranrund eranrund requested a review from jcape May 1, 2020 20:15
@eranrund eranrund merged commit 17c6328 into mobilecoinfoundation:master May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants