3v4l.org

run code in 300+ PHP versions simultaneously
} <?php //Case Battle Fairness | Round Validation $serverSeed = 'cef7544d66f612a41121f506a2903135'; // Server seed $eosBlockSeed = '1a869e974688d612eae6886a5813c2d67da069f3be2b3bf23d381cf2705c9dab'; // EOS Block Seed // 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 == '') { 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'); if (!function_exists('calculateDecimalValue')) { 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; } } if (!function_exists('getProvablyFairResult')) { function getProvablyFairResult(string $init, string $serverSeed, int $qty): array { $preResult = hash_hmac(HASH_TYPE, $init, $serverSeed); $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); // Print header echo "Case Battle Fairness Validation Results\n"; echo "=====================================\n"; echo "Server Seed: " . substr($serverSeed, 0, 16) . "...\n"; echo "EOS Block Seed: " . substr($eosBlockSeed, 0, 32) . "...\n"; echo "Ticket Quantity: " . number_format($ticketQuantity) . "\n\n"; // Create table header echo str_pad("Round", 7) . " | "; for ($player = 1; $player <= 4; $player++) { echo str_pad("Player $player", 12) . " | "; } echo "\n"; echo str_repeat("-", 7) . " | " . str_repeat(str_repeat("-", 12) . " | ", 4) . "\n"; // Calculate and display results for all rounds and players for ($roundNumber = 1; $roundNumber <= 50; $roundNumber++) { echo str_pad($roundNumber, 7, " ", STR_PAD_LEFT) . " | "; for ($playerPosition = 1; $playerPosition <= 4; $playerPosition++) { if ($isTiebreaker) { $stringToHash = "$eosBlockSeed-$roundNumber"; } else { $stringToHash = "$eosBlockSeed-$roundNumber-$playerPosition"; } $result = getProvablyFairResult($stringToHash, $serverSeed, $ticketQuantity); echo str_pad(number_format($result['result']), 12, " ", STR_PAD_LEFT) . " | "; } echo "\n"; // Add a separator line every 10 rounds for better readability if ($roundNumber % 10 == 0 && $roundNumber < 50) { echo str_repeat("-", 7) . " | " . str_repeat(str_repeat("-", 12) . " | ", 4) . "\n"; } } echo "\n\nNote: Each result represents the ticket number (1 to " . number_format($ticketQuantity) . ") that won for that player in that round.\n"; // Optional: Show example of hash calculation for verification echo "\n\nExample Verification (Round 1, Player 1):\n"; echo "==========================================\n"; $exampleString = "$eosBlockSeed-1-1"; $exampleResult = getProvablyFairResult($exampleString, $serverSeed, $ticketQuantity); echo "Input String: " . substr($exampleString, 0, 50) . "...\n"; echo "HMAC-SHA256 Hash: " . $exampleResult['preResult'] . "\n"; echo "Result: " . number_format($exampleResult['result']) . "\n"; ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 34
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 40
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 93
Branch analysis from position: 93
2 jumps found. (Code = 44) Position 1 = 95, Position 2 = 84
Branch analysis from position: 95
1 jumps found. (Code = 42) Position 1 = 183
Branch analysis from position: 183
2 jumps found. (Code = 44) Position 1 = 185, Position 2 = 115
Branch analysis from position: 185
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 115
1 jumps found. (Code = 42) Position 1 = 156
Branch analysis from position: 156
2 jumps found. (Code = 44) Position 1 = 158, Position 2 = 125
Branch analysis from position: 158
2 jumps found. (Code = 46) Position 1 = 162, Position 2 = 164
Branch analysis from position: 162
2 jumps found. (Code = 43) Position 1 = 165, Position 2 = 182
Branch analysis from position: 165
2 jumps found. (Code = 44) Position 1 = 185, Position 2 = 115
Branch analysis from position: 185
Branch analysis from position: 115
Branch analysis from position: 182
Branch analysis from position: 164
Branch analysis from position: 125
2 jumps found. (Code = 43) Position 1 = 126, Position 2 = 131
Branch analysis from position: 126
1 jumps found. (Code = 42) Position 1 = 137
Branch analysis from position: 137
2 jumps found. (Code = 44) Position 1 = 158, Position 2 = 125
Branch analysis from position: 158
Branch analysis from position: 125
Branch analysis from position: 131
2 jumps found. (Code = 44) Position 1 = 158, Position 2 = 125
Branch analysis from position: 158
Branch analysis from position: 125
Branch analysis from position: 84
2 jumps found. (Code = 44) Position 1 = 95, Position 2 = 84
Branch analysis from position: 95
Branch analysis from position: 84
Branch analysis from position: 40
Branch analysis from position: 34
Branch analysis from position: 9
filename:       /in/cm4n2
function name:  (null)
number of ops:  222
compiled vars:  !0 = $serverSeed, !1 = $eosBlockSeed, !2 = $isTiebreaker, !3 = $ticketQuantity, !4 = $player, !5 = $roundNumber, !6 = $playerPosition, !7 = $stringToHash, !8 = $result, !9 = $exampleString, !10 = $exampleResult
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    1     0  E >   ECHO                                                     '%7D%0A%0A'
    6     1        ASSIGN                                                   !0, 'cef7544d66f612a41121f506a2903135'
    7     2        ASSIGN                                                   !1, '1a869e974688d612eae6886a5813c2d67da069f3be2b3bf23d381cf2705c9dab'
   10     3        ASSIGN                                                   !2, <false>
   19     4        ASSIGN                                                   !3, 100000
   23     5        IS_EQUAL                                         ~15     !0, ''
          6      > JMPNZ_EX                                         ~15     ~15, ->9
          7    >   IS_EQUAL                                         ~16     !1, ''
          8        BOOL                                             ~15     ~16
          9    > > JMPZ                                                     ~15, ->12
   24    10    >   ECHO                                                     'Fill+in+details'
   25    11      > RETURN                                                   null
   28    12    >   INIT_FCALL                                               'define'
         13        SEND_VAL                                                 'MAX_HEX_SEGMENTS'
         14        SEND_VAL                                                 6
         15        DO_ICALL                                                 
   29    16        INIT_FCALL                                               'define'
         17        SEND_VAL                                                 'HEX_SEGMENT_SIZE'
         18        SEND_VAL                                                 2
         19        DO_ICALL                                                 
   30    20        INIT_FCALL                                               'define'
         21        SEND_VAL                                                 'BASE_FOR_HEX_CONVERSION'
         22        SEND_VAL                                                 256
         23        DO_ICALL                                                 
   31    24        INIT_FCALL                                               'define'
         25        SEND_VAL                                                 'HASH_TYPE'
         26        SEND_VAL                                                 'sha256'
         27        DO_ICALL                                                 
   33    28        INIT_FCALL                                               'function_exists'
         29        SEND_VAL                                                 'calculateDecimalValue'
         30        DO_ICALL                                         $21     
         31        BOOL_NOT                                         ~22     $21
         32      > JMPZ                                                     ~22, ->34
   34    33    >   DECLARE_FUNCTION                                         'calculatedecimalvalue'
   45    34    >   INIT_FCALL                                               'function_exists'
         35        SEND_VAL                                                 'getProvablyFairResult'
         36        DO_ICALL                                         $23     
         37        BOOL_NOT                                         ~24     $23
         38      > JMPZ                                                     ~24, ->40
   46    39    >   DECLARE_FUNCTION                                         'getprovablyfairresult'
   58    40    >   INIT_FCALL                                               'preg_replace'
         41        SEND_VAL                                                 '%2F%0D%7C%0A%2F'
         42        SEND_VAL                                                 ''
         43        SEND_VAR                                                 !0
         44        DO_ICALL                                         $25     
         45        ASSIGN                                                   !0, $25
   59    46        INIT_FCALL                                               'preg_replace'
         47        SEND_VAL                                                 '%2F%0D%7C%0A%2F'
         48        SEND_VAL                                                 ''
         49        SEND_VAR                                                 !1
         50        DO_ICALL                                         $27     
         51        ASSIGN                                                   !1, $27
   62    52        ECHO                                                     'Case+Battle+Fairness+Validation+Results%0A'
   63    53        ECHO                                                     '%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0A'
   64    54        INIT_FCALL                                               'substr'
         55        SEND_VAR                                                 !0
         56        SEND_VAL                                                 0
         57        SEND_VAL                                                 16
         58        DO_ICALL                                         $29     
         59        CONCAT                                           ~30     'Server+Seed%3A+', $29
         60        CONCAT                                           ~31     ~30, '...%0A'
         61        ECHO                                                     ~31
   65    62        INIT_FCALL                                               'substr'
         63        SEND_VAR                                                 !1
         64        SEND_VAL                                                 0
         65        SEND_VAL                                                 32
         66        DO_ICALL                                         $32     
         67        CONCAT                                           ~33     'EOS+Block+Seed%3A+', $32
         68        CONCAT                                           ~34     ~33, '...%0A'
         69        ECHO                                                     ~34
   66    70        INIT_FCALL                                               'number_format'
         71        SEND_VAR                                                 !3
         72        DO_ICALL                                         $35     
         73        CONCAT                                           ~36     'Ticket+Quantity%3A+', $35
         74        CONCAT                                           ~37     ~36, '%0A%0A'
         75        ECHO                                                     ~37
   69    76        INIT_FCALL                                               'str_pad'
         77        SEND_VAL                                                 'Round'
         78        SEND_VAL                                                 7
         79        DO_ICALL                                         $38     
         80        CONCAT                                           ~39     $38, '+%7C+'
         81        ECHO                                                     ~39
   70    82        ASSIGN                                                   !4, 1
         83      > JMP                                                      ->93
   71    84    >   INIT_FCALL                                               'str_pad'
         85        NOP                                                      
         86        FAST_CONCAT                                      ~41     'Player+', !4
         87        SEND_VAL                                                 ~41
         88        SEND_VAL                                                 12
         89        DO_ICALL                                         $42     
         90        CONCAT                                           ~43     $42, '+%7C+'
         91        ECHO                                                     ~43
   70    92        PRE_INC                                                  !4
         93    >   IS_SMALLER_OR_EQUAL                                      !4, 4
         94      > JMPNZ                                                    ~45, ->84
   73    95    >   ECHO                                                     '%0A'
   74    96        INIT_FCALL                                               'str_repeat'
         97        SEND_VAL                                                 '-'
         98        SEND_VAL                                                 7
         99        DO_ICALL                                         $46     
        100        CONCAT                                           ~47     $46, '+%7C+'
        101        INIT_FCALL                                               'str_repeat'
        102        INIT_FCALL                                               'str_repeat'
        103        SEND_VAL                                                 '-'
        104        SEND_VAL                                                 12
        105        DO_ICALL                                         $48     
        106        CONCAT                                           ~49     $48, '+%7C+'
        107        SEND_VAL                                                 ~49
        108        SEND_VAL                                                 4
        109        DO_ICALL                                         $50     
        110        CONCAT                                           ~51     ~47, $50
        111        CONCAT                                           ~52     ~51, '%0A'
        112        ECHO                                                     ~52
   77   113        ASSIGN                                                   !5, 1
        114      > JMP                                                      ->183
   78   115    >   INIT_FCALL                                               'str_pad'
        116        SEND_VAR                                                 !5
        117        SEND_VAL                                                 7
        118        SEND_VAL                                                 '+'
        119        SEND_VAL                                                 0
        120        DO_ICALL                                         $54     
        121        CONCAT                                           ~55     $54, '+%7C+'
        122        ECHO                                                     ~55
   80   123        ASSIGN                                                   !6, 1
        124      > JMP                                                      ->156
   81   125    > > JMPZ                                                     !2, ->131
   82   126    >   ROPE_INIT                                     3  ~58     !1
        127        ROPE_ADD                                      1  ~58     ~58, '-'
        128        ROPE_END                                      2  ~57     ~58, !5
        129        ASSIGN                                                   !7, ~57
   81   130      > JMP                                                      ->137
   84   131    >   ROPE_INIT                                     5  ~62     !1
        132        ROPE_ADD                                      1  ~62     ~62, '-'
        133        ROPE_ADD                                      2  ~62     ~62, !5
        134        ROPE_ADD                                      3  ~62     ~62, '-'
        135        ROPE_END                                      4  ~61     ~62, !6
        136        ASSIGN                                                   !7, ~61
   87   137    >   INIT_FCALL_BY_NAME                                       'getProvablyFairResult'
        138        SEND_VAR_EX                                              !7
        139        SEND_VAR_EX                                              !0
        140        SEND_VAR_EX                                              !3
        141        DO_FCALL                                      0  $66     
        142        ASSIGN                                                   !8, $66
   88   143        INIT_FCALL                                               'str_pad'
        144        INIT_FCALL                                               'number_format'
        145        FETCH_DIM_R                                      ~68     !8, 'result'
        146        SEND_VAL                                                 ~68
        147        DO_ICALL                                         $69     
        148        SEND_VAR                                                 $69
        149        SEND_VAL                                                 12
        150        SEND_VAL                                                 '+'
        151        SEND_VAL                                                 0
        152        DO_ICALL                                         $70     
        153        CONCAT                                           ~71     $70, '+%7C+'
        154        ECHO                                                     ~71
   80   155        PRE_INC                                                  !6
        156    >   IS_SMALLER_OR_EQUAL                                      !6, 4
        157      > JMPNZ                                                    ~73, ->125
   90   158    >   ECHO                                                     '%0A'
   93   159        MOD                                              ~74     !5, 10
        160        IS_EQUAL                                         ~75     ~74, 0
        161      > JMPZ_EX                                          ~75     ~75, ->164
        162    >   IS_SMALLER                                       ~76     !5, 50
        163        BOOL                                             ~75     ~76
        164    > > JMPZ                                                     ~75, ->182
   94   165    >   INIT_FCALL                                               'str_repeat'
        166        SEND_VAL                                                 '-'
        167        SEND_VAL                                                 7
        168        DO_ICALL                                         $77     
        169        CONCAT                                           ~78     $77, '+%7C+'
        170        INIT_FCALL                                               'str_repeat'
        171        INIT_FCALL                                               'str_repeat'
        172        SEND_VAL                                                 '-'
        173        SEND_VAL                                                 12
        174        DO_ICALL                                         $79     
        175        CONCAT                                           ~80     $79, '+%7C+'
        176        SEND_VAL                                                 ~80
        177        SEND_VAL                                                 4
        178        DO_ICALL                                         $81     
        179        CONCAT                                           ~82     ~78, $81
        180        CONCAT                                           ~83     ~82, '%0A'
        181        ECHO                                                     ~83
   77   182    >   PRE_INC                                                  !5
        183    >   IS_SMALLER_OR_EQUAL                                      !5, 50
        184      > JMPNZ                                                    ~85, ->115
   98   185    >   INIT_FCALL                                               'number_format'
        186        SEND_VAR                                                 !3
        187        DO_ICALL                                         $86     
        188        CONCAT                                           ~87     '%0A%0ANote%3A+Each+result+represents+the+ticket+number+%281+to+', $86
        189        CONCAT                                           ~88     ~87, '%29+that+won+for+that+player+in+that+round.%0A'
        190        ECHO                                                     ~88
  101   191        ECHO                                                     '%0A%0AExample+Verification+%28Round+1%2C+Player+1%29%3A%0A'
  102   192        ECHO                                                     '%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0A'
  103   193        NOP                                                      
        194        FAST_CONCAT                                      ~89     !1, '-1-1'
        195        ASSIGN                                                   !9, ~89
  104   196        INIT_FCALL_BY_NAME                                       'getProvablyFairResult'
        197        SEND_VAR_EX                                              !9
        198        SEND_VAR_EX                                              !0
        199        SEND_VAR_EX                                              !3
        200        DO_FCALL                                      0  $91     
        201        ASSIGN                                                   !10, $91
  105   202        INIT_FCALL                                               'substr'
        203        SEND_VAR                                                 !9
        204        SEND_VAL                                                 0
        205        SEND_VAL                                                 50
        206        DO_ICALL                                         $93     
        207        CONCAT                                           ~94     'Input+String%3A+', $93
        208        CONCAT                                           ~95     ~94, '...%0A'
        209        ECHO                                                     ~95
  106   210        FETCH_DIM_R                                      ~96     !10, 'preResult'
        211        CONCAT                                           ~97     'HMAC-SHA256+Hash%3A+', ~96
        212        CONCAT                                           ~98     ~97, '%0A'
        213        ECHO                                                     ~98
  107   214        INIT_FCALL                                               'number_format'
        215        FETCH_DIM_R                                      ~99     !10, 'result'
        216        SEND_VAL                                                 ~99
        217        DO_ICALL                                         $100    
        218        CONCAT                                           ~101    'Result%3A+', $100
        219        CONCAT                                           ~102    ~101, '%0A'
        220        ECHO                                                     ~102
  108   221      > RETURN                                                   1


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

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cm4n2
function name:  getProvablyFairResult
number of ops:  24
compiled vars:  !0 = $init, !1 = $serverSeed, !2 = $qty, !3 = $preResult, !4 = $decimalValue, !5 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   48     3        INIT_FCALL                                               'hash_hmac'
          4        FETCH_CONSTANT                                   ~6      'HASH_TYPE'
          5        SEND_VAL                                                 ~6
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !3, $7
   49    10        INIT_FCALL_BY_NAME                                       'calculateDecimalValue'
         11        SEND_VAR_EX                                              !3
         12        DO_FCALL                                      0  $9      
         13        ASSIGN                                                   !4, $9
   50    14        MUL                                              ~11     !4, !2
         15        CAST                                          4  ~12     ~11
         16        ADD                                              ~13     ~12, 1
         17        ASSIGN                                                   !5, ~13
   52    18        INIT_ARRAY                                       ~15     !3, 'preResult'
   53    19        ADD_ARRAY_ELEMENT                                ~15     !5, 'result'
         20        VERIFY_RETURN_TYPE                                       ~15
         21      > RETURN                                                   ~15
   55    22*       VERIFY_RETURN_TYPE                                       
         23*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.97 ms | 1033 KiB | 23 Q