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

Deny clippy::arithmetic_side_effects for fuel-merkle #729

Merged
merged 35 commits into from
May 15, 2024

Conversation

Dentosal
Copy link
Member

@Dentosal Dentosal commented May 2, 2024

Closes #170

Denies the following lints:

  • clippy::arithmetic_side_effects
  • clippy::cast_sign_loss
  • clippy::cast_possible_truncation
  • clippy::cast_possible_wrap

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests

Before requesting review

  • I have reviewed the code myself

@Dentosal Dentosal added tech-debt fuel-merkle Related to the `fuel-merkle` crate. labels May 2, 2024
@Dentosal Dentosal self-assigned this May 2, 2024

impl<T> ComparablePath for T
Copy link
Member Author

Choose a reason for hiding this comment

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

Merged into Path trait, as they were not used separately.


pub enum Instruction {
Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed to Side, and used in more places

@@ -1,50 +1,32 @@
#[derive(Debug, Eq, PartialEq)]
pub enum Bit {
Copy link
Member Author

Choose a reason for hiding this comment

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

Replaced with bool or Side enum, depending on which made sense.

Comment on lines -7 to -9
trait GetBit {
fn get_bit(&self, bit_index: u32) -> Option<Bit>;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This was used only once, below. I just inlined it.

@Dentosal Dentosal marked this pull request as ready for review May 2, 2024 23:15
@Dentosal Dentosal requested a review from a team May 2, 2024 23:16
@Dentosal Dentosal mentioned this pull request May 2, 2024
5 tasks
fuel-merkle/src/binary/root_calculator.rs Outdated Show resolved Hide resolved
fuel-merkle/src/binary/merkle_tree.rs Show resolved Hide resolved
fuel-merkle/src/common/msb.rs Outdated Show resolved Hide resolved
fuel-merkle/src/common/position.rs Outdated Show resolved Hide resolved
fuel-merkle/src/common/position.rs Outdated Show resolved Hide resolved
fuel-merkle/src/common/position.rs Outdated Show resolved Hide resolved
@Dentosal Dentosal requested a review from xgreenx May 7, 2024 23:45
fuel-merkle/src/binary/merkle_tree.rs Outdated Show resolved Hide resolved
fuel-merkle/src/common/path_iterator.rs Outdated Show resolved Hide resolved
fuel-merkle/src/common/position.rs Outdated Show resolved Hide resolved
fuel-merkle/src/common/position.rs Outdated Show resolved Hide resolved
fuel-merkle/src/common/position.rs Outdated Show resolved Hide resolved
fuel-merkle/src/common/position.rs Show resolved Hide resolved
@Dentosal Dentosal requested a review from xgreenx May 14, 2024 19:03
Copy link
Member Author

@Dentosal Dentosal May 15, 2024

Choose a reason for hiding this comment

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

The Subtree was just a hand-rolled non-empty linked list. It was always used wrapped in an option, so the use was exactly equivalent to a linked list. I first replaced it with alloc::collections::LinkedList but why not use a normal Vec instead? Actually MerkleRootCalculator already does that, so I just replaces all Subtree instances with it.

@Dentosal Dentosal requested a review from MitchTurner May 15, 2024 07:44
Copy link
Collaborator

@xgreenx xgreenx left a comment

Choose a reason for hiding this comment

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

LGTM! It would be nice if @bvrooman reviewed the change=)

.checked_sub(1)
.expect("Path to a tree without leaves"),
)
.unwrap(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can't guaranty that this will not fail. Is someone provides invalid leaves_count, it will fail

Copy link
Contributor

Choose a reason for hiding this comment

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

If the tree has a root, then leaves_count will be at least 1. In real use cases, this should be okay. But if someone were to provide arguments that are inconsistent with a real tree, this could fail. I don't think that's an issue.

Copy link
Contributor

@bvrooman bvrooman left a comment

Choose a reason for hiding this comment

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

lgtm

@Dentosal Dentosal added this pull request to the merge queue May 15, 2024
Merged via the queue into master with commit da27533 May 15, 2024
38 checks passed
@Dentosal Dentosal deleted the dento/deny-unchecked-arithmetic-merkle branch May 15, 2024 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fuel-merkle Related to the `fuel-merkle` crate. tech-debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove any unchecked arithmetic
4 participants