Skip to main content

Global Variables

For developers coming from solidity, this concept will be similar to how the global block variable exposes a series of block values. The idea is the same in Aztec. Developers can access a namespace of values made available in each function.

Aztec has two execution environments, Private and Public. Each execution environment contains a different global variables object.

Private Global Variables

tx-context
pub struct TxContext {
pub chain_id: Field,
pub version: Field,
pub gas_settings: GasSettings,
}
Source code: noir-projects/noir-protocol-circuits/crates/types/src/transaction/tx_context.nr#L8-L14

The private global variables are equal to the transaction context and contain:

Chain Id

The chain id differs depending on which Aztec instance you are on ( NOT the Ethereum hardfork that the rollup is settling to ). On original deployment of the network, this value will be 1.

context.chain_id();

Version

The version number indicates which Aztec hardfork you are on. The Genesis block of the network will have the version number 1.

context.version();

Gas Settings

The gas limits set by the user for the transaction, the max fee per gas, and the inclusion fee.

Public Global Variables

global-variables
pub struct GlobalVariables {
pub chain_id: Field,
pub version: Field,
pub block_number: Field,
pub slot_number: Field,
pub timestamp: u64,
pub coinbase: EthAddress,
pub fee_recipient: AztecAddress,
pub gas_fees: GasFees,
}
Source code: noir-projects/noir-protocol-circuits/crates/types/src/abis/global_variables.nr#L9-L20

The public global variables contain the values present in the private global variables described above, with the addition of:

Timestamp

The timestamp is the unix timestamp in which the block has been executed. The value is provided by the block's proposer (therefore can have variance). This value will always increase.

context.timestamp();

Block Number

The block number is a sequential identifier that labels each individual block of the network. This value will be the block number of the block the accessing transaction is included in. The block number of the genesis block will be 1, with the number increasing by 1 for every block after.

context.block_number();
Why do the available global variables differ per execution environment?

The global variables are constrained by the proving environment. In the case of public functions, they are executed on a sequencer that will know the timestamp and number of the next block ( as they are the block producer ). In the case of private functions, we cannot be sure which block our transaction will be included in, hence we can not guarantee values for the timestamp or block number.