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

Move canon check from Digest to BFieldElement #235

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

jan-ferdinand
Copy link
Member

  • Reject non-canonical BFieldElements when parsing string slices or interpreting byte sequences
  • Move canon check of BFieldElements from Digest to BFieldElement
  • Deprecate functionality for platform-dependent endianness when decoding

BREAKING CHANGE: The error variant NotCanonical from enum TryFromDigestError has moved into enum ParseBFieldElementError.

This was described as the cleaner solution in #199, a sentiment I concur with.

Supersedes #206.

@jan-ferdinand jan-ferdinand added the ⏭️ breaking change Breaking change, will require an increment of the major version number. E.g: 0.3.0 -> 0.4.0 label Oct 3, 2024
Comment on lines -462 to +465
let mut buffer = [0u8; 8];
u.fill_buffer(&mut buffer)?;
let num_leafs = u64::from_be_bytes(buffer) >> 1; // num_leafs can be at most 63 bits

let mut peaks = vec![];
for _ in 0..(num_leafs.count_ones()) {
let peak = Digest::arbitrary(u)?;
peaks.push(peak);
}
let num_leafs = u.arbitrary::<u64>()? >> 1; // num_leafs can be at most 63 bits
let peaks = (0..num_leafs.count_ones())
.map(|_| Digest::arbitrary(u))
.try_collect()?;
Copy link
Member Author

@jan-ferdinand jan-ferdinand Oct 3, 2024

Choose a reason for hiding this comment

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

This piece of code came up when searching for the regex (b|l|n)e_bytes. The change doesn't really fit the theme of this PR, but I couldn't resist simplifying things.

@coveralls
Copy link

coveralls commented Oct 3, 2024

Coverage Status

coverage: 97.79% (+0.03%) from 97.76%
when pulling 7dafa32 on bfield_parsing
into 8482f93 on master.

@jan-ferdinand
Copy link
Member Author

@Sword-Smith, any opposition?

- Reject non-canonical `BFieldElement`s when parsing string slices or
  interpreting byte sequences
- Move canon check of `BFieldElement`s from `Digest` to `BFieldElement`
- Deprecate functionality for platform-dependent endianness when
  decoding

BREAKING CHANGE: The error variant `NotCanonical` from enum
`TryFromDigestError` has moved into enum `ParseBFieldElementError`.
@jan-ferdinand jan-ferdinand merged commit 7dafa32 into master Oct 7, 2024
4 checks passed
@jan-ferdinand jan-ferdinand deleted the bfield_parsing branch October 7, 2024 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⏭️ breaking change Breaking change, will require an increment of the major version number. E.g: 0.3.0 -> 0.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants