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

Note possible checked_sub cases #57

Merged
merged 25 commits into from
Jun 10, 2023
Merged

Conversation

doubledup
Copy link
Contributor

@doubledup doubledup commented May 17, 2023

For #22, I've looked through the places we've used subtraction and haven't found any cases where checked_sub is strictly necessary. The constraints for each case are documented in comments before the subtraction. I've also added a few constraints where necessary.

Opening as a draft since I'm not sure whether we want to use checked_sub anyway, just in case the constraints change and we miss something. There is a small performance cost to checked_sub and I'm fairly certain it's unnecessary, so it's down to a cautiousness vs performance tradeoff.

@doubledup doubledup changed the title Checked sub Note possible checked_sub cases May 18, 2023
ssz-rs-derive/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Owner

@ralexstokes ralexstokes left a comment

Choose a reason for hiding this comment

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

I need to make another pass on the merkle code but this is great!

ssz-rs/src/bitlist.rs Show resolved Hide resolved
ssz-rs/src/bitlist.rs Outdated Show resolved Hide resolved
ssz-rs/src/bitlist.rs Outdated Show resolved Hide resolved
ssz-rs/src/merkleization/mod.rs Outdated Show resolved Hide resolved
ssz-rs/src/merkleization/mod.rs Outdated Show resolved Hide resolved
@ralexstokes
Copy link
Owner

so it's down to a cautiousness vs performance tradeoff.

I think we are fine to just add comments like you have done; I would consider calling them out explicitly with a SAFETY: marker in the comments

@ralexstokes ralexstokes added this to the v1.0.0 milestone Jun 5, 2023
@ralexstokes ralexstokes mentioned this pull request Jun 5, 2023
@doubledup doubledup marked this pull request as ready for review June 7, 2023 14:42
@codecov
Copy link

codecov bot commented Jun 8, 2023

Codecov Report

Patch coverage: 95.74% and project coverage change: +30.97 🎉

Comparison is base (2300ff8) 44.28% compared to head (8bde6b5) 75.26%.

Additional details and impacted files
@@             Coverage Diff             @@
##             main      #57       +/-   ##
===========================================
+ Coverage   44.28%   75.26%   +30.97%     
===========================================
  Files          20       18        -2     
  Lines        1409      857      -552     
===========================================
+ Hits          624      645       +21     
+ Misses        785      212      -573     
Impacted Files Coverage Δ
ssz-rs/src/bitvector.rs 82.02% <0.00%> (-0.94%) ⬇️
ssz-rs/src/bitlist.rs 79.20% <83.33%> (+0.26%) ⬆️
ssz-rs/src/de.rs 80.00% <100.00%> (+7.11%) ⬆️
ssz-rs/src/merkleization/mod.rs 92.66% <100.00%> (+0.82%) ⬆️

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Owner

@ralexstokes ralexstokes left a comment

Choose a reason for hiding this comment

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

had a question about offset checking for container deserialization

and still need to look at the merkle code

but everything else is looking great!

Comment on lines 323 to 327
for i in chunks.len()..leaf_count {
let start = leaf_start + (i * BYTES_PER_CHUNK);
let end = leaf_start + (i + 1) * BYTES_PER_CHUNK;
buffer[start..end].copy_from_slice(&zero_chunk);
}
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think the bounds on this iterator are correct chunks.len()..leaf_count and it was fine only bc we are just writing zeros to memory that was already zero (initialized in buffer)

I deleted it anyway bc it didn't seem to be doing anything

@ralexstokes ralexstokes mentioned this pull request Jun 10, 2023
@ralexstokes ralexstokes merged commit d72b6f9 into ralexstokes:main Jun 10, 2023
@doubledup doubledup deleted the checked-sub branch June 12, 2023 08:07
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