From 699fb791ad786e88f7c031168c8f1e119cbc94c0 Mon Sep 17 00:00:00 2001 From: esau <152162806+sklppy88@users.noreply.github.com> Date: Mon, 15 Jul 2024 22:31:10 +0200 Subject: [PATCH] feat: add unconstrained context to txe (#7448) Please read [contributing guidelines](CONTRIBUTING.md) and remove this line. --- .../aztec/src/state_vars/shared_mutable/test.nr | 6 +++++- .../aztec-nr/aztec/src/test/helpers/cheatcodes.nr | 14 ++++++++++++++ .../aztec/src/test/helpers/test_environment.nr | 7 ++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/test.nr b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/test.nr index e162a642eaa..3bbe4121dc8 100644 --- a/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/test.nr +++ b/noir-projects/aztec-nr/aztec/src/state_vars/shared_mutable/test.nr @@ -1,5 +1,5 @@ use crate::{ - context::{PublicContext, PrivateContext}, + context::{PublicContext, PrivateContext, UnconstrainedContext}, state_vars::shared_mutable::{ shared_mutable::SharedMutable, scheduled_value_change::ScheduledValueChange, scheduled_delay_change::ScheduledDelayChange @@ -33,6 +33,10 @@ fn in_private( SharedMutable::new(&mut env.private_at(historical_block_number), storage_slot) } +fn in_unconstrained(env: TestEnvironment) -> SharedMutable { + SharedMutable::new(env.unkonstrained(), storage_slot) +} + #[test] fn test_get_current_value_in_public_initial() { let env = setup(); diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr index 3d6b791e833..e230ebbab67 100644 --- a/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/cheatcodes.nr @@ -10,6 +10,14 @@ unconstrained pub fn reset() { oracle_reset(); } +unconstrained pub fn get_chain_id() -> Field { + oracle_get_chain_id() +} + +unconstrained pub fn get_version() -> Field { + oracle_get_version() +} + unconstrained pub fn get_contract_address() -> AztecAddress { oracle_get_contract_address() } @@ -112,6 +120,12 @@ unconstrained pub fn set_fn_selector(selector: FunctionSelector) { #[oracle(reset)] fn oracle_reset() {} +#[oracle(getChainId)] +fn oracle_get_chain_id() -> Field {} + +#[oracle(getVersion)] +fn oracle_get_version() -> Field {} + #[oracle(getContractAddress)] fn oracle_get_contract_address() -> AztecAddress {} diff --git a/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr index b6d0cc4546a..b6238d4e02d 100644 --- a/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr +++ b/noir-projects/aztec-nr/aztec/src/test/helpers/test_environment.nr @@ -7,7 +7,7 @@ use dep::protocol_types::{ use crate::context::inputs::{PublicContextInputs, PrivateContextInputs}; use crate::context::{packed_returns::PackedReturns, call_interfaces::CallInterface}; -use crate::context::{PrivateContext, PublicContext, PrivateVoidCallInterface}; +use crate::context::{PrivateContext, PublicContext, UnconstrainedContext, PrivateVoidCallInterface}; use crate::test::helpers::{cheatcodes, utils::{apply_side_effects_private, Deployer, TestAccount}, keys}; use crate::keys::constants::{NULLIFIER_INDEX, INCOMING_INDEX, OUTGOING_INDEX, TAGGING_INDEX}; use crate::hash::{hash_args, hash_args_array}; @@ -56,6 +56,11 @@ impl TestEnvironment { self.private_at(cheatcodes::get_block_number()) } + // unconstrained is a key word, so we mis-spell purposefully here, like we do with contrakt + fn unkonstrained(self) -> UnconstrainedContext { + UnconstrainedContext::new() + } + fn private_at(&mut self, historical_block_number: u32) -> PrivateContext { if historical_block_number >= cheatcodes::get_block_number() { self.advance_block_to(historical_block_number + 1);