Skip to content

Commit 14dece1

Browse files
committed
re-export functions
1 parent ad6e726 commit 14dece1

File tree

5 files changed

+122
-93
lines changed

5 files changed

+122
-93
lines changed

src/bignum.nr

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ pub comptime fn derive_bignum(
6666
MOD_BITS: u32,
6767
params: Quoted,
6868
) -> Quoted {
69-
let constrained_ops = quote { $crate::fns::constrained_ops };
70-
let unconstrained_ops = quote { $crate::fns::unconstrained_ops };
7169
let typ = strukt.as_type();
72-
let serialization = quote { $crate::fns::serialization };
7370
quote {
7471

7572
// implement BigNum for BigNum
@@ -127,100 +124,100 @@ pub comptime fn derive_bignum(
127124

128125
fn derive_from_seed<let SeedBytes: u32>(seed: [u8; SeedBytes]) -> Self {
129126
let params = Self::params();
130-
$typ::from_limbs($constrained_ops::derive_from_seed::<$N, $MOD_BITS, SeedBytes>(params, seed))
127+
$typ::from_limbs($crate::derive_from_seed::<$N, $MOD_BITS, SeedBytes>(params, seed))
131128
}
132129

133130
unconstrained fn __derive_from_seed<let SeedBytes: u32>(seed: [u8; SeedBytes]) -> Self {
134131
let params = Self::params();
135-
Self { limbs: $unconstrained_ops::__derive_from_seed::<$N, $MOD_BITS, SeedBytes>(params, seed) }
132+
Self { limbs: $crate::__derive_from_seed::<$N, $MOD_BITS, SeedBytes>(params, seed) }
136133
}
137134

138135
fn from_be_bytes(x: [u8; ($MOD_BITS + 7) / 8]) -> Self {
139-
Self { limbs: $serialization::from_be_bytes::<$N, $MOD_BITS>(x) }
136+
Self { limbs: $crate::from_be_bytes::<$N, $MOD_BITS>(x) }
140137
}
141138

142139
fn to_be_bytes(self) -> [u8; ($MOD_BITS + 7) / 8] {
143-
$serialization::to_be_bytes::<$N, $MOD_BITS>(self.limbs)
140+
$crate::to_be_bytes::<$N, $MOD_BITS>(self.limbs)
144141
}
145142

146143
fn from_le_bytes(x: [u8; ($MOD_BITS + 7) / 8]) -> Self {
147-
Self { limbs: $serialization::from_le_bytes::<$N, $MOD_BITS>(x) }
144+
Self { limbs: $crate::from_le_bytes::<$N, $MOD_BITS>(x) }
148145
}
149146

150147
fn to_le_bytes(self) -> [u8; ($MOD_BITS + 7) / 8] {
151-
$serialization::to_le_bytes::<$N, $MOD_BITS>(self.limbs)
148+
$crate::to_le_bytes::<$N, $MOD_BITS>(self.limbs)
152149
}
153150

154151
unconstrained fn __eq(self: Self, other: Self) -> bool {
155-
$crate::fns::unconstrained_ops::__eq(self.get_limbs(), other.get_limbs())
152+
$crate::__eq(self.get_limbs(), other.get_limbs())
156153
}
157154

158155
unconstrained fn __is_zero(self: Self) -> bool {
159-
$crate::fns::unconstrained_ops::__is_zero(self.get_limbs())
156+
$crate::__is_zero(self.get_limbs())
160157
}
161158

162159
unconstrained fn __neg(self: Self) -> Self {
163160
let params = Self::params();
164-
Self {limbs: $unconstrained_ops::__neg(params.modulus, self.get_limbs())}
161+
Self {limbs: $crate::__neg(params.modulus, self.get_limbs())}
165162
}
166163

167164
unconstrained fn __add(self: Self, other: Self) -> Self {
168165
let params = Self::params();
169-
Self {limbs: $unconstrained_ops::__add(params.modulus, self.get_limbs(), other.get_limbs())}
166+
Self {limbs: $crate::__add(params.modulus, self.get_limbs(), other.get_limbs())}
170167
}
171168

172169
unconstrained fn __sub(self: Self, other: Self) -> Self {
173170
let params = Self::params();
174-
Self {limbs: $unconstrained_ops::__sub(params.modulus, self.get_limbs(), other.get_limbs())}
171+
Self {limbs: $crate::__sub(params.modulus, self.get_limbs(), other.get_limbs())}
175172
}
176173

177174
unconstrained fn __mul(self: Self, other: Self) -> Self {
178175
let params = Self::params();
179-
Self {limbs: $unconstrained_ops::__mul(params, self.get_limbs(), other.get_limbs())}
176+
Self {limbs: $crate::__mul(params, self.get_limbs(), other.get_limbs())}
180177
}
181178

182179
unconstrained fn __sqr(self: Self) -> Self {
183180
let params = Self::params();
184-
Self {limbs: $unconstrained_ops::__sqr(params, self.get_limbs()) }
181+
Self {limbs: $crate::__sqr(params, self.get_limbs()) }
185182
}
186183

187184
unconstrained fn __div(self: Self, divisor: Self) -> Self {
188185
let params = Self::params();
189-
Self {limbs: $unconstrained_ops::__div(params, self.get_limbs(), divisor.get_limbs())}
186+
Self {limbs: $crate::__div(params, self.get_limbs(), divisor.get_limbs())}
190187
}
191188

192189
unconstrained fn __udiv_mod(self: Self, divisor: Self) -> (Self, Self) {
193-
let (q, r) = $unconstrained_ops::__udiv_mod(self.get_limbs(), divisor.get_limbs());
190+
let (q, r) = $crate::__udiv_mod(self.get_limbs(), divisor.get_limbs());
194191
(Self{limbs: q}, Self{limbs: r})
195192
}
196193

197194
unconstrained fn __invmod(self: Self) -> Self {
198195
let params = Self::params();
199196
assert(params.has_multiplicative_inverse);
200-
Self {limbs: $unconstrained_ops::__invmod(params, self.get_limbs())}
197+
Self {limbs: $crate::__invmod(params, self.get_limbs())}
201198
}
202199

203200
unconstrained fn __pow(self: Self, exponent: Self) -> Self {
204201
let params = Self::params();
205-
Self {limbs: $unconstrained_ops::__pow(params, self.get_limbs(), exponent.get_limbs())}
202+
Self {limbs: $crate::__pow(params, self.get_limbs(), exponent.get_limbs())}
206203
}
207204

208205
#[deprecated("use __sqrt")]
209206
unconstrained fn __tonelli_shanks_sqrt(self: Self) -> std::option::Option<Self> {
210207
let params = Self::params();
211-
let maybe_limbs: Option<[u128; $N]> = $unconstrained_ops::__sqrt(params, self.get_limbs());
208+
let maybe_limbs: Option<[u128; $N]> = $crate::__sqrt(params, self.get_limbs());
212209
maybe_limbs.map(|limbs| Self {limbs: limbs})
213210
}
214211

215212
unconstrained fn __sqrt(self: Self) -> std::option::Option<Self> {
216213
let params = Self::params();
217-
let maybe_limbs: Option<[u128; $N]> = $unconstrained_ops::__sqrt(params, self.get_limbs());
214+
let maybe_limbs: Option<[u128; $N]> = $crate::__sqrt(params, self.get_limbs());
218215
maybe_limbs.map(|limbs| Self {limbs: limbs })
219216
}
220217

221218
fn assert_is_not_equal(self: Self, other: Self) {
222219
let params = Self::params();
223-
$crate::fns::constrained_ops::assert_is_not_equal(
220+
$crate::assert_is_not_equal(
224221
params,
225222
self.get_limbs(),
226223
other.get_limbs(),
@@ -229,47 +226,47 @@ pub comptime fn derive_bignum(
229226

230227
fn validate_in_field(self: Self) {
231228
let params = Self::params();
232-
$constrained_ops::validate_in_field::<$N, $MOD_BITS>(params, self.get_limbs());
229+
$crate::validate_in_field::<$N, $MOD_BITS>(params, self.get_limbs());
233230
}
234231

235232
fn validate_in_range(self: Self) {
236-
$constrained_ops::validate_in_range::<u128, $N, $MOD_BITS>(self.get_limbs());
233+
$crate::validate_in_range::<u128, $N, $MOD_BITS>(self.get_limbs());
237234
}
238235

239236
fn sqr(self: Self) -> Self {
240237
let params = Self::params();
241-
Self { limbs: $constrained_ops::sqr::<$N, $MOD_BITS>(params, self.get_limbs()) }
238+
Self { limbs: $crate::sqr::<$N, $MOD_BITS>(params, self.get_limbs()) }
242239
}
243240

244241
fn udiv_mod(self: Self, divisor: Self) -> (Self, Self) {
245-
let (q, r) = $constrained_ops::udiv_mod::<$N, $MOD_BITS>(self.get_limbs(), divisor.get_limbs());
242+
let (q, r) = $crate::udiv_mod::<$N, $MOD_BITS>(self.get_limbs(), divisor.get_limbs());
246243
(Self {limbs: q}, Self {limbs: r})
247244
}
248245

249246
fn udiv(self: Self, divisor: Self) -> Self {
250-
Self {limbs: $constrained_ops::udiv::<$N, $MOD_BITS>(self.get_limbs(), divisor.get_limbs())}
247+
Self {limbs: $crate::udiv::<$N, $MOD_BITS>(self.get_limbs(), divisor.get_limbs())}
251248
}
252249

253250
fn umod(self: Self, divisor: Self) -> Self {
254-
Self {limbs: $constrained_ops::umod::<$N, $MOD_BITS>(self.get_limbs(), divisor.get_limbs())}
251+
Self {limbs: $crate::umod::<$N, $MOD_BITS>(self.get_limbs(), divisor.get_limbs())}
255252
}
256253

257254
fn is_zero(self: Self) -> bool {
258255
let params = Self::params();
259-
$constrained_ops::is_zero::<$N, $MOD_BITS>(params, self.get_limbs())
256+
$crate::is_zero::<$N, $MOD_BITS>(params, self.get_limbs())
260257
}
261258

262259
fn is_zero_integer(self: Self) -> bool {
263-
$constrained_ops::is_zero_integer(self.get_limbs())
260+
$crate::is_zero_integer(self.get_limbs())
264261
}
265262

266263
fn assert_is_not_zero(self: Self) {
267264
let params = Self::params();
268-
$constrained_ops::assert_is_not_zero::<$N, $MOD_BITS>(params, self.get_limbs());
265+
$crate::assert_is_not_zero::<$N, $MOD_BITS>(params, self.get_limbs());
269266
}
270267

271268
fn assert_is_not_zero_integer(self: Self) {
272-
$constrained_ops::assert_is_not_zero_integer(self.get_limbs());
269+
$crate::assert_is_not_zero_integer(self.get_limbs());
273270
}
274271
}
275272

@@ -282,49 +279,49 @@ pub comptime fn derive_bignum(
282279

283280
impl std::convert::From<Field> for $typ {
284281
fn from(input: Field) -> Self {
285-
$typ { limbs: $constrained_ops::from_field::<$N, $MOD_BITS>($params, input) }
282+
$typ { limbs: $crate::from_field::<$N, $MOD_BITS>($params, input) }
286283
}
287284
}
288285

289286
impl std::ops::Neg for $typ {
290287
fn neg(self) -> Self {
291-
$typ { limbs: $constrained_ops::neg::<$N, $MOD_BITS>($params, self.limbs) }
288+
$typ { limbs: $crate::neg::<$N, $MOD_BITS>($params, self.limbs) }
292289
}
293290
}
294291

295292
impl std::ops::Add for $typ {
296293
fn add(self, other: Self) -> Self {
297-
$typ { limbs: $constrained_ops::add::<$N, $MOD_BITS>($params, self.limbs, other.limbs) }
294+
$typ { limbs: $crate::add::<$N, $MOD_BITS>($params, self.limbs, other.limbs) }
298295
}
299296
}
300297

301298
impl std::ops::Sub for $typ {
302299
fn sub(self, other: Self) -> Self {
303-
$typ { limbs: $constrained_ops::sub::<$N, $MOD_BITS>($params, self.limbs, other.limbs) }
300+
$typ { limbs: $crate::sub::<$N, $MOD_BITS>($params, self.limbs, other.limbs) }
304301
}
305302
}
306303

307304
impl std::ops::Mul for $typ {
308305
fn mul(self, other: Self) -> Self {
309-
$typ { limbs: $constrained_ops::mul::<$N, $MOD_BITS>($params, self.limbs, other.limbs) }
306+
$typ { limbs: $crate::mul::<$N, $MOD_BITS>($params, self.limbs, other.limbs) }
310307
}
311308
}
312309

313310
impl std::ops::Div for $typ {
314311
fn div(self, other: Self) -> Self {
315-
$typ { limbs: $constrained_ops::div::<$N, $MOD_BITS>($params, self.limbs, other.limbs) }
312+
$typ { limbs: $crate::div::<$N, $MOD_BITS>($params, self.limbs, other.limbs) }
316313
}
317314
}
318315

319316
impl std::cmp::Eq for $typ {
320317
fn eq(self, other: Self) -> bool {
321-
$constrained_ops::eq::<$N, $MOD_BITS>($params, self.limbs, other.limbs)
318+
$crate::eq::<$N, $MOD_BITS>($params, self.limbs, other.limbs)
322319
}
323320
}
324321

325322
impl std::cmp::Ord for $typ {
326323
fn cmp(self, other: Self) -> std::cmp::Ordering {
327-
$constrained_ops::cmp::<$N, $MOD_BITS>(self.limbs, other.limbs)
324+
$crate::cmp::<$N, $MOD_BITS>(self.limbs, other.limbs)
328325
}
329326
}
330327

0 commit comments

Comments
 (0)