Skip to content

Commit

Permalink
Merge pull request #254 from AntelopeIO/GH-253-bls-n0
Browse files Browse the repository at this point in the history
Return -1 on n==0 for bls_g1_weighted_sum, bls_g2_weighted_sum, and bls_pairing
  • Loading branch information
heifner authored Dec 6, 2023
2 parents 122ff08 + f9331b1 commit 1c151b5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 45 deletions.
9 changes: 9 additions & 0 deletions libraries/eosiolib/core/eosio/check.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ namespace eosio {
}
}


/**
* Return codes returned by host functions
*/
enum return_code : int32_t {
failure = -1,
success = 0
};

/**
* @defgroup system System
* @ingroup core
Expand Down
69 changes: 24 additions & 45 deletions libraries/eosiolib/core/eosio/crypto_bls_ext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,57 +68,36 @@ namespace eosio {
}

inline int32_t bls_g1_weighted_sum(const bls_g1 g1_points[], const bls_scalar scalars[], uint32_t num, bls_g1& res) {
if (num > 0) {
return internal_use_do_not_use::bls_g1_weighted_sum(
g1_points[0].data(), num * g1_points[0].size(),
scalars[0].data(), num * scalars[0].size(),
num,
res.data(), res.size()
);
} else {
return internal_use_do_not_use::bls_g1_weighted_sum(
nullptr, 0,
nullptr, 0,
0,
res.data(), res.size()
);
}
if (num == 0)
return return_code::failure;
return internal_use_do_not_use::bls_g1_weighted_sum(
g1_points[0].data(), num * g1_points[0].size(),
scalars[0].data(), num * scalars[0].size(),
num,
res.data(), res.size()
);
}

inline int32_t bls_g2_weighted_sum(const bls_g2 g2_points[], const bls_scalar scalars[], uint32_t num, bls_g2& res) {
if (num > 0) {
return internal_use_do_not_use::bls_g2_weighted_sum(
g2_points[0].data(), num * g2_points[0].size(),
scalars[0].data(), num * scalars[0].size(),
num,
res.data(), res.size()
);
} else {
return internal_use_do_not_use::bls_g2_weighted_sum(
nullptr, 0,
nullptr, 0,
0,
res.data(), res.size()
);
}
if (num == 0)
return return_code::failure;
return internal_use_do_not_use::bls_g2_weighted_sum(
g2_points[0].data(), num * g2_points[0].size(),
scalars[0].data(), num * scalars[0].size(),
num,
res.data(), res.size()
);
}

inline int32_t bls_pairing(const bls_g1 g1_points[], const bls_g2 g2_points[], const uint32_t num, bls_gt& res) {
if (num > 0) {
return internal_use_do_not_use::bls_pairing(
g1_points[0].data(), num * g1_points[0].size(),
g2_points[0].data(), num * g2_points[0].size(),
num,
res.data(), res.size()
);
} else {
return internal_use_do_not_use::bls_pairing(
nullptr, 0,
nullptr, 0,
0,
res.data(), res.size()
);
}
if (num == 0)
return return_code::failure;
return internal_use_do_not_use::bls_pairing(
g1_points[0].data(), num * g1_points[0].size(),
g2_points[0].data(), num * g2_points[0].size(),
num,
res.data(), res.size()
);
}

inline int32_t bls_g1_map(const bls_fp& e, bls_g1& res) {
Expand Down

0 comments on commit 1c151b5

Please sign in to comment.