Skip to content

Commit 26b6d5a

Browse files
chore: domain separator tweaks (#19199)
Working towards improving domain separation. (Getting ci to run the tests for me, to see what mistakes I've made) In this PR: - Remove unused domain separators from constants.nr - Add some comments to constants.nr (and some physical reordering to group them better... this is fine because the eventual goal is to use strings for domain separators instead of brittle enums). - Rename from `GENERATOR_INDEX__` to `DOM_SEP__`, because "generator index" is carried over from when we used to use pedersen hashes and makes no sense anymore. - Most of the line changes of this PR come from this. - Renamed one of the separators from `__CONTRACT_LEAF` to `__CONTRACT_CLASS_ID` to help my brain. - Created `domain_separators.nr`, which contains dormant tests to generate "proper" domain separators using strings. This PR won't go as far as instating those strings, because all the hard-coded constants in all tests in the repo will break. That'll be a fun task for someone in January. Future domain separation tasks for another PR: - instate the domain separation strings. - Claude says there are poseidon2 hashes which aren't using any domain separator, which could be at risk of collisions. We'll need to add those.
2 parents 6bffcbd + 484e94f commit 26b6d5a

File tree

115 files changed

+845
-555
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+845
-555
lines changed

barretenberg/cpp/pil/vm2/bytecode/address_derivation.pil

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace address_derivation;
3737
// It's reused between the partial address and salted initialization hash. Weird.
3838
// TODO: We need this temporarily while we dont allow for aliases in the lookup tuple
3939
pol commit partial_address_domain_separator;
40-
sel * (partial_address_domain_separator - constants.GENERATOR_INDEX__PARTIAL_ADDRESS) = 0;
40+
sel * (partial_address_domain_separator - constants.DOM_SEP__PARTIAL_ADDRESS) = 0;
4141

4242
// TODO: We need these temporarily while we dont allow for aliases in the lookup tuple
4343
pol commit const_two;
@@ -73,7 +73,7 @@ namespace address_derivation;
7373

7474
// TODO: We need this temporarily while we dont allow for aliases in the lookup tuple
7575
pol commit public_keys_hash_domain_separator;
76-
sel * (public_keys_hash_domain_separator - constants.GENERATOR_INDEX__PUBLIC_KEYS_HASH) = 0;
76+
sel * (public_keys_hash_domain_separator - constants.DOM_SEP__PUBLIC_KEYS_HASH) = 0;
7777

7878
// Remove all the 0s for is_infinite when removed from public_keys.nr
7979
// https://github.com/AztecProtocol/aztec-packages/issues/7529
@@ -104,7 +104,7 @@ namespace address_derivation;
104104

105105
// TODO: We need this temporarily while we dont allow for aliases in the lookup tuple
106106
pol commit preaddress_domain_separator;
107-
sel * (preaddress_domain_separator - constants.GENERATOR_INDEX__CONTRACT_ADDRESS_V1) = 0;
107+
sel * (preaddress_domain_separator - constants.DOM_SEP__CONTRACT_ADDRESS_V1) = 0;
108108

109109
#[PREADDRESS_POSEIDON2]
110110
sel { sel /* =1 */, preaddress_domain_separator, public_keys_hash, partial_address, preaddress }

barretenberg/cpp/pil/vm2/bytecode/bc_hashing.pil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ namespace bc_hashing;
108108

109109
// At the start of a new bytecode hash, the initial field has to be the separator, and we skip the lookup:
110110
#[START_IS_SEPARATOR]
111-
start * (packed_fields_0 - constants.GENERATOR_INDEX__PUBLIC_BYTECODE) = 0;
111+
start * (packed_fields_0 - constants.DOM_SEP__PUBLIC_BYTECODE) = 0;
112112

113113
#[GET_PACKED_FIELD_0]
114114
sel_not_start { pc_index, bytecode_id, packed_fields_0 }

barretenberg/cpp/pil/vm2/bytecode/class_id_derivation.pil

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ namespace class_id_derivation;
1717
pol commit private_functions_root;
1818
pol commit public_bytecode_commitment; // This is constrained via executions's lookup to instr_fetching, which looks up bc_decomposition <-> bc_hashing
1919
// The result of
20-
// H(GENERATOR_INDEX__CONTRACT_LEAF, artifact_hash, private_functions_root, public_bytecode_commitment)
20+
// H(DOM_SEP__CONTRACT_CLASS_ID, artifact_hash, private_functions_root, public_bytecode_commitment)
2121
pol commit class_id;
2222

2323
// TODO: We need these temporarily while we dont allow for aliases in the lookup tuple.
24-
pol commit gen_index_contract_leaf;
25-
sel * (gen_index_contract_leaf - constants.GENERATOR_INDEX__CONTRACT_LEAF) = 0;
24+
pol commit gen_index_contract_class_id;
25+
sel * (gen_index_contract_class_id - constants.DOM_SEP__CONTRACT_CLASS_ID) = 0;
2626
pol commit const_two;
2727
sel * (const_two - 2) = 0;
2828

2929
// Since the inputs to poseidon2 have to be chunks of 3, we need two lookups if we want to do this in a single row
3030
#[CLASS_ID_POSEIDON2_0]
31-
sel { gen_index_contract_leaf, artifact_hash, private_functions_root, class_id, const_two }
31+
sel { gen_index_contract_class_id, artifact_hash, private_functions_root, class_id, const_two }
3232
in poseidon2_hash.start { poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2, poseidon2_hash.output, poseidon2_hash.num_perm_rounds_rem };
3333

3434
#[CLASS_ID_POSEIDON2_1]

barretenberg/cpp/pil/vm2/bytecode/update_check.pil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ namespace update_check;
6969

7070
// TODO: Remove this as a column when we can lookup with constants
7171
pol commit public_leaf_index_domain_separator;
72-
sel * (constants.GENERATOR_INDEX__PUBLIC_LEAF_INDEX - public_leaf_index_domain_separator) = 0;
72+
sel * (constants.DOM_SEP__PUBLIC_LEAF_INDEX - public_leaf_index_domain_separator) = 0;
7373

7474
// TODO: Remove this as a column when we can lookup with constants
7575
pol commit deployer_protocol_contract_address;

barretenberg/cpp/pil/vm2/calldata_hashing.pil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ namespace calldata_hashing;
8787

8888
// At the start of a new calldata hash, the initial field has to be the separator, and we skip the lookup:
8989
#[START_IS_SEPARATOR]
90-
start * (input[0] - constants.GENERATOR_INDEX__PUBLIC_CALLDATA) = 0;
90+
start * (input[0] - constants.DOM_SEP__PUBLIC_CALLDATA) = 0;
9191

9292
// The index increments by 3 each row (unless we are at latch):
9393
#[INDEX_INCREMENTS]

barretenberg/cpp/pil/vm2/constants_gen.pil

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,15 @@ namespace constants;
164164
pol UPDATES_DELAYED_PUBLIC_MUTABLE_METADATA_BIT_SIZE = 144;
165165
pol GRUMPKIN_ONE_X = 1;
166166
pol GRUMPKIN_ONE_Y = 17631683881184975370165255887551781615748388533673675138860;
167-
pol GENERATOR_INDEX__NOTE_HASH_NONCE = 2;
168-
pol GENERATOR_INDEX__UNIQUE_NOTE_HASH = 3;
169-
pol GENERATOR_INDEX__SILOED_NOTE_HASH = 4;
170-
pol GENERATOR_INDEX__OUTER_NULLIFIER = 7;
171-
pol GENERATOR_INDEX__CONTRACT_ADDRESS_V1 = 15;
172-
pol GENERATOR_INDEX__CONTRACT_LEAF = 16;
173-
pol GENERATOR_INDEX__PUBLIC_LEAF_INDEX = 23;
174-
pol GENERATOR_INDEX__PARTIAL_ADDRESS = 27;
175-
pol GENERATOR_INDEX__PUBLIC_CALLDATA = 43;
176-
pol GENERATOR_INDEX__PUBLIC_KEYS_HASH = 52;
177-
pol GENERATOR_INDEX__PUBLIC_BYTECODE = 60;
167+
pol DOM_SEP__NOTE_HASH_NONCE = 2;
168+
pol DOM_SEP__UNIQUE_NOTE_HASH = 3;
169+
pol DOM_SEP__SILOED_NOTE_HASH = 4;
170+
pol DOM_SEP__OUTER_NULLIFIER = 7;
171+
pol DOM_SEP__PUBLIC_LEAF_INDEX = 23;
172+
pol DOM_SEP__PUBLIC_BYTECODE = 60;
173+
pol DOM_SEP__CONTRACT_CLASS_ID = 16;
174+
pol DOM_SEP__PUBLIC_KEYS_HASH = 52;
175+
pol DOM_SEP__PARTIAL_ADDRESS = 27;
176+
pol DOM_SEP__CONTRACT_ADDRESS_V1 = 15;
177+
pol DOM_SEP__PUBLIC_CALLDATA = 43;
178178

barretenberg/cpp/pil/vm2/trees/note_hash_tree_check.pil

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ namespace note_hash_tree_check;
7979

8080
// TODO: We need this temporarily while we do not allow for aliases in the lookup tuple
8181
pol commit siloing_separator;
82-
sel * (constants.GENERATOR_INDEX__SILOED_NOTE_HASH - siloing_separator) = 0;
82+
sel * (constants.DOM_SEP__SILOED_NOTE_HASH - siloing_separator) = 0;
8383

8484
#[SILO_POSEIDON2]
8585
should_silo { sel, siloing_separator, address, note_hash, siloed_note_hash }
@@ -115,15 +115,15 @@ namespace note_hash_tree_check;
115115

116116
// TODO: We need this temporarily while we do not allow for aliases in the lookup tuple
117117
pol commit nonce_separator;
118-
sel * (constants.GENERATOR_INDEX__NOTE_HASH_NONCE - nonce_separator) = 0;
118+
sel * (constants.DOM_SEP__NOTE_HASH_NONCE - nonce_separator) = 0;
119119

120120
#[NONCE_COMPUTATION_POSEIDON2]
121121
should_unique { sel, nonce_separator, first_nullifier, note_hash_index, nonce }
122122
in poseidon2_hash.end { poseidon2_hash.start, poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2, poseidon2_hash.output };
123123

124124
// TODO: We need this temporarily while we do not allow for aliases in the lookup tuple
125125
pol commit unique_note_hash_separator;
126-
sel * (constants.GENERATOR_INDEX__UNIQUE_NOTE_HASH - unique_note_hash_separator) = 0;
126+
sel * (constants.DOM_SEP__UNIQUE_NOTE_HASH - unique_note_hash_separator) = 0;
127127

128128
#[UNIQUE_NOTE_HASH_POSEIDON2]
129129
should_unique { sel, unique_note_hash_separator, nonce, siloed_note_hash, unique_note_hash }

barretenberg/cpp/pil/vm2/trees/nullifier_check.pil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ namespace nullifier_check;
106106

107107
// TODO: We need this temporarily while we do not allow for aliases in the lookup tuple
108108
pol commit siloing_separator;
109-
sel * (constants.GENERATOR_INDEX__OUTER_NULLIFIER - siloing_separator) = 0;
109+
sel * (constants.DOM_SEP__OUTER_NULLIFIER - siloing_separator) = 0;
110110

111111
#[SILO_POSEIDON2]
112112
should_silo { sel, siloing_separator, address, nullifier, siloed_nullifier }

barretenberg/cpp/pil/vm2/trees/public_data_check.pil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ namespace public_data_check;
149149

150150
// TODO: We need this temporarily while we do not allow for aliases in the lookup tuple
151151
pol commit siloing_separator;
152-
sel * (constants.GENERATOR_INDEX__PUBLIC_LEAF_INDEX - siloing_separator) = 0;
152+
sel * (constants.DOM_SEP__PUBLIC_LEAF_INDEX - siloing_separator) = 0;
153153

154154
#[SILO_POSEIDON2]
155155
sel { sel, siloing_separator, address, slot, leaf_slot }

barretenberg/cpp/pil/vm2/trees/written_public_data_slots_tree_check.pil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace written_public_data_slots_tree_check;
8282

8383
// TODO: We need this temporarily while we do not allow for aliases in the lookup tuple
8484
pol commit siloing_separator;
85-
sel * (constants.GENERATOR_INDEX__PUBLIC_LEAF_INDEX - siloing_separator) = 0;
85+
sel * (constants.DOM_SEP__PUBLIC_LEAF_INDEX - siloing_separator) = 0;
8686

8787
#[SILO_POSEIDON2]
8888
sel { sel, siloing_separator, address, slot, leaf_slot }

0 commit comments

Comments
 (0)