LCOV - code coverage report
Current view: top level - flamenco/runtime/program - fd_precompiles.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 65 238 27.3 %
Date: 2026-09-17 04:28:31 Functions: 4 6 66.7 %

          Line data    Source code
       1             : #include "fd_precompiles.h"
       2             : #include "../context/fd_exec_instr_ctx.h"
       3             : #include "../fd_runtime.h"
       4             : #include "../fd_system_ids.h"
       5             : #include "../fd_system_ids_pp.h"
       6             : #include "../../../ballet/keccak256/fd_keccak256.h"
       7             : #include "../../../ballet/secp256r1/fd_secp256r1.h"
       8             : #include "../../../ballet/secp256k1/fd_secp256k1.h"
       9             : #include "../../../ballet/ed25519/fd_ed25519.h"
      10             : 
      11             : /* Docs:
      12             :    https://docs.solana.com/developing/runtime-facilities/programs#ed25519-program
      13             :    https://docs.solana.com/developing/runtime-facilities/programs#secp256k1-program */
      14             : 
      15             : /* There are 3 precompiles and 2 ways to serialize data.
      16             :    The most recent one seems are ed25519 and secp256r1 with 2 bytes per instruction,
      17             :    that works better with JS sdk even though it consumes a few bytes. */
      18             : struct __attribute__((packed)) fd_precompile_sig_offsets {
      19             :   ushort sig_offset;
      20             :   ushort sig_instr_idx;
      21             :   ushort pubkey_offset;
      22             :   ushort pubkey_instr_idx;
      23             :   ushort msg_offset;
      24             :   ushort msg_data_sz;
      25             :   ushort msg_instr_idx;
      26             : };
      27             : typedef struct fd_precompile_sig_offsets fd_ed25519_signature_offsets_t;
      28             : typedef struct fd_precompile_sig_offsets fd_secp256r1_signature_offsets_t;
      29             : 
      30             : struct __attribute__((packed)) fd_precompile_one_byte_idx_sig_offsets {
      31             :   ushort sig_offset;
      32             :   uchar  sig_instr_idx;
      33             :   ushort pubkey_offset;
      34             :   uchar  pubkey_instr_idx;
      35             :   ushort msg_offset;
      36             :   ushort msg_data_sz;
      37             :   uchar  msg_instr_idx;
      38             : };
      39             : typedef struct fd_precompile_one_byte_idx_sig_offsets fd_secp256k1_signature_offsets_t;
      40             : 
      41             : /*
      42             :   Common
      43             : */
      44             : 
      45           6 : #define SIGNATURE_SERIALIZED_SIZE         (64UL)
      46          12 : #define SIGNATURE_OFFSETS_SERIALIZED_SIZE (14UL)
      47          12 : #define SIGNATURE_OFFSETS_START            (2UL)
      48             : #define DATA_START (SIGNATURE_OFFSETS_SERIALIZED_SIZE + SIGNATURE_OFFSETS_START)
      49             : 
      50             : /*
      51             :   Custom
      52             : */
      53             : 
      54           6 : #define ED25519_PUBKEY_SERIALIZED_SIZE              (32UL)
      55             : 
      56           0 : #define SECP256R1_PUBKEY_SERIALIZED_SIZE            (33UL)
      57             : 
      58           0 : #define SECP256K1_PUBKEY_SERIALIZED_SIZE            (20UL)
      59           0 : #define SECP256K1_SIGNATURE_OFFSETS_SERIALIZED_SIZE (11UL)
      60           0 : #define SECP256K1_SIGNATURE_OFFSETS_START            (1UL)
      61             : #define SECP256K1_DATA_START (SECP256K1_SIGNATURE_OFFSETS_SERIALIZED_SIZE + SECP256K1_SIGNATURE_OFFSETS_START)
      62             : 
      63             : FD_STATIC_ASSERT( sizeof( fd_ed25519_signature_offsets_t )==SIGNATURE_OFFSETS_SERIALIZED_SIZE, fd_ballet );
      64             : FD_STATIC_ASSERT( sizeof( fd_secp256k1_signature_offsets_t )==SECP256K1_SIGNATURE_OFFSETS_SERIALIZED_SIZE, fd_ballet );
      65             : 
      66             : /*
      67             :   Common code
      68             : */
      69             : 
      70             : /* fd_precompile_get_instr_data fetches data across instructions.
      71             :    In Agave, the 2 precompiles have slightly different behavior:
      72             :    1. Ed25519 has 16-bit instr index vs Secp256k1 has 8-bit
      73             :    2. Ed25519 accepts instr index==0xFFFF as a special value to indicate
      74             :       the current instruction, Secp256k1 doesn't have this feature
      75             :    3. Ed25519 always return InvalidDataOffsets, while Secp256k1 can
      76             :       return InvalidDataOffsets or InvalidSignature
      77             :    All these differences are completely useless, so we unify the logic.
      78             :    We handle the special case of index==0xFFFF as in Ed25519.
      79             :    We handle errors as in Secp256k1. */
      80             : static inline int
      81             : fd_precompile_get_instr_data( fd_exec_instr_ctx_t * ctx,
      82             :                               ushort                index,
      83             :                               ushort                offset,
      84             :                               ushort                sz,
      85          18 :                               uchar const **        res ) {
      86          18 :   uchar const * data;
      87          18 :   ulong         data_sz;
      88             :   /* The special value index==USHORT_MAX means current instruction.
      89             :      This feature has been introduced for ed25519, but not for secp256k1 where
      90             :      index is 1-byte only.
      91             :      So, fortunately, we can use the same function.
      92             :      https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/ed25519_instruction.rs#L161-L163
      93             :      https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L1018 */
      94          18 :   if( index==USHORT_MAX ) {
      95             : 
      96             :     /* Use current instruction data */
      97          18 :     data    = ctx->instr->data;
      98          18 :     data_sz = ctx->instr->data_sz;
      99             : 
     100          18 :   } else {
     101             : 
     102           0 :     if( FD_UNLIKELY( index>=TXN( ctx->txn_in->txn )->instr_cnt ) )
     103           0 :       return FD_EXECUTOR_PRECOMPILE_ERR_DATA_OFFSET;
     104             : 
     105           0 :     fd_txn_t const *       txn     = TXN( ctx->txn_in->txn );
     106           0 :     uchar const *          payload = ctx->txn_in->txn->payload;
     107           0 :     fd_txn_instr_t const * instr   = &txn->instr[ index ];
     108             : 
     109           0 :     data    = fd_txn_get_instr_data( instr, payload );
     110           0 :     data_sz = instr->data_sz;
     111             : 
     112           0 :   }
     113             : 
     114          18 :   if( FD_UNLIKELY( (ulong)offset+(ulong)sz > data_sz ) )  /* (offset+sz) in [0,2^17) */
     115           0 :     return FD_EXECUTOR_PRECOMPILE_ERR_SIGNATURE;
     116             : 
     117          18 :   *res = data + offset;
     118          18 :   return 0;
     119          18 : }
     120             : 
     121             : /*
     122             :   Ed25519
     123             : */
     124             : 
     125             : int
     126           6 : fd_precompile_ed25519_verify( fd_exec_instr_ctx_t * ctx ) {
     127             : 
     128           6 :   uchar const * data    = ctx->instr->data;
     129           6 :   ulong         data_sz = ctx->instr->data_sz;
     130             : 
     131             :   /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/ed25519_instruction.rs#L90-L96
     132             :      note: this part is really silly and in fact in leaves out the edge case [0, 0].
     133             : 
     134             :      Our implementation does the following:
     135             :      1. assert that there's enough data to deser 1+ fd_ed25519_sig_offsets
     136             :         (in particular, data[0] is accessible)
     137             :         - in the unlikely case, check for the Agave edge case
     138             :      2. if data[0]==0 return
     139             :      3. compute and check expected size */
     140           6 :   if( FD_UNLIKELY( data_sz < DATA_START ) ) {
     141           0 :     if( FD_UNLIKELY( data_sz == 2 && data[0] == 0 ) ) {
     142           0 :       return FD_EXECUTOR_INSTR_SUCCESS;
     143           0 :     }
     144           0 :     ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
     145           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     146           0 :   }
     147             : 
     148           6 :   ulong sig_cnt = data[0];
     149           6 :   if( FD_UNLIKELY( sig_cnt==0 ) ) {
     150           0 :     ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
     151           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     152           0 :   }
     153             : 
     154             :   /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/ed25519_instruction.rs#L97-L103 */
     155           6 :   ulong expected_data_size = sig_cnt * SIGNATURE_OFFSETS_SERIALIZED_SIZE + SIGNATURE_OFFSETS_START;
     156           6 :   if( FD_UNLIKELY( data_sz < expected_data_size ) ) {
     157           0 :     ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
     158           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     159           0 :   }
     160             : 
     161           6 :   ulong off = SIGNATURE_OFFSETS_START;
     162          12 :   for( ulong i = 0; i < sig_cnt; ++i ) {
     163           6 :     fd_ed25519_signature_offsets_t const * sigoffs = (const fd_ed25519_signature_offsets_t *) (data + off);
     164           6 :     off += SIGNATURE_OFFSETS_SERIALIZED_SIZE;
     165             : 
     166             :     /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/ed25519_instruction.rs#L110-L112 */
     167             :     // ???
     168             : 
     169             :     /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/ed25519_instruction.rs#L114-L121 */
     170           6 :     uchar const * sig = NULL;
     171           6 :     int err = fd_precompile_get_instr_data( ctx,
     172           6 :                                             sigoffs->sig_instr_idx,
     173           6 :                                             sigoffs->sig_offset,
     174           6 :                                             SIGNATURE_SERIALIZED_SIZE,
     175           6 :                                             &sig );
     176           6 :     if( FD_UNLIKELY( err ) ) {
     177           0 :       ctx->txn_out->err.custom_err = (uint)err;
     178           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     179           0 :     }
     180             : 
     181             :     /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/ed25519_instruction.rs#L123-L124
     182             :        Note: we parse the signature as part of fd_ed25519_verify.
     183             :        Because of this, the return error code might be different from Agave in some edge cases. */
     184             : 
     185             :     /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/ed25519_instruction.rs#L126-L133 */
     186           6 :     uchar const * pubkey = NULL;
     187           6 :     err = fd_precompile_get_instr_data( ctx,
     188           6 :                                         sigoffs->pubkey_instr_idx,
     189           6 :                                         sigoffs->pubkey_offset,
     190           6 :                                         ED25519_PUBKEY_SERIALIZED_SIZE,
     191           6 :                                         &pubkey );
     192           6 :     if( FD_UNLIKELY( err ) ) {
     193           0 :       ctx->txn_out->err.custom_err = (uint)err;
     194           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     195           0 :     }
     196             : 
     197             :     /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/ed25519_instruction.rs#L135-L136
     198             :        Note: we parse the public key as part of fd_ed25519_verify.
     199             :        Because of this, the return error code might be different from Agave in some edge cases. */
     200             : 
     201             :     /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/ed25519_instruction.rs#L138-L145 */
     202           6 :     uchar const * msg = NULL;
     203           6 :     ushort msg_sz = sigoffs->msg_data_sz;
     204           6 :     err = fd_precompile_get_instr_data( ctx,
     205           6 :                                         sigoffs->msg_instr_idx,
     206           6 :                                         sigoffs->msg_offset,
     207           6 :                                         msg_sz,
     208           6 :                                         &msg );
     209           6 :     if( FD_UNLIKELY( err ) ) {
     210           0 :       ctx->txn_out->err.custom_err = (uint)err;
     211           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     212           0 :     }
     213             : 
     214             :     /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/ed25519_instruction.rs#L147-L149 */
     215           6 :     fd_sha512_t sha[1];
     216           6 :     if( FD_UNLIKELY( fd_ed25519_verify( msg, msg_sz, sig, pubkey, sha )!=FD_ED25519_SUCCESS ) ) {
     217           0 :       ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_SIGNATURE;
     218           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     219           0 :     }
     220           6 :   }
     221             : 
     222           6 :   return FD_EXECUTOR_INSTR_SUCCESS;
     223           6 : }
     224             : 
     225             : /*
     226             :   Secp256K1
     227             : */
     228             : 
     229             : int
     230           0 : fd_precompile_secp256k1_verify( fd_exec_instr_ctx_t * ctx ) {
     231             : 
     232           0 :   uchar const * data    = ctx->instr->data;
     233           0 :   ulong         data_sz = ctx->instr->data_sz;
     234             : 
     235             :   /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L934-L947
     236             :      see comment in ed25519, here the special case is [0] instead of [0, 0] */
     237           0 :   if( FD_UNLIKELY( data_sz < SECP256K1_DATA_START ) ) {
     238           0 :     if( FD_UNLIKELY( data_sz == 1 && data[0] == 0 ) ) {
     239           0 :       return FD_EXECUTOR_INSTR_SUCCESS;
     240           0 :     }
     241           0 :     ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
     242           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     243           0 :   }
     244             : 
     245             :   /* https://github.com/anza-xyz/agave/blob/574bae8fefc0ed256b55340b9d87b7689bcdf222/sdk/src/secp256k1_instruction.rs#L938-L947 */
     246           0 :   ulong sig_cnt = data[0];
     247           0 :   if( FD_UNLIKELY( sig_cnt==0 && data_sz>1 ) ) {
     248           0 :     ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
     249           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     250           0 :   }
     251             : 
     252             :   /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L948-L953 */
     253           0 :   ulong expected_data_size = sig_cnt * SECP256K1_SIGNATURE_OFFSETS_SERIALIZED_SIZE + SECP256K1_SIGNATURE_OFFSETS_START;
     254           0 :   if( FD_UNLIKELY( data_sz < expected_data_size ) ) {
     255           0 :     ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
     256           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     257           0 :   }
     258             : 
     259           0 :   ulong off = SECP256K1_SIGNATURE_OFFSETS_START;
     260           0 :   for( ulong i = 0; i < sig_cnt; ++i ) {
     261           0 :     fd_secp256k1_signature_offsets_t const * sigoffs = (const fd_secp256k1_signature_offsets_t *) (data + off);
     262           0 :     off += SECP256K1_SIGNATURE_OFFSETS_SERIALIZED_SIZE;
     263             : 
     264             :     /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L960-L961 */
     265             :     // ???
     266             : 
     267             :     /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L963-L973
     268             :        Note: for whatever reason, Agave returns InvalidInstructionDataSize instead of InvalidDataOffsets.
     269             :        We just return the err as is. */
     270           0 :     uchar const * sig = NULL;
     271           0 :     int err = fd_precompile_get_instr_data( ctx,
     272           0 :                                             sigoffs->sig_instr_idx,
     273           0 :                                             sigoffs->sig_offset,
     274           0 :                                             SIGNATURE_SERIALIZED_SIZE + 1, /* extra byte is recovery id */
     275           0 :                                             &sig );
     276           0 :     if( FD_UNLIKELY( err ) ) {
     277           0 :       ctx->txn_out->err.custom_err = (uint)err;
     278           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     279           0 :     }
     280             : 
     281             :     /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L975-L981
     282             :        Note: we parse the signature and recovery id as part of fd_secp256k1_recover.
     283             :        Because of this, the return error code might be different from Agave in some edge cases. */
     284           0 :     int recovery_id = (int)sig[SIGNATURE_SERIALIZED_SIZE]; /* extra byte is recovery id */
     285             : 
     286             :     /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L983-L989 */
     287           0 :     uchar const * eth_address = NULL;
     288           0 :     err = fd_precompile_get_instr_data( ctx,
     289           0 :                                         sigoffs->pubkey_instr_idx,
     290           0 :                                         sigoffs->pubkey_offset,
     291           0 :                                         SECP256K1_PUBKEY_SERIALIZED_SIZE,
     292           0 :                                         &eth_address );
     293           0 :     if( FD_UNLIKELY( err ) ) {
     294           0 :       ctx->txn_out->err.custom_err = (uint)err;
     295           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     296           0 :     }
     297             : 
     298             :     /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L991-L997 */
     299           0 :     uchar const * msg = NULL;
     300           0 :     ushort msg_sz = sigoffs->msg_data_sz;
     301           0 :     err = fd_precompile_get_instr_data( ctx,
     302           0 :                                         sigoffs->msg_instr_idx,
     303           0 :                                         sigoffs->msg_offset,
     304           0 :                                         msg_sz,
     305           0 :                                         &msg );
     306           0 :     if( FD_UNLIKELY( err ) ) {
     307           0 :       ctx->txn_out->err.custom_err = (uint)err;
     308           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     309           0 :     }
     310             : 
     311             :     /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L999-L1001 */
     312           0 :     uchar msg_hash[ FD_KECCAK256_HASH_SZ ];
     313           0 :     fd_keccak256_hash( msg, msg_sz, msg_hash );
     314             : 
     315             :     /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L1003-L1008 */
     316           0 :     uchar pubkey[64];
     317           0 :     if ( FD_UNLIKELY( fd_secp256k1_recover( pubkey, msg_hash, sig, recovery_id ) == NULL ) ) {
     318           0 :       ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_SIGNATURE;
     319           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     320           0 :     }
     321             : 
     322             :     /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L1009-L1013 */
     323           0 :     uchar pubkey_hash[ FD_KECCAK256_HASH_SZ ];
     324           0 :     fd_keccak256_hash( pubkey, 64, pubkey_hash );
     325             : 
     326           0 :     if( FD_UNLIKELY( memcmp( eth_address, pubkey_hash+(FD_KECCAK256_HASH_SZ-SECP256K1_PUBKEY_SERIALIZED_SIZE), SECP256K1_PUBKEY_SERIALIZED_SIZE ) ) ) {
     327           0 :       ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_SIGNATURE;
     328           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     329           0 :     }
     330           0 :   }
     331             : 
     332           0 :   return FD_EXECUTOR_INSTR_SUCCESS;
     333           0 : }
     334             : 
     335             : /*
     336             :   Secp256r1
     337             : */
     338             : 
     339             : int
     340           0 : fd_precompile_secp256r1_verify( fd_exec_instr_ctx_t * ctx ) {
     341           0 :   uchar const * data    = ctx->instr->data;
     342           0 :   ulong         data_sz = ctx->instr->data_sz;
     343             : 
     344             :   /* ... */
     345           0 :   if( FD_UNLIKELY( data_sz < DATA_START ) ) {
     346           0 :     ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
     347           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     348           0 :   }
     349             : 
     350           0 :   ulong sig_cnt = data[0];
     351           0 :   if( FD_UNLIKELY( sig_cnt==0UL ) ) {
     352           0 :     ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
     353           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     354           0 :   }
     355             : 
     356             :   /* https://github.com/anza-xyz/agave/blob/v2.3.1/precompiles/src/secp256r1.rs#L30 */
     357           0 :   if( FD_UNLIKELY( sig_cnt>8UL ) ) {
     358           0 :     ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
     359           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     360           0 :   }
     361             : 
     362             :   /* ... */
     363           0 :   ulong expected_data_size = sig_cnt * SIGNATURE_OFFSETS_SERIALIZED_SIZE + SIGNATURE_OFFSETS_START;
     364           0 :   if( FD_UNLIKELY( data_sz < expected_data_size ) ) {
     365           0 :     ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
     366           0 :     return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     367           0 :   }
     368             : 
     369           0 :   ulong off = SIGNATURE_OFFSETS_START;
     370           0 :   for( ulong i = 0; i < sig_cnt; ++i ) {
     371           0 :     fd_secp256r1_signature_offsets_t const * sigoffs = (const fd_secp256r1_signature_offsets_t *) (data + off);
     372           0 :     off += SIGNATURE_OFFSETS_SERIALIZED_SIZE;
     373             : 
     374             :     /* ... */
     375           0 :     uchar const * sig = NULL;
     376           0 :     int err = fd_precompile_get_instr_data( ctx,
     377           0 :                                             sigoffs->sig_instr_idx,
     378           0 :                                             sigoffs->sig_offset,
     379           0 :                                             SIGNATURE_SERIALIZED_SIZE,
     380           0 :                                             &sig );
     381           0 :     if( FD_UNLIKELY( err ) ) {
     382           0 :       ctx->txn_out->err.custom_err = (uint)err;
     383           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     384           0 :     }
     385             : 
     386             :     /* ... */
     387           0 :     uchar const * pubkey = NULL;
     388           0 :     err = fd_precompile_get_instr_data( ctx,
     389           0 :                                         sigoffs->pubkey_instr_idx,
     390           0 :                                         sigoffs->pubkey_offset,
     391           0 :                                         SECP256R1_PUBKEY_SERIALIZED_SIZE,
     392           0 :                                         &pubkey );
     393           0 :     if( FD_UNLIKELY( err ) ) {
     394           0 :       ctx->txn_out->err.custom_err = (uint)err;
     395           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     396           0 :     }
     397             : 
     398             :     /* ... */
     399           0 :     uchar const * msg = NULL;
     400           0 :     ushort msg_sz = sigoffs->msg_data_sz;
     401           0 :     err = fd_precompile_get_instr_data( ctx,
     402           0 :                                         sigoffs->msg_instr_idx,
     403           0 :                                         sigoffs->msg_offset,
     404           0 :                                         msg_sz,
     405           0 :                                         &msg );
     406           0 :     if( FD_UNLIKELY( err ) ) {
     407           0 :       ctx->txn_out->err.custom_err = (uint)err;
     408           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     409           0 :     }
     410             : 
     411             :     /* ... */
     412           0 :     fd_sha256_t sha[1];
     413           0 :     if( FD_UNLIKELY( fd_secp256r1_verify( msg, msg_sz, sig, pubkey, sha )!=FD_SECP256R1_SUCCESS ) ) {
     414           0 :       ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_SIGNATURE;
     415           0 :       return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
     416           0 :     }
     417           0 :   }
     418             : 
     419           0 :   return FD_EXECUTOR_INSTR_SUCCESS;
     420           0 : }
     421             : 
     422             : static const fd_precompile_program_t precompiles[] = {
     423             :     { &fd_solana_secp256r1_program_id,          NO_ENABLE_FEATURE_ID,                                 fd_precompile_secp256r1_verify },
     424             :     { &fd_solana_keccak_secp_256k_program_id,   NO_ENABLE_FEATURE_ID,                                 fd_precompile_secp256k1_verify },
     425             :     { &fd_solana_ed25519_sig_verify_program_id, NO_ENABLE_FEATURE_ID,                                 fd_precompile_ed25519_verify   },
     426             :     {0}
     427             : };
     428             : 
     429             : fd_precompile_program_t const *
     430         282 : fd_precompiles( void ) {
     431         282 :   return precompiles;
     432         282 : }
     433             : 
     434             : #define MAP_PERFECT_NAME fd_native_precompile_program_fn_lookup_tbl
     435             : #define MAP_PERFECT_LG_TBL_SZ 2
     436             : #define MAP_PERFECT_T fd_native_prog_info_t
     437        2787 : #define MAP_PERFECT_HASH_C 63546U
     438             : #define MAP_PERFECT_KEY key.uc
     439             : #define MAP_PERFECT_KEY_T fd_pubkey_t const *
     440             : #define MAP_PERFECT_ZERO_KEY  (0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0)
     441             : #define MAP_PERFECT_COMPLEX_KEY 1
     442        2787 : #define MAP_PERFECT_KEYS_EQUAL(k1,k2) (!memcmp( (k1), (k2), 32UL ))
     443             : 
     444        2787 : #define PERFECT_HASH( u ) (((MAP_PERFECT_HASH_C*(u))>>30)&0x3U)
     445             : 
     446             : #define MAP_PERFECT_HASH_PP( a00,a01,a02,a03,a04,a05,a06,a07,a08,a09,a10,a11,a12,a13,a14,a15, \
     447             :                              a16,a17,a18,a19,a20,a21,a22,a23,a24,a25,a26,a27,a28,a29,a30,a31) \
     448             :                                           PERFECT_HASH( (a00 | (a01<<8)) )
     449        2787 : #define MAP_PERFECT_HASH_R( ptr ) PERFECT_HASH( fd_uint_load_2( (uchar const *)ptr ) )
     450             : 
     451             : #define MAP_PERFECT_0 ( ED25519_SV_PROG_ID  ), .fn = fd_precompile_ed25519_verify
     452             : #define MAP_PERFECT_1 ( KECCAK_SECP_PROG_ID ), .fn = fd_precompile_secp256k1_verify
     453             : #define MAP_PERFECT_2 ( SECP256R1_PROG_ID   ), .fn = fd_precompile_secp256r1_verify
     454             : 
     455             : #include "../../../util/tmpl/fd_map_perfect.c"
     456             : #undef PERFECT_HASH
     457             : 
     458             : fd_exec_instr_fn_t
     459        2787 : fd_executor_lookup_native_precompile_program( fd_pubkey_t const * pubkey ) {
     460        2787 :   const fd_native_prog_info_t null_function = {0};
     461        2787 :   return fd_native_precompile_program_fn_lookup_tbl_query( pubkey, &null_function )->fn;
     462        2787 : }

Generated by: LCOV version 1.14