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

Support impl Trait in attribute name interpolation #1313

Open
jschneider-bensch opened this issue Feb 17, 2025 · 2 comments
Open

Support impl Trait in attribute name interpolation #1313

jschneider-bensch opened this issue Feb 17, 2025 · 2 comments
Labels
attributes workaround This bug has a workaround

Comments

@jschneider-bensch
Copy link
Contributor

If we have a signature like this

pub(crate) fn kem_keygen(
    alg: KemScheme,
    rng: &mut (impl CryptoRng + RngCore),
) -> Result<(KemSk, KemPk), TLSError>

it would be good to be able to refer to $:{impl CryptoRng + RngCore) when using e.g. proverif::replace.

@W95Psp
Copy link
Collaborator

W95Psp commented Feb 17, 2025

I think you can use the following as workaround:

pub(crate) fn kem_keygen<R: CryptoRng + RngCore>(
    alg: KemScheme,
    rng: &mut R,
) -> Result<(KemSk, KemPk), TLSError>

Then you'll be able to use $:{R}.

Example in the playground:

trait Rng {}

fn f<T: Rng>(rng: &mut T) {
    hax_lib::proverif!("$:{T}");
}

Open this code snippet in the playground

@W95Psp W95Psp added the workaround This bug has a workaround label Feb 17, 2025
@jschneider-bensch
Copy link
Contributor Author

jschneider-bensch commented Feb 17, 2025

This should work, at least for cases where only the impl trait is passed around:

trait Rng {}

fn f<T: Rng>(rng: &mut T) {
    hax_lib::proverif!("$:{T}");
}

fn g<T: Rng>(rng: &mut T) {
    f(rng)
}

Playground

ProVerif needs the types to have the same names, so it wouldn't work if we actually instantiate the type:

trait Rng {}

fn f<T: Rng>(rng: &mut T) {
    hax_lib::proverif!("$:{T}");
}

fn g<T: Rng>(rng: &mut T) {
    f(rng)
}

struct R;
impl Rng for R {}

fn h() {
    g(&mut R)
}

Playground

Here, the concrete type is playground__t_R which PV won't be able to match to v_T.

The other issue is that the PV backend does not yet do it's translation of Rust types to PV types for generics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
attributes workaround This bug has a workaround
Projects
None yet
Development

No branches or pull requests

2 participants