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

Sqrt fails formal verification #1586

Open
Gungy2 opened this issue Jun 1, 2023 · 5 comments
Open

Sqrt fails formal verification #1586

Gungy2 opened this issue Jun 1, 2023 · 5 comments

Comments

@Gungy2
Copy link
Contributor

Gungy2 commented Jun 1, 2023

Describe the error

There seems to be a bug in sqrt for formal verification. The following example fails verification (irrespective of the value of tokensToReturn.

To Reproduce

const tokensToReturn = (depositInvariant * stableTokenBalance) / slbTokenBalance;
require(sqrt(tokensToReturn) * sqrt(tokensToReturn) <= tokensToReturn, "Sqrt works");

Extra information

I am using the latest version of Reach. Also, may I please ask you to prioritize this, if at all possible? My Master thesis is due in about 2 weeks, and my project has been blocked by this bug for about 3 weeks now. Thank you so much!

@jeapostrophe
Copy link
Collaborator

What is the error you get?

@Gungy2
Copy link
Contributor Author

Gungy2 commented Jun 2, 2023

image

@Gungy2
Copy link
Contributor Author

Gungy2 commented Jun 2, 2023

I think the conversation on Discord is also relevant.

@Gungy2
Copy link
Contributor Author

Gungy2 commented Jun 6, 2023

Alternatively, even easier:

export const main =
  Reach.App( () => {
    const A = Participant('A', { x: UInt });
    init();
      A.only(() => {
        const x = declassify(interact.x);
        assume(x > 0, "x too low");
      });
      A.publish(x);
      commit();
      assert(sqrt(x) * sqrt(x) <= x);
    }
  );

This gives:

  // Violation Witness

  const UInt.max = 4;

  const x/43 = "A".interact.x;
  //    ^ could = 3
  //      from: ./t/y/sqrt.rsh:5:34:property binding

  // Theorem Formalization

  const v51 = sqrtx/43;
  //    ^ would be 2
  const v54 = (v51 * v51) <= x/43;
  //    ^ would be false
  assert(v54);

  Verifying when NO participants are honest
Checked 5 theorems; 2 failures (and 1 omitted repeats) :'(

@jeapostrophe
Copy link
Collaborator

If you are not able to test or use the new SMT assertion, then you can change your code from using a require to using an enforce, which will make it happen at run-time.

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

No branches or pull requests

2 participants