3v4l.org

run code in 300+ PHP versions simultaneously
<?php // // // EmpireDrop Provably Fair Case Battles // // // /* * Fill in all three below and click the blue 'eval();' button. ------------------ */ $server_seed = ''; $client_seed = ''; $nonce = $roundNumber = 0; /* ------------------ */ if ($server_seed == '' || $client_seed == '' || $nonce < 0) { echo "Fill in details"; return; } define('MIN_RESULT', 0.00001); define('MAX_RESULT', 100); define('CONVERT_RATE', 100000); define('HASH_TYPE', 'sha256'); function getProvablyFairResult(string $client_seed, string $server_seed, int $nounce) { $hash = hash_hmac(HASH_TYPE, "{$client_seed}-{$nounce}", $server_seed); $normalized = hexdec($hash) / (16 ** strlen($hash)); $roll = MIN_RESULT + $normalized * (MAX_RESULT - MIN_RESULT); return convertDecimalValue($roll); } function convertDecimalValue(float $value): int { return round($value * CONVERT_RATE); } $result = getProvablyFairResult($client_seed, $server_seed, $nonce); echo "Result: {$result}";
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 47) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
Branch analysis from position: 8
filename:       /in/pGCPE
function name:  (null)
number of ops:  40
compiled vars:  !0 = $server_seed, !1 = $client_seed, !2 = $nonce, !3 = $roundNumber, !4 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   ASSIGN                                                   !0, ''
   11     1        ASSIGN                                                   !1, ''
   12     2        ASSIGN                                           ~7      !3, 0
          3        ASSIGN                                                   !2, ~7
   16     4        IS_EQUAL                                         ~9      !0, ''
          5      > JMPNZ_EX                                         ~9      ~9, ->8
          6    >   IS_EQUAL                                         ~10     !1, ''
          7        BOOL                                             ~9      ~10
          8    > > JMPNZ_EX                                         ~9      ~9, ->11
          9    >   IS_SMALLER                                       ~11     !2, 0
         10        BOOL                                             ~9      ~11
         11    > > JMPZ                                                     ~9, ->14
   17    12    >   ECHO                                                     'Fill+in+details'
   18    13      > RETURN                                                   null
   21    14    >   INIT_FCALL                                               'define'
         15        SEND_VAL                                                 'MIN_RESULT'
         16        SEND_VAL                                                 1.0e-5
         17        DO_ICALL                                                 
   22    18        INIT_FCALL                                               'define'
         19        SEND_VAL                                                 'MAX_RESULT'
         20        SEND_VAL                                                 100
         21        DO_ICALL                                                 
   23    22        INIT_FCALL                                               'define'
         23        SEND_VAL                                                 'CONVERT_RATE'
         24        SEND_VAL                                                 100000
         25        DO_ICALL                                                 
   24    26        INIT_FCALL                                               'define'
         27        SEND_VAL                                                 'HASH_TYPE'
         28        SEND_VAL                                                 'sha256'
         29        DO_ICALL                                                 
   41    30        INIT_FCALL                                               'getprovablyfairresult'
         31        SEND_VAR                                                 !1
         32        SEND_VAR                                                 !0
         33        SEND_VAR                                                 !2
         34        DO_FCALL                                      0  $16     
         35        ASSIGN                                                   !4, $16
   43    36        NOP                                                      
         37        FAST_CONCAT                                      ~18     'Result%3A+', !4
         38        ECHO                                                     ~18
         39      > RETURN                                                   1

Function getprovablyfairresult:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pGCPE
function name:  getProvablyFairResult
number of ops:  32
compiled vars:  !0 = $client_seed, !1 = $server_seed, !2 = $nounce, !3 = $hash, !4 = $normalized, !5 = $roll
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   28     3        INIT_FCALL                                               'hash_hmac'
          4        FETCH_CONSTANT                                   ~6      'HASH_TYPE'
          5        SEND_VAL                                                 ~6
          6        ROPE_INIT                                     3  ~8      !0
          7        ROPE_ADD                                      1  ~8      ~8, '-'
          8        ROPE_END                                      2  ~7      ~8, !2
          9        SEND_VAL                                                 ~7
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $10     
         12        ASSIGN                                                   !3, $10
   29    13        INIT_FCALL                                               'hexdec'
         14        SEND_VAR                                                 !3
         15        DO_ICALL                                         $12     
         16        STRLEN                                           ~13     !3
         17        POW                                              ~14     16, ~13
         18        DIV                                              ~15     $12, ~14
         19        ASSIGN                                                   !4, ~15
   30    20        FETCH_CONSTANT                                   ~17     'MIN_RESULT'
         21        FETCH_CONSTANT                                   ~18     'MAX_RESULT'
         22        FETCH_CONSTANT                                   ~19     'MIN_RESULT'
         23        SUB                                              ~20     ~18, ~19
         24        MUL                                              ~21     !4, ~20
         25        ADD                                              ~22     ~17, ~21
         26        ASSIGN                                                   !5, ~22
   32    27        INIT_FCALL_BY_NAME                                       'convertDecimalValue'
         28        SEND_VAR_EX                                              !5
         29        DO_FCALL                                      0  $24     
         30      > RETURN                                                   $24
   33    31*     > RETURN                                                   null

End of function getprovablyfairresult

Function convertdecimalvalue:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pGCPE
function name:  convertDecimalValue
number of ops:  10
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   38     1        INIT_FCALL                                               'round'
          2        FETCH_CONSTANT                                   ~1      'CONVERT_RATE'
          3        MUL                                              ~2      !0, ~1
          4        SEND_VAL                                                 ~2
          5        DO_ICALL                                         $3      
          6        VERIFY_RETURN_TYPE                                       $3
          7      > RETURN                                                   $3
   39     8*       VERIFY_RETURN_TYPE                                       
          9*     > RETURN                                                   null

End of function convertdecimalvalue

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.54 ms | 994 KiB | 18 Q