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

Field.greaterThan not working outside circuit #858

Closed
mitschabaude opened this issue Apr 13, 2023 · 1 comment · Fixed by #902
Closed

Field.greaterThan not working outside circuit #858

mitschabaude opened this issue Apr 13, 2023 · 1 comment · Fixed by #902
Labels
bug Something isn't working

Comments

@mitschabaude
Copy link
Member

mitschabaude commented Apr 13, 2023

reproduction:

await isReady;
let x = Field(1).greaterThan(0);

throws:

Error: This function can't be run outside of a checked computation.

from here:
https://github.com/o1-labs/snarky/blob/045d11106d1dcb217c249784dc694d05931f30a8/src/base/snark0.ml#L745-L747

The same issue can sometimes lead to different issues because snarky internal states aren't properly cleaned up, so that it thinks it is in a checked computation, but will return a witness outside the circuit.

Which is actually another bug!

@mitschabaude mitschabaude added the bug Something isn't working label Apr 13, 2023
@mitschabaude
Copy link
Member Author

mitschabaude commented Apr 13, 2023

Reproduction of different issue caused by not cleaning up "is running":

import { Field, isReady, Experimental, Struct } from 'snarkyjs';

await isReady;

let DummyProgram = Experimental.ZkProgram({
  publicInput: Struct({}),
  methods: {
    emptyMethod: {
      privateInputs: [],
      method(publicInput: {}) {},
    },
  },
});

await DummyProgram.compile();

// now snarky thinks it's "running"

let x = Field(1).greaterThan(0);

console.log(x);

This version doesn't throw, which implies that compile() leaves the internal state Run_state.is_running !state = true

the log shows that x is a witness even though this is not supposed be circuit code:

{ value: [ 2, [ 0, [Uint8Array] ], [ 3, [Uint8Array], [Array] ] ] }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant