From b08764055053eeef08d264e50ea9db2517947aec Mon Sep 17 00:00:00 2001 From: benesjan Date: Thu, 16 May 2024 15:34:28 +0000 Subject: [PATCH] feat: generic key validation request 2 --- .../vm/avm_trace/aztec_constants.hpp | 8 ++-- .../circuits/private-function.md | 2 +- .../circuits/private-kernel-initial.mdx | 8 ++-- .../circuits/private-kernel-inner.mdx | 6 +-- .../circuits/private-kernel-reset.md | 2 +- docs/docs/protocol-specs/constants.md | 4 +- .../src/core/libraries/ConstantsGen.sol | 8 ++-- .../aztec/src/context/private_context.nr | 48 ++++++++++++------- .../aztec-nr/aztec/src/keys/public_keys.nr | 21 +++++++- .../aztec/src/oracle/nullifier_keys.nr | 36 +++++++++----- .../kernel_circuit_public_inputs_composer.nr | 2 +- .../src/private_call_data_validator.nr | 4 +- ...e_kernel_circuit_public_inputs_composer.nr | 14 +++--- .../src/private_kernel_init.nr | 8 ++-- .../src/private_kernel_reset.nr | 16 +++---- .../src/private_kernel_tail.nr | 6 +-- .../src/private_kernel_tail_to_public.nr | 8 ++-- .../src/tests/validate_arrays.nr | 6 +-- .../private_validation_request_processor.nr | 21 ++++---- .../src/abis/private_circuit_public_inputs.nr | 22 ++++----- .../validation_requests.nr | 14 +++--- .../validation_requests_builder.nr | 8 ++-- .../crates/types/src/constants.nr | 8 ++-- .../crates/types/src/tests/fixture_builder.nr | 17 ++++--- .../private_circuit_public_inputs_builder.nr | 14 +++--- yarn-project/circuits.js/src/constants.gen.ts | 8 ++-- ...ate_kernel_reset_circuit_private_inputs.ts | 6 +-- .../structs/private_circuit_public_inputs.ts | 10 ++-- .../src/structs/validation_requests.ts | 8 ++-- .../circuits.js/src/tests/factories.ts | 8 ++-- .../src/type_conversion.ts | 12 ++--- .../build_private_kernel_reset_hints.ts | 9 ++-- .../pxe/src/simulator_oracle/index.ts | 2 +- .../simulator/src/acvm/oracle/oracle.ts | 4 +- .../simulator/src/acvm/oracle/typed_oracle.ts | 4 +- .../simulator/src/client/db_oracle.ts | 2 +- .../src/client/private_execution.test.ts | 32 +++++++------ .../simulator/src/client/simulator.test.ts | 2 +- .../simulator/src/client/view_data_oracle.ts | 4 +- 39 files changed, 234 insertions(+), 188 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp index c56cc0dfc547..4b2f6fa73be9 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/aztec_constants.hpp @@ -13,7 +13,7 @@ const size_t MAX_PUBLIC_DATA_READS_PER_CALL = 16; const size_t MAX_NOTE_HASH_READ_REQUESTS_PER_CALL = 32; const size_t MAX_NULLIFIER_READ_REQUESTS_PER_CALL = 2; const size_t MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL = 2; -const size_t MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL = 1; +const size_t MAX_KEY_VALIDATION_REQUESTS_PER_CALL = 1; const size_t MAX_NOTE_ENCRYPTED_LOGS_PER_CALL = 16; const size_t MAX_ENCRYPTED_LOGS_PER_CALL = 4; const size_t MAX_UNENCRYPTED_LOGS_PER_CALL = 4; @@ -27,7 +27,7 @@ const size_t MAX_NEW_L2_TO_L1_MSGS_PER_TX = 2; const size_t MAX_NOTE_HASH_READ_REQUESTS_PER_TX = 128; const size_t MAX_NULLIFIER_READ_REQUESTS_PER_TX = 8; const size_t MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX = 8; -const size_t MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX = 4; +const size_t MAX_KEY_VALIDATION_REQUESTS_PER_TX = 4; const size_t MAX_NOTE_ENCRYPTED_LOGS_PER_TX = 64; const size_t MAX_ENCRYPTED_LOGS_PER_TX = 8; const size_t MAX_UNENCRYPTED_LOGS_PER_TX = 8; @@ -112,7 +112,7 @@ const size_t HEADER_LENGTH = const size_t PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = CALL_CONTEXT_LENGTH + 4 + MAX_BLOCK_NUMBER_LENGTH + (READ_REQUEST_LENGTH * MAX_NOTE_HASH_READ_REQUESTS_PER_CALL) + (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL) + - (NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL) + + (NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_KEY_VALIDATION_REQUESTS_PER_CALL) + (NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + (NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL) + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + 1 + (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 + @@ -137,7 +137,7 @@ const size_t VALIDATION_REQUESTS_LENGTH = ROLLUP_VALIDATION_REQUESTS_LENGTH + (SCOPED_READ_REQUEST_LEN * MAX_NOTE_HASH_READ_REQUESTS_PER_TX) + (SCOPED_READ_REQUEST_LEN * MAX_NULLIFIER_READ_REQUESTS_PER_TX) + (SCOPED_READ_REQUEST_LEN * MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX) + - (SCOPED_NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX) + + (SCOPED_NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_KEY_VALIDATION_REQUESTS (PUBLIC_DATA_READ_LENGTH * MAX_PUBLIC_DATA_READS_PER_TX); const size_t PUBLIC_DATA_UPDATE_REQUEST_LENGTH = 2; const size_t COMBINED_ACCUMULATED_DATA_LENGTH = diff --git a/docs/docs/protocol-specs/circuits/private-function.md b/docs/docs/protocol-specs/circuits/private-function.md index 613282ef1b7d..d137504d2271 100644 --- a/docs/docs/protocol-specs/circuits/private-function.md +++ b/docs/docs/protocol-specs/circuits/private-function.md @@ -51,7 +51,7 @@ The public inputs of _every_ private function _must_ adhere to the following ABI | `encrypted_note_preimage_hashes` | [[`EncryptedNotePreimageHash`](#encryptednotepreimagehash); [`MAX_ENCRYPTED_NOTE_PREIMAGE_HASHES_PER_CALL`](../constants.md#circuit-constants)] | Hashes of the encrypted note preimages emitted in this function call. | | `note_hash_read_requests` | [[`ReadRequest`](#readrequest); [`MAX_NOTE_HASH_READ_REQUESTS_PER_CALL`](../constants.md#circuit-constants)] | Requests to prove the note hashes being read exist. | | `nullifier_read_requests` | [[`ReadRequest`](#readrequest); [`MAX_NULLIFIER_READ_REQUESTS_PER_CALL`](../constants.md#circuit-constants)] | Requests to prove the nullifiers being read exist. | -| `nullifier_key_validation_requests` | [[`ParentSecretKeyValidationRequest`](#parentsecretkeyvalidationrequest); [`MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL`](../constants.md#circuit-constants)] | Requests to validate nullifier keys used in this function call. | +| `key_validation_requests` | [[`ParentSecretKeyValidationRequest`](#parentsecretkeyvalidationrequest); [`MAX_KEY_VALIDATION_REQUESTS_PER_CALL`](../constants.md#circuit-constants)] | Requests to validate keys used in this function call. | | `public_call_requests` | [[`PublicCallRequest`](#publiccallrequest); [`MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL`](../constants.md#circuit-constants)] | Requests to call public functions. | | `private_call_requests` | [[`PrivateCallRequest`](#privatecallrequest); [`MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL`](../constants.md#circuit-constants)] | Requests to call Private functions. | | `counter_start` | `u32` | Counter at which the function call was initiated. | diff --git a/docs/docs/protocol-specs/circuits/private-kernel-initial.mdx b/docs/docs/protocol-specs/circuits/private-kernel-initial.mdx index 843f516772e0..84fcf1d13b09 100644 --- a/docs/docs/protocol-specs/circuits/private-kernel-initial.mdx +++ b/docs/docs/protocol-specs/circuits/private-kernel-initial.mdx @@ -452,7 +452,7 @@ class PrivateFunctionPublicInputs { l2_to_l1_messages: List~field~ note_hash_read_requests: List~ReadRequest~ nullifier_read_requests: List~ReadRequest~ - nullifier_key_validation_requests: List~ParentSecretKeyValidationRequest~ + key_validation_requests: List~ParentSecretKeyValidationRequest~ unencrypted_log_hashes: List~UnencryptedLogHash~ encrypted_log_hashes: List~EncryptedLogHash~ encrypted_note_preimage_hashes: List~EncryptedNotePreimageHash~ @@ -470,7 +470,7 @@ PrivateFunctionPublicInputs *-- NoteHash: note_hashes PrivateFunctionPublicInputs *-- Nullifier: nullifiers PrivateFunctionPublicInputs *-- ReadRequest: note_hash_read_requests PrivateFunctionPublicInputs *-- ReadRequest: nullifier_read_requests -PrivateFunctionPublicInputs *-- ParentSecretKeyValidationRequest: nullifier_key_validation_requests +PrivateFunctionPublicInputs *-- ParentSecretKeyValidationRequest: key_validation_requests PrivateFunctionPublicInputs *-- UnencryptedLogHash: unencrypted_log_hashes PrivateFunctionPublicInputs *-- EncryptedLogHash: encrypted_log_hashes PrivateFunctionPublicInputs *-- EncryptedNotePreimageHash: encrypted_note_preimage_hashes @@ -529,7 +529,7 @@ class ParentSecretKeyValidationRequest { parent_public_key: GrumpkinPoint hardened_child_secret_key: fq } -ParentSecretKeyValidationRequest ..> ParentSecretKeyValidationRequestContext: nullifier_key_validation_requests\n->nullifier_key_validation_request_contexts +ParentSecretKeyValidationRequest ..> ParentSecretKeyValidationRequestContext: key_validation_requests\n->nullifier_key_validation_request_contexts class UnencryptedLogHash { hash: field @@ -776,7 +776,7 @@ Would it be accurate to describe this as `AccumulatedTransientSideEffects`, perh | `encrypted_note_preimage_hash_contexts` | [[`EncryptedNotePreimageHashContext`](#encryptednotepreimagehash); [`MAX_ENCRYPTED_NOTE_PREIMAGE_HASHES_PER_TX`](../constants.md#circuit-constants)] | Hashes of the encrypted note preimages with extra data aiding verification. | | `note_hash_read_requests` | [[`ReadRequest`](./private-function#readrequest); [`MAX_NOTE_HASH_READ_REQUESTS_PER_TX`](../constants.md#circuit-constants)] | Requests to prove the note hashes being read exist. | | `nullifier_read_requests` | [[`ReadRequest`](./private-function#readrequest); [`MAX_NULLIFIER_READ_REQUESTS_PER_TX`](../constants.md#circuit-constants)] | Requests to prove the nullifiers being read exist. | -| `nullifier_key_validation_request_contexts` | [[`ParentSecretKeyValidationRequestContext`](#parentsecretkeyvalidationrequestcontext); [`MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX`](../constants.md#circuit-constants)] | Requests to validate nullifier keys. | +| `nullifier_key_validation_request_contexts` | [[`ParentSecretKeyValidationRequestContext`](#parentsecretkeyvalidationrequestcontext); [`MAX_KEY_VALIDATION_REQUESTS_PER_TX`](../constants.md#circuit-constants)] | Requests to validate nullifier keys. | | `public_call_request_contexts` | [[`PublicCallRequestContext`](./public-kernel-tail.md#publiccallrequestcontext); [`MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX`](../constants.md#circuit-constants)] | Requests to call publics functions. | | `private_call_request_stack` | [[`PrivateCallRequestContext`](#privatecallrequestcontext); [`MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX`](../constants.md#circuit-constants)] | Requests to call private functions. Pushed to the stack in reverse order so that they will be executed in chronological order. | diff --git a/docs/docs/protocol-specs/circuits/private-kernel-inner.mdx b/docs/docs/protocol-specs/circuits/private-kernel-inner.mdx index 7041d3a6999f..5e22f2c38687 100644 --- a/docs/docs/protocol-specs/circuits/private-kernel-inner.mdx +++ b/docs/docs/protocol-specs/circuits/private-kernel-inner.mdx @@ -251,7 +251,7 @@ class PrivateFunctionPublicInputs { encrypted_note_preimage_hashes: List~EncryptedNotePreimageHash~ note_hash_read_requests: List~ReadRequest~ nullifier_read_requests: List~ReadRequest~ - nullifier_key_validation_requests: List~ParentSecretKeyValidationRequest~ + key_validation_requests: List~ParentSecretKeyValidationRequest~ public_call_requests: List~PublicCallRequest~ private_call_requests: List~PrivateCallRequest~ counter_start: u32 @@ -266,7 +266,7 @@ PrivateFunctionPublicInputs *-- NoteHash: note_hashes PrivateFunctionPublicInputs *-- Nullifier: nullifiers PrivateFunctionPublicInputs *-- ReadRequest: note_hash_read_requests PrivateFunctionPublicInputs *-- ReadRequest: nullifier_read_requests -PrivateFunctionPublicInputs *-- ParentSecretKeyValidationRequest: nullifier_key_validation_requests +PrivateFunctionPublicInputs *-- ParentSecretKeyValidationRequest: key_validation_requests PrivateFunctionPublicInputs *-- UnencryptedLogHash: unencrypted_log_hashes PrivateFunctionPublicInputs *-- EncryptedLogHash: encrypted_log_hashes PrivateFunctionPublicInputs *-- EncryptedNotePreimageHash: encrypted_note_preimage_hashes @@ -338,7 +338,7 @@ class ParentSecretKeyValidationRequest { parent_public_key: GrumpkinPoint hardened_child_secret_key: fq } -ParentSecretKeyValidationRequest ..> ParentSecretKeyValidationRequestContext: nullifier_key_validation_requests\n->nullifier_key_validation_request_contexts +ParentSecretKeyValidationRequest ..> ParentSecretKeyValidationRequestContext: key_validation_requests\n->nullifier_key_validation_request_contexts class UnencryptedLogHash { hash: field diff --git a/docs/docs/protocol-specs/circuits/private-kernel-reset.md b/docs/docs/protocol-specs/circuits/private-kernel-reset.md index 0b0dd79141bd..e0da44c25d91 100644 --- a/docs/docs/protocol-specs/circuits/private-kernel-reset.md +++ b/docs/docs/protocol-specs/circuits/private-kernel-reset.md @@ -236,7 +236,7 @@ The format aligns with the [`PreviousKernel`](./private-kernel-inner#previousker | Field | Type | Description | | -------------------- | ---------------------------------------------------------------------------------------------- | --------------------------------------- | -| `master_secret_keys` | [`field`; [`MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX`](../constants.md#circuit-constants)] | Master secret keys for the secret keys. | +| `master_secret_keys` | [`field`; [`MAX_KEY_VALIDATION_REQUESTS_PER_TX`](../constants.md#circuit-constants)] | Master secret keys for the secret keys. | ### _Hints_ for [Transient Note Reset Private Kernel Circuit](#transient-note-reset-private-kernel-circuit) diff --git a/docs/docs/protocol-specs/constants.md b/docs/docs/protocol-specs/constants.md index 969a98ffae47..945a8c3c180b 100644 --- a/docs/docs/protocol-specs/constants.md +++ b/docs/docs/protocol-specs/constants.md @@ -52,7 +52,7 @@ The statically-sized nature the kernel & rollup circuits will restrict the quant | `MAX_ENCRYPTED_NOTE_PREIMAGE_HASHES_PER_CALL` | 128 | | `MAX_NOTE_HASH_READ_REQUESTS_PER_CALL` | 128 | | `MAX_NULLIFIER_READ_REQUESTS_PER_CALL` | 128 | -| `MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL` | 1 | TODO: we shouldn't need this, given the reset circuit. | +| `MAX_KEY_VALIDATION_REQUESTS_PER_CALL | 1 | TODO: we shouldn't need this, given the reset circuit. | | `MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL` | 32 | | `MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL` | 32 | @@ -71,7 +71,7 @@ The statically-sized nature the kernel & rollup circuits will restrict the quant | `MAX_ENCRYPTED_NOTE_PREIMAGE_HASHES_PER_TX` | 128 | | `MAX_OPTIONALLY_REVEALED_DATA_LENGTH_PER_TX` | 4 | | `MAX_NOTE_HASH_READ_REQUESTS_PER_TX` | 128 | TODO: we shouldn't need this, given the reset circuit. | -| `MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX` | 4 | TODO: we shouldn't need this, given the reset circuit. | +| `MAX_KEY_VALIDATION_REQUESTS_PER_TX` | 4 | TODO: we shouldn't need this, given the reset circuit. | | `MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX` | 32 | | `MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX` | 32 | diff --git a/l1-contracts/src/core/libraries/ConstantsGen.sol b/l1-contracts/src/core/libraries/ConstantsGen.sol index 4aeefe97cccd..558ea9754744 100644 --- a/l1-contracts/src/core/libraries/ConstantsGen.sol +++ b/l1-contracts/src/core/libraries/ConstantsGen.sol @@ -25,7 +25,7 @@ library Constants { uint256 internal constant MAX_NOTE_HASH_READ_REQUESTS_PER_CALL = 32; uint256 internal constant MAX_NULLIFIER_READ_REQUESTS_PER_CALL = 2; uint256 internal constant MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL = 2; - uint256 internal constant MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL = 16; + uint256 internal constant MAX_KEY_VALIDATION_REQUESTS_PER_CALL = 16; uint256 internal constant MAX_NOTE_ENCRYPTED_LOGS_PER_CALL = 16; uint256 internal constant MAX_ENCRYPTED_LOGS_PER_CALL = 4; uint256 internal constant MAX_UNENCRYPTED_LOGS_PER_CALL = 4; @@ -39,7 +39,7 @@ library Constants { uint256 internal constant MAX_NOTE_HASH_READ_REQUESTS_PER_TX = 128; uint256 internal constant MAX_NULLIFIER_READ_REQUESTS_PER_TX = 8; uint256 internal constant MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX = 8; - uint256 internal constant MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX = 64; + uint256 internal constant MAX_KEY_VALIDATION_REQUESTS_PER_TX = 64; uint256 internal constant MAX_NOTE_ENCRYPTED_LOGS_PER_TX = 64; uint256 internal constant MAX_ENCRYPTED_LOGS_PER_TX = 8; uint256 internal constant MAX_UNENCRYPTED_LOGS_PER_TX = 8; @@ -142,7 +142,7 @@ library Constants { uint256 internal constant PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = CALL_CONTEXT_LENGTH + 4 + MAX_BLOCK_NUMBER_LENGTH + (READ_REQUEST_LENGTH * MAX_NOTE_HASH_READ_REQUESTS_PER_CALL) + (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL) - + (NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL) + + (NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_KEY_VALIDATION_REQUESTS_PER_CALL) + (NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + (NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL) + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + 1 @@ -170,7 +170,7 @@ library Constants { + (SCOPED_READ_REQUEST_LEN * MAX_NOTE_HASH_READ_REQUESTS_PER_TX) + (SCOPED_READ_REQUEST_LEN * MAX_NULLIFIER_READ_REQUESTS_PER_TX) + (SCOPED_READ_REQUEST_LEN * MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX) - + (SCOPED_NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX) + + (SCOPED_NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_KEY_VALIDATION_REQUESTS_PER_TX) + (PUBLIC_DATA_READ_LENGTH * MAX_PUBLIC_DATA_READS_PER_TX); uint256 internal constant PUBLIC_DATA_UPDATE_REQUEST_LENGTH = 2; uint256 internal constant COMBINED_ACCUMULATED_DATA_LENGTH = MAX_NEW_NOTE_HASHES_PER_TX diff --git a/noir-projects/aztec-nr/aztec/src/context/private_context.nr b/noir-projects/aztec-nr/aztec/src/context/private_context.nr index abc74607c84e..3bd5235c6cd0 100644 --- a/noir-projects/aztec-nr/aztec/src/context/private_context.nr +++ b/noir-projects/aztec-nr/aztec/src/context/private_context.nr @@ -2,9 +2,10 @@ use crate::{ context::{inputs::PrivateContextInputs, interface::ContextInterface}, messaging::process_l1_to_l2_message, hash::{hash_args_array, ArgsHasher, compute_encrypted_log_hash, compute_unencrypted_log_hash}, + keys::public_keys::{NULLIFIER_INDEX, OUTGOING_INDEX, NUM_KEY_TYPES, get_sk_app_generator}, note::{note_interface::NoteInterface, utils::compute_note_hash_for_insertion}, oracle::{ - nullifier_keys::get_nullifier_key_validation_request, arguments, returns, + nullifier_keys::get_key_validation_request, arguments, returns, call_private_function::call_private_function_internal, header::get_header_at, logs::emit_encrypted_log, logs_traits::{LensForEncryptedLog, ToBytesForUnencryptedLog}, enqueue_public_function_call::{ @@ -26,8 +27,8 @@ use dep::protocol_types::{ MAX_NEW_NOTE_HASHES_PER_CALL, MAX_NEW_L2_TO_L1_MSGS_PER_CALL, MAX_NEW_NULLIFIERS_PER_CALL, MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, MAX_NULLIFIER_READ_REQUESTS_PER_CALL, - MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL, MAX_ENCRYPTED_LOGS_PER_CALL, - MAX_UNENCRYPTED_LOGS_PER_CALL, MAX_NOTE_ENCRYPTED_LOGS_PER_CALL + MAX_KEY_VALIDATION_REQUESTS_PER_CALL, MAX_ENCRYPTED_LOGS_PER_CALL, MAX_UNENCRYPTED_LOGS_PER_CALL, + MAX_NOTE_ENCRYPTED_LOGS_PER_CALL }, contrakt::{storage_read::StorageRead, storage_update_request::StorageUpdateRequest}, grumpkin_private_key::GrumpkinPrivateKey, grumpkin_point::GrumpkinPoint, header::Header, @@ -51,7 +52,8 @@ struct PrivateContext { note_hash_read_requests: BoundedVec, nullifier_read_requests: BoundedVec, - nullifier_key_validation_requests: BoundedVec, + key_validation_requests: BoundedVec, + app_secret_keys_generators: BoundedVec, new_note_hashes: BoundedVec, new_nullifiers: BoundedVec, @@ -71,7 +73,10 @@ struct PrivateContext { encrypted_log_preimages_length: Field, unencrypted_log_preimages_length: Field, - last_nullifier_key_validation_request: Option, + // Contains the last key validation request for each key type. This is used to cache the last request and avoid + // fetching the same request multiple times. + // The index of the array corresponds to the key type (0 nullifier, 1 incoming, ). + last_key_validation_requests: [Option; NUM_KEY_TYPES], } impl ContextInterface for PrivateContext { @@ -120,7 +125,8 @@ impl PrivateContext { max_block_number: MaxBlockNumber::empty(), note_hash_read_requests: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), - nullifier_key_validation_requests: BoundedVec::new(), + key_validation_requests: BoundedVec::new(), + app_secret_keys_generators: BoundedVec::new(), new_note_hashes: BoundedVec::new(), new_nullifiers: BoundedVec::new(), historical_header: inputs.historical_header, @@ -133,7 +139,7 @@ impl PrivateContext { unencrypted_logs_hashes: BoundedVec::new(), encrypted_log_preimages_length: 0, unencrypted_log_preimages_length: 0, - last_nullifier_key_validation_request: Option::none() + last_key_validation_requests: [Option::none(); NUM_KEY_TYPES] } } @@ -164,7 +170,7 @@ impl PrivateContext { max_block_number: self.max_block_number, note_hash_read_requests: self.note_hash_read_requests.storage, nullifier_read_requests: self.nullifier_read_requests.storage, - nullifier_key_validation_requests: self.nullifier_key_validation_requests.storage, + key_validation_requests: self.key_validation_requests.storage, new_note_hashes: self.new_note_hashes.storage, new_nullifiers: self.new_nullifiers.storage, private_call_stack_hashes: self.private_call_stack_hashes.storage, @@ -208,20 +214,29 @@ impl PrivateContext { } pub fn request_nsk_app(&mut self, npk_m_hash: Field) -> Field { - let cached_request = self.last_nullifier_key_validation_request.unwrap_or(NullifierKeyValidationRequest::empty()); + self.request_sk_app(npk_m_hash, NULLIFIER_INDEX) + } + + pub fn request_osk_app(&mut self, opk_m_hash: Field) -> Field { + self.request_sk_app(opk_m_hash, OUTGOING_INDEX) + } + + fn request_sk_app(&mut self, pk_m_hash: Field, key_index: Field) -> Field { + let cached_request = self.last_key_validation_requests[key_index].unwrap_or(NullifierKeyValidationRequest::empty()); - if cached_request.master_nullifier_public_key.hash() == npk_m_hash { + if cached_request.master_nullifier_public_key.hash() == pk_m_hash { // We get a match so the cached request is the latest one cached_request.app_nullifier_secret_key } else { // We didn't get a match meaning the cached result is stale. We fetch new values from oracle and instruct // protocol circuits to validate them by storing the validation request in context. - let request = get_nullifier_key_validation_request(npk_m_hash); + let request = get_key_validation_request(pk_m_hash); // We constrain that the npk_m_hash matches the one in the request (otherwise we could get an arbitrary // valid key request and not the one corresponding to npk_m_hash). - assert(request.master_nullifier_public_key.hash() == npk_m_hash); - self.nullifier_key_validation_requests.push(request); - self.last_nullifier_key_validation_request = Option::some(request); + assert(request.master_nullifier_public_key.hash() == pk_m_hash); + self.key_validation_requests.push(request); + self.app_secret_keys_generators.push(get_sk_app_generator(key_index)); + self.last_key_validation_requests[key_index] = Option::some(request); request.app_nullifier_secret_key } } @@ -660,7 +675,8 @@ impl Empty for PrivateContext { max_block_number: MaxBlockNumber::empty(), note_hash_read_requests: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), - nullifier_key_validation_requests: BoundedVec::new(), + key_validation_requests: BoundedVec::new(), + app_secret_keys_generators: BoundedVec::new(), new_note_hashes: BoundedVec::new(), new_nullifiers: BoundedVec::new(), private_call_stack_hashes : BoundedVec::new(), @@ -673,7 +689,7 @@ impl Empty for PrivateContext { unencrypted_logs_hashes: BoundedVec::new(), encrypted_log_preimages_length: 0, unencrypted_log_preimages_length: 0, - last_nullifier_key_validation_request: Option::none(), + last_key_validation_requests: [Option::none(); NUM_KEY_TYPES] } } } diff --git a/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr b/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr index ffdff5aa001a..5bfc38f9758a 100644 --- a/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr +++ b/noir-projects/aztec-nr/aztec/src/keys/public_keys.nr @@ -3,6 +3,9 @@ use dep::protocol_types::{ grumpkin_point::GrumpkinPoint, traits::{Deserialize, Serialize} }; +// TODO(benesjan): used only in get_sk_app_generator +use dep::protocol_types::constants::{GENERATOR_INDEX__NSK_M, GENERATOR_INDEX__IVSK_M, GENERATOR_INDEX__OVSK_M, GENERATOR_INDEX__TSK_M}; + // Note: In fetch_key_from_registry we expect that the shared mutable slot is index * 2 + 1 for the x coordinate and // index * 2 + 2 for the y coordinate. For example, the npk_m x coordinates will be stored in a map at storage slot // 0 * 2 + 1 = 1, and the npk_m y coordinates at 2 * 2 + 2 = 6. If this changes the function will need to be @@ -13,6 +16,22 @@ global OUTGOING_INDEX = 2; global TAGGING_INDEX = 3; global PUBLIC_KEYS_LENGTH = 8; +// TODO(benesjan): used also in private_context.nr. Move to shared location? +global NUM_KEY_TYPES = 4; + +// TODO(benesjan): Is this the best place to have this? +pub fn get_sk_app_generator(key_index: Field) -> Field { + assert(key_index as u8 < NUM_KEY_TYPES, "Invalid key index"); + if key_index == NULLIFIER_INDEX { + GENERATOR_INDEX__NSK_M + } else if key_index == INCOMING_INDEX { + GENERATOR_INDEX__IVSK_M + } else if key_index == OUTGOING_INDEX { + GENERATOR_INDEX__OVSK_M + } else { + GENERATOR_INDEX__TSK_M + } +} struct PublicKeys { npk_m: GrumpkinPoint, @@ -41,7 +60,7 @@ impl PublicKeys { } pub fn get_key_by_index(self, index: Field) -> GrumpkinPoint { - assert(index as u8 < 4, "Invalid key index"); + assert(index as u8 < NUM_KEY_TYPES, "Invalid key index"); if index == NULLIFIER_INDEX { self.npk_m } else if index == INCOMING_INDEX { diff --git a/noir-projects/aztec-nr/aztec/src/oracle/nullifier_keys.nr b/noir-projects/aztec-nr/aztec/src/oracle/nullifier_keys.nr index 0eb33d7cb159..d6ef90d447f4 100644 --- a/noir-projects/aztec-nr/aztec/src/oracle/nullifier_keys.nr +++ b/noir-projects/aztec-nr/aztec/src/oracle/nullifier_keys.nr @@ -1,21 +1,33 @@ -use dep::protocol_types::{grumpkin_point::GrumpkinPoint, abis::nullifier_key_validation_request::NullifierKeyValidationRequest}; +use dep::protocol_types::{ + grumpkin_point::GrumpkinPoint, + abis::nullifier_key_validation_request::{NullifierKeyValidationRequest, NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH} +}; -#[oracle(getNullifierKeys)] -fn get_nullifier_key_validation_request_oracle(_npk_m_hash: Field) -> [Field; 3] {} +// TODO(benesjan): It's weird to be importing here form keys and it's probably a circular dependency - restructure it +use crate::keys::public_keys::NULLIFIER_INDEX; -unconstrained fn get_nullifier_key_validation_request_internal(npk_m_hash: Field) -> NullifierKeyValidationRequest { - let result = get_nullifier_key_validation_request_oracle(npk_m_hash); - NullifierKeyValidationRequest { - master_nullifier_public_key: GrumpkinPoint { x: result[0], y: result[1] }, - app_nullifier_secret_key: result[2] - } +#[oracle(getKeyValidationRequest)] +fn get_key_validation_request_oracle( + _npk_m_hash: Field, + _key_index: Field +) -> [Field; NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH] {} + +unconstrained fn get_key_validation_request_internal( + npk_m_hash: Field, + key_index: Field +) -> NullifierKeyValidationRequest { + let result = get_key_validation_request_oracle(npk_m_hash, key_index); + NullifierKeyValidationRequest::deserialize(result) +} + +pub fn get_key_validation_request(pk_m_hash: Field, key_index: Field) -> NullifierKeyValidationRequest { + get_key_validation_request_internal(pk_m_hash, key_index) } -// We get the full struct Nullifier Keys here pub fn get_nullifier_key_validation_request(npk_m_hash: Field) -> NullifierKeyValidationRequest { - get_nullifier_key_validation_request_internal(npk_m_hash) + get_key_validation_request_internal(npk_m_hash, NULLIFIER_INDEX) } pub fn get_nsk_app(npk_m_hash: Field) -> Field { - get_nullifier_key_validation_request_internal(npk_m_hash).app_nullifier_secret_key + get_nullifier_key_validation_request(npk_m_hash).app_nullifier_secret_key } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr index c5f8835c4bc5..2bf711e6ef24 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/kernel_circuit_public_inputs_composer.nr @@ -259,7 +259,7 @@ impl KernelCircuitPublicInputsComposer { ); assert_eq( - array_length(self.previous_kernel.public_inputs.validation_requests.nullifier_key_validation_requests), 0, "Non empty nullifier key validation requests" + array_length(self.previous_kernel.public_inputs.validation_requests.key_validation_requests), 0, "Non empty nullifier key validation requests" ); } } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_call_data_validator.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_call_data_validator.nr index 98dcf2727f84..437e1c4dd121 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_call_data_validator.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_call_data_validator.nr @@ -16,7 +16,7 @@ fn validate_arrays(data: PrivateCallData) -> ArrayLengths { ArrayLengths { note_hash_read_requests: validate_array(public_inputs.note_hash_read_requests), nullifier_read_requests: validate_array(public_inputs.nullifier_read_requests), - nullifier_key_validation_requests: validate_array(public_inputs.nullifier_key_validation_requests), + key_validation_requests: validate_array(public_inputs.key_validation_requests), new_note_hashes: validate_array(public_inputs.new_note_hashes), new_nullifiers: validate_array(public_inputs.new_nullifiers), new_l2_to_l1_msgs: validate_array(public_inputs.new_l2_to_l1_msgs), @@ -143,7 +143,7 @@ fn validate_split_public_call_requests( struct ArrayLengths { note_hash_read_requests: u64, nullifier_read_requests: u64, - nullifier_key_validation_requests: u64, + key_validation_requests: u64, new_note_hashes: u64, new_nullifiers: u64, new_l2_to_l1_msgs: u64, diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_circuit_public_inputs_composer.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_circuit_public_inputs_composer.nr index 32e9219529ee..8cc6f4535ef4 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_circuit_public_inputs_composer.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_circuit_public_inputs_composer.nr @@ -60,7 +60,7 @@ impl PrivateKernelCircuitPublicInputsComposer { public_inputs.validation_requests.max_block_number = start.for_rollup.max_block_number; public_inputs.validation_requests.note_hash_read_requests = array_to_bounded_vec(start.note_hash_read_requests); public_inputs.validation_requests.nullifier_read_requests = array_to_bounded_vec(start.nullifier_read_requests); - public_inputs.validation_requests.nullifier_key_validation_requests = array_to_bounded_vec(start.nullifier_key_validation_requests); + public_inputs.validation_requests.key_validation_requests = array_to_bounded_vec(start.key_validation_requests); let start = previous_kernel_public_inputs.end; public_inputs.end.new_note_hashes = array_to_bounded_vec(start.new_note_hashes); @@ -99,7 +99,7 @@ impl PrivateKernelCircuitPublicInputsComposer { self.propagate_max_block_number(source); self.propagate_note_hash_read_requests(source); self.propagate_nullifier_read_requests(source); - self.propagate_nullifier_key_validation_requests(source); + self.propagate_key_validation_requests(source); self.propagate_note_hashes(source); self.propagate_nullifiers(source); self.propagate_l2_to_l1_messages(source); @@ -141,12 +141,12 @@ impl PrivateKernelCircuitPublicInputsComposer { } } - fn propagate_nullifier_key_validation_requests(&mut self, source: DataSource) { - let nullifier_key_validation_requests = source.private_call_public_inputs.nullifier_key_validation_requests; - for i in 0..nullifier_key_validation_requests.len() { - let request = nullifier_key_validation_requests[i]; + fn propagate_key_validation_requests(&mut self, source: DataSource) { + let key_validation_requests = source.private_call_public_inputs.key_validation_requests; + for i in 0..key_validation_requests.len() { + let request = key_validation_requests[i]; if !is_empty(request) { - self.public_inputs.validation_requests.nullifier_key_validation_requests.push(request.scope(source.storage_contract_address)); + self.public_inputs.validation_requests.key_validation_requests.push(request.scope(source.storage_contract_address)); } } } diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr index c6ae0c8d1939..3f6dbb77664f 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_init.nr @@ -194,17 +194,17 @@ mod tests { } #[test] - fn propagate_nullifier_key_validation_requests() { + fn propagate_key_validation_requests() { let mut builder = PrivateKernelInitInputsBuilder::new(); let request_0 = NullifierKeyValidationRequest { master_nullifier_public_key: GrumpkinPoint { x: 1, y: 2 }, app_nullifier_secret_key: 3 }; - builder.private_call.public_inputs.nullifier_key_validation_requests.push(request_0); + builder.private_call.public_inputs.key_validation_requests.push(request_0); let public_inputs = builder.execute(); - assert_eq(array_length(public_inputs.validation_requests.nullifier_key_validation_requests), 1); + assert_eq(array_length(public_inputs.validation_requests.key_validation_requests), 1); - let request = public_inputs.validation_requests.nullifier_key_validation_requests[0]; + let request = public_inputs.validation_requests.key_validation_requests[0]; assert_eq(request.request, request_0); assert_eq( request.contract_address, builder.private_call.public_inputs.call_context.storage_contract_address diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr index 99b827e9be96..7683141e5778 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_reset.nr @@ -11,8 +11,8 @@ use dep::types::{ }, constants::{ MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_NOTE_HASH_READ_REQUESTS_PER_TX, - MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_ENCRYPTED_LOGS_PER_TX, - MAX_UNENCRYPTED_LOGS_PER_TX, MAX_NOTE_ENCRYPTED_LOGS_PER_TX + MAX_KEY_VALIDATION_REQUESTS_PER_TX, MAX_ENCRYPTED_LOGS_PER_TX, MAX_UNENCRYPTED_LOGS_PER_TX, + MAX_NOTE_ENCRYPTED_LOGS_PER_TX }, grumpkin_private_key::GrumpkinPrivateKey, utils::arrays::array_length, traits::is_empty, PrivateKernelCircuitPublicInputs @@ -31,7 +31,7 @@ struct PrivateKernelResetHints { transient_note_hash_indexes_for_logs: [u64; MAX_NOTE_ENCRYPTED_LOGS_PER_TX], note_hash_read_request_hints: NoteHashReadRequestHints, nullifier_read_request_hints: NullifierReadRequestHints, - master_nullifier_secret_keys: [GrumpkinPrivateKey; MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX], + master_secret_keys: [GrumpkinPrivateKey; MAX_KEY_VALIDATION_REQUESTS_PER_TX], } struct PrivateKernelResetCircuitPrivateInputs { @@ -55,7 +55,7 @@ impl PrivateKernelResetCircuitPrivateInputs { nullifier_read_request_hints: self.hints.nullifier_read_request_hints, pending_nullifiers: previous_public_inputs.end.new_nullifiers, nullifier_tree_root: previous_public_inputs.constants.historical_header.state.partial.nullifier_tree.root, - master_nullifier_secret_keys: self.hints.master_nullifier_secret_keys + master_secret_keys: self.hints.master_secret_keys }.validate(); let removed_logs_len = verify_squashed_transient_note_hashes_and_nullifiers( @@ -91,7 +91,7 @@ mod tests { }; use dep::types::constants::{ MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, - MAX_NULLIFIER_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, + MAX_NULLIFIER_READ_REQUESTS_PER_TX, MAX_KEY_VALIDATION_REQUESTS_PER_TX, MAX_ENCRYPTED_LOGS_PER_TX, MAX_UNENCRYPTED_LOGS_PER_TX, MAX_NOTE_ENCRYPTED_LOGS_PER_TX, DA_BYTES_PER_FIELD }; @@ -179,7 +179,7 @@ mod tests { transient_note_hash_indexes_for_logs: self.transient_note_hash_indexes_for_logs, note_hash_read_request_hints: self.note_hash_read_request_hints_builder.to_hints(), nullifier_read_request_hints: self.nullifier_read_request_hints_builder.to_hints(), - master_nullifier_secret_keys: [GrumpkinPrivateKey::empty(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX] + master_secret_keys: [GrumpkinPrivateKey::empty(); MAX_KEY_VALIDATION_REQUESTS_PER_TX] }; let kernel = PrivateKernelResetCircuitPrivateInputs { previous_kernel: self.previous_kernel.to_private_kernel_data(), outputs, hints }; @@ -301,14 +301,14 @@ mod tests { let nullifier_rr = builder.previous_kernel.nullifier_read_requests.storage[remaining_nullifier_rr_index]; let nk_validation_index = builder.previous_kernel.add_request_for_nullifier_key_validation(GrumpkinPoint::new(1, 2), 27); - let nk_validation = builder.previous_kernel.nullifier_key_validation_requests.storage[nk_validation_index]; + let nk_validation = builder.previous_kernel.key_validation_requests.storage[nk_validation_index]; // Check that they have been propagated to the next kernel let result = builder.execute(); assert_eq(result.validation_requests.note_hash_read_requests[0], note_hash_rr); assert_eq(result.validation_requests.nullifier_read_requests[0], nullifier_rr); - assert_eq(result.validation_requests.nullifier_key_validation_requests[0], nk_validation); + assert_eq(result.validation_requests.key_validation_requests[0], nk_validation); } #[test] diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr index 3c887b053611..3f6857acc252 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail.nr @@ -7,8 +7,8 @@ use dep::types::{ }, constants::{ MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_NOTE_HASH_READ_REQUESTS_PER_TX, - MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_ENCRYPTED_LOGS_PER_TX, - MAX_UNENCRYPTED_LOGS_PER_TX, MAX_NOTE_ENCRYPTED_LOGS_PER_TX + MAX_KEY_VALIDATION_REQUESTS_PER_TX, MAX_ENCRYPTED_LOGS_PER_TX, MAX_UNENCRYPTED_LOGS_PER_TX, + MAX_NOTE_ENCRYPTED_LOGS_PER_TX }, grumpkin_private_key::GrumpkinPrivateKey, utils::arrays::array_length, traits::is_empty }; @@ -72,7 +72,7 @@ mod tests { }; use dep::types::constants::{ MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, - MAX_NULLIFIER_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, + MAX_NULLIFIER_READ_REQUESTS_PER_TX, MAX_KEY_VALIDATION_REQUESTS_PER_TX, MAX_ENCRYPTED_LOGS_PER_TX, MAX_UNENCRYPTED_LOGS_PER_TX, MAX_NOTE_ENCRYPTED_LOGS_PER_TX, DA_BYTES_PER_FIELD, DA_GAS_PER_BYTE }; diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr index 3fd1370fcf13..dfc7fb4bd817 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/private_kernel_tail_to_public.nr @@ -7,8 +7,8 @@ use dep::types::{ }, constants::{ MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_NOTE_HASH_READ_REQUESTS_PER_TX, - MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_ENCRYPTED_LOGS_PER_TX, - MAX_UNENCRYPTED_LOGS_PER_TX, MAX_NOTE_ENCRYPTED_LOGS_PER_TX + MAX_KEY_VALIDATION_REQUESTS_PER_TX, MAX_ENCRYPTED_LOGS_PER_TX, MAX_UNENCRYPTED_LOGS_PER_TX, + MAX_NOTE_ENCRYPTED_LOGS_PER_TX }, grumpkin_private_key::GrumpkinPrivateKey, utils::arrays::array_length, traits::is_empty }; @@ -71,8 +71,8 @@ mod tests { }; use dep::types::constants::{ MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, - MAX_NULLIFIER_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, - DA_BYTES_PER_FIELD, DA_GAS_PER_BYTE, MAX_NOTE_ENCRYPTED_LOGS_PER_TX + MAX_NULLIFIER_READ_REQUESTS_PER_TX, MAX_KEY_VALIDATION_REQUESTS_PER_TX, DA_BYTES_PER_FIELD, + DA_GAS_PER_BYTE, MAX_NOTE_ENCRYPTED_LOGS_PER_TX }; use dep::types::{ abis::{ diff --git a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/validate_arrays.nr b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/validate_arrays.nr index a8c1b2f6efd8..bfcf149995e0 100644 --- a/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/validate_arrays.nr +++ b/noir-projects/noir-protocol-circuits/crates/private-kernel-lib/src/tests/validate_arrays.nr @@ -32,12 +32,12 @@ fn validate_arrays_malformed_nullifier_read_requests_fails() { builder.validate(); } -// Enable this test if MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL is greater than 1. +// Enable this test if MAX_KEY_VALIDATION_REQUESTS_PER_CALL is greater than 1. // #[test(should_fail_with="invalid array")] -// fn validate_arrays_malformed_nullifier_key_validation_requests_fails() { +// fn validate_arrays_malformed_key_validation_requests_fails() { // let mut builder = PrivateCallDataValidatorBuilder::new(); -// builder.private_call.public_inputs.nullifier_key_validation_requests.extend_from_array( +// builder.private_call.public_inputs.key_validation_requests.extend_from_array( // [ // NullifierKeyValidationRequest::empty(), // NullifierKeyValidationRequest { master_nullifier_public_key: GrumpkinPoint { x: 12, y: 34 }, app_nullifier_secret_key: 5 } diff --git a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/private_validation_request_processor.nr b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/private_validation_request_processor.nr index d8516c91ae2f..952416d9bd63 100644 --- a/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/private_validation_request_processor.nr +++ b/noir-projects/noir-protocol-circuits/crates/reset-kernel-lib/src/private_validation_request_processor.nr @@ -9,7 +9,7 @@ use dep::types::{ nullifier_key_validation_request::ScopedNullifierKeyValidationRequest }, constants::{ - MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, + MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_KEY_VALIDATION_REQUESTS_PER_TX, GENERATOR_INDEX__NSK_M, MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NULLIFIER_READ_REQUESTS_PER_TX }, grumpkin_private_key::GrumpkinPrivateKey, hash::poseidon2_hash, traits::is_empty, @@ -24,14 +24,15 @@ struct PrivateValidationRequestProcessor { nullifier_read_request_hints: NullifierReadRequestHints, pending_nullifiers: [ScopedNullifier; MAX_NEW_NULLIFIERS_PER_TX], nullifier_tree_root: Field, - master_nullifier_secret_keys: [GrumpkinPrivateKey; MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX], + master_secret_keys: [GrumpkinPrivateKey; MAX_KEY_VALIDATION_REQUESTS_PER_TX], + app_secret_keys_generators: [Field; MAX_KEY_VALIDATION_REQUESTS_PER_TX], } impl PrivateValidationRequestProcessor { pub fn validate(self) -> ValidationRequests { let remaining_note_hash_read_requests = self.validate_note_hash_read_requests(); let remaining_nullifier_read_requests = self.validate_nullifier_read_requests(); - let remaining_nullifier_key_validation_requests = self.validate_nullifier_keys(); + let remaining_key_validation_requests = self.validate_nullifier_keys(); ValidationRequests { for_rollup: self.validation_requests.for_rollup, @@ -39,7 +40,7 @@ impl PrivateValidationRequestProcessor { public_data_reads: self.validation_requests.public_data_reads, note_hash_read_requests: remaining_note_hash_read_requests.storage, nullifier_read_requests: remaining_nullifier_read_requests.storage, - nullifier_key_validation_requests: remaining_nullifier_key_validation_requests.storage + key_validation_requests: remaining_key_validation_requests.storage } } @@ -65,14 +66,14 @@ impl PrivateValidationRequestProcessor { ) } - fn validate_nullifier_keys(self) -> BoundedVec { - let mut should_propagate = [false; MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX]; - let requests = self.validation_requests.nullifier_key_validation_requests; - for i in 0..MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX { + fn validate_nullifier_keys(self) -> BoundedVec { + let mut should_propagate = [false; MAX_KEY_VALIDATION_REQUESTS_PER_TX]; + let requests = self.validation_requests.key_validation_requests; + for i in 0..MAX_KEY_VALIDATION_REQUESTS_PER_TX { let request = requests[i].request; if !is_empty(request) { let contract_address = requests[i].contract_address; - let master_nullifier_secret_key = self.master_nullifier_secret_keys[i]; + let master_nullifier_secret_key = self.master_secret_keys[i]; if !is_empty(master_nullifier_secret_key) { // First we check that derived public key matches master nullifier public key from request let master_nullifier_public_key = master_nullifier_secret_key.derive_public_key(); @@ -84,7 +85,7 @@ impl PrivateValidationRequestProcessor { let app_nullifier_secret_key = poseidon2_hash( [ - master_nullifier_secret_key.high, master_nullifier_secret_key.low, contract_address.to_field(), GENERATOR_INDEX__NSK_M + master_nullifier_secret_key.high, master_nullifier_secret_key.low, contract_address.to_field(), self.app_secret_keys_generators[i] ] ); assert( diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr index 849e0c82b47f..2fdabd567f33 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/private_circuit_public_inputs.nr @@ -6,11 +6,11 @@ use crate::{ }, constants::{ MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, MAX_NULLIFIER_READ_REQUESTS_PER_CALL, - MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL, MAX_NEW_NOTE_HASHES_PER_CALL, - MAX_NEW_NULLIFIERS_PER_CALL, MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, - MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, MAX_NEW_L2_TO_L1_MSGS_PER_CALL, - PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH, GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS, - MAX_ENCRYPTED_LOGS_PER_CALL, MAX_UNENCRYPTED_LOGS_PER_CALL, MAX_NOTE_ENCRYPTED_LOGS_PER_CALL + MAX_KEY_VALIDATION_REQUESTS_PER_CALL, MAX_NEW_NOTE_HASHES_PER_CALL, MAX_NEW_NULLIFIERS_PER_CALL, + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, + MAX_NEW_L2_TO_L1_MSGS_PER_CALL, PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH, + GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS, MAX_ENCRYPTED_LOGS_PER_CALL, + MAX_UNENCRYPTED_LOGS_PER_CALL, MAX_NOTE_ENCRYPTED_LOGS_PER_CALL }, header::Header, hash::pedersen_hash, messaging::l2_to_l1_message::L2ToL1Message, traits::{Deserialize, Hash, Serialize, Empty}, utils::reader::Reader, @@ -30,7 +30,7 @@ struct PrivateCircuitPublicInputs { note_hash_read_requests: [ReadRequest; MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], nullifier_read_requests: [ReadRequest; MAX_NULLIFIER_READ_REQUESTS_PER_CALL], - nullifier_key_validation_requests: [NullifierKeyValidationRequest; MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL], + key_validation_requests: [NullifierKeyValidationRequest; MAX_KEY_VALIDATION_REQUESTS_PER_CALL], new_note_hashes: [NoteHash; MAX_NEW_NOTE_HASHES_PER_CALL], new_nullifiers: [Nullifier; MAX_NEW_NULLIFIERS_PER_CALL], @@ -69,7 +69,7 @@ impl Eq for PrivateCircuitPublicInputs { (self.max_block_number == other.max_block_number) & (self.note_hash_read_requests == other.note_hash_read_requests) & (self.nullifier_read_requests == other.nullifier_read_requests) & - (self.nullifier_key_validation_requests == other.nullifier_key_validation_requests) & + (self.key_validation_requests == other.key_validation_requests) & (self.new_note_hashes == other.new_note_hashes) & (self.new_nullifiers == other.new_nullifiers) & (self.private_call_stack_hashes == other.private_call_stack_hashes) & @@ -105,8 +105,8 @@ impl Serialize for PrivateCircuitPublicInp for i in 0..self.nullifier_read_requests.len() { fields.extend_from_array(self.nullifier_read_requests[i].serialize()); } - for i in 0..self.nullifier_key_validation_requests.len() { - fields.extend_from_array(self.nullifier_key_validation_requests[i].serialize()); + for i in 0..self.key_validation_requests.len() { + fields.extend_from_array(self.key_validation_requests[i].serialize()); } for i in 0..self.new_note_hashes.len() { fields.extend_from_array(self.new_note_hashes[i].serialize()); @@ -155,7 +155,7 @@ impl Deserialize for PrivateCircuitPublicI max_block_number: reader.read_struct(MaxBlockNumber::deserialize), note_hash_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL]), nullifier_read_requests: reader.read_struct_array(ReadRequest::deserialize, [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL]), - nullifier_key_validation_requests: reader.read_struct_array(NullifierKeyValidationRequest::deserialize, [NullifierKeyValidationRequest::empty(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL]), + key_validation_requests: reader.read_struct_array(NullifierKeyValidationRequest::deserialize, [NullifierKeyValidationRequest::empty(); MAX_KEY_VALIDATION_REQUESTS_PER_CALL]), new_note_hashes: reader.read_struct_array(NoteHash::deserialize, [NoteHash::empty(); MAX_NEW_NOTE_HASHES_PER_CALL]), new_nullifiers: reader.read_struct_array(Nullifier::deserialize, [Nullifier::empty(); MAX_NEW_NULLIFIERS_PER_CALL]), private_call_stack_hashes: reader.read_array([0; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL]), @@ -195,7 +195,7 @@ impl Empty for PrivateCircuitPublicInputs { max_block_number: MaxBlockNumber::empty(), note_hash_read_requests: [ReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_CALL], nullifier_read_requests: [ReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_CALL], - nullifier_key_validation_requests: [NullifierKeyValidationRequest::empty(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL], + key_validation_requests: [NullifierKeyValidationRequest::empty(); MAX_KEY_VALIDATION_REQUESTS_PER_CALL], new_note_hashes: [NoteHash::empty(); MAX_NEW_NOTE_HASHES_PER_CALL], new_nullifiers: [Nullifier::empty(); MAX_NEW_NULLIFIERS_PER_CALL], private_call_stack_hashes: [0; MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL], diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests.nr index 2cc7fabdb0c8..c1f340ec337e 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests.nr @@ -7,7 +7,7 @@ use crate::{ }, constants::{ MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NULLIFIER_READ_REQUESTS_PER_TX, - MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, + MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, MAX_KEY_VALIDATION_REQUESTS_PER_TX, MAX_PUBLIC_DATA_READS_PER_TX, VALIDATION_REQUESTS_LENGTH }, traits::{Serialize, Deserialize, Empty}, utils::reader::Reader @@ -19,7 +19,7 @@ struct ValidationRequests { note_hash_read_requests: [ScopedReadRequest; MAX_NOTE_HASH_READ_REQUESTS_PER_TX], nullifier_read_requests: [ScopedReadRequest; MAX_NULLIFIER_READ_REQUESTS_PER_TX], nullifier_non_existent_read_requests: [ScopedReadRequest; MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX], - nullifier_key_validation_requests: [ScopedNullifierKeyValidationRequest; MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX], + key_validation_requests: [ScopedNullifierKeyValidationRequest; MAX_KEY_VALIDATION_REQUESTS_PER_TX], public_data_reads: [PublicDataRead; MAX_PUBLIC_DATA_READS_PER_TX], } @@ -41,8 +41,8 @@ impl Serialize for ValidationRequests { fields.extend_from_array(self.nullifier_non_existent_read_requests[i].serialize()); } - for i in 0..MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX { - fields.extend_from_array(self.nullifier_key_validation_requests[i].serialize()); + for i in 0..MAX_KEY_VALIDATION_REQUESTS_PER_TX { + fields.extend_from_array(self.key_validation_requests[i].serialize()); } for i in 0..MAX_PUBLIC_DATA_READS_PER_TX { @@ -64,7 +64,7 @@ impl Deserialize for ValidationRequests { note_hash_read_requests: reader.read_struct_array(ScopedReadRequest::deserialize, [ScopedReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_TX]), nullifier_read_requests: reader.read_struct_array(ScopedReadRequest::deserialize, [ScopedReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_TX]), nullifier_non_existent_read_requests: reader.read_struct_array(ScopedReadRequest::deserialize, [ScopedReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX]), - nullifier_key_validation_requests: reader.read_struct_array(ScopedNullifierKeyValidationRequest::deserialize, [ScopedNullifierKeyValidationRequest::empty(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX]), + key_validation_requests: reader.read_struct_array(ScopedNullifierKeyValidationRequest::deserialize, [ScopedNullifierKeyValidationRequest::empty(); MAX_KEY_VALIDATION_REQUESTS_PER_TX]), public_data_reads: reader.read_struct_array(PublicDataRead::deserialize, [PublicDataRead::empty(); MAX_PUBLIC_DATA_READS_PER_TX]), }; @@ -81,7 +81,7 @@ impl Empty for ValidationRequests { note_hash_read_requests: [ScopedReadRequest::empty(); MAX_NOTE_HASH_READ_REQUESTS_PER_TX], nullifier_read_requests: [ScopedReadRequest::empty(); MAX_NULLIFIER_READ_REQUESTS_PER_TX], nullifier_non_existent_read_requests: [ScopedReadRequest::empty(); MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX], - nullifier_key_validation_requests: [ScopedNullifierKeyValidationRequest::empty(); MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX], + key_validation_requests: [ScopedNullifierKeyValidationRequest::empty(); MAX_KEY_VALIDATION_REQUESTS_PER_TX], public_data_reads: [PublicDataRead::empty(); MAX_PUBLIC_DATA_READS_PER_TX], } } @@ -93,7 +93,7 @@ impl Eq for ValidationRequests { (self.note_hash_read_requests == other.note_hash_read_requests) & (self.nullifier_read_requests == other.nullifier_read_requests) & (self.nullifier_non_existent_read_requests == other.nullifier_non_existent_read_requests) & - (self.nullifier_key_validation_requests == other.nullifier_key_validation_requests) & + (self.key_validation_requests == other.key_validation_requests) & (self.public_data_reads == other.public_data_reads) } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr index 6fe9d71310a9..c382163eea00 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/abis/validation_requests/validation_requests_builder.nr @@ -8,7 +8,7 @@ use crate::{ }, constants::{ MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NULLIFIER_READ_REQUESTS_PER_TX, - MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, + MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, MAX_KEY_VALIDATION_REQUESTS_PER_TX, MAX_PUBLIC_DATA_READS_PER_TX }, traits::Empty @@ -19,7 +19,7 @@ struct ValidationRequestsBuilder { note_hash_read_requests: BoundedVec, nullifier_read_requests: BoundedVec, nullifier_non_existent_read_requests: BoundedVec, - nullifier_key_validation_requests: BoundedVec, + key_validation_requests: BoundedVec, public_data_reads: BoundedVec, } @@ -30,7 +30,7 @@ impl ValidationRequestsBuilder { note_hash_read_requests: self.note_hash_read_requests.storage, nullifier_read_requests: self.nullifier_read_requests.storage, nullifier_non_existent_read_requests: self.nullifier_non_existent_read_requests.storage, - nullifier_key_validation_requests: self.nullifier_key_validation_requests.storage, + key_validation_requests: self.key_validation_requests.storage, public_data_reads: self.public_data_reads.storage } } @@ -47,7 +47,7 @@ impl Empty for ValidationRequestsBuilder { note_hash_read_requests: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), nullifier_non_existent_read_requests: BoundedVec::new(), - nullifier_key_validation_requests: BoundedVec::new(), + key_validation_requests: BoundedVec::new(), public_data_reads: BoundedVec::new(), } } diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr index a39b851d2231..524fb66674a1 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/constants.nr @@ -32,7 +32,7 @@ global MAX_PUBLIC_DATA_READS_PER_CALL: u64 = 16; global MAX_NOTE_HASH_READ_REQUESTS_PER_CALL: u64 = 32; global MAX_NULLIFIER_READ_REQUESTS_PER_CALL: u64 = 2; // Change it to a larger value when there's a seperate reset circuit. global MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL: u64 = 2; -global MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL: u64 = 16; +global MAX_KEY_VALIDATION_REQUESTS_PER_CALL: u64 = 16; global MAX_NOTE_ENCRYPTED_LOGS_PER_CALL: u64 = 16; global MAX_ENCRYPTED_LOGS_PER_CALL: u64 = 4; // If modifying, update DEPLOYER_CONTRACT_ADDRESS. global MAX_UNENCRYPTED_LOGS_PER_CALL: u64 = 4; // If modifying, update DEPLOYER_CONTRACT_ADDRESS. @@ -48,7 +48,7 @@ global MAX_NEW_L2_TO_L1_MSGS_PER_TX: u64 = 2; global MAX_NOTE_HASH_READ_REQUESTS_PER_TX: u64 = 128; global MAX_NULLIFIER_READ_REQUESTS_PER_TX: u64 = 8; // Change it to a larger value when there's a seperate reset circuit. global MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX: u64 = 8; -global MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX: u64 = 64; +global MAX_KEY_VALIDATION_REQUESTS_PER_TX: u64 = 64; global MAX_NOTE_ENCRYPTED_LOGS_PER_TX: u64 = 64; global MAX_ENCRYPTED_LOGS_PER_TX: u64 = 8; global MAX_UNENCRYPTED_LOGS_PER_TX: u64 = 8; @@ -176,14 +176,14 @@ global STATE_REFERENCE_LENGTH: u64 = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + PARTIAL_ global TX_CONTEXT_LENGTH: u64 = 2 + GAS_SETTINGS_LENGTH; global TX_REQUEST_LENGTH: u64 = 2 + TX_CONTEXT_LENGTH + FUNCTION_DATA_LENGTH; global HEADER_LENGTH: u64 = APPEND_ONLY_TREE_SNAPSHOT_LENGTH + CONTENT_COMMITMENT_LENGTH + STATE_REFERENCE_LENGTH + GLOBAL_VARIABLES_LENGTH; -global PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH: u64 = CALL_CONTEXT_LENGTH + 4 + MAX_BLOCK_NUMBER_LENGTH + (READ_REQUEST_LENGTH * MAX_NOTE_HASH_READ_REQUESTS_PER_CALL) + (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL) + (NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL) + (NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + (NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL) + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + 1 + (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 + (NOTE_LOG_HASH_LENGTH * MAX_NOTE_ENCRYPTED_LOGS_PER_CALL) + (LOG_HASH_LENGTH * MAX_ENCRYPTED_LOGS_PER_CALL) + (LOG_HASH_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 2 + HEADER_LENGTH + TX_CONTEXT_LENGTH; +global PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH: u64 = CALL_CONTEXT_LENGTH + 4 + MAX_BLOCK_NUMBER_LENGTH + (READ_REQUEST_LENGTH * MAX_NOTE_HASH_READ_REQUESTS_PER_CALL) + (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL) + (NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_KEY_VALIDATION_REQUESTS_PER_CALL) + (NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + (NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL) + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + 1 + (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 + (NOTE_LOG_HASH_LENGTH * MAX_NOTE_ENCRYPTED_LOGS_PER_CALL) + (LOG_HASH_LENGTH * MAX_ENCRYPTED_LOGS_PER_CALL) + (LOG_HASH_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 2 + HEADER_LENGTH + TX_CONTEXT_LENGTH; global PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH: u64 = CALL_CONTEXT_LENGTH + 2 + (READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL) + (READ_REQUEST_LENGTH * MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL) + (CONTRACT_STORAGE_UPDATE_REQUEST_LENGTH * MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL) + (CONTRACT_STORAGE_READ_LENGTH * MAX_PUBLIC_DATA_READS_PER_CALL) + MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL + (NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL) + (NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL) + (L2_TO_L1_MESSAGE_LENGTH * MAX_NEW_L2_TO_L1_MSGS_PER_CALL) + 2 + (LOG_HASH_LENGTH * MAX_UNENCRYPTED_LOGS_PER_CALL) + 1 + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + AZTEC_ADDRESS_LENGTH + /* revert_code */ 1 + 2 * GAS_LENGTH + /* transaction_fee */ 1; global PRIVATE_CALL_STACK_ITEM_LENGTH: u64 = AZTEC_ADDRESS_LENGTH + FUNCTION_DATA_LENGTH + PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH; global PUBLIC_CONTEXT_INPUTS_LENGTH: u64 = CALL_CONTEXT_LENGTH + HEADER_LENGTH + GLOBAL_VARIABLES_LENGTH + GAS_LENGTH + 2; global SCOPED_READ_REQUEST_LEN = READ_REQUEST_LENGTH + 1; global PUBLIC_DATA_READ_LENGTH = 2; -global VALIDATION_REQUESTS_LENGTH = ROLLUP_VALIDATION_REQUESTS_LENGTH + (SCOPED_READ_REQUEST_LEN * MAX_NOTE_HASH_READ_REQUESTS_PER_TX) + (SCOPED_READ_REQUEST_LEN * MAX_NULLIFIER_READ_REQUESTS_PER_TX) + (SCOPED_READ_REQUEST_LEN * MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX) + (SCOPED_NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX) + (PUBLIC_DATA_READ_LENGTH * MAX_PUBLIC_DATA_READS_PER_TX); +global VALIDATION_REQUESTS_LENGTH = ROLLUP_VALIDATION_REQUESTS_LENGTH + (SCOPED_READ_REQUEST_LEN * MAX_NOTE_HASH_READ_REQUESTS_PER_TX) + (SCOPED_READ_REQUEST_LEN * MAX_NULLIFIER_READ_REQUESTS_PER_TX) + (SCOPED_READ_REQUEST_LEN * MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX) + (SCOPED_NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_KEY_VALIDATION_REQUESTS_PER_TX) + (PUBLIC_DATA_READ_LENGTH * MAX_PUBLIC_DATA_READS_PER_TX); global PUBLIC_DATA_UPDATE_REQUEST_LENGTH = 2; global COMBINED_ACCUMULATED_DATA_LENGTH = MAX_NEW_NOTE_HASHES_PER_TX + MAX_NEW_NULLIFIERS_PER_TX + MAX_NEW_L2_TO_L1_MSGS_PER_TX + 5 + (MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX * PUBLIC_DATA_UPDATE_REQUEST_LENGTH) + GAS_LENGTH; diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr index c27429ffbf2d..acba1925c014 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/fixture_builder.nr @@ -19,9 +19,8 @@ use crate::{ MAX_PUBLIC_DATA_READS_PER_TX, MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, MAX_PUBLIC_CALL_STACK_LENGTH_PER_TX, MAX_NOTE_HASH_READ_REQUESTS_PER_TX, MAX_NULLIFIER_READ_REQUESTS_PER_TX, - MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, - VK_TREE_HEIGHT, MAX_ENCRYPTED_LOGS_PER_TX, MAX_UNENCRYPTED_LOGS_PER_TX, - MAX_NOTE_ENCRYPTED_LOGS_PER_TX + MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, MAX_KEY_VALIDATION_REQUESTS_PER_TX, VK_TREE_HEIGHT, + MAX_ENCRYPTED_LOGS_PER_TX, MAX_UNENCRYPTED_LOGS_PER_TX, MAX_NOTE_ENCRYPTED_LOGS_PER_TX }, hash::silo_nullifier, header::Header, messaging::l2_to_l1_message::{L2ToL1Message, ScopedL2ToL1Message}, @@ -64,7 +63,7 @@ struct FixtureBuilder { note_hash_read_requests: BoundedVec, nullifier_read_requests: BoundedVec, nullifier_non_existent_read_requests: BoundedVec, - nullifier_key_validation_requests: BoundedVec, + key_validation_requests: BoundedVec, public_data_reads: BoundedVec, // Proof. @@ -110,7 +109,7 @@ impl FixtureBuilder { note_hash_read_requests: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), nullifier_non_existent_read_requests: BoundedVec::new(), - nullifier_key_validation_requests: BoundedVec::new(), + key_validation_requests: BoundedVec::new(), public_data_reads: BoundedVec::new(), proof: NestedRecursiveProof::empty(), vk: VerificationKey::empty(), @@ -188,7 +187,7 @@ impl FixtureBuilder { note_hash_read_requests: self.note_hash_read_requests, nullifier_read_requests: self.nullifier_read_requests, nullifier_non_existent_read_requests: self.nullifier_non_existent_read_requests, - nullifier_key_validation_requests: self.nullifier_key_validation_requests, + key_validation_requests: self.key_validation_requests, public_data_reads: self.public_data_reads }; validation_requests.finish() @@ -420,9 +419,9 @@ impl FixtureBuilder { master_nullifier_public_key: GrumpkinPoint, app_nullifier_secret_key: Field ) -> u64 { - let new_request_index = self.nullifier_key_validation_requests.len(); + let new_request_index = self.key_validation_requests.len(); let request = NullifierKeyValidationRequest { master_nullifier_public_key, app_nullifier_secret_key }; - self.nullifier_key_validation_requests.push(request.scope(self.storage_contract_address)); + self.key_validation_requests.push(request.scope(self.storage_contract_address)); new_request_index } @@ -542,7 +541,7 @@ impl Empty for FixtureBuilder { note_hash_read_requests: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), nullifier_non_existent_read_requests: BoundedVec::new(), - nullifier_key_validation_requests: BoundedVec::new(), + key_validation_requests: BoundedVec::new(), public_data_reads: BoundedVec::new(), proof: NestedRecursiveProof::empty(), vk: VerificationKey::empty(), diff --git a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr index edcab97af367..e2e565152f71 100644 --- a/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr +++ b/noir-projects/noir-protocol-circuits/crates/types/src/tests/private_circuit_public_inputs_builder.nr @@ -12,10 +12,10 @@ use crate::{ use crate::{ constants::{ MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, MAX_NULLIFIER_READ_REQUESTS_PER_CALL, - MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL, MAX_NEW_NOTE_HASHES_PER_CALL, - MAX_NEW_NULLIFIERS_PER_CALL, MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, - MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, MAX_NEW_L2_TO_L1_MSGS_PER_CALL, MAX_ENCRYPTED_LOGS_PER_CALL, - MAX_UNENCRYPTED_LOGS_PER_CALL, MAX_NOTE_ENCRYPTED_LOGS_PER_CALL + MAX_KEY_VALIDATION_REQUESTS_PER_CALL, MAX_NEW_NOTE_HASHES_PER_CALL, MAX_NEW_NULLIFIERS_PER_CALL, + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, + MAX_NEW_L2_TO_L1_MSGS_PER_CALL, MAX_ENCRYPTED_LOGS_PER_CALL, MAX_UNENCRYPTED_LOGS_PER_CALL, + MAX_NOTE_ENCRYPTED_LOGS_PER_CALL }, traits::Empty }; @@ -34,7 +34,7 @@ struct PrivateCircuitPublicInputsBuilder { note_hash_read_requests: BoundedVec, nullifier_read_requests: BoundedVec, - nullifier_key_validation_requests: BoundedVec, + key_validation_requests: BoundedVec, new_note_hashes: BoundedVec, new_nullifiers: BoundedVec, @@ -208,7 +208,7 @@ impl PrivateCircuitPublicInputsBuilder { max_block_number: self.max_block_number, note_hash_read_requests: self.note_hash_read_requests.storage, nullifier_read_requests: self.nullifier_read_requests.storage, - nullifier_key_validation_requests: self.nullifier_key_validation_requests.storage, + key_validation_requests: self.key_validation_requests.storage, new_note_hashes: self.new_note_hashes.storage, new_nullifiers: self.new_nullifiers.storage, private_call_stack_hashes: self.private_call_stack_hashes.storage, @@ -246,7 +246,7 @@ impl Empty for PrivateCircuitPublicInputsBuilder { max_block_number: MaxBlockNumber::empty(), note_hash_read_requests: BoundedVec::new(), nullifier_read_requests: BoundedVec::new(), - nullifier_key_validation_requests: BoundedVec::new(), + key_validation_requests: BoundedVec::new(), new_note_hashes: BoundedVec::new(), new_nullifiers: BoundedVec::new(), private_call_stack_hashes: BoundedVec::new(), diff --git a/yarn-project/circuits.js/src/constants.gen.ts b/yarn-project/circuits.js/src/constants.gen.ts index 563f1b3cb40d..5fba2c559ced 100644 --- a/yarn-project/circuits.js/src/constants.gen.ts +++ b/yarn-project/circuits.js/src/constants.gen.ts @@ -11,7 +11,7 @@ export const MAX_PUBLIC_DATA_READS_PER_CALL = 16; export const MAX_NOTE_HASH_READ_REQUESTS_PER_CALL = 32; export const MAX_NULLIFIER_READ_REQUESTS_PER_CALL = 2; export const MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL = 2; -export const MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL = 16; +export const MAX_KEY_VALIDATION_REQUESTS_PER_CALL = 16; export const MAX_NOTE_ENCRYPTED_LOGS_PER_CALL = 16; export const MAX_ENCRYPTED_LOGS_PER_CALL = 4; export const MAX_UNENCRYPTED_LOGS_PER_CALL = 4; @@ -25,7 +25,7 @@ export const MAX_NEW_L2_TO_L1_MSGS_PER_TX = 2; export const MAX_NOTE_HASH_READ_REQUESTS_PER_TX = 128; export const MAX_NULLIFIER_READ_REQUESTS_PER_TX = 8; export const MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX = 8; -export const MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX = 64; +export const MAX_KEY_VALIDATION_REQUESTS_PER_TX = 64; export const MAX_NOTE_ENCRYPTED_LOGS_PER_TX = 64; export const MAX_ENCRYPTED_LOGS_PER_TX = 8; export const MAX_UNENCRYPTED_LOGS_PER_TX = 8; @@ -126,7 +126,7 @@ export const PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH = MAX_BLOCK_NUMBER_LENGTH + READ_REQUEST_LENGTH * MAX_NOTE_HASH_READ_REQUESTS_PER_CALL + READ_REQUEST_LENGTH * MAX_NULLIFIER_READ_REQUESTS_PER_CALL + - NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL + + NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_KEY_VALIDATION_REQUESTS_PER_CALL + NOTE_HASH_LENGTH * MAX_NEW_NOTE_HASHES_PER_CALL + NULLIFIER_LENGTH * MAX_NEW_NULLIFIERS_PER_CALL + MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL + @@ -171,7 +171,7 @@ export const VALIDATION_REQUESTS_LENGTH = SCOPED_READ_REQUEST_LEN * MAX_NOTE_HASH_READ_REQUESTS_PER_TX + SCOPED_READ_REQUEST_LEN * MAX_NULLIFIER_READ_REQUESTS_PER_TX + SCOPED_READ_REQUEST_LEN * MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX + - SCOPED_NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX + + SCOPED_NULLIFIER_KEY_VALIDATION_REQUEST_LENGTH * MAX_KEY_VALIDATION_REQUESTS_PER_TX + PUBLIC_DATA_READ_LENGTH * MAX_PUBLIC_DATA_READS_PER_TX; export const PUBLIC_DATA_UPDATE_REQUEST_LENGTH = 2; export const COMBINED_ACCUMULATED_DATA_LENGTH = diff --git a/yarn-project/circuits.js/src/structs/kernel/private_kernel_reset_circuit_private_inputs.ts b/yarn-project/circuits.js/src/structs/kernel/private_kernel_reset_circuit_private_inputs.ts index 980af10d329d..06859c109e98 100644 --- a/yarn-project/circuits.js/src/structs/kernel/private_kernel_reset_circuit_private_inputs.ts +++ b/yarn-project/circuits.js/src/structs/kernel/private_kernel_reset_circuit_private_inputs.ts @@ -2,10 +2,10 @@ import { GrumpkinScalar } from '@aztec/foundation/fields'; import { BufferReader, type Tuple, serializeToBuffer } from '@aztec/foundation/serialize'; import { + MAX_KEY_VALIDATION_REQUESTS_PER_TX, MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_NOTE_ENCRYPTED_LOGS_PER_TX, - MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, } from '../../constants.gen.js'; import { type GrumpkinPrivateKey } from '../../types/grumpkin_private_key.js'; import { countAccumulatedItems } from '../../utils/index.js'; @@ -67,7 +67,7 @@ export class PrivateKernelResetHints { /** * The master nullifier secret keys for the nullifier key validation requests. */ - public masterNullifierSecretKeys: Tuple, + public masterNullifierSecretKeys: Tuple, ) {} toBuffer() { @@ -94,7 +94,7 @@ export class PrivateKernelResetHints { reader.readNumbers(MAX_NOTE_ENCRYPTED_LOGS_PER_TX), reader.readObject({ fromBuffer: noteHashReadRequestHintsFromBuffer }), reader.readObject({ fromBuffer: nullifierReadRequestHintsFromBuffer }), - reader.readArray(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, GrumpkinScalar), + reader.readArray(MAX_KEY_VALIDATION_REQUESTS_PER_TX, GrumpkinScalar), ); } } diff --git a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts index 7eae5eedb781..ca65fa15f945 100644 --- a/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts +++ b/yarn-project/circuits.js/src/structs/private_circuit_public_inputs.ts @@ -14,12 +14,12 @@ import { type FieldsOf } from '@aztec/foundation/types'; import { GeneratorIndex, MAX_ENCRYPTED_LOGS_PER_CALL, + MAX_KEY_VALIDATION_REQUESTS_PER_CALL, MAX_NEW_L2_TO_L1_MSGS_PER_CALL, MAX_NEW_NOTE_HASHES_PER_CALL, MAX_NEW_NULLIFIERS_PER_CALL, MAX_NOTE_ENCRYPTED_LOGS_PER_CALL, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, - MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL, MAX_NULLIFIER_READ_REQUESTS_PER_CALL, MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, @@ -80,7 +80,7 @@ export class PrivateCircuitPublicInputs { */ public nullifierKeyValidationRequests: Tuple< NullifierKeyValidationRequest, - typeof MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL + typeof MAX_KEY_VALIDATION_REQUESTS_PER_CALL >, /** * New note hashes created by the corresponding function call. @@ -178,7 +178,7 @@ export class PrivateCircuitPublicInputs { reader.readObject(MaxBlockNumber), reader.readArray(MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, ReadRequest), reader.readArray(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, ReadRequest), - reader.readArray(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL, NullifierKeyValidationRequest), + reader.readArray(MAX_KEY_VALIDATION_REQUESTS_PER_CALL, NullifierKeyValidationRequest), reader.readArray(MAX_NEW_NOTE_HASHES_PER_CALL, NoteHash), reader.readArray(MAX_NEW_NULLIFIERS_PER_CALL, Nullifier), reader.readArray(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, Fr), @@ -208,7 +208,7 @@ export class PrivateCircuitPublicInputs { reader.readObject(MaxBlockNumber), reader.readArray(MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, ReadRequest), reader.readArray(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, ReadRequest), - reader.readArray(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL, NullifierKeyValidationRequest), + reader.readArray(MAX_KEY_VALIDATION_REQUESTS_PER_CALL, NullifierKeyValidationRequest), reader.readArray(MAX_NEW_NOTE_HASHES_PER_CALL, NoteHash), reader.readArray(MAX_NEW_NULLIFIERS_PER_CALL, Nullifier), reader.readFieldArray(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL), @@ -241,7 +241,7 @@ export class PrivateCircuitPublicInputs { MaxBlockNumber.empty(), makeTuple(MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, ReadRequest.empty), makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, ReadRequest.empty), - makeTuple(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL, NullifierKeyValidationRequest.empty), + makeTuple(MAX_KEY_VALIDATION_REQUESTS_PER_CALL, NullifierKeyValidationRequest.empty), makeTuple(MAX_NEW_NOTE_HASHES_PER_CALL, NoteHash.empty), makeTuple(MAX_NEW_NULLIFIERS_PER_CALL, Nullifier.empty), makeTuple(MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, Fr.zero), diff --git a/yarn-project/circuits.js/src/structs/validation_requests.ts b/yarn-project/circuits.js/src/structs/validation_requests.ts index 6d33a5b5865a..8caa42a4ff68 100644 --- a/yarn-project/circuits.js/src/structs/validation_requests.ts +++ b/yarn-project/circuits.js/src/structs/validation_requests.ts @@ -4,8 +4,8 @@ import { BufferReader, type Tuple, serializeToBuffer } from '@aztec/foundation/s import { inspect } from 'util'; import { + MAX_KEY_VALIDATION_REQUESTS_PER_TX, MAX_NOTE_HASH_READ_REQUESTS_PER_TX, - MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, MAX_NULLIFIER_READ_REQUESTS_PER_TX, MAX_PUBLIC_DATA_READS_PER_TX, @@ -45,7 +45,7 @@ export class ValidationRequests { */ public nullifierKeyValidationRequests: Tuple< ScopedNullifierKeyValidationRequest, - typeof MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX + typeof MAX_KEY_VALIDATION_REQUESTS_PER_TX >, /** * All the public data reads made in this transaction. @@ -80,7 +80,7 @@ export class ValidationRequests { reader.readArray(MAX_NOTE_HASH_READ_REQUESTS_PER_TX, ScopedReadRequest), reader.readArray(MAX_NULLIFIER_READ_REQUESTS_PER_TX, ScopedReadRequest), reader.readArray(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, ScopedReadRequest), - reader.readArray(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, ScopedNullifierKeyValidationRequest), + reader.readArray(MAX_KEY_VALIDATION_REQUESTS_PER_TX, ScopedNullifierKeyValidationRequest), reader.readArray(MAX_PUBLIC_DATA_READS_PER_TX, PublicDataRead), ); } @@ -100,7 +100,7 @@ export class ValidationRequests { makeTuple(MAX_NOTE_HASH_READ_REQUESTS_PER_TX, ScopedReadRequest.empty), makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_TX, ScopedReadRequest.empty), makeTuple(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, ScopedReadRequest.empty), - makeTuple(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, ScopedNullifierKeyValidationRequest.empty), + makeTuple(MAX_KEY_VALIDATION_REQUESTS_PER_TX, ScopedNullifierKeyValidationRequest.empty), makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, PublicDataRead.empty), ); } diff --git a/yarn-project/circuits.js/src/tests/factories.ts b/yarn-project/circuits.js/src/tests/factories.ts index 49ccb6738b4e..4a38ecc04b9f 100644 --- a/yarn-project/circuits.js/src/tests/factories.ts +++ b/yarn-project/circuits.js/src/tests/factories.ts @@ -40,6 +40,8 @@ import { LogHash, MAX_ENCRYPTED_LOGS_PER_CALL, MAX_ENCRYPTED_LOGS_PER_TX, + MAX_KEY_VALIDATION_REQUESTS_PER_CALL, + MAX_KEY_VALIDATION_REQUESTS_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_CALL, MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_NEW_NOTE_HASHES_PER_CALL, @@ -50,8 +52,6 @@ import { MAX_NOTE_ENCRYPTED_LOGS_PER_TX, MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, MAX_NOTE_HASH_READ_REQUESTS_PER_TX, - MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL, - MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL, MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, MAX_NULLIFIER_READ_REQUESTS_PER_CALL, @@ -280,7 +280,7 @@ export function makeValidationRequests(seed = 1) { makeTuple(MAX_NOTE_HASH_READ_REQUESTS_PER_TX, makeScopedReadRequest, seed + 0x80), makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_TX, makeScopedReadRequest, seed + 0x90), makeTuple(MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, makeScopedReadRequest, seed + 0x95), - makeTuple(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, makeScopedNullifierKeyValidationRequest, seed + 0x100), + makeTuple(MAX_KEY_VALIDATION_REQUESTS_PER_TX, makeScopedNullifierKeyValidationRequest, seed + 0x100), makeTuple(MAX_PUBLIC_DATA_READS_PER_TX, makePublicDataRead, seed + 0xe00), ); } @@ -782,7 +782,7 @@ export function makePrivateCircuitPublicInputs(seed = 0): PrivateCircuitPublicIn noteHashReadRequests: makeTuple(MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, makeReadRequest, seed + 0x300), nullifierReadRequests: makeTuple(MAX_NULLIFIER_READ_REQUESTS_PER_CALL, makeReadRequest, seed + 0x310), nullifierKeyValidationRequests: makeTuple( - MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL, + MAX_KEY_VALIDATION_REQUESTS_PER_CALL, makeNullifierKeyValidationRequest, seed + 0x320, ), diff --git a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts index 750d1909db5c..3cb8c34f2db2 100644 --- a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts +++ b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts @@ -31,12 +31,12 @@ import { type LeafDataReadHint, LogHash, MAX_ENCRYPTED_LOGS_PER_TX, + MAX_KEY_VALIDATION_REQUESTS_PER_TX, MAX_NEW_L2_TO_L1_MSGS_PER_TX, MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_NOTE_ENCRYPTED_LOGS_PER_TX, MAX_NOTE_HASH_READ_REQUESTS_PER_TX, - MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_TX, MAX_NULLIFIER_READ_REQUESTS_PER_TX, MAX_PRIVATE_CALL_STACK_LENGTH_PER_TX, @@ -783,7 +783,7 @@ export function mapPrivateCircuitPublicInputsToNoir( returns_hash: mapFieldToNoir(privateCircuitPublicInputs.returnsHash), note_hash_read_requests: mapTuple(privateCircuitPublicInputs.noteHashReadRequests, mapReadRequestToNoir), nullifier_read_requests: mapTuple(privateCircuitPublicInputs.nullifierReadRequests, mapReadRequestToNoir), - nullifier_key_validation_requests: mapTuple( + key_validation_requests: mapTuple( privateCircuitPublicInputs.nullifierKeyValidationRequests, mapNullifierKeyValidationRequestToNoir, ), @@ -1039,7 +1039,7 @@ function mapValidationRequestsToNoir(requests: ValidationRequests): ValidationRe requests.nullifierNonExistentReadRequests, mapScopedReadRequestToNoir, ), - nullifier_key_validation_requests: mapTuple( + key_validation_requests: mapTuple( requests.nullifierKeyValidationRequests, mapScopedNullifierKeyValidationRequestToNoir, ), @@ -1066,8 +1066,8 @@ function mapValidationRequestsFromNoir(requests: ValidationRequestsNoir): Valida mapScopedReadRequestFromNoir, ), mapTupleFromNoir( - requests.nullifier_key_validation_requests, - MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, + requests.key_validation_requests, + MAX_KEY_VALIDATION_REQUESTS_PER_TX, mapScopedNullifierKeyValidationRequestFromNoir, ), mapTupleFromNoir(requests.public_data_reads, MAX_PUBLIC_DATA_READS_PER_TX, mapPublicDataReadFromNoir), @@ -1499,7 +1499,7 @@ function mapPrivateKernelResetHintsToNoir(inputs: PrivateKernelResetHints): Priv transient_note_hash_indexes_for_logs: mapTuple(inputs.transientNoteHashIndexesForLogs, mapNumberToNoir), note_hash_read_request_hints: mapNoteHashReadRequestHintsToNoir(inputs.noteHashReadRequestHints), nullifier_read_request_hints: mapNullifierReadRequestHintsToNoir(inputs.nullifierReadRequestHints), - master_nullifier_secret_keys: mapTuple(inputs.masterNullifierSecretKeys, mapGrumpkinPrivateKeyToNoir), + master_secret_keys: mapTuple(inputs.masterNullifierSecretKeys, mapGrumpkinPrivateKeyToNoir), }; } diff --git a/yarn-project/pxe/src/kernel_prover/private_inputs_builders/build_private_kernel_reset_hints.ts b/yarn-project/pxe/src/kernel_prover/private_inputs_builders/build_private_kernel_reset_hints.ts index 1449ceec2ac2..2d2af753a6f3 100644 --- a/yarn-project/pxe/src/kernel_prover/private_inputs_builders/build_private_kernel_reset_hints.ts +++ b/yarn-project/pxe/src/kernel_prover/private_inputs_builders/build_private_kernel_reset_hints.ts @@ -1,10 +1,10 @@ import { type Fr, GrumpkinScalar, + MAX_KEY_VALIDATION_REQUESTS_PER_TX, MAX_NEW_NOTE_HASHES_PER_TX, MAX_NEW_NULLIFIERS_PER_TX, MAX_NOTE_ENCRYPTED_LOGS_PER_TX, - MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, type MAX_NULLIFIER_READ_REQUESTS_PER_TX, MembershipWitness, NULLIFIER_TREE_HEIGHT, @@ -48,13 +48,10 @@ function getNullifierReadRequestHints( } async function getMasterNullifierSecretKeys( - nullifierKeyValidationRequests: Tuple< - ScopedNullifierKeyValidationRequest, - typeof MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX - >, + nullifierKeyValidationRequests: Tuple, oracle: ProvingDataOracle, ) { - const keys = makeTuple(MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_TX, GrumpkinScalar.zero); + const keys = makeTuple(MAX_KEY_VALIDATION_REQUESTS_PER_TX, GrumpkinScalar.zero); for (let i = 0; i < nullifierKeyValidationRequests.length; ++i) { const request = nullifierKeyValidationRequests[i].request; if (request.isEmpty()) { diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index 0aafc0509191..de383b85dcd6 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -37,7 +37,7 @@ export class SimulatorOracle implements DBOracle { private log = createDebugLogger('aztec:pxe:simulator_oracle'), ) {} - async getNullifierKeys(npkMHash: Fr, contractAddress: AztecAddress): Promise { + async getKeyValidationRequest(npkMHash: Fr, contractAddress: AztecAddress): Promise { const masterNullifierPublicKey = await this.keyStore.getMasterNullifierPublicKey(npkMHash); const appNullifierSecretKey = await this.keyStore.getAppNullifierSecretKey(npkMHash, contractAddress); return { masterNullifierPublicKey, appNullifierSecretKey }; diff --git a/yarn-project/simulator/src/acvm/oracle/oracle.ts b/yarn-project/simulator/src/acvm/oracle/oracle.ts index 9def84c9f12a..abc5c69c604f 100644 --- a/yarn-project/simulator/src/acvm/oracle/oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/oracle.ts @@ -40,8 +40,8 @@ export class Oracle { return unpacked.map(toACVMField); } - async getNullifierKeys([masterNullifierPublicKeyHash]: ACVMField[]): Promise { - const { masterNullifierPublicKey, appNullifierSecretKey } = await this.typedOracle.getNullifierKeys( + async getKeyValidationRequest([masterNullifierPublicKeyHash]: ACVMField[]): Promise { + const { masterNullifierPublicKey, appNullifierSecretKey } = await this.typedOracle.getKeyValidationRequest( fromACVMField(masterNullifierPublicKeyHash), ); diff --git a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts index 4a9100403849..32f70678e354 100644 --- a/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts +++ b/yarn-project/simulator/src/acvm/oracle/typed_oracle.ts @@ -89,8 +89,8 @@ export abstract class TypedOracle { throw new OracleMethodNotAvailableError('unpackReturns'); } - getNullifierKeys(_npkMHash: Fr): Promise { - throw new OracleMethodNotAvailableError('getNullifierKeys'); + getKeyValidationRequest(_npkMHash: Fr): Promise { + throw new OracleMethodNotAvailableError('getKeyValidationRequest'); } getContractInstance(_address: AztecAddress): Promise { diff --git a/yarn-project/simulator/src/client/db_oracle.ts b/yarn-project/simulator/src/client/db_oracle.ts index f36616c2303f..2f5a516c6629 100644 --- a/yarn-project/simulator/src/client/db_oracle.ts +++ b/yarn-project/simulator/src/client/db_oracle.ts @@ -71,7 +71,7 @@ export interface DBOracle extends CommitmentsDB { * @returns A Promise that resolves to nullifier keys. * @throws If the nullifier keys are not registered in the key store. */ - getNullifierKeys(npkMHash: Fr, contractAddress: AztecAddress): Promise; + getKeyValidationRequest(npkMHash: Fr, contractAddress: AztecAddress): Promise; /** * Retrieves a set of notes stored in the database for a given contract address and storage slot. diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 7750808fd5dc..277644ec057a 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -191,21 +191,23 @@ describe('Private Execution test suite', () => { beforeEach(async () => { trees = {}; oracle = mock(); - oracle.getNullifierKeys.mockImplementation((masterNullifierPublicKeyHash: Fr, contractAddress: AztecAddress) => { - if (masterNullifierPublicKeyHash.equals(ownerCompleteAddress.publicKeys.masterNullifierPublicKey.hash())) { - return Promise.resolve({ - masterNullifierPublicKey: ownerCompleteAddress.publicKeys.masterNullifierPublicKey, - appNullifierSecretKey: computeAppNullifierSecretKey(ownerMasterNullifierSecretKey, contractAddress), - }); - } - if (masterNullifierPublicKeyHash.equals(recipientCompleteAddress.publicKeys.masterNullifierPublicKey.hash())) { - return Promise.resolve({ - masterNullifierPublicKey: recipientCompleteAddress.publicKeys.masterNullifierPublicKey, - appNullifierSecretKey: computeAppNullifierSecretKey(recipientMasterNullifierSecretKey, contractAddress), - }); - } - throw new Error(`Unknown master nullifier public key hash: ${masterNullifierPublicKeyHash}`); - }); + oracle.getKeyValidationRequest.mockImplementation( + (masterNullifierPublicKeyHash: Fr, contractAddress: AztecAddress) => { + if (masterNullifierPublicKeyHash.equals(ownerCompleteAddress.publicKeys.masterNullifierPublicKey.hash())) { + return Promise.resolve({ + masterNullifierPublicKey: ownerCompleteAddress.publicKeys.masterNullifierPublicKey, + appNullifierSecretKey: computeAppNullifierSecretKey(ownerMasterNullifierSecretKey, contractAddress), + }); + } + if (masterNullifierPublicKeyHash.equals(recipientCompleteAddress.publicKeys.masterNullifierPublicKey.hash())) { + return Promise.resolve({ + masterNullifierPublicKey: recipientCompleteAddress.publicKeys.masterNullifierPublicKey, + appNullifierSecretKey: computeAppNullifierSecretKey(recipientMasterNullifierSecretKey, contractAddress), + }); + } + throw new Error(`Unknown master nullifier public key hash: ${masterNullifierPublicKeyHash}`); + }, + ); // We call insertLeaves here with no leaves to populate empty public data tree root --> this is necessary to be // able to get ivpk_m during execution diff --git a/yarn-project/simulator/src/client/simulator.test.ts b/yarn-project/simulator/src/client/simulator.test.ts index f4cdbd7c97b7..b62ebc12cc3a 100644 --- a/yarn-project/simulator/src/client/simulator.test.ts +++ b/yarn-project/simulator/src/client/simulator.test.ts @@ -42,7 +42,7 @@ describe('Simulator', () => { oracle = mock(); node = mock(); - oracle.getNullifierKeys.mockResolvedValue({ + oracle.getKeyValidationRequest.mockResolvedValue({ masterNullifierPublicKey: ownerMasterNullifierPublicKey, appNullifierSecretKey, }); diff --git a/yarn-project/simulator/src/client/view_data_oracle.ts b/yarn-project/simulator/src/client/view_data_oracle.ts index 68479c6266b5..ab92dfda9170 100644 --- a/yarn-project/simulator/src/client/view_data_oracle.ts +++ b/yarn-project/simulator/src/client/view_data_oracle.ts @@ -40,8 +40,8 @@ export class ViewDataOracle extends TypedOracle { * @returns A Promise that resolves to nullifier keys. * @throws If the nullifier keys are not registered in the key store. */ - public override getNullifierKeys(npkMHash: Fr): Promise { - return this.db.getNullifierKeys(npkMHash, this.contractAddress); + public override getKeyValidationRequest(npkMHash: Fr): Promise { + return this.db.getKeyValidationRequest(npkMHash, this.contractAddress); } /**