|
1 | | -import { TFHE_RS_ZK_MAX_BITS, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT } from 'core/consts.js'; |
2 | | -import { CofheError, CofheErrorCode } from '../error.js'; |
3 | | -import { type EncryptableItem, FheTypes } from '../types.js'; |
4 | | -import { toBigIntOrThrow, validateBigIntInRange, toHexString, hexToBytes } from '../utils.js'; |
| 1 | +import { TFHE_RS_ZK_MAX_BITS, TFHE_RS_SAFE_SERIALIZATION_SIZE_LIMIT } from '../consts'; |
| 2 | +import { CofheError, CofheErrorCode } from '../error'; |
| 3 | +import { type EncryptableItem, FheTypes } from '../types'; |
| 4 | +import { toBigIntOrThrow, validateBigIntInRange, toHexString, hexToBytes } from '../utils'; |
5 | 5 |
|
6 | 6 | // ===== TYPES ===== |
7 | 7 |
|
@@ -90,67 +90,66 @@ export const MAX_UINT64: bigint = 18446744073709551615n; // 2^64 - 1 |
90 | 90 | export const MAX_UINT128: bigint = 340282366920938463463374607431768211455n; // 2^128 - 1 |
91 | 91 | export const MAX_UINT256: bigint = 115792089237316195423570985008687907853269984665640564039457584007913129640319n; // 2^256 - 1 |
92 | 92 | export const MAX_UINT160: bigint = 1461501637330902918203684832716283019655932542975n; // 2^160 - 1 |
93 | | -export const MAX_ENCRYPTABLE_BITS: number = 2048; |
94 | 93 |
|
95 | 94 | // ===== CORE FUNCTIONS ===== |
96 | 95 |
|
97 | 96 | export const zkPack = (items: EncryptableItem[], builder: ZkCiphertextListBuilder): ZkCiphertextListBuilder => { |
98 | | - let totalBits = 0n; |
| 97 | + let totalBits = 0; |
99 | 98 | for (const item of items) { |
100 | 99 | switch (item.utype) { |
101 | 100 | case FheTypes.Bool: { |
102 | 101 | builder.push_boolean(item.data); |
103 | | - totalBits += 1n; |
| 102 | + totalBits += 1; |
104 | 103 | break; |
105 | 104 | } |
106 | 105 | case FheTypes.Uint8: { |
107 | 106 | const bint = toBigIntOrThrow(item.data); |
108 | 107 | validateBigIntInRange(bint, MAX_UINT8); |
109 | 108 | builder.push_u8(parseInt(bint.toString())); |
110 | | - totalBits += 8n; |
| 109 | + totalBits += 8; |
111 | 110 | break; |
112 | 111 | } |
113 | 112 | case FheTypes.Uint16: { |
114 | 113 | const bint = toBigIntOrThrow(item.data); |
115 | 114 | validateBigIntInRange(bint, MAX_UINT16); |
116 | 115 | builder.push_u16(parseInt(bint.toString())); |
117 | | - totalBits += 16n; |
| 116 | + totalBits += 16; |
118 | 117 | break; |
119 | 118 | } |
120 | 119 | case FheTypes.Uint32: { |
121 | 120 | const bint = toBigIntOrThrow(item.data); |
122 | 121 | validateBigIntInRange(bint, MAX_UINT32); |
123 | 122 | builder.push_u32(parseInt(bint.toString())); |
124 | | - totalBits += 32n; |
| 123 | + totalBits += 32; |
125 | 124 | break; |
126 | 125 | } |
127 | 126 | case FheTypes.Uint64: { |
128 | 127 | const bint = toBigIntOrThrow(item.data); |
129 | 128 | validateBigIntInRange(bint, MAX_UINT64); |
130 | 129 | builder.push_u64(bint); |
131 | | - totalBits += 64n; |
| 130 | + totalBits += 64; |
132 | 131 | break; |
133 | 132 | } |
134 | 133 | case FheTypes.Uint128: { |
135 | 134 | const bint = toBigIntOrThrow(item.data); |
136 | 135 | validateBigIntInRange(bint, MAX_UINT128); |
137 | 136 | builder.push_u128(bint); |
138 | | - totalBits += 128n; |
| 137 | + totalBits += 128; |
139 | 138 | break; |
140 | 139 | } |
141 | 140 | // [U256-DISABLED] |
142 | 141 | // case FheTypes.Uint256: { |
143 | 142 | // const bint = toBigIntOrThrow(item.data); |
144 | 143 | // validateBigIntInRange(bint, MAX_UINT256); |
145 | 144 | // builder.push_u256(bint); |
146 | | - // totalBits += 256n; |
| 145 | + // totalBits += 256; |
147 | 146 | // break; |
148 | 147 | // } |
149 | 148 | case FheTypes.Uint160: { |
150 | 149 | const bint = toBigIntOrThrow(item.data); |
151 | 150 | validateBigIntInRange(bint, MAX_UINT160); |
152 | 151 | builder.push_u160(bint); |
153 | | - totalBits += 160n; |
| 152 | + totalBits += 160; |
154 | 153 | break; |
155 | 154 | } |
156 | 155 | default: { |
|
0 commit comments