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

refactor: Improve codebase #490

Merged
merged 1 commit into from
Aug 24, 2023
Merged

refactor: Improve codebase #490

merged 1 commit into from
Aug 24, 2023

Conversation

howjmay
Copy link
Contributor

@howjmay howjmay commented Jun 27, 2023

Improve error check and slice operations

@CLAassistant
Copy link

CLAassistant commented Jun 27, 2023

CLA assistant check
All committers have signed the CLA.

@github-actions
Copy link

🔒 Could not start CI tests due to missing safe PR label. Please contact a DEDIS maintainer.

1 similar comment
@github-actions
Copy link

🔒 Could not start CI tests due to missing safe PR label. Please contact a DEDIS maintainer.

ver, _ := d.verifiers[dd.Index]
ver, ok := d.verifiers[dd.Index]
if !ok {
return nil, fmt.Errorf("verifiers not exists")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return nil, fmt.Errorf("verifiers not exists")
return nil, fmt.Errorf("missing verifiers")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Member

@ineiti ineiti left a comment

Choose a reason for hiding this comment

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

LGTM, only the error message should be changed.

@sonarcloud
Copy link

sonarcloud bot commented Jun 28, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

57.1% 57.1% Coverage
9.5% 9.5% Duplication

@ineiti
Copy link
Member

ineiti commented Jun 28, 2023

Please add a short description to the PR, and then I think it's good to go.

@howjmay
Copy link
Contributor Author

howjmay commented Jun 28, 2023

Added!

share/poly.go Outdated
@@ -35,7 +35,7 @@ type PriShare struct {
func (p *PriShare) Hash(s kyber.HashFactory) []byte {
h := s.Hash()
_, _ = p.V.MarshalTo(h)
_ = binary.Write(h, binary.LittleEndian, p.I)
_ = binary.Write(h, binary.LittleEndian, int32(p.I))
Copy link
Member

Choose a reason for hiding this comment

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

Looking at it once more: could this be a breaking change? If the current int is 64 bit, now it will hash it as 32 bits.

It is definitely a good idea to cast the int here, I'm just not sure whether it will break protocols having used this with 64 bits. Any idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think int is architecture-dependent, which means both 32 and 64 bits should work. But it is definitely better to use a type with clear width

Copy link
Member

@ineiti ineiti Jun 29, 2023

Choose a reason for hiding this comment

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

Yes, that's what https://go.dev/tour/basics/11 says, too. So if a binary for a 64-bit platform used this library before the change, it will have used a 64 bit representation of p.I for the hashing. With this change it will use a 32 bit representation, and the comparison will fail, e.g., in a signature.

Same thing if you use int64 - for a 32 bit platform, this might make it not working anymore. So I'm trying to figure out if somebody out there actually relies on this, and cannot come up with a good way of deciding whether yes, or no :)

@pierluca or @jbsv, what is your take on this? Creating a new major version of kyber would be the safest, but it seems a bit too much, except if we do it for all hashes of ints.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am curious how about changing the datatype of p.I here? I think that should be the easier and safest too.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, hindsight is 20/20, that is what I would do now. But only after seeing problems like this and working for a couple of years with Rust :)

Now this change would be a breaking change, because then a lot of code would not even compile anymore. So let's wait for @pierluca 's return and see what he thinks. I'm currently thinking of keeping the p.I there without a cast. Which is wrong, but at least not in a breaking way!

If ever there is a version 4 of kyber, this is something that would need to be addressed at a moment...

Copy link
Contributor

Choose a reason for hiding this comment

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

Apologies for the delay. First of all, thanks @howjmay for the good suggestions in this PR. Regarding this int32, I can only agree with @ineiti: it is a breaking change.
Furthermore, we're most commonly using this library on x64 systems on our end, so this would be very likely to break a few things.

This would indeed make sense for a version 4 of Kyber, for which right now we don't really have the resources. On the other hand, I think we're piling up quite a bit of changes that could justify a version 4, if the resources allow it on our side into 2024 (or there's interest on your side, @ineiti ), we should definitely plan for it.

Copy link
Member

Choose a reason for hiding this comment

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

Added v4 label :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ineiti So I think if I remove this change, the rest of the change is ok for merging?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, here and on line 307. Both need to be removed.

Copy link
Member

@ineiti ineiti left a comment

Choose a reason for hiding this comment

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

LGTM, I propose to merge these changes @pierluca

In fact, @howjmay you should rebase against the latest base branch.

@howjmay
Copy link
Contributor Author

howjmay commented Aug 24, 2023

LGTM, I propose to merge these changes @pierluca

In fact, @howjmay you should rebase against the latest base branch.

I just updated !

@sonarcloud
Copy link

sonarcloud bot commented Aug 24, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

80.0% 80.0% Coverage
10.5% 10.5% Duplication

@pierluca pierluca merged commit e423d8e into dedis:master Aug 24, 2023
7 checks passed
@pierluca pierluca removed the v4 label Aug 24, 2023
@howjmay howjmay deleted the fix branch August 24, 2023 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants