-
Notifications
You must be signed in to change notification settings - Fork 0
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
This does not contain any provable code yet #1
Labels
bug
Something isn't working
Comments
What about the following pattern: const bn254_prime = Field3.from(21888242871839275222246405745257275088696311157297823662689037894645226208583n);
export default class Fq{
value: Field3;
modulus: Field3;
constructor(value: Field3) {
this.modulus = bn254_prime;
this.value = value;
}
add(x: Fq) {
return new Fq(
ForeignField.add(this.value, x.value, Field3.toBigint(this.modulus))
);
}
sub(x: Fq) {
return new Fq(
ForeignField.sub(this.value, x.value, Field3.toBigint(this.modulus))
);
} Now, I'm aiming to use toBigInt operation inside the Is it provable inside o1js now? |
I wouldn't say so!
|
Got it. So, this is going to work: const bn254_prime = 21888242871839275222246405745257275088696311157297823662689037894645226208583n;
export default class Fq{
value: Field3;
constructor(value: Field3) {
this.value = value;
}
add(x: Fq) {
return new Fq(
ForeignField.add(this.value, x.value, bn254_prime)
);
}
sub(x: Fq) {
return new Fq(
ForeignField.sub(this.value, x.value, bn254_prime)
);
} |
yes 👍🏻 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The current pattern of using o1js'
Gadgets.ForeignField
is wrong: you're convertingField3
to/from bigint in every operation. This will fail in provable code -- bigint operations are not provable, and you can't read out JS values of provable types likeField3
in a circuit.To make an operation provable, you need to build a circuit, not just do normal JS operations. We have a lot of methods for building circuits, like
Gadgets.ForeignField.{add(),mul()}
and of course all the lower-level methods onField
to operate on the individual limbs of aField3
.The text was updated successfully, but these errors were encountered: