Coder Social home page Coder Social logo

Comments (3)

xJonathanLEI avatar xJonathanLEI commented on August 15, 2024

Sorry but some of these have already been answered in #446, an issue submitted by yourself. I prefer not to waste my time answering in this case.

from starknet-rs.

satoshiotomakan avatar satoshiotomakan commented on August 15, 2024

@xJonathanLEI sorry for the duplicates, my mistake.

from starknet-rs.

xJonathanLEI avatar xJonathanLEI commented on August 15, 2024

Unwraps:

FieldElement::from_bytes_be(&result).unwrap()

modulus is a FieldElement, and result is mod modulus. So result is always a valid FieldElement.

FieldElement::from_bytes_be(&result).unwrap()

result is always smaller than modulus, which is a valid FieldElement itself.

pub fn double_assign(&mut self) {
if self.infinity {
return;
}
// l = (3x^2+a)/2y with a=1 from stark curve
let lambda = {
let dividend = FieldElement::THREE * (self.x * self.x) + FieldElement::ONE;
let divisor_inv = (FieldElement::TWO * self.y).invert().unwrap();
dividend * divisor_inv
};
let result_x = (lambda * lambda) - self.x - self.x;
self.y = lambda * (self.x - result_x) - self.y;
self.x = result_x;
}

I'm actually not sure about this. This seems to panic when self.y is zero.

pub fn from_dec_str(value: &str) -> Result<Self, FromStrError> {
// Ported from:
// https://github.com/paritytech/parity-common/blob/b37d0b312d39fa47c61c4430b30ca87d90e45a08/uint/src/uint.rs#L599
let mut res = U256::ZERO;
for b in value.bytes().map(|b| b.wrapping_sub(b'0')) {
if b > 9 {
return Err(FromStrError::InvalidCharacter);
}
let r = {
let product = res.checked_mul(&U256::from_u8(10));
if product.is_some().into() {
product.unwrap()
} else {
return Err(FromStrError::OutOfRange);
}
};
let r = {
let sum = r.checked_add(&U256::from_u8(b));
if sum.is_some().into() {
sum.unwrap()
} else {
return Err(FromStrError::OutOfRange);
}
};
res = r;
}

We already checked for is_some before unwrapping. It's safe.

Panics:

} else {
// TODO: add `checked_floor_div` for panic-less use
panic!("division by zero");
}

As mentioned in the comment, panicking on division by zero is the expected behavior, similar to how division by zero panics for any other types.

from starknet-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.