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

[seraphis] ringct: adjust multiexp #8679

Merged
merged 1 commit into from
Apr 25, 2023

Conversation

UkoeHB
Copy link
Contributor

@UkoeHB UkoeHB commented Dec 14, 2022

This is a PR in my 'upstreaming seraphis_lib project', the changes here are not used anywhere yet.

  • Refactors pippenger_cached_data to use a vector of ge_cached directly. This makes pippenger_cached_data reusable (I use it in a multiexp utility in the seraphis_lib).
  • Exposes ge_p3 versions of the multiexp functions for efficiency when desired.
  • Replaces tabs with spaces in the multiexp notes, so they are legible in text editors that don't render tabs consistently (mine shows all the whitespace in the multiexp notes as single spaces).

@UkoeHB UkoeHB changed the title [seraphis] multiexp: adjust pippenger_cached_data for better reusability [seraphis] ringct: adjust multiexp Dec 14, 2022
rct::key res;
ge_p3_tobytes(res.bytes, &result);
const ge_p3 result_p3 = pippenger_p3(std::move(data), cache, cache_size, c);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since pippenger_p3 takes const&, you can just pass it as is

Copy link
Contributor

@jeffro256 jeffro256 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like both straus and pippenger retain the exact same functionality . Would be nice to have some performance tests comparing the _p3 versions to their counterparts to see the efficiency difference. Besides that, just one minor warning thing.

src/ringct/multiexp.cc Show resolved Hide resolved
src/ringct/multiexp.h Show resolved Hide resolved
@UkoeHB
Copy link
Contributor Author

UkoeHB commented Dec 16, 2022

You can check this perf test: https://github.com/monero-project/monero/blob/master/tests/performance_tests/ge_tobytes.h

It's not significant, but still nice to shave off easy wins like this (iirc sarang was a big fan of avoiding serialization/deserialization ops).

Copy link
Collaborator

@j-berman j-berman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pointing out for other reviewers there's a nice unit test helping make sure pippenger_cached_data retains behavior here:

TEST(multiexp, pippenger_cached)
{
static constexpr size_t N = 256;
std::vector<rct::MultiexpData> P(N);
for (size_t n = 0; n < N; ++n)
{
P[n].scalar = rct::zero();
ASSERT_TRUE(ge_frombytes_vartime(&P[n].point, rct::scalarmultBase(rct::skGen()).bytes) == 0);
}
std::shared_ptr<rct::pippenger_cached_data> cache = rct::pippenger_init_cache(P);
for (size_t n = 0; n < N/16; ++n)
{
std::vector<rct::MultiexpData> data;
size_t sz = 1 + crypto::rand<size_t>() % (N-1);
for (size_t s = 0; s < sz; ++s)
{
data.push_back({rct::skGen(), P[s].point});
}
ASSERT_TRUE(basic(data) == pippenger(data, cache));
}
}

@luigi1111 luigi1111 merged commit ecf0d01 into monero-project:master Apr 25, 2023
@UkoeHB UkoeHB deleted the multiexp_refactor branch May 15, 2023 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants