Comments (10)
from lambdaworks.
I think that you've just found a bug. @MauroToscano @ajgara @schouhy take a look when you can and tell me if I'm mistaken.
I think that you should make the PR with the test passing and file an issue related to this so it can be studied later.
from lambdaworks.
Can i take it?
from lambdaworks.
Can i take it?
Sure, we'd love it!
from lambdaworks.
Hi, thanks! Where should be implemented? in the same math/src/unsigned_integer/element.rs file?
from lambdaworks.
Hello :), in principle, I have done and tested. I defined a new type pub type U256 = UnsignedInteger<4>; (4 limbs * 64 = 256) and the tests for all implemented methods. There is only one test that I cannot pass,related with the multiplication.
Test code failing below:
#[test]
fn mul_two_256_bit_integers_works_4() {
let a = U256::from("15bf61fcf53a3f0ae1e8e555d");
let b = U256::from("cbbc474761bb7995ff54e25fa5d5d0cde405e9f");
let c_expected = U256::from(
"114ec14db0c80d30b7dcb9c45948ef04cc149e612cb544f447b146553aff2ac3",
);
assert_eq!(a * b, c_expected);
}
With error:
mul_two_256_bit_integers_works_4' panicked at 'UnsignedInteger multiplication overflow.'
The fact is if i use the mul
method instead of *
operator the tests passes fine, and if i debug the values there really is no overflow.
Test code passing below:
#[test]
fn mul_two_256_bit_integers_works_4() {
let a = U256::from("15bf61fcf53a3f0ae1e8e555d");
let b = U256::from("cbbc474761bb7995ff54e25fa5d5d0cde405e9f");
let c_expected = U256::from(
"114ec14db0c80d30b7dcb9c45948ef04cc149e612cb544f447b146553aff2ac3",
);
let (overflow, c) = U256::mul(&a, &b);
dbg!(overflow);
dbg!(c);
assert_eq!(c, c_expected);
}
with debug output:
overflow = UnsignedInteger { limbs: [ 0, 0, 0, 0,],}
c = UnsignedInteger {limbs: [1247146686250749232,13248668456779837188,14705552823470605556,5165987579446635203,]}
Question:
As can be seen there is any overflow. Since 'UnsignedInteger' implements the 'Mul' trait, shouldn't the mul
method and the *
operator behave the same?
from lambdaworks.
Hi, thanks! Where should be implemented? in the same math/src/unsigned_integer/element.rs file?
It would be nice to add the line above the U384 definition.
EDIT: It's ok where you put it.
from lambdaworks.
Hello :), in principle, I have done and tested. I defined a new type pub type U256 = UnsignedInteger<4>; (4 limbs * 64 = 256) and the tests for all implemented methods. There is only one test that I cannot pass,related with the multiplication.
Test code failing below:
#[test] fn mul_two_256_bit_integers_works_4() { let a = U256::from("15bf61fcf53a3f0ae1e8e555d"); let b = U256::from("cbbc474761bb7995ff54e25fa5d5d0cde405e9f"); let c_expected = U256::from( "114ec14db0c80d30b7dcb9c45948ef04cc149e612cb544f447b146553aff2ac3", ); assert_eq!(a * b, c_expected); }
With error:
mul_two_256_bit_integers_works_4' panicked at 'UnsignedInteger multiplication overflow.'
The fact is if i use the
mul
method instead of*
operator the tests passes fine, and if i debug the values there really is no overflow.Test code passing below:
#[test] fn mul_two_256_bit_integers_works_4() { let a = U256::from("15bf61fcf53a3f0ae1e8e555d"); let b = U256::from("cbbc474761bb7995ff54e25fa5d5d0cde405e9f"); let c_expected = U256::from( "114ec14db0c80d30b7dcb9c45948ef04cc149e612cb544f447b146553aff2ac3", ); let (overflow, c) = U256::mul(&a, &b); dbg!(overflow); dbg!(c); assert_eq!(c, c_expected); }
with debug output:
overflow = UnsignedInteger { limbs: [ 0, 0, 0, 0,],} c = UnsignedInteger {limbs: [1247146686250749232,13248668456779837188,14705552823470605556,5165987579446635203,]}
Question: As can be seen there is any overflow. Since 'UnsignedInteger' implements the 'Mul' trait, shouldn't the
mul
method and the*
operator behave the same?
To answer your question, if I'm not mistaken, yes. I'll look into this, it could be a nice bug to issue.
Where can I find this code?
from lambdaworks.
Thanks for pointing this out! It should be fixed now. Let us know how it goes!
from lambdaworks.
Resolved in #50
from lambdaworks.
Related Issues (20)
- Polynomial commitment scheme based on IPA HOT 1
- Add subgroup check to pairings HOT 2
- Implement "Efficient Final Exponentiation via Cyclotomic Structure for Pairings over Families of Elliptic Curves" HOT 2
- Error instead of panicking on `inv` function for `FieldElement` HOT 2
- Bn254 Curve HOT 2
- Broken links in Readme HOT 2
- Add GCD as a standalone function HOT 1
- Cairo Prover CLI Improvements
- feat(ci): add just file for easier linting
- Bug: UnsignedInteger reveals the secret value HOT 2
- feat(benchmarks): Benchmark Maintenance
- Bls 12 377 support with pairings
- impl IsUnsignedInteger trait for u8 too HOT 2
- Pedersen Hash
- Rescue Prime Hash
- Followup on #202 from previous repo HOT 1
- bug: MontgomeryBackendPrimeField<N> gives incorrect addition for small limb fields HOT 3
- Cairo Prover: Prove Pure Cairo (non-starknet contract) HOT 5
- Cairo Prover: Prove programs with inputs HOT 4
- Improving Cairo programs with imputs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lambdaworks.