3v4l.org

run code in 500+ PHP versions simultaneously
<?php //Case Battle Fairness | Round Validation $serverSeed = ''; // Server seed $eosBlockSeed = ''; // EOS Block Seed /* * This is the round number, where 1 round is one case opened. If the battle has 10 cases, * this means there are 10 rounds - 1-10. * IMPORTANT: If it's the tiebreaker round, it will always be totalRounds + 1 * because the tiebreaker is considered as one additional round. If you have 2 cases * which results in 2 rounds, the tiebreaker roundNumber is 3 because it's total (2) + 1. */ $roundNumber = -1; /* * Player position that we want to validate the roll for. * For example, if you want to validate your own roll and you were holding * the 3rd position from left to right, then playerPosition will be 3. */ $playerPosition = -1; // The Player Position (1 to 4) // Update this to true if you are validating a tiebreaker result. $isTiebreaker = false; /* * Case Ticket's Quantity, by default it's 100,000 * We only change this if there's a case that has different ticket distribution. * Right now, all cases use 100,000 by default. * IMPORTANT: If it's the tiebreaker round, this will be number of players participating on the tiebreaker. * For example, if two players are participating on a tiebreaker the ticketQuantity is 2. */ $ticketQuantity = 100000; /* ------------------ */ if ($serverSeed == '' || $eosBlockSeed == '' || $roundNumber < 0 || $playerPosition < 1 || $playerPosition > 4 || $ticketQuantity <= 0) { echo "Fill in details"; return; } define('MAX_HEX_SEGMENTS', 6); define('HEX_SEGMENT_SIZE', 2); define('BASE_FOR_HEX_CONVERSION', 256); define('HASH_TYPE', 'sha256'); function calculateDecimalValue(string $preResult): float { $decimalValue = 0; for ($i = 0; $i < MAX_HEX_SEGMENTS; $i++) { $hexValue = substr($preResult, HEX_SEGMENT_SIZE * $i, HEX_SEGMENT_SIZE); $decimalValue += hexdec($hexValue) / pow(BASE_FOR_HEX_CONVERSION, $i + 1); } return $decimalValue; } function getProvablyFairResult(string $init, int $qty): array { $preResult = hash(HASH_TYPE, $init); $decimalValue = calculateDecimalValue($preResult); $result = (int) ($decimalValue * $qty) + 1; return [ 'preResult' => $preResult, 'result' => $result, ]; } $serverSeed = preg_replace("/\r|\n/", "", $serverSeed); $eosBlockSeed = preg_replace("/\r|\n/", "", $eosBlockSeed); if ($isTiebreaker) { $stringToHash = "$serverSeed-$eosBlockSeed-$roundNumber"; } else { $stringToHash = "$serverSeed-$eosBlockSeed-$roundNumber-$playerPosition"; } $result = getProvablyFairResult($stringToHash, $ticketQuantity); echo "Result: {$result['result']}"; ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
2 jumps found. (Code = 47) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
2 jumps found. (Code = 47) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
2 jumps found. (Code = 47) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
2 jumps found. (Code = 47) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 55
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
Branch analysis from position: 19
Branch analysis from position: 16
Branch analysis from position: 13
Branch analysis from position: 10
filename:       /in/SCdP9
function name:  (null)
number of ops:  73
compiled vars:  !0 = $serverSeed, !1 = $eosBlockSeed, !2 = $roundNumber, !3 = $playerPosition, !4 = $isTiebreaker, !5 = $ticketQuantity, !6 = $stringToHash, !7 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                       !0, ''
    5     1        ASSIGN                                                       !1, ''
   14     2        ASSIGN                                                       !2, -1
   21     3        ASSIGN                                                       !3, -1
   25     4        ASSIGN                                                       !4, <false>
   34     5        ASSIGN                                                       !5, 100000
   39     6        IS_EQUAL                                             ~14     !0, ''
          7      > JMPNZ_EX                                             ~14     ~14, ->10
          8    >   IS_EQUAL                                             ~15     !1, ''
          9        BOOL                                                 ~14     ~15
         10    > > JMPNZ_EX                                             ~14     ~14, ->13
         11    >   IS_SMALLER                                           ~16     !2, 0
         12        BOOL                                                 ~14     ~16
         13    > > JMPNZ_EX                                             ~14     ~14, ->16
         14    >   IS_SMALLER                                           ~17     !3, 1
         15        BOOL                                                 ~14     ~17
         16    > > JMPNZ_EX                                             ~14     ~14, ->19
         17    >   IS_SMALLER                                           ~18     4, !3
         18        BOOL                                                 ~14     ~18
         19    > > JMPNZ_EX                                             ~14     ~14, ->22
         20    >   IS_SMALLER_OR_EQUAL                                  ~19     !5, 0
         21        BOOL                                                 ~14     ~19
         22    > > JMPZ                                                         ~14, ->25
   40    23    >   ECHO                                                         'Fill+in+details'
   41    24      > RETURN                                                       null
   44    25    >   INIT_FCALL                                                   'define'
         26        SEND_VAL                                                     'MAX_HEX_SEGMENTS'
         27        SEND_VAL                                                     6
         28        DO_ICALL                                                     
   45    29        INIT_FCALL                                                   'define'
         30        SEND_VAL                                                     'HEX_SEGMENT_SIZE'
         31        SEND_VAL                                                     2
         32        DO_ICALL                                                     
   46    33        INIT_FCALL                                                   'define'
         34        SEND_VAL                                                     'BASE_FOR_HEX_CONVERSION'
         35        SEND_VAL                                                     256
         36        DO_ICALL                                                     
   47    37        INIT_FCALL                                                   'define'
         38        SEND_VAL                                                     'HASH_TYPE'
         39        SEND_VAL                                                     'sha256'
         40        DO_ICALL                                                     
   70    41        FRAMELESS_ICALL_3                preg_replace        ~24     '%2F%0D%7C%0A%2F', ''
         42        OP_DATA                                                      !0
         43        ASSIGN                                                       !0, ~24
   71    44        FRAMELESS_ICALL_3                preg_replace        ~26     '%2F%0D%7C%0A%2F', ''
         45        OP_DATA                                                      !1
         46        ASSIGN                                                       !1, ~26
   72    47      > JMPZ                                                         !4, ->55
   73    48    >   ROPE_INIT                                         5  ~29     !0
         49        ROPE_ADD                                          1  ~29     ~29, '-'
         50        ROPE_ADD                                          2  ~29     ~29, !1
         51        ROPE_ADD                                          3  ~29     ~29, '-'
         52        ROPE_END                                          4  ~28     ~29, !2
         53        ASSIGN                                                       !6, ~28
   72    54      > JMP                                                          ->63
   75    55    >   ROPE_INIT                                         7  ~34     !0
         56        ROPE_ADD                                          1  ~34     ~34, '-'
         57        ROPE_ADD                                          2  ~34     ~34, !1
         58        ROPE_ADD                                          3  ~34     ~34, '-'
         59        ROPE_ADD                                          4  ~34     ~34, !2
         60        ROPE_ADD                                          5  ~34     ~34, '-'
         61        ROPE_END                                          6  ~33     ~34, !3
         62        ASSIGN                                                       !6, ~33
   78    63    >   INIT_FCALL                                                   'getprovablyfairresult'
         64        SEND_VAR                                                     !6
         65        SEND_VAR                                                     !5
         66        DO_FCALL                                          0  $39     
         67        ASSIGN                                                       !7, $39
   80    68        NOP                                                          
         69        FETCH_DIM_R                                          ~41     !7, 'result'
         70        FAST_CONCAT                                          ~42     'Result%3A+', ~41
         71        ECHO                                                         ~42
   82    72      > RETURN                                                       1

Function calculatedecimalvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 4
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 4
Branch analysis from position: 25
Branch analysis from position: 4
filename:       /in/SCdP9
function name:  calculateDecimalValue
number of ops:  29
compiled vars:  !0 = $preResult, !1 = $decimalValue, !2 = $i, !3 = $hexValue
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   49     0  E >   RECV                                                 !0      
   51     1        ASSIGN                                                       !1, 0
   52     2        ASSIGN                                                       !2, 0
          3      > JMP                                                          ->22
   53     4    >   FETCH_CONSTANT                                       ~6      'HEX_SEGMENT_SIZE'
          5        MUL                                                  ~7      !2, ~6
          6        FETCH_CONSTANT                                       ~8      'HEX_SEGMENT_SIZE'
          7        FRAMELESS_ICALL_3                substr              ~9      !0, ~7
          8        OP_DATA                                                      ~8
          9        ASSIGN                                                       !3, ~9
   54    10        INIT_FCALL                                                   'hexdec'
         11        SEND_VAR                                                     !3
         12        DO_ICALL                                             $11     
         13        INIT_FCALL                                                   'pow'
         14        FETCH_CONSTANT                                       ~12     'BASE_FOR_HEX_CONVERSION'
         15        SEND_VAL                                                     ~12
         16        ADD                                                  ~13     !2, 1
         17        SEND_VAL                                                     ~13
         18        DO_ICALL                                             $14     
         19        DIV                                                  ~15     $11, $14
         20        ASSIGN_OP                                         1          !1, ~15
   52    21        PRE_INC                                                      !2
         22    >   FETCH_CONSTANT                                       ~18     'MAX_HEX_SEGMENTS'
         23        IS_SMALLER                                                   !2, ~18
         24      > JMPNZ                                                        ~19, ->4
   56    25    >   VERIFY_RETURN_TYPE                                           !1
         26      > RETURN                                                       !1
   57    27*       VERIFY_RETURN_TYPE                                           
         28*     > RETURN                                                       null

End of function calculatedecimalvalue

Function getprovablyfairresult:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SCdP9
function name:  getProvablyFairResult
number of ops:  22
compiled vars:  !0 = $init, !1 = $qty, !2 = $preResult, !3 = $decimalValue, !4 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   59     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   61     2        INIT_FCALL                                                   'hash'
          3        FETCH_CONSTANT                                       ~5      'HASH_TYPE'
          4        SEND_VAL                                                     ~5
          5        SEND_VAR                                                     !0
          6        DO_ICALL                                             $6      
          7        ASSIGN                                                       !2, $6
   62     8        INIT_FCALL                                                   'calculatedecimalvalue'
          9        SEND_VAR                                                     !2
         10        DO_FCALL                                          0  $8      
         11        ASSIGN                                                       !3, $8
   63    12        MUL                                                  ~10     !3, !1
         13        CAST                                              4  ~11     ~10
         14        ADD                                                  ~12     ~11, 1
         15        ASSIGN                                                       !4, ~12
   65    16        INIT_ARRAY                                           ~14     !2, 'preResult'
   66    17        ADD_ARRAY_ELEMENT                                    ~14     !4, 'result'
         18        VERIFY_RETURN_TYPE                                           ~14
         19      > RETURN                                                       ~14
   68    20*       VERIFY_RETURN_TYPE                                           
         21*     > RETURN                                                       null

End of function getprovablyfairresult

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
307.19 ms | 3377 KiB | 20 Q