Skip to content

Commit abbde46

Browse files
committed
Add comment for clearing flags, remove dead code
1 parent a521912 commit abbde46

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

soroban-sdk/src/crypto/bls12_381.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,7 @@ impl Neg for Fp {
206206
1873798617647539866,
207207
]);
208208
// Compute modulus - value
209-
let borrow = res.sub_with_borrow(&fp_bigint);
210-
if borrow {
211-
sdk_panic!("invalid input - Fp is larger than the field modulus")
212-
}
209+
res.sub_with_borrow(&fp_bigint);
213210
let mut bytes = [0u8; 48];
214211
res.copy_into_array(&mut bytes);
215212
Fp::from_array(&self.env(), &bytes)
@@ -230,14 +227,6 @@ impl G1Affine {
230227
}
231228
}
232229

233-
// impl TryFromVal<Env, Val> for G1Affine {
234-
// type Error = ConversionError;
235-
236-
// fn try_from_val(env: &Env, v: &Val) -> Result<Self, Self::Error> {
237-
// Ok(G1Affine(BytesN::try_from_val(env, v)?))
238-
// }
239-
// }
240-
241230
impl Add for G1Affine {
242231
type Output = G1Affine;
243232

soroban-sdk/src/testutils/arbitrary.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,13 @@ mod objects {
697697

698698
fn try_from_val(env: &Env, v: &ArbitraryG1Affine) -> Result<Self, Self::Error> {
699699
let mut bytes = v.bytes;
700-
bytes[0] &= 0b0001_1111; // Clear the top 3 bits
700+
// the top 3 bits in a G1 point are reserved for flags:
701+
// compression_flag (bit 0), infinity_flag (bit 1) and sort_flag
702+
// (bit 2). Only infinity_flag is possible to be set, in which case
703+
// the rest of the bytes must be zeros. The host will reject any
704+
// invalid input. Clearing the flags here just to give it better
705+
// chance of a valid input.
706+
bytes[0] &= 0b0001_1111;
701707
Ok(G1Affine::from_array(env, &bytes))
702708
}
703709
}
@@ -717,7 +723,13 @@ mod objects {
717723

718724
fn try_from_val(env: &Env, v: &ArbitraryG2Affine) -> Result<Self, Self::Error> {
719725
let mut bytes = v.bytes;
720-
bytes[0] &= 0b0001_1111; // Clear the top 3 bits
726+
// the top 3 bits in a G1 point are reserved for flags:
727+
// compression_flag (bit 0), infinity_flag (bit 1) and sort_flag
728+
// (bit 2). Only infinity_flag is possible to be set, in which case
729+
// the rest of the bytes must be zeros. The host will reject any
730+
// invalid input. Clearing the flags here just to give it better
731+
// chance of a valid input.
732+
bytes[0] &= 0b0001_1111;
721733
Ok(G2Affine::from_array(env, &bytes))
722734
}
723735
}

0 commit comments

Comments
 (0)