Skip to content

Commit

Permalink
feat: Add reset tiny and optimize tail (#7422)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirasistant authored Jul 11, 2024
1 parent 2a7494b commit 399917b
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 22 deletions.
1 change: 1 addition & 0 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ library Constants {
uint256 internal constant PRIVATE_KERNEL_RESET_BIG_INDEX = 3;
uint256 internal constant PRIVATE_KERNEL_RESET_MEDIUM_INDEX = 4;
uint256 internal constant PRIVATE_KERNEL_RESET_SMALL_INDEX = 5;
uint256 internal constant PRIVATE_KERNEL_RESET_TINY_INDEX = 6;
uint256 internal constant PRIVATE_KERNEL_TAIL_INDEX = 10;
uint256 internal constant PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX = 11;
uint256 internal constant EMPTY_NESTED_INDEX = 12;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use dep::types::{
},
constants::{
PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_FULL_INDEX,
PRIVATE_KERNEL_RESET_BIG_INDEX, PRIVATE_KERNEL_RESET_MEDIUM_INDEX, PRIVATE_KERNEL_RESET_SMALL_INDEX
PRIVATE_KERNEL_RESET_BIG_INDEX, PRIVATE_KERNEL_RESET_MEDIUM_INDEX, PRIVATE_KERNEL_RESET_SMALL_INDEX,
PRIVATE_KERNEL_RESET_TINY_INDEX
}
};

Expand All @@ -23,6 +24,7 @@ global ALLOWED_PREVIOUS_CIRCUITS = [
PRIVATE_KERNEL_RESET_BIG_INDEX,
PRIVATE_KERNEL_RESET_MEDIUM_INDEX,
PRIVATE_KERNEL_RESET_SMALL_INDEX,
PRIVATE_KERNEL_RESET_TINY_INDEX,
];

struct PrivateKernelInnerCircuitPrivateInputs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use dep::types::{
abis::{private_kernel_data::PrivateKernelData, kernel_circuit_public_inputs::KernelCircuitPublicInputs},
constants::{
PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_FULL_INDEX,
PRIVATE_KERNEL_RESET_BIG_INDEX, PRIVATE_KERNEL_RESET_MEDIUM_INDEX, PRIVATE_KERNEL_RESET_SMALL_INDEX
PRIVATE_KERNEL_RESET_BIG_INDEX, PRIVATE_KERNEL_RESET_MEDIUM_INDEX, PRIVATE_KERNEL_RESET_SMALL_INDEX,
PRIVATE_KERNEL_RESET_TINY_INDEX
}
};

Expand All @@ -17,6 +18,7 @@ global ALLOWED_PREVIOUS_CIRCUITS = [
PRIVATE_KERNEL_RESET_BIG_INDEX,
PRIVATE_KERNEL_RESET_MEDIUM_INDEX,
PRIVATE_KERNEL_RESET_SMALL_INDEX,
PRIVATE_KERNEL_RESET_TINY_INDEX,
];

struct PrivateKernelTailCircuitPrivateInputs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use dep::types::{
abis::{private_kernel_data::PrivateKernelData, kernel_circuit_public_inputs::PublicKernelCircuitPublicInputs},
constants::{
PRIVATE_KERNEL_INIT_INDEX, PRIVATE_KERNEL_INNER_INDEX, PRIVATE_KERNEL_RESET_FULL_INDEX,
PRIVATE_KERNEL_RESET_BIG_INDEX, PRIVATE_KERNEL_RESET_MEDIUM_INDEX, PRIVATE_KERNEL_RESET_SMALL_INDEX
PRIVATE_KERNEL_RESET_BIG_INDEX, PRIVATE_KERNEL_RESET_MEDIUM_INDEX, PRIVATE_KERNEL_RESET_SMALL_INDEX,
PRIVATE_KERNEL_RESET_TINY_INDEX
}
};

Expand All @@ -18,6 +19,7 @@ global ALLOWED_PREVIOUS_CIRCUITS = [
PRIVATE_KERNEL_RESET_BIG_INDEX,
PRIVATE_KERNEL_RESET_MEDIUM_INDEX,
PRIVATE_KERNEL_RESET_SMALL_INDEX,
PRIVATE_KERNEL_RESET_TINY_INDEX,
];

struct PrivateKernelTailToPublicCircuitPrivateInputs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ global PRIVATE_KERNEL_RESET_FULL_INDEX: u32 = 2;
global PRIVATE_KERNEL_RESET_BIG_INDEX: u32 = 3;
global PRIVATE_KERNEL_RESET_MEDIUM_INDEX: u32 = 4;
global PRIVATE_KERNEL_RESET_SMALL_INDEX: u32 = 5;
global PRIVATE_KERNEL_RESET_TINY_INDEX: u32 = 6;
global PRIVATE_KERNEL_TAIL_INDEX: u32 = 10;
global PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX: u32 = 11;
global EMPTY_NESTED_INDEX: u32 = 12;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use crate::constants::{
PRIVATE_KERNEL_RESET_SMALL_INDEX, PRIVATE_KERNEL_TAIL_INDEX, PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX,
EMPTY_NESTED_INDEX, PRIVATE_KERNEL_EMPTY_INDEX, PUBLIC_KERNEL_SETUP_INDEX,
PUBLIC_KERNEL_APP_LOGIC_INDEX, PUBLIC_KERNEL_TEARDOWN_INDEX, PUBLIC_KERNEL_TAIL_INDEX,
BASE_PARITY_INDEX, ROOT_PARITY_INDEX, BASE_ROLLUP_INDEX, MERGE_ROLLUP_INDEX, ROOT_ROLLUP_INDEX
BASE_PARITY_INDEX, ROOT_PARITY_INDEX, BASE_ROLLUP_INDEX, MERGE_ROLLUP_INDEX, ROOT_ROLLUP_INDEX,
PRIVATE_KERNEL_RESET_TINY_INDEX
};
use crate::merkle_tree::merkle_tree::MerkleTree;

Expand All @@ -25,6 +26,7 @@ pub fn get_vk_merkle_tree() -> MerkleTree<VK_TREE_WIDTH> {
leaves[PRIVATE_KERNEL_RESET_BIG_INDEX] = 3;
leaves[PRIVATE_KERNEL_RESET_MEDIUM_INDEX] = 4;
leaves[PRIVATE_KERNEL_RESET_SMALL_INDEX] = 5;
leaves[PRIVATE_KERNEL_RESET_TINY_INDEX] = 6;
leaves[PRIVATE_KERNEL_TAIL_INDEX] = 10;
leaves[PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX] = 11;
leaves[EMPTY_NESTED_INDEX] = 12;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,13 @@ fn assert_split_sorted_transformed_value_arrays<T, S, N>(
let value = transformed_value_array[i];
let sorted_index = index_hints[i];
let is_lt = original.counter() < split_counter;
let (sorted_value, sorted_counter, num) = if is_lt {
(
sorted_transformed_value_array_lt[sorted_index], sorted_counters_lt[sorted_index], num_lt
)
let (sorted_value, sorted_counter) = if is_lt {
(sorted_transformed_value_array_lt[sorted_index], sorted_counters_lt[sorted_index])
} else {
(
sorted_transformed_value_array_gte[sorted_index], sorted_counters_gte[sorted_index], num_gte
)
(sorted_transformed_value_array_gte[sorted_index], sorted_counters_gte[sorted_index])
};
assert_eq(value, sorted_value, "mismatch sorted values");
assert_eq(original.counter(), sorted_counter, "mismatch counters");
if num != 0 {
let (counter, prev_counter) = if is_lt {
(sorted_counters_lt[num], sorted_counters_lt[num - 1])
} else {
(sorted_counters_gte[num], sorted_counters_gte[num - 1])
};
let is_incrementing = counter > prev_counter;
assert(ascending == is_incrementing, "value array must be sorted by counter");
assert(counter != prev_counter, "counters must not be the same");
}
if is_lt {
num_lt += 1;
} else {
Expand All @@ -58,6 +44,21 @@ fn assert_split_sorted_transformed_value_arrays<T, S, N>(
}
}

for i in 1..N {
if i < num_lt {
let counter = sorted_counters_lt[i];
let prev_counter = sorted_counters_lt[i - 1];
assert(ascending == (counter > prev_counter), "value array must be sorted by counter");
assert(counter != prev_counter, "counters must not be the same");
}
if i < num_gte {
let counter = sorted_counters_gte[i];
let prev_counter = sorted_counters_gte[i - 1];
assert(ascending == (counter > prev_counter), "value array must be sorted by counter");
assert(counter != prev_counter, "counters must not be the same");
}
}

let num_non_empty_values_lt = validate_array(sorted_transformed_value_array_lt);
assert_eq(num_non_empty_values_lt, num_lt, "mismatch number of values lt");

Expand Down
11 changes: 11 additions & 0 deletions noir-projects/noir-protocol-circuits/reset_variants.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,16 @@
"NULLIFIER_SETTLED_AMOUNT": 8,
"NULLIFIER_KEYS": 8
}
},
{
"tag": "tiny",
"priority": 101,
"replacements": {
"NOTE_HASH_PENDING_AMOUNT": 4,
"NOTE_HASH_SETTLED_AMOUNT": 4,
"NULLIFIER_PENDING_AMOUNT": 4,
"NULLIFIER_SETTLED_AMOUNT": 4,
"NULLIFIER_KEYS": 4
}
}
]
2 changes: 2 additions & 0 deletions yarn-project/bb-prover/src/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export function mapProtocolArtifactNameToCircuitName(
return 'private-kernel-reset-medium';
case 'PrivateKernelResetSmallArtifact':
return 'private-kernel-reset-small';
case 'PrivateKernelResetTinyArtifact':
return 'private-kernel-reset-tiny';
case 'EmptyNestedArtifact':
return 'empty-nested';
case 'PrivateKernelEmptyArtifact':
Expand Down
1 change: 1 addition & 0 deletions yarn-project/circuit-types/src/stats/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export type CircuitName =
| 'private-kernel-reset-big'
| 'private-kernel-reset-medium'
| 'private-kernel-reset-small'
| 'private-kernel-reset-tiny'
| 'private-kernel-tail'
| 'private-kernel-tail-to-public'
| 'app-circuit'
Expand Down
1 change: 1 addition & 0 deletions yarn-project/circuits.js/src/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const PRIVATE_KERNEL_RESET_FULL_INDEX = 2;
export const PRIVATE_KERNEL_RESET_BIG_INDEX = 3;
export const PRIVATE_KERNEL_RESET_MEDIUM_INDEX = 4;
export const PRIVATE_KERNEL_RESET_SMALL_INDEX = 5;
export const PRIVATE_KERNEL_RESET_TINY_INDEX = 6;
export const PRIVATE_KERNEL_TAIL_INDEX = 10;
export const PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX = 11;
export const EMPTY_NESTED_INDEX = 12;
Expand Down
7 changes: 6 additions & 1 deletion yarn-project/noir-protocol-circuits-types/src/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import PrivateKernelResetBigSimulatedJson from '../artifacts/private_kernel_rese
import PrivateKernelResetMediumSimulatedJson from '../artifacts/private_kernel_reset_simulated_medium.json' assert { type: 'json' };
import PrivateKernelResetSmallSimulatedJson from '../artifacts/private_kernel_reset_simulated_small.json' assert { type: 'json' };
import PrivateKernelResetSmallJson from '../artifacts/private_kernel_reset_small.json' assert { type: 'json' };
import PrivateKernelResetTinyJson from '../artifacts/private_kernel_reset_tiny.json' assert { type: 'json' };
import PrivateKernelTailJson from '../artifacts/private_kernel_tail.json' assert { type: 'json' };
import PrivateKernelTailSimulatedJson from '../artifacts/private_kernel_tail_simulated.json' assert { type: 'json' };
import PrivateKernelTailToPublicJson from '../artifacts/private_kernel_tail_to_public.json' assert { type: 'json' };
Expand All @@ -40,13 +41,15 @@ export type PrivateResetArtifacts =
| 'PrivateKernelResetFullArtifact'
| 'PrivateKernelResetBigArtifact'
| 'PrivateKernelResetMediumArtifact'
| 'PrivateKernelResetSmallArtifact';
| 'PrivateKernelResetSmallArtifact'
| 'PrivateKernelResetTinyArtifact';

export const PrivateResetTagToArtifactName: Record<PrivateKernelResetTags, PrivateResetArtifacts> = {
full: 'PrivateKernelResetFullArtifact',
big: 'PrivateKernelResetBigArtifact',
medium: 'PrivateKernelResetMediumArtifact',
small: 'PrivateKernelResetSmallArtifact',
tiny: 'PrivateKernelResetTinyArtifact',
};

export type ServerProtocolArtifact =
Expand Down Expand Up @@ -104,6 +107,7 @@ export const ResetSimulatedArtifacts: Record<PrivateResetArtifacts, NoirCompiled
PrivateKernelResetBigArtifact: PrivateKernelResetBigSimulatedJson as NoirCompiledCircuit,
PrivateKernelResetMediumArtifact: PrivateKernelResetMediumSimulatedJson as NoirCompiledCircuit,
PrivateKernelResetSmallArtifact: PrivateKernelResetSmallSimulatedJson as NoirCompiledCircuit,
PrivateKernelResetTinyArtifact: PrivateKernelResetTinyJson as NoirCompiledCircuit,
};

export const ClientCircuitArtifacts: Record<ClientProtocolArtifact, NoirCompiledCircuit> = {
Expand All @@ -113,6 +117,7 @@ export const ClientCircuitArtifacts: Record<ClientProtocolArtifact, NoirCompiled
PrivateKernelResetBigArtifact: PrivateKernelResetBigJson as NoirCompiledCircuit,
PrivateKernelResetMediumArtifact: PrivateKernelResetMediumJson as NoirCompiledCircuit,
PrivateKernelResetSmallArtifact: PrivateKernelResetSmallJson as NoirCompiledCircuit,
PrivateKernelResetTinyArtifact: PrivateKernelResetTinyJson as NoirCompiledCircuit,
PrivateKernelTailArtifact: PrivateKernelTailJson as NoirCompiledCircuit,
PrivateKernelTailToPublicArtifact: PrivateKernelTailToPublicJson as NoirCompiledCircuit,
};
Expand Down
4 changes: 4 additions & 0 deletions yarn-project/noir-protocol-circuits-types/src/vks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
PRIVATE_KERNEL_RESET_FULL_INDEX,
PRIVATE_KERNEL_RESET_MEDIUM_INDEX,
PRIVATE_KERNEL_RESET_SMALL_INDEX,
PRIVATE_KERNEL_RESET_TINY_INDEX,
PRIVATE_KERNEL_TAIL_INDEX,
PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX,
PUBLIC_KERNEL_APP_LOGIC_INDEX,
Expand All @@ -38,6 +39,7 @@ import PrivateKernelResetFullVkJson from '../artifacts/keys/private_kernel_reset
import PrivateKernelResetBigVkJson from '../artifacts/keys/private_kernel_reset_big.vk.data.json' assert { type: 'json' };
import PrivateKernelResetMediumVkJson from '../artifacts/keys/private_kernel_reset_medium.vk.data.json' assert { type: 'json' };
import PrivateKernelResetSmallVkJson from '../artifacts/keys/private_kernel_reset_small.vk.data.json' assert { type: 'json' };
import PrivateKernelResetTinyVkJson from '../artifacts/keys/private_kernel_reset_tiny.vk.data.json' assert { type: 'json' };
import PrivateKernelTailVkJson from '../artifacts/keys/private_kernel_tail.vk.data.json' assert { type: 'json' };
import PrivateKernelTailToPublicVkJson from '../artifacts/keys/private_kernel_tail_to_public.vk.data.json' assert { type: 'json' };
import PublicKernelAppLogicVkJson from '../artifacts/keys/public_kernel_app_logic.vk.data.json' assert { type: 'json' };
Expand Down Expand Up @@ -90,6 +92,7 @@ const ClientCircuitVks: Record<ClientProtocolArtifact, VerificationKeyData> = {
PrivateKernelResetBigArtifact: keyJsonToVKData(PrivateKernelResetBigVkJson),
PrivateKernelResetMediumArtifact: keyJsonToVKData(PrivateKernelResetMediumVkJson),
PrivateKernelResetSmallArtifact: keyJsonToVKData(PrivateKernelResetSmallVkJson),
PrivateKernelResetTinyArtifact: keyJsonToVKData(PrivateKernelResetTinyVkJson),
PrivateKernelTailArtifact: keyJsonToVKData(PrivateKernelTailVkJson),
PrivateKernelTailToPublicArtifact: keyJsonToVKData(PrivateKernelTailToPublicVkJson),
};
Expand All @@ -108,6 +111,7 @@ export const ProtocolCircuitVkIndexes: Record<ProtocolArtifact, number> = {
PrivateKernelResetBigArtifact: PRIVATE_KERNEL_RESET_BIG_INDEX,
PrivateKernelResetMediumArtifact: PRIVATE_KERNEL_RESET_MEDIUM_INDEX,
PrivateKernelResetSmallArtifact: PRIVATE_KERNEL_RESET_SMALL_INDEX,
PrivateKernelResetTinyArtifact: PRIVATE_KERNEL_RESET_TINY_INDEX,
PrivateKernelTailArtifact: PRIVATE_KERNEL_TAIL_INDEX,
PrivateKernelTailToPublicArtifact: PRIVATE_KERNEL_TAIL_TO_PUBLIC_INDEX,
PublicKernelSetupArtifact: PUBLIC_KERNEL_SETUP_INDEX,
Expand Down

0 comments on commit 399917b

Please sign in to comment.