Skip to content

Commit

Permalink
Update zkprogram poly
Browse files Browse the repository at this point in the history
  • Loading branch information
only4sim committed Nov 26, 2023
1 parent 3af4477 commit 7dd97d3
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions src/libs/poly.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
function poly(input, coefficients) {
let result = new Field(0);
import {
Field,
Mina,
PrivateKey,
AccountUpdate,
SelfProof,
ZkProgram,
Struct,
Bool,
Circuit,
Poseidon,
MerkleMap,
MerkleTree,
MerkleWitness,
MerkleMapWitness,
verify,
Provable,
} from 'o1js';

for (let i = 0; i < coefficients.length; i++) {
const term = coefficients[i].mul(input.pow(i));
result = result.add(term);
}
const Poly = ZkProgram({
name: 'Poly',
publicOutput: Field,
methods: {
poly: {
privateInputs: [Field, Provable.Array(Field, 5)],

method(input: Field, coefficients: Field[]): Field {
let result = new Field(0);
let power = new Field(1);

for (let i = 0; i < coefficients.length; i++) {
const term = coefficients[i].mul(power);
result = result.add(term);
power = power.mul(input);
}
return result;
},
},
},
});

return result;
}

0 comments on commit 7dd97d3

Please sign in to comment.