Quellcode durchsuchen

SIMD-0284: Add little-endian compatibility for alt_bn128 (#8771)

* SIMD-0284: Add little-endian compatibility for alt_bn128

* add tests for little-endian
samkim-crypto vor 3 Wochen
Ursprung
Commit
0356684899

+ 9 - 0
feature-set/src/lib.rs

@@ -173,6 +173,7 @@ impl FeatureSet {
             poseidon_enforce_padding: self.is_active(&poseidon_enforce_padding::id()),
             fix_alt_bn128_pairing_length_check: self
                 .is_active(&fix_alt_bn128_pairing_length_check::id()),
+            alt_bn128_little_endian: self.is_active(&alt_bn128_little_endian::id()),
         }
     }
 }
@@ -1199,6 +1200,10 @@ pub mod replace_spl_token_with_p_token {
         Pubkey::from_str_const("ptokNfvuU7terQ2r2452RzVXB3o4GT33yPWo1fUkkZ2");
 }
 
+pub mod alt_bn128_little_endian {
+    solana_pubkey::declare_id!("bnS3pWfLrxHRJvMyLm6EaYQkP7A2Fe9DxoKv4aGA8YM");
+}
+
 pub static FEATURE_NAMES: LazyLock<AHashMap<Pubkey, &'static str>> = LazyLock::new(|| {
     [
         (secp256k1_program_enabled::id(), "secp256k1 program"),
@@ -2150,6 +2155,10 @@ pub static FEATURE_NAMES: LazyLock<AHashMap<Pubkey, &'static str>> = LazyLock::n
             replace_spl_token_with_p_token::id(),
             "SIMD-0266: Efficient Token program",
         ),
+        (
+            alt_bn128_little_endian::id(),
+            "SIMD-0284: Add little-endian compatibility for alt_bn128",
+        ),
         /*************** ADD NEW FEATURES HERE ***************/
     ]
     .iter()

+ 92 - 39
programs/sbf/rust/alt_bn128/src/lib.rs

@@ -2,13 +2,14 @@
 
 use {
     solana_bn254::prelude::{
-        alt_bn128_g1_addition_be, alt_bn128_g1_multiplication_be, alt_bn128_pairing_be,
+        alt_bn128_g1_addition_be, alt_bn128_g1_addition_le, alt_bn128_g1_multiplication_be,
+        alt_bn128_g1_multiplication_le, alt_bn128_pairing_be, alt_bn128_pairing_le,
     },
     solana_msg::msg,
     solana_program_entrypoint::{custom_heap_default, custom_panic_default},
 };
 
-fn alt_bn128_addition_test() {
+fn alt_bn128_addition_be_test() {
     // chfast1
     let result = alt_bn128_g1_addition_be(&[
         0x18, 0xb1, 0x8a, 0xcf, 0xb4, 0xc2, 0xc3, 0x2, 0x76, 0xdb, 0x54, 0x11, 0x36, 0x8e, 0x71,
@@ -239,7 +240,32 @@ fn alt_bn128_addition_test() {
     ); // 15bf2bb17880144b5d1cd2b1f46eff9d617bffd1ca57c37fb5a49bd84e53cf66049c797f9ce0d17083deb32b5e36f2ea2a212ee036598dd7624c168993d1355f
 }
 
-fn alt_bn128_multiplication_test() {
+fn alt_bn128_addition_le_test() {
+    let result = alt_bn128_g1_addition_le(&[
+        0xc9, 0x3d, 0x9, 0x4e, 0x3, 0x74, 0x3b, 0x5d, 0xc, 0x61, 0x91, 0x46, 0x12, 0xdd, 0x11,
+        0xb3, 0x85, 0x71, 0x8e, 0x36, 0x11, 0x54, 0xdb, 0x76, 0x2, 0xc3, 0xc2, 0xb4, 0xcf, 0x8a,
+        0xb1, 0x18, 0x66, 0x72, 0xf3, 0x98, 0x81, 0x28, 0xd, 0xfc, 0x2e, 0xd3, 0x58, 0x96, 0x81,
+        0x96, 0x57, 0x75, 0x49, 0xa7, 0x9f, 0xf5, 0xb9, 0x4c, 0x13, 0xb5, 0xc, 0x84, 0x20, 0x47,
+        0x9c, 0x90, 0x3c, 0x6, 0xed, 0x4e, 0x1, 0x6a, 0x7c, 0x9e, 0x1, 0x88, 0x3a, 0x96, 0x92,
+        0x2c, 0xff, 0x20, 0x7f, 0x18, 0x1a, 0xbb, 0xc0, 0x2b, 0x9c, 0xc, 0xf0, 0x45, 0x61, 0xbd,
+        0x84, 0x8a, 0xf5, 0xb7, 0xc2, 0x7, 0xd7, 0x17, 0xfa, 0x78, 0x84, 0x78, 0xd6, 0x2b, 0x74,
+        0x5c, 0x48, 0xa4, 0x6, 0x17, 0x36, 0xdf, 0x17, 0x9a, 0x4c, 0xf7, 0xa3, 0xd, 0xd7, 0xf2,
+        0x40, 0xe9, 0x47, 0xc1, 0x20, 0x4e, 0x61, 0x6,
+    ]);
+    assert!(result.is_ok());
+    assert_eq!(
+        result.unwrap(),
+        &[
+            0x3, 0x97, 0x83, 0x2, 0xe2, 0xae, 0xee, 0xa1, 0x5f, 0xb6, 0xe6, 0x4c, 0xa, 0x83, 0x5e,
+            0xd8, 0x4d, 0xfe, 0xa3, 0xc, 0xac, 0x45, 0x3c, 0x3d, 0x9c, 0x4b, 0xfd, 0x5e, 0x5c,
+            0x52, 0x43, 0x22, 0x15, 0xc9, 0x95, 0xf1, 0x48, 0x7d, 0x5e, 0xae, 0xb9, 0x7d, 0x53,
+            0x32, 0x75, 0xed, 0xe, 0x18, 0x23, 0x47, 0x96, 0x35, 0xcc, 0x21, 0xdf, 0x9, 0xe5, 0xa8,
+            0x6d, 0xbe, 0x33, 0x1d, 0x1d, 0x30,
+        ]
+    );
+}
+
+fn alt_bn128_multiplication_be_test() {
     // chfast1
     let result = alt_bn128_g1_multiplication_be(&[
         0x2b, 0xd3, 0xe6, 0xd0, 0xf3, 0xb1, 0x42, 0x92, 0x4f, 0x5c, 0xa7, 0xb4, 0x9c, 0xe5, 0xb9,
@@ -637,7 +663,30 @@ fn alt_bn128_multiplication_test() {
     ); // 039730ea8dff1254c0fee9c0ea777d29a9c710b7e616683f194f18c43b43b869073a5ffcc6fc7a28c30723d6e58ce577356982d65b833a5a5c15bf9024b43d98
 }
 
-fn alt_bn128_pairing_test() {
+fn alt_bn128_multiplication_le_test() {
+    let result = alt_bn128_g1_multiplication_le(&[
+        0xb7, 0x9f, 0xa, 0x1a, 0x8b, 0x26, 0x2, 0x1d, 0xe6, 0x48, 0x56, 0xae, 0xd7, 0x3, 0x47,
+        0x4c, 0xd5, 0xb9, 0xe5, 0x9c, 0xb4, 0xa7, 0x5c, 0x4f, 0x92, 0x42, 0xb1, 0xf3, 0xd0, 0xe6,
+        0xd3, 0x2b, 0x4, 0xb2, 0xfd, 0xce, 0x66, 0xae, 0xc, 0x39, 0xc8, 0x19, 0x46, 0x4a, 0xad,
+        0xdf, 0x49, 0x2e, 0xce, 0x9, 0x9, 0x30, 0x70, 0x1d, 0x2f, 0x5e, 0x91, 0x85, 0xaf, 0xa6,
+        0xe0, 0x1c, 0x61, 0x21, 0xc2, 0x15, 0xfa, 0x50, 0xe7, 0x8c, 0x13, 0x11, 0x0, 0x0, 0x0, 0x0,
+        0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+        0x0, 0x0,
+    ]);
+    assert!(result.is_ok());
+    assert_eq!(
+        result.unwrap(),
+        &[
+            0x5c, 0x1e, 0xc3, 0x13, 0x9c, 0x6c, 0x2a, 0xee, 0xa4, 0xf5, 0x53, 0xa0, 0x74, 0xb2,
+            0x47, 0x8a, 0xef, 0xfa, 0xe8, 0x34, 0xd4, 0x29, 0xbe, 0xe4, 0xca, 0x53, 0x21, 0x98,
+            0x6a, 0x8d, 0xa, 0x7, 0xfc, 0x1a, 0x98, 0xc6, 0xce, 0xc3, 0xe, 0x69, 0x15, 0xf3, 0xf0,
+            0xf4, 0x4b, 0x7, 0x43, 0x19, 0xf0, 0xb0, 0xd5, 0xcd, 0xf9, 0x89, 0xb9, 0xff, 0xa9,
+            0xa3, 0xeb, 0x14, 0xe9, 0x8c, 0x1b, 0x3,
+        ]
+    );
+}
+
+fn alt_bn128_pairing_be_test() {
     // jeff1
     let result = alt_bn128_pairing_be(&[
         0x1c, 0x76, 0x47, 0x6f, 0x4d, 0xef, 0x4b, 0xb9, 0x45, 0x41, 0xd5, 0x7e, 0xbb, 0xa1, 0x19,
@@ -675,53 +724,57 @@ fn alt_bn128_pairing_test() {
             0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1
         ]
     ); // 0000000000000000000000000000000000000000000000000000000000000001
+}
 
-    // jeff2
-    let result = alt_bn128_pairing_be(&[
-        0x2e, 0xca, 0xc, 0x72, 0x38, 0xbf, 0x16, 0xe8, 0x3e, 0x7a, 0x1e, 0x6c, 0x5d, 0x49, 0x54,
-        0x6, 0x85, 0xff, 0x51, 0x38, 0xf, 0x30, 0x98, 0x42, 0xa9, 0x85, 0x61, 0x55, 0x80, 0x19,
-        0xfc, 0x2, 0x3, 0xd3, 0x26, 0x3, 0x61, 0xbb, 0x84, 0x51, 0xde, 0x5f, 0xf5, 0xec, 0xd1,
-        0x7f, 0x1, 0xf, 0xf2, 0x2f, 0x5c, 0x31, 0xcd, 0xf1, 0x84, 0xe9, 0x2, 0xb, 0x6, 0xfa, 0x59,
-        0x97, 0xdb, 0x84, 0x12, 0x13, 0xd2, 0x14, 0x9b, 0x0, 0x61, 0x37, 0xfc, 0xfb, 0x23, 0x3,
-        0x66, 0x6, 0xf8, 0x48, 0xd6, 0x38, 0xd5, 0x76, 0xa1, 0x20, 0xca, 0x98, 0x1b, 0x5b, 0x1a,
-        0x5f, 0x93, 0x0, 0xb3, 0xee, 0x22, 0x76, 0xcf, 0x73, 0xc, 0xf4, 0x93, 0xcd, 0x95, 0xd6,
-        0x46, 0x77, 0xbb, 0xb7, 0x5f, 0xc4, 0x2d, 0xb7, 0x25, 0x13, 0xa4, 0xc1, 0xe3, 0x87, 0xb4,
-        0x76, 0xd0, 0x56, 0xf8, 0xa, 0xa7, 0x5f, 0x21, 0xee, 0x62, 0x26, 0xd3, 0x14, 0x26, 0x32,
-        0x2a, 0xfc, 0xda, 0x62, 0x14, 0x64, 0xd0, 0x61, 0x1d, 0x22, 0x67, 0x83, 0x26, 0x2e, 0x21,
-        0xbb, 0x3b, 0xc8, 0x6b, 0x53, 0x7e, 0x98, 0x62, 0x37, 0x9, 0x6d, 0xf1, 0xf8, 0x2d, 0xff,
-        0x33, 0x7d, 0xd5, 0x97, 0x2e, 0x32, 0xa8, 0xad, 0x43, 0xe2, 0x8a, 0x78, 0xa9, 0x6a, 0x82,
-        0x3e, 0xf1, 0xcd, 0x4d, 0xeb, 0xe1, 0x2b, 0x65, 0x52, 0xea, 0x5f, 0x6, 0x96, 0x7a, 0x12,
-        0x37, 0xeb, 0xfe, 0xca, 0x9a, 0xaa, 0xe0, 0xd6, 0xd0, 0xba, 0xb8, 0xe2, 0x8c, 0x19, 0x8c,
-        0x5a, 0x33, 0x9e, 0xf8, 0xa2, 0x40, 0x7e, 0x31, 0xcd, 0xac, 0x51, 0x6d, 0xb9, 0x22, 0x16,
-        0xf, 0xa2, 0x57, 0xa5, 0xfd, 0x5b, 0x28, 0x6, 0x42, 0xff, 0x47, 0xb6, 0x5e, 0xca, 0x77,
-        0xe6, 0x26, 0xcb, 0x68, 0x5c, 0x84, 0xfa, 0x6d, 0x3b, 0x68, 0x82, 0xa2, 0x83, 0xdd, 0xd1,
-        0x19, 0x8e, 0x93, 0x93, 0x92, 0xd, 0x48, 0x3a, 0x72, 0x60, 0xbf, 0xb7, 0x31, 0xfb, 0x5d,
-        0x25, 0xf1, 0xaa, 0x49, 0x33, 0x35, 0xa9, 0xe7, 0x12, 0x97, 0xe4, 0x85, 0xb7, 0xae, 0xf3,
-        0x12, 0xc2, 0x18, 0x0, 0xde, 0xef, 0x12, 0x1f, 0x1e, 0x76, 0x42, 0x6a, 0x0, 0x66, 0x5e,
-        0x5c, 0x44, 0x79, 0x67, 0x43, 0x22, 0xd4, 0xf7, 0x5e, 0xda, 0xdd, 0x46, 0xde, 0xbd, 0x5c,
-        0xd9, 0x92, 0xf6, 0xed, 0x9, 0x6, 0x89, 0xd0, 0x58, 0x5f, 0xf0, 0x75, 0xec, 0x9e, 0x99,
-        0xad, 0x69, 0xc, 0x33, 0x95, 0xbc, 0x4b, 0x31, 0x33, 0x70, 0xb3, 0x8e, 0xf3, 0x55, 0xac,
-        0xda, 0xdc, 0xd1, 0x22, 0x97, 0x5b, 0x12, 0xc8, 0x5e, 0xa5, 0xdb, 0x8c, 0x6d, 0xeb, 0x4a,
-        0xab, 0x71, 0x80, 0x8d, 0xcb, 0x40, 0x8f, 0xe3, 0xd1, 0xe7, 0x69, 0xc, 0x43, 0xd3, 0x7b,
-        0x4c, 0xe6, 0xcc, 0x1, 0x66, 0xfa, 0x7d, 0xaa,
-    ]); // 2eca0c7238bf16e83e7a1e6c5d49540685ff51380f309842a98561558019fc0203d3260361bb8451de5ff5ecd17f010ff22f5c31cdf184e9020b06fa5997db841213d2149b006137fcfb23036606f848d638d576a120ca981b5b1a5f9300b3ee2276cf730cf493cd95d64677bbb75fc42db72513a4c1e387b476d056f80aa75f21ee6226d31426322afcda621464d0611d226783262e21bb3bc86b537e986237096df1f82dff337dd5972e32a8ad43e28a78a96a823ef1cd4debe12b6552ea5f06967a1237ebfeca9aaae0d6d0bab8e28c198c5a339ef8a2407e31cdac516db922160fa257a5fd5b280642ff47b65eca77e626cb685c84fa6d3b6882a283ddd1198e9393920d483a7260bfb731fb5d25f1aa493335a9e71297e485b7aef312c21800deef121f1e76426a00665e5c4479674322d4f75edadd46debd5cd992f6ed090689d0585ff075ec9e99ad690c3395bc4b313370b38ef355acdadcd122975b12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa
+fn alt_bn128_pairing_le_test() {
+    let result = alt_bn128_pairing_le(&[
+        0x59, 0x3f, 0xc4, 0x24, 0x60, 0xc1, 0x31, 0xdd, 0x64, 0xa6, 0xad, 0x76, 0xaa, 0xa7, 0xff,
+        0x81, 0x33, 0x19, 0xa1, 0xbb, 0x7e, 0xd5, 0x41, 0x45, 0xb9, 0x4b, 0xef, 0x4d, 0x6f, 0x47,
+        0x76, 0x1c, 0x41, 0xef, 0x6a, 0xa7, 0x3, 0x9b, 0x5c, 0xe4, 0x94, 0xd2, 0xe9, 0xd3, 0x55,
+        0x9b, 0x81, 0xfc, 0x45, 0x87, 0x67, 0x1c, 0x81, 0xe2, 0xfe, 0x4, 0xe2, 0x73, 0xf6, 0x20,
+        0x29, 0xdd, 0x34, 0x30, 0x78, 0x16, 0xa4, 0x15, 0x63, 0x4b, 0xaf, 0x49, 0x40, 0xc0, 0x8a,
+        0x4c, 0x11, 0x60, 0x59, 0x90, 0x28, 0x8d, 0x84, 0x61, 0x35, 0xb4, 0x34, 0x8b, 0xfa, 0x3b,
+        0x48, 0x1, 0xca, 0x11, 0xbf, 0x4, 0xf7, 0x5b, 0xa3, 0x3, 0x20, 0x45, 0x4a, 0x6b, 0x39,
+        0x14, 0x35, 0xc6, 0x36, 0x96, 0x32, 0xa7, 0x99, 0xcf, 0x93, 0x1a, 0xe5, 0x88, 0xd8, 0x4b,
+        0x6c, 0xd4, 0xf5, 0xbf, 0x5e, 0xd1, 0x9d, 0x20, 0x50, 0x75, 0x87, 0xde, 0xe4, 0xe5, 0x5f,
+        0x16, 0x48, 0xb0, 0x9b, 0xc, 0x1f, 0xe6, 0xcc, 0xa2, 0x7e, 0xe0, 0x39, 0xfe, 0xc6, 0x20,
+        0x5f, 0x84, 0xf9, 0x1b, 0xc, 0xf3, 0x4c, 0x2a, 0xa, 0x12, 0x4d, 0x34, 0xbe, 0x51, 0x2a,
+        0x3c, 0x93, 0xbf, 0xad, 0x1f, 0xc4, 0x7a, 0xcd, 0x1a, 0xa7, 0xa2, 0xc, 0xfd, 0x5c, 0x44,
+        0x1a, 0xad, 0xa2, 0x37, 0x35, 0xc9, 0xcf, 0xf6, 0x4a, 0x32, 0xb8, 0x2b, 0x7c, 0xdf, 0xb6,
+        0xd1, 0x49, 0xde, 0x22, 0xc3, 0xea, 0xcb, 0xf1, 0x6f, 0x3c, 0x2, 0xa2, 0x5b, 0xfa, 0xcd,
+        0xf, 0xc7, 0x4a, 0x1c, 0xd4, 0x10, 0x77, 0x9, 0xf1, 0x1c, 0x9f, 0x12, 0x1e, 0x11, 0x11,
+        0xf4, 0x6b, 0x6a, 0xce, 0xfa, 0x53, 0x38, 0xa7, 0x70, 0x38, 0xb9, 0x85, 0x35, 0x88, 0xa2,
+        0xfc, 0x42, 0xf2, 0x2b, 0x46, 0xe9, 0x6d, 0x28, 0x17, 0x3c, 0xe, 0x83, 0x1a, 0xc6, 0x32,
+        0x20, 0xed, 0xf6, 0x92, 0xd9, 0x5c, 0xbd, 0xde, 0x46, 0xdd, 0xda, 0x5e, 0xf7, 0xd4, 0x22,
+        0x43, 0x67, 0x79, 0x44, 0x5c, 0x5e, 0x66, 0x0, 0x6a, 0x42, 0x76, 0x1e, 0x1f, 0x12, 0xef,
+        0xde, 0x0, 0x18, 0xc2, 0x12, 0xf3, 0xae, 0xb7, 0x85, 0xe4, 0x97, 0x12, 0xe7, 0xa9, 0x35,
+        0x33, 0x49, 0xaa, 0xf1, 0x25, 0x5d, 0xfb, 0x31, 0xb7, 0xbf, 0x60, 0x72, 0x3a, 0x48, 0xd,
+        0x92, 0x93, 0x93, 0x8e, 0x19, 0xaa, 0x7d, 0xfa, 0x66, 0x1, 0xcc, 0xe6, 0x4c, 0x7b, 0xd3,
+        0x43, 0xc, 0x69, 0xe7, 0xd1, 0xe3, 0x8f, 0x40, 0xcb, 0x8d, 0x80, 0x71, 0xab, 0x4a, 0xeb,
+        0x6d, 0x8c, 0xdb, 0xa5, 0x5e, 0xc8, 0x12, 0x5b, 0x97, 0x22, 0xd1, 0xdc, 0xda, 0xac, 0x55,
+        0xf3, 0x8e, 0xb3, 0x70, 0x33, 0x31, 0x4b, 0xbc, 0x95, 0x33, 0xc, 0x69, 0xad, 0x99, 0x9e,
+        0xec, 0x75, 0xf0, 0x5f, 0x58, 0xd0, 0x89, 0x6, 0x9,
+    ]);
     assert!(result.is_ok());
     assert_eq!(
         result.unwrap(),
         &[
-            0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
-            0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1
+            0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+            0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
         ]
-    ); // 0000000000000000000000000000000000000000000000000000000000000001
+    );
 }
 
 #[no_mangle]
 pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
     msg!("alt_bn128");
 
-    alt_bn128_addition_test();
-    alt_bn128_multiplication_test();
-    alt_bn128_pairing_test();
+    alt_bn128_addition_be_test();
+    alt_bn128_addition_le_test();
+    alt_bn128_multiplication_be_test();
+    alt_bn128_multiplication_le_test();
+    alt_bn128_pairing_be_test();
+    alt_bn128_pairing_le_test();
 
     0
 }

+ 68 - 12
programs/sbf/rust/alt_bn128_compression/src/lib.rs

@@ -2,14 +2,15 @@
 
 use {
     solana_bn254::compression::prelude::{
-        alt_bn128_g1_compress, alt_bn128_g1_decompress, alt_bn128_g2_compress,
-        alt_bn128_g2_decompress,
+        alt_bn128_g1_compress, alt_bn128_g1_compress_le, alt_bn128_g1_decompress,
+        alt_bn128_g1_decompress_le, alt_bn128_g2_compress, alt_bn128_g2_compress_le,
+        alt_bn128_g2_decompress, alt_bn128_g2_decompress_le,
     },
     solana_msg::msg,
     solana_program_entrypoint::{custom_heap_default, custom_panic_default},
 };
 
-fn alt_bn128_compression_g1() {
+fn alt_bn128_compression_g1_be() {
     let points_g1: [[u8; 64]; 3] = [
         [
             45, 206, 255, 166, 152, 55, 128, 138, 79, 217, 145, 164, 25, 74, 120, 234, 234, 217,
@@ -26,13 +27,36 @@ fn alt_bn128_compression_g1() {
         [0u8; 64],
     ];
     points_g1.iter().for_each(|point| {
-        let g1_compressed = alt_bn128_g1_compress(point).unwrap();
-        let g1_decompressed = alt_bn128_g1_decompress(&g1_compressed).unwrap();
-        assert_eq!(*point, g1_decompressed);
+        let g1_compressed_be = alt_bn128_g1_compress(point).unwrap();
+        let g1_decompressed_be = alt_bn128_g1_decompress(&g1_compressed_be).unwrap();
+        assert_eq!(*point, g1_decompressed_be);
     });
 }
 
-fn alt_bn128_compression_g2() {
+fn alt_bn128_compression_g1_le() {
+    let points_g1: [[u8; 64]; 3] = [
+        [
+            172, 168, 98, 175, 44, 12, 205, 184, 120, 133, 44, 162, 149, 68, 217, 234, 234, 120,
+            74, 25, 164, 145, 217, 79, 138, 128, 55, 152, 166, 255, 206, 45, 84, 193, 81, 42, 122,
+            218, 191, 243, 254, 32, 8, 148, 104, 218, 202, 209, 151, 245, 219, 123, 101, 90, 236,
+            147, 75, 106, 175, 209, 15, 216, 24, 20,
+        ],
+        [
+            172, 168, 98, 175, 44, 12, 205, 184, 120, 133, 44, 162, 149, 68, 217, 234, 234, 120,
+            74, 25, 164, 145, 217, 79, 138, 128, 55, 152, 166, 255, 206, 45, 243, 59, 43, 174, 156,
+            177, 96, 72, 142, 169, 105, 212, 40, 144, 182, 197, 197, 98, 165, 5, 81, 235, 99, 36,
+            222, 53, 130, 15, 99, 118, 75, 28,
+        ],
+        [0u8; 64],
+    ];
+    points_g1.iter().for_each(|point| {
+        let g1_compressed_le = alt_bn128_g1_compress_le(point).unwrap();
+        let g1_decompressed_le = alt_bn128_g1_decompress_le(&g1_compressed_le).unwrap();
+        assert_eq!(*point, g1_decompressed_le);
+    });
+}
+
+fn alt_bn128_compression_g2_be() {
     let points_g2: [[u8; 128]; 3] = [
         [
             40, 57, 233, 205, 180, 46, 35, 111, 215, 5, 23, 93, 12, 71, 118, 225, 7, 46, 247, 147,
@@ -55,17 +79,49 @@ fn alt_bn128_compression_g2() {
         [0u8; 128],
     ];
     points_g2.iter().for_each(|point| {
-        let g2_compressed = alt_bn128_g2_compress(point).unwrap();
-        let g2_decompressed = alt_bn128_g2_decompress(&g2_compressed).unwrap();
-        assert_eq!(*point, g2_decompressed);
+        let g2_compressed_be = alt_bn128_g2_compress(point).unwrap();
+        let g2_decompressed_be = alt_bn128_g2_decompress(&g2_compressed_be).unwrap();
+        assert_eq!(*point, g2_decompressed_be);
     });
 }
+
+fn alt_bn128_compression_g2_le() {
+    let points_g2: [[u8; 128]; 3] = [
+        [
+            56, 176, 86, 18, 168, 81, 174, 75, 159, 92, 196, 168, 183, 205, 137, 17, 209, 133, 189,
+            236, 151, 238, 180, 66, 212, 151, 34, 110, 176, 124, 203, 0, 25, 242, 52, 141, 103,
+            146, 80, 184, 189, 106, 130, 47, 147, 247, 46, 7, 225, 118, 71, 12, 93, 23, 5, 215,
+            111, 35, 46, 180, 205, 233, 57, 40, 18, 152, 147, 62, 189, 19, 17, 90, 174, 147, 144,
+            60, 91, 177, 200, 22, 245, 3, 211, 247, 49, 94, 131, 218, 100, 254, 246, 80, 6, 168,
+            129, 14, 22, 4, 108, 174, 147, 88, 183, 79, 31, 228, 109, 33, 15, 182, 130, 50, 253,
+            21, 141, 98, 169, 251, 62, 104, 142, 122, 81, 18, 20, 210, 26, 16,
+        ],
+        [
+            56, 176, 86, 18, 168, 81, 174, 75, 159, 92, 196, 168, 183, 205, 137, 17, 209, 133, 189,
+            236, 151, 238, 180, 66, 212, 151, 34, 110, 176, 124, 203, 0, 25, 242, 52, 141, 103,
+            146, 80, 184, 189, 106, 130, 47, 147, 247, 46, 7, 225, 118, 71, 12, 93, 23, 5, 215,
+            111, 35, 46, 180, 205, 233, 57, 40, 53, 101, 233, 153, 89, 120, 15, 226, 222, 54, 225,
+            43, 54, 185, 184, 128, 104, 84, 174, 137, 132, 231, 204, 221, 196, 161, 58, 144, 108,
+            166, 226, 33, 49, 249, 16, 42, 131, 51, 105, 236, 109, 230, 3, 71, 130, 180, 254, 100,
+            96, 66, 244, 30, 13, 74, 17, 80, 155, 37, 224, 206, 94, 124, 73, 32,
+        ],
+        [0u8; 128],
+    ];
+    points_g2.iter().for_each(|point| {
+        let g2_compressed_le = alt_bn128_g2_compress_le(point).unwrap();
+        let g2_decompressed_le = alt_bn128_g2_decompress_le(&g2_compressed_le).unwrap();
+        assert_eq!(*point, g2_decompressed_le);
+    });
+}
+
 #[no_mangle]
 pub extern "C" fn entrypoint(_input: *mut u8) -> u64 {
     msg!("alt_bn128_compression");
 
-    alt_bn128_compression_g1();
-    alt_bn128_compression_g2();
+    alt_bn128_compression_g1_be();
+    alt_bn128_compression_g1_le();
+    alt_bn128_compression_g2_be();
+    alt_bn128_compression_g2_le();
     0
 }
 

+ 2 - 0
svm-feature-set/src/lib.rs

@@ -51,6 +51,7 @@ pub struct SVMFeatureSet {
     pub vote_state_v4: bool,
     pub poseidon_enforce_padding: bool,
     pub fix_alt_bn128_pairing_length_check: bool,
+    pub alt_bn128_little_endian: bool,
 }
 
 impl SVMFeatureSet {
@@ -98,6 +99,7 @@ impl SVMFeatureSet {
             vote_state_v4: true,
             poseidon_enforce_padding: true,
             fix_alt_bn128_pairing_length_check: true,
+            alt_bn128_little_endian: true,
         }
     }
 }

+ 83 - 12
syscalls/src/lib.rs

@@ -1573,20 +1573,21 @@ declare_builtin_function!(
             VersionedG1Multiplication, VersionedPairing, ALT_BN128_ADDITION_OUTPUT_SIZE,
             ALT_BN128_G1_ADD_BE, ALT_BN128_G1_MUL_BE, ALT_BN128_MULTIPLICATION_OUTPUT_SIZE,
             ALT_BN128_PAIRING_BE, ALT_BN128_PAIRING_ELEMENT_SIZE,
-            ALT_BN128_PAIRING_OUTPUT_SIZE,
+            ALT_BN128_PAIRING_OUTPUT_SIZE, ALT_BN128_G1_ADD_LE, ALT_BN128_G1_MUL_LE,
+            ALT_BN128_PAIRING_LE
         };
 
         let execution_cost = invoke_context.get_execution_cost();
         let (cost, output): (u64, usize) = match group_op {
-            ALT_BN128_G1_ADD_BE => (
+            ALT_BN128_G1_ADD_BE | ALT_BN128_G1_ADD_LE => (
                 execution_cost.alt_bn128_addition_cost,
                 ALT_BN128_ADDITION_OUTPUT_SIZE,
             ),
-            ALT_BN128_G1_MUL_BE => (
+            ALT_BN128_G1_MUL_BE | ALT_BN128_G1_MUL_LE => (
                 execution_cost.alt_bn128_multiplication_cost,
                 ALT_BN128_MULTIPLICATION_OUTPUT_SIZE,
             ),
-            ALT_BN128_PAIRING_BE => {
+            ALT_BN128_PAIRING_BE | ALT_BN128_PAIRING_LE => {
                 let ele_len = input_size
                     .checked_div(ALT_BN128_PAIRING_ELEMENT_SIZE as u64)
                     .expect("div by non-zero constant");
@@ -1625,6 +1626,13 @@ declare_builtin_function!(
             ALT_BN128_G1_ADD_BE => {
                 alt_bn128_versioned_g1_addition(VersionedG1Addition::V0, input, Endianness::BE)
             }
+            ALT_BN128_G1_ADD_LE => {
+                if invoke_context.get_feature_set().alt_bn128_little_endian {
+                    alt_bn128_versioned_g1_addition(VersionedG1Addition::V0, input, Endianness::LE)
+                } else {
+                    return Err(SyscallError::InvalidAttribute.into());
+                }
+            }
             ALT_BN128_G1_MUL_BE => {
                 alt_bn128_versioned_g1_multiplication(
                     VersionedG1Multiplication::V1,
@@ -1632,6 +1640,17 @@ declare_builtin_function!(
                     Endianness::BE
                 )
             }
+            ALT_BN128_G1_MUL_LE => {
+                if invoke_context.get_feature_set().alt_bn128_little_endian {
+                    alt_bn128_versioned_g1_multiplication(
+                        VersionedG1Multiplication::V1,
+                        input,
+                        Endianness::LE
+                    )
+                } else {
+                    return Err(SyscallError::InvalidAttribute.into());
+                }
+            }
             ALT_BN128_PAIRING_BE => {
                 let version = if invoke_context
                     .get_feature_set()
@@ -1642,6 +1661,13 @@ declare_builtin_function!(
                 };
                 alt_bn128_versioned_pairing(version, input, Endianness::BE)
             }
+            ALT_BN128_PAIRING_LE => {
+                if invoke_context.get_feature_set().alt_bn128_little_endian {
+                    alt_bn128_versioned_pairing(VersionedPairing::V1, input, Endianness::LE)
+                } else {
+                    return Err(SyscallError::InvalidAttribute.into());
+                }
+            }
             _ => {
                 return Err(SyscallError::InvalidAttribute.into());
             }
@@ -1835,27 +1861,32 @@ declare_builtin_function!(
         use solana_bn254::{
             prelude::{ALT_BN128_G1_POINT_SIZE, ALT_BN128_G2_POINT_SIZE},
             compression::prelude::{
-                alt_bn128_g1_compress, alt_bn128_g1_decompress, alt_bn128_g2_compress,
-                alt_bn128_g2_decompress, ALT_BN128_G1_COMPRESS_BE, ALT_BN128_G1_DECOMPRESS_BE,
-                ALT_BN128_G2_COMPRESS_BE, ALT_BN128_G2_DECOMPRESS_BE, ALT_BN128_G1_COMPRESSED_POINT_SIZE,
-                ALT_BN128_G2_COMPRESSED_POINT_SIZE,
+                alt_bn128_g1_compress, alt_bn128_g1_decompress,
+                alt_bn128_g2_compress, alt_bn128_g2_decompress,
+                alt_bn128_g1_compress_le, alt_bn128_g1_decompress_le,
+                alt_bn128_g2_compress_le, alt_bn128_g2_decompress_le,
+                ALT_BN128_G1_COMPRESS_BE, ALT_BN128_G1_DECOMPRESS_BE,
+                ALT_BN128_G2_COMPRESS_BE, ALT_BN128_G2_DECOMPRESS_BE,
+                ALT_BN128_G1_COMPRESSED_POINT_SIZE, ALT_BN128_G2_COMPRESSED_POINT_SIZE,
+                ALT_BN128_G1_COMPRESS_LE, ALT_BN128_G2_COMPRESS_LE,
+                ALT_BN128_G1_DECOMPRESS_LE, ALT_BN128_G2_DECOMPRESS_LE,
             }
         };
         let execution_cost = invoke_context.get_execution_cost();
         let base_cost = execution_cost.syscall_base_cost;
         let (cost, output): (u64, usize) = match op {
-            ALT_BN128_G1_COMPRESS_BE => (
+            ALT_BN128_G1_COMPRESS_BE | ALT_BN128_G1_COMPRESS_LE => (
                 base_cost.saturating_add(execution_cost.alt_bn128_g1_compress),
                 ALT_BN128_G1_COMPRESSED_POINT_SIZE,
             ),
-            ALT_BN128_G1_DECOMPRESS_BE => {
+            ALT_BN128_G1_DECOMPRESS_BE | ALT_BN128_G1_DECOMPRESS_LE => {
                 (base_cost.saturating_add(execution_cost.alt_bn128_g1_decompress), ALT_BN128_G1_POINT_SIZE)
             }
-            ALT_BN128_G2_COMPRESS_BE => (
+            ALT_BN128_G2_COMPRESS_BE | ALT_BN128_G2_COMPRESS_LE => (
                 base_cost.saturating_add(execution_cost.alt_bn128_g2_compress),
                 ALT_BN128_G2_COMPRESSED_POINT_SIZE,
             ),
-            ALT_BN128_G2_DECOMPRESS_BE => {
+            ALT_BN128_G2_DECOMPRESS_BE | ALT_BN128_G2_DECOMPRESS_LE => {
                 (base_cost.saturating_add(execution_cost.alt_bn128_g2_decompress), ALT_BN128_G2_POINT_SIZE)
             }
             _ => {
@@ -1884,24 +1915,64 @@ declare_builtin_function!(
                 };
                 call_result.copy_from_slice(&result_point);
             }
+            ALT_BN128_G1_COMPRESS_LE => {
+                if invoke_context.get_feature_set().alt_bn128_little_endian {
+                    let Ok(result_point) = alt_bn128_g1_compress_le(input) else {
+                        return Ok(1);
+                    };
+                    call_result.copy_from_slice(&result_point);
+                } else {
+                    return Err(SyscallError::InvalidAttribute.into());
+                }
+            }
             ALT_BN128_G1_DECOMPRESS_BE => {
                 let Ok(result_point) = alt_bn128_g1_decompress(input) else {
                     return Ok(1);
                 };
                 call_result.copy_from_slice(&result_point);
             }
+            ALT_BN128_G1_DECOMPRESS_LE => {
+                if invoke_context.get_feature_set().alt_bn128_little_endian {
+                    let Ok(result_point) = alt_bn128_g1_decompress_le(input) else {
+                        return Ok(1);
+                    };
+                    call_result.copy_from_slice(&result_point);
+                } else {
+                    return Err(SyscallError::InvalidAttribute.into());
+                }
+            }
             ALT_BN128_G2_COMPRESS_BE => {
                 let Ok(result_point) = alt_bn128_g2_compress(input) else {
                     return Ok(1);
                 };
                 call_result.copy_from_slice(&result_point);
             }
+            ALT_BN128_G2_COMPRESS_LE => {
+                if invoke_context.get_feature_set().alt_bn128_little_endian {
+                    let Ok(result_point) = alt_bn128_g2_compress_le(input) else {
+                        return Ok(1);
+                    };
+                    call_result.copy_from_slice(&result_point);
+                } else {
+                    return Err(SyscallError::InvalidAttribute.into());
+                }
+            }
             ALT_BN128_G2_DECOMPRESS_BE => {
                 let Ok(result_point) = alt_bn128_g2_decompress(input) else {
                     return Ok(1);
                 };
                 call_result.copy_from_slice(&result_point);
             }
+            ALT_BN128_G2_DECOMPRESS_LE => {
+                if invoke_context.get_feature_set().alt_bn128_little_endian {
+                    let Ok(result_point) = alt_bn128_g2_decompress_le(input) else {
+                        return Ok(1);
+                    };
+                    call_result.copy_from_slice(&result_point);
+                } else {
+                    return Err(SyscallError::InvalidAttribute.into());
+                }
+            }
             _ => return Err(SyscallError::InvalidAttribute.into()),
         }