o1js-pack 0.3.1 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. package/.github/workflows/ci.yml +1 -1
  2. package/.husky/pre-commit +0 -0
  3. package/README.md +9 -30
  4. package/build/src/index.d.ts +5 -5
  5. package/build/src/index.js +5 -5
  6. package/build/src/lib/PackingPlant.d.ts +132 -92
  7. package/build/src/lib/PackingPlant.js +190 -74
  8. package/build/src/lib/PackingPlant.js.map +1 -1
  9. package/build/src/lib/packed-types/PackedBool.d.ts +85 -77
  10. package/build/src/lib/packed-types/PackedBool.js +49 -47
  11. package/build/src/lib/packed-types/PackedBool.js.map +1 -1
  12. package/build/src/lib/packed-types/PackedBool.test.d.ts +1 -1
  13. package/build/src/lib/packed-types/PackedBool.test.js +75 -75
  14. package/build/src/lib/packed-types/PackedBool.test.js.map +1 -1
  15. package/build/src/lib/packed-types/PackedString.d.ts +181 -78
  16. package/build/src/lib/packed-types/PackedString.js +127 -82
  17. package/build/src/lib/packed-types/PackedString.js.map +1 -1
  18. package/build/src/lib/packed-types/PackedString.test.d.ts +1 -1
  19. package/build/src/lib/packed-types/PackedString.test.js +100 -99
  20. package/build/src/lib/packed-types/PackedString.test.js.map +1 -1
  21. package/build/src/lib/packed-types/PackedUInt32.d.ts +85 -77
  22. package/build/src/lib/packed-types/PackedUInt32.js +49 -47
  23. package/build/src/lib/packed-types/PackedUInt32.js.map +1 -1
  24. package/build/src/lib/packed-types/PackedUInt32.test.d.ts +1 -1
  25. package/build/src/lib/packed-types/PackedUInt32.test.js +83 -83
  26. package/build/src/lib/packed-types/PackedUInt32.test.js.map +1 -1
  27. package/package.json +1 -1
  28. package/tests/provable/end_to_end.test.ts +65 -0
  29. package/tests/provable/example_packed_string_circuit.ts +47 -0
  30. package/tests/provable/example_packed_uint_circuit.ts +39 -0
  31. package/build/src/lib/packed-types/PackedCharacter.d.ts +0 -51
  32. package/build/src/lib/packed-types/PackedCharacter.js +0 -34
  33. package/build/src/lib/packed-types/PackedCharacter.js.map +0 -1
  34. package/build/src/lib/packed-types/PackedCharacter.test.d.ts +0 -1
  35. package/build/src/lib/packed-types/PackedCharacter.test.js +0 -31
  36. package/build/src/lib/packed-types/PackedCharacter.test.js.map +0 -1
  37. package/build/src/lib/scratch.d.ts +0 -1
  38. package/build/src/lib/scratch.js +0 -16
  39. package/build/src/lib/scratch.js.map +0 -1
  40. package/build/src/packed-types/PackedBool.d.ts +0 -51
  41. package/build/src/packed-types/PackedBool.js +0 -34
  42. package/build/src/packed-types/PackedBool.js.map +0 -1
  43. package/build/src/packed-types/PackedBool.test.d.ts +0 -1
  44. package/build/src/packed-types/PackedBool.test.js +0 -101
  45. package/build/src/packed-types/PackedBool.test.js.map +0 -1
  46. package/build/src/packed-types/PackedCharacter.d.ts +0 -51
  47. package/build/src/packed-types/PackedCharacter.js +0 -34
  48. package/build/src/packed-types/PackedCharacter.js.map +0 -1
  49. package/build/src/packed-types/PackedCharacter.test.d.ts +0 -1
  50. package/build/src/packed-types/PackedCharacter.test.js +0 -31
  51. package/build/src/packed-types/PackedCharacter.test.js.map +0 -1
  52. package/build/src/packed-types/PackedUInt32.d.ts +0 -51
  53. package/build/src/packed-types/PackedUInt32.js +0 -34
  54. package/build/src/packed-types/PackedUInt32.js.map +0 -1
  55. package/build/src/packed-types/PackedUInt32.test.d.ts +0 -1
  56. package/build/src/packed-types/PackedUInt32.test.js +0 -68
  57. package/build/src/packed-types/PackedUInt32.test.js.map +0 -1
  58. package/build/src/packed-types/PackingPlant.d.ts +0 -54
  59. package/build/src/packed-types/PackingPlant.js +0 -45
  60. package/build/src/packed-types/PackingPlant.js.map +0 -1
  61. package/build/src/packed-types/scratch.d.ts +0 -1
  62. package/build/src/packed-types/scratch.js +0 -5
  63. package/build/src/packed-types/scratch.js.map +0 -1
  64. package/coverage/clover.xml +0 -166
  65. package/coverage/coverage-final.json +0 -5
  66. package/coverage/lcov-report/PackedBool.ts.html +0 -268
  67. package/coverage/lcov-report/PackedUInt32.ts.html +0 -313
  68. package/coverage/lcov-report/base.css +0 -224
  69. package/coverage/lcov-report/block-navigation.js +0 -87
  70. package/coverage/lcov-report/favicon.png +0 -0
  71. package/coverage/lcov-report/index.html +0 -131
  72. package/coverage/lcov-report/lib/PackingPlant.ts.html +0 -478
  73. package/coverage/lcov-report/lib/index.html +0 -116
  74. package/coverage/lcov-report/lib/packed-types/PackedBool.ts.html +0 -238
  75. package/coverage/lcov-report/lib/packed-types/PackedString.ts.html +0 -364
  76. package/coverage/lcov-report/lib/packed-types/PackedUInt32.ts.html +0 -238
  77. package/coverage/lcov-report/lib/packed-types/index.html +0 -146
  78. package/coverage/lcov-report/prettify.css +0 -1
  79. package/coverage/lcov-report/prettify.js +0 -2
  80. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  81. package/coverage/lcov-report/sorter.js +0 -196
  82. package/coverage/lcov.info +0 -282
@@ -9,7 +9,7 @@ on: [push, pull_request]
9
9
  jobs:
10
10
  test:
11
11
  runs-on: ubuntu-latest
12
- timeout-minutes: 10
12
+ timeout-minutes: 40
13
13
  steps:
14
14
  - name: Set up NodeJS
15
15
  uses: actions/setup-node@v2
package/.husky/pre-commit CHANGED
File without changes
package/README.md CHANGED
@@ -1,33 +1,18 @@
1
- # O1JS Pack
1
+ # o1js Pack
2
2
 
3
- Make the most of your ZKApp state!
3
+ Make the most of your zkApp state!
4
4
 
5
5
  ## What is it
6
6
 
7
- O1JS Pack is a library for [O1JS](https://github.com/o1-labs/o1js/) that allows a zkapp developer to pack extra data into a single Field.
7
+ o1js Pack is a library for [o1js](https://github.com/o1-labs/o1js/) that allows a zkApp developer to pack extra data into a single Field.
8
8
 
9
- ### Usage in a ZKApp
9
+ ### Usage in a zkApp
10
10
 
11
- ```
12
- import {
13
- PackedBoolFactory,
14
- PackedStringFactory,
15
- PackedUInt32Factory,
16
- } from 'o1js-pack';
17
-
18
- const MyPackedBools = PackedBoolFactory(); // Max of 254 Bools
19
- const MyPackedString = PackedStringFactory(); // Max of 120 Characters
20
- const MyPackedUInts = PackedUInt32Factory(); // Max of 7 UInt32s
21
-
22
- const sevenUints = [1, 2, 3, 4, 5, 6, 7].map(x => UInt32.from(x));
23
- const myPackedUInts = new MyPackedUInts(MyPackedUInts.pack(sevenUints), sevenUints);
24
- ```
11
+ TODO
25
12
 
26
- ## What's the catch?
13
+ ### Smart Contract
27
14
 
28
- If a zkapp has two or more independent Fields of state, then preconditions can be set on just one, or on any combination of the Fields. With SnarkyPack, one precondition will be set on the packed Field, which means that independent updates cannot happen asynchronously.
29
-
30
- For example, let's say there is a voting app with two independent Fields of state: `yesCount` and `noCount`. If one user issues an update to `yesCount` and another user issues an update to `noCount` at the same time, both proofs may be valid at the same time. Both transactions may succeed during the same block, since they don't interfere with each others' preconditions. With SnarkyPack, a devolper can save state by putting both `yesCount` and `noCount` into the same Field of state, making room for other state to exist on chain. The tradeoff is that two votes will no longer be able to be cast independently. `yesCount` and `noCount` depend on the same precontition, meaning that to update one or the other, you must lock both.
15
+ ### ZK Program
31
16
 
32
17
  ## How to build
33
18
 
@@ -39,18 +24,12 @@ npm run build
39
24
 
40
25
  ```sh
41
26
  npm run test src # non-proof tests
42
- npm run testw # watch mode
43
- ```
44
-
45
- ## How to run coverage
46
-
47
- ```sh
48
- npm run coverage
27
+ npm run test tests/provable # provable tests
49
28
  ```
50
29
 
51
30
  ## Credits
52
31
 
53
- Thanks to @mario_zito for seeding the idea for this library on discord ([Thread 1](https://discord.com/channels/484437221055922177/1128509274465779822), [Thread 2](https://discord.com/channels/484437221055922177/1128501705173106698)), and to @gregor for sounding out the early implementation.
32
+ Thanks to @mario_zito for seeding the idea for this library on Discord ([Thread 1](https://discord.com/channels/484437221055922177/1128509274465779822), [Thread 2](https://discord.com/channels/484437221055922177/1128501705173106698)), and to @gregor for sounding out the early implementation.
54
33
 
55
34
  Thanks to @iam-dev for early adoption!
56
35
 
@@ -1,5 +1,5 @@
1
- import { PackedBoolFactory } from './lib/packed-types/PackedBool.js';
2
- import { PackedUInt32Factory } from './lib/packed-types/PackedUInt32.js';
3
- import { PackingPlant, MultiPackingPlant } from './lib/PackingPlant.js';
4
- import { PackedStringFactory } from './lib/packed-types/PackedString.js';
5
- export { PackedBoolFactory, PackedStringFactory, PackedUInt32Factory, PackingPlant, MultiPackingPlant, };
1
+ import { PackedBoolFactory } from './lib/packed-types/PackedBool.js';
2
+ import { PackedUInt32Factory } from './lib/packed-types/PackedUInt32.js';
3
+ import { PackingPlant, MultiPackingPlant } from './lib/PackingPlant.js';
4
+ import { PackedStringFactory } from './lib/packed-types/PackedString.js';
5
+ export { PackedBoolFactory, PackedStringFactory, PackedUInt32Factory, PackingPlant, MultiPackingPlant, };
@@ -1,6 +1,6 @@
1
- import { PackedBoolFactory } from './lib/packed-types/PackedBool.js';
2
- import { PackedUInt32Factory } from './lib/packed-types/PackedUInt32.js';
3
- import { PackingPlant, MultiPackingPlant } from './lib/PackingPlant.js';
4
- import { PackedStringFactory } from './lib/packed-types/PackedString.js';
5
- export { PackedBoolFactory, PackedStringFactory, PackedUInt32Factory, PackingPlant, MultiPackingPlant, };
1
+ import { PackedBoolFactory } from './lib/packed-types/PackedBool.js';
2
+ import { PackedUInt32Factory } from './lib/packed-types/PackedUInt32.js';
3
+ import { PackingPlant, MultiPackingPlant } from './lib/PackingPlant.js';
4
+ import { PackedStringFactory } from './lib/packed-types/PackedString.js';
5
+ export { PackedBoolFactory, PackedStringFactory, PackedUInt32Factory, PackingPlant, MultiPackingPlant, };
6
6
  //# sourceMappingURL=index.js.map
@@ -1,92 +1,132 @@
1
- import { Field, InferProvable } from 'o1js';
2
- export declare function PackingPlant<A, T extends InferProvable<A> = InferProvable<A>>(elementType: A, l: number, bitSize: bigint): (abstract new (packed: Field, aux: Array<T>) => {
3
- packed: Field;
4
- aux: Array<T>;
5
- bitSize: bigint;
6
- assertEquals(other: any): void;
7
- }) & {
8
- type: import("o1js/dist/node/bindings/lib/provable-snarky").ProvableExtended<{
9
- packed: import("o1js/dist/node/lib/field").Field;
10
- }, {
11
- packed: string;
12
- }>;
13
- l: number;
14
- toAuxiliary(value?: {
15
- packed: Field;
16
- } | undefined): Array<T>;
17
- pack(aux: Array<T>): Field;
18
- unpack(f: Field): T[];
19
- _isStruct: true;
20
- toFields: (value: {
21
- packed: import("o1js/dist/node/lib/field").Field;
22
- }) => import("o1js/dist/node/lib/field").Field[];
23
- fromFields: (fields: import("o1js/dist/node/lib/field").Field[]) => {
24
- packed: import("o1js/dist/node/lib/field").Field;
25
- };
26
- sizeInFields(): number;
27
- check: (value: {
28
- packed: import("o1js/dist/node/lib/field").Field;
29
- }) => void;
30
- toInput: (x: {
31
- packed: import("o1js/dist/node/lib/field").Field;
32
- }) => {
33
- fields?: import("o1js/dist/node/lib/field").Field[] | undefined;
34
- packed?: [import("o1js/dist/node/lib/field").Field, number][] | undefined;
35
- };
36
- toJSON: (x: {
37
- packed: import("o1js/dist/node/lib/field").Field;
38
- }) => {
39
- packed: string;
40
- };
41
- fromJSON: (x: {
42
- packed: string;
43
- }) => {
44
- packed: import("o1js/dist/node/lib/field").Field;
45
- };
46
- };
47
- export declare function MultiPackingPlant<A, T extends InferProvable<A> = InferProvable<A>>(elementType: A, l: number, bitSize: bigint): (abstract new (packed: Array<Field>, aux: Array<T>) => {
48
- packed: Array<Field>;
49
- aux: Array<T>;
50
- bitSize: bigint;
51
- assertEquals(other: any): void;
52
- }) & {
53
- type: import("o1js/dist/node/bindings/lib/provable-snarky").ProvableExtended<{
54
- packed: import("o1js/dist/node/lib/field").Field[];
55
- }, {
56
- packed: string[];
57
- }>;
58
- l: number;
59
- n: number;
60
- toAuxiliary(value?: {
61
- packed: Array<Field>;
62
- } | undefined): Array<T>;
63
- pack(aux: Array<T>): Array<Field>;
64
- unpack(fields: Array<Field>): T[];
65
- _isStruct: true;
66
- toFields: (value: {
67
- packed: import("o1js/dist/node/lib/field").Field[];
68
- }) => import("o1js/dist/node/lib/field").Field[];
69
- fromFields: (fields: import("o1js/dist/node/lib/field").Field[]) => {
70
- packed: import("o1js/dist/node/lib/field").Field[];
71
- };
72
- sizeInFields(): number;
73
- check: (value: {
74
- packed: import("o1js/dist/node/lib/field").Field[];
75
- }) => void;
76
- toInput: (x: {
77
- packed: import("o1js/dist/node/lib/field").Field[];
78
- }) => {
79
- fields?: import("o1js/dist/node/lib/field").Field[] | undefined;
80
- packed?: [import("o1js/dist/node/lib/field").Field, number][] | undefined;
81
- };
82
- toJSON: (x: {
83
- packed: import("o1js/dist/node/lib/field").Field[];
84
- }) => {
85
- packed: string[];
86
- };
87
- fromJSON: (x: {
88
- packed: string[];
89
- }) => {
90
- packed: import("o1js/dist/node/lib/field").Field[];
91
- };
92
- };
1
+ import { Field, InferProvable } from 'o1js';
2
+ export declare function PackingPlant<A, T extends InferProvable<A> = InferProvable<A>>(elementType: A, l: number, bitSize: bigint): (abstract new (packed: Field) => {
3
+ assertEquals(other: any): void;
4
+ packed: import("o1js/dist/node/lib/field").Field;
5
+ }) & {
6
+ type: import("o1js/dist/node/bindings/lib/provable-snarky").ProvableExtended<{
7
+ packed: import("o1js/dist/node/lib/field").Field;
8
+ }, {
9
+ packed: string;
10
+ }>;
11
+ l: number;
12
+ bitSize: bigint;
13
+ extractField(input: T): Field;
14
+ sizeInBits(): bigint;
15
+ unpack(f: Field): Array<T>;
16
+ /**
17
+ *
18
+ * @param unpacked Array of the implemented packed type
19
+ * @throws if the length of the array is longer than the length of the implementing factory config
20
+ */
21
+ checkPack(unpacked: Array<T>): void;
22
+ /**
23
+ *
24
+ * @param unpacked Array of the implemented packed type, must be shorter than the max allowed, which varies by type, will throw if the input is too long
25
+ * @returns Field, packed with the information from the unpacked input
26
+ */
27
+ pack(unpacked: Array<T>): Field;
28
+ /**
29
+ *
30
+ * @param f Field, packed with the information, as returned by #pack
31
+ * @returns Array of bigints, which can be decoded by the implementing class into the final type
32
+ */
33
+ unpackToBigints(f: Field): Array<bigint>;
34
+ _isStruct: true;
35
+ toFields: (value: {
36
+ packed: import("o1js/dist/node/lib/field").Field;
37
+ }) => import("o1js/dist/node/lib/field").Field[];
38
+ toAuxiliary: (value?: {
39
+ packed: import("o1js/dist/node/lib/field").Field;
40
+ } | undefined) => any[];
41
+ fromFields: (fields: import("o1js/dist/node/lib/field").Field[]) => {
42
+ packed: import("o1js/dist/node/lib/field").Field;
43
+ };
44
+ sizeInFields(): number;
45
+ check: (value: {
46
+ packed: import("o1js/dist/node/lib/field").Field;
47
+ }) => void;
48
+ toInput: (x: {
49
+ packed: import("o1js/dist/node/lib/field").Field;
50
+ }) => {
51
+ fields?: import("o1js/dist/node/lib/field").Field[] | undefined;
52
+ packed?: [import("o1js/dist/node/lib/field").Field, number][] | undefined;
53
+ };
54
+ toJSON: (x: {
55
+ packed: import("o1js/dist/node/lib/field").Field;
56
+ }) => {
57
+ packed: string;
58
+ };
59
+ fromJSON: (x: {
60
+ packed: string;
61
+ }) => {
62
+ packed: import("o1js/dist/node/lib/field").Field;
63
+ };
64
+ };
65
+ export declare function MultiPackingPlant<A, T extends InferProvable<A> = InferProvable<A>>(elementType: A, l: number, bitSize: bigint): (abstract new (packed: Array<Field>) => {
66
+ assertEquals(other: any): void;
67
+ packed: import("o1js/dist/node/lib/field").Field[];
68
+ }) & {
69
+ type: import("o1js/dist/node/bindings/lib/provable-snarky").ProvableExtended<{
70
+ packed: import("o1js/dist/node/lib/field").Field[];
71
+ }, {
72
+ packed: string[];
73
+ }>;
74
+ l: number;
75
+ n: number;
76
+ bitSize: bigint;
77
+ extractField(input: T | undefined): Field;
78
+ sizeInBits(): bigint;
79
+ elementsPerField(): number;
80
+ unpack(fields: Array<Field>): Array<T>;
81
+ /**
82
+ *
83
+ * @param unpacked Array of the implemented packed type
84
+ * @throws if the length of the array is longer than the length of the implementing factory config
85
+ */
86
+ checkPack(unpacked: Array<T>): void;
87
+ /**
88
+ *
89
+ * @param unpacked Array of the implemented packed type, must be shorter than the max allowed, which varies by type, will throw if the input is too long
90
+ * @returns Array of Fields, packed such that each Field has as much information as possible
91
+ *
92
+ * e.g. 15 Characters pack into 1 Field. 15 or fewer Characters will return an array of 1 Field
93
+ * 30 of fewer Characters will return an aray of 2 Fields
94
+ */
95
+ pack(unpacked: Array<T>): Array<Field>;
96
+ /**
97
+ *
98
+ * @param fields Array of Fields, packed such that each Field has as much information as possible, as returned in #pack
99
+ * @returns Array of bigints, which can be decoded by the implementing class into the final type
100
+ */
101
+ unpackToBigints(fields: Array<Field>): Array<bigint>;
102
+ _isStruct: true;
103
+ toFields: (value: {
104
+ packed: import("o1js/dist/node/lib/field").Field[];
105
+ }) => import("o1js/dist/node/lib/field").Field[];
106
+ toAuxiliary: (value?: {
107
+ packed: import("o1js/dist/node/lib/field").Field[];
108
+ } | undefined) => any[];
109
+ fromFields: (fields: import("o1js/dist/node/lib/field").Field[]) => {
110
+ packed: import("o1js/dist/node/lib/field").Field[];
111
+ };
112
+ sizeInFields(): number;
113
+ check: (value: {
114
+ packed: import("o1js/dist/node/lib/field").Field[];
115
+ }) => void;
116
+ toInput: (x: {
117
+ packed: import("o1js/dist/node/lib/field").Field[];
118
+ }) => {
119
+ fields?: import("o1js/dist/node/lib/field").Field[] | undefined;
120
+ packed?: [import("o1js/dist/node/lib/field").Field, number][] | undefined;
121
+ };
122
+ toJSON: (x: {
123
+ packed: import("o1js/dist/node/lib/field").Field[];
124
+ }) => {
125
+ packed: string[];
126
+ };
127
+ fromJSON: (x: {
128
+ packed: string[];
129
+ }) => {
130
+ packed: import("o1js/dist/node/lib/field").Field[];
131
+ };
132
+ };
@@ -1,75 +1,191 @@
1
- import { Field, Struct, Poseidon, provable, Provable, } from 'o1js';
2
- const MAX_BITS_PER_FIELD = 254n;
3
- export function PackingPlant(elementType, l, bitSize) {
4
- if (bitSize * BigInt(l) > MAX_BITS_PER_FIELD) {
5
- throw new Error(`The Packing Plant is only accepting orders that can fit into one Field, try using MultiPackingPlant`);
6
- }
7
- class Packed_ extends Struct({
8
- packed: Field,
9
- }) {
10
- constructor(packed, aux) {
11
- if (aux.length > l) {
12
- throw new Error(`Length of aux data is too long, input of size ${aux.length} is larger than max allowed ${l}`);
13
- }
14
- super({ packed });
15
- this.bitSize = bitSize;
16
- this.aux = aux;
17
- }
18
- static toAuxiliary(value) {
19
- throw new Error('Must implement toAuxiliary');
20
- return [];
21
- }
22
- static pack(aux) {
23
- throw new Error('Must implement pack');
24
- let f = Field(0);
25
- return f;
26
- }
27
- static unpack(f) {
28
- return this.toAuxiliary({ packed: f });
29
- }
30
- assertEquals(other) {
31
- this.packed.assertEquals(other.packed);
32
- }
33
- }
34
- Packed_.type = provable({ packed: Field }, {});
35
- Packed_.l = l;
36
- return Packed_;
37
- }
38
- export function MultiPackingPlant(elementType, l, bitSize) {
39
- if (bitSize * BigInt(l) > 8n * MAX_BITS_PER_FIELD) {
40
- throw new Error(`The Packing Plant is only accepting orders that can fit into eight Fields`);
41
- }
42
- const n = Math.ceil(Number(bitSize * BigInt(l)) / Number(255n));
43
- class Packed_ extends Struct({
44
- packed: Provable.Array(Field, n),
45
- }) {
46
- constructor(packed, aux) {
47
- if (aux.length > l) {
48
- throw new Error('Length of aux data is too long');
49
- }
50
- super({ packed });
51
- this.bitSize = bitSize;
52
- this.aux = aux;
53
- }
54
- static toAuxiliary(value) {
55
- throw new Error('Must implement toAuxiliary');
56
- return [];
57
- }
58
- static pack(aux) {
59
- throw new Error('Must implement pack');
60
- let f = [Field(0)];
61
- return f;
62
- }
63
- static unpack(fields) {
64
- return this.toAuxiliary({ packed: fields });
65
- }
66
- assertEquals(other) {
67
- Poseidon.hash(this.packed).assertEquals(Poseidon.hash(other.packed));
68
- }
69
- }
70
- Packed_.type = provable({ packed: Provable.Array(Field, n) }, {});
71
- Packed_.l = l;
72
- Packed_.n = n;
73
- return Packed_;
74
- }
1
+ import { Field, Struct, provable, Provable, } from 'o1js';
2
+ const MAX_BITS_PER_FIELD = 254n;
3
+ export function PackingPlant(elementType, l, bitSize) {
4
+ if (bitSize * BigInt(l) > MAX_BITS_PER_FIELD) {
5
+ throw new Error(`The Packing Plant is only accepting orders that can fit into one Field, try using MultiPackingPlant`);
6
+ }
7
+ class Packed_ extends Struct({
8
+ packed: Field,
9
+ }) {
10
+ constructor(packed) {
11
+ super({ packed });
12
+ }
13
+ // Must implement these in type-specific implementation
14
+ static extractField(input) {
15
+ throw new Error('Must implement extractField');
16
+ }
17
+ static sizeInBits() {
18
+ throw new Error('Must implement sizeInBits');
19
+ }
20
+ static unpack(f) {
21
+ throw new Error('Must implement unpack');
22
+ }
23
+ // End
24
+ /**
25
+ *
26
+ * @param unpacked Array of the implemented packed type
27
+ * @throws if the length of the array is longer than the length of the implementing factory config
28
+ */
29
+ static checkPack(unpacked) {
30
+ if (unpacked.length > l) {
31
+ throw new Error(`Input of size ${unpacked.length} is larger than expected size of ${l}`);
32
+ }
33
+ }
34
+ /**
35
+ *
36
+ * @param unpacked Array of the implemented packed type, must be shorter than the max allowed, which varies by type, will throw if the input is too long
37
+ * @returns Field, packed with the information from the unpacked input
38
+ */
39
+ static pack(unpacked) {
40
+ this.checkPack(unpacked);
41
+ let f = this.extractField(unpacked[0]);
42
+ const n = Math.min(unpacked.length, l);
43
+ for (let i = 1; i < n; i++) {
44
+ const c = Field((2n ** this.sizeInBits()) ** BigInt(i));
45
+ f = f.add(this.extractField(unpacked[i]).mul(c));
46
+ }
47
+ return f;
48
+ }
49
+ /**
50
+ *
51
+ * @param f Field, packed with the information, as returned by #pack
52
+ * @returns Array of bigints, which can be decoded by the implementing class into the final type
53
+ */
54
+ static unpackToBigints(f) {
55
+ let unpacked = new Array(l);
56
+ unpacked.fill(0n);
57
+ let packedN;
58
+ if (f) {
59
+ packedN = f.toBigInt();
60
+ }
61
+ else {
62
+ throw new Error('No Packed Value Provided');
63
+ }
64
+ for (let i = 0; i < l; i++) {
65
+ unpacked[i] = packedN & ((1n << this.sizeInBits()) - 1n);
66
+ packedN >>= this.sizeInBits();
67
+ }
68
+ return unpacked;
69
+ }
70
+ assertEquals(other) {
71
+ this.packed.assertEquals(other.packed);
72
+ }
73
+ }
74
+ Packed_.type = provable({ packed: Field }, {});
75
+ Packed_.l = l;
76
+ Packed_.bitSize = bitSize;
77
+ return Packed_;
78
+ }
79
+ export function MultiPackingPlant(elementType, l, bitSize) {
80
+ if (bitSize * BigInt(l) > 8n * MAX_BITS_PER_FIELD) {
81
+ throw new Error(`The Packing Plant is only accepting orders that can fit into eight Fields`);
82
+ }
83
+ const n = Math.ceil(Number(bitSize * BigInt(l)) / Number(255n));
84
+ class Packed_ extends Struct({
85
+ packed: Provable.Array(Field, n),
86
+ }) {
87
+ constructor(packed) {
88
+ super({ packed });
89
+ }
90
+ // Must implement these in type-specific implementation
91
+ static extractField(input) {
92
+ throw new Error('Must implement extractField');
93
+ }
94
+ static sizeInBits() {
95
+ throw new Error('Must implement sizeInBits');
96
+ }
97
+ static elementsPerField() {
98
+ throw new Error('Must implement elementsPerField');
99
+ }
100
+ static unpack(fields) {
101
+ throw new Error('Must implement unpack');
102
+ }
103
+ // End
104
+ /**
105
+ *
106
+ * @param unpacked Array of the implemented packed type
107
+ * @throws if the length of the array is longer than the length of the implementing factory config
108
+ */
109
+ static checkPack(unpacked) {
110
+ if (unpacked.length > this.l) {
111
+ throw new Error(`Input of size ${unpacked.length} is larger than expected size of ${l}`);
112
+ }
113
+ }
114
+ /**
115
+ *
116
+ * @param unpacked Array of the implemented packed type, must be shorter than the max allowed, which varies by type, will throw if the input is too long
117
+ * @returns Array of Fields, packed such that each Field has as much information as possible
118
+ *
119
+ * e.g. 15 Characters pack into 1 Field. 15 or fewer Characters will return an array of 1 Field
120
+ * 30 of fewer Characters will return an aray of 2 Fields
121
+ */
122
+ static pack(unpacked) {
123
+ this.checkPack(unpacked);
124
+ const q = this.elementsPerField();
125
+ let fields = [];
126
+ let mutableUnpacked = [...unpacked];
127
+ for (let i = 0; i < this.n; i++) {
128
+ let f = this.extractField(mutableUnpacked[i * q]);
129
+ if (!f) {
130
+ throw new Error('Unexpected Array Length');
131
+ }
132
+ for (let j = 1; j < q; j++) {
133
+ const idx = i * q + j;
134
+ let value = this.extractField(mutableUnpacked[idx]);
135
+ if (!value) {
136
+ throw new Error('Unexpected Array Length');
137
+ }
138
+ value = value || Field(0);
139
+ const c = Field((2n ** this.sizeInBits()) ** BigInt(j));
140
+ f = f.add(value.mul(c));
141
+ }
142
+ fields.push(f);
143
+ }
144
+ return fields;
145
+ }
146
+ /**
147
+ *
148
+ * @param fields Array of Fields, packed such that each Field has as much information as possible, as returned in #pack
149
+ * @returns Array of bigints, which can be decoded by the implementing class into the final type
150
+ */
151
+ static unpackToBigints(fields) {
152
+ let uints_ = new Array(this.l); // array length is number of elements per field * number of fields
153
+ uints_.fill(0n);
154
+ let packedNs = new Array(this.n);
155
+ packedNs.fill(0n);
156
+ const packedArg = new Array(this.n);
157
+ packedArg.fill(Field(0), 0, this.n);
158
+ for (let i = 0; i < this.n; i++) {
159
+ if (fields[i]) {
160
+ packedArg[i] = fields[i];
161
+ }
162
+ }
163
+ if (packedArg.length !== this.n) {
164
+ throw new Error(`Packed value must be exactly ${this.n} in length`);
165
+ }
166
+ for (let i = 0; i < this.n; i++) {
167
+ packedNs[i] = packedArg[i].toConstant().toBigInt();
168
+ }
169
+ for (let i = 0; i < packedNs.length; i++) {
170
+ let packedN = packedNs[i];
171
+ for (let j = 0; j < this.elementsPerField(); j++) {
172
+ const k = i * this.elementsPerField() + j;
173
+ uints_[k] = packedN & ((1n << this.sizeInBits()) - 1n);
174
+ packedN >>= this.sizeInBits();
175
+ }
176
+ }
177
+ return uints_;
178
+ }
179
+ assertEquals(other) {
180
+ for (let x = 0; x < n; x++) {
181
+ this.packed[x].assertEquals(other.packed[x]);
182
+ }
183
+ }
184
+ }
185
+ Packed_.type = provable({ packed: Provable.Array(Field, n) }, {});
186
+ Packed_.l = l;
187
+ Packed_.n = n;
188
+ Packed_.bitSize = bitSize;
189
+ return Packed_;
190
+ }
75
191
  //# sourceMappingURL=PackingPlant.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PackingPlant.js","sourceRoot":"","sources":["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