@@ -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