Skip to content

Commit

Permalink
Adapt to bn254 poseidon
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbosio committed Mar 12, 2024
1 parent bcf6af9 commit 145a962
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/lib/gadgets/elliptic-curve-bn254.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { provable } from '../circuit-value-bn254.js';
import { assertPositiveInteger } from '../../bindings/crypto/non-negative.js';
import { arrayGet, assertBoolean } from './basic-bn254.js';
import { sliceField3 } from './bit-slices-bn254.js';
import { Hashed } from '../provable-types/packed.js';
import { Hashed } from '../provable-types/packed-bn254.js';

// external API
export { EllipticCurveBn254, PointBn254, Ecdsa };
Expand Down
2 changes: 1 addition & 1 deletion src/lib/hash-bn254.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FieldBn254 } from './core-bn254.js';
import { createHashHelpers } from './hash-generic.js';
import { ProvableBn254 } from './provable-bn254.js';
import { MlFieldArray } from './ml/fields-bn254.js';
import { Poseidon as PoseidonBigint } from '../bindings/crypto/poseidon.js';
import { PoseidonBn254 as PoseidonBigint } from '../bindings/crypto/poseidon.js';
import { assert } from './errors.js';
import { rangeCheckN } from './gadgets/range-check-bn254.js';
import { TupleN } from './util/types.js';
Expand Down
18 changes: 9 additions & 9 deletions src/lib/provable-types/packed-bn254.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
} from '../circuit-value-bn254.js';
import { FieldBn254 } from '../field-bn254.js';
import { assert } from '../gadgets/common-bn254.js';
import { Poseidon, ProvableHashable, packToFields } from '../hash.js';
import { Provable } from '../provable.js';
import { fields, modifiedField } from './fields.js';
import { Poseidon, ProvableHashable, packToFields } from '../hash-bn254.js';
import { ProvableBn254 } from '../provable-bn254.js';
import { fields, modifiedField } from './fields-bn254.js';

export { Packed, Hashed };

Expand All @@ -23,7 +23,7 @@ export { Packed, Hashed };
* Using a packed representation can make sense in provable code where the number of constraints
* depends on the number of field elements per value.
*
* For example, `Provable.if(bool, x, y)` takes O(n) constraints, where n is the number of field
* For example, `ProvableBn254.if(bool, x, y)` takes O(n) constraints, where n is the number of field
* elements in x and y.
*
* Usage:
Expand Down Expand Up @@ -90,7 +90,7 @@ class Packed<T> {
let input = type.toInput(x);
let packed = packToFields(input);
let unconstrained = Unconstrained.witness(() =>
Provable.toConstant(type, x)
ProvableBn254.toConstant(type, x)
);
return new this(packed, unconstrained);
}
Expand All @@ -99,7 +99,7 @@ class Packed<T> {
* Unpack a value.
*/
unpack(): T {
let value = Provable.witness(this.Constructor.innerProvable, () =>
let value = ProvableBn254.witness(this.Constructor.innerProvable, () =>
this.value.get()
);

Expand Down Expand Up @@ -153,7 +153,7 @@ function countFields(input: HashInput) {
* Since a hash is only a single field element, this can be more efficient in provable code
* where the number of constraints depends on the number of field elements per value.
*
* For example, `Provable.if(bool, x, y)` takes O(n) constraints, where n is the number of field
* For example, `ProvableBn254.if(bool, x, y)` takes O(n) constraints, where n is the number of field
* elements in x and y. With Hashed, this is reduced to O(1).
*
* The downside is that you will pay the overhead of hashing your values, so it helps to experiment
Expand Down Expand Up @@ -232,7 +232,7 @@ class Hashed<T> {
static hash<T>(value: T, hash?: FieldBn254): Hashed<T> {
hash ??= this._hash(value);
let unconstrained = Unconstrained.witness(() =>
Provable.toConstant(this.innerProvable, value)
ProvableBn254.toConstant(this.innerProvable, value)
);
return new this(hash, unconstrained);
}
Expand All @@ -241,7 +241,7 @@ class Hashed<T> {
* Unwrap a value from its hashed variant.
*/
unhash(): T {
let value = Provable.witness(this.Constructor.innerProvable, () =>
let value = ProvableBn254.witness(this.Constructor.innerProvable, () =>
this.value.get()
);

Expand Down

0 comments on commit 145a962

Please sign in to comment.