3v4l.org

run code in 500+ PHP versions simultaneously
<?php $serverSeed = 'e78c228314facf55690f0d2cbbfec52e1c4576d82ef57e31c0c0054590f8b78d'; $serverSeedHash = '997a9ff96cbca4eab99d38895c32e9c030b031c33ecc1d507467a7640a4f46d5'; $clientSeed = 'f683e8c90dd7207618efb578f0ac98f8'; $nonce = 89; $chance = '0.57520129'; $reportedRoll = '3436792651121867'; $reportedResult = 'LOST'; $digest = hash_hmac('sha256', $clientSeed . ':' . $nonce, $serverSeed); $roll = hexdec(substr($digest, 0, 13)); $rollText = sprintf('%.0f', $roll); $scale = 100000000; $space = 2 ** 52; [$whole, $fraction] = array_pad(explode('.', $chance, 2), 2, ''); // Exact here: every integer intermediate stays below PHP float's 53-bit limit. $probability = (float) $whole * $scale + (float) str_pad(substr($fraction, 0, 8), 8, '0'); $wholeSteps = floor($space / $scale); $threshold = $probability * $wholeSteps + floor($probability * ($space - $wholeSteps * $scale) / $scale); $result = $roll < $threshold ? 'WON' : 'LOST'; $check = fn(bool $ok) => $ok ? 'OK' : 'MISMATCH'; echo 'Hash: ' . $check(hash('sha256', $serverSeed) === strtolower($serverSeedHash)) . PHP_EOL; echo "Roll: $rollText / $reportedRoll — " . $check($rollText === $reportedRoll) . PHP_EOL; echo "Result: $result / $reportedResult — " . $check($result === $reportedResult);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 72, Position 2 = 74
Branch analysis from position: 72
1 jumps found. (Code = 42) Position 1 = 75
Branch analysis from position: 75
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 74
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MmqA2
function name:  (null)
number of ops:  116
compiled vars:  !0 = $serverSeed, !1 = $serverSeedHash, !2 = $clientSeed, !3 = $nonce, !4 = $chance, !5 = $reportedRoll, !6 = $reportedResult, !7 = $digest, !8 = $roll, !9 = $rollText, !10 = $scale, !11 = $space, !12 = $whole, !13 = $fraction, !14 = $probability, !15 = $wholeSteps, !16 = $threshold, !17 = $result, !18 = $check
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, 'e78c228314facf55690f0d2cbbfec52e1c4576d82ef57e31c0c0054590f8b78d'
    3     1        ASSIGN                                                       !1, '997a9ff96cbca4eab99d38895c32e9c030b031c33ecc1d507467a7640a4f46d5'
    4     2        ASSIGN                                                       !2, 'f683e8c90dd7207618efb578f0ac98f8'
    5     3        ASSIGN                                                       !3, 89
    6     4        ASSIGN                                                       !4, '0.57520129'
    7     5        ASSIGN                                                       !5, '3436792651121867'
    8     6        ASSIGN                                                       !6, 'LOST'
   10     7        INIT_FCALL                                                   'hash_hmac'
          8        SEND_VAL                                                     'sha256'
          9        CONCAT                                               ~26     !2, '%3A'
         10        CONCAT                                               ~27     ~26, !3
         11        SEND_VAL                                                     ~27
         12        SEND_VAR                                                     !0
         13        DO_ICALL                                             $28     
         14        ASSIGN                                                       !7, $28
   11    15        INIT_FCALL                                                   'hexdec'
         16        FRAMELESS_ICALL_3                substr              ~30     !7, 0
         17        OP_DATA                                                      13
         18        SEND_VAL                                                     ~30
         19        DO_ICALL                                             $31     
         20        ASSIGN                                                       !8, $31
   12    21        INIT_FCALL                                                   'sprintf'
         22        SEND_VAL                                                     '%25.0f'
         23        SEND_VAR                                                     !8
         24        DO_ICALL                                             $33     
         25        ASSIGN                                                       !9, $33
   14    26        ASSIGN                                                       !10, 100000000
   15    27        ASSIGN                                                       !11, 4503599627370496
   16    28        INIT_FCALL                                                   'array_pad'
         29        INIT_FCALL                                                   'explode'
         30        SEND_VAL                                                     '.'
         31        SEND_VAR                                                     !4
         32        SEND_VAL                                                     2
         33        DO_ICALL                                             $37     
         34        SEND_VAR                                                     $37
         35        SEND_VAL                                                     2
         36        SEND_VAL                                                     ''
         37        DO_ICALL                                             $38     
         38        FETCH_LIST_R                                         $39     $38, 0
         39        ASSIGN                                                       !12, $39
         40        FETCH_LIST_R                                         $41     $38, 1
         41        ASSIGN                                                       !13, $41
         42        FREE                                                         $38
   18    43        CAST                                              5  ~43     !12
         44        MUL                                                  ~44     !10, ~43
   19    45        INIT_FCALL                                                   'str_pad'
         46        FRAMELESS_ICALL_3                substr              ~45     !13, 0
         47        OP_DATA                                                      8
         48        SEND_VAL                                                     ~45
         49        SEND_VAL                                                     8
         50        SEND_VAL                                                     '0'
         51        DO_ICALL                                             $46     
         52        CAST                                              5  ~47     $46
         53        ADD                                                  ~48     ~44, ~47
   18    54        ASSIGN                                                       !14, ~48
   20    55        INIT_FCALL                                                   'floor'
         56        DIV                                                  ~50     !11, !10
         57        SEND_VAL                                                     ~50
         58        DO_ICALL                                             $51     
         59        ASSIGN                                                       !15, $51
   21    60        MUL                                                  ~53     !14, !15
   22    61        INIT_FCALL                                                   'floor'
         62        MUL                                                  ~54     !15, !10
         63        SUB                                                  ~55     !11, ~54
         64        MUL                                                  ~56     !14, ~55
         65        DIV                                                  ~57     ~56, !10
         66        SEND_VAL                                                     ~57
         67        DO_ICALL                                             $58     
         68        ADD                                                  ~59     ~53, $58
   21    69        ASSIGN                                                       !16, ~59
   23    70        IS_SMALLER                                                   !8, !16
         71      > JMPZ                                                         ~61, ->74
         72    >   QM_ASSIGN                                            ~62     'WON'
         73      > JMP                                                          ->75
         74    >   QM_ASSIGN                                            ~62     'LOST'
         75    >   ASSIGN                                                       !17, ~62
   24    76        DECLARE_LAMBDA_FUNCTION                              ~64     [0]
         77        ASSIGN                                                       !18, ~64
   26    78        INIT_DYNAMIC_CALL                                            !18
         79        INIT_FCALL                                                   'hash'
         80        SEND_VAL                                                     'sha256'
         81        SEND_VAR                                                     !0
         82        DO_ICALL                                             $66     
         83        INIT_FCALL                                                   'strtolower'
         84        SEND_VAR                                                     !1
         85        DO_ICALL                                             $67     
         86        IS_IDENTICAL                                         ~68     $66, $67
         87        SEND_VAL_EX                                                  ~68
         88        DO_FCALL                                          0  $69     
         89        CONCAT                                               ~70     'Hash%3A+', $69
         90        CONCAT                                               ~71     ~70, '%0A'
         91        ECHO                                                         ~71
   27    92        ROPE_INIT                                         5  ~73     'Roll%3A+'
         93        ROPE_ADD                                          1  ~73     ~73, !9
         94        ROPE_ADD                                          2  ~73     ~73, '+%2F+'
         95        ROPE_ADD                                          3  ~73     ~73, !5
         96        ROPE_END                                          4  ~72     ~73, '+%E2%80%94+'
         97        INIT_DYNAMIC_CALL                                            !18
         98        IS_IDENTICAL                                         ~76     !9, !5
         99        SEND_VAL_EX                                                  ~76
        100        DO_FCALL                                          0  $77     
        101        CONCAT                                               ~78     ~72, $77
        102        CONCAT                                               ~79     ~78, '%0A'
        103        ECHO                                                         ~79
   28   104        ROPE_INIT                                         5  ~81     'Result%3A+'
        105        ROPE_ADD                                          1  ~81     ~81, !17
        106        ROPE_ADD                                          2  ~81     ~81, '+%2F+'
        107        ROPE_ADD                                          3  ~81     ~81, !6
        108        ROPE_END                                          4  ~80     ~81, '+%E2%80%94+'
        109        INIT_DYNAMIC_CALL                                            !18
        110        IS_IDENTICAL                                         ~84     !17, !6
        111        SEND_VAL_EX                                                  ~84
        112        DO_FCALL                                          0  $85     
        113        CONCAT                                               ~86     ~80, $85
        114        ECHO                                                         ~86
        115      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 2, Position 2 = 4
Branch analysis from position: 2
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/MmqA2
function name:  {closure:/in/MmqA2:24}
number of ops:  7
compiled vars:  !0 = $ok
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   RECV                                                 !0      
          1      > JMPZ                                                         !0, ->4
          2    >   QM_ASSIGN                                            ~1      'OK'
          3      > JMP                                                          ->5
          4    >   QM_ASSIGN                                            ~1      'MISMATCH'
          5    > > RETURN                                                       ~1
          6*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
142.79 ms | 501 KiB | 16 Q