Skip to content

Commit fe58c0f

Browse files
authored
refactor: move public_checks caller helpers into aztec-nr (prep for public_checks demotion) (#23215)
Moves PublicChecks caller helpers from public_checks_contract/src/utils.nr into aztec-nr/aztec/src/public_checks.nr. Consumer contracts (app_subscription, crowdfunding) now import from aztec-nr. Stacked on #23214.
1 parent 0b0d739 commit fe58c0f

9 files changed

Lines changed: 36 additions & 12 deletions

File tree

docs/docs-developers/docs/foundational-topics/call_types.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ It is also possible to create public functions that can _only_ be invoked by pri
132132

133133
A common pattern is to enqueue public calls to check some validity condition on public state, e.g. that a deadline has not expired or that some public value is set.
134134

135-
#include_code enqueueing /noir-projects/noir-contracts/contracts/protocol/public_checks_contract/src/utils.nr rust
135+
#include_code enqueueing /noir-projects/aztec-nr/aztec/src/public_checks.nr rust
136136

137137
Note that this reveals what public function is being called on what contract, and perhaps more importantly which contract enqueued the call during private execution.
138138
To prevent this you can enqueue a call to a public function using `self.enqueue_incognito` that behaves the same as `self.enqueue` but conceals the message sender.
@@ -146,7 +146,7 @@ An example of how a deadline can be checked using the `PublicChecks` contract fo
146146

147147
`privately_check_timestamp` and `privately_check_block_number` are helper functions around the call to the `PublicChecks` contract:
148148

149-
#include_code helper_public_checks_functions /noir-projects/noir-contracts/contracts/protocol/public_checks_contract/src/utils.nr rust
149+
#include_code helper_public_checks_functions /noir-projects/aztec-nr/aztec/src/public_checks.nr rust
150150

151151
This is what the implementation of the check timestamp functionality looks like:
152152

docs/docs-developers/docs/resources/migration_notes.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ Aztec is in active development. Each version may introduce breaking changes that
99

1010
## TBD
1111

12+
### [Aztec.nr] `public_checks` helpers moved to `aztec-nr`
13+
14+
The `privately_check_timestamp`, `privately_check_block_number`, and related caller helpers previously in `noir-contracts/contracts/protocol/public_checks_contract/src/utils.nr` are now in `aztec-nr/aztec/src/public_checks.nr`. Consumer contracts should update their imports:
15+
16+
```diff
17+
- use public_checks::utils::privately_check_timestamp;
18+
+ use aztec::public_checks::privately_check_timestamp;
19+
```
20+
1221
### [Aztec.js] `AccountManager.create` takes an options bag
1322

1423
`AccountManager.create` no longer takes `salt` as a positional argument. The trailing `salt?: Salt` parameter has been folded into a new `AccountManagerCreateOptions` bag alongside `immutablesHash` and `deployer`:

noir-projects/aztec-nr/aztec/src/lib.nr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub use protocol_types as protocol;
4646
pub(crate) mod logging;
4747
pub mod utils;
4848
pub mod authwit;
49+
pub mod public_checks;
4950
pub mod macros;
5051

5152
pub mod test;

noir-projects/noir-contracts/contracts/protocol/public_checks_contract/src/utils.nr renamed to noir-projects/aztec-nr/aztec/src/public_checks.nr

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use crate::PublicChecks;
2-
use aztec::context::PrivateContext;
3-
use aztec::protocol::constants::PUBLIC_CHECKS_ADDRESS;
1+
use crate::context::calls::PublicStaticCall;
2+
use crate::context::PrivateContext;
3+
use crate::protocol::abis::function_selector::FunctionSelector;
4+
use crate::protocol::constants::PUBLIC_CHECKS_ADDRESS;
45

56
// docs:start:helper_public_checks_functions
67
/// Asserts that the current timestamp in the enqueued public call enqueued by `check_timestamp` satisfies
@@ -9,7 +10,14 @@ use aztec::protocol::constants::PUBLIC_CHECKS_ADDRESS;
910
/// This conceals an address of the calling contract by setting `context.msg_sender` to the public checks contract
1011
/// address.
1112
pub fn privately_check_timestamp(operation: u8, value: u64, context: &mut PrivateContext) {
12-
PublicChecks::at(PUBLIC_CHECKS_ADDRESS).check_timestamp(operation, value).enqueue_view_incognito(context);
13+
let selector = comptime { FunctionSelector::from_signature("check_timestamp(u8,u64)") };
14+
PublicStaticCall::<15, 2, ()>::new(
15+
PUBLIC_CHECKS_ADDRESS,
16+
selector,
17+
"check_timestamp",
18+
[operation as Field, value as Field],
19+
)
20+
.enqueue_view_incognito(context);
1321
}
1422

1523
/// Asserts that the current block number in the enqueued public call enqueued by `check_block_number` satisfies
@@ -19,7 +27,14 @@ pub fn privately_check_timestamp(operation: u8, value: u64, context: &mut Privat
1927
/// address.
2028
pub fn privately_check_block_number(operation: u8, value: u32, context: &mut PrivateContext) {
2129
// docs:start:enqueueing
22-
PublicChecks::at(PUBLIC_CHECKS_ADDRESS).check_block_number(operation, value).enqueue_view_incognito(context);
30+
let selector = comptime { FunctionSelector::from_signature("check_block_number(u8,u32)") };
31+
PublicStaticCall::<18, 2, ()>::new(
32+
PUBLIC_CHECKS_ADDRESS,
33+
selector,
34+
"check_block_number",
35+
[operation as Field, value as Field],
36+
)
37+
.enqueue_view_incognito(context);
2338
// docs:end:enqueueing
2439
}
2540
// docs:end:helper_public_checks_functions

noir-projects/noir-contracts/contracts/app/app_subscription_contract/Nargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ type = "contract"
77
[dependencies]
88
aztec = { path = "../../../../aztec-nr/aztec" }
99
token = { path = "../token_contract" }
10-
public_checks = { path = "../../protocol/public_checks_contract" }

noir-projects/noir-contracts/contracts/app/app_subscription_contract/src/main.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub contract AppSubscription {
5252
state_vars::{Owned, PrivateMutable, PublicImmutable},
5353
utils::comparison::Comparator,
5454
};
55-
use public_checks::utils::privately_check_block_number;
55+
use aztec::public_checks::privately_check_block_number;
5656
use token::Token;
5757

5858
#[storage]

noir-projects/noir-contracts/contracts/app/crowdfunding_contract/Nargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ type = "contract"
88
aztec = { path = "../../../../aztec-nr/aztec" }
99
uint_note = { path = "../../../../aztec-nr/uint-note" }
1010
token = { path = "../token_contract" }
11-
public_checks = { path = "../../protocol/public_checks_contract" }

noir-projects/noir-contracts/contracts/app/crowdfunding_contract/src/main.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub contract Crowdfunding {
1313
utils::{array, comparison::Comparator},
1414
};
1515
use aztec::note::{constants::MAX_NOTES_PER_PAGE, HintedNote, note_getter_options::NoteStatus};
16-
use public_checks::utils::privately_check_timestamp;
16+
use aztec::public_checks::privately_check_timestamp;
1717
use token::Token;
1818
use uint_note::UintNote;
1919

noir-projects/noir-contracts/contracts/protocol/public_checks_contract/src/main.nr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
mod test;
2-
pub mod utils;
32

43
use aztec::macros::aztec;
54

@@ -15,6 +14,7 @@ pub contract PublicChecks {
1514
// docs:start:check_timestamp
1615
/// Asserts that the current timestamp satisfies the `operation` with respect
1716
/// to the `value.
17+
/// NOTE: signature is hardcoded in `aztec-nr/aztec/src/public_checks.nr`; keep in sync.
1818
#[external("public")]
1919
#[view]
2020
fn check_timestamp(operation: u8, value: u64) {
@@ -26,6 +26,7 @@ pub contract PublicChecks {
2626

2727
/// Asserts that the current block number satisfies the `operation` with respect
2828
/// to the `value.
29+
/// NOTE: signature is hardcoded in `aztec-nr/aztec/src/public_checks.nr`; keep in sync.
2930
#[external("public")]
3031
#[view]
3132
fn check_block_number(operation: u8, value: u32) {

0 commit comments

Comments
 (0)