Skip to content

Commit 91ece74

Browse files
committed
Clarify flag bit positions
1 parent ac10277 commit 91ece74

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

soroban-env-common/env.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,7 +2367,7 @@
23672367
{ "name": "point2", "type": "BytesObject" }
23682368
],
23692369
"return": "BytesObject",
2370-
"docs": "Adds two BN254 G1 points. G1 encoding: 64-byte uncompressed format: be_bytes(X)||be_bytes(Y), where X and Y are 32-byte big-endian Fp field elements. The two flag bits (bit 0 and 1) of the first byte must be unset -- infinity is represented as 64 zero bytes. Points must be on curve.",
2370+
"docs": "Adds two BN254 G1 points. G1 encoding: 64-byte uncompressed format: be_bytes(X)||be_bytes(Y), where X and Y are 32-byte big-endian Fp field elements. The two flag bits (0x80 and 0x40) of the first byte must be unset -- infinity is represented as 64 zero bytes. Points must be on curve.",
23712371
"min_supported_protocol": 25
23722372
},
23732373
{
@@ -2389,7 +2389,7 @@
23892389
{ "name": "vp2", "type": "VecObject" }
23902390
],
23912391
"return": "Bool",
2392-
"docs": "Performs BN254 multi-pairing check over equal-length non-empty vectors of G1 and G2 points. Returns true iff the product of pairings e(G1[0],G2[0])*...*e(G1[n-1],G2[n-1]) equals 1 in Fq12. G1 encoding: 64 bytes as in bn254_g1_add. G2 encoding: 128-byte uncompressed format: be_bytes(X)||be_bytes(Y), where X and Y are Fp2 elements (64 bytes each). Fp2 element encoding: be_bytes(c1)||be_bytes(c0) where c0 is the real part and c1 is the imaginary part (each 32-byte big-endian Fp). The two flag bits (bit 0 and 1) of the first byte must be unset -- G2 infinity is 128 zero bytes. G2 points must be on curve AND in the correct subgroup.",
2392+
"docs": "Performs BN254 multi-pairing check over equal-length non-empty vectors of G1 and G2 points. Returns true iff the product of pairings e(G1[0],G2[0])*...*e(G1[n-1],G2[n-1]) equals 1 in Fq12. G1 encoding: 64 bytes as in bn254_g1_add. G2 encoding: 128-byte uncompressed format: be_bytes(X)||be_bytes(Y), where X and Y are Fp2 elements (64 bytes each). Fp2 element encoding: be_bytes(c1)||be_bytes(c0) where c0 is the real part and c1 is the imaginary part (each 32-byte big-endian Fp). The two flag bits (0x80 and 0x40) of the first byte must be unset -- G2 infinity is 128 zero bytes. G2 points must be on curve AND in the correct subgroup.",
23932393
"min_supported_protocol": 25
23942394
},
23952395
{

soroban-env-host/src/crypto/bn254.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ impl Host {
3939

4040
// Arkworks and ethereum differ in terms of how flags are handled.
4141
//
42-
// - In arkworks, the two free bits are reserved for flags: the MSB is the
43-
// Y-sign flag, and the 2nd MSB is the infinity flag
42+
// - In arkworks, the two free bits are reserved for flags: the
43+
// most-significant-bit is the Y-sign flag, and the 2nd
44+
// most-significant-bit is the infinity flag
4445
// - In ethereum, the two free bits are always unset.
4546
//
4647
// Since encoding/decoding is in uncompressed mode (Y is included), there is
@@ -65,6 +66,11 @@ impl Host {
6566
));
6667
}
6768

69+
// The incoming bytes is in big-endian, the sign bits are contained in
70+
// the first byte (for G1Affine that's the MSB of the y-coordinate (Fp),
71+
// for G2Affine that's the MSB of the c1 (Fp) part of the Y-coordinate
72+
// (Fp2)). The highest bit (0x80) is the y-sign flag, the 2nd highest
73+
// bit (0x40) is the infinity flag. We ensure both are unset.
6874
let flags = 0b1100_0000 & bytes[0];
6975
if flags != 0b0000_0000 {
7076
return Err(self.err(

0 commit comments

Comments
 (0)