algebra icon indicating copy to clipboard operation
algebra copied to clipboard

A confusing "conflict implementation" when implementing the curves for customized trait.

Open ChenxingLi opened this issue 4 years ago • 3 comments

I'm trying to implement a trait for a projective curve with the following code

use ark_bls12_381;
use ark_ec::PairingEngine;

pub trait CustomizedTrait {}

impl CustomizedTrait for <ark_bls12_381::Bls12_381 as PairingEngine>::G1Projective {}
impl CustomizedTrait for u64 {}

However, the rust compiler results in an error. It thinks u64 and <Bls12_381 as PairingEngine>::G1Projective are the same type.

error[E0119]: conflicting implementations of trait `CustomizedTrait` for type `u64`:
  --> src\main.rs:31:1
   |
30 | impl CustomizedTrait for <ark_bls12_381::Bls12_381 as PairingEngine>::G1Projective {}
   | ---------------------------------------------------------------------------------- first implementation here
31 | impl CustomizedTrait for u64 {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `u64`

But if I implement the trait for the projective curve directly, every things go well.

use ark_bls12_381;
use ark_ec::PairingEngine;

pub trait CustomizedTrait {}

impl CustomizedTrait for ark_bls12_381::G1Projective {}
impl CustomizedTrait for u64 {}

Have you met this problem when developing such project, especially when implementing the serialization components?

ChenxingLi avatar Jan 21 '21 09:01 ChenxingLi

I think this is a problem with Rust atm, not our libraries; it might be related to lazy normalization. I’ll try to produce an independent example

Pratyush avatar Jan 21 '21 16:01 Pratyush

Is this still an issue with the latest stable?

Pratyush avatar Aug 12 '22 19:08 Pratyush

Is this still an issue with the latest stable?

Yes, this issue still exists with the most recent rust version 1.64.0 and arkworks version 0.3.0.

ChenxingLi avatar Oct 18 '22 09:10 ChenxingLi