snarkvm_console_network_environment/
environment.rs

1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use crate::prelude::{Deserialize, DeserializeOwned, Serialize};
17use snarkvm_curves::{
18    AffineCurve,
19    MontgomeryParameters,
20    PairingEngine,
21    ProjectiveCurve,
22    TwistedEdwardsParameters,
23    bls12_377::Bls12_377,
24    edwards_bls12::{EdwardsAffine, EdwardsParameters},
25};
26use snarkvm_fields::{PrimeField, SquareRootField};
27use snarkvm_utilities::BigInteger;
28
29use core::{fmt::Debug, hash::Hash};
30use zeroize::Zeroize;
31
32pub trait Environment:
33    'static + Copy + Clone + Debug + PartialEq + Eq + Hash + Serialize + DeserializeOwned + Send + Sync
34{
35    type Affine: AffineCurve<
36            Projective = Self::Projective,
37            BaseField = Self::Field,
38            ScalarField = Self::Scalar,
39            Coordinates = (Self::Field, Self::Field),
40        >;
41    type BigInteger: BigInteger;
42    type Field: PrimeField<BigInteger = Self::BigInteger> + SquareRootField + Copy + Zeroize;
43    type PairingCurve: PairingEngine<Fr = Self::Field>;
44    type Projective: ProjectiveCurve<Affine = Self::Affine, BaseField = Self::Field, ScalarField = Self::Scalar>;
45    type Scalar: PrimeField<BigInteger = Self::BigInteger> + Copy + Zeroize;
46
47    /// The coefficient `A` of the twisted Edwards curve.
48    const EDWARDS_A: Self::Field;
49    /// The coefficient `D` of the twisted Edwards curve.
50    const EDWARDS_D: Self::Field;
51
52    /// The coefficient `A` of the Montgomery curve.
53    const MONTGOMERY_A: Self::Field;
54    /// The coefficient `B` of the Montgomery curve.
55    const MONTGOMERY_B: Self::Field;
56
57    /// The maximum number of bytes allowed in a string.
58    const MAX_STRING_BYTES: u32 = u8::MAX as u32;
59
60    /// Halts the program from further synthesis, evaluation, and execution in the current environment.
61    fn halt<S: Into<String>, T>(message: S) -> T {
62        panic!("{}", message.into())
63    }
64}
65
66#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
67pub struct Console;
68
69impl Environment for Console {
70    type Affine = EdwardsAffine;
71    type BigInteger = <Self::Field as PrimeField>::BigInteger;
72    type Field = <Self::Affine as AffineCurve>::BaseField;
73    type PairingCurve = Bls12_377;
74    type Projective = <Self::Affine as AffineCurve>::Projective;
75    type Scalar = <Self::Affine as AffineCurve>::ScalarField;
76
77    /// The coefficient `A` of the twisted Edwards curve.
78    const EDWARDS_A: Self::Field = <EdwardsParameters as TwistedEdwardsParameters>::EDWARDS_A;
79    /// The coefficient `D` of the twisted Edwards curve.
80    const EDWARDS_D: Self::Field = <EdwardsParameters as TwistedEdwardsParameters>::EDWARDS_D;
81    /// The coefficient `A` of the Montgomery curve.
82    const MONTGOMERY_A: Self::Field = <EdwardsParameters as MontgomeryParameters>::MONTGOMERY_A;
83    /// The coefficient `B` of the Montgomery curve.
84    const MONTGOMERY_B: Self::Field = <EdwardsParameters as MontgomeryParameters>::MONTGOMERY_B;
85}