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
@@ -1,77 +1,85 @@
1
- import { Field, Bool } from 'o1js';
2
- export declare function PackedBoolFactory(l: number): {
3
- new (packed: import("o1js/dist/node/lib/field.js").Field, aux: import("o1js/dist/node/lib/bool.js").Bool[]): {
4
- toBooleans(): Array<boolean>;
5
- packed: import("o1js/dist/node/lib/field.js").Field;
6
- aux: import("o1js/dist/node/lib/bool.js").Bool[];
7
- bitSize: bigint;
8
- assertEquals(other: {
9
- packed: import("o1js/dist/node/lib/field.js").Field;
10
- aux: import("o1js/dist/node/lib/bool.js").Bool[];
11
- bitSize: bigint;
12
- assertEquals(other: any): void;
13
- }): void;
14
- };
15
- toAuxiliary(value?: {
16
- packed: Field;
17
- } | undefined): Array<Bool>;
18
- pack(aux: Array<Bool>): Field;
19
- fromAuxiliary(aux: Array<Bool>): {
20
- toBooleans(): Array<boolean>;
21
- packed: import("o1js/dist/node/lib/field.js").Field;
22
- aux: import("o1js/dist/node/lib/bool.js").Bool[];
23
- bitSize: bigint;
24
- assertEquals(other: {
25
- packed: import("o1js/dist/node/lib/field.js").Field;
26
- aux: import("o1js/dist/node/lib/bool.js").Bool[];
27
- bitSize: bigint;
28
- assertEquals(other: any): void;
29
- }): void;
30
- };
31
- fromBooleans(bigints: Array<boolean>): {
32
- toBooleans(): Array<boolean>;
33
- packed: import("o1js/dist/node/lib/field.js").Field;
34
- aux: import("o1js/dist/node/lib/bool.js").Bool[];
35
- bitSize: bigint;
36
- assertEquals(other: {
37
- packed: import("o1js/dist/node/lib/field.js").Field;
38
- aux: import("o1js/dist/node/lib/bool.js").Bool[];
39
- bitSize: bigint;
40
- assertEquals(other: any): void;
41
- }): void;
42
- };
43
- type: import("o1js/dist/node/bindings/lib/provable-snarky.js").ProvableExtended<{
44
- packed: import("o1js/dist/node/lib/field.js").Field;
45
- }, {
46
- packed: string;
47
- }>;
48
- l: number;
49
- unpack(f: import("o1js/dist/node/lib/field.js").Field): import("o1js/dist/node/lib/bool.js").Bool[];
50
- _isStruct: true;
51
- toFields: (value: {
52
- packed: import("o1js/dist/node/lib/field.js").Field;
53
- }) => import("o1js/dist/node/lib/field.js").Field[];
54
- fromFields: (fields: import("o1js/dist/node/lib/field.js").Field[]) => {
55
- packed: import("o1js/dist/node/lib/field.js").Field;
56
- };
57
- sizeInFields(): number;
58
- check: (value: {
59
- packed: import("o1js/dist/node/lib/field.js").Field;
60
- }) => void;
61
- toInput: (x: {
62
- packed: import("o1js/dist/node/lib/field.js").Field;
63
- }) => {
64
- fields?: import("o1js/dist/node/lib/field.js").Field[] | undefined;
65
- packed?: [import("o1js/dist/node/lib/field.js").Field, number][] | undefined;
66
- };
67
- toJSON: (x: {
68
- packed: import("o1js/dist/node/lib/field.js").Field;
69
- }) => {
70
- packed: string;
71
- };
72
- fromJSON: (x: {
73
- packed: string;
74
- }) => {
75
- packed: import("o1js/dist/node/lib/field.js").Field;
76
- };
77
- };
1
+ import { Field, Bool } from 'o1js';
2
+ export declare function PackedBoolFactory(l?: number): {
3
+ new (packed: import("o1js/dist/node/lib/field.js").Field): {
4
+ toBooleans(): Array<boolean>;
5
+ assertEquals(other: {
6
+ assertEquals(other: any): void;
7
+ packed: import("o1js/dist/node/lib/field.js").Field;
8
+ }): void;
9
+ packed: import("o1js/dist/node/lib/field.js").Field;
10
+ };
11
+ extractField(input: Bool): Field;
12
+ sizeInBits(): bigint;
13
+ /**
14
+ *
15
+ * @param f Field, packed with the information, as returned by #pack
16
+ * @returns Array of Bool
17
+ */
18
+ unpack(f: Field): Bool[];
19
+ /**
20
+ *
21
+ * @param bools Array of Bools to be packed
22
+ * @returns Instance of the implementing class
23
+ */
24
+ fromBools(bools: Array<Bool>): {
25
+ toBooleans(): Array<boolean>;
26
+ assertEquals(other: {
27
+ assertEquals(other: any): void;
28
+ packed: import("o1js/dist/node/lib/field.js").Field;
29
+ }): void;
30
+ packed: import("o1js/dist/node/lib/field.js").Field;
31
+ };
32
+ /**
33
+ *
34
+ * @param booleans Array of booleans to be packed
35
+ * @returns Instance of the implementing class
36
+ */
37
+ fromBooleans(booleans: Array<boolean>): {
38
+ toBooleans(): Array<boolean>;
39
+ assertEquals(other: {
40
+ assertEquals(other: any): void;
41
+ packed: import("o1js/dist/node/lib/field.js").Field;
42
+ }): void;
43
+ packed: import("o1js/dist/node/lib/field.js").Field;
44
+ };
45
+ type: import("o1js/dist/node/bindings/lib/provable-snarky.js").ProvableExtended<{
46
+ packed: import("o1js/dist/node/lib/field.js").Field;
47
+ }, {
48
+ packed: string;
49
+ }>;
50
+ l: number;
51
+ bitSize: bigint;
52
+ checkPack(unpacked: import("o1js/dist/node/lib/bool.js").Bool[]): void;
53
+ pack(unpacked: import("o1js/dist/node/lib/bool.js").Bool[]): import("o1js/dist/node/lib/field.js").Field;
54
+ unpackToBigints(f: import("o1js/dist/node/lib/field.js").Field): bigint[];
55
+ _isStruct: true;
56
+ toFields: (value: {
57
+ packed: import("o1js/dist/node/lib/field.js").Field;
58
+ }) => import("o1js/dist/node/lib/field.js").Field[];
59
+ toAuxiliary: (value?: {
60
+ packed: import("o1js/dist/node/lib/field.js").Field;
61
+ } | undefined) => any[];
62
+ fromFields: (fields: import("o1js/dist/node/lib/field.js").Field[]) => {
63
+ packed: import("o1js/dist/node/lib/field.js").Field;
64
+ };
65
+ sizeInFields(): number;
66
+ check: (value: {
67
+ packed: import("o1js/dist/node/lib/field.js").Field;
68
+ }) => void;
69
+ toInput: (x: {
70
+ packed: import("o1js/dist/node/lib/field.js").Field;
71
+ }) => {
72
+ fields?: import("o1js/dist/node/lib/field.js").Field[] | undefined;
73
+ packed?: [import("o1js/dist/node/lib/field.js").Field, number][] | undefined;
74
+ };
75
+ toJSON: (x: {
76
+ packed: import("o1js/dist/node/lib/field.js").Field;
77
+ }) => {
78
+ packed: string;
79
+ };
80
+ fromJSON: (x: {
81
+ packed: string;
82
+ }) => {
83
+ packed: import("o1js/dist/node/lib/field.js").Field;
84
+ };
85
+ };
@@ -1,48 +1,50 @@
1
- import { Field, Provable, Bool } from 'o1js';
2
- import { PackingPlant } from '../PackingPlant.js';
3
- const SIZE_IN_BITS = 1n;
4
- export function PackedBoolFactory(l) {
5
- class PackedBool_ extends PackingPlant(Bool, l, SIZE_IN_BITS) {
6
- static toAuxiliary(value) {
7
- const auxiliary = Provable.witness(Provable.Array(Bool, l), () => {
8
- let bools_ = new Array(l);
9
- bools_.fill(0n);
10
- let packedN;
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
- bools_[i] = packedN & ((1n << SIZE_IN_BITS) - 1n);
19
- packedN >>= SIZE_IN_BITS;
20
- }
21
- return bools_.map((x) => Bool.fromJSON(Boolean(x)));
22
- });
23
- return auxiliary;
24
- }
25
- static pack(aux) {
26
- let f = aux[0].toField();
27
- const n = Math.min(aux.length, l);
28
- for (let i = 1; i < n; i++) {
29
- const c = Field((2n ** SIZE_IN_BITS) ** BigInt(i));
30
- f = f.add(aux[i].toField().mul(c));
31
- }
32
- return f;
33
- }
34
- static fromAuxiliary(aux) {
35
- const packed = PackedBool_.pack(aux);
36
- return new PackedBool_(packed, aux);
37
- }
38
- static fromBooleans(bigints) {
39
- const uint32s = bigints.map((x) => Bool(x));
40
- return this.fromAuxiliary(uint32s);
41
- }
42
- toBooleans() {
43
- return PackedBool_.unpack(this.packed).map((x) => x.toBoolean());
44
- }
45
- }
46
- return PackedBool_;
47
- }
1
+ import { Provable, Bool } from 'o1js';
2
+ import { PackingPlant } from '../PackingPlant.js';
3
+ const L = 254; // 254 1-bit booleans fit in one Field
4
+ const SIZE_IN_BITS = 1n;
5
+ export function PackedBoolFactory(l = L) {
6
+ class PackedBool_ extends PackingPlant(Bool, l, SIZE_IN_BITS) {
7
+ static extractField(input) {
8
+ return input.toField();
9
+ }
10
+ static sizeInBits() {
11
+ return SIZE_IN_BITS;
12
+ }
13
+ /**
14
+ *
15
+ * @param f Field, packed with the information, as returned by #pack
16
+ * @returns Array of Bool
17
+ */
18
+ static unpack(f) {
19
+ const unpacked = Provable.witness(Provable.Array(Bool, l), () => {
20
+ const unpacked = this.unpackToBigints(f);
21
+ return unpacked.map((x) => Bool.fromJSON(Boolean(x)));
22
+ });
23
+ f.assertEquals(PackedBool_.pack(unpacked));
24
+ return unpacked;
25
+ }
26
+ /**
27
+ *
28
+ * @param bools Array of Bools to be packed
29
+ * @returns Instance of the implementing class
30
+ */
31
+ static fromBools(bools) {
32
+ const packed = PackedBool_.pack(bools);
33
+ return new PackedBool_(packed);
34
+ }
35
+ /**
36
+ *
37
+ * @param booleans Array of booleans to be packed
38
+ * @returns Instance of the implementing class
39
+ */
40
+ static fromBooleans(booleans) {
41
+ const bools = booleans.map((x) => Bool(x));
42
+ return PackedBool_.fromBools(bools);
43
+ }
44
+ toBooleans() {
45
+ return PackedBool_.unpack(this.packed).map((x) => x.toBoolean());
46
+ }
47
+ }
48
+ return PackedBool_;
49
+ }
48
50
  //# sourceMappingURL=PackedBool.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PackedBool.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/PackedBool.ts"],"names":[],"mappings":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AAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3C,OAAO,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC;QAED,UAAU;YACR,OAAO,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QACnE,CAAC;KACF;IACD,OAAO,WAAW,CAAC;AACrB,CAAC"}
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,76 +1,76 @@
1
- import { Bool, Provable } from 'o1js';
2
- import { PackedBoolFactory } from './PackedBool';
3
- describe('PackedBool', () => {
4
- class PackedBool extends PackedBoolFactory(254) {
5
- }
6
- const booleans = new Array(127).fill([true, false]).flat();
7
- const bools = booleans.map((x) => Bool(x));
8
- describe('Outside of the circuit', () => {
9
- it('#fromBooleans', () => {
10
- const myPackedBool = PackedBool.fromBooleans(booleans);
11
- expect(myPackedBool.toBooleans()).toMatchObject(booleans);
12
- });
13
- it('#pack and #unPack', () => {
14
- const packed = PackedBool.pack(bools);
15
- const unpacked = PackedBool.unpack(packed);
16
- expect(unpacked.length).toBe(bools.length);
17
- expect(unpacked).toMatchObject(bools);
18
- });
19
- });
20
- describe('Provable Properties', () => {
21
- it('#sizeInFields', () => {
22
- class one extends PackedBoolFactory(1) {
23
- }
24
- class two_five_four extends PackedBoolFactory(254) {
25
- }
26
- expect(one.sizeInFields()).toBe(1);
27
- expect(two_five_four.sizeInFields()).toBe(1);
28
- });
29
- });
30
- describe('Defensive Cases', () => {
31
- it('throws for input >= 255 bools', () => {
32
- expect(() => PackedBoolFactory(254)).not.toThrow();
33
- expect(() => PackedBoolFactory(255)).toThrow();
34
- });
35
- it('initalizes with more input than allowed', () => {
36
- const tooMany = [...booleans].concat(false);
37
- expect(() => {
38
- PackedBool.fromBooleans(tooMany);
39
- }).toThrow();
40
- });
41
- it('initalizes with less input than specified', () => {
42
- const booleans = [true, false];
43
- const pad = new Array(252);
44
- pad.fill(false);
45
- const expected = booleans.concat(pad);
46
- expect(PackedBool.fromBooleans(booleans).toBooleans()).toMatchObject(expected);
47
- });
48
- });
49
- describe('In the circuit', () => {
50
- const outsidePackedBool = PackedBool.fromBooleans(booleans);
51
- it('Initializes', () => {
52
- expect(() => {
53
- Provable.runAndCheck(() => {
54
- const packedBool = new PackedBool(outsidePackedBool.packed, outsidePackedBool.aux);
55
- PackedBool.check({ packed: packedBool.packed });
56
- });
57
- }).not.toThrow();
58
- });
59
- it('#assertEquals', () => {
60
- expect(() => {
61
- Provable.runAndCheck(() => {
62
- const packedBool = new PackedBool(outsidePackedBool.packed, outsidePackedBool.aux);
63
- packedBool.assertEquals(outsidePackedBool);
64
- });
65
- }).not.toThrow();
66
- expect(() => {
67
- Provable.runAndCheck(() => {
68
- const fakePacked = outsidePackedBool.packed.add(32);
69
- const packedBool = new PackedBool(fakePacked, outsidePackedBool.aux);
70
- packedBool.assertEquals(outsidePackedBool);
71
- });
72
- }).toThrow();
73
- });
74
- });
75
- });
1
+ import { Bool, Provable } from 'o1js';
2
+ import { PackedBoolFactory } from './PackedBool';
3
+ describe('PackedBool', () => {
4
+ const booleans = new Array(127).fill([true, false]).flat();
5
+ const bools = booleans.map((x) => Bool(x));
6
+ class PackedBool extends PackedBoolFactory() {
7
+ }
8
+ describe('Outside of the circuit', () => {
9
+ it('#fromBooleans', () => {
10
+ const myPackedBool = PackedBool.fromBooleans(booleans);
11
+ expect(myPackedBool.toBooleans()).toMatchObject(booleans);
12
+ });
13
+ it('#pack and #unPack', () => {
14
+ const packed = PackedBool.pack(bools);
15
+ const unpacked = PackedBool.unpack(packed);
16
+ expect(unpacked.length).toBe(bools.length);
17
+ expect(unpacked).toMatchObject(bools);
18
+ });
19
+ });
20
+ describe('Provable Properties', () => {
21
+ it('#sizeInFields', () => {
22
+ class one extends PackedBoolFactory(1) {
23
+ }
24
+ class two_five_four extends PackedBoolFactory(254) {
25
+ }
26
+ expect(one.sizeInFields()).toBe(1);
27
+ expect(two_five_four.sizeInFields()).toBe(1);
28
+ });
29
+ });
30
+ describe('Defensive Cases', () => {
31
+ it('throws for input >= 255 bools', () => {
32
+ expect(() => PackedBoolFactory(254)).not.toThrow();
33
+ expect(() => PackedBoolFactory(255)).toThrow();
34
+ });
35
+ it('initalizes with more input than allowed', () => {
36
+ const tooMany = [...booleans].concat(false);
37
+ expect(() => {
38
+ PackedBool.fromBooleans(tooMany);
39
+ }).toThrow();
40
+ });
41
+ it('initalizes with less input than specified', () => {
42
+ const booleans = [true, false];
43
+ const pad = new Array(252);
44
+ pad.fill(false);
45
+ const expected = booleans.concat(pad);
46
+ expect(PackedBool.fromBooleans(booleans).toBooleans()).toMatchObject(expected);
47
+ });
48
+ });
49
+ describe('In the circuit', () => {
50
+ const outsidePackedBool = PackedBool.fromBooleans(booleans);
51
+ it('Initializes', () => {
52
+ expect(() => {
53
+ Provable.runAndCheck(() => {
54
+ const packedBool = new PackedBool(outsidePackedBool.packed);
55
+ PackedBool.check({ packed: packedBool.packed });
56
+ });
57
+ }).not.toThrow();
58
+ });
59
+ it('#assertEquals', () => {
60
+ expect(() => {
61
+ Provable.runAndCheck(() => {
62
+ const packedBool = new PackedBool(outsidePackedBool.packed);
63
+ packedBool.assertEquals(outsidePackedBool);
64
+ });
65
+ }).not.toThrow();
66
+ expect(() => {
67
+ Provable.runAndCheck(() => {
68
+ const fakePacked = outsidePackedBool.packed.add(32);
69
+ const packedBool = new PackedBool(fakePacked);
70
+ packedBool.assertEquals(outsidePackedBool);
71
+ });
72
+ }).toThrow();
73
+ });
74
+ });
75
+ });
76
76
  //# sourceMappingURL=PackedBool.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PackedBool.test.js","sourceRoot":"","sources":["../../../../src/lib/packed-types/PackedBool.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,MAAM,CAA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