oasisprotocol / oasis-core

Performant and Confidentiality-Preserving Smart Contracts + Blockchains
https://oasisprotocol.org
Apache License 2.0
332 stars 109 forks source link

size is not the same as degree, but careless doc reader could make mistake #5831

Open bennetyee opened 3 weeks ago

bennetyee commented 3 weeks ago

https://github.com/oasisprotocol/oasis-core/blob/18da8bc49d92a543795246b8bb7fb574df070eec/secret-sharing/src/poly/univariate.rs#L89

because we don't trim high degree zeros, size does not return one more than the degree of the polynomial.

while this is not a bug, it feels like a potential foot gun for careless future users of this code.

peternose commented 3 weeks ago

size does not return one more than the degree of the polynomial.

True. Size returns the size of the underlying vector, which is the same as the number of (zero and non-zero) coefficients in the polynomial. Again avoiding degree to have constant time operations.

    /// Returns the number of coefficients in the polynomial.
    pub fn size(&self) -> usize {