Skip to content

Commit

Permalink
feat: generic key validation request 2
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed May 16, 2024
1 parent d4968b2 commit 89bc538
Show file tree
Hide file tree
Showing 39 changed files with 234 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 +
Expand All @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/protocol-specs/circuits/private-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/protocol-specs/circuits/private-kernel-initial.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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~
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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. |

Expand Down
6 changes: 3 additions & 3 deletions docs/docs/protocol-specs/circuits/private-kernel-inner.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/protocol-specs/circuits/private-kernel-reset.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/protocol-specs/constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand All @@ -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 |

Expand Down
8 changes: 4 additions & 4 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 89bc538

Please sign in to comment.