o1js-pack 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.github/workflows/ci.yml +1 -1
- package/build/src/lib/PackingPlant.d.ts +66 -18
- package/build/src/lib/PackingPlant.js +145 -28
- package/build/src/lib/PackingPlant.js.map +1 -1
- package/build/src/lib/packed-types/PackedBool.d.ts +34 -21
- package/build/src/lib/packed-types/PackedBool.js +35 -34
- package/build/src/lib/packed-types/PackedBool.js.map +1 -1
- package/build/src/lib/packed-types/PackedBool.test.js +5 -5
- package/build/src/lib/packed-types/PackedBool.test.js.map +1 -1
- package/build/src/lib/packed-types/PackedString.d.ts +35 -21
- package/build/src/lib/packed-types/PackedString.js +38 -61
- package/build/src/lib/packed-types/PackedString.js.map +1 -1
- package/build/src/lib/packed-types/PackedString.test.js +6 -6
- package/build/src/lib/packed-types/PackedString.test.js.map +1 -1
- package/build/src/lib/packed-types/PackedUInt32.d.ts +33 -20
- package/build/src/lib/packed-types/PackedUInt32.js +33 -32
- package/build/src/lib/packed-types/PackedUInt32.js.map +1 -1
- package/build/src/lib/packed-types/PackedUInt32.test.js +4 -4
- package/build/src/lib/packed-types/PackedUInt32.test.js.map +1 -1
- package/package.json +1 -1
- package/tests/provable/end_to_end.test.ts +67 -0
- package/tests/provable/example_packed_string_circuit.ts +52 -0
- package/tests/provable/example_packed_uint_circuit.ts +45 -0
@@ -1,44 +1,53 @@
|
|
1
1
|
import { Field, Character } from 'o1js';
|
2
|
-
export declare function PackedStringFactory(l
|
3
|
-
new (packed: import("o1js/dist/node/lib/field.js").Field[]
|
2
|
+
export declare function PackedStringFactory(l?: number): {
|
3
|
+
new (packed: import("o1js/dist/node/lib/field.js").Field[]): {
|
4
4
|
toString(): string;
|
5
|
-
packed: import("o1js/dist/node/lib/field.js").Field[];
|
6
|
-
aux: Character[];
|
7
5
|
bitSize: bigint;
|
8
6
|
assertEquals(other: {
|
9
|
-
packed: import("o1js/dist/node/lib/field.js").Field[];
|
10
|
-
aux: Character[];
|
11
7
|
bitSize: bigint;
|
12
8
|
assertEquals(other: any): void;
|
9
|
+
packed: import("o1js/dist/node/lib/field.js").Field[];
|
13
10
|
}): void;
|
11
|
+
packed: import("o1js/dist/node/lib/field.js").Field[];
|
14
12
|
};
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
extractField(input: Character): Field;
|
14
|
+
sizeInBits(): bigint;
|
15
|
+
elementsPerField(): number;
|
16
|
+
/**
|
17
|
+
*
|
18
|
+
* @param fields Array of Fields, containing packed Characters
|
19
|
+
* @returns Array of Character
|
20
|
+
*/
|
21
|
+
unpack(fields: Field[]): Character[];
|
22
|
+
/**
|
23
|
+
*
|
24
|
+
* @param characters Array of Character to be packed
|
25
|
+
* @returns Instance of the implementing class
|
26
|
+
*/
|
27
|
+
fromCharacters(characters: Array<Character>): {
|
20
28
|
toString(): string;
|
21
|
-
packed: import("o1js/dist/node/lib/field.js").Field[];
|
22
|
-
aux: Character[];
|
23
29
|
bitSize: bigint;
|
24
30
|
assertEquals(other: {
|
25
|
-
packed: import("o1js/dist/node/lib/field.js").Field[];
|
26
|
-
aux: Character[];
|
27
31
|
bitSize: bigint;
|
28
32
|
assertEquals(other: any): void;
|
33
|
+
packed: import("o1js/dist/node/lib/field.js").Field[];
|
29
34
|
}): void;
|
35
|
+
packed: import("o1js/dist/node/lib/field.js").Field[];
|
30
36
|
};
|
31
|
-
|
37
|
+
/**
|
38
|
+
*
|
39
|
+
* @param str string to be packed
|
40
|
+
* @returns Instance of the implementing class
|
41
|
+
*/
|
42
|
+
fromString(str: string): {
|
32
43
|
toString(): string;
|
33
|
-
packed: import("o1js/dist/node/lib/field.js").Field[];
|
34
|
-
aux: Character[];
|
35
44
|
bitSize: bigint;
|
36
45
|
assertEquals(other: {
|
37
|
-
packed: import("o1js/dist/node/lib/field.js").Field[];
|
38
|
-
aux: Character[];
|
39
46
|
bitSize: bigint;
|
40
47
|
assertEquals(other: any): void;
|
48
|
+
packed: import("o1js/dist/node/lib/field.js").Field[];
|
41
49
|
}): void;
|
50
|
+
packed: import("o1js/dist/node/lib/field.js").Field[];
|
42
51
|
};
|
43
52
|
type: import("o1js/dist/node/bindings/lib/provable-snarky.js").ProvableExtended<{
|
44
53
|
packed: import("o1js/dist/node/lib/field.js").Field[];
|
@@ -47,11 +56,16 @@ export declare function PackedStringFactory(l: number): {
|
|
47
56
|
}>;
|
48
57
|
l: number;
|
49
58
|
n: number;
|
50
|
-
|
59
|
+
checkPack(unpacked: Character[]): void;
|
60
|
+
pack(unpacked: Character[]): import("o1js/dist/node/lib/field.js").Field[];
|
61
|
+
unpackToBigints(fields: import("o1js/dist/node/lib/field.js").Field[]): bigint[];
|
51
62
|
_isStruct: true;
|
52
63
|
toFields: (value: {
|
53
64
|
packed: import("o1js/dist/node/lib/field.js").Field[];
|
54
65
|
}) => import("o1js/dist/node/lib/field.js").Field[];
|
66
|
+
toAuxiliary: (value?: {
|
67
|
+
packed: import("o1js/dist/node/lib/field.js").Field[];
|
68
|
+
} | undefined) => any[];
|
55
69
|
fromFields: (fields: import("o1js/dist/node/lib/field.js").Field[]) => {
|
56
70
|
packed: import("o1js/dist/node/lib/field.js").Field[];
|
57
71
|
};
|
@@ -1,75 +1,52 @@
|
|
1
1
|
import { Field, Provable, Character } from 'o1js';
|
2
2
|
import { MultiPackingPlant } from '../PackingPlant.js';
|
3
3
|
const SIZE_IN_BITS = 16n;
|
4
|
+
const L = 15; // Default to one-field worth of characters
|
4
5
|
const CHARS_PER_FIELD = 15;
|
5
|
-
export function PackedStringFactory(l) {
|
6
|
+
export function PackedStringFactory(l = L) {
|
6
7
|
class PackedString_ extends MultiPackingPlant(Character, l, SIZE_IN_BITS) {
|
7
|
-
static
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
}
|
26
|
-
for (let i = 0; i < packedNs.length; i++) {
|
27
|
-
let packedN = packedNs[i];
|
28
|
-
for (let j = 0; j < CHARS_PER_FIELD; j++) {
|
29
|
-
const k = i * CHARS_PER_FIELD + j;
|
30
|
-
uints_[k] = packedN & ((1n << SIZE_IN_BITS) - 1n);
|
31
|
-
packedN >>= SIZE_IN_BITS;
|
32
|
-
}
|
33
|
-
}
|
34
|
-
return uints_.map((x) => Character.fromString(String.fromCharCode(Number(x))));
|
8
|
+
static extractField(input) {
|
9
|
+
return input.value;
|
10
|
+
}
|
11
|
+
static sizeInBits() {
|
12
|
+
return SIZE_IN_BITS;
|
13
|
+
}
|
14
|
+
static elementsPerField() {
|
15
|
+
return CHARS_PER_FIELD;
|
16
|
+
}
|
17
|
+
/**
|
18
|
+
*
|
19
|
+
* @param fields Array of Fields, containing packed Characters
|
20
|
+
* @returns Array of Character
|
21
|
+
*/
|
22
|
+
static unpack(fields) {
|
23
|
+
const unpacked = Provable.witness(Provable.Array(Character, l), () => {
|
24
|
+
let unpacked = this.unpackToBigints(fields);
|
25
|
+
return unpacked.map((x) => Character.fromString(String.fromCharCode(Number(x))));
|
35
26
|
});
|
36
|
-
return
|
27
|
+
return unpacked;
|
37
28
|
}
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
// f = initialChar.value is the same as f = 0; f += char.value * c^0;
|
47
|
-
// If f is initialized as 0, then it is a "constant" field and can't be added to a "variable" field in a proof
|
48
|
-
let f = initialChar.value;
|
49
|
-
const n = Math.min(mutableAux.length + 1, CHARS_PER_FIELD);
|
50
|
-
for (let i = 1; i < n; i++) {
|
51
|
-
const char = mutableAux.shift();
|
52
|
-
if (!char) {
|
53
|
-
throw new Error('Unexpected Array Length');
|
54
|
-
}
|
55
|
-
const value = char.value || Field(0);
|
56
|
-
const c = Field((2n ** SIZE_IN_BITS) ** BigInt(i));
|
57
|
-
f = f.add(value.mul(c));
|
58
|
-
}
|
59
|
-
fields.push(f);
|
60
|
-
}
|
61
|
-
return fields;
|
29
|
+
/**
|
30
|
+
*
|
31
|
+
* @param characters Array of Character to be packed
|
32
|
+
* @returns Instance of the implementing class
|
33
|
+
*/
|
34
|
+
static fromCharacters(characters) {
|
35
|
+
const packed = this.pack(characters);
|
36
|
+
return new PackedString_(packed);
|
62
37
|
}
|
38
|
+
/**
|
39
|
+
*
|
40
|
+
* @param str string to be packed
|
41
|
+
* @returns Instance of the implementing class
|
42
|
+
*/
|
63
43
|
static fromString(str) {
|
64
|
-
let characters =
|
44
|
+
let characters = new Array(l);
|
45
|
+
characters.fill(new Character(Field(0)), 0, l);
|
65
46
|
for (let i = 0; i < str.length; i++) {
|
66
|
-
characters
|
47
|
+
characters[i] = Character.fromString(str[i]);
|
67
48
|
}
|
68
|
-
return this.
|
69
|
-
}
|
70
|
-
static fromAuxiliary(aux) {
|
71
|
-
const packed = this.pack(aux);
|
72
|
-
return new PackedString_(packed, aux);
|
49
|
+
return this.fromCharacters(characters);
|
73
50
|
}
|
74
51
|
toString() {
|
75
52
|
const nullChar = String.fromCharCode(0);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"PackedString.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/PackedString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,YAAY,GAAG,GAAG,CAAC;AACzB,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,MAAM,UAAU,mBAAmB,CAAC,
|
1
|
+
{"version":3,"file":"PackedString.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/PackedString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM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AAC,IAAI,CAAC,IAAI,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAC/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACnC,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;aAC9C;YACD,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;QACzC,CAAC;QAED,QAAQ;YACN,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YACxC,OAAO,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;iBACrC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,QAAQ,CAAC;iBACxC,IAAI,CAAC,EAAE,CAAC,CAAC;QACd,CAAC;KACF;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
@@ -16,8 +16,8 @@ describe('PackedString', () => {
|
|
16
16
|
const myEthAddress = EthAddressString.fromString(vitalik_dot_eth);
|
17
17
|
expect(myEthAddress.toString()).toBe(vitalik_dot_eth);
|
18
18
|
});
|
19
|
-
it('#
|
20
|
-
const myEthAddress = EthAddressString.
|
19
|
+
it('#fromCharacters', () => {
|
20
|
+
const myEthAddress = EthAddressString.fromCharacters(characters);
|
21
21
|
expect(myEthAddress.toString()).toBe(vitalik_dot_eth);
|
22
22
|
});
|
23
23
|
it('#pack and #unPack', () => {
|
@@ -54,7 +54,7 @@ describe('PackedString', () => {
|
|
54
54
|
class String10 extends PackedStringFactory(10) {
|
55
55
|
}
|
56
56
|
expect(() => {
|
57
|
-
|
57
|
+
String10.fromString('abcdefghijk');
|
58
58
|
}).toThrow();
|
59
59
|
});
|
60
60
|
it('Exceeds maximum size string', () => {
|
@@ -74,7 +74,7 @@ describe('PackedString', () => {
|
|
74
74
|
it('Initializes a string', () => {
|
75
75
|
expect(() => {
|
76
76
|
Provable.runAndCheck(() => {
|
77
|
-
const myEthAddress = new EthAddressString(outsideEthAddress.packed
|
77
|
+
const myEthAddress = new EthAddressString(outsideEthAddress.packed);
|
78
78
|
EthAddressString.check({ packed: myEthAddress.packed });
|
79
79
|
});
|
80
80
|
}).not.toThrow();
|
@@ -82,7 +82,7 @@ describe('PackedString', () => {
|
|
82
82
|
it('#assertEquals', () => {
|
83
83
|
expect(() => {
|
84
84
|
Provable.runAndCheck(() => {
|
85
|
-
const myEthAddress = new EthAddressString(outsideEthAddress.packed
|
85
|
+
const myEthAddress = new EthAddressString(outsideEthAddress.packed);
|
86
86
|
myEthAddress.assertEquals(outsideEthAddress);
|
87
87
|
});
|
88
88
|
}).not.toThrow();
|
@@ -90,7 +90,7 @@ describe('PackedString', () => {
|
|
90
90
|
Provable.runAndCheck(() => {
|
91
91
|
const fakePacked = [...outsideEthAddress.packed];
|
92
92
|
fakePacked[0] = fakePacked[0].add(1);
|
93
|
-
const myEthAddress = new EthAddressString(fakePacked
|
93
|
+
const myEthAddress = new EthAddressString(fakePacked);
|
94
94
|
myEthAddress.assertEquals(outsideEthAddress);
|
95
95
|
});
|
96
96
|
}).toThrow();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"PackedString.test.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/PackedString.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAS,QAAQ,EAAE,MAAM,MAAM,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;QACtC,MAAM,eAAe,GAAG,4CAA4C,CAAC;QACrE,MAAM,gBAAiB,SAAQ,mBAAmB,CAAC,EAAE,CAAC;SAAG;Q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AG,EAAE;gBACV,QAAQ,CAAC,WAAW,CAAC,GAAG,EAAE;oBACxB,MAAM,UAAU,GAAG,CAAC,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;oBACjD,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;oBACrC,MAAM,YAAY,GAAG,IAAI,gBAAgB,CAAC,UAAU,CAAC,CAAC;oBAEtD,YAAY,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;gBAC/C,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -1,44 +1,52 @@
|
|
1
1
|
import { Field, UInt32 } from 'o1js';
|
2
|
-
export declare function PackedUInt32Factory(l
|
3
|
-
new (packed: import("o1js/dist/node/lib/field.js").Field
|
2
|
+
export declare function PackedUInt32Factory(l?: number): {
|
3
|
+
new (packed: import("o1js/dist/node/lib/field.js").Field): {
|
4
4
|
toBigInts(): Array<bigint>;
|
5
|
-
packed: import("o1js/dist/node/lib/field.js").Field;
|
6
|
-
aux: UInt32[];
|
7
5
|
bitSize: bigint;
|
8
6
|
assertEquals(other: {
|
9
|
-
packed: import("o1js/dist/node/lib/field.js").Field;
|
10
|
-
aux: UInt32[];
|
11
7
|
bitSize: bigint;
|
12
8
|
assertEquals(other: any): void;
|
9
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
13
10
|
}): void;
|
11
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
14
12
|
};
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
extractField(input: UInt32): Field;
|
14
|
+
sizeInBits(): bigint;
|
15
|
+
/**
|
16
|
+
*
|
17
|
+
* @param f Field, packed with the information, as returned by #pack
|
18
|
+
* @returns Array of UInt32
|
19
|
+
*/
|
20
|
+
unpack(f: Field): UInt32[];
|
21
|
+
/**
|
22
|
+
*
|
23
|
+
* @param uint32s Array of UInt32s to be packed
|
24
|
+
* @returns Instance of the implementing class
|
25
|
+
*/
|
26
|
+
fromUInt32s(uint32s: Array<UInt32>): {
|
20
27
|
toBigInts(): Array<bigint>;
|
21
|
-
packed: import("o1js/dist/node/lib/field.js").Field;
|
22
|
-
aux: UInt32[];
|
23
28
|
bitSize: bigint;
|
24
29
|
assertEquals(other: {
|
25
|
-
packed: import("o1js/dist/node/lib/field.js").Field;
|
26
|
-
aux: UInt32[];
|
27
30
|
bitSize: bigint;
|
28
31
|
assertEquals(other: any): void;
|
32
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
29
33
|
}): void;
|
34
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
30
35
|
};
|
36
|
+
/**
|
37
|
+
*
|
38
|
+
* @param bigints Array of bigints to be packed
|
39
|
+
* @returns Instance of the implementing class
|
40
|
+
*/
|
31
41
|
fromBigInts(bigints: Array<bigint>): {
|
32
42
|
toBigInts(): Array<bigint>;
|
33
|
-
packed: import("o1js/dist/node/lib/field.js").Field;
|
34
|
-
aux: UInt32[];
|
35
43
|
bitSize: bigint;
|
36
44
|
assertEquals(other: {
|
37
|
-
packed: import("o1js/dist/node/lib/field.js").Field;
|
38
|
-
aux: UInt32[];
|
39
45
|
bitSize: bigint;
|
40
46
|
assertEquals(other: any): void;
|
47
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
41
48
|
}): void;
|
49
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
42
50
|
};
|
43
51
|
type: import("o1js/dist/node/bindings/lib/provable-snarky.js").ProvableExtended<{
|
44
52
|
packed: import("o1js/dist/node/lib/field.js").Field;
|
@@ -46,11 +54,16 @@ export declare function PackedUInt32Factory(l: number): {
|
|
46
54
|
packed: string;
|
47
55
|
}>;
|
48
56
|
l: number;
|
49
|
-
|
57
|
+
checkPack(unpacked: UInt32[]): void;
|
58
|
+
pack(unpacked: UInt32[]): import("o1js/dist/node/lib/field.js").Field;
|
59
|
+
unpackToBigints(f: import("o1js/dist/node/lib/field.js").Field): bigint[];
|
50
60
|
_isStruct: true;
|
51
61
|
toFields: (value: {
|
52
62
|
packed: import("o1js/dist/node/lib/field.js").Field;
|
53
63
|
}) => import("o1js/dist/node/lib/field.js").Field[];
|
64
|
+
toAuxiliary: (value?: {
|
65
|
+
packed: import("o1js/dist/node/lib/field.js").Field;
|
66
|
+
} | undefined) => any[];
|
54
67
|
fromFields: (fields: import("o1js/dist/node/lib/field.js").Field[]) => {
|
55
68
|
packed: import("o1js/dist/node/lib/field.js").Field;
|
56
69
|
};
|
@@ -1,43 +1,44 @@
|
|
1
|
-
import {
|
1
|
+
import { Provable, UInt32 } from 'o1js';
|
2
2
|
import { PackingPlant } from '../PackingPlant.js';
|
3
|
+
const L = 7; // 7 32-bit uints fit in one Field
|
3
4
|
const SIZE_IN_BITS = 32n;
|
4
|
-
export function PackedUInt32Factory(l) {
|
5
|
+
export function PackedUInt32Factory(l = L) {
|
5
6
|
class PackedUInt32_ extends PackingPlant(UInt32, l, SIZE_IN_BITS) {
|
6
|
-
static
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
if (value && value.packed) {
|
12
|
-
packedN = value.packed.toBigInt();
|
13
|
-
}
|
14
|
-
else {
|
15
|
-
throw new Error('No Packed Value Provided');
|
16
|
-
}
|
17
|
-
for (let i = 0; i < l; i++) {
|
18
|
-
uints_[i] = packedN & ((1n << SIZE_IN_BITS) - 1n);
|
19
|
-
packedN >>= SIZE_IN_BITS;
|
20
|
-
}
|
21
|
-
return uints_.map((x) => UInt32.from(x));
|
22
|
-
});
|
23
|
-
return auxiliary;
|
7
|
+
static extractField(input) {
|
8
|
+
return input.value;
|
9
|
+
}
|
10
|
+
static sizeInBits() {
|
11
|
+
return SIZE_IN_BITS;
|
24
12
|
}
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
13
|
+
/**
|
14
|
+
*
|
15
|
+
* @param f Field, packed with the information, as returned by #pack
|
16
|
+
* @returns Array of UInt32
|
17
|
+
*/
|
18
|
+
static unpack(f) {
|
19
|
+
const unpacked = Provable.witness(Provable.Array(UInt32, l), () => {
|
20
|
+
const unpacked = this.unpackToBigints(f);
|
21
|
+
return unpacked.map((x) => UInt32.from(x));
|
22
|
+
});
|
23
|
+
return unpacked;
|
33
24
|
}
|
34
|
-
|
35
|
-
|
36
|
-
|
25
|
+
/**
|
26
|
+
*
|
27
|
+
* @param uint32s Array of UInt32s to be packed
|
28
|
+
* @returns Instance of the implementing class
|
29
|
+
*/
|
30
|
+
static fromUInt32s(uint32s) {
|
31
|
+
const packed = PackedUInt32_.pack(uint32s);
|
32
|
+
return new PackedUInt32_(packed);
|
37
33
|
}
|
34
|
+
/**
|
35
|
+
*
|
36
|
+
* @param bigints Array of bigints to be packed
|
37
|
+
* @returns Instance of the implementing class
|
38
|
+
*/
|
38
39
|
static fromBigInts(bigints) {
|
39
40
|
const uint32s = bigints.map((x) => UInt32.from(x));
|
40
|
-
return
|
41
|
+
return PackedUInt32_.fromUInt32s(uint32s);
|
41
42
|
}
|
42
43
|
toBigInts() {
|
43
44
|
return PackedUInt32_.unpack(this.packed).map((x) => x.toBigint());
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"PackedUInt32.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/PackedUInt32.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"PackedUInt32.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/PackedUInt32.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,QAAQ,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,kCAAkC;AAC/C,MAAM,YAAY,GAA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C,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QACpE,CAAC;KACF;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Provable, UInt32 } from 'o1js';
|
2
2
|
import { PackedUInt32Factory } from './PackedUInt32';
|
3
3
|
describe('PackedUInt32', () => {
|
4
|
-
class PackedUInt32 extends PackedUInt32Factory(
|
4
|
+
class PackedUInt32 extends PackedUInt32Factory() {
|
5
5
|
}
|
6
6
|
describe('Outside of the circuit', () => {
|
7
7
|
const bigints = [10n, 2n ** 32n - 1n, 0n, 10n, 2n ** 32n - 100n, 42n, 0n];
|
@@ -59,7 +59,7 @@ describe('PackedUInt32', () => {
|
|
59
59
|
it('Initializes', () => {
|
60
60
|
expect(() => {
|
61
61
|
Provable.runAndCheck(() => {
|
62
|
-
const packedUInt32 = new PackedUInt32(outsidePackedUInt.packed
|
62
|
+
const packedUInt32 = new PackedUInt32(outsidePackedUInt.packed);
|
63
63
|
PackedUInt32.check({ packed: packedUInt32.packed });
|
64
64
|
});
|
65
65
|
}).not.toThrow();
|
@@ -67,14 +67,14 @@ describe('PackedUInt32', () => {
|
|
67
67
|
it('#assertEquals', () => {
|
68
68
|
expect(() => {
|
69
69
|
Provable.runAndCheck(() => {
|
70
|
-
const packedUInt32 = new PackedUInt32(outsidePackedUInt.packed
|
70
|
+
const packedUInt32 = new PackedUInt32(outsidePackedUInt.packed);
|
71
71
|
packedUInt32.assertEquals(outsidePackedUInt);
|
72
72
|
});
|
73
73
|
}).not.toThrow();
|
74
74
|
expect(() => {
|
75
75
|
Provable.runAndCheck(() => {
|
76
76
|
const fakePacked = outsidePackedUInt.packed.add(32);
|
77
|
-
const packedUInt32 = new PackedUInt32(fakePacked
|
77
|
+
const packedUInt32 = new PackedUInt32(fakePacked);
|
78
78
|
packedUInt32.assertEquals(outsidePackedUInt);
|
79
79
|
});
|
80
80
|
}).toThrow();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"PackedUInt32.test.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/PackedUInt32.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,MAAM,YAAa,SAAQ,mBAAmB,
|
1
|
+
{"version":3,"file":"PackedUInt32.test.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/PackedUInt32.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAErD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,MAAM,YAAa,SAAQ,mBAAmB,EAAE;KAAG;IACnD,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;QACtC,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE,EAAE,IAAI,GAAG,GAAG,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,IAAI,GAAG,GAAG,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QAC1E,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAEjD,EAAE,CAAC,cAAc,EAAE,GAAG,EAAE;YACtB,MAAM,cAAc,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YACzD,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mBAAmB,EAAE,GAAG,EAAE;YAC3B,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,C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EAAE,GAAG,EAAE;YACvB,MAAM,CAAC,GAAG,EAAE;gBACV,QAAQ,CAAC,WAAW,CAAC,GAAG,EAAE;oBACxB,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;oBAChE,YAAY,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;gBAC/C,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;YACjB,MAAM,CAAC,GAAG,EAAE;gBACV,QAAQ,CAAC,WAAW,CAAC,GAAG,EAAE;oBACxB,MAAM,UAAU,GAAG,iBAAiB,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;oBACpD,MAAM,YAAY,GAAG,IAAI,YAAY,CAAC,UAAU,CAAC,CAAC;oBAClD,YAAY,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;gBAC/C,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACf,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
@@ -0,0 +1,67 @@
|
|
1
|
+
import { Votes, VotesProgram, VotesProof } from './example_packed_uint_circuit';
|
2
|
+
import {
|
3
|
+
TextInput,
|
4
|
+
TextInputProgram,
|
5
|
+
TextInputProof,
|
6
|
+
} from './example_packed_string_circuit';
|
7
|
+
import { Character, Poseidon } from 'o1js';
|
8
|
+
|
9
|
+
describe('End to End Votes Test', () => {
|
10
|
+
const init = [0n, 0n];
|
11
|
+
const initVotes = Votes.fromBigInts(init);
|
12
|
+
let initProof: VotesProof;
|
13
|
+
|
14
|
+
beforeAll(async () => {
|
15
|
+
await VotesProgram.compile();
|
16
|
+
initProof = await VotesProgram.init(initVotes);
|
17
|
+
initProof.verify();
|
18
|
+
});
|
19
|
+
|
20
|
+
describe('Incrementing votes', () => {
|
21
|
+
it('Increments the 0th index', async () => {
|
22
|
+
const unpackedVotes = [1n, 0n];
|
23
|
+
const proofVotes = Votes.fromBigInts(unpackedVotes);
|
24
|
+
const proof = await VotesProgram.incrementIndex0(proofVotes, initProof);
|
25
|
+
proof.verify();
|
26
|
+
proofVotes.packed.assertEquals(proof.publicInput.packed);
|
27
|
+
});
|
28
|
+
|
29
|
+
// Temporarily skipping, the proof does not verify, but the behavior does not match #toThrow
|
30
|
+
it.skip('throws when verifying an invalid proof', async () => {
|
31
|
+
const unpackedVotes = [1n, 0n];
|
32
|
+
const proofVotes = Votes.fromBigInts(unpackedVotes);
|
33
|
+
const proof = await VotesProgram.incrementIndex1(proofVotes, initProof);
|
34
|
+
expect(() => {
|
35
|
+
proof.verify();
|
36
|
+
}).toThrow();
|
37
|
+
});
|
38
|
+
});
|
39
|
+
});
|
40
|
+
|
41
|
+
describe('End to End Text Input Test', () => {
|
42
|
+
const init = 'Mina Protocol';
|
43
|
+
const initTextInput = TextInput.fromString(init);
|
44
|
+
let initProof: TextInputProof;
|
45
|
+
|
46
|
+
beforeAll(async () => {
|
47
|
+
await TextInputProgram.compile();
|
48
|
+
initProof = await TextInputProgram.init(initTextInput);
|
49
|
+
initProof.verify();
|
50
|
+
});
|
51
|
+
|
52
|
+
describe('Adding Input', () => {
|
53
|
+
it('adds input', async () => {
|
54
|
+
let unpackedTextInput = 'Zina Protocol';
|
55
|
+
let proofTextInput = TextInput.fromString(unpackedTextInput);
|
56
|
+
const p1 = await TextInputProgram.changeFirstLetter(
|
57
|
+
proofTextInput,
|
58
|
+
initProof,
|
59
|
+
TextInput.unpack(new TextInput(initProof.publicInput.packed).packed),
|
60
|
+
Character.fromString('Z')
|
61
|
+
);
|
62
|
+
Poseidon.hash(proofTextInput.packed).assertEquals(
|
63
|
+
Poseidon.hash(p1.publicInput.packed)
|
64
|
+
);
|
65
|
+
});
|
66
|
+
});
|
67
|
+
});
|