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 input validation in bootstrap.sh and refactor bit_traits.rs #9406

Merged
merged 8 commits into from
Nov 7, 2024

Conversation

cypherpepe
Copy link
Contributor

  • Improved the input validation logic for the 'clean' command in bootstrap.sh to accept various forms of confirmation such as 'y', 'Y', 'yes', and 'YES'.
  • Refactored bit_traits.rs to reduce code duplication and improve efficiency:
    • Utilized leading_zeros() to optimize the get_msb function.
    • Implemented a generalized BitsQueryable trait for numeric types, reducing the need for multiple implementations.
    • Maintained individual implementations for FieldElement and MemoryAddress to prevent type-related issues.

- Refactored the BitsQueryable trait to avoid code duplication for numeric types.
- Implemented the get_msb function using the leading_zeros() method for better efficiency.
- Ensured compatibility with u8, u16, u32, u64, u128, and usize through a generalized implementation.
- Maintained individual implementations for FieldElement and MemoryAddress to prevent type-related issues.
- Enhanced the input validation logic for the 'clean' command.
- Now accepts various forms of confirmation such as 'y', 'Y', 'yes', and 'YES'.
- This change makes the script more user-friendly and less prone to input errors.
Copy link
Contributor

@fcarreiro fcarreiro left a comment

Choose a reason for hiding this comment

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

Thank you for this! We'll look into it asap. Our CI doesn't work well with external contributors so we need to do a few manual steps.

@fcarreiro fcarreiro changed the title Improve input validation in bootstrap.sh and refactor bit_traits.rs refactor: Improve input validation in bootstrap.sh and refactor bit_traits.rs Oct 31, 2024
@fcarreiro
Copy link
Contributor

Hi Cypherpepe, this PR does not build: https://github.com/AztecProtocol/aztec-packages/runs/32359062333

./avm-transpiler+build *failed* |    Compiling avm-transpiler v0.1.0 (/usr/src/avm-transpiler)
  ./avm-transpiler+build *failed* | error[E0119]: conflicting implementations of trait `BitsQueryable` for type `GenericFieldElement<ark_ff::fields::models::fp::Fp<ark_ff::fields::models::fp::montgomery_backend::MontBackend<ark_bn254::fields::fr::FrConfig, 4>, 4>>`
  ./avm-transpiler+build *failed* |   --> src/bit_traits.rs:21:1
  ./avm-transpiler+build *failed* |    |
  ./avm-transpiler+build *failed* | 15 | impl BitsQueryable for FieldElement {
  ./avm-transpiler+build *failed* |    | ----------------------------------- first implementation here
  ./avm-transpiler+build *failed* | ...
  ./avm-transpiler+build *failed* | 21 | impl<T> BitsQueryable for T
  ./avm-transpiler+build *failed* |    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `GenericFieldElement<ark_ff::fields::models::fp::Fp<ark_ff::fields::models::fp::montgomery_backend::MontBackend<ark_bn254::fields::fr::FrConfig, 4>, 4>>`
  ./avm-transpiler+build *failed* |    |
  ./avm-transpiler+build *failed* |    = note: upstream crates may add a new impl of trait `std::convert::From<acvm::acir::acir_field::GenericFieldElement<ark_ff::fields::models::fp::Fp<ark_ff::fields::models::fp::montgomery_backend::MontBackend<ark_bn254::fields::fr::FrConfig, 4>, 4>>>` for type `u128` in future versions

- Removed the blanket implementation of the `BitsQueryable` trait for all types `T: Into<u128> + Copy`, which was causing a conflict with the existing implementation for `FieldElement`.
- Added explicit implementations of the `BitsQueryable` trait for primitive integer types (`u8`, `u16`, `u32`, `u64`, `u128`, `usize`) using the `impl_bits_queryable_for_integers!` macro.
- This change resolves the compilation error related to conflicting trait implementations and makes the code more robust against future changes.
@cypherpepe
Copy link
Contributor Author

Hi, I've removed the universal implementation and instead provided explicit implementations for the primitive integer types using a macro. This avoids the conflict with Field Element.

@cypherpepe cypherpepe requested a review from fcarreiro November 4, 2024 11:08
@@ -65,19 +27,27 @@ impl BitsQueryable for MemoryAddress {
}
}

macro_rules! impl_bits_queryable_for_integers {
Copy link
Contributor

Choose a reason for hiding this comment

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

I've consulted with a few people and we think we prefer the explicit BitsQueryable implementations instead of the macro. The rest looks good and still valuable (if small).

Could you make this changes and merge master? Then I can duplicate the PR again, run CI and if it passes we merge.

@cypherpepe
Copy link
Contributor Author

@fcarreiro, I've made the changes you requested:

  • Removed the macro and added explicit BitsQueryable implementations for all integer types.
  • Optimized the get_msb function using leading_zeros().
  • Updated the branch with the latest changes from master.

@cypherpepe cypherpepe requested a review from fcarreiro November 6, 2024 11:15
Copy link
Contributor

@fcarreiro fcarreiro left a comment

Choose a reason for hiding this comment

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

CI passes in #9637
We can merge

@ludamad ludamad merged commit 65b1cd2 into AztecProtocol:master Nov 7, 2024
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