snarkvm_circuit_network/
canary_v0.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
// Copyright 2024 Aleo Network Foundation
// This file is part of the snarkVM library.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::Aleo;
use snarkvm_circuit_algorithms::{
    BHP256,
    BHP512,
    BHP768,
    BHP1024,
    Commit,
    CommitUncompressed,
    Hash,
    HashMany,
    HashToGroup,
    HashToScalar,
    HashUncompressed,
    Keccak256,
    Keccak384,
    Keccak512,
    Pedersen64,
    Pedersen128,
    Poseidon2,
    Poseidon4,
    Poseidon8,
    Sha3_256,
    Sha3_384,
    Sha3_512,
};
use snarkvm_circuit_collections::merkle_tree::MerklePath;
use snarkvm_circuit_types::{
    Boolean,
    Field,
    Group,
    Scalar,
    environment::{Assignment, CanaryCircuit, R1CS, prelude::*},
};

use core::fmt;

type E = CanaryCircuit;

thread_local! {
    /// The group bases for the Aleo signature and encryption schemes.
    static GENERATOR_G: Vec<Group<AleoCanaryV0>> = Vec::constant(<console::CanaryV0 as console::Network>::g_powers().to_vec());

    /// The encryption domain as a constant field element.
    static ENCRYPTION_DOMAIN: Field<AleoCanaryV0> = Field::constant(<console::CanaryV0 as console::Network>::encryption_domain());
    /// The graph key domain as a constant field element.
    static GRAPH_KEY_DOMAIN: Field<AleoCanaryV0> = Field::constant(<console::CanaryV0 as console::Network>::graph_key_domain());
    /// The serial number domain as a constant field element.
    static SERIAL_NUMBER_DOMAIN: Field<AleoCanaryV0> = Field::constant(<console::CanaryV0 as console::Network>::serial_number_domain());

    /// The BHP hash function, which can take an input of up to 256 bits.
    static BHP_256: BHP256<AleoCanaryV0> = BHP256::<AleoCanaryV0>::constant(console::CANARY_BHP_256.clone());
    /// The BHP hash function, which can take an input of up to 512 bits.
    static BHP_512: BHP512<AleoCanaryV0> = BHP512::<AleoCanaryV0>::constant(console::CANARY_BHP_512.clone());
    /// The BHP hash function, which can take an input of up to 768 bits.
    static BHP_768: BHP768<AleoCanaryV0> = BHP768::<AleoCanaryV0>::constant(console::CANARY_BHP_768.clone());
    /// The BHP hash function, which can take an input of up to 1024 bits.
    static BHP_1024: BHP1024<AleoCanaryV0> = BHP1024::<AleoCanaryV0>::constant(console::CANARY_BHP_1024.clone());

    /// The Keccak hash function, which outputs 256 bits.
    static KECCAK_256: Keccak256<AleoCanaryV0> = Keccak256::<AleoCanaryV0>::new();
    /// The Keccak hash function, which outputs 384 bits.
    static KECCAK_384: Keccak384<AleoCanaryV0> = Keccak384::<AleoCanaryV0>::new();
    /// The Keccak hash function, which outputs 512 bits.
    static KECCAK_512: Keccak512<AleoCanaryV0> = Keccak512::<AleoCanaryV0>::new();

    /// The Pedersen hash function, which can take an input of up to 64 bits.
    static PEDERSEN_64: Pedersen64<AleoCanaryV0> = Pedersen64::<AleoCanaryV0>::constant(console::CANARY_PEDERSEN_64.clone());
    /// The Pedersen hash function, which can take an input of up to 128 bits.
    static PEDERSEN_128: Pedersen128<AleoCanaryV0> = Pedersen128::<AleoCanaryV0>::constant(console::CANARY_PEDERSEN_128.clone());

    /// The Poseidon hash function, using a rate of 2.
    static POSEIDON_2: Poseidon2<AleoCanaryV0> = Poseidon2::<AleoCanaryV0>::constant(console::CANARY_POSEIDON_2.clone());
    /// The Poseidon hash function, using a rate of 4.
    static POSEIDON_4: Poseidon4<AleoCanaryV0> = Poseidon4::<AleoCanaryV0>::constant(console::CANARY_POSEIDON_4.clone());
    /// The Poseidon hash function, using a rate of 8.
    static POSEIDON_8: Poseidon8<AleoCanaryV0> = Poseidon8::<AleoCanaryV0>::constant(console::CANARY_POSEIDON_8.clone());

    /// The SHA-3 hash function, which outputs 256 bits.
    static SHA3_256: Sha3_256<AleoCanaryV0> = Sha3_256::<AleoCanaryV0>::new();
    /// The SHA-3 hash function, which outputs 384 bits.
    static SHA3_384: Sha3_384<AleoCanaryV0> = Sha3_384::<AleoCanaryV0>::new();
    /// The SHA-3 hash function, which outputs 512 bits.
    static SHA3_512: Sha3_512<AleoCanaryV0> = Sha3_512::<AleoCanaryV0>::new();
}

#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub struct AleoCanaryV0;

impl Aleo for AleoCanaryV0 {
    /// Initializes the global constants for the Aleo environment.
    fn initialize_global_constants() {
        GENERATOR_G.with(|_| ());
        ENCRYPTION_DOMAIN.with(|_| ());
        GRAPH_KEY_DOMAIN.with(|_| ());
        SERIAL_NUMBER_DOMAIN.with(|_| ());
        BHP_256.with(|_| ());
        BHP_512.with(|_| ());
        BHP_768.with(|_| ());
        BHP_1024.with(|_| ());
        KECCAK_256.with(|_| ());
        KECCAK_384.with(|_| ());
        KECCAK_512.with(|_| ());
        PEDERSEN_64.with(|_| ());
        PEDERSEN_128.with(|_| ());
        POSEIDON_2.with(|_| ());
        POSEIDON_4.with(|_| ());
        POSEIDON_8.with(|_| ());
        SHA3_256.with(|_| ());
        SHA3_384.with(|_| ());
        SHA3_512.with(|_| ());
    }

    /// Returns the encryption domain as a constant field element.
    fn encryption_domain() -> Field<Self> {
        ENCRYPTION_DOMAIN.with(|domain| domain.clone())
    }

    /// Returns the graph key domain as a constant field element.
    fn graph_key_domain() -> Field<Self> {
        GRAPH_KEY_DOMAIN.with(|domain| domain.clone())
    }

    /// Returns the serial number domain as a constant field element.
    fn serial_number_domain() -> Field<Self> {
        SERIAL_NUMBER_DOMAIN.with(|domain| domain.clone())
    }

    /// Returns the scalar multiplication on the generator `G`.
    #[inline]
    fn g_scalar_multiply(scalar: &Scalar<Self>) -> Group<Self> {
        GENERATOR_G.with(|bases| {
            bases
                .iter()
                .zip_eq(&scalar.to_bits_le())
                .fold(Group::zero(), |output, (base, bit)| Group::ternary(bit, &(&output + base), &output))
        })
    }

    /// Returns a BHP commitment with an input hasher of 256-bits.
    fn commit_bhp256(input: &[Boolean<Self>], randomizer: &Scalar<Self>) -> Field<Self> {
        BHP_256.with(|bhp| bhp.commit(input, randomizer))
    }

    /// Returns a BHP commitment with an input hasher of 512-bits.
    fn commit_bhp512(input: &[Boolean<Self>], randomizer: &Scalar<Self>) -> Field<Self> {
        BHP_512.with(|bhp| bhp.commit(input, randomizer))
    }

    /// Returns a BHP commitment with an input hasher of 768-bits.
    fn commit_bhp768(input: &[Boolean<Self>], randomizer: &Scalar<Self>) -> Field<Self> {
        BHP_768.with(|bhp| bhp.commit(input, randomizer))
    }

    /// Returns a BHP commitment with an input hasher of 1024-bits.
    fn commit_bhp1024(input: &[Boolean<Self>], randomizer: &Scalar<Self>) -> Field<Self> {
        BHP_1024.with(|bhp| bhp.commit(input, randomizer))
    }

    /// Returns a Pedersen commitment for the given (up to) 64-bit input and randomizer.
    fn commit_ped64(input: &[Boolean<Self>], randomizer: &Scalar<Self>) -> Field<Self> {
        PEDERSEN_64.with(|pedersen| pedersen.commit(input, randomizer))
    }

    /// Returns a Pedersen commitment for the given (up to) 128-bit input and randomizer.
    fn commit_ped128(input: &[Boolean<Self>], randomizer: &Scalar<Self>) -> Field<Self> {
        PEDERSEN_128.with(|pedersen| pedersen.commit(input, randomizer))
    }

    /// Returns a BHP commitment with an input hasher of 256-bits.
    fn commit_to_group_bhp256(input: &[Boolean<Self>], randomizer: &Scalar<Self>) -> Group<Self> {
        BHP_256.with(|bhp| bhp.commit_uncompressed(input, randomizer))
    }

    /// Returns a BHP commitment with an input hasher of 512-bits.
    fn commit_to_group_bhp512(input: &[Boolean<Self>], randomizer: &Scalar<Self>) -> Group<Self> {
        BHP_512.with(|bhp| bhp.commit_uncompressed(input, randomizer))
    }

    /// Returns a BHP commitment with an input hasher of 768-bits.
    fn commit_to_group_bhp768(input: &[Boolean<Self>], randomizer: &Scalar<Self>) -> Group<Self> {
        BHP_768.with(|bhp| bhp.commit_uncompressed(input, randomizer))
    }

    /// Returns a BHP commitment with an input hasher of 1024-bits.
    fn commit_to_group_bhp1024(input: &[Boolean<Self>], randomizer: &Scalar<Self>) -> Group<Self> {
        BHP_1024.with(|bhp| bhp.commit_uncompressed(input, randomizer))
    }

    /// Returns a Pedersen commitment for the given (up to) 64-bit input and randomizer.
    fn commit_to_group_ped64(input: &[Boolean<Self>], randomizer: &Scalar<Self>) -> Group<Self> {
        PEDERSEN_64.with(|pedersen| pedersen.commit_uncompressed(input, randomizer))
    }

    /// Returns a Pedersen commitment for the given (up to) 128-bit input and randomizer.
    fn commit_to_group_ped128(input: &[Boolean<Self>], randomizer: &Scalar<Self>) -> Group<Self> {
        PEDERSEN_128.with(|pedersen| pedersen.commit_uncompressed(input, randomizer))
    }

    /// Returns the BHP hash with an input hasher of 256-bits.
    fn hash_bhp256(input: &[Boolean<Self>]) -> Field<Self> {
        BHP_256.with(|bhp| bhp.hash(input))
    }

    /// Returns the BHP hash with an input hasher of 512-bits.
    fn hash_bhp512(input: &[Boolean<Self>]) -> Field<Self> {
        BHP_512.with(|bhp| bhp.hash(input))
    }

    /// Returns the BHP hash with an input hasher of 768-bits.
    fn hash_bhp768(input: &[Boolean<Self>]) -> Field<Self> {
        BHP_768.with(|bhp| bhp.hash(input))
    }

    /// Returns the BHP hash with an input hasher of 1024-bits.
    fn hash_bhp1024(input: &[Boolean<Self>]) -> Field<Self> {
        BHP_1024.with(|bhp| bhp.hash(input))
    }

    /// Returns the Keccak hash with a 256-bit output.
    fn hash_keccak256(input: &[Boolean<Self>]) -> Vec<Boolean<Self>> {
        KECCAK_256.with(|keccak| keccak.hash(input))
    }

    /// Returns the Keccak hash with a 384-bit output.
    fn hash_keccak384(input: &[Boolean<Self>]) -> Vec<Boolean<Self>> {
        KECCAK_384.with(|keccak| keccak.hash(input))
    }

    /// Returns the Keccak hash with a 512-bit output.
    fn hash_keccak512(input: &[Boolean<Self>]) -> Vec<Boolean<Self>> {
        KECCAK_512.with(|keccak| keccak.hash(input))
    }

    /// Returns the Pedersen hash for a given (up to) 64-bit input.
    fn hash_ped64(input: &[Boolean<Self>]) -> Field<Self> {
        PEDERSEN_64.with(|pedersen| pedersen.hash(input))
    }

    /// Returns the Pedersen hash for a given (up to) 128-bit input.
    fn hash_ped128(input: &[Boolean<Self>]) -> Field<Self> {
        PEDERSEN_128.with(|pedersen| pedersen.hash(input))
    }

    /// Returns the Poseidon hash with an input rate of 2.
    fn hash_psd2(input: &[Field<Self>]) -> Field<Self> {
        POSEIDON_2.with(|poseidon| poseidon.hash(input))
    }

    /// Returns the Poseidon hash with an input rate of 4.
    fn hash_psd4(input: &[Field<Self>]) -> Field<Self> {
        POSEIDON_4.with(|poseidon| poseidon.hash(input))
    }

    /// Returns the Poseidon hash with an input rate of 8.
    fn hash_psd8(input: &[Field<Self>]) -> Field<Self> {
        POSEIDON_8.with(|poseidon| poseidon.hash(input))
    }

    /// Returns the SHA-3 hash with a 256-bit output.
    fn hash_sha3_256(input: &[Boolean<Self>]) -> Vec<Boolean<Self>> {
        SHA3_256.with(|sha3| sha3.hash(input))
    }

    /// Returns the SHA-3 hash with a 384-bit output.
    fn hash_sha3_384(input: &[Boolean<Self>]) -> Vec<Boolean<Self>> {
        SHA3_384.with(|sha3| sha3.hash(input))
    }

    /// Returns the SHA-3 hash with a 512-bit output.
    fn hash_sha3_512(input: &[Boolean<Self>]) -> Vec<Boolean<Self>> {
        SHA3_512.with(|sha3| sha3.hash(input))
    }

    /// Returns the extended Poseidon hash with an input rate of 2.
    fn hash_many_psd2(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>> {
        POSEIDON_2.with(|poseidon| poseidon.hash_many(input, num_outputs))
    }

    /// Returns the extended Poseidon hash with an input rate of 4.
    fn hash_many_psd4(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>> {
        POSEIDON_4.with(|poseidon| poseidon.hash_many(input, num_outputs))
    }

    /// Returns the extended Poseidon hash with an input rate of 8.
    fn hash_many_psd8(input: &[Field<Self>], num_outputs: u16) -> Vec<Field<Self>> {
        POSEIDON_8.with(|poseidon| poseidon.hash_many(input, num_outputs))
    }

    /// Returns the BHP hash with an input hasher of 256-bits.
    fn hash_to_group_bhp256(input: &[Boolean<Self>]) -> Group<Self> {
        BHP_256.with(|bhp| bhp.hash_uncompressed(input))
    }

    /// Returns the BHP hash with an input hasher of 512-bits.
    fn hash_to_group_bhp512(input: &[Boolean<Self>]) -> Group<Self> {
        BHP_512.with(|bhp| bhp.hash_uncompressed(input))
    }

    /// Returns the BHP hash with an input hasher of 768-bits.
    fn hash_to_group_bhp768(input: &[Boolean<Self>]) -> Group<Self> {
        BHP_768.with(|bhp| bhp.hash_uncompressed(input))
    }

    /// Returns the BHP hash with an input hasher of 1024-bits.
    fn hash_to_group_bhp1024(input: &[Boolean<Self>]) -> Group<Self> {
        BHP_1024.with(|bhp| bhp.hash_uncompressed(input))
    }

    /// Returns the Pedersen hash for a given (up to) 64-bit input.
    fn hash_to_group_ped64(input: &[Boolean<Self>]) -> Group<Self> {
        PEDERSEN_64.with(|pedersen| pedersen.hash_uncompressed(input))
    }

    /// Returns the Pedersen hash for a given (up to) 128-bit input.
    fn hash_to_group_ped128(input: &[Boolean<Self>]) -> Group<Self> {
        PEDERSEN_128.with(|pedersen| pedersen.hash_uncompressed(input))
    }

    /// Returns the Poseidon hash with an input rate of 2 on the affine curve.
    fn hash_to_group_psd2(input: &[Field<Self>]) -> Group<Self> {
        POSEIDON_2.with(|poseidon| poseidon.hash_to_group(input))
    }

    /// Returns the Poseidon hash with an input rate of 4 on the affine curve.
    fn hash_to_group_psd4(input: &[Field<Self>]) -> Group<Self> {
        POSEIDON_4.with(|poseidon| poseidon.hash_to_group(input))
    }

    /// Returns the Poseidon hash with an input rate of 8 on the affine curve.
    fn hash_to_group_psd8(input: &[Field<Self>]) -> Group<Self> {
        POSEIDON_8.with(|poseidon| poseidon.hash_to_group(input))
    }

    /// Returns the Poseidon hash with an input rate of 2 on the scalar field.
    fn hash_to_scalar_psd2(input: &[Field<Self>]) -> Scalar<Self> {
        POSEIDON_2.with(|poseidon| poseidon.hash_to_scalar(input))
    }

    /// Returns the Poseidon hash with an input rate of 4 on the scalar field.
    fn hash_to_scalar_psd4(input: &[Field<Self>]) -> Scalar<Self> {
        POSEIDON_4.with(|poseidon| poseidon.hash_to_scalar(input))
    }

    /// Returns the Poseidon hash with an input rate of 8 on the scalar field.
    fn hash_to_scalar_psd8(input: &[Field<Self>]) -> Scalar<Self> {
        POSEIDON_8.with(|poseidon| poseidon.hash_to_scalar(input))
    }

    /// Returns `true` if the given Merkle path is valid for the given root and leaf.
    fn verify_merkle_path_bhp<const DEPTH: u8>(
        path: &MerklePath<Self, DEPTH>,
        root: &Field<Self>,
        leaf: &Vec<Boolean<Self>>,
    ) -> Boolean<Self> {
        BHP_1024.with(|bhp1024| BHP_512.with(|bhp512| path.verify(bhp1024, bhp512, root, leaf)))
    }

    /// Returns `true` if the given Merkle path is valid for the given root and leaf.
    fn verify_merkle_path_psd<const DEPTH: u8>(
        path: &MerklePath<Self, DEPTH>,
        root: &Field<Self>,
        leaf: &Vec<Field<Self>>,
    ) -> Boolean<Self> {
        POSEIDON_4.with(|psd4| POSEIDON_2.with(|psd2| path.verify(psd4, psd2, root, leaf)))
    }
}

impl Environment for AleoCanaryV0 {
    type Affine = <E as Environment>::Affine;
    type BaseField = <E as Environment>::BaseField;
    type Network = <E as Environment>::Network;
    type ScalarField = <E as Environment>::ScalarField;

    /// Returns the `zero` constant.
    fn zero() -> LinearCombination<Self::BaseField> {
        E::zero()
    }

    /// Returns the `one` constant.
    fn one() -> LinearCombination<Self::BaseField> {
        E::one()
    }

    /// Returns a new variable of the given mode and value.
    fn new_variable(mode: Mode, value: Self::BaseField) -> Variable<Self::BaseField> {
        E::new_variable(mode, value)
    }

    /// Returns a new witness of the given mode and value.
    fn new_witness<Fn: FnOnce() -> Output::Primitive, Output: Inject>(mode: Mode, logic: Fn) -> Output {
        E::new_witness(mode, logic)
    }

    /// Enters a new scope for the environment.
    fn scope<S: Into<String>, Fn, Output>(name: S, logic: Fn) -> Output
    where
        Fn: FnOnce() -> Output,
    {
        E::scope(name, logic)
    }

    /// Adds one constraint enforcing that `(A * B) == C`.
    fn enforce<Fn, A, B, C>(constraint: Fn)
    where
        Fn: FnOnce() -> (A, B, C),
        A: Into<LinearCombination<Self::BaseField>>,
        B: Into<LinearCombination<Self::BaseField>>,
        C: Into<LinearCombination<Self::BaseField>>,
    {
        E::enforce(constraint)
    }

    /// Returns `true` if all constraints in the environment are satisfied.
    fn is_satisfied() -> bool {
        E::is_satisfied()
    }

    /// Returns `true` if all constraints in the current scope are satisfied.
    fn is_satisfied_in_scope() -> bool {
        E::is_satisfied_in_scope()
    }

    /// Returns the number of constants in the entire circuit.
    fn num_constants() -> u64 {
        E::num_constants()
    }

    /// Returns the number of public variables in the entire circuit.
    fn num_public() -> u64 {
        E::num_public()
    }

    /// Returns the number of private variables in the entire circuit.
    fn num_private() -> u64 {
        E::num_private()
    }

    /// Returns the number of constant, public, and private variables in the entire circuit.
    fn num_variables() -> u64 {
        E::num_variables()
    }

    /// Returns the number of constraints in the entire circuit.
    fn num_constraints() -> u64 {
        E::num_constraints()
    }

    /// Returns the number of nonzeros in the entire circuit.
    fn num_nonzeros() -> (u64, u64, u64) {
        E::num_nonzeros()
    }

    /// Returns the number of constants for the current scope.
    fn num_constants_in_scope() -> u64 {
        E::num_constants_in_scope()
    }

    /// Returns the number of public variables for the current scope.
    fn num_public_in_scope() -> u64 {
        E::num_public_in_scope()
    }

    /// Returns the number of private variables for the current scope.
    fn num_private_in_scope() -> u64 {
        E::num_private_in_scope()
    }

    /// Returns the number of constraints for the current scope.
    fn num_constraints_in_scope() -> u64 {
        E::num_constraints_in_scope()
    }

    /// Returns the number of nonzeros for the current scope.
    fn num_nonzeros_in_scope() -> (u64, u64, u64) {
        E::num_nonzeros_in_scope()
    }

    /// Returns the variable limit for the circuit, if one exists.
    fn get_variable_limit() -> Option<u64> {
        E::get_variable_limit()
    }

    /// Sets the variable limit for the circuit.
    fn set_variable_limit(limit: Option<u64>) {
        E::set_variable_limit(limit)
    }

    /// Returns the constraint limit for the circuit, if one exists.
    fn get_constraint_limit() -> Option<u64> {
        E::get_constraint_limit()
    }

    /// Sets the constraint limit for the circuit.
    fn set_constraint_limit(limit: Option<u64>) {
        E::set_constraint_limit(limit)
    }

    /// Halts the program from further synthesis, evaluation, and execution in the current environment.
    fn halt<S: Into<String>, T>(message: S) -> T {
        E::halt(message)
    }

    /// Returns the R1CS circuit, resetting the circuit.
    fn inject_r1cs(r1cs: R1CS<Self::BaseField>) {
        E::inject_r1cs(r1cs)
    }

    /// Returns the R1CS circuit, resetting the circuit.
    fn eject_r1cs_and_reset() -> R1CS<Self::BaseField> {
        E::eject_r1cs_and_reset()
    }

    /// Returns the R1CS assignment of the circuit, resetting the circuit.
    fn eject_assignment_and_reset() -> Assignment<<Self::Network as console::Environment>::Field> {
        E::eject_assignment_and_reset()
    }

    /// Clears the circuit and initializes an empty environment.
    fn reset() {
        E::reset()
    }
}

impl Display for AleoCanaryV0 {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        // TODO (howardwu): Find a better way to print the circuit.
        fmt::Display::fmt(&CanaryCircuit, f)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use snarkvm_circuit_types::Field;

    type CurrentAleo = AleoCanaryV0;

    /// Compute 2^EXPONENT - 1, in a purposefully constraint-inefficient manner for testing.
    fn create_example_circuit<E: Environment>() -> Field<E> {
        let one = snarkvm_console_types::Field::<<E as Environment>::Network>::one();
        let two = one + one;

        const EXPONENT: u64 = 64;

        // Compute 2^EXPONENT - 1, in a purposefully constraint-inefficient manner for testing.
        let mut candidate = Field::<E>::new(Mode::Public, one);
        let mut accumulator = Field::new(Mode::Private, two);
        for _ in 0..EXPONENT {
            candidate += &accumulator;
            accumulator *= Field::new(Mode::Private, two);
        }

        assert_eq!((accumulator - Field::one()).eject_value(), candidate.eject_value());
        assert_eq!(2, E::num_public());
        assert_eq!(2 * EXPONENT + 1, E::num_private());
        assert_eq!(EXPONENT, E::num_constraints());
        assert!(E::is_satisfied());

        candidate
    }

    #[test]
    fn test_print_circuit() {
        let circuit = CurrentAleo {};
        let _candidate = create_example_circuit::<CurrentAleo>();
        let output = format!("{circuit}");
        println!("{output}");
    }

    #[test]
    fn test_circuit_scope() {
        CurrentAleo::scope("test_circuit_scope", || {
            assert_eq!(0, CurrentAleo::num_constants());
            assert_eq!(1, CurrentAleo::num_public());
            assert_eq!(0, CurrentAleo::num_private());
            assert_eq!(0, CurrentAleo::num_constraints());

            assert_eq!(0, CurrentAleo::num_constants_in_scope());
            assert_eq!(0, CurrentAleo::num_public_in_scope());
            assert_eq!(0, CurrentAleo::num_private_in_scope());
            assert_eq!(0, CurrentAleo::num_constraints_in_scope());
        })
    }
}