dalek-cryptography / bulletproofs

A pure-Rust implementation of Bulletproofs using Ristretto.
MIT License
1.02k stars 218 forks source link

Derive `Copy` trait for `LinearCombination`. #301

Closed CPerezz closed 4 years ago

CPerezz commented 4 years ago

I haven't been able to find any reason why the Copy trait cannot be derived/implemented for LinearCombination (Security/design reasons mentioned in the repo or something like this).

It would be nice to have it (at least from my POV) since it enables to perform operations like:

  let mut words = vec![LinearCombination::from(Scalar::zero()); width];
  let words_slice = &mut words[1..1 + data.len()];

  words_slice.copy_from_slice(data);

// Instead of doing:
  words_slice.clone_from_slice(data);
// Which performs worse.
oleganza commented 4 years ago

Copy trait is for raw memcpy-ing the bytes. But LinearCombination contains a Vec which owns a pointer to a heap. It is incorrect to attempt to copy such pointer w/o copying the entire vector, hence Vec does not implement Copy and therefore LC also doesn't.

CPerezz commented 4 years ago

@oleganza you're totally right. Idk what I was thinking. Sorry for the inconvenience. Closing the issue.