-
Notifications
You must be signed in to change notification settings - Fork 72
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
[5.0] Return error for num == 0 for bls_g1_weighted_sum, bls_g2_weighted_sum and bls_pairing #1954
Conversation
|
@@ -319,7 +319,7 @@ namespace eosio { namespace chain { namespace webassembly { | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to your change, and probably not something we want to do in 5.0, but maybe in the future we can make the code a little cleaner by converting the eos span<char>
-> std::span<uint8_t>
only once, as in:
int32_t interface::bls_g1_weighted_sum(span<const char> _points, span<const char> _scalars, const uint32_t n, span<char> result) const {
if(n == 0 || _points.size() != n*96 || _scalars.size() != n*32 || result.size() != 96)
return return_code::failure;
std::span<const uint8_t> points((const uint8_t*)_points.data(), n*96);
std::span<const uint8_t> scalars((const uint8_t*)_scalars.data(), n*32);
// Use much efficient scale for the special case of n == 1.
if (1 == n) {
std::optional<bls12_381::g1> a = bls12_381::g1::fromAffineBytesLE(points.first<96>(), true, false);
if(!a)
return return_code::failure;
std::array<uint64_t, 4> b = bls12_381::scalar::fromBytesLE<4>(scalars.first<32>());
bls12_381::g1 c = a->scale(b);
c.toAffineBytesLE(std::span<uint8_t, 96>((uint8_t*)result.data(), 96), false);
return return_code::success;
}
std::vector<bls12_381::g1> pv;
std::vector<std::array<uint64_t, 4>> sv;
pv.reserve(n);
sv.reserve(n);
for(uint32_t i = 0; i < n; i++)
{
std::optional<bls12_381::g1> p = bls12_381::g1::fromAffineBytesLE(points.subspan(i*96).first<96>(), true, false);
if(!p.has_value())
return return_code::failure;
std::array<uint64_t, 4> s = bls12_381::scalar::fromBytesLE<4>(scalars.subspan(i*32).first<32>());
pv.push_back(p.value());
sv.push_back(s);
if(i%10 == 0)
context.trx_context.checktime();
}
bls12_381::g1 r = bls12_381::g1::weightedSum(pv, sv, [this](){ context.trx_context.checktime();}); // accessing value is safe
r.toAffineBytesLE(std::span<uint8_t, 96>((uint8_t*)result.data(), 96), false);
return return_code::success;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a code style change like this appropriate at this point.
Return error for
num == 0
for host functionsbls_g1_weighted_sum
,bls_g2_weighted_sum
, andbls_pairing
.Resolves #1953