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

Tie SessionId to SessionParameters::Digest #41

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

fjarri
Copy link
Member

@fjarri fjarri commented Oct 22, 2024

Fixes #9
Affects #25

  • SessionId now hashes the incoming randomness using SessionParameters::Digest and keeps that hash. SessionId::new() renamed to from_seed().
  • FirstRound::new takes an &[u8] instead of a SessionId to reduce the coupling between layers.

This PR may possibly include making SessionId generic over SessionParameters and using digest::Output<SP::Digest> (which is a stack array) instead of Box<[u8]>, but that actually affects a lot of types (messages, evidences), so I am not sure if it's worth it.

@coveralls
Copy link

coveralls commented Oct 22, 2024

Pull Request Test Coverage Report for Build 11505566321

Warning: 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

  • 5 of 13 (38.46%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.04%) to 71.361%

Changes Missing Coverage Covered Lines Changed/Added Lines %
manul/src/session/session.rs 4 12 33.33%
Files with Coverage Reduction New Missed Lines %
manul/src/session/session.rs 1 73.46%
Totals Coverage Status
Change from base Build 11505291503: 0.04%
Covered Lines: 1206
Relevant Lines: 1690

💛 - Coveralls

Comment on lines 70 to 91
/// 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(),
)
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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. :)

Copy link
Member Author

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.

Copy link
Contributor

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. :/

Copy link
Member Author

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.

manul/src/session/session.rs Show resolved Hide resolved
examples/src/simple_malicious.rs Show resolved Hide resolved
examples/src/simple_malicious.rs Show resolved Hide resolved
@dvdplm dvdplm self-requested a review October 24, 2024 12:00
Copy link
Contributor

@dvdplm dvdplm left a 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.

@fjarri
Copy link
Member Author

fjarri commented Oct 24, 2024

Added more warnings to SessionId::from_seed() and exposed SessionId::random() for tests only. We can explore any improvements in follow-up PRs.

@fjarri fjarri merged commit 088e933 into entropyxyz:master Oct 24, 2024
8 checks passed
@fjarri fjarri deleted the session-id branch October 24, 2024 18:48
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.

SessionId improvements
3 participants