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

[Info] Cannot use U256::from(B256) due to ruint limitation #554

Open
greged93 opened this issue Mar 5, 2024 · 1 comment
Open

[Info] Cannot use U256::from(B256) due to ruint limitation #554

greged93 opened this issue Mar 5, 2024 · 1 comment
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@greged93
Copy link

greged93 commented Mar 5, 2024

Component

primitives

What version of Alloy are you on?

v0.6.4

Operating System

macOS (Apple Silicon)

Describe the bug

Despite the implementation of From<FixedBytes<N> for Uint<N*8>, it is currently not possible to run the below code:

use alloy_primitives::{FixedBytes, Uint};

fn main() {
    let fb = FixedBytes::<32>::new([1u8; 32]);
    let u = Uint::<256, 4>::from(fb);
    dbg!(u);
}

This is due to the line Uint::<256, 4>::from(fb), resolving the from to https://github.com/recmo/uint/blob/main/src/from.rs#L147, which requires the provided type to implement TryFrom and not From, causing the below error:

error[E0271]: type mismatch resolving `<Uint<256, 4> as TryFrom<FixedBytes<32>>>::Error == ToUintError<Uint<256, 4>>`
   --> src/main.rs:5:34
    |
5   |     let u = Uint::<256, 4>::from(fb);
    |             -------------------- ^^ expected `ToUintError<Uint<256, 4>>`, found `Infallible`
    |             |
    |             required by a bound introduced by this call
    |
    = note: expected enum `ToUintError<Uint<256, 4>>`
               found enum `Infallible`
    = note: required for `Uint<256, 4>` to implement `UintTryFrom<FixedBytes<32>>`
note: required by a bound in `ruint::from::<impl Uint<BITS, LIMBS>>::from`
@greged93 greged93 added the bug Something isn't working label Mar 5, 2024
@greged93 greged93 changed the title [Bug] failure to resolve From for Uint [Bug] failure to resolve From<FixedBytes<N>> for Uint<8*N> Mar 5, 2024
@DaniPopes
Copy link
Member

Yeah this is a limitation of ruint, for now you'll have to either do <U256 as From<_>>::from or use let u: U256 = bytes.into();.

I'll keep this open for visibility.

@DaniPopes DaniPopes changed the title [Bug] failure to resolve From<FixedBytes<N>> for Uint<8*N> Cannot use U256::from(B256) due to ruint limitation Mar 5, 2024
@prestwich prestwich changed the title Cannot use U256::from(B256) due to ruint limitation [Info] Cannot use U256::from(B256) due to ruint limitation Mar 5, 2024
@prestwich prestwich added the wontfix This will not be worked on label Mar 5, 2024
@linear linear bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 5, 2024
@DaniPopes DaniPopes reopened this Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants