Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(circuits): delete old code that set a different generator index per vector entry in pedersen commitment #2700

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,46 +58,24 @@ typename CircuitTypes<Builder>::fr DefaultPrivateNote<Builder, V>::compute_commi

grumpkin_point const storage_slot_point = state_var->storage_slot_point;

std::vector<fr> const inputs;
std::vector<generator_index_t> const generators;

auto gen_pair_address = [&](std::optional<address> 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<fr> 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();
}

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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename NCT, typename V> struct DefaultPrivateNotePreimage {
using fr = typename NCT::fr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -62,36 +61,21 @@ typename CircuitTypes<Builder>::fr DefaultSingletonPrivateNote<Builder, V>::comp

grumpkin_point const storage_slot_point = state_var->storage_slot_point;

std::vector<fr> const inputs;
std::vector<generator_index_t> const generators;

auto gen_pair_address = [&](std::optional<address> 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<fr> 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();
}

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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ template <typename Builder, typename V> class MappingStateVar : public StateVar<
V& at(std::optional<fr> const& key);

static std::tuple<NT::grumpkin_point, bool> compute_slot_point_at_mapping_key(NT::fr const& start_slot,
size_t level_of_container_nesting,
std::optional<NT::fr> const& key);

std::tuple<grumpkin_point, bool> compute_slot_point_at_mapping_key(std::optional<fr> const& key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,27 @@ using aztec3::utils::types::NativeTypes;

template <typename Builder, typename V>
std::tuple<NativeTypes::grumpkin_point, bool> MappingStateVar<Builder, V>::compute_slot_point_at_mapping_key(
NT::fr const& start_slot, size_t level_of_container_nesting, std::optional<typename NT::fr> const& key)
NT::fr const& start_slot, std::optional<typename NT::fr> const& key)
{
bool const is_partial_slot = false;

std::vector<std::pair<NativeTypes::fr, generator_index_t>> input_pairs;
std::vector<NativeTypes::fr> 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 <typename Builder, typename V>
Expand All @@ -72,33 +67,23 @@ std::tuple<typename CircuitTypes<Builder>::grumpkin_point, bool> MappingStateVar
{
bool is_partial_slot = false;

std::vector<std::pair<fr, generator_index_t>> input_pairs;
std::vector<fr> 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 <typename Builder, typename V> V& MappingStateVar<Builder, V>::at(std::optional<fr> const& key)
Expand All @@ -115,8 +100,8 @@ template <typename Builder, typename V> V& MappingStateVar<Builder, V>::at(std::

bool is_partial_slot = false;
NativeTypes::grumpkin_point native_new_slot_point;
std::tie(native_new_slot_point, is_partial_slot) = MappingStateVar<Builder, V>::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<Builder, V>::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
Expand Down