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

Cleanup: use associated const rather than const generic to specify Aggregator verify key length #334

Closed
branlwyd opened this issue Oct 13, 2022 · 2 comments

Comments

@branlwyd
Copy link
Contributor

Currently, the length of an Aggregator's verify key length is defined by the const generic L parameter on the Aggregator trait:

pub trait Aggregator<const L: usize>: Vdaf

This works fine, but requires generic code working with the Aggregator to specify L as an explicit const generic in functions that work with an Aggregator<L>; the Rust compiler is not yet clever enough to infer L.

I think we could work around this by instead specifying the verify key length as an associated constant, something like:

pub trait Aggregator: Vdaf {
  const VERIFY_KEY_LEN: usize;
}

Each implementation of the Aggregator trait would then define its verify key length. Concrete VDAF implementations which want to support multiple verify key lengths (which I think is common) can keep the concrete struct implementing Aggregator generic on L, as it already is for e.g. Prio3:

pub struct Prio3<T, P, const L: usize>

Example Rust playground showing this technique: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e4507e8cb4677ffef618304f3ec9d0e4

This suggestion would be a breaking change, so it should be implemented as part of a major version cutover.

@branlwyd
Copy link
Contributor Author

I tried this out in 7b5ae53 and unfortunately got the following error:

error: generic parameters may not be used in const operations
   --> src/vdaf.rs:200:27
    |
200 |         verify_key: &[u8; Self::VERIFY_KEY_LEN],
    |                           ^^^^^^^^^^^^^^^^^^^^ cannot perform const operation using `Self`
    |
    = note: type parameters may not be used in const expressions

Googling finds rust-lang/rust#60551 -- it doesn't look like there's any reason this code couldn't work, the Rust maintainers simply haven't gotten around to stabilizing it yet. :-(

@branlwyd
Copy link
Contributor Author

(closing as infeasible for now, we might try this cleanup again once the above-referenced bug is fixed)

@branlwyd branlwyd closed this as not planned Won't fix, can't repro, duplicate, stale Oct 14, 2022
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