Skip to content

Commit 2787f65

Browse files
nicole-grausjotabulaciosNicoleNicoleColoCarletti
authored
bn254 sqrt and decompression (lambdaclass#905)
* save work * add sqrt for bn254 * compression and decompression for G1 working * save work * g2 decompress working with sqrt input 0 * add random sqrt test * change trait and add documentation * fix bls compression and decompression * fix cargo clippy and check * resolve conversations * decompression check bytes length * decompression checks correct bytes length * fix clippy no default features * fix ubuntu cargo clippy * fix ubuntu clippy * fix errors * fmt * fix clippy * change compress g2 function * check correct input bytes in decompress_g2_point function for bls12 --------- Co-authored-by: jotabulacios <jbulacios@fi.uba.ar> Co-authored-by: Nicole <nicole@Nicoles-Air.fibertel.com.ar> Co-authored-by: Nicole <nicole@Nicoles-MacBook-Air.local> Co-authored-by: Joaquin Carletti <56092489+ColoCarletti@users.noreply.github.com> Co-authored-by: diegokingston <dkingston@fi.uba.ar> Co-authored-by: Diego K <43053772+diegokingston@users.noreply.github.com>
1 parent 28e2cdd commit 2787f65

File tree

8 files changed

+657
-22
lines changed

8 files changed

+657
-22
lines changed

math/Cargo.toml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ license.workspace = true
88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11-
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
12-
serde_json = { version = "1.0", default-features = false, features = ["alloc"], optional = true }
11+
serde = { version = "1.0", default-features = false, features = [
12+
"derive",
13+
], optional = true }
14+
serde_json = { version = "1.0", default-features = false, features = [
15+
"alloc",
16+
], optional = true }
1317
proptest = { version = "1.1.0", optional = true }
1418
winter-math = { package = "winter-math", version = "0.6.4", default-features = false, optional = true }
15-
miden-core = { package = "miden-core" , version = "0.7", default-features = false, optional = true }
19+
miden-core = { package = "miden-core", version = "0.7", default-features = false, optional = true }
1620

1721
# rayon
1822
rayon = { version = "1.7", optional = true }
@@ -28,13 +32,13 @@ cudarc = { version = "0.9.7", optional = true }
2832
lambdaworks-gpu = { workspace = true, optional = true }
2933

3034
[dev-dependencies]
31-
rand = { version = "0.8.5", default-features = false }
35+
rand = { version = "0.8.5", features = ["std"] }
3236
rand_chacha = "0.3.1"
3337
criterion = "0.5.1"
3438
const-random = "0.1.15"
3539
iai-callgrind.workspace = true
3640
proptest = "1.1.0"
37-
pprof = { version = "0.13.0", features = ["criterion","flamegraph"] }
41+
pprof = { version = "0.13.0", features = ["criterion", "flamegraph"] }
3842

3943
[features]
4044
default = ["parallel", "std"]
@@ -97,4 +101,3 @@ harness = false
97101
name = "criterion_metal"
98102
harness = false
99103
required-features = ["metal"]
100-

math/src/elliptic_curve/short_weierstrass/curves/bls12_381/compression.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ impl Compress for BLS12381Curve {
5757
}
5858
}
5959

60-
fn decompress_g1_point(input_bytes: &mut [u8; 48]) -> Result<Self::G1Point, Self::Error> {
60+
fn decompress_g1_point(input_bytes: &mut [u8]) -> Result<Self::G1Point, Self::Error> {
61+
if !input_bytes.len() == 48 {
62+
return Err(ByteConversionError::InvalidValue);
63+
}
6164
let first_byte = input_bytes.first().unwrap();
6265
// We get the 3 most significant bits
6366
let prefix_bits = first_byte >> 5;
@@ -150,7 +153,11 @@ impl Compress for BLS12381Curve {
150153
}
151154
}
152155

153-
fn decompress_g2_point(input_bytes: &mut [u8; 96]) -> Result<Self::G2Point, Self::Error> {
156+
fn decompress_g2_point(input_bytes: &mut [u8]) -> Result<Self::G2Point, Self::Error> {
157+
if !input_bytes.len() == 96 {
158+
return Err(ByteConversionError::InvalidValue);
159+
}
160+
154161
let first_byte = input_bytes.first().unwrap();
155162

156163
// We get the first 3 bits

0 commit comments

Comments
 (0)