hf-resistance
This commit is contained in:
5
api.php
5
api.php
@@ -101,6 +101,9 @@ elseif($q=="getPublicKey"){
|
||||
api_echo(VERSION);
|
||||
|
||||
} elseif($q=="send"){
|
||||
$current=$block->current();
|
||||
|
||||
if($current['height']>10790&&$current['height']<10810) api_err("Hard fork in progress. Please retry the transaction later!"); //10800
|
||||
|
||||
$acc = new Account;
|
||||
$block = new Block;
|
||||
@@ -131,7 +134,9 @@ elseif($q=="getPublicKey"){
|
||||
$val=$data['val']+0;
|
||||
$fee=$val*0.0025;
|
||||
if($fee<0.00000001) $fee=0.00000001;
|
||||
|
||||
|
||||
if($fee>10&&$current['height']>10800) $fee=10; //10800
|
||||
if($val<0.00000001) api_err("Invalid value");
|
||||
|
||||
|
||||
|
||||
@@ -195,22 +195,26 @@ public function forge($nonce, $argon, $public_key, $private_key){
|
||||
}
|
||||
|
||||
|
||||
public function mine($public_key, $nonce, $argon, $difficulty=0, $current_id=0){
|
||||
|
||||
public function mine($public_key, $nonce, $argon, $difficulty=0, $current_id=0, $current_height=0){
|
||||
global $_config;
|
||||
if($current_id===0){
|
||||
$current=$this->current();
|
||||
$current_id=$current['id'];
|
||||
}
|
||||
$current_height=$current['height'];
|
||||
}
|
||||
if($difficulty===0) $difficulty=$this->difficulty();
|
||||
|
||||
|
||||
$argon='$argon2i$v=19$m=16384,t=4,p=4'.$argon;
|
||||
|
||||
if($current_height>10800) $argon='$argon2i$v=19$m=524288,t=1,p=1'.$argon; //10800
|
||||
else $argon='$argon2i$v=19$m=16384,t=4,p=4'.$argon;
|
||||
$base="$public_key-$nonce-".$current_id."-$difficulty";
|
||||
|
||||
|
||||
|
||||
|
||||
if(!password_verify($base,$argon)) { return false; }
|
||||
if(!password_verify($base,$argon)) { return false; }
|
||||
|
||||
if($_config['testnet']==true) return true;
|
||||
|
||||
$hash=$base.$argon;
|
||||
|
||||
@@ -246,7 +250,7 @@ public function parse_block($block, $height, $data, $test=true){
|
||||
foreach($data as &$x){
|
||||
if(empty($x['src'])) $x['src']=$acc->get_address($x['public_key']);
|
||||
|
||||
if(!$trx->check($x)) return false;
|
||||
if(!$trx->check($x,$height)) return false;
|
||||
|
||||
$balance[$x['src']]+=$x['val']+$x['fee'];
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
define("VERSION", "0.1a");
|
||||
define("VERSION", "0.2b");
|
||||
|
||||
date_default_timezone_set("Europe/Amsterdam");
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class Transaction {
|
||||
_log("$x[id] - Transaction has empty src");
|
||||
continue;
|
||||
}
|
||||
if(!$this->check($trans)){
|
||||
if(!$this->check($trans, $current['height'])){
|
||||
_log("$x[id] - Transaction Check Failed");
|
||||
continue;
|
||||
}
|
||||
@@ -114,8 +114,13 @@ class Transaction {
|
||||
}
|
||||
|
||||
|
||||
public function check($x){
|
||||
public function check($x, $height=0){
|
||||
|
||||
if($height===0){
|
||||
$block=new Block;
|
||||
$current=$block->current();
|
||||
$height=$current['height'];
|
||||
}
|
||||
$acc= new Account;
|
||||
$info=$x['val']."-".$x['fee']."-".$x['dst']."-".$x['message']."-".$x['version']."-".$x['public_key']."-".$x['date'];
|
||||
|
||||
@@ -125,6 +130,7 @@ class Transaction {
|
||||
$fee=$x['val']*0.0025;
|
||||
$fee=number_format($fee,8,".","");
|
||||
if($fee<0.00000001) $fee=0.00000001;
|
||||
if($height>10800&&$fee>10) $fee=10; //10800
|
||||
if($fee!=$x['fee']) { _log("$x[id] - Fee not 0.25%"); return false; }
|
||||
|
||||
if(!$acc->valid($x['dst'])) { _log("$x[id] - Invalid destination address"); return false; }
|
||||
|
||||
2
mine.php
2
mine.php
@@ -30,7 +30,7 @@ set_time_limit(360);
|
||||
$q=$_GET['q'];
|
||||
|
||||
$ip=$_SERVER['REMOTE_ADDR'];
|
||||
if(!in_array($ip,$_config['allowed_hosts'])) api_err("unauthorized");
|
||||
if($_config['testnet']==false&&!in_array($ip,$_config['allowed_hosts'])) api_err("unauthorized");
|
||||
|
||||
if($q=="info"){
|
||||
$diff=$block->difficulty();
|
||||
|
||||
6
peer.php
6
peer.php
@@ -69,6 +69,12 @@ elseif($q=="ping"){
|
||||
|
||||
|
||||
elseif($q=="submitTransaction"){
|
||||
|
||||
$current=$block->current();
|
||||
|
||||
if($current['height']>10790&&$current['height']<10810) api_err("Hard fork in progress. Please retry the transaction later!");
|
||||
|
||||
|
||||
if($_config['sanity_sync']==1) api_err("sanity-sync");
|
||||
|
||||
$data['id']=san($data['id']);
|
||||
|
||||
@@ -85,7 +85,7 @@ do {
|
||||
$prev = $block->get($current['height']-1);
|
||||
|
||||
$public=$acc->public_key($data['generator']);
|
||||
if(!$block->mine($public, $data['nonce'],$data['argon'],$block->difficulty($current['height']-1),$prev['id'])) { echo "Invalid prev-block\n"; break;}
|
||||
if(!$block->mine($public, $data['nonce'],$data['argon'],$block->difficulty($current['height']-1),$prev['id'], $prev['height'])) { echo "Invalid prev-block\n"; break;}
|
||||
$block->pop(1);
|
||||
if(!$block->check($data)) break;
|
||||
|
||||
@@ -134,7 +134,7 @@ $total_peers=count($r);
|
||||
|
||||
$peered=array();
|
||||
|
||||
if($total_peers==0){
|
||||
if($total_peers==0&&$_config['testnet']==false){
|
||||
$i=0;
|
||||
echo "No peers found. Attempting to get peers from arionum.com\n";
|
||||
$f=file("https://www.arionum.com/peers.txt");
|
||||
@@ -284,7 +284,7 @@ if($current['height']<$largest_height&&$largest_height>1){
|
||||
}
|
||||
|
||||
for($i=$last_good+1;$i<=$largest_height;$i++){
|
||||
if(!$block->mine($cblock[$i]['public_key'], $cblock[$i]['nonce'], $cblock[$i]['argon'], $cblock[$i]['difficulty'], $cblock[$i-1]['id'])) {$invalid=true; break; }
|
||||
if(!$block->mine($cblock[$i]['public_key'], $cblock[$i]['nonce'], $cblock[$i]['argon'], $cblock[$i]['difficulty'], $cblock[$i-1]['id'],$cblock[$i-1]['height'])) {$invalid=true; break; }
|
||||
}
|
||||
}
|
||||
if($invalid==false){
|
||||
@@ -380,7 +380,7 @@ if($_config['sanity_recheck_blocks']>0){
|
||||
|
||||
$key=$db->single("SELECT public_key FROM accounts WHERE id=:id",array(":id"=>$data['generator']));
|
||||
|
||||
if(!$block->mine($key,$data['nonce'], $data['argon'], $data['difficulty'], $blocks[$i-1]['id'])) {
|
||||
if(!$block->mine($key,$data['nonce'], $data['argon'], $data['difficulty'], $blocks[$i-1]['id'], $blocks[$i-1]['height'])) {
|
||||
$db->run("UPDATE config SET val=1 WHERE cfg='sanity_sync'");
|
||||
_log("Invalid block detected. Deleting everything after $data[height] - $data[id]");
|
||||
sleep(10);
|
||||
|
||||
2
util.php
2
util.php
@@ -91,7 +91,7 @@ elseif($cmd=="recheck-blocks"){
|
||||
|
||||
$key=$db->single("SELECT public_key FROM accounts WHERE id=:id",array(":id"=>$data['generator']));
|
||||
|
||||
if(!$block->mine($key,$data['nonce'], $data['argon'], $data['difficulty'], $blocks[$i-1]['id'])) {
|
||||
if(!$block->mine($key,$data['nonce'], $data['argon'], $data['difficulty'], $blocks[$i-1]['id'],$blocks[$i-1]['height'])) {
|
||||
_log("Invalid block detected. We should delete everything after $data[height] - $data[id]");
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user