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 24815 : #define SIGNATURE_SERIALIZED_SIZE (64UL)
46 36213 : #define SIGNATURE_OFFSETS_SERIALIZED_SIZE (14UL)
47 34498 : #define SIGNATURE_OFFSETS_START (2UL)
48 : #define DATA_START (SIGNATURE_OFFSETS_SERIALIZED_SIZE + SIGNATURE_OFFSETS_START)
49 :
50 : /*
51 : Custom
52 : */
53 :
54 4789 : #define ED25519_PUBKEY_SERIALIZED_SIZE (32UL)
55 :
56 13378 : #define SECP256R1_PUBKEY_SERIALIZED_SIZE (33UL)
57 :
58 2809 : #define SECP256K1_PUBKEY_SERIALIZED_SIZE (20UL)
59 5344 : #define SECP256K1_SIGNATURE_OFFSETS_SERIALIZED_SIZE (11UL)
60 4545 : #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 63386 : uchar const ** res ) {
86 63386 : uchar const * data;
87 63386 : 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 63386 : if( index==USHORT_MAX ) {
95 :
96 : /* Use current instruction data */
97 53220 : data = ctx->instr->data;
98 53220 : data_sz = ctx->instr->data_sz;
99 :
100 53220 : } else {
101 :
102 10166 : if( FD_UNLIKELY( index>=TXN( ctx->txn_in->txn )->instr_cnt ) )
103 645 : return FD_EXECUTOR_PRECOMPILE_ERR_DATA_OFFSET;
104 :
105 9521 : fd_txn_t const * txn = TXN( ctx->txn_in->txn );
106 9521 : uchar const * payload = ctx->txn_in->txn->payload;
107 9521 : fd_txn_instr_t const * instr = &txn->instr[ index ];
108 :
109 9521 : data = fd_txn_get_instr_data( instr, payload );
110 9521 : data_sz = instr->data_sz;
111 :
112 9521 : }
113 :
114 62741 : if( FD_UNLIKELY( (ulong)offset+(ulong)sz > data_sz ) ) /* (offset+sz) in [0,2^17) */
115 1426 : return FD_EXECUTOR_PRECOMPILE_ERR_SIGNATURE;
116 :
117 61315 : *res = data + offset;
118 61315 : return 0;
119 62741 : }
120 :
121 : /*
122 : Ed25519
123 : */
124 :
125 : int
126 4690 : fd_precompile_ed25519_verify( fd_exec_instr_ctx_t * ctx ) {
127 :
128 4690 : uchar const * data = ctx->instr->data;
129 4690 : 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 4690 : if( FD_UNLIKELY( data_sz < DATA_START ) ) {
141 339 : if( FD_UNLIKELY( data_sz == 2 && data[0] == 0 ) ) {
142 72 : return FD_EXECUTOR_INSTR_SUCCESS;
143 72 : }
144 267 : ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
145 267 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
146 339 : }
147 :
148 4351 : ulong sig_cnt = data[0];
149 4351 : if( FD_UNLIKELY( sig_cnt==0 ) ) {
150 84 : ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
151 84 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
152 84 : }
153 :
154 : /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/ed25519_instruction.rs#L97-L103 */
155 4267 : ulong expected_data_size = sig_cnt * SIGNATURE_OFFSETS_SERIALIZED_SIZE + SIGNATURE_OFFSETS_START;
156 4267 : if( FD_UNLIKELY( data_sz < expected_data_size ) ) {
157 15 : ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
158 15 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
159 15 : }
160 :
161 4252 : ulong off = SIGNATURE_OFFSETS_START;
162 6512 : for( ulong i = 0; i < sig_cnt; ++i ) {
163 5243 : fd_ed25519_signature_offsets_t const * sigoffs = (const fd_ed25519_signature_offsets_t *) (data + off);
164 5243 : 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 5243 : uchar const * sig = NULL;
171 5243 : int err = fd_precompile_get_instr_data( ctx,
172 5243 : sigoffs->sig_instr_idx,
173 5243 : sigoffs->sig_offset,
174 5243 : SIGNATURE_SERIALIZED_SIZE,
175 5243 : &sig );
176 5243 : if( FD_UNLIKELY( err ) ) {
177 454 : ctx->txn_out->err.custom_err = (uint)err;
178 454 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
179 454 : }
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 4789 : uchar const * pubkey = NULL;
187 4789 : err = fd_precompile_get_instr_data( ctx,
188 4789 : sigoffs->pubkey_instr_idx,
189 4789 : sigoffs->pubkey_offset,
190 4789 : ED25519_PUBKEY_SERIALIZED_SIZE,
191 4789 : &pubkey );
192 4789 : if( FD_UNLIKELY( err ) ) {
193 78 : ctx->txn_out->err.custom_err = (uint)err;
194 78 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
195 78 : }
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 4711 : uchar const * msg = NULL;
203 4711 : ushort msg_sz = sigoffs->msg_data_sz;
204 4711 : err = fd_precompile_get_instr_data( ctx,
205 4711 : sigoffs->msg_instr_idx,
206 4711 : sigoffs->msg_offset,
207 4711 : msg_sz,
208 4711 : &msg );
209 4711 : if( FD_UNLIKELY( err ) ) {
210 256 : ctx->txn_out->err.custom_err = (uint)err;
211 256 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
212 256 : }
213 :
214 : /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/ed25519_instruction.rs#L147-L149 */
215 4455 : fd_sha512_t sha[1];
216 4455 : if( FD_UNLIKELY( fd_ed25519_verify( msg, msg_sz, sig, pubkey, sha )!=FD_ED25519_SUCCESS ) ) {
217 2195 : ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_SIGNATURE;
218 2195 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
219 2195 : }
220 4455 : }
221 :
222 1269 : return FD_EXECUTOR_INSTR_SUCCESS;
223 4252 : }
224 :
225 : /*
226 : Secp256K1
227 : */
228 :
229 : int
230 2746 : fd_precompile_secp256k1_verify( fd_exec_instr_ctx_t * ctx ) {
231 :
232 2746 : uchar const * data = ctx->instr->data;
233 2746 : 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 2746 : if( FD_UNLIKELY( data_sz < SECP256K1_DATA_START ) ) {
238 352 : if( FD_UNLIKELY( data_sz == 1 && data[0] == 0 ) ) {
239 86 : return FD_EXECUTOR_INSTR_SUCCESS;
240 86 : }
241 266 : ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
242 266 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
243 352 : }
244 :
245 : /* https://github.com/anza-xyz/agave/blob/574bae8fefc0ed256b55340b9d87b7689bcdf222/sdk/src/secp256k1_instruction.rs#L938-L947 */
246 2394 : ulong sig_cnt = data[0];
247 2394 : if( FD_UNLIKELY( sig_cnt==0 && data_sz>1 ) ) {
248 111 : ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
249 111 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
250 111 : }
251 :
252 : /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L948-L953 */
253 2283 : ulong expected_data_size = sig_cnt * SECP256K1_SIGNATURE_OFFSETS_SERIALIZED_SIZE + SECP256K1_SIGNATURE_OFFSETS_START;
254 2283 : if( FD_UNLIKELY( data_sz < expected_data_size ) ) {
255 21 : ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
256 21 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
257 21 : }
258 :
259 2262 : ulong off = SECP256K1_SIGNATURE_OFFSETS_START;
260 4150 : for( ulong i = 0; i < sig_cnt; ++i ) {
261 3061 : fd_secp256k1_signature_offsets_t const * sigoffs = (const fd_secp256k1_signature_offsets_t *) (data + off);
262 3061 : 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 3061 : uchar const * sig = NULL;
271 3061 : int err = fd_precompile_get_instr_data( ctx,
272 3061 : sigoffs->sig_instr_idx,
273 3061 : sigoffs->sig_offset,
274 3061 : SIGNATURE_SERIALIZED_SIZE + 1, /* extra byte is recovery id */
275 3061 : &sig );
276 3061 : if( FD_UNLIKELY( err ) ) {
277 252 : ctx->txn_out->err.custom_err = (uint)err;
278 252 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
279 252 : }
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 2809 : 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 2809 : uchar const * eth_address = NULL;
288 2809 : err = fd_precompile_get_instr_data( ctx,
289 2809 : sigoffs->pubkey_instr_idx,
290 2809 : sigoffs->pubkey_offset,
291 2809 : SECP256K1_PUBKEY_SERIALIZED_SIZE,
292 2809 : ð_address );
293 2809 : if( FD_UNLIKELY( err ) ) {
294 147 : ctx->txn_out->err.custom_err = (uint)err;
295 147 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
296 147 : }
297 :
298 : /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L991-L997 */
299 2662 : uchar const * msg = NULL;
300 2662 : ushort msg_sz = sigoffs->msg_data_sz;
301 2662 : err = fd_precompile_get_instr_data( ctx,
302 2662 : sigoffs->msg_instr_idx,
303 2662 : sigoffs->msg_offset,
304 2662 : msg_sz,
305 2662 : &msg );
306 2662 : if( FD_UNLIKELY( err ) ) {
307 272 : ctx->txn_out->err.custom_err = (uint)err;
308 272 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
309 272 : }
310 :
311 : /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L999-L1001 */
312 2390 : uchar msg_hash[ FD_KECCAK256_HASH_SZ ];
313 2390 : 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 2390 : uchar pubkey[64];
317 2390 : if ( FD_UNLIKELY( fd_secp256k1_recover( pubkey, msg_hash, sig, recovery_id ) == NULL ) ) {
318 391 : ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_SIGNATURE;
319 391 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
320 391 : }
321 :
322 : /* https://github.com/anza-xyz/agave/blob/v1.18.12/sdk/src/secp256k1_instruction.rs#L1009-L1013 */
323 1999 : uchar pubkey_hash[ FD_KECCAK256_HASH_SZ ];
324 1999 : fd_keccak256_hash( pubkey, 64, pubkey_hash );
325 :
326 1999 : if( FD_UNLIKELY( memcmp( eth_address, pubkey_hash+(FD_KECCAK256_HASH_SZ-SECP256K1_PUBKEY_SERIALIZED_SIZE), SECP256K1_PUBKEY_SERIALIZED_SIZE ) ) ) {
327 111 : ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_SIGNATURE;
328 111 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
329 111 : }
330 1999 : }
331 :
332 1089 : return FD_EXECUTOR_INSTR_SUCCESS;
333 2262 : }
334 :
335 : /*
336 : Secp256r1
337 : */
338 :
339 : int
340 13520 : fd_precompile_secp256r1_verify( fd_exec_instr_ctx_t * ctx ) {
341 13520 : uchar const * data = ctx->instr->data;
342 13520 : ulong data_sz = ctx->instr->data_sz;
343 :
344 : /* ... */
345 13520 : if( FD_UNLIKELY( data_sz < DATA_START ) ) {
346 422 : ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
347 422 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
348 422 : }
349 :
350 13098 : ulong sig_cnt = data[0];
351 13098 : if( FD_UNLIKELY( sig_cnt==0UL ) ) {
352 70 : ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
353 70 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
354 70 : }
355 :
356 : /* https://github.com/anza-xyz/agave/blob/v2.3.1/precompiles/src/secp256r1.rs#L30 */
357 13028 : if( FD_UNLIKELY( sig_cnt>8UL ) ) {
358 27 : ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
359 27 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
360 27 : }
361 :
362 : /* ... */
363 13001 : ulong expected_data_size = sig_cnt * SIGNATURE_OFFSETS_SERIALIZED_SIZE + SIGNATURE_OFFSETS_START;
364 13001 : if( FD_UNLIKELY( data_sz < expected_data_size ) ) {
365 23 : ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_INSTR_DATA_SIZE;
366 23 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
367 23 : }
368 :
369 12978 : ulong off = SIGNATURE_OFFSETS_START;
370 17544 : for( ulong i = 0; i < sig_cnt; ++i ) {
371 13702 : fd_secp256r1_signature_offsets_t const * sigoffs = (const fd_secp256r1_signature_offsets_t *) (data + off);
372 13702 : off += SIGNATURE_OFFSETS_SERIALIZED_SIZE;
373 :
374 : /* ... */
375 13702 : uchar const * sig = NULL;
376 13702 : int err = fd_precompile_get_instr_data( ctx,
377 13702 : sigoffs->sig_instr_idx,
378 13702 : sigoffs->sig_offset,
379 13702 : SIGNATURE_SERIALIZED_SIZE,
380 13702 : &sig );
381 13702 : if( FD_UNLIKELY( err ) ) {
382 324 : ctx->txn_out->err.custom_err = (uint)err;
383 324 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
384 324 : }
385 :
386 : /* ... */
387 13378 : uchar const * pubkey = NULL;
388 13378 : err = fd_precompile_get_instr_data( ctx,
389 13378 : sigoffs->pubkey_instr_idx,
390 13378 : sigoffs->pubkey_offset,
391 13378 : SECP256R1_PUBKEY_SERIALIZED_SIZE,
392 13378 : &pubkey );
393 13378 : if( FD_UNLIKELY( err ) ) {
394 81 : ctx->txn_out->err.custom_err = (uint)err;
395 81 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
396 81 : }
397 :
398 : /* ... */
399 13297 : uchar const * msg = NULL;
400 13297 : ushort msg_sz = sigoffs->msg_data_sz;
401 13297 : err = fd_precompile_get_instr_data( ctx,
402 13297 : sigoffs->msg_instr_idx,
403 13297 : sigoffs->msg_offset,
404 13297 : msg_sz,
405 13297 : &msg );
406 13297 : if( FD_UNLIKELY( err ) ) {
407 207 : ctx->txn_out->err.custom_err = (uint)err;
408 207 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
409 207 : }
410 :
411 : /* ... */
412 13090 : fd_sha256_t sha[1];
413 13090 : if( FD_UNLIKELY( fd_secp256r1_verify( msg, msg_sz, sig, pubkey, sha )!=FD_SECP256R1_SUCCESS ) ) {
414 8524 : ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_SIGNATURE;
415 8524 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
416 8524 : }
417 13090 : }
418 :
419 3842 : return FD_EXECUTOR_INSTR_SUCCESS;
420 12978 : }
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 32 : fd_precompiles( void ) {
431 32 : return precompiles;
432 32 : }
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 70738 : #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 70738 : #define MAP_PERFECT_KEYS_EQUAL(k1,k2) (!memcmp( (k1), (k2), 32UL ))
443 :
444 70738 : #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 70738 : #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 70752 : fd_executor_lookup_native_precompile_program( fd_pubkey_t const * pubkey ) {
460 70752 : const fd_native_prog_info_t null_function = {0};
461 70752 : return fd_native_precompile_program_fn_lookup_tbl_query( pubkey, &null_function )->fn;
462 70752 : }
|