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

pow can return invalid results #6157

Open
IGI-111 opened this issue Jun 20, 2024 · 1 comment
Open

pow can return invalid results #6157

IGI-111 opened this issue Jun 20, 2024 · 1 comment
Labels
audit-report Related to the audit report bug Something isn't working lib: std Standard library

Comments

@IGI-111
Copy link
Contributor

IGI-111 commented Jun 20, 2024

pow may return results where the value is superior to the type maximum due to all primitive types of size < 8 bytes being treated as u64

@IGI-111 IGI-111 added bug Something isn't working lib: std Standard library labels Jun 20, 2024
@vaivaswatha
Copy link
Contributor

#[test]
    fn u32_pow() -> () {
      disable_panic_on_overflow();
      let x: u32 = 2;
      let y: u32 = 64;
      let z = x.pow(y); //this becomes 2**32, since u32 are essentially u64 under disguise, and explicit checks must be made to ensure values fall within range
      assert(z == 0);
      ()
    }
    #[test]
    fn u64_pow() -> () {
      disable_panic_on_overflow();
      let x: u64 = 2;
      let y: u32 = 64;
      let z = x.pow(y);
      assert(z == 0);
      ()
    }

@IGI-111 IGI-111 added the audit-report Related to the audit report label Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audit-report Related to the audit report bug Something isn't working lib: std Standard library
Projects
None yet
Development

No branches or pull requests

2 participants