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

Fix arithmetic overflow error in 'accountsHash' function #4

Open
Robin-3 opened this issue May 16, 2023 · 0 comments
Open

Fix arithmetic overflow error in 'accountsHash' function #4

Robin-3 opened this issue May 16, 2023 · 0 comments

Comments

@Robin-3
Copy link

Robin-3 commented May 16, 2023

I noticed an arithmetic overflow error in the 'accountsHash' function located in the file "src/day4/Account.mo". The error is causing the program to throw an 'arithmetic overflow' with error code IC0503.

I have identified the problematic code block. Here's the corrected code:

  public func accountsHash(lhs : Account) : Nat32 {
    let lhsSubaccount : Subaccount = Option.get<Subaccount>(
      lhs.subaccount,
      _getDefaultSubaccount(),
    );
    let hashSum = Nat.add(
      Nat32.toNat(Principal.hash(lhs.owner)),
      Nat32.toNat(Blob.hash(lhsSubaccount)),
    );
    Nat32.fromNat(hashSum % (2 ** 32 - 1));
  };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant