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

Improve error when reading variable in provable code #998

Merged
merged 13 commits into from
Jun 22, 2023

Conversation

mitschabaude
Copy link
Member

@mitschabaude mitschabaude commented Jun 21, 2023

closes #899
closes #478
closes #489

bindings: o1-labs/o1js-bindings#52

Consider this method which incorrectly tries to extract the JS value of a variable:

  @method update(y: Field): Field {
    console.log(y.toString());
    // ...
 }

We used to get an error that confused people again & again:

Error: Can't evaluate prover code outside an as_prover block

This frequently caused people to wrap their entire logic in Provable.asProver(...) 😬

With this PR, the error now looks like:

image

Equivalent error messages happen in methods such as Bool.toBoolean(), Field.toBigInt() and PublicKey.toBase58(). We took care to adapt the error message to refer to a method that a user likely called themselves - e.g., refer to PublicKey.toBase58() in the error message even though it causes the error by internally calling Field.toBigInt().

@mitschabaude mitschabaude merged commit 93874df into main Jun 22, 2023
9 checks passed
@mitschabaude mitschabaude deleted the feature/better-readvar-error branch June 22, 2023 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants