diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.tpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.tpp index 1b10b8216b5..0b5d674a791 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note.tpp @@ -18,10 +18,6 @@ using aztec3::circuits::apps::state_vars::StateVar; namespace aztec3::circuits::apps::notes { -using aztec3::GeneratorIndex; - -using crypto::generators::generator_index_t; - using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; using plonk::stdlib::witness_t; @@ -62,27 +58,6 @@ typename CircuitTypes::fr DefaultPrivateNote::compute_commi grumpkin_point const storage_slot_point = state_var->storage_slot_point; - std::vector const inputs; - std::vector const generators; - - auto gen_pair_address = [&](std::optional
const& input, size_t const hash_sub_index) { - if (!input) { - throw_or_abort( - "Cannot commit to a partial preimage. Call compute_partial_commitment instead, or complete " - "the preimage."); - } - return std::make_pair((*input).to_field(), generator_index_t({ GeneratorIndex::COMMITMENT, hash_sub_index })); - }; - - auto gen_pair_fr = [&](std::optional const& input, size_t const hash_sub_index) { - if (!input) { - throw_or_abort( - "Cannot commit to a partial preimage. Call compute_partial_commitment instead, or complete " - "the preimage."); - } - return std::make_pair(*input, generator_index_t({ GeneratorIndex::COMMITMENT, hash_sub_index })); - }; - if (!note_preimage.salt) { note_preimage.salt = get_oracle().generate_random_element(); } @@ -90,18 +65,17 @@ typename CircuitTypes::fr DefaultPrivateNote::compute_commi const auto& [value, owner, creator_address, memo, salt, nonce, is_dummy] = note_preimage; const grumpkin_point commitment_point = - storage_slot_point + - CT::commit( - { gen_pair_fr(value, PrivateStateNoteGeneratorIndex::VALUE), - gen_pair_address(owner, PrivateStateNoteGeneratorIndex::OWNER), - gen_pair_address(creator_address, PrivateStateNoteGeneratorIndex::CREATOR), - gen_pair_fr(memo, PrivateStateNoteGeneratorIndex::MEMO), - gen_pair_fr(salt, PrivateStateNoteGeneratorIndex::SALT), - gen_pair_fr(nonce, PrivateStateNoteGeneratorIndex::NONCE), - std::make_pair( - is_dummy, generator_index_t({ GeneratorIndex::COMMITMENT, PrivateStateNoteGeneratorIndex::IS_DUMMY })) - - }); + storage_slot_point + CT::commit( + { + *value, /*PrivateStateNoteGeneratorIndex::VALUE*/ + (*owner).to_field(), /*PrivateStateNoteGeneratorIndex::OWNER*/ + (*creator_address).to_field(), /*PrivateStateNoteGeneratorIndex::CREATOR*/ + *memo, /*PrivateStateNoteGeneratorIndex::MEMO*/ + *salt, /*PrivateStateNoteGeneratorIndex::SALT*/ + *nonce, /*PrivateStateNoteGeneratorIndex::NONCE*/ + is_dummy, /*PrivateStateNoteGeneratorIndex::IS_DUMMY*/ + }, + GeneratorIndex::COMMITMENT); commitment = commitment_point.x; diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp index 28e5fa2922c..e93eb00e0bb 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_private_note/note_preimage.hpp @@ -10,7 +10,6 @@ namespace aztec3::circuits::apps::notes { using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; -using crypto::generators::generator_index_t; template struct DefaultPrivateNotePreimage { using fr = typename NCT::fr; diff --git a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp index 1e43b9642c4..76742963edf 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/notes/default_singleton_private_note/note.tpp @@ -5,6 +5,7 @@ #include "../../state_vars/state_var_base.hpp" #include "../note_interface.hpp" +#include "aztec3/constants.hpp" #include "aztec3/utils/types/circuit_types.hpp" #include "aztec3/utils/types/convert.hpp" #include "aztec3/utils/types/native_types.hpp" @@ -20,8 +21,6 @@ namespace aztec3::circuits::apps::notes { using aztec3::GeneratorIndex; -using crypto::generators::generator_index_t; - using aztec3::utils::types::CircuitTypes; using aztec3::utils::types::NativeTypes; using plonk::stdlib::witness_t; @@ -62,23 +61,6 @@ typename CircuitTypes::fr DefaultSingletonPrivateNote::comp grumpkin_point const storage_slot_point = state_var->storage_slot_point; - std::vector const inputs; - std::vector const generators; - - auto gen_pair_address = [&](std::optional
const& input, size_t const hash_sub_index) { - if (!input) { - throw_or_abort("Cannot commit to a partial preimage."); - } - return std::make_pair((*input).to_field(), generator_index_t({ GeneratorIndex::COMMITMENT, hash_sub_index })); - }; - - auto gen_pair_fr = [&](std::optional const& input, size_t const hash_sub_index) { - if (!input) { - throw_or_abort("Cannot commit to a partial preimage."); - } - return std::make_pair(*input, generator_index_t({ GeneratorIndex::COMMITMENT, hash_sub_index })); - }; - if (!note_preimage.salt) { note_preimage.salt = get_oracle().generate_random_element(); } @@ -86,12 +68,14 @@ typename CircuitTypes::fr DefaultSingletonPrivateNote::comp const auto& [value, owner, salt, nonce] = note_preimage; const grumpkin_point commitment_point = - storage_slot_point + CT::commit({ - gen_pair_fr(value, PrivateStateNoteGeneratorIndex::VALUE), - gen_pair_address(owner, PrivateStateNoteGeneratorIndex::OWNER), - gen_pair_fr(salt, PrivateStateNoteGeneratorIndex::SALT), - gen_pair_fr(nonce, PrivateStateNoteGeneratorIndex::NONCE), - }); + storage_slot_point + CT::commit( + { + *value, /*PrivateStateNoteGeneratorIndex::VALUE*/ + (*owner).to_field(), /*PrivateStateNoteGeneratorIndex::OWNER*/ + *salt, /*PrivateStateNoteGeneratorIndex::SALT*/ + *nonce, /*PrivateStateNoteGeneratorIndex::NONCE*/ + }, + GeneratorIndex::COMMITMENT); commitment = commitment_point.x; diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.hpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.hpp index b8e76a52a28..1add53261f8 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.hpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.hpp @@ -64,7 +64,6 @@ template class MappingStateVar : public StateVar< V& at(std::optional const& key); static std::tuple compute_slot_point_at_mapping_key(NT::fr const& start_slot, - size_t level_of_container_nesting, std::optional const& key); std::tuple compute_slot_point_at_mapping_key(std::optional const& key); diff --git a/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp b/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp index 7f1f9d85076..2299ec01adb 100644 --- a/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp +++ b/circuits/cpp/src/aztec3/circuits/apps/state_vars/mapping_state_var.tpp @@ -38,32 +38,27 @@ using aztec3::utils::types::NativeTypes; template std::tuple MappingStateVar::compute_slot_point_at_mapping_key( - NT::fr const& start_slot, size_t level_of_container_nesting, std::optional const& key) + NT::fr const& start_slot, std::optional const& key) { bool const is_partial_slot = false; - std::vector> input_pairs; + std::vector inputs; // TODO: compare (in a test) this little calc against calling `compute_start_slot_point`. - input_pairs.emplace_back( - start_slot, - generator_index_t({ StorageSlotGeneratorIndex::MAPPING_SLOT, 0 })); // hash_sub_index 0 is reserved for the + inputs.emplace_back(start_slot); if (key) { - input_pairs.emplace_back( - *key, generator_index_t({ StorageSlotGeneratorIndex::MAPPING_SLOT, level_of_container_nesting })); + inputs.emplace_back(*key); } else { // If this mapping key has no mapping_key_value (std::nullopt), then we must be partially committing and // omitting this mapping key from that partial commitment. // So use a placeholder generator for this mapping key, to signify "this mapping key is missing". // Note: we can't just commit to a value of `0` for this mapping key, since `0` is a valid value to // commit to, and so "missing" is distinguished as follows. - input_pairs.emplace_back( - NativeTypes::fr(1), - generator_index_t({ StorageSlotGeneratorIndex::MAPPING_SLOT_PLACEHOLDER, level_of_container_nesting })); + inputs.emplace_back(NativeTypes::fr(1)); } - return std::make_tuple(NativeTypes::commit(input_pairs), is_partial_slot); + return std::make_tuple(NativeTypes::commit(inputs, StorageSlotGeneratorIndex::MAPPING_SLOT), is_partial_slot); } template @@ -72,33 +67,23 @@ std::tuple::grumpkin_point, bool> MappingStateVar { bool is_partial_slot = false; - std::vector> input_pairs; + std::vector inputs; - input_pairs.push_back( - std::make_pair(this->start_slot, - generator_index_t({ StorageSlotGeneratorIndex::MAPPING_SLOT, - 0 }))); // hash_sub_index 0 is reserved for the start_slot. + inputs.push_back(this->start_slot); if (key) { - input_pairs.push_back(std::make_pair( - *key, - generator_index_t( - { StorageSlotGeneratorIndex::MAPPING_SLOT, - this->level_of_container_nesting }))); // hash_sub_index 0 is reserved for the start_slot. + inputs.push_back(*key); } else { // If this mapping key has no mapping_key_value (std::nullopt), then we must be partially committing and // omitting this mapping key from that partial commitment. // So use a placeholder generator for this mapping key, to signify "this mapping key is missing". // Note: we can't just commit to a value of `0` for this mapping key, since `0` is a valid value to // commit to, and so "missing" is distinguished as follows. - input_pairs.push_back(std::make_pair(fr(1), - generator_index_t({ StorageSlotGeneratorIndex::MAPPING_SLOT_PLACEHOLDER, - this->level_of_container_nesting }))); - + inputs.push_back(fr(1)); is_partial_slot = true; } - return std::make_tuple(CT::commit(input_pairs), is_partial_slot); + return std::make_tuple(CT::commit(inputs, StorageSlotGeneratorIndex::MAPPING_SLOT), is_partial_slot); } template V& MappingStateVar::at(std::optional const& key) @@ -115,8 +100,8 @@ template V& MappingStateVar::at(std:: bool is_partial_slot = false; NativeTypes::grumpkin_point native_new_slot_point; - std::tie(native_new_slot_point, is_partial_slot) = MappingStateVar::compute_slot_point_at_mapping_key( - this->start_slot.get_value(), this->level_of_container_nesting, native_key); + std::tie(native_new_slot_point, is_partial_slot) = + MappingStateVar::compute_slot_point_at_mapping_key(this->start_slot.get_value(), native_key); NativeTypes::fr const native_lookup = native_new_slot_point.x; // Check cache