LCOV - code coverage report
Current view: top level - flamenco/runtime/tests - fd_sol_compat.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 221 0.0 %
Date: 2026-05-31 08:07:40 Functions: 0 14 0.0 %

          Line data    Source code
       1             : #include "fd_solfuzz.h"
       2             : #include "fd_solfuzz_private.h"
       3             : #include "fd_sol_compat.h"
       4             : #include "../../capture/fd_solcap_writer.h"
       5             : #include "fd_gossip_harness.h"
       6             : #include "fd_cost_harness.h"
       7             : 
       8             : #include "generated/block.pb.h"
       9             : #include "generated/instr.pb.h"
      10             : #include "generated/vm.pb.h"
      11             : #include "generated/txn.pb.h"
      12             : #include "generated/bundle.pb.h"
      13             : #include "generated/cost.pb.h"
      14             : #include "generated/elf.pb.h"
      15             : #include "generated/vm_serialization.pb.h"
      16             : 
      17             : #include <assert.h>
      18             : #include <errno.h>
      19             : #include <fcntl.h>
      20             : #include <unistd.h>
      21             : 
      22             : static fd_wksp_t *           wksp   = NULL;
      23             : static fd_solfuzz_runner_t * runner = NULL;
      24             : 
      25             : static fd_solfuzz_runner_t *
      26           0 : sol_compat_setup_runner( fd_solfuzz_runner_options_t const * options ) {
      27           0 :   runner = fd_solfuzz_runner_new( wksp, 3UL, options );
      28           0 :   if( FD_UNLIKELY( !runner ) ) {
      29           0 :     FD_LOG_ERR(( "fd_solfuzz_runner_new() failed" ));
      30           0 :     return NULL;
      31           0 :   }
      32             : 
      33           0 :   char const * solcap_path = getenv( "FD_SOLCAP" );
      34           0 :   if( solcap_path ) {
      35           0 :     int fd = open( solcap_path, O_WRONLY | O_CREAT | O_TRUNC, 0644 );
      36           0 :     if( FD_UNLIKELY( fd == -1 ) ) {
      37           0 :       FD_LOG_ERR(( "open($FD_SOLCAP=%s) failed (%i-%s)", solcap_path, errno, fd_io_strerror( errno ) ));
      38           0 :     }
      39           0 :     runner->solcap_file = (void *)(ulong)fd;
      40           0 :     FD_LOG_NOTICE(( "Logging to solcap file %s", solcap_path ));
      41             : 
      42           0 :     void * solcap_mem = fd_wksp_alloc_laddr( runner->wksp, fd_solcap_writer_align(), fd_solcap_writer_footprint(), 1UL );
      43           0 :     runner->solcap = fd_solcap_writer_init( solcap_mem, fd );
      44           0 :     FD_TEST( runner->solcap );
      45           0 :   }
      46             : 
      47           0 :   return runner;
      48           0 : }
      49             : 
      50             : static void
      51           0 : sol_compat_cleanup_runner( fd_solfuzz_runner_t * runner ) {
      52             :   /* Cleanup test runner */
      53           0 :   if( runner->solcap ) {
      54           0 :     fd_wksp_free_laddr( ( runner->solcap ) );
      55           0 :     runner->solcap = NULL;
      56           0 :     if( runner->solcap_file ) {
      57           0 :       close( (int)(ulong)runner->solcap_file );
      58           0 :       runner->solcap_file = NULL;
      59           0 :     }
      60           0 :   }
      61           0 :   fd_solfuzz_runner_delete( runner );
      62           0 : }
      63             : 
      64             : void
      65           0 : sol_compat_init( int log_level ) {
      66           0 :   int argc = 1;
      67           0 :   char * argv[2] = { (char *)"fd_exec_sol_compat", NULL };
      68           0 :   char ** argv_ = argv;
      69           0 :   if( !getenv( "FD_LOG_PATH" ) ) {
      70           0 :     setenv( "FD_LOG_PATH", "", 1 );
      71           0 :   }
      72             : 
      73           0 :   char const * enable_vm_tracing_env  = getenv( "ENABLE_VM_TRACING");
      74           0 :   int enable_vm_tracing               = enable_vm_tracing_env!=NULL;
      75           0 :   fd_solfuzz_runner_options_t options = {
      76           0 :     .enable_vm_tracing = enable_vm_tracing
      77           0 :   };
      78             : 
      79           0 :   fd_log_enable_unclean_exit();
      80           0 :   fd_boot( &argc, &argv_ );
      81             : 
      82           0 :   if( FD_UNLIKELY( wksp || runner ) ) {
      83           0 :     FD_LOG_ERR(( "sol_compat_init() called multiple times" ));
      84           0 :   }
      85             : 
      86           0 :   ulong footprint = 7UL<<30;
      87           0 :   ulong part_max  = fd_wksp_part_max_est( footprint, 64UL<<10 );
      88           0 :   ulong data_max  = fd_wksp_data_max_est( footprint, part_max );
      89           0 :   wksp = fd_wksp_demand_paged_new( "sol_compat", 42U, part_max, data_max );
      90           0 :   if( FD_UNLIKELY( !wksp ) ) FD_LOG_ERR(( "fd_wksp_demand_paged_new() failed" ));
      91             : 
      92           0 :   runner = sol_compat_setup_runner( &options );
      93           0 :   if( FD_UNLIKELY( !runner ) ) FD_LOG_ERR(( "sol_compat_setup_runner() failed" ));
      94             : 
      95           0 :   fd_log_level_logfile_set( log_level );
      96           0 :   fd_log_level_core_set(4);  /* abort on FD_LOG_ERR */
      97           0 : }
      98             : 
      99             : void
     100           0 : sol_compat_fini( void ) {
     101           0 :   sol_compat_cleanup_runner( runner );
     102           0 :   fd_wksp_delete_anonymous( wksp );
     103           0 :   wksp   = NULL;
     104           0 :   runner = NULL;
     105           0 :   fd_halt();
     106           0 : }
     107             : 
     108             : sol_compat_features_t const *
     109           0 : sol_compat_get_features_v1( void ) {
     110           0 :   static sol_compat_features_t features;
     111           0 :   static ulong hardcoded_features[ FD_FEATURE_ID_CNT ];
     112           0 :   static ulong supported_features[ FD_FEATURE_ID_CNT ];
     113             : 
     114           0 :   FD_ONCE_BEGIN {
     115           0 :     features.struct_size = sizeof(sol_compat_features_t);
     116           0 :     features.hardcoded_features = hardcoded_features;
     117           0 :     features.supported_features = supported_features;
     118           0 :     for( fd_feature_id_t const * iter = fd_feature_iter_init();
     119           0 :          !fd_feature_iter_done( iter );
     120           0 :          iter = fd_feature_iter_next( iter ) ) {
     121           0 :       if( iter->reverted ) continue; /* skip reverted features */
     122             : 
     123             :       /* Pretend that features activated on all clusters are hardcoded */
     124           0 :       if( iter->hardcode_for_fuzzing ) {
     125           0 :         hardcoded_features[ features.hardcoded_features_cnt++ ] = iter->id.ul[0];
     126           0 :       } else {
     127           0 :         supported_features[ features.supported_feature_cnt++  ] = iter->id.ul[0];
     128           0 :       }
     129           0 :     }
     130           0 :   }
     131           0 :   FD_ONCE_END;
     132             : 
     133           0 :   return &features;
     134           0 : }
     135             : 
     136             : /*
     137             :  * execute_v1
     138             :  */
     139             : 
     140             : int
     141             : sol_compat_instr_execute_v1( uchar *       out,
     142             :                              ulong *       out_sz,
     143             :                              uchar const * in,
     144           0 :                              ulong         in_sz ) {
     145           0 :   fd_exec_test_instr_context_t input[1] = {0};
     146           0 :   void * res = sol_compat_decode_lenient( &input, in, in_sz, &fd_exec_test_instr_context_t_msg );
     147           0 :   if( FD_UNLIKELY( !res ) ) return 0;
     148             : 
     149           0 :   int ok = 0;
     150           0 :   fd_spad_push( runner->spad );
     151           0 :   void * output = NULL;
     152           0 :   fd_solfuzz_pb_execute_wrapper( runner, input, &output, fd_solfuzz_pb_instr_run );
     153           0 :   if( output ) {
     154           0 :     ok = !!sol_compat_encode( out, out_sz, output, &fd_exec_test_instr_effects_t_msg );
     155           0 :   }
     156           0 :   fd_spad_pop( runner->spad );
     157             : 
     158           0 :   pb_release( &fd_exec_test_instr_context_t_msg, input );
     159           0 :   fd_solfuzz_runner_leak_check( runner );
     160           0 :   return ok;
     161           0 : }
     162             : 
     163             : int
     164             : sol_compat_txn_execute_v1( uchar *       out,
     165             :                            ulong *       out_sz,
     166             :                            uchar const * in,
     167           0 :                            ulong         in_sz ) {
     168           0 :   fd_exec_test_txn_context_t input[1] = {0};
     169           0 :   void * res = sol_compat_decode_lenient( &input, in, in_sz, &fd_exec_test_txn_context_t_msg );
     170           0 :   if( FD_UNLIKELY( !res ) ) return 0;
     171             : 
     172           0 :   int ok = 0;
     173           0 :   fd_spad_push( runner->spad );
     174           0 :   void * output = NULL;
     175           0 :   fd_solfuzz_pb_execute_wrapper( runner, input, &output, fd_solfuzz_pb_txn_run );
     176           0 :   if( output ) {
     177           0 :     ok = !!sol_compat_encode( out, out_sz, output, &fd_exec_test_txn_result_t_msg );
     178           0 :   }
     179           0 :   fd_spad_pop( runner->spad );
     180             : 
     181           0 :   pb_release( &fd_exec_test_txn_context_t_msg, input );
     182           0 :   fd_solfuzz_runner_leak_check( runner );
     183           0 :   return ok;
     184           0 : }
     185             : 
     186             : int
     187             : sol_compat_bundle_execute_v1( uchar *       out,
     188             :                               ulong *       out_sz,
     189             :                               uchar const * in,
     190           0 :                               ulong         in_sz ) {
     191           0 :   fd_exec_test_bundle_context_t input[1] = {0};
     192           0 :   void * res = sol_compat_decode_lenient( &input, in, in_sz, &fd_exec_test_bundle_context_t_msg );
     193           0 :   if( FD_UNLIKELY( !res ) ) return 0;
     194             : 
     195           0 :   int ok = 0;
     196           0 :   fd_spad_push( runner->spad );
     197           0 :   void * output = NULL;
     198           0 :   fd_solfuzz_pb_execute_wrapper( runner, input, &output, fd_solfuzz_pb_bundle_run );
     199           0 :   if( output ) {
     200           0 :     ok = !!sol_compat_encode( out, out_sz, output, &fd_exec_test_bundle_effects_t_msg );
     201           0 :   }
     202           0 :   fd_spad_pop( runner->spad );
     203             : 
     204           0 :   pb_release( &fd_exec_test_bundle_context_t_msg, input );
     205           0 :   fd_solfuzz_runner_leak_check( runner );
     206           0 :   return ok;
     207           0 : }
     208             : 
     209             : int
     210             : sol_compat_txn_cost_v1( uchar *       out,
     211             :                         ulong *       out_sz,
     212             :                         uchar const * in,
     213           0 :                         ulong         in_sz ) {
     214           0 :   fd_exec_test_cost_context_t input[1] = { FD_EXEC_TEST_COST_CONTEXT_INIT_ZERO };
     215           0 :   void * res = sol_compat_decode_lenient( &input, in, in_sz, &fd_exec_test_cost_context_t_msg );
     216           0 :   if( FD_UNLIKELY( !res ) ) return 0;
     217             : 
     218           0 :   fd_spad_push( runner->spad );
     219           0 :   fd_exec_test_cost_result_t output_msg = FD_EXEC_TEST_COST_RESULT_INIT_ZERO;
     220           0 :   int ok = fd_solfuzz_pb_cost_run( runner, input, &output_msg );
     221           0 :   if( FD_LIKELY( ok ) ) {
     222           0 :     ok = !!sol_compat_encode( out, out_sz, &output_msg, &fd_exec_test_cost_result_t_msg );
     223           0 :   }
     224           0 :   fd_spad_pop( runner->spad );
     225             : 
     226           0 :   pb_release( &fd_exec_test_cost_context_t_msg, input );
     227           0 :   fd_solfuzz_runner_leak_check( runner );
     228           0 :   return ok;
     229           0 : }
     230             : 
     231             : int
     232             : sol_compat_block_execute_v1( uchar *       out,
     233             :                              ulong *       out_sz,
     234             :                              uchar const * in,
     235           0 :                              ulong         in_sz ) {
     236           0 :   fd_exec_test_block_context_t input[1] = {0};
     237           0 :   void * res = sol_compat_decode_lenient( &input, in, in_sz, &fd_exec_test_block_context_t_msg );
     238           0 :   if( FD_UNLIKELY( !res ) ) return 0;
     239             : 
     240           0 :   fd_spad_push( runner->spad );
     241           0 :   int ok = 0;
     242           0 :   void * output = NULL;
     243           0 :   fd_solfuzz_pb_execute_wrapper( runner, input, &output, fd_solfuzz_pb_block_run );
     244           0 :   if( output ) {
     245           0 :     ok = !!sol_compat_encode( out, out_sz, output, &fd_exec_test_block_effects_t_msg );
     246           0 :   }
     247           0 :   fd_spad_pop( runner->spad );
     248             : 
     249           0 :   pb_release( &fd_exec_test_block_context_t_msg, input );
     250           0 :   fd_solfuzz_runner_leak_check( runner );
     251           0 :   return ok;
     252           0 : }
     253             : 
     254             : int
     255             : sol_compat_vm_syscall_execute_v1( uchar *       out,
     256             :                                   ulong *       out_sz,
     257             :                                   uchar const * in,
     258           0 :                                   ulong         in_sz ) {
     259           0 :   fd_exec_test_syscall_context_t input[1] = {0};
     260           0 :   void * res = sol_compat_decode_lenient( &input, in, in_sz, &fd_exec_test_syscall_context_t_msg );
     261           0 :   if( FD_UNLIKELY( !res ) ) return 0;
     262             : 
     263           0 :   fd_spad_push( runner->spad );
     264           0 :   int ok = 0;
     265           0 :   void * output = NULL;
     266           0 :   fd_solfuzz_pb_execute_wrapper( runner, input, &output, fd_solfuzz_pb_syscall_run );
     267           0 :   if( output ) {
     268           0 :     ok = !!sol_compat_encode( out, out_sz, output, &fd_exec_test_syscall_effects_t_msg );
     269           0 :   }
     270           0 :   fd_spad_pop( runner->spad );
     271             : 
     272           0 :   pb_release( &fd_exec_test_syscall_context_t_msg, input );
     273           0 :   fd_solfuzz_runner_leak_check( runner );
     274           0 :   return ok;
     275           0 : }
     276             : 
     277             : int
     278             : sol_compat_gossip_decode_v1( uchar *       out,
     279             :                              ulong *       out_sz,
     280             :                              uchar const * in,
     281           0 :                              ulong         in_sz ) {
     282           0 :   fd_spad_push( runner->spad );
     283           0 :   int ok = fd_solfuzz_gossip_decode( runner, out, out_sz, in, in_sz );
     284           0 :   fd_spad_pop( runner->spad );
     285           0 :   fd_solfuzz_runner_leak_check( runner );
     286           0 :   return ok;
     287           0 : }
     288             : 
     289             : int
     290             : sol_compat_elf_loader_v1( uchar *       out,
     291             :                           ulong *       out_sz,
     292             :                           uchar const * in,
     293           0 :                           ulong         in_sz ) {
     294           0 :   fd_exec_test_elf_loader_ctx_t input[1] = {0};
     295           0 :   void * res = sol_compat_decode_lenient( &input, in, in_sz, &fd_exec_test_elf_loader_ctx_t_msg );
     296           0 :   if( FD_UNLIKELY( !res ) ) return 0;
     297             : 
     298           0 :   int ok = 0;
     299           0 :   fd_spad_push( runner->spad );
     300           0 :   void * output = NULL;
     301           0 :   fd_solfuzz_pb_execute_wrapper( runner, input, &output, fd_solfuzz_pb_elf_loader_run );
     302           0 :   if( output ) {
     303           0 :     ok = !!sol_compat_encode( out, out_sz, output, &fd_exec_test_elf_loader_effects_t_msg );
     304           0 :   }
     305           0 :   fd_spad_pop( runner->spad );
     306             : 
     307           0 :   pb_release( &fd_exec_test_elf_loader_ctx_t_msg, input );
     308           0 :   fd_solfuzz_runner_leak_check( runner );
     309           0 :   return ok;
     310           0 : }
     311             : 
     312             : int
     313             : sol_compat_vm_serialize_execute_v1( uchar *       out,
     314             :                                     ulong *       out_sz,
     315             :                                     uchar const * in,
     316           0 :                                     ulong         in_sz ) {
     317           0 :   fd_exec_test_instr_context_t input[1] = {0};
     318           0 :   void * res = sol_compat_decode_lenient( &input, in, in_sz, &fd_exec_test_instr_context_t_msg );
     319           0 :   if( FD_UNLIKELY( !res ) ) return 0;
     320             : 
     321           0 :   int ok = 0;
     322           0 :   fd_spad_push( runner->spad );
     323           0 :   void * output = NULL;
     324           0 :   fd_solfuzz_pb_execute_wrapper( runner, input, &output, fd_solfuzz_pb_vm_serialize_run );
     325           0 :   if( output ) {
     326           0 :     ok = !!sol_compat_encode( out, out_sz, output, &fd_exec_test_vm_serialization_effects_t_msg );
     327           0 :   }
     328           0 :   fd_spad_pop( runner->spad );
     329             : 
     330           0 :   pb_release( &fd_exec_test_instr_context_t_msg, input );
     331           0 :   fd_solfuzz_runner_leak_check( runner );
     332           0 :   return ok;
     333           0 : }

Generated by: LCOV version 1.14