The second zk program in this code does not compile. It throws an error. I am verifying a zkp inside a ZKProgram method. The problem seems to arise only if I try to constrain the public inputs of the input zkp. (zk --version = 0.10.2, Node.js v18.15.0)
// run using
// npm run build && node build/src/demo_error.js
import {
Field,
Poseidon,
SelfProof,
Experimental,
verify,
Struct,
MerkleMapWitness,
Mina,
isReady,
shutdown,
} from 'snarkyjs';
class twoFields extends Struct({
a: Field,
b: Field
}){
}
const clientTxnCorrect = Experimental.ZkProgram({
publicInput: twoFields,
methods: {
isCorrect: {
privateInputs:[Field],
method(
clientMsg: twoFields,
clientSecret: Field
) {
// really just a void proof to make sure method is not empty
clientSecret.assertEquals(clientMsg.a);
}
}
}
});
class currStateFields extends Struct({
x: Field,
y: Field
}){
}
const serverTxnCorrect = Experimental.ZkProgram({
publicInput: currStateFields,
methods: {
isValid: {
privateInputs:[SelfProof<twoFields>],
method(
currState: currStateFields,
clientProof: SelfProof<twoFields>
) {
// this line does not throw an error
clientProof.verify();
// this line throws an error
clientProof.publicInput.a.assertEquals(currState.x);
// this line throws an error
// clientProof.publicInput.b.assertEquals(currState.y);
}
}
}
});
await isReady;
console.log('SnarkyJS loaded');
const _1 = await clientTxnCorrect.compile();
const _2 = await serverTxnCorrect.compile();
console.log("Success");
await shutdown();