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

Double reference in miller_loop #101

Open
burdges opened this issue Mar 27, 2019 · 0 comments
Open

Double reference in miller_loop #101

burdges opened this issue Mar 27, 2019 · 0 comments

Comments

@burdges
Copy link

burdges commented Mar 27, 2019

The function miller_loop takes an IntoIterator<Item = &'a (&'a _, &' _)> which agrees with the IntoIterator for a &Vec<(&_,&_)>, but basically nothing else.

There is no way to construct the outer &'a from iterator adapters, requiring a fresh allocation. Yet, you could easily make any collection work without the outer &'a using .into_iter().map(|t| *t) or |(x,y)| (x,y) or similar. I'd think the G2 prepared points are commonly ephemeral, so this requires two ephemeral data structures, one containing the prepared points, and one containing the references to them, while both sound superfluous.

We cannot wrap the current miller_loop in an interface that takes borrows, but maybe it'd work if miller_loop took them directly, so maybe try

fn miller_loop<I,P1,P2>(i: I) -> Self::Fqk
where
    I: IntoIterator<Item=(P1,P2)>,
    P1: Borrow<<Self::G1Affine as CurveAffine>::Prepared>,
    P2: Borrow<<Self::G2Affine as CurveAffine>::Prepared>,

You could make Item: Borrow<(P1,P2)> too if you wanted backwards compatibility with the current interface, but I'd make callers use .into_iter().map(|t| *t) here myself.

In fact, you allocate internally anyways, so maybe one should favor &[P1,P2] over the iterator anyways, not sure.

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

No branches or pull requests

1 participant