-
Notifications
You must be signed in to change notification settings - Fork 1
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
Tie SessionId
to SessionParameters::Digest
#41
Conversation
Pull Request Test Coverage Report for Build 11505566321Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
manul/src/session/session.rs
Outdated
/// Creates a session identifier deterministically from the given bytestring. | ||
/// | ||
/// **Warning:** make sure the bytestring you provide will not be reused within your application. | ||
/// Session ID collisions will affect error attribution and evidence verification. | ||
pub fn from_seed<SP: SessionParameters>(bytes: &[u8]) -> Self { | ||
Self( | ||
SP::Digest::new_with_prefix(b"SessionId") | ||
.chain_update(bytes) | ||
.finalize() | ||
.as_ref() | ||
.into(), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outside tests/benches/examples, why would we want users to create their own session identifiers? The safest way to use the API seems to not allow misuse ever, so: can we get away without this method completely?
If we cannot, is it possible to enforce some minimum length (of the seed)? Or is the Digest
safe even with a single 0
as input?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you propose that we create them randomly when a Session
is created? I thought there may be use in making them deterministically based on e.g. current block hash and other network parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, create them without any user provided input. Upstream should treat it as an opaque token, or "shared randomness" as it were. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the thing though, how do you share it between the nodes? I don't see any other way but generating it based on some publicly available pseudo-random data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, fair point. Maybe we can force users to implement the method themselves, like a "must-implement" trait? That way they can use the (hopefully) correct contextual information to ensure it never repeats. :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I don't really see how that would be functionally different from the existing from_seed
method. Let's get this PR in, and if you have ideas on how the process can be made safer, open an issue, and we'll explore that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, leaving any outstanding tweaks to you, feel free to merge at will.
Added more warnings to |
Fixes #9
Affects #25
SessionId
now hashes the incoming randomness usingSessionParameters::Digest
and keeps that hash.SessionId::new()
renamed tofrom_seed()
.FirstRound::new
takes an&[u8]
instead of aSessionId
to reduce the coupling between layers.This PR may possibly include making
SessionId
generic overSessionParameters
and usingdigest::Output<SP::Digest>
(which is a stack array) instead ofBox<[u8]>
, but that actually affects a lot of types (messages, evidences), so I am not sure if it's worth it.