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 24833 : #define SIGNATURE_SERIALIZED_SIZE (64UL)
46 36247 : #define SIGNATURE_OFFSETS_SERIALIZED_SIZE (14UL)
47 34518 : #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 13402 : #define SECP256R1_PUBKEY_SERIALIZED_SIZE (33UL)
57 :
58 2806 : #define SECP256K1_PUBKEY_SERIALIZED_SIZE (20UL)
59 5338 : #define SECP256K1_SIGNATURE_OFFSETS_SERIALIZED_SIZE (11UL)
60 4539 : #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 63379 : uchar const ** res ) {
86 63379 : uchar const * data;
87 63379 : 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 63379 : if( index==USHORT_MAX ) {
95 :
96 : /* Use current instruction data */
97 53221 : data = ctx->instr->data;
98 53221 : data_sz = ctx->instr->data_sz;
99 :
100 53221 : } else {
101 :
102 10158 : if( FD_UNLIKELY( index>=TXN( ctx->txn_in->txn )->instr_cnt ) )
103 645 : return FD_EXECUTOR_PRECOMPILE_ERR_DATA_OFFSET;
104 :
105 9513 : fd_txn_t const * txn = TXN( ctx->txn_in->txn );
106 9513 : uchar const * payload = ctx->txn_in->txn->payload;
107 9513 : fd_txn_instr_t const * instr = &txn->instr[ index ];
108 :
109 9513 : data = fd_txn_get_instr_data( instr, payload );
110 9513 : data_sz = instr->data_sz;
111 :
112 9513 : }
113 :
114 62734 : 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 61308 : *res = data + offset;
118 61308 : return 0;
119 62734 : }
120 :
121 : /*
122 : Ed25519
123 : */
124 :
125 : int
126 4689 : fd_precompile_ed25519_verify( fd_exec_instr_ctx_t * ctx ) {
127 :
128 4689 : uchar const * data = ctx->instr->data;
129 4689 : 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 4689 : 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 4350 : ulong sig_cnt = data[0];
149 4350 : 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 4266 : ulong expected_data_size = sig_cnt * SIGNATURE_OFFSETS_SERIALIZED_SIZE + SIGNATURE_OFFSETS_START;
156 4266 : 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 4251 : ulong off = SIGNATURE_OFFSETS_START;
162 6516 : 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 2190 : ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_SIGNATURE;
218 2190 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
219 2190 : }
220 4455 : }
221 :
222 1273 : return FD_EXECUTOR_INSTR_SUCCESS;
223 4251 : }
224 :
225 : /*
226 : Secp256K1
227 : */
228 :
229 : int
230 2743 : fd_precompile_secp256k1_verify( fd_exec_instr_ctx_t * ctx ) {
231 :
232 2743 : uchar const * data = ctx->instr->data;
233 2743 : 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 2743 : 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 2391 : ulong sig_cnt = data[0];
247 2391 : 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 2280 : ulong expected_data_size = sig_cnt * SECP256K1_SIGNATURE_OFFSETS_SERIALIZED_SIZE + SECP256K1_SIGNATURE_OFFSETS_START;
254 2280 : 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 2259 : ulong off = SECP256K1_SIGNATURE_OFFSETS_START;
260 4144 : for( ulong i = 0; i < sig_cnt; ++i ) {
261 3058 : fd_secp256k1_signature_offsets_t const * sigoffs = (const fd_secp256k1_signature_offsets_t *) (data + off);
262 3058 : 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 3058 : uchar const * sig = NULL;
271 3058 : int err = fd_precompile_get_instr_data( ctx,
272 3058 : sigoffs->sig_instr_idx,
273 3058 : sigoffs->sig_offset,
274 3058 : SIGNATURE_SERIALIZED_SIZE + 1, /* extra byte is recovery id */
275 3058 : &sig );
276 3058 : 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 2806 : 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 2806 : uchar const * eth_address = NULL;
288 2806 : err = fd_precompile_get_instr_data( ctx,
289 2806 : sigoffs->pubkey_instr_idx,
290 2806 : sigoffs->pubkey_offset,
291 2806 : SECP256K1_PUBKEY_SERIALIZED_SIZE,
292 2806 : ð_address );
293 2806 : 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 2659 : uchar const * msg = NULL;
300 2659 : ushort msg_sz = sigoffs->msg_data_sz;
301 2659 : err = fd_precompile_get_instr_data( ctx,
302 2659 : sigoffs->msg_instr_idx,
303 2659 : sigoffs->msg_offset,
304 2659 : msg_sz,
305 2659 : &msg );
306 2659 : 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 2387 : uchar msg_hash[ FD_KECCAK256_HASH_SZ ];
313 2387 : 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 2387 : uchar pubkey[64];
317 2387 : 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 1996 : uchar pubkey_hash[ FD_KECCAK256_HASH_SZ ];
324 1996 : fd_keccak256_hash( pubkey, 64, pubkey_hash );
325 :
326 1996 : 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 1996 : }
331 :
332 1086 : return FD_EXECUTOR_INSTR_SUCCESS;
333 2259 : }
334 :
335 : /*
336 : Secp256r1
337 : */
338 :
339 : int
340 13531 : fd_precompile_secp256r1_verify( fd_exec_instr_ctx_t * ctx ) {
341 13531 : uchar const * data = ctx->instr->data;
342 13531 : ulong data_sz = ctx->instr->data_sz;
343 :
344 : /* ... */
345 13531 : 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 13109 : ulong sig_cnt = data[0];
351 13109 : 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 13039 : 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 13012 : ulong expected_data_size = sig_cnt * SIGNATURE_OFFSETS_SERIALIZED_SIZE + SIGNATURE_OFFSETS_START;
364 13012 : 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 12989 : ulong off = SIGNATURE_OFFSETS_START;
370 17588 : for( ulong i = 0; i < sig_cnt; ++i ) {
371 13726 : fd_secp256r1_signature_offsets_t const * sigoffs = (const fd_secp256r1_signature_offsets_t *) (data + off);
372 13726 : off += SIGNATURE_OFFSETS_SERIALIZED_SIZE;
373 :
374 : /* ... */
375 13726 : uchar const * sig = NULL;
376 13726 : int err = fd_precompile_get_instr_data( ctx,
377 13726 : sigoffs->sig_instr_idx,
378 13726 : sigoffs->sig_offset,
379 13726 : SIGNATURE_SERIALIZED_SIZE,
380 13726 : &sig );
381 13726 : 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 13402 : uchar const * pubkey = NULL;
388 13402 : err = fd_precompile_get_instr_data( ctx,
389 13402 : sigoffs->pubkey_instr_idx,
390 13402 : sigoffs->pubkey_offset,
391 13402 : SECP256R1_PUBKEY_SERIALIZED_SIZE,
392 13402 : &pubkey );
393 13402 : 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 13321 : uchar const * msg = NULL;
400 13321 : ushort msg_sz = sigoffs->msg_data_sz;
401 13321 : err = fd_precompile_get_instr_data( ctx,
402 13321 : sigoffs->msg_instr_idx,
403 13321 : sigoffs->msg_offset,
404 13321 : msg_sz,
405 13321 : &msg );
406 13321 : 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 13114 : fd_sha256_t sha[1];
413 13114 : if( FD_UNLIKELY( fd_secp256r1_verify( msg, msg_sz, sig, pubkey, sha )!=FD_SECP256R1_SUCCESS ) ) {
414 8515 : ctx->txn_out->err.custom_err = FD_EXECUTOR_PRECOMPILE_ERR_SIGNATURE;
415 8515 : return FD_EXECUTOR_INSTR_ERR_CUSTOM_ERR;
416 8515 : }
417 13114 : }
418 :
419 3862 : return FD_EXECUTOR_INSTR_SUCCESS;
420 12989 : }
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 28 : fd_precompiles( void ) {
431 28 : return precompiles;
432 28 : }
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 70508 : #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 70508 : #define MAP_PERFECT_KEYS_EQUAL(k1,k2) (!memcmp( (k1), (k2), 32UL ))
443 :
444 70508 : #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 70508 : #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 70503 : fd_executor_lookup_native_precompile_program( fd_pubkey_t const * pubkey ) {
460 70503 : const fd_native_prog_info_t null_function = {0};
461 70503 : return fd_native_precompile_program_fn_lookup_tbl_query( pubkey, &null_function )->fn;
462 70503 : }
|