Skip to content

Commit

Permalink
Initializes the global constants
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed Apr 29, 2024
1 parent 4eea169 commit 77bb761
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions circuit/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub trait Aleo: Environment {
/// The maximum number of field elements in data (must not exceed u16::MAX).
const MAX_DATA_SIZE_IN_FIELDS: u32 = <Self::Network as console::Network>::MAX_DATA_SIZE_IN_FIELDS;

/// Initializes the global constants for the Aleo environment.
fn initialize_global_constants();

/// Returns the encryption domain as a constant field element.
fn encryption_domain() -> Field<Self>;

Expand Down
23 changes: 23 additions & 0 deletions circuit/network/src/testnet_v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,29 @@ thread_local! {
pub struct AleoTestnetV0;

impl Aleo for AleoTestnetV0 {
/// 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())
Expand Down
23 changes: 23 additions & 0 deletions circuit/network/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,29 @@ thread_local! {
pub struct AleoV0;

impl Aleo for AleoV0 {
/// 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())
Expand Down
2 changes: 2 additions & 0 deletions synthesizer/process/src/stack/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ impl<N: Network> StackExecute<N> for Stack<N> {
) -> Result<Response<N>> {
let timer = timer!("Stack::execute_function");

// Ensure the global constants for the Aleo environment are initialized.
A::initialize_global_constants();
// Ensure the circuit environment is clean.
A::reset();

Expand Down

0 comments on commit 77bb761

Please sign in to comment.