Exemplo n.º 1
0
 public function findUpstreamShareStrict($aBlock, $last = 0)
 {
     // Many use stratum, so we create our stratum check first
     $version = pack("I*", sprintf('%08d', $aBlock['version']));
     $previousblockhash = pack("H*", swapEndian($aBlock['previousblockhash']));
     $merkleroot = pack("H*", swapEndian($aBlock['merkleroot']));
     $time = pack("I*", $aBlock['time']);
     $bits = pack("H*", swapEndian($aBlock['bits']));
     $nonce = pack("I*", $aBlock['nonce']);
     $header_bin = $version . $previousblockhash . $merkleroot . $time . $bits . $nonce;
     $header_hex = implode(unpack("H*", $header_bin));
     // Stratum supported blockhash solution entry
     $stmt = $this->mysqli->prepare("SELECT SUBSTRING_INDEX( `username` , '.', 1 ) AS account, username as worker, id FROM {$this->table} WHERE solution = ? LIMIT 1");
     if ($this->checkStmt($stmt) && $stmt->bind_param('s', $aBlock['hash']) && $stmt->execute() && ($result = $stmt->get_result())) {
         $this->oUpstream = $result->fetch_object();
         $this->share_type = 'stratum_blockhash';
         if (!empty($this->oUpstream->account) && !empty($this->oUpstream->worker) && is_int($this->oUpstream->id)) {
             return true;
         }
     }
     // Stratum scrypt hash check
     $scrypt_hash = swapEndian(bin2hex(Scrypt::calc($header_bin, $header_bin, 1024, 1, 1, 32)));
     $stmt = $this->mysqli->prepare("SELECT SUBSTRING_INDEX( `username` , '.', 1 ) AS account, username as worker, id FROM {$this->table} WHERE solution = ? LIMIT 1");
     if ($this->checkStmt($stmt) && $stmt->bind_param('s', $scrypt_hash) && $stmt->execute() && ($result = $stmt->get_result())) {
         $this->oUpstream = $result->fetch_object();
         $this->share_type = 'stratum_solution';
         if (!empty($this->oUpstream->account) && !empty($this->oUpstream->worker) && is_int($this->oUpstream->id)) {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * Find upstream accepted share that should be valid for a specific block
  * Assumptions:
  *  * Shares are matching blocks in ASC order
  *  * We can skip all upstream shares of previously found ones used in a block
  * @param last int Skips all shares up to last to find new share
  * @return bool
  **/
 public function findUpstreamShare($aBlock, $last = 0)
 {
     // Many use stratum, so we create our stratum check first
     $version = pack("I*", sprintf('%08d', $aBlock['version']));
     $previousblockhash = pack("H*", swapEndian($aBlock['previousblockhash']));
     $merkleroot = pack("H*", swapEndian($aBlock['merkleroot']));
     $time = pack("I*", $aBlock['time']);
     $bits = pack("H*", swapEndian($aBlock['bits']));
     $nonce = pack("I*", $aBlock['nonce']);
     $header_bin = $version . $previousblockhash . $merkleroot . $time . $bits . $nonce;
     $header_hex = implode(unpack("H*", $header_bin));
     // Stratum supported blockhash solution entry
     $stmt = $this->mysqli->prepare("SELECT SUBSTRING_INDEX( `username` , '.', 1 ) AS account, username as worker, id FROM {$this->table} WHERE solution = ? LIMIT 1");
     if ($this->checkStmt($stmt) && $stmt->bind_param('s', $aBlock['hash']) && $stmt->execute() && ($result = $stmt->get_result())) {
         $this->oUpstream = $result->fetch_object();
         $this->share_type = 'stratum_blockhash';
         if (!empty($this->oUpstream->account) && !empty($this->oUpstream->worker) && is_int($this->oUpstream->id)) {
             return true;
         }
     }
     // Stratum scrypt hash check
     $scrypt_hash = swapEndian(bin2hex(Scrypt::calc($header_bin, $header_bin, 1024, 1, 1, 32)));
     $stmt = $this->mysqli->prepare("SELECT SUBSTRING_INDEX( `username` , '.', 1 ) AS account, username as worker, id FROM {$this->table} WHERE solution = ? LIMIT 1");
     if ($this->checkStmt($stmt) && $stmt->bind_param('s', $scrypt_hash) && $stmt->execute() && ($result = $stmt->get_result())) {
         $this->oUpstream = $result->fetch_object();
         $this->share_type = 'stratum_solution';
         if (!empty($this->oUpstream->account) && !empty($this->oUpstream->worker) && is_int($this->oUpstream->id)) {
             return true;
         }
     }
     // Failed to fetch via startum solution, try pushpoold
     // Fallback to pushpoold solution type
     $ppheader = sprintf('%08d', $aBlock['version']) . word_reverse($aBlock['previousblockhash']) . word_reverse($aBlock['merkleroot']) . dechex($aBlock['time']) . $aBlock['bits'] . dechex($aBlock['nonce']);
     $stmt = $this->mysqli->prepare("SELECT SUBSTRING_INDEX( `username` , '.', 1 ) AS account, username as worker, id FROM {$this->table} WHERE solution LIKE CONCAT(?, '%') LIMIT 1");
     if ($this->checkStmt($stmt) && $stmt->bind_param('s', $ppheader) && $stmt->execute() && ($result = $stmt->get_result())) {
         $this->oUpstream = $result->fetch_object();
         $this->share_type = 'pp_solution';
         if (!empty($this->oUpstream->account) && !empty($this->oUpstream->worker) && is_int($this->oUpstream->id)) {
             return true;
         }
     }
     // Still no match, try upstream result with timerange
     $stmt = $this->mysqli->prepare("\n      SELECT\n      SUBSTRING_INDEX( `username` , '.', 1 ) AS account, username as worker, id\n      FROM {$this->table}\n      WHERE upstream_result = 'Y'\n      AND id > ?\n      AND UNIX_TIMESTAMP(time) >= ?\n      AND UNIX_TIMESTAMP(time) <= ( ? + 60 )\n      ORDER BY id ASC LIMIT 1");
     if ($this->checkStmt($stmt) && $stmt->bind_param('iii', $last, $aBlock['time'], $aBlock['time']) && $stmt->execute() && ($result = $stmt->get_result())) {
         $this->oUpstream = $result->fetch_object();
         $this->share_type = 'upstream_share';
         if (!empty($this->oUpstream->account) && !empty($this->oUpstream->worker) && is_int($this->oUpstream->id)) {
             return true;
         }
     }
     // We failed again, now we take ANY result matching the timestamp
     $stmt = $this->mysqli->prepare("\n      SELECT\n      SUBSTRING_INDEX( `username` , '.', 1 ) AS account, username as worker, id\n      FROM {$this->table}\n      WHERE our_result = 'Y'\n      AND id > ?\n      AND UNIX_TIMESTAMP(time) >= ?\n      ORDER BY id ASC LIMIT 1");
     if ($this->checkStmt($stmt) && $stmt->bind_param('ii', $last, $aBlock['time']) && $stmt->execute() && ($result = $stmt->get_result())) {
         $this->oUpstream = $result->fetch_object();
         $this->share_type = 'any_share';
         if (!empty($this->oUpstream->account) && !empty($this->oUpstream->worker) && is_int($this->oUpstream->id)) {
             return true;
         }
     }
     $this->setErrorMessage($this->getErrorMsg('E0052', $aBlock['height']));
     return false;
 }
Exemplo n.º 3
0
<?php

require_once 'scrypt.php';
$input = "   \n    7e 87 9a 21 4f 3e c9 86 7c a9 40 e6 41 71 8f 26\n    ba ee 55 5b 8c 61 c1 b5 0d f8 46 11 6d cd 3b 1d\n    ee 24 f3 19 df 9b 3d 85 14 12 1e 4b 5a c5 aa 32\n    76 02 1d 29 09 c7 48 29 ed eb c6 8d b8 b8 c2 5e";
$output = "\n   a4 1f 85 9c 66 08 cc 99 3b 81 ca cb 02 0c ef 05\n   04 4b 21 81 a2 fd 33 7d fd 7b 1c 63 96 68 2f 29\n   b4 39 31 68 e3 c9 e6 bc fe 6b c5 b7 a0 6d 96 ba\n   e4 24 cc 10 2c 91 74 5c 24 ad 67 3d c7 61 8f 81";
$input = str_replace([" ", "\n", "\r"], '', $input);
$output = str_replace([" ", "\n", "\r"], '', $output);
$input_binary = pack("H*", $input);
$output_binary = Scrypt::salsa20_8_core_binary($input_binary);
echo bin2hex($output_binary) . "\n";
echo "{$output}\n";
$scrypt = Scrypt::calculate("", "", 4, 1, 1, 64);
echo bin2hex($scrypt) . "\n";
die;
$b0 = "\nf7 ce 0b 65 3d 2d 72 a4 10 8c f5 ab e9 12 ff dd\n           77 76 16 db bb 27 a7 0e 82 04 f3 ae 2d 0f 6f ad\n           89 f6 8f 48 11 d1 e8 7b cc 3b d7 40 0a 9f fd 29\n           09 4f 01 84 63 95 74 f3 9a e5 a1 31 52 17 bc d7\n";
$b1 = "\n89 49 91 44 72 13 bb 22 6c 25 b5 4d a8 63 70 fb\n           cd 98 43 80 37 46 66 bb 8f fc b5 bf 40 c2 54 b0\n           67 d2 7c 51 ce 4a d5 fe d8 29 c9 0b 50 5a 57 1b\n           7f 4d 1c ad 6a 52 3c da 77 0e 67 bc ea af 7e 89\n";
$b0 = hex2bin(str_replace([" ", "\n", "\r"], '', $b0));
$b1 = hex2bin(str_replace([" ", "\n", "\r"], '', $b1));
$out = Scrypt::scryptBlockMix(1, [$b0, $b1]);
echo bin2hex($out[0]) . "\n";
echo bin2hex($out[1]) . "\n";
$b = "\nf7 ce 0b 65 3d 2d 72 a4 10 8c f5 ab e9 12 ff dd\n       77 76 16 db bb 27 a7 0e 82 04 f3 ae 2d 0f 6f ad\n       89 f6 8f 48 11 d1 e8 7b cc 3b d7 40 0a 9f fd 29\n       09 4f 01 84 63 95 74 f3 9a e5 a1 31 52 17 bc d7\n       89 49 91 44 72 13 bb 22 6c 25 b5 4d a8 63 70 fb\n       cd 98 43 80 37 46 66 bb 8f fc b5 bf 40 c2 54 b0\n       67 d2 7c 51 ce 4a d5 fe d8 29 c9 0b 50 5a 57 1b\n       7f 4d 1c ad 6a 52 3c da 77 0e 67 bc ea af 7e 89\n";
$b = hex2bin(str_replace([" ", "\n", "\r"], '', $b));
$b = str_split($b, 64);
$out = Scrypt::scryptROMix(1, $b, 16);
echo bin2hex(implode('', $out));