Skip to content

Commit

Permalink
move g1_hash and g1_equal inside function body and next to their use,…
Browse files Browse the repository at this point in the history
… use std::hash<const char*> for hashing, use size() instead of 96 * sizeof(char)
  • Loading branch information
linh2931 committed Dec 14, 2023
1 parent ac597ea commit 89672ac
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions contracts/eosio.bios/src/eosio.bios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@ void bios::setabi( name account, const std::vector<char>& abi ) {
}
}

// helpers for defining std::unordered_set<eosio::bls_g1>
struct g1_hash {
// bls_g1 is defined as std::array<char, 96>
std::size_t operator()(const eosio::bls_g1& g1) const {
std::hash<std::string> hash_func;
return hash_func(g1.data());
}
};

struct g1_equal {
bool operator()(const eosio::bls_g1& lhs, const eosio::bls_g1& rhs) const {
return std::memcmp(lhs.data(), rhs.data(), 96 * sizeof(char)) == 0;
}
};

void bios::setfinalizer( const finalizer_policy& finalizer_policy ) {
// exensive checks are performed to make sure setfinalizer host function
// will never fail
Expand All @@ -51,8 +36,20 @@ void bios::setfinalizer( const finalizer_policy& finalizer_policy ) {
const std::string pk_prefix = "PUB_BLS";
const std::string sig_prefix = "SIG_BLS";

// use raw affine format for uniqueness check
// use raw affine format (bls_g1 is std::array<char, 96>) for uniqueness check
struct g1_hash {
std::size_t operator()(const eosio::bls_g1& g1) const {
std::hash<const char*> hash_func;
return hash_func(g1.data());
}
};
struct g1_equal {
bool operator()(const eosio::bls_g1& lhs, const eosio::bls_g1& rhs) const {
return std::memcmp(lhs.data(), rhs.data(), lhs.size()) == 0;
}
};
std::unordered_set<eosio::bls_g1, g1_hash, g1_equal> unique_finalizer_keys;

uint64_t weight_sum = 0;

for (const auto& f: finalizer_policy.finalizers) {
Expand Down

0 comments on commit 89672ac

Please sign in to comment.