Skip to content

Commit

Permalink
chore: refactor hash.hpp to use const& (#1578)
Browse files Browse the repository at this point in the history
There was a period where msgpack did not allow binding with const&. This
is now fixed, and recommended
  • Loading branch information
ludamad authored Aug 16, 2023
1 parent c2c30da commit 4c329af
Showing 1 changed file with 41 additions and 43 deletions.
84 changes: 41 additions & 43 deletions circuits/cpp/src/aztec3/circuits/hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using aztec3::circuits::abis::FunctionLeafPreimage;
using MemoryStore = stdlib::merkle_tree::MemoryStore;
using MerkleTree = stdlib::merkle_tree::MerkleTree<MemoryStore>;

template <typename NCT> typename NCT::fr compute_var_args_hash(std::vector<typename NCT::fr> args)
template <typename NCT> typename NCT::fr compute_var_args_hash(std::vector<typename NCT::fr> const& args)
{
auto const MAX_ARGS = 32;
if (args.size() > MAX_ARGS) {
Expand All @@ -31,9 +31,9 @@ template <typename NCT> typename NCT::fr compute_var_args_hash(std::vector<typen
return NCT::hash(args, FUNCTION_ARGS);
}

template <typename NCT> typename NCT::fr compute_constructor_hash(FunctionData<NCT> function_data,
typename NCT::fr args_hash,
typename NCT::fr constructor_vk_hash)
template <typename NCT> typename NCT::fr compute_constructor_hash(FunctionData<NCT> const& function_data,
typename NCT::fr const& args_hash,
typename NCT::fr const& constructor_vk_hash)
{
using fr = typename NCT::fr;

Expand All @@ -48,35 +48,32 @@ template <typename NCT> typename NCT::fr compute_constructor_hash(FunctionData<N
return NCT::compress(inputs, aztec3::GeneratorIndex::CONSTRUCTOR);
}

template <typename NCT> typename NCT::fr compute_partial_address(typename NCT::fr contract_address_salt,
typename NCT::fr function_tree_root,
typename NCT::fr constructor_hash)
template <typename NCT> typename NCT::fr compute_partial_address(typename NCT::fr const& contract_address_salt,
typename NCT::fr const& function_tree_root,
typename NCT::fr const& constructor_hash)
{
using fr = typename NCT::fr;
std::vector<fr> const inputs = {
fr(0), fr(0), contract_address_salt, function_tree_root, constructor_hash,
std::vector<typename NCT::fr> const inputs = {
typename NCT::fr(0), typename NCT::fr(0), contract_address_salt, function_tree_root, constructor_hash,
};
return NCT::hash(inputs, aztec3::GeneratorIndex::PARTIAL_ADDRESS);
}

template <typename NCT>
typename NCT::address compute_contract_address_from_partial(Point<NCT> const& point, typename NCT::fr partial_address)
typename NCT::address compute_contract_address_from_partial(Point<NCT> const& point,
typename NCT::fr const& partial_address)
{
using fr = typename NCT::fr;
using address = typename NCT::address;

std::vector<fr> const inputs = {
std::vector<typename NCT::fr> const inputs = {
point.x,
point.y,
partial_address,
};
return address(NCT::hash(inputs, aztec3::GeneratorIndex::CONTRACT_ADDRESS));
return { NCT::hash(inputs, aztec3::GeneratorIndex::CONTRACT_ADDRESS) };
}

template <typename NCT> typename NCT::address compute_contract_address(Point<NCT> const& point,
typename NCT::fr contract_address_salt,
typename NCT::fr function_tree_root,
typename NCT::fr constructor_hash)
typename NCT::fr const& contract_address_salt,
typename NCT::fr const& function_tree_root,
typename NCT::fr const& constructor_hash)
{
using fr = typename NCT::fr;

Expand All @@ -86,8 +83,8 @@ template <typename NCT> typename NCT::address compute_contract_address(Point<NCT
return compute_contract_address_from_partial(point, partial_address);
}

template <typename NCT>
typename NCT::fr compute_commitment_nonce(typename NCT::fr first_nullifier, typename NCT::fr commitment_index)
template <typename NCT> typename NCT::fr compute_commitment_nonce(typename NCT::fr const& first_nullifier,
typename NCT::fr const& commitment_index)
{
using fr = typename NCT::fr;

Expand All @@ -99,8 +96,8 @@ typename NCT::fr compute_commitment_nonce(typename NCT::fr first_nullifier, type
return NCT::hash(inputs, aztec3::GeneratorIndex::COMMITMENT_NONCE);
}

template <typename NCT>
typename NCT::fr silo_commitment(typename NCT::address contract_address, typename NCT::fr inner_commitment)
template <typename NCT> typename NCT::fr silo_commitment(typename NCT::address const& contract_address,
typename NCT::fr const& inner_commitment)
{
using fr = typename NCT::fr;

Expand All @@ -126,7 +123,7 @@ typename NCT::fr compute_unique_commitment(typename NCT::fr nonce, typename NCT:
}

template <typename NCT>
typename NCT::fr silo_nullifier(typename NCT::address contract_address, typename NCT::fr nullifier)
typename NCT::fr silo_nullifier(typename NCT::address const& contract_address, typename NCT::fr nullifier)
{
using fr = typename NCT::fr;

Expand All @@ -140,12 +137,12 @@ typename NCT::fr silo_nullifier(typename NCT::address contract_address, typename
}


template <typename NCT> typename NCT::fr compute_block_hash(typename NCT::fr globals_hash,
typename NCT::fr private_data_tree_root,
typename NCT::fr nullifier_tree_root,
typename NCT::fr contract_tree_root,
typename NCT::fr l1_to_l2_data_tree_root,
typename NCT::fr public_data_tree_root)
template <typename NCT> typename NCT::fr compute_block_hash(typename NCT::fr const& globals_hash,
typename NCT::fr const& private_data_tree_root,
typename NCT::fr const& nullifier_tree_root,
typename NCT::fr const& contract_tree_root,
typename NCT::fr const& l1_to_l2_data_tree_root,
typename NCT::fr const& public_data_tree_root)
{
using fr = typename NCT::fr;

Expand All @@ -157,12 +154,13 @@ template <typename NCT> typename NCT::fr compute_block_hash(typename NCT::fr glo
return NCT::compress(inputs, aztec3::GeneratorIndex::BLOCK_HASH);
}

template <typename NCT> typename NCT::fr compute_block_hash_with_globals(typename abis::GlobalVariables<NCT> globals,
typename NCT::fr private_data_tree_root,
typename NCT::fr nullifier_tree_root,
typename NCT::fr contract_tree_root,
typename NCT::fr l1_to_l2_data_tree_root,
typename NCT::fr public_data_tree_root)
template <typename NCT>
typename NCT::fr compute_block_hash_with_globals(abis::GlobalVariables<NCT> const& globals,
typename NCT::fr const& private_data_tree_root,
typename NCT::fr const& nullifier_tree_root,
typename NCT::fr const& contract_tree_root,
typename NCT::fr const& l1_to_l2_data_tree_root,
typename NCT::fr const& public_data_tree_root)
{
using fr = typename NCT::fr;

Expand All @@ -174,7 +172,7 @@ template <typename NCT> typename NCT::fr compute_block_hash_with_globals(typenam
return NCT::compress(inputs, aztec3::GeneratorIndex::BLOCK_HASH);
}

template <typename NCT> typename NCT::fr compute_globals_hash(typename abis::GlobalVariables<NCT> globals)
template <typename NCT> typename NCT::fr compute_globals_hash(abis::GlobalVariables<NCT> const& globals)
{
return globals.hash();
}
Expand Down Expand Up @@ -400,11 +398,11 @@ template <typename NCT> typename NCT::fr compute_public_data_tree_index(typename
return NCT::compress({ contract_address, storage_slot }, GeneratorIndex::PUBLIC_LEAF_INDEX);
}

template <typename NCT> typename NCT::fr compute_l2_to_l1_hash(typename NCT::address contract_address,
typename NCT::fr rollup_version_id,
typename NCT::fr portal_contract_address,
typename NCT::fr chain_id,
typename NCT::fr content)
template <typename NCT> typename NCT::fr compute_l2_to_l1_hash(typename NCT::address const& contract_address,
typename NCT::fr const& rollup_version_id,
typename NCT::fr const& portal_contract_address,
typename NCT::fr const& chain_id,
typename NCT::fr const& content)
{
using fr = typename NCT::fr;

Expand Down Expand Up @@ -435,7 +433,7 @@ template <typename NCT> typename NCT::fr compute_l2_to_l1_hash(typename NCT::add
* @return Resulting sha256 hash stored in 2 fields.
*/
template <typename NCT> std::array<typename NCT::fr, NUM_FIELDS_PER_SHA256> accumulate_sha256(
std::array<typename NCT::fr, NUM_FIELDS_PER_SHA256 * 2> hashes)
std::array<typename NCT::fr, NUM_FIELDS_PER_SHA256 * 2> const& hashes)
{
using fr = typename NCT::fr;

Expand Down

0 comments on commit 4c329af

Please sign in to comment.