Skip to content

Commit

Permalink
add scale from field element to test
Browse files Browse the repository at this point in the history
  • Loading branch information
mitschabaude committed Apr 3, 2024
1 parent 011d6a8 commit bc9b4ae
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/lib/provable/test/group.unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Provable } from '../provable.js';
import { Poseidon } from '../../../mina-signer/src/poseidon-bigint.js';
import { runAndCheckSync } from '../core/provable-context.js';
import { Scalar } from '../scalar.js';
import { Field } from '../field.js';

console.log('group consistency tests');

Expand All @@ -15,6 +16,9 @@ test(Random.field, Random.field, (a, s0, assert) => {
const g = Group.from(x1, y1);
const s = Scalar.from(s0);
runScale(g, s, (g, s) => g.scale(s), assert);

const sField = Field.from(s0);
runScale(g, sField, (g, s) => g.scale(Scalar.fromNativeField(s)), assert);
});

// tests consistency between in- and out-circuit implementations
Expand Down Expand Up @@ -83,18 +87,18 @@ function run(
});
}

function runScale(
function runScale<T extends Scalar | Field>(
g: Group,
s: Scalar,
f: (g1: Group, s: Scalar) => Group,
s: T,
f: (g1: Group, s: T) => Group,
assert: (b: boolean, message?: string | undefined) => void
) {
let result_out_circuit = f(g, s);

runAndCheckSync(() => {
let result_in_circuit = f(
Provable.witness(Group, () => g),
Provable.witness(Scalar, () => s)
Provable.witness(s.constructor as any, (): T => s)
);

Provable.asProver(() => {
Expand Down

0 comments on commit bc9b4ae

Please sign in to comment.