Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: testing all values in PublicGlobalVariables and PrivateGlobalVariables #4481

Merged
16 changes: 16 additions & 0 deletions avm-transpiler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions boxes/blank-react/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
contract Blank {
use dep::aztec::{
abi,
oracle::{
get_public_key::get_public_key,
},
protocol_types::address::AztecAddress
};

#[aztec(private)]
fn constructor() {}

Expand Down
3 changes: 1 addition & 2 deletions boxes/blank/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
contract Blank {
use dep::aztec::{
abi,
oracle::{
get_public_key::get_public_key,
},
protocol_types::address::AztecAddress
};

#[aztec(private)]
fn constructor() {}

Expand Down
7 changes: 5 additions & 2 deletions boxes/token/src/contracts/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ contract Token {
note_header::NoteHeader,
utils as note_utils,
},
context::{PrivateContext, PublicContext, Context},
hash::{compute_secret_hash},
state_vars::{map::Map, public_state::PublicState, set::Set},
protocol_types::{
Expand Down Expand Up @@ -328,7 +327,11 @@ contract Token {
) -> pub [Field; 4] {
let note_header = NoteHeader::new(contract_address, nonce, storage_slot);
if (storage_slot == storage.pending_shields.get_storage_slot()) {
note_utils::compute_note_hash_and_nullifier(TransparentNote::deserialize_content, note_header, serialized_note)
note_utils::compute_note_hash_and_nullifier(
TransparentNote::deserialize_content,
note_header,
serialized_note
)
} else {
note_utils::compute_note_hash_and_nullifier(TokenNote::deserialize_content, note_header, serialized_note)
}
Expand Down
2 changes: 1 addition & 1 deletion boxes/token/src/contracts/src/types/balances_map.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use dep::std::option::Option;
use dep::safe_math::SafeU120;
use dep::aztec::{
context::{PrivateContext, PublicContext, Context},
context::Context,
hash::pedersen_hash,
protocol_types::{
address::AztecAddress,
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/developers/contracts/portals/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ To consume the message, we can use the `consume_l1_to_l2_message` function withi
Note that while the `secret` and the `content` are both hashed, they are actually hashed with different hash functions!
:::

#include_code context_consume_l1_to_l2_message /yarn-project/aztec-nr/aztec/src/context/private.nr rust
#include_code context_consume_l1_to_l2_message /yarn-project/aztec-nr/aztec/src/context/private_context.nr rust

Computing the `content` must be done manually in its current form, as we are still adding a number of bytes utilities. A good example exists within the [Token bridge example](https://github.com/AztecProtocol/aztec-packages/blob/master/yarn-project/noir-contracts/contracts/token_bridge_contract/src/util.nr).

Expand Down Expand Up @@ -78,7 +78,7 @@ The portal must ensure that the sender is as expected. One way to do this is to

To send a message to L1 from your Aztec contract, you must use the `message_portal` function on the `context`. When messaging to L1, only the `content` is required (as a `Field`).

#include_code context_message_portal /yarn-project/aztec-nr/aztec/src/context/private.nr rust
#include_code context_message_portal /yarn-project/aztec-nr/aztec/src/context/private_context.nr rust

When sending a message from L2 to L1 we don't need to pass recipient, deadline, secret nor fees. Recipient is populated with the attached portal and the remaining values are not needed as the message is inserted into the outbox at the same time as it was included in a block (for the inbox it could be inserted and then only included in rollup block later).

Expand Down
10 changes: 5 additions & 5 deletions docs/docs/developers/contracts/syntax/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ The following section will cover both contexts.
## The Private Context

The code snippet below shows what is contained within the private context.
#include_code private-context /yarn-project/aztec-nr/aztec/src/context/private.nr rust
#include_code private-context /yarn-project/aztec-nr/aztec/src/context/private_context.nr rust

### Private Context Broken Down

#### Inputs

The context inputs includes all of the information that is passed from the kernel circuit into the application circuit. It contains the following values.

#include_code private-context-inputs /yarn-project/aztec-nr/aztec/src/abi.nr rust
#include_code private-context-inputs /yarn-project/aztec-nr/aztec/src/context/inputs/private_context_inputs.nr rust

As shown in the snippet, the application context is made up of 4 main structures. The call context, the block header, the contract deployment data and the private global variables.

Expand Down Expand Up @@ -89,7 +89,7 @@ Just like with the `is_contract_deployment` flag mentioned earlier. This data wi

In the private execution context, we only have access to a subset of the total global variables, we are restricted to those which can be reliably proven by the kernel circuits.

#include_code private-global-variables /yarn-project/aztec-nr/aztec/src/abi.nr rust
#include_code private-global-variables /yarn-project/aztec-nr/aztec/src/context/globals/private_global_variables.nr rust

### Args Hash

Expand Down Expand Up @@ -141,10 +141,10 @@ The Public Context includes all of the information passed from the `Public VM` i

In the current version of the system, the public context is almost a clone of the private execution context. It contains the same call context data, access to the same historical tree roots, however it does NOT have access to contract deployment data, this is due to traditional contract deployments only currently being possible from private transactions.

#include_code public-context-inputs /yarn-project/aztec-nr/aztec/src/abi.nr rust
#include_code public-context-inputs /yarn-project/aztec-nr/aztec/src/context/inputs/public_context_inputs.nr rust

### Public Global Variables

The public global variables are provided by the rollup sequencer and consequently contain some more values than the private global variables.

#include_code public-global-variables /yarn-project/aztec-nr/aztec/src/abi.nr rust
#include_code global-variables /yarn-project/noir-protocol-circuits/src/crates/types/src/abis/global_variables.nr rust
4 changes: 2 additions & 2 deletions docs/docs/developers/contracts/syntax/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ For developers coming from solidity, this concept will be similar to how the glo
`Aztec` has two execution environments, Private and Public. Each execution environment contains a different global variables object.

## Private Global Variables
#include_code private-global-variables /yarn-project/aztec-nr/aztec/src/abi.nr rust
#include_code private-global-variables /yarn-project/aztec-nr/aztec/src/context/globals/private_global_variables.nr rust

The private global variables contain:
### Chain Id
Expand All @@ -27,7 +27,7 @@ context.version();


## Public Global Variables
#include_code public-global-variables /yarn-project/aztec-nr/aztec/src/abi.nr rust
#include_code global-variables /yarn-project/noir-protocol-circuits/src/crates/types/src/abis/global_variables.nr rust

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

Expand Down
12 changes: 11 additions & 1 deletion noir/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions noir/aztec_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ repository.workspace = true
[dependencies]
noirc_frontend.workspace = true
iter-extended.workspace = true
convert_case = "0.6.0"
29 changes: 18 additions & 11 deletions noir/aztec_macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::borrow::{Borrow, BorrowMut};
use std::vec;

use convert_case::{Case, Casing};
use iter_extended::vecmap;
use noirc_frontend::macros_api::FieldElement;
use noirc_frontend::macros_api::{
Expand Down Expand Up @@ -1049,7 +1050,10 @@ fn generate_selector_impl(structure: &NoirStruct) -> TypeImpl {
fn create_inputs(ty: &str) -> Param {
let context_ident = ident("inputs");
let context_pattern = Pattern::Identifier(context_ident);
let type_path = chained_path!("aztec", "abi", ty);

let path_snippet = ty.to_case(Case::Snake); // e.g. private_context_inputs
let type_path = chained_path!("aztec", "context", "inputs", &path_snippet, ty);

let context_type = make_type(UnresolvedTypeData::Named(type_path, vec![]));
let visibility = Visibility::Private;

Expand Down Expand Up @@ -1088,8 +1092,8 @@ fn create_context(ty: &str, params: &[Param]) -> Result<Vec<Statement>, AztecMac
let let_hasher = mutable_assignment(
"hasher", // Assigned to
call(
variable_path(chained_path!("aztec", "abi", "Hasher", "new")), // Path
vec![], // args
variable_path(chained_path!("aztec", "hasher", "Hasher", "new")), // Path
vec![], // args
),
);

Expand Down Expand Up @@ -1148,12 +1152,14 @@ fn create_context(ty: &str, params: &[Param]) -> Result<Vec<Statement>, AztecMac
vec![], // args
);

let path_snippet = ty.to_case(Case::Snake); // e.g. private_context

// let mut context = {ty}::new(inputs, hash);
let let_context = mutable_assignment(
"context", // Assigned to
call(
variable_path(chained_path!("aztec", "context", ty, "new")), // Path
vec![inputs_expression, hash_call], // args
variable_path(chained_path!("aztec", "context", &path_snippet, ty, "new")), // Path
vec![inputs_expression, hash_call], // args
),
);
injected_expressions.push(let_context);
Expand Down Expand Up @@ -1200,7 +1206,7 @@ fn create_avm_context() -> Result<Statement, AztecMacroError> {
/// ```noir
/// /// Before
/// #[aztec(private)]
/// fn foo() -> abi::PrivateCircuitPublicInputs {
/// fn foo() -> protocol_types::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs {
/// // ...
/// let my_return_value: Field = 10;
/// context.return_values.push(my_return_value);
Expand Down Expand Up @@ -1376,8 +1382,8 @@ fn make_castable_return_type(expression: Expression) -> Statement {

/// Create Return Type
///
/// Public functions return abi::PublicCircuitPublicInputs while
/// private functions return abi::PrivateCircuitPublicInputs
/// Public functions return protocol_types::abis::public_circuit_public_inputs::PublicCircuitPublicInputs while
/// private functions return protocol_types::abis::private_circuit_public_inputs::::PrivateCircuitPublicInputs
///
/// This call constructs an ast token referencing the above types
/// The name is set in the function above `transform`, hence the
Expand All @@ -1387,7 +1393,7 @@ fn make_castable_return_type(expression: Expression) -> Statement {
/// ```noir
///
/// /// Before
/// fn foo() -> abi::PrivateCircuitPublicInputs {
/// fn foo() -> protocol_types::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs {
/// // ...
/// }
///
Expand All @@ -1397,7 +1403,8 @@ fn make_castable_return_type(expression: Expression) -> Statement {
/// // ...
/// }
fn create_return_type(ty: &str) -> FunctionReturnType {
let return_path = chained_path!("aztec", "abi", ty);
let path_snippet = ty.to_case(Case::Snake); // e.g. private_circuit_public_inputs or public_circuit_public_inputs
let return_path = chained_path!("aztec", "protocol_types", "abis", &path_snippet, ty);
return_type(return_path)
}

Expand All @@ -1409,7 +1416,7 @@ fn create_return_type(ty: &str) -> FunctionReturnType {
/// The replaced code:
/// ```noir
/// /// Before
/// fn foo() -> abi::PrivateCircuitPublicInputs {
/// fn foo() -> protocol_types::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs {
/// // ...
/// context.finish()
/// }
Expand Down
Loading
Loading