Skip to content

Commit 5d2eb19

Browse files
committed
feat(public_checks): demote to non-protocol contract; introduce hand-written interface
1 parent adb099b commit 5d2eb19

27 files changed

Lines changed: 125 additions & 84 deletions

File tree

barretenberg/cpp/pil/vm2/constants_gen.pil

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ namespace constants;
1919
pol CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS = 3;
2020
pol MULTI_CALL_ENTRYPOINT_ADDRESS = 4;
2121
pol FEE_JUICE_ADDRESS = 5;
22-
pol PUBLIC_CHECKS_ADDRESS = 6;
2322
pol FEE_JUICE_BALANCES_SLOT = 1;
2423
pol UPDATED_CLASS_IDS_SLOT = 1;
2524
pol FLAT_PUBLIC_LOGS_HEADER_LENGTH = 1;

barretenberg/cpp/src/barretenberg/aztec/aztec_constants.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#define CONTRACT_CLASS_REGISTRY_CONTRACT_ADDRESS 3
2626
#define MULTI_CALL_ENTRYPOINT_ADDRESS 4
2727
#define FEE_JUICE_ADDRESS 5
28-
#define PUBLIC_CHECKS_ADDRESS 6
2928
#define FEE_JUICE_BALANCES_SLOT 1
3029
#define UPDATED_CLASS_IDS_SLOT 1
3130
#define FLAT_PUBLIC_LOGS_HEADER_LENGTH 1

noir-projects/aztec-nr/aztec/Nargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ type = "lib"
66

77
[dependencies]
88
protocol_types = { path = "../../noir-protocol-circuits/crates/types" }
9+
standard_addresses = { path = "../standard_addresses" }
910
sha256 = { tag = "v0.3.0", git = "https://github.com/noir-lang/sha256" }
1011
poseidon = { tag = "v0.3.0", git = "https://github.com/noir-lang/poseidon" }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub(crate) mod logging;
4747
pub mod utils;
4848
pub mod authwit;
4949
pub mod public_checks;
50+
pub mod public_checks_interface;
5051
pub mod macros;
5152

5253
pub mod test;
Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use crate::context::calls::PublicStaticCall;
21
use crate::context::PrivateContext;
3-
use crate::protocol::abis::function_selector::FunctionSelector;
4-
use crate::protocol::constants::PUBLIC_CHECKS_ADDRESS;
2+
use crate::public_checks_interface::PublicChecksInterface;
3+
use standard_addresses::PUBLIC_CHECKS_ADDRESS;
54

65
// docs:start:helper_public_checks_functions
76
/// Asserts that the current timestamp in the enqueued public call enqueued by `check_timestamp` satisfies
@@ -10,14 +9,7 @@ use crate::protocol::constants::PUBLIC_CHECKS_ADDRESS;
109
/// This conceals an address of the calling contract by setting `context.msg_sender` to the public checks contract
1110
/// address.
1211
pub fn privately_check_timestamp(operation: u8, value: u64, context: &mut PrivateContext) {
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);
12+
PublicChecksInterface::at(PUBLIC_CHECKS_ADDRESS).check_timestamp(operation, value).enqueue_view_incognito(context);
2113
}
2214

2315
/// Asserts that the current block number in the enqueued public call enqueued by `check_block_number` satisfies
@@ -27,14 +19,7 @@ pub fn privately_check_timestamp(operation: u8, value: u64, context: &mut Privat
2719
/// address.
2820
pub fn privately_check_block_number(operation: u8, value: u32, context: &mut PrivateContext) {
2921
// docs:start:enqueueing
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);
22+
PublicChecksInterface::at(PUBLIC_CHECKS_ADDRESS).check_block_number(operation, value).enqueue_view_incognito(context);
3823
// docs:end:enqueueing
3924
}
4025
// docs:end:helper_public_checks_functions
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use crate::context::calls::PublicStaticCall;
2+
use crate::protocol::abis::function_selector::FunctionSelector;
3+
use crate::protocol::address::AztecAddress;
4+
5+
/// Hand-written interface stub for the `PublicChecks` standard contract.
6+
///
7+
/// The `PublicChecks` contract exposes two view functions that can be enqueued
8+
/// from private context via `enqueue_view_incognito` to assert timestamp or
9+
/// block-number constraints without revealing the calling contract address.
10+
///
11+
/// The selectors are derived with `comptime { FunctionSelector::from_signature(...) }`,
12+
/// which matches exactly what the `#[aztec]` macro generates for the real contract.
13+
pub struct PublicChecksInterface {
14+
pub target_contract: AztecAddress,
15+
}
16+
17+
impl PublicChecksInterface {
18+
pub fn at(target_contract: AztecAddress) -> Self {
19+
Self { target_contract }
20+
}
21+
22+
pub fn check_timestamp(self, operation: u8, value: u64) -> PublicStaticCall<15, 2, ()> {
23+
let selector = comptime { FunctionSelector::from_signature("check_timestamp(u8,u64)") };
24+
PublicStaticCall::new(
25+
self.target_contract,
26+
selector,
27+
"check_timestamp",
28+
[operation as Field, value as Field],
29+
)
30+
}
31+
32+
pub fn check_block_number(self, operation: u8, value: u32) -> PublicStaticCall<18, 2, ()> {
33+
let selector = comptime { FunctionSelector::from_signature("check_block_number(u8,u32)") };
34+
PublicStaticCall::new(
35+
self.target_contract,
36+
selector,
37+
"check_block_number",
38+
[operation as Field, value as Field],
39+
)
40+
}
41+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ use protocol_types::{address::AztecAddress, traits::FromField};
44
pub global AUTH_REGISTRY_ADDRESS: AztecAddress = AztecAddress::from_field(
55
0x1f7f0c3d878160356b2025b056a7a390ab34bd17f2ba4320ffb4a71698d5bf3a,
66
);
7+
8+
pub global PUBLIC_CHECKS_ADDRESS: AztecAddress = AztecAddress::from_field(
9+
0x0ed9aa9b8262bd0afb923764799e058ad10cf0de3e01dcf955055b11fdb20d70,
10+
);

noir-projects/noir-contracts/Nargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ members = [
2828
"contracts/fees/sponsored_fpc_contract",
2929
"contracts/message_discovery/handshake_registry_contract",
3030
"contracts/standard/auth_registry_contract",
31+
"contracts/standard/public_checks_contract",
3132
"contracts/protocol/contract_class_registry_contract",
3233
"contracts/protocol/contract_instance_registry_contract",
3334
"contracts/protocol/fee_juice_contract",
3435
"contracts/protocol/multi_call_entrypoint_contract",
35-
"contracts/protocol/public_checks_contract",
3636
"contracts/protocol_interface/contract_instance_registry_interface",
3737
"contracts/protocol_interface/fee_juice_interface",
3838
"contracts/test/generic_proxy_contract",

noir-projects/noir-contracts/contracts/protocol/public_checks_contract/Nargo.toml renamed to noir-projects/noir-contracts/contracts/standard/public_checks_contract/Nargo.toml

File renamed without changes.

noir-projects/noir-contracts/contracts/protocol/public_checks_contract/src/main.nr renamed to noir-projects/noir-contracts/contracts/standard/public_checks_contract/src/main.nr

File renamed without changes.

0 commit comments

Comments
 (0)